Fix CPWindow -canBecomeKeyWindow and -canBecomeMainWindow to match Cocoa behavior (and misleading documentation)

Minor code formatting cleanup as well
This commit is contained in:
Aparajita Fishman committed 2013-01-06 16:21:10 +08:00
1 parent 3e6517849e
commit 8d68e805f4
3 files changed
+39 -11

No files matched your search

+15 -8
View File
@@ -1856,9 +1856,16 @@ CPTexturedBackgroundWindowMask
*/
- (BOOL)canBecomeKeyWindow
{
// 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 & CPTitledWindowMask) || (_styleMask & CPResizableWindowMask) || [self isFullPlatformWindow];
/*
In Cocoa only titled windows return YES here by default. But the main browser
window in Cappuccino doesn't have a title bar even that it's both titled and
resizable, so we return YES when isFullPlatformWindow too.
Note that Cocoa will return NO for a non-titled, resizable window. The Cocoa documention
says it will return YES if there is a "resize bar", but in practice
that is not the same as the resizable mask.
*/
return (_styleMask & CPTitledWindowMask) || [self isFullPlatformWindow];
}
/*!
@@ -2222,11 +2229,11 @@ CPTexturedBackgroundWindowMask
*/
- (BOOL)canBecomeMainWindow
{
// FIXME: Also check if we can resize and titlebar.
if ([self isVisible])
return YES;
return NO;
// Note that the Cocoa documentation says that this method returns YES if
// the window is visible and has a title bar or a "resize mechanism". It turns
// out a "resize mechanism" is not the same as having the resize mask set.
// In practice a window must have a title bar to become main.
return ([self isVisible] && (_styleMask & CPTitledWindowMask));
}
/*!
+8 -1
View File
@@ -375,7 +375,14 @@ var CPRunLoopLastNativeRunLoop = 0;
//initiate a new window.setTimeout if there are any timers
if (_nextTimerFireDatesForModes[aMode] !== nil)
_nativeTimersForModes[aMode] = window.setNativeTimeout(function() { _effectiveDate = nextFireDate; _nativeTimersForModes[aMode] = nil; ++CPRunLoopLastNativeRunLoop; [self limitDateForMode:aMode]; _effectiveDate = nil; }, MAX(0, [nextFireDate timeIntervalSinceNow] * 1000));
_nativeTimersForModes[aMode] = window.setNativeTimeout(function()
{
_effectiveDate = nextFireDate;
_nativeTimersForModes[aMode] = nil;
++CPRunLoopLastNativeRunLoop;
[self limitDateForMode:aMode];
_effectiveDate = nil;
}, MAX(0, [nextFireDate timeIntervalSinceNow] * 1000));
}
// Run loop performers
+16 -2
View File
@@ -245,13 +245,27 @@ var _CPTimerBridgeTimer = function(codeOrFunction, aDelay, shouldRepeat, functio
theFunction = nil;
if (typeof codeOrFunction === "string")
theFunction = function() { new Function(codeOrFunction)(); if (!shouldRepeat) CPTimersForTimeoutIDs[timeoutID] = nil; }
{
theFunction = function()
{
new Function(codeOrFunction)();
if (!shouldRepeat)
CPTimersForTimeoutIDs[timeoutID] = nil;
}
}
else
{
if (!functionArgs)
functionArgs = [];
theFunction = function() { codeOrFunction.apply(window, functionArgs); if (!shouldRepeat) CPTimersForTimeoutIDs[timeoutID] = nil; }
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.