diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index 0fb6bb6e7238..ac97edae3c77 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -124,7 +124,9 @@ CFStringRef kOurTISPropertyUnicodeKeyLayoutData = NULL; CFStringRef kOurTISPropertyInputSourceID = NULL; CFStringRef kOurTISPropertyInputSourceLanguages = NULL; -extern PRBool gCocoaWindowMethodsSwizzled; // Defined in nsCocoaWindow.mm +// these are defined in nsCocoaWindow.mm +extern PRBool gCocoaWindowMethodsSwizzled; +extern PRBool gConsumeRollupEvent; PRBool gChildViewMethodsSwizzled = PR_FALSE; @@ -3197,24 +3199,27 @@ static const PRInt32 sShadowInvalidationInterval = 100; } +// Returns true if the event should no longer be processed, false otherwise. +// This does not return whether or not anything was rolled up. - (BOOL)maybeRollup:(NSEvent*)theEvent { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; - PRBool retVal = PR_FALSE; + BOOL consumeEvent = NO; + if (gRollupWidget && gRollupListener) { NSWindow* currentPopup = static_cast(gRollupWidget->GetNativeData(NS_NATIVE_WINDOW)); if (!nsCocoaUtils::IsEventOverWindow(theEvent, currentPopup)) { - PRBool rollup = PR_TRUE; + // event is not over the rollup window, default is to roll up + PRBool shouldRollup = PR_TRUE; + + // check to see if scroll events should roll up the popup if ([theEvent type] == NSScrollWheel) { - gRollupListener->ShouldRollupOnMouseWheelEvent(&rollup); - // We don't want the event passed on for scrollwheel events if we're - // not supposed to close the popup. Otherwise the background window - // will scroll when a custom context menu or the autoscroll popup is - // open (and the mouse isn't over the popup) -- which doesn't seem right. - // This change resolves bmo bug 344367. - retVal = PR_TRUE; + gRollupListener->ShouldRollupOnMouseWheelEvent(&shouldRollup); + // always consume scroll events that aren't over the popup + consumeEvent = YES; } + // if we're dealing with menus, we probably have submenus and // we don't want to rollup if the click is in a parent menu of // the current submenu @@ -3227,21 +3232,20 @@ static const PRInt32 sShadowInvalidationInterval = 100; nsIWidget* widget = widgetChain[i]; NSWindow* currWindow = (NSWindow*)widget->GetNativeData(NS_NATIVE_WINDOW); if (nsCocoaUtils::IsEventOverWindow(theEvent, currWindow)) { - rollup = PR_FALSE; + shouldRollup = PR_FALSE; break; } - } // foreach parent menu widget - } // if rollup listener knows about menus + } + } - // if we've determined that we should still rollup, do it. - if (rollup) { + if (shouldRollup) { gRollupListener->Rollup(nsnull); - retVal = PR_TRUE; + consumeEvent = (BOOL)gConsumeRollupEvent; } } } - return retVal; + return consumeEvent; NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO); } diff --git a/widget/src/cocoa/nsCocoaWindow.mm b/widget/src/cocoa/nsCocoaWindow.mm index 8a4284d5e8bf..b2a9df9363bf 100644 --- a/widget/src/cocoa/nsCocoaWindow.mm +++ b/widget/src/cocoa/nsCocoaWindow.mm @@ -81,6 +81,8 @@ nsCocoaWindowList *gGeckoAppModalWindowList = NULL; PRBool gCocoaWindowMethodsSwizzled = PR_FALSE; +PRBool gConsumeRollupEvent; + // defined in nsMenuBarX.mm extern NSMenu* sApplicationMenu; // Application menu shared by all menubars @@ -1286,6 +1288,9 @@ NS_IMETHODIMP nsCocoaWindow::CaptureRollupEvents(nsIRollupListener * aListener, NS_ADDREF(aListener); gRollupWidget = this; NS_ADDREF(this); + + gConsumeRollupEvent = aConsumeRollupEvent; + // Sometimes more than one popup window can be visible at the same time // (e.g. nested non-native context menus, or the test case (attachment // 276885) for bmo bug 392389, which displays a non-native combo-box in