Bug 1354117 - remove old panel code from CustomizableUI, add migration, r?jaws draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 01 Aug 2017 12:56:48 +0100
changeset 621136 fa270b0a427405582ece7222a4c6873f68d0b77c
parent 621135 e4b19cf307976aa52e2117dedb30f11155dc0719
child 621137 22e7d3f2e658bfa552bdbaa34f691843919592a2
push id72277
push usergijskruitbosch@gmail.com
push dateFri, 04 Aug 2017 12:03:53 +0000
reviewersjaws
bugs1354117
milestone57.0a1
Bug 1354117 - remove old panel code from CustomizableUI, add migration, r?jaws MozReview-Commit-ID: 8kTETHR1P7X
browser/components/customizableui/CustomizableUI.jsm
browser/components/customizableui/content/panelUI.inc.xul
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -26,21 +26,16 @@ XPCOMUtils.defineLazyGetter(this, "gWidg
   return Services.strings.createBundle(kUrl);
 });
 XPCOMUtils.defineLazyModuleGetter(this, "ShortcutUtils",
   "resource://gre/modules/ShortcutUtils.jsm");
 XPCOMUtils.defineLazyServiceGetter(this, "gELS",
   "@mozilla.org/eventlistenerservice;1", "nsIEventListenerService");
 XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
                                   "resource://gre/modules/LightweightThemeManager.jsm");
-XPCOMUtils.defineLazyPreferenceGetter(this, "gPhotonStructure", "browser.photon.structure.enabled", false,
-  (pref, oldValue, newValue) => {
-    CustomizableUIInternal._updateAreasForPhoton();
-    CustomizableUIInternal.notifyListeners("onPhotonChanged");
-  });
 
 const kNSXUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 
 const kSpecialWidgetPfx = "customizableui-special-";
 
 const kPrefCustomizationState        = "browser.uiCustomization.state";
 const kPrefCustomizationAutoAdd      = "browser.uiCustomization.autoAdd";
 const kPrefCustomizationDebug        = "browser.uiCustomization.debug";
@@ -59,17 +54,17 @@ const kSubviewEvents = [
   "ViewShowing",
   "ViewHiding"
 ];
 
 /**
  * The current version. We can use this to auto-add new default widgets as necessary.
  * (would be const but isn't because of testing purposes)
  */
