From 282e96649a66d87653ceee2d701e5392d0f2c4ae Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Mon, 3 Dec 2012 22:21:01 +0000 Subject: [PATCH 1/5] Formatting. --- Tests/AppKit/CPApplicationTest.j | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/AppKit/CPApplicationTest.j b/Tests/AppKit/CPApplicationTest.j index 35b14ec98..f3ceefb57 100644 --- a/Tests/AppKit/CPApplicationTest.j +++ b/Tests/AppKit/CPApplicationTest.j @@ -195,7 +195,7 @@ globalResults = []; [[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification:) name:CPApplicationWillTerminateNotification - object:nil]; + object:nil]; [app replyToApplicationShouldTerminate:CPTerminateNow]; [self assert:CPApplicationWillTerminateNotification equals:[globalResults[0] name]]; @@ -223,8 +223,8 @@ globalResults = []; - (void)testTargetForAction { - var mainWin = [[TestMainWindow alloc] init]; - var keyWin = [[TestKeyWindow alloc] init]; + var mainWin = [[TestMainWindow alloc] init], + keyWin = [[TestKeyWindow alloc] init]; mainWin._isVisible = YES; keyWin._isVisible = YES; [mainWin makeMainWindow]; @@ -252,6 +252,6 @@ globalResults = []; // when no target is given, targetForAction is called [self assert:app equals:[app targetForAction:@selector(someTestMethod:) to:nil from:nil]]; - } + @end From c9434ec4dc94466ce5fe5cfbe2f0f3df11560284 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Mon, 3 Dec 2012 22:22:16 +0000 Subject: [PATCH 2/5] Fixed: CPFontManager attempt to access DOM in non-DOM apps. The DOM access caused `CPFontManagerTest` when executed with rhino. --- AppKit/CPFontManager.j | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AppKit/CPFontManager.j b/AppKit/CPFontManager.j index cee4f062d..cfeede594 100644 --- a/AppKit/CPFontManager.j +++ b/AppKit/CPFontManager.j @@ -99,6 +99,9 @@ var CPSharedFontManager = nil, { if (!_availableFonts) { + _availableFonts = []; + +#if PLATFORM(DOM) _CPFontDetectSpan = document.createElement("span"); _CPFontDetectSpan.fontSize = "24px"; _CPFontDetectSpan.appendChild(document.createTextNode("mmmmmmmmmml")); @@ -110,13 +113,16 @@ var CPSharedFontManager = nil, _CPFontDetectReferenceFonts = _CPFontDetectPickTwoDifferentFonts(["monospace", "serif", "sans-serif", "cursive"]); - _availableFonts = []; for (var i = 0; i < _CPFontDetectAllFonts.length; i++) { var available = _CPFontDetectFontAvailable(_CPFontDetectAllFonts[i]); if (available) _availableFonts.push(_CPFontDetectAllFonts[i]); } +#else + // If there's no font detection, just assume all fonts are available. + _availableFonts = _CPFontDetectAllFonts; +#endif } return _availableFonts; } From 2611e867b3623793fe95d0792f1d557685400606 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Mon, 3 Dec 2012 22:44:12 +0000 Subject: [PATCH 3/5] Fixed: ce9534c too negative with canBecomeKeyWindow. Due to a typo in ce9534c, even standard titled windows returned NO for `canBecomeKeyWindow`. This triggered errors in `CPApplicationTest`. The fix returns the correct YES for `canBecomeKeyWindow` of titled windows. --- AppKit/CPWindow/CPWindow.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index c1e14a813..ffd7de7e6 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -1858,7 +1858,7 @@ CPTexturedBackgroundWindowMask { // In Cocoa only resizable or titled windows return YES here by default. But the main browser window in Cappuccino // doesn't have these masks even that it's both titled and resizable, so we return YES when isFullPlatformWindow too. - return (_styleMask & CPResizableWindowMask) || (_styleMask & CPResizableWindowMask) || [self isFullPlatformWindow]; + return (_styleMask & CPTitledWindowMask) || (_styleMask & CPResizableWindowMask) || [self isFullPlatformWindow]; } /*! From ad5f0a7f7d11f5e5ed66c3afb48770c6dabdee1a Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Mon, 3 Dec 2012 22:45:53 +0000 Subject: [PATCH 4/5] Avoid touching the window object in CPApplication of non-DOM apps. --- AppKit/CPApplication.j | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 68b256c5f..63b1691a3 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -250,8 +250,13 @@ CPRunContinuesResponse = -1002; _documentController = [CPDocumentController sharedDocumentController]; var needsUntitled = !!_documentController, - URLStrings = window.cpOpeningURLStrings && window.cpOpeningURLStrings(), - index = 0, + URLStrings = nil; + +#if PLATFORM(DOM) + URLStrings = window.cpOpeningURLStrings && window.cpOpeningURLStrings(); +#endif + + var index = 0, count = [URLStrings count]; for (; index < count; ++index) @@ -1009,7 +1014,8 @@ CPRunContinuesResponse = -1002; */ - (CPArray)arguments { - if (_fullArgsString !== window.location.hash) + // FIXME This should probably not access the window object #if !PLATFORM(DOM), but the unit tests rely on it. + if (window && window.location && _fullArgsString !== window.location.hash) [self _reloadArguments]; return _args; @@ -1036,8 +1042,9 @@ CPRunContinuesResponse = -1002; if (!args || args.length == 0) { _args = []; +#if PLATFORM(DOM) window.location.hash = @"#"; - +#endif return; } @@ -1052,12 +1059,15 @@ CPRunContinuesResponse = -1002; var hash = [toEncode componentsJoinedByString:@"/"]; +#if PLATFORM(DOM) window.location.hash = @"#" + hash; +#endif } - (void)_reloadArguments { - _fullArgsString = window.location.hash; + // FIXME This should probably not access the window object #if !PLATFORM(DOM), but the unit tests rely on it. + _fullArgsString = (window && window.location) ? window.location.hash : ""; if (_fullArgsString.length) { From 77955f4e2baebd13aad599604b9bb4cf9bfb8463 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Tue, 11 Dec 2012 00:57:42 +0000 Subject: [PATCH 5/5] Allow setTimeout(f) to support some JS libraries such as PDF.js. Without this change some 3rd party JS libraries such as PDF.js, which rely on the nonstandard setTimeout(f), will not operate correctly. According to MDN the delay argument is required. However browsers seem to treat setTimeout without delay argument the same as a delay of 0. This fix makes it so that Cappuccino apps do the same. --- Foundation/CPTimer.j | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Foundation/CPTimer.j b/Foundation/CPTimer.j index 6edfa4818..19cca083b 100644 --- a/Foundation/CPTimer.j +++ b/Foundation/CPTimer.j @@ -254,6 +254,9 @@ var _CPTimerBridgeTimer = function(codeOrFunction, aDelay, shouldRepeat, functio theFunction = function() { codeOrFunction.apply(window, functionArgs); if (!shouldRepeat) CPTimersForTimeoutIDs[timeoutID] = nil; } } + // A call such as setTimeout(f) is technically invalid but browsers seem to treat it as setTimeout(f, 0), so so will we. + aDelay = aDelay | 0.0; + CPTimersForTimeoutIDs[timeoutID] = [CPTimer scheduledTimerWithTimeInterval:aDelay / 1000 callback:theFunction repeats:shouldRepeat]; return timeoutID;