Bug 792296, don't flush while getting popup state and calling other popup methods, r=neil
authorNeil Deakin <neil@mozilla.com>
Tue, 23 Oct 2012 08:11:09 -0400
changeset 111278 ddfc1c5c777aa8e64b3f4e66a5f34c311c8441b9
parent 111277 b8214dfa2924cac611ac07580827e44f3b820631
child 111279 3d0fe5f0aa25095e32dab074b0acacdc5f8a5cbb
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersneil
bugs792296
milestone19.0a1
Bug 792296, don't flush while getting popup state and calling other popup methods, r=neil
layout/xul/base/src/nsPopupBoxObject.cpp
toolkit/content/tests/chrome/test_popuphidden.xul
--- a/layout/xul/base/src/nsPopupBoxObject.cpp
+++ b/layout/xul/base/src/nsPopupBoxObject.cpp
@@ -102,17 +102,17 @@ nsPopupBoxObject::OpenPopupAtScreen(int3
   if (pm && mContent)
     pm->ShowPopupAtScreen(mContent, aXPos, aYPos, aIsContextMenu, aTriggerEvent);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPopupBoxObject::MoveTo(int32_t aLeft, int32_t aTop)
 {
-  nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
+  nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
   if (menuPopupFrame) {
     menuPopupFrame->MoveTo(aLeft, aTop, true);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -130,28 +130,30 @@ nsPopupBoxObject::SizeTo(int32_t aWidth,
   content->SetAttr(kNameSpaceID_None, nsGkAtoms::height, height, true);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPopupBoxObject::GetAutoPosition(bool* aShouldAutoPosition)
 {
-  nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
+  *aShouldAutoPosition = true;
+
+  nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
   if (menuPopupFrame) {
     *aShouldAutoPosition = menuPopupFrame->GetAutoPosition();
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPopupBoxObject::SetAutoPosition(bool aShouldAutoPosition)
 {
-  nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
+  nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
   if (menuPopupFrame) {
     menuPopupFrame->SetAutoPosition(aShouldAutoPosition);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
@@ -189,17 +191,17 @@ nsPopupBoxObject::EnableKeyboardNavigato
 }
 
 NS_IMETHODIMP
 nsPopupBoxObject::GetPopupState(nsAString& aState)
 {
   // set this here in case there's no frame for the popup
   aState.AssignLiteral("closed");
 
-  nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
+  nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
   if (menuPopupFrame) {
     switch (menuPopupFrame->PopupState()) {
       case ePopupShowing:
       case ePopupOpen:
         aState.AssignLiteral("showing");
         break;
       case ePopupOpenAndVisible:
         aState.AssignLiteral("open");
@@ -219,30 +221,30 @@ nsPopupBoxObject::GetPopupState(nsAStrin
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPopupBoxObject::GetTriggerNode(nsIDOMNode** aTriggerNode)
 {
   *aTriggerNode = nullptr;
 
-  nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
+  nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
   nsIContent* triggerContent = nsMenuPopupFrame::GetTriggerContent(menuPopupFrame);
   if (triggerContent)
     CallQueryInterface(triggerContent, aTriggerNode);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPopupBoxObject::GetAnchorNode(nsIDOMElement** aAnchor)
 {
   *aAnchor = nullptr;
 
-  nsMenuPopupFrame *menuPopupFrame = do_QueryFrame(GetFrame(false));
+  nsMenuPopupFrame *menuPopupFrame = mContent ? do_QueryFrame(mContent->GetPrimaryFrame()) : nullptr;
   if (!menuPopupFrame)
     return NS_OK;
 
   nsIContent* anchor = menuPopupFrame->GetAnchor();
   if (anchor)
     CallQueryInterface(anchor, aAnchor);
 
   return NS_OK;
--- a/toolkit/content/tests/chrome/test_popuphidden.xul
+++ b/toolkit/content/tests/chrome/test_popuphidden.xul
@@ -37,16 +37,17 @@ function runTests(popup)
 {
   popup.hidden = false;
   popup.openPopup(null, "after_start");
 }
 
 function hidePopupWhileShowing(popup)
 {
   popup.hidden = true;
+  popup.clientWidth; // flush layout
   is(popup.state, 'closed', 'popupshowing hidden');
   SimpleTest.executeSoon(function () runTests($('popupinbutton')));
 }
 
 function checkEndTest(event)
 {
   var button = $("button");
   if (event.originalTarget != button || event.attrName != 'open' || event.attrChange != event.REMOVAL)