-var kVersion = 7;
+var kVersion = 8;
 
 /**
  * Buttons removed from built-ins by version they were removed. kVersion must be
  * bumped any time a new id is added to this. Use the button id as key, and
  * version the button is removed in as the value.  e.g. "pocket-button": 5
  */
 var ObsoleteBuiltinButtons = {
   "pocket-button": 6
@@ -183,69 +178,21 @@ var CustomizableUIInternal = {
     log.debug("Initializing");
 
     this.addListener(this);
     this._defineBuiltInWidgets();
     this.loadSavedState();
     this._introduceNewBuiltinWidgets();
     this._markObsoleteBuiltinButtonsSeen();
 
-    /**
-     * Please be advised that adding items to the panel by default could
-     * cause CART talos test regressions. This might happen when the
-     * number of items in the panel causes the area to become "scrollable"
-     * during the last phases of the transition. See bug 1230671 for an
-     * example of this. Be sure that what you're adding really needs to go
-     * into the panel by default, and if it does, consider swapping
-     * something out for it.
-     */
-    let panelPlacements = [
-      "edit-controls",
-      "zoom-controls",
-      "new-window-button",
-      "privatebrowsing-button",
-      "save-page-button",
-      "print-button",
-      "history-panelmenu",
-      "fullscreen-button",
-      "find-button",
-      "preferences-button",
-      "add-ons-button",
-      "sync-button",
-    ];
-
-    if (!AppConstants.MOZ_DEV_EDITION) {
-      panelPlacements.splice(-1, 0, "developer-button");
-    }
-
-    if (AppConstants.E10S_TESTING_ONLY) {
-      if (gPalette.has("e10s-button")) {
-        let newWindowIndex = panelPlacements.indexOf("new-window-button");
-        if (newWindowIndex > -1) {
-          panelPlacements.splice(newWindowIndex + 1, 0, "e10s-button");
-        }
-      }
-    }
-
-    let showCharacterEncoding = Services.prefs.getComplexValue(
-      "browser.menu.showCharacterEncoding",
-      Ci.nsIPrefLocalizedString
-    ).data;
-    if (showCharacterEncoding == "true") {
-      panelPlacements.push("characterencoding-button");
-    }
-
-    if (AppConstants.MOZ_DEV_EDITION || AppConstants.NIGHTLY_BUILD) {
-      if (Services.prefs.getBoolPref("extensions.webcompat-reporter.enabled")) {
-        panelPlacements.push("webcompat-reporter-button");
-      }
-    }
-
-    gDefaultPanelPlacements = panelPlacements;
-    this._updateAreasForPhoton();
+    this.registerArea(CustomizableUI.AREA_FIXED_OVERFLOW_PANEL, {
+      type: CustomizableUI.TYPE_MENU_PANEL,
+      defaultPlacements: [],
+      anchor: "nav-bar-overflow-button",
+    }, true);
 
     let navbarPlacements = [
       "back-button",
       "forward-button",
       "stop-reload-button",
       "home-button",
       "urlbar-container",
       "search-container",
@@ -308,55 +255,16 @@ var CustomizableUIInternal = {
       legacy: true,
       defaultPlacements: ["addonbar-closebutton", "status-bar"],
       defaultCollapsed: false,
     }, true);
 
     SearchWidgetTracker.init();
   },
 
-  _updatePanelContextMenuLocation(window) {
-    let panelID = gPhotonStructure ? "widget-overflow" : "PanelUI-popup";
-    let contextMenu = window.document.getElementById("customizationPanelItemContextMenu");
-    window.document.getElementById(panelID).appendChild(contextMenu);
-  },
-
-  _updateAreasForPhoton() {
-    for (let [win, ] of gBuildWindows) {
-      this._updatePanelContextMenuLocation(win);
-    }
-
-    if (gPhotonStructure) {
-      if (gAreas.has(CustomizableUI.AREA_PANEL)) {
-        this.unregisterArea(CustomizableUI.AREA_PANEL, true);
-      }
-      this.registerArea(CustomizableUI.AREA_FIXED_OVERFLOW_PANEL, {
-        type: CustomizableUI.TYPE_MENU_PANEL,
-        defaultPlacements: [],
-        anchor: "nav-bar-overflow-button",
-      }, true);
-    } else {
-      if (gAreas.has(CustomizableUI.AREA_FIXED_OVERFLOW_PANEL)) {
-        this.unregisterArea(CustomizableUI.AREA_FIXED_OVERFLOW_PANEL, true);
-      }
-      // In tests we destroy some widgets. Those should be removed from the
-      // default placements when re-registering the panel.
-      let placementsToUse = Array.from(gDefaultPanelPlacements);
-      if (!gPalette.has("e10s-button") && placementsToUse.includes("e10s-button")) {
-        placementsToUse.splice(placementsToUse.indexOf("e10s-button"), 1);
-      }
-      this.registerArea(CustomizableUI.AREA_PANEL, {
-        anchor: "PanelUI-menu-button",
-        type: CustomizableUI.TYPE_MENU_PANEL,
-        defaultPlacements: placementsToUse,
-      }, true);
-      PanelWideWidgetTracker.init();
-    }
-  },
-
   get _builtinToolbars() {
     let toolbars = new Set([
       CustomizableUI.AREA_NAVBAR,
       CustomizableUI.AREA_BOOKMARKS,
       CustomizableUI.AREA_TABSTRIP,
       CustomizableUI.AREA_ADDONBAR,
     ]);
     if (AppConstants.platform != "macosx") {
@@ -438,16 +346,58 @@ var CustomizableUIInternal = {
 
       if (!newPlacements.includes("sidebar-button")) {
         newPlacements.push("sidebar-button");
       }
 
       gSavedState.placements[CustomizableUI.AREA_NAVBAR] = newPlacements;
     }
 
+    if (currentVersion < 8 && gSavedState.placements &&
+        gSavedState.placements["PanelUI-contents"]) {
+      let savedPanelPlacements = gSavedState.placements["PanelUI-contents"];
+      delete gSavedState.placements["PanelUI-contents"];
+      let defaultPlacements = [
+        "edit-controls",
+        "zoom-controls",
+        "new-window-button",
+        "privatebrowsing-button",
+        "save-page-button",
+        "print-button",
+        "history-panelmenu",
+        "fullscreen-button",
+        "find-button",
+        "preferences-button",
+        "add-ons-button",
+        "sync-button",
+        "e10s-button",
+      ];
+
+      if (!AppConstants.MOZ_DEV_EDITION) {
+        defaultPlacements.splice(-1, 0, "developer-button");
+      }
+
+      let showCharacterEncoding = Services.prefs.getComplexValue(
+        "browser.menu.showCharacterEncoding",
+        Ci.nsIPrefLocalizedString
+      ).data;
+      if (showCharacterEncoding == "true") {
+        defaultPlacements.push("characterencoding-button");
+      }
+
+      if (AppConstants.MOZ_DEV_EDITION || AppConstants.NIGHTLY_BUILD) {
+        if (Services.prefs.getBoolPref("extensions.webcompat-reporter.enabled")) {
+          defaultPlacements.push("webcompat-reporter-button");
+        }
+      }
+      savedPanelPlacements = savedPanelPlacements.filter(id => defaultPlacements.includes(id));
+      if (savedPanelPlacements.length) {
+        gSavedState.placements[this.AREA_FIXED_OVERFLOW_PANEL] = savedPanelPlacements;
+      }
+    }
   },
 
   /**
    * _markObsoleteBuiltinButtonsSeen
    * when upgrading, ensure obsoleted buttons are in seen state.
    */
   _markObsoleteBuiltinButtonsSeen() {
     if (!gSavedState)
@@ -798,23 +748,16 @@ var CustomizableUIInternal = {
           continue;
         } // Special widgets are always removable, so no need to check them
 
         if (inPrivateWindow && widget && !widget.showInPrivateBrowsing) {
           continue;
         }
 
         this.ensureButtonContextMenu(node, aAreaNode);
-        if (node.localName == "toolbarbutton") {
-          if (areaIsPanel && !gPhotonStructure) {
-            node.setAttribute("wrap", "true");
-          } else {
-            node.removeAttribute("wrap");
-          }
-        }
 
         // This needs updating in case we're resetting / undoing a reset.
         if (widget) {
           widget.currentArea = aArea;
         }
         this.insertWidgetBefore(node, currentNode, container, aArea);
         if (gResetting) {
           this.notifyListeners("onWidgetReset", node, container);
@@ -985,19 +928,16 @@ var CustomizableUIInternal = {
     for (let child of aPanelContents.children) {
       if (child.localName != "toolbarbutton") {
         if (child.localName == "toolbaritem") {
           this.ensureButtonContextMenu(child, aPanelContents, true);
         }
         continue;
       }
       this.ensureButtonContextMenu(child, aPanelContents, true);
-      if (!gPhotonStructure) {
-        child.setAttribute("wrap", "true");
-      }
     }
 
     this.registerBuildArea(aArea, aPanelContents);
   },
 
   onWidgetAdded(aWidgetId, aArea, aPosition) {
     this.insertNode(aWidgetId, aArea, aPosition, true);
 
@@ -1039,17 +979,16 @@ var CustomizableUIInternal = {
 
       this.notifyListeners("onWidgetBeforeDOMChange", widgetNode, null, container, true);
 
       // We remove location attributes here to make sure they're gone too when a
       // widget is removed from a toolbar to the palette. See bug 930950.
       this.removeLocationAttributes(widgetNode);
       // We also need to remove the panel context menu if it's there:
       this.ensureButtonContextMenu(widgetNode);
-      widgetNode.removeAttribute("wrap");
       if (gPalette.has(aWidgetId) || this.isSpecialWidget(aWidgetId)) {
         container.removeChild(widgetNode);
       } else {
         areaNode.toolbox.palette.appendChild(widgetNode);
       }
       this.notifyListeners("onWidgetAfterDOMChange", widgetNode, null, container, true);
 
       if (isToolbar) {
@@ -1103,17 +1042,16 @@ var CustomizableUIInternal = {
   },
 
   registerBuildWindow(aWindow) {
     if (!gBuildWindows.has(aWindow)) {
       gBuildWindows.set(aWindow, new Set());
 
       aWindow.addEventListener("unload", this);
       aWindow.addEventListener("command", this, true);
-      this._updatePanelContextMenuLocation(aWindow);
 
       this.notifyListeners("onWindowOpened", aWindow);
     }
   },
 
   unregisterBuildWindow(aWindow) {
     aWindow.removeEventListener("unload", this);
     aWindow.removeEventListener("command", this, true);
@@ -1212,19 +1150,16 @@ var CustomizableUIInternal = {
     if (!widgetNode) {
       log.error("Widget '" + aWidgetId + "' not found, unable to move");
       return;
     }
 
     let areaId = aAreaNode.id;
     if (isNew) {
       this.ensureButtonContextMenu(widgetNode, aAreaNode);
-      if (widgetNode.localName == "toolbarbutton" && areaId == CustomizableUI.AREA_PANEL) {
-        widgetNode.setAttribute("wrap", "true");
-      }
     }
 
     let [insertionContainer, nextNode] = this.findInsertionPoints(widgetNode, aAreaNode);
     this.insertWidgetBefore(widgetNode, nextNode, insertionContainer, areaId);
 
     if (gAreas.get(areaId).get("type") == CustomizableUI.TYPE_TOOLBAR) {
       aAreaNode.setAttribute("currentset", gPlacements.get(areaId).join(","));
     }
@@ -2240,17 +2175,16 @@ var CustomizableUIInternal = {
     }
 
     this.notifyListeners("onWidgetCreated", widget.id);
 
     if (widget.defaultArea) {
       let addToDefaultPlacements = false;
       let area = gAreas.get(widget.defaultArea);
       if (!CustomizableUI.isBuiltinToolbar(widget.defaultArea) &&
-          widget.defaultArea != CustomizableUI.AREA_PANEL &&
           widget.defaultArea != CustomizableUI.AREA_FIXED_OVERFLOW_PANEL) {
         addToDefaultPlacements = true;
       }
 
       if (addToDefaultPlacements) {
         if (area.has("defaultPlacements")) {
           area.get("defaultPlacements").push(widget.id);
         } else {
@@ -2912,16 +2846,17 @@ var CustomizableUIInternal = {
     }
   },
 };
 Object.freeze(CustomizableUIInternal);
 
 this.CustomizableUI = {
   /**
    * Constant reference to the ID of the menu panel.
+   * DEPRECATED.
    */
   AREA_PANEL: "PanelUI-contents",
   /**
    * Constant reference to the ID of the navigation toolbar.
    */
   AREA_NAVBAR: "nav-bar",
   /**
    * Constant reference to the ID of the menubar's toolbar.
@@ -3855,17 +3790,17 @@ this.CustomizableUI = {
    *         palette, undefined otherwise.
    */
   getPlaceForItem(aElement) {
     let place;
     let node = aElement;
     while (node && !place) {
       if (node.localName == "toolbar")
         place = "toolbar";
-      else if (node.id == CustomizableUI.AREA_PANEL || node.id == CustomizableUI.AREA_FIXED_OVERFLOW_PANEL)
+      else if (node.id == CustomizableUI.AREA_FIXED_OVERFLOW_PANEL)
         place = "panel";
       else if (node.id == "customization-palette")
         place = "palette";
 
       node = node.parentNode;
     }
     return place;
   },
@@ -4332,17 +4267,17 @@ OverflowableToolbar.prototype = {
 
     while (child && this._target.scrollLeftMin != this._target.scrollLeftMax) {
       let prevChild = child.previousSibling;
 
       if (child.getAttribute("overflows") != "false") {
         this._collapsed.set(child.id, this._target.clientWidth);
         child.setAttribute("overflowedItem", true);
         child.setAttribute("cui-anchorid", this._chevron.id);
-        CustomizableUIInternal.ensureButtonContextMenu(child, this._toolbar, gPhotonStructure);
+        CustomizableUIInternal.ensureButtonContextMenu(child, this._toolbar, true);
         CustomizableUIInternal.notifyListeners("onWidgetOverflow", child, this._target);
 
         this._list.insertBefore(child, this._list.firstChild);
         if (!this._toolbar.hasAttribute("overflowing")) {
           CustomizableUI.addListener(this);
         }
         this._toolbar.setAttribute("overflowing", "true");
       }
@@ -4473,17 +4408,17 @@ OverflowableToolbar.prototype = {
       if (nowOverflowed) {
         // NB: we're guaranteed that it has a previousSibling, because if it didn't,
         // we would have added it to the toolbar instead. See getOverflowedNextNode.
         let prevId = aNode.previousSibling.id;
         let minSize = this._collapsed.get(prevId);
         this._collapsed.set(aNode.id, minSize);
         aNode.setAttribute("cui-anchorid", this._chevron.id);
         aNode.setAttribute("overflowedItem", true);
-        CustomizableUIInternal.ensureButtonContextMenu(aNode, aContainer, gPhotonStructure);
+        CustomizableUIInternal.ensureButtonContextMenu(aNode, aContainer, true);
         CustomizableUIInternal.notifyListeners("onWidgetOverflow", aNode, this._target);
       } else if (!nowInBar) {
         // If it is not overflowed and not in the toolbar, and was not overflowed
         // either, it moved out of the toolbar. That means there's now space in there!
         // Let's try to move stuff back:
         this._moveItemsBackToTheirOrigin(true);
       }
       // If it's in the toolbar now, then we don't care. An overflow event may
--- a/browser/components/customizableui/content/panelUI.inc.xul
+++ b/browser/components/customizableui/content/panelUI.inc.xul
@@ -396,16 +396,50 @@
         </vbox>
         <button id="PanelUI-panic-view-button"
                 label="&panicButton.view.forgetButton;"/>
       </vbox>
     </panelview>
 
   </panelmultiview>
 
+</panel>
+
+<panel id="widget-overflow"
+       role="group"
+       type="arrow"
+       noautofocus="true"
+       position="bottomcenter topright"
+#ifndef MOZ_PHOTON_THEME
+       context="toolbar-context-menu"
+#endif
+       hidden="true">
+#ifdef MOZ_PHOTON_THEME
+  <photonpanelmultiview mainViewId="widget-overflow-mainView">
+    <panelview id="widget-overflow-mainView"
+               context="toolbar-context-menu">
+#endif
+      <vbox class="panel-subview-body">
+        <vbox id="widget-overflow-scroller">
+          <vbox id="widget-overflow-list" class="widget-overflow-list"
+                overflowfortoolbar="nav-bar"/>
+          <toolbarseparator id="widget-overflow-fixed-separator" hidden="true"/>
+          <vbox id="widget-overflow-fixed-list" class="widget-overflow-list" hidden="true"
+                emptylabel="&customizeMode.emptyOverflowList.description;"/>
+        </vbox>
+      </vbox>
+#ifdef MOZ_PHOTON_THEME
+      <toolbarbutton command="cmd_CustomizeToolbars"
+                      id="overflowMenu-customize-button"
+                      class="subviewbutton panel-subview-footer"
+                      accesskey="&overflowCustomizeToolbar.accesskey;"
+                      label="&overflowCustomizeToolbar.label;"/>
+    </panelview>
+  </photonpanelmultiview>
+#endif
   <!-- This menu is here because not having it in the menu in which it's used flickers
        when hover styles overlap. See https://bugzilla.mozilla.org/show_bug.cgi?id=1378427 .
        -->
   <menupopup id="customizationPanelItemContextMenu"
              onpopupshowing="gCustomizeMode.onPanelContextMenuShowing(event)">
     <menuitem oncommand="gCustomizeMode.addToPanel(document.popupNode)"
               id="customizationPanelItemContextMenuPin"
               photonaccesskey="&customizeMenu.pinToOverflowMenu.accesskey;"
@@ -432,50 +466,16 @@
     <menuseparator/>
     <menuitem command="cmd_CustomizeToolbars"
               class="viewCustomizeToolbar"
               accesskey="&viewCustomizeToolbar.accesskey;"
               label="&viewCustomizeToolbar.label;"/>
   </menupopup>
 </panel>
 
-<panel id="widget-overflow"
-       role="group"
-       type="arrow"
-       noautofocus="true"
-       position="bottomcenter topright"
-#ifndef MOZ_PHOTON_THEME
-       context="toolbar-context-menu"
-#endif
-       hidden="true">
-#ifdef MOZ_PHOTON_THEME
-  <photonpanelmultiview mainViewId="widget-overflow-mainView">
-    <panelview id="widget-overflow-mainView"
-               context="toolbar-context-menu">
-#endif
-      <vbox class="panel-subview-body">
-        <vbox id="widget-overflow-scroller">
-          <vbox id="widget-overflow-list" class="widget-overflow-list"
-                overflowfortoolbar="nav-bar"/>
-          <toolbarseparator id="widget-overflow-fixed-separator" hidden="true"/>
-          <vbox id="widget-overflow-fixed-list" class="widget-overflow-list" hidden="true"
-                emptylabel="&customizeMode.emptyOverflowList.description;"/>
-        </vbox>
-      </vbox>
-#ifdef MOZ_PHOTON_THEME
-      <toolbarbutton command="cmd_CustomizeToolbars"
-                      id="overflowMenu-customize-button"
-                      class="subviewbutton panel-subview-footer"
-                      accesskey="&overflowCustomizeToolbar.accesskey;"
-                      label="&overflowCustomizeToolbar.label;"/>
-    </panelview>
-  </photonpanelmultiview>
-#endif
-</panel>
-
 <panel id="customization-tipPanel"
        type="arrow"
        flip="none"
        side="left"
        position="leftcenter topright"
        noautohide="true"
        hidden="true">
   <hbox class="customization-tipPanel-wrapper">