Bug 841308 - Make WillPaintWindow be called for cocoa popups. r=roc, a=bajaj
authorMatt Woodrow <mwoodrow@mozilla.com>
Tue, 26 Feb 2013 10:18:48 +1300
changeset 132313 9b6f8360af6198ee7ff6c9cfffe1e4972e696aa5
parent 132312 8323e52f55db55d75d94d113d6b95e62311f70ea
child 132314 a4dc2d408983f0dc084aef294befe609bcbe4cd2
push idunknown
push userunknown
push dateunknown
reviewersroc, bajaj
bugs841308
milestone21.0a2
Bug 841308 - Make WillPaintWindow be called for cocoa popups. r=roc, a=bajaj
view/src/nsView.cpp
widget/cocoa/nsChildView.h
widget/cocoa/nsChildView.mm
--- a/view/src/nsView.cpp
+++ b/view/src/nsView.cpp
@@ -305,16 +305,18 @@ void nsView::SetDimensions(const nsRect&
 
 void nsView::NotifyEffectiveVisibilityChanged(bool aEffectivelyVisible)
 {
   if (!aEffectivelyVisible)
   {
     DropMouseGrabbing();
   }
 
+  SetForcedRepaint(true);
+
   if (nullptr != mWindow)
   {
     if (aEffectivelyVisible)
     {
       DoResetWidgetBounds(false, true);
       mWindow->Show(true);
     }
     else
--- a/widget/cocoa/nsChildView.h
+++ b/widget/cocoa/nsChildView.h
@@ -480,16 +480,17 @@ public:
 
   virtual nsresult SynthesizeNativeMouseMove(nsIntPoint aPoint)
   { return SynthesizeNativeMouseEvent(aPoint, NSMouseMoved, 0); }
 
   // Mac specific methods
   
   virtual bool      DispatchWindowEvent(nsGUIEvent& event);
 
+  void WillPaintWindow();
   bool PaintWindow(nsIntRegion aRegion, bool aIsAlternate);
 
 #ifdef ACCESSIBILITY
   already_AddRefed<mozilla::a11y::Accessible> GetDocumentAccessible();
 #endif
 
   virtual void CreateCompositor();
   virtual gfxASurface* GetThebesSurface();
@@ -553,16 +554,18 @@ protected:
   virtual already_AddRefed<nsIWidget>
   AllocateChildPopupWidget()
   {
     static NS_DEFINE_IID(kCPopUpCID, NS_POPUP_CID);
     nsCOMPtr<nsIWidget> widget = do_CreateInstance(kCPopUpCID);
     return widget.forget();
   }
 
+  nsIWidget* GetWidgetForListenerEvents();
+
 protected:
 
   NSView<mozView>*      mView;      // my parallel cocoa view (ChildView or NativeScrollbarView), [STRONG]
   nsRefPtr<mozilla::widget::TextInputHandler> mTextInputHandler;
   InputContext          mInputContext;
 
   NSView<mozView>*      mParentView;
   nsIWidget*            mParentWidget;
--- a/widget/cocoa/nsChildView.mm
+++ b/widget/cocoa/nsChildView.mm
@@ -1492,29 +1492,45 @@ NS_IMETHODIMP nsChildView::DispatchEvent
 
 bool nsChildView::DispatchWindowEvent(nsGUIEvent &event)
 {
   nsEventStatus status;
   DispatchEvent(&event, status);
   return ConvertStatus(status);
 }
 
-bool nsChildView::PaintWindow(nsIntRegion aRegion, bool aIsAlternate)
-{
-  nsCOMPtr<nsIWidget> widget = this;
-
+nsIWidget*
+nsChildView::GetWidgetForListenerEvents()
+{
   // If there is no listener, use the parent popup's listener if that exists.
   if (!mWidgetListener && mParentWidget) {
     nsWindowType type;
     mParentWidget->GetWindowType(type);
     if (type == eWindowType_popup) {
-      widget = mParentWidget;
+      return mParentWidget;
     }
   }
 
+  return this;
+}
+
+void nsChildView::WillPaintWindow()
+{
+  nsCOMPtr<nsIWidget> widget = GetWidgetForListenerEvents();
+
+  nsIWidgetListener* listener = widget->GetWidgetListener();
+  if (listener) {
+    listener->WillPaintWindow(widget);
+  }
+}
+
+bool nsChildView::PaintWindow(nsIntRegion aRegion, bool aIsAlternate)
+{
+  nsCOMPtr<nsIWidget> widget = GetWidgetForListenerEvents();
+
   nsIWidgetListener* listener = widget->GetWidgetListener();
   if (!listener)
     return false;
 
   bool returnValue = false;
   bool oldDispatchPaint = mIsDispatchPaint;
   mIsDispatchPaint = true;
   uint32_t flags = 0;
@@ -2691,20 +2707,17 @@ NSEvent* gLastDragMouseDownEvent = nil;
       }
       NS_ADDREF(mGeckoChild);
       [widgetArray addObject:[NSNumber numberWithUnsignedInteger:(NSUInteger)mGeckoChild]];
       [self performSelector:@selector(releaseWidgets:)
                  withObject:widgetArray
                  afterDelay:0];
     }
 
-    nsIWidgetListener* listener = mGeckoChild->GetWidgetListener();
-    if (listener) {
-      listener->WillPaintWindow(mGeckoChild);
-    }
+    mGeckoChild->WillPaintWindow();
   }
   [super viewWillDraw];
 }
 
 // Allows us to turn off setting up the clip region
 // before each drawRect. We already clip within gecko.
 - (BOOL)wantsDefaultClipping
 {