Bug 1519577 Remove support for unused toolbarbutton anchor attribute r=NeilDeakin
authorAndrew Swan <aswan@mozilla.com>
Tue, 14 May 2019 13:08:53 -0700
changeset 474976 82d77e63f4d3971ee341c6a49daacc6524e9d80c
parent 474975 8f0abb76f7bb982c13424019f7bda30089acf1e8
child 474977 595c3065e9ac64ed1d4ada38c3a83c6ba2a0ff91
push id113185
push useraswan@mozilla.com
push dateWed, 22 May 2019 23:25:35 +0000
treeherdermozilla-inbound@c8e9b6a81194 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeilDeakin
bugs1519577
milestone69.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 1519577 Remove support for unused toolbarbutton anchor attribute r=NeilDeakin This code contains an undesirable dependency between the layout code and the implementation of toolbarbutton. Since it isn't actually used anywhere by the firefox UI, remove it here. Differential Revision: https://phabricator.services.mozilla.com/D31939
browser/base/content/browser.xul
layout/xul/nsMenuFrame.cpp
layout/xul/nsMenuFrame.h
layout/xul/nsMenuPopupFrame.cpp
layout/xul/nsMenuPopupFrame.h
layout/xul/nsPopupSetFrame.cpp
layout/xul/nsXULPopupManager.cpp
toolkit/content/tests/chrome/chrome.ini
toolkit/content/tests/chrome/test_menu_anchored.xul
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -1198,17 +1198,16 @@
                      label="&fullScreenCmd.label;"
                      tooltip="dynamic-shortcut-tooltip"/>
 
       <toolbarbutton id="bookmarks-menu-button"
                      class="toolbarbutton-1 chromeclass-toolbar-additional subviewbutton-nav"
                      type="menu"
                      label="&bookmarksMenuButton2.label;"
                      tooltip="dynamic-shortcut-tooltip"
-                     anchor="dropmarker"
                      ondragenter="PlacesMenuDNDHandler.onDragEnter(event);"
                      ondragover="PlacesMenuDNDHandler.onDragOver(event);"
                      ondragleave="PlacesMenuDNDHandler.onDragLeave(event);"
                      ondrop="PlacesMenuDNDHandler.onDrop(event);"
                      oncommand="BookmarkingUI.onCommand(event);">
         <menupopup id="BMB_bookmarksPopup"
                    class="cui-widget-panel cui-widget-panelview cui-widget-panelWithFooter PanelUI-subView"
                    placespopup="true"
--- a/layout/xul/nsMenuFrame.cpp
+++ b/layout/xul/nsMenuFrame.cpp
@@ -620,35 +620,16 @@ nsresult nsMenuFrame::AttributeChanged(i
       aAttribute == nsGkAtoms::name) {
     nsCOMPtr<nsIRunnable> event =
         new nsMenuAttributeChangedEvent(this, aAttribute);
     nsContentUtils::AddScriptRunner(event);
   }
   return NS_OK;
 }
 
-nsIContent* nsMenuFrame::GetAnchor() {
-  mozilla::dom::Element* anchor = nullptr;
-
-  nsAutoString id;
-  mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::anchor, id);
-  if (!id.IsEmpty()) {
-    Document* doc = mContent->OwnerDoc();
-
-    anchor =
-        doc->GetAnonymousElementByAttribute(mContent, nsGkAtoms::anonid, id);
-    if (!anchor) {
-      anchor = doc->GetElementById(id);
-    }
-  }
-
-  // Always return the menu's content if the anchor wasn't set or wasn't found.
-  return anchor && anchor->GetPrimaryFrame() ? anchor : GetContent();
-}
-
 void nsMenuFrame::OpenMenu(bool aSelectFirstItem) {
   if (!mContent) return;
 
   nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
   if (pm) {
     pm->KillMenuTimer();
     // This opens the menu asynchronously
     pm->ShowMenu(mContent, aSelectFirstItem, true);
@@ -688,18 +669,17 @@ nsSize nsMenuFrame::GetXULMinSize(nsBoxL
 NS_IMETHODIMP
 nsMenuFrame::DoXULLayout(nsBoxLayoutState& aState) {
   // lay us out
   nsresult rv = nsBoxFrame::DoXULLayout(aState);
 
   nsMenuPopupFrame* popupFrame = GetPopup();
   if (popupFrame) {
     bool sizeToPopup = IsSizedToPopup(mContent, false);
-    popupFrame->LayoutPopup(aState, this, GetAnchor()->GetPrimaryFrame(),
-                            sizeToPopup);
+    popupFrame->LayoutPopup(aState, this, sizeToPopup);
   }
 
   return rv;
 }
 
 //
 // Enter
 //
--- a/layout/xul/nsMenuFrame.h
+++ b/layout/xul/nsMenuFrame.h
@@ -118,22 +118,16 @@ class nsMenuFrame final : public nsBoxFr
   virtual void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
                             nsFrameList& aFrameList) override;
   virtual void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
 
   NS_IMETHOD SelectMenu(bool aActivateFlag);
 
   virtual nsIScrollableFrame* GetScrollTargetFrame() override;
 
-  // Retrieve the element that the menu should be anchored to. By default this
-  // is the menu itself. However, the anchor attribute may refer to the value of
-  // an anonid within the menu's binding, or, if not found, the id of an element
-  // in the document.
-  nsIContent* GetAnchor();
-
   /**
    * NOTE: OpenMenu will open the menu asynchronously.
    */
   void OpenMenu(bool aSelectFirstItem);
   // CloseMenu closes the menu asynchronously
   void CloseMenu(bool aDeselectMenu);
 
   bool IsChecked() { return mChecked; }
--- a/layout/xul/nsMenuPopupFrame.cpp
+++ b/layout/xul/nsMenuPopupFrame.cpp
@@ -456,18 +456,17 @@ bool nsMenuPopupFrame::IsLeafDynamic() c
 void nsMenuPopupFrame::UpdateWidgetProperties() {
   if (nsIWidget* widget = GetWidget()) {
     widget->SetWindowOpacity(StyleUIReset()->mWindowOpacity);
     widget->SetWindowTransform(ComputeWidgetTransform());
   }
 }
 
 void nsMenuPopupFrame::LayoutPopup(nsBoxLayoutState& aState,
-                                   nsIFrame* aParentMenu, nsIFrame* aAnchor,
-                                   bool aSizedToPopup) {
+                                   nsIFrame* aParentMenu, bool aSizedToPopup) {
   if (IsLeaf()) {
     return;
   }
 
   SchedulePaint();
 
   bool shouldPosition = true;
   bool isOpen = IsOpen();
@@ -512,17 +511,17 @@ void nsMenuPopupFrame::LayoutPopup(nsBox
   bool sizeChanged = (mPrefSize != prefSize);
   if (sizeChanged) {
     SetXULBounds(aState, nsRect(0, 0, prefSize.width, prefSize.height), false);
     mPrefSize = prefSize;
   }
 
   bool needCallback = false;
   if (shouldPosition) {
-    SetPopupPosition(aAnchor, false, aSizedToPopup,
+    SetPopupPosition(aParentMenu, false, aSizedToPopup,
                      mPopupState == ePopupPositioning);
     needCallback = true;
   }
 
   nsRect bounds(GetRect());
   XULLayout(aState);
 
   // if the width or height changed, readjust the popup position. This is a
@@ -539,17 +538,17 @@ void nsMenuPopupFrame::LayoutPopup(nsBox
       if (isOpen) {
         rePosition = true;
         needCallback = true;
       }
     }
   }
 
   if (rePosition) {
-    SetPopupPosition(aAnchor, false, aSizedToPopup, false);
+    SetPopupPosition(aParentMenu, false, aSizedToPopup, false);
   }
 
   nsPresContext* pc = PresContext();
   nsView* view = GetView();
 
   if (sizeChanged) {
     // If the size of the popup changed, apply any size constraints.
     nsIWidget* widget = view->GetWidget();
@@ -599,17 +598,17 @@ void nsMenuPopupFrame::LayoutPopup(nsBox
 
     // If there are no transitions, fire the popupshown event right away.
     nsCOMPtr<nsIRunnable> event = new nsXULPopupShownEvent(GetContent(), pc);
     mContent->OwnerDoc()->Dispatch(TaskCategory::Other, event.forget());
   }
 
   if (needCallback && !mReflowCallbackData.mPosted) {
     pc->PresShell()->PostReflowCallback(this);
-    mReflowCallbackData.MarkPosted(aAnchor, aSizedToPopup, openChanged);
+    mReflowCallbackData.MarkPosted(aParentMenu, aSizedToPopup, openChanged);
   }
 }
 
 bool nsMenuPopupFrame::ReflowFinished() {
   SetPopupPosition(mReflowCallbackData.mAnchor, false,
                    mReflowCallbackData.mSizedToPopup, true);
 
   mReflowCallbackData.Clear();
--- a/layout/xul/nsMenuPopupFrame.h
+++ b/layout/xul/nsMenuPopupFrame.h
@@ -252,17 +252,17 @@ class nsMenuPopupFrame final : public ns
 
   virtual bool IsLeafDynamic() const override;
 
   virtual void UpdateWidgetProperties() override;
 
   // layout, position and display the popup as needed
   MOZ_CAN_RUN_SCRIPT_BOUNDARY
   void LayoutPopup(nsBoxLayoutState& aState, nsIFrame* aParentMenu,
-                   nsIFrame* aAnchor, bool aSizedToPopup);
+                   bool aSizedToPopup);
 
   nsView* GetRootViewForPopup(nsIFrame* aStartFrame);
 
   // Set the position of the popup either relative to the anchor aAnchorFrame
   // (or the frame for mAnchorContent if aAnchorFrame is null), anchored at a
   // rectangle, or at a specific point if a screen position is set. The popup
   // will be adjusted so that it is on screen. If aIsMove is true, then the
   // popup is being moved, and should not be flipped. If aNotify is true, then
--- a/layout/xul/nsPopupSetFrame.cpp
+++ b/layout/xul/nsPopupSetFrame.cpp
@@ -104,17 +104,17 @@ void nsPopupSetFrame::DestroyFrom(nsIFra
 NS_IMETHODIMP
 nsPopupSetFrame::DoXULLayout(nsBoxLayoutState& aState) {
   // lay us out
   nsresult rv = nsBoxFrame::DoXULLayout(aState);
 
   // lay out all of our currently open popups.
   for (nsFrameList::Enumerator e(mPopupList); !e.AtEnd(); e.Next()) {
     nsMenuPopupFrame* popupChild = static_cast<nsMenuPopupFrame*>(e.get());
-    popupChild->LayoutPopup(aState, nullptr, nullptr, false);
+    popupChild->LayoutPopup(aState, nullptr, false);
   }
 
   return rv;
 }
 
 void nsPopupSetFrame::RemovePopupFrame(nsIFrame* aPopup) {
   MOZ_ASSERT((aPopup->GetStateBits() & NS_FRAME_OUT_OF_FLOW) &&
                  aPopup->IsMenuPopupFrame(),
--- a/layout/xul/nsXULPopupManager.cpp
+++ b/layout/xul/nsXULPopupManager.cpp
@@ -677,17 +677,17 @@ void nsXULPopupManager::ShowMenu(nsICont
 
       if (onMenuBar || !onmenu)
     position.AssignLiteral("after_start");
   else
     position.AssignLiteral("end_before");
 
   // there is no trigger event for menus
   InitTriggerEvent(nullptr, nullptr, nullptr);
-  popupFrame->InitializePopup(menuFrame->GetAnchor(), nullptr, position, 0, 0,
+  popupFrame->InitializePopup(aMenu, nullptr, position, 0, 0,
                               MenuPopupAnchorType_Node, true);
 
   if (aAsynchronous) {
     nsCOMPtr<nsIRunnable> event = new nsXULPopupShowingEvent(
         popupFrame->GetContent(), parentIsContextMenu, aSelectFirstItem);
     aMenu->OwnerDoc()->Dispatch(TaskCategory::Other, event.forget());
   } else {
     nsCOMPtr<nsIContent> popupContent = popupFrame->GetContent();
--- a/toolkit/content/tests/chrome/chrome.ini
+++ b/toolkit/content/tests/chrome/chrome.ini
@@ -122,17 +122,16 @@ tags = clipboard
 [test_labelcontrol.xul]
 [test_largemenu.html]
 skip-if = os == 'linux' && !debug # Bug 1207174
 [test_maximized_persist.xul]
 support-files = window_maximized_persist.xul
 [test_navigate_persist.html]
 support-files = window_navigate_persist.html
 [test_menu.xul]
-[test_menu_anchored.xul]
 [test_menu_withcapture.xul]
 [test_menu_hide.xul]
 [test_menuchecks.xul]
 [test_menuitem_blink.xul]
 [test_menuitem_commands.xul]
 [test_menulist.xul]
 [test_menulist_keynav.xul]
 [test_menulist_null_value.xul]
deleted file mode 100644
--- a/toolkit/content/tests/chrome/test_menu_anchored.xul
+++ /dev/null
@@ -1,77 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
-<!--
-  Test for menus with the anchor attribute set
-  -->
-<window title="Anchored Menus Test"
-        align="start"
-        onload="setTimeout(runTest, 0, 'tb1');"
-        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
-  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
-  <script type="application/javascript" src="xul_selectcontrol.js"/>
-
-<hbox>
-
-<toolbarbutton id="tb1" type="menu" label="Open" anchor="dropmarker">
-  <menupopup id="popup1"
-             onpopupshown="checkPopup(this, document.getAnonymousElementByAttribute(this.parentNode, 'anonid', 'dropmarker'))"
-             onpopuphidden="runTest('tb2')">
-    <menuitem label="Item"/>
-  </menupopup>
-</toolbarbutton>
-
-<toolbarbutton id="tb2" type="menu" label="Open" anchor="someanchor">
-  <menupopup id="popup2" onpopupshown="checkPopup(this, $('someanchor'))" onpopuphidden="runTest('tb3')">
-    <menuitem label="Item"/>
-  </menupopup>
-</toolbarbutton>
-
-<toolbarbutton id="tb3" type="menu" label="Open" anchor="noexist">
-  <menupopup id="popup3" onpopupshown="checkPopup(this, this.parentNode)" onpopuphidden="SimpleTest.finish()">
-    <menuitem label="Item"/>
-  </menupopup>
-</toolbarbutton>
-
-</hbox>
-
-<hbox pack="end" width="180">
-  <button id="someanchor" label="Anchor"/>
-</hbox>
-
-<!-- test results are displayed in the html:body -->
-<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
-
-<script type="application/javascript"><![CDATA[
-
-function runTest(menuid)
-{
-  let menu = $(menuid);
-  let dropmarker = document.getAnonymousElementByAttribute(menu, "anonid", "dropmarker");
-
-  synthesizeMouseAtCenter(dropmarker, { });
-}
-
-function isWithinHalfPixel(a, b)
-{
-  return Math.abs(a - b) <= 0.5;
-}
-
-function checkPopup(popup, anchor)
-{
-  let popupRect = popup.getBoundingClientRect();
-  let anchorRect = anchor.getBoundingClientRect();
-
-  ok(isWithinHalfPixel(popupRect.left, anchorRect.left), popup.id + " left");
-  ok(isWithinHalfPixel(popupRect.top, anchorRect.bottom), popup.id + " top");
-
-  popup.hidePopup();
-}
-
-SimpleTest.waitForExplicitFinish();
-
-]]>
-</script>
-
-</window>