Bug 703260, part 2, remove view usage from popup manager's widget callbacks, r=mats
authorNeil Deakin <neil@mozilla.com>
Mon, 21 Nov 2011 12:53:20 -0500
changeset 80580 e4a32b4ffd93f7594ff7496d44f51e6eb7bb4ae8
parent 80579 9298bebc43bf6d96bf3bf773931ca59ef1a815f5
child 80581 7e2695c9d94e2f652122fd8374e62ae881373e49
push id21511
push userbmo@edmorley.co.uk
push dateTue, 22 Nov 2011 02:38:00 +0000
treeherdermozilla-central@b8955ff00aae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs703260
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 703260, part 2, remove view usage from popup manager's widget callbacks, r=mats
layout/xul/base/public/nsXULPopupManager.h
layout/xul/base/src/nsXULPopupManager.cpp
view/src/nsViewManager.cpp
--- a/layout/xul/base/public/nsXULPopupManager.h
+++ b/layout/xul/base/public/nsXULPopupManager.h
@@ -76,17 +76,16 @@
  */
 
 class nsMenuFrame;
 class nsMenuPopupFrame;
 class nsMenuBarFrame;
 class nsMenuParent;
 class nsIDOMKeyEvent;
 class nsIDocShellTreeItem;
-class nsIView;
 
 // when a menu command is executed, the closemenu attribute may be used
 // to define how the menu should be closed up
 enum CloseMenuMode {
   CloseMenuMode_Auto, // close up the chain of menus, default value
   CloseMenuMode_None, // don't close up any menus
   CloseMenuMode_Single // close up only the menu the command is inside
 };
@@ -473,19 +472,20 @@ public:
    */
   void HidePopup(nsIContent* aPopup,
                  bool aHideChain,
                  bool aDeselectMenu,
                  bool aAsynchronous,
                  nsIContent* aLastPopup = nsnull);
 
   /**
-   * Hide the popup associated the view aView
+   * Hide the popup aFrame. This method is called by the view manager when the
+   * close button is pressed.
    */
-  void HidePopup(nsIView* aView);
+  void HidePopup(nsIFrame* aFrame);
 
   /**
    * Hide a popup after a short delay. This is used when rolling over menu items.
    * This timer is stored in mCloseTimer. The timer may be cancelled and the popup
    * closed by calling KillMenuTimer.
    */
   void HidePopupAfterDelay(nsMenuPopupFrame* aPopup);
 
@@ -548,23 +548,23 @@ public:
    * focused, or if it is a submenu of another menu that isn't open.
    */
   bool MayShowPopup(nsMenuPopupFrame* aFrame);
 
   /**
    * Indicate that the popup associated with aView has been moved to the
    * specified screen coordiates.
    */
-  void PopupMoved(nsIView* aView, nsIntPoint aPoint);
+  void PopupMoved(nsIFrame* aFrame, nsIntPoint aPoint);
 
   /**
    * Indicate that the popup associated with aView has been resized to the
    * specified screen width and height.
    */
-  void PopupResized(nsIView* aView, nsIntSize ASize);
+  void PopupResized(nsIFrame* aFrame, nsIntSize ASize);
 
   /**
    * Called when a popup frame is destroyed. In this case, just remove the
    * item and later popups from the list. No point going through HidePopup as
    * the frames have gone away.
    */
   void PopupDestroyed(nsMenuPopupFrame* aFrame);
 
--- a/layout/xul/base/src/nsXULPopupManager.cpp
+++ b/layout/xul/base/src/nsXULPopupManager.cpp
@@ -331,34 +331,33 @@ nsXULPopupManager::AdjustPopupsOnWindowC
       }
     }
 
     item = item->GetParent();
   }
 }
 
 static
-nsMenuPopupFrame* GetPopupToMoveOrResize(nsIView* aView)
+nsMenuPopupFrame* GetPopupToMoveOrResize(nsIFrame* aFrame)
 {
-  nsIFrame *frame = aView->GetFrame();
-  if (!frame || frame->GetType() != nsGkAtoms::menuPopupFrame)
+  if (!aFrame || aFrame->GetType() != nsGkAtoms::menuPopupFrame)
     return nsnull;
 
   // no point moving or resizing hidden popups
-  nsMenuPopupFrame* menuPopupFrame = static_cast<nsMenuPopupFrame *>(frame);
+  nsMenuPopupFrame* menuPopupFrame = static_cast<nsMenuPopupFrame *>(aFrame);
   if (menuPopupFrame->PopupState() != ePopupOpenAndVisible)
     return nsnull;
 
   return menuPopupFrame;
 }
 
 void
-nsXULPopupManager::PopupMoved(nsIView* aView, nsIntPoint aPnt)
+nsXULPopupManager::PopupMoved(nsIFrame* aFrame, nsIntPoint aPnt)
 {
-  nsMenuPopupFrame* menuPopupFrame = GetPopupToMoveOrResize(aView);
+  nsMenuPopupFrame* menuPopupFrame = GetPopupToMoveOrResize(aFrame);
   if (!menuPopupFrame)
     return;
 
   // Don't do anything if the popup is already at the specified location. This
   // prevents recursive calls when a popup is positioned.
   nsIntPoint currentPnt = menuPopupFrame->ScreenPosition();
   if (aPnt.x != currentPnt.x || aPnt.y != currentPnt.y) {
     // Update the popup's position using SetPopupPosition if the popup is
@@ -371,19 +370,19 @@ nsXULPopupManager::PopupMoved(nsIView* a
     }
     else {
       menuPopupFrame->MoveTo(aPnt.x, aPnt.y, false);
     }
   }
 }
 
 void
-nsXULPopupManager::PopupResized(nsIView* aView, nsIntSize aSize)
+nsXULPopupManager::PopupResized(nsIFrame* aFrame, nsIntSize aSize)
 {
-  nsMenuPopupFrame* menuPopupFrame = GetPopupToMoveOrResize(aView);
+  nsMenuPopupFrame* menuPopupFrame = GetPopupToMoveOrResize(aFrame);
   if (!menuPopupFrame)
     return;
 
   nsPresContext* presContext = menuPopupFrame->PresContext();
 
   nsSize currentSize = menuPopupFrame->GetSize();
   if (aSize.width != presContext->AppUnitsToDevPixels(currentSize.width) ||
       aSize.height != presContext->AppUnitsToDevPixels(currentSize.height)) {
@@ -993,23 +992,20 @@ nsXULPopupManager::HidePopupCallback(nsI
       FirePopupHidingEvent(popupToHide, nextPopup, aLastPopup,
                            popupFrame->PresContext(),
                            foundMenu->PopupType(), aDeselectMenu);
     }
   }
 }
 
 void
-nsXULPopupManager::HidePopup(nsIView* aView)
+nsXULPopupManager::HidePopup(nsIFrame* aFrame)
 {
-  nsIFrame *frame = aView->GetFrame();
-  if (!frame || frame->GetType() != nsGkAtoms::menuPopupFrame)
-    return;
-
-  HidePopup(frame->GetContent(), false, true, false);
+  if (aFrame && aFrame->GetType() == nsGkAtoms::menuPopupFrame)
+    HidePopup(aFrame->GetContent(), false, true, false);
 }
 
 void
 nsXULPopupManager::HidePopupAfterDelay(nsMenuPopupFrame* aPopup)
 {
   // Don't close up immediately.
   // Kick off a close timer.
   KillMenuTimer();
--- a/view/src/nsViewManager.cpp
+++ b/view/src/nsViewManager.cpp
@@ -730,17 +730,17 @@ NS_IMETHODIMP nsViewManager::DispatchEve
                                     NSIntPixelsToAppUnits(height, p2a));
                 *aStatus = nsEventStatus_eConsumeNoDefault;
               }
             else if (IsViewForPopup(aView))
               {
                 nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
                 if (pm)
                   {
-                    pm->PopupResized(aView, nsIntSize(width, height));
+                    pm->PopupResized(aView->GetFrame(), nsIntSize(width, height));
                     *aStatus = nsEventStatus_eConsumeNoDefault;
                   }
               }
           }
         }
 
         break;
 
@@ -749,17 +749,17 @@ NS_IMETHODIMP nsViewManager::DispatchEve
         // A popup's parent view is the root view for the parent window, so when
         // a popup moves, the popup's frame and view position must be updated
         // to match.
         if (aView && IsViewForPopup(aView))
           {
             nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
             if (pm)
               {
-                pm->PopupMoved(aView, aEvent->refPoint);
+                pm->PopupMoved(aView->GetFrame(), aEvent->refPoint);
                 *aStatus = nsEventStatus_eConsumeNoDefault;
               }
           }
         break;
       }
 
     case NS_DONESIZEMOVE:
       {
@@ -781,17 +781,17 @@ NS_IMETHODIMP nsViewManager::DispatchEve
         // event listener may cancel the event and the popup will not be hidden.
         nsIWidget* widget = aView->GetWidget();
         if (widget) {
           nsWindowType type;
           widget->GetWindowType(type);
           if (type == eWindowType_popup) {
             nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
             if (pm) {
-              pm->HidePopup(aView);
+              pm->HidePopup(aView->GetFrame());
               *aStatus = nsEventStatus_eConsumeNoDefault;
             }
           }
         }
       }
       break;
 
     case NS_WILL_PAINT: