Bug 958674 - Paint popup synchronously when showing the window, like we do for normal windows. r=smichaud
authorMarkus Stange <mstange@themasta.com>
Mon, 03 Feb 2014 17:54:55 +0100
changeset 166641 0d119852513a94e624b59f6f8709449364b5b166
parent 166640 54001ad1dfb72982d2ab07c188fde14264c03a78
child 166642 89554fdaf65d038ce73fc68c349c4b823a722424
push id4808
push userryanvm@gmail.com
push dateMon, 03 Feb 2014 23:16:15 +0000
treeherderfx-team@c150845d077d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmichaud
bugs958674
milestone29.0a1
Bug 958674 - Paint popup synchronously when showing the window, like we do for normal windows. r=smichaud
widget/cocoa/nsCocoaWindow.h
widget/cocoa/nsCocoaWindow.mm
--- a/widget/cocoa/nsCocoaWindow.h
+++ b/widget/cocoa/nsCocoaWindow.h
@@ -97,16 +97,17 @@ typedef struct _nsCocoaWindowList {
 
 - (void)mouseEntered:(NSEvent*)aEvent;
 - (void)mouseExited:(NSEvent*)aEvent;
 - (void)mouseMoved:(NSEvent*)aEvent;
 - (void)updateTrackingArea;
 - (NSView*)trackingAreaView;
 
 - (void)setBeingShown:(BOOL)aValue;
+- (BOOL)isBeingShown;
 - (BOOL)isVisibleOrBeingShown;
 
 - (ChildView*)mainChildView;
 
 - (NSArray*)titlebarControls;
 
 - (void)setWantsTitleDrawn:(BOOL)aDrawTitle;
 - (BOOL)wantsTitleDrawn;
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -681,24 +681,33 @@ NS_IMETHODIMP nsCocoaWindow::Show(bool b
   if (!mWindow)
     return NS_OK;
 
   // We need to re-execute sometimes in order to bring already-visible
   // windows forward.
   if (!mSheetNeedsShow && !bState && ![mWindow isVisible])
     return NS_OK;
 
+  // Protect against re-entering.
+  if (bState && [mWindow isBeingShown])
+    return NS_OK;
+
   [mWindow setBeingShown:bState];
 
   nsIWidget* parentWidget = mParent;
   nsCOMPtr<nsPIWidgetCocoa> piParentWidget(do_QueryInterface(parentWidget));
   NSWindow* nativeParentWindow = (parentWidget) ?
     (NSWindow*)parentWidget->GetNativeData(NS_NATIVE_WINDOW) : nil;
 
   if (bState && !mBounds.IsEmpty()) {
+    if (mPopupContentView) {
+      // Ensure our content view is visible. We never need to hide it.
+      mPopupContentView->Show(true);
+    }
+
     if (mWindowType == eWindowType_sheet) {
       // bail if no parent window (its basically what we do in Carbon)
       if (!nativeParentWindow || !piParentWidget)
         return NS_ERROR_FAILURE;
 
       NSWindow* topNonSheetWindow = nativeParentWindow;
       
       // If this sheet is the child of another sheet, hide the parent so that
@@ -751,16 +760,17 @@ NS_IMETHODIMP nsCocoaWindow::Show(bool b
       [mWindow _setWindowNumber:-1];
       [mWindow _setWindowNumber:windowNumber];
       // For reasons that aren't yet clear, calls to [NSWindow orderFront:] or
       // [NSWindow makeKeyAndOrderFront:] can sometimes trigger "Error (1000)
       // creating CGSWindow", which in turn triggers an internal inconsistency
       // NSException.  These errors shouldn't be fatal.  So we need to wrap
       // calls to ...orderFront: in LOGONLY blocks.  See bmo bug 470864.
       NS_OBJC_BEGIN_TRY_LOGONLY_BLOCK;
+      [[mWindow contentView] setNeedsDisplay:YES];
       [mWindow orderFront:nil];
       NS_OBJC_END_TRY_LOGONLY_BLOCK;
       SendSetZLevelEvent();
       AdjustWindowShadow();
       SetWindowBackgroundBlur();
       // If our popup window is a non-native context menu, tell the OS (and
       // other programs) that a menu has opened.  This is how the OS knows to
       // close other programs' context menus when ours open.
@@ -897,21 +907,16 @@ NS_IMETHODIMP nsCocoaWindow::Show(bool b
       if ([mWindow isKindOfClass:[PopupWindow class]] &&
           [(PopupWindow*) mWindow isContextMenu]) {
         [[NSDistributedNotificationCenter defaultCenter]
           postNotificationName:@"com.apple.HIToolbox.endMenuTrackingNotification"
                         object:@"org.mozilla.gecko.PopupWindow"];
       }
     }
   }
-  
-  if (mPopupContentView) {
-    mPopupContentView->Show(bState);
-    [[mWindow contentView] setNeedsDisplay:YES];
-  }
 
   [mWindow setBeingShown:NO];
 
   return NS_OK;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
 }
 
@@ -2632,16 +2637,21 @@ static NSMutableSet *gSwizzledFrameViewC
   return self;
 }
 
 - (void)setBeingShown:(BOOL)aValue
 {
   mBeingShown = aValue;
 }
 
+- (BOOL)isBeingShown
+{
+  return mBeingShown;
+}
+
 - (BOOL)isVisibleOrBeingShown
 {
   return [super isVisible] || mBeingShown;
 }
 
 - (void)disableSetNeedsDisplay
 {
   mDisabledNeedsDisplay = YES;