Bug 1383009 - add flexible spacers and library button to the navbar by default, r?jaws
Because we generate IDs for special nodes, we should update the inDefaultState getter to actually consider
these nodes to match even when the ids differ. This wasn't an issue before because specials weren't in the
default set for any nodes.
MozReview-Commit-ID: AI85yt2LuJD
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -921,128 +921,41 @@
<toolbaritem id="search-container" title="&searchItem.title;"
align="center" class="chromeclass-toolbar-additional panel-wide-item"
cui-areatype="toolbar"
flex="100" persist="width" removable="true">
<searchbar id="searchbar" flex="1"/>
</toolbaritem>
- <toolbarbutton id="bookmarks-menu-button"
- class="toolbarbutton-1 chromeclass-toolbar-additional"
- removable="true"
- type="menu"
- label="&bookmarksMenuButton.label;"
- tooltip="dynamic-shortcut-tooltip"
- anchor="dropmarker"
- ondragenter="PlacesMenuDNDHandler.onDragEnter(event);"
- ondragover="PlacesMenuDNDHandler.onDragOver(event);"
- ondragleave="PlacesMenuDNDHandler.onDragLeave(event);"
- ondrop="PlacesMenuDNDHandler.onDrop(event);"
- cui-areatype="toolbar"
- oncommand="BookmarkingUI.onCommand(event);">
- <observes element="bookmarkThisPageBroadcaster" attribute="starred"/>
- <observes element="bookmarkThisPageBroadcaster" attribute="buttontooltiptext"/>
- <menupopup id="BMB_bookmarksPopup"
- class="cui-widget-panel cui-widget-panelview cui-widget-panelWithFooter PanelUI-subView"
- placespopup="true"
- context="placesContext"
- openInTabs="children"
- oncommand="BookmarksEventHandler.onCommand(event);"
- onclick="BookmarksEventHandler.onClick(event, this.parentNode._placesView);"
- onpopupshowing="BookmarkingUI.onPopupShowing(event);
- BookmarkingUI.attachPlacesView(event, this);"
- tooltip="bhTooltip" popupsinherittooltip="true">
- <menuitem id="BMB_viewBookmarksSidebar"
- class="subviewbutton"
- label="&viewBookmarksSidebar2.label;"
- type="checkbox"
- oncommand="SidebarUI.toggle('viewBookmarksSidebar');">
- <observes element="viewBookmarksSidebar" attribute="checked"/>
- </menuitem>
- <!-- NB: temporary solution for bug 985024, this should go away soon. -->
- <menuitem id="BMB_bookmarksShowAllTop"
- class="menuitem-iconic subviewbutton"
- label="&showAllBookmarks2.label;"
- command="Browser:ShowAllBookmarks"
- key="manBookmarkKb"/>
- <menuseparator/>
- <menuitem label="&recentBookmarks.label;"
- id="BMB_recentBookmarks"
- disabled="true"
- class="menuitem-iconic subviewbutton"/>
- <menuseparator/>
- <menu id="BMB_bookmarksToolbar"
- class="menu-iconic bookmark-item subviewbutton"
- label="&personalbarCmd.label;"
- container="true">
- <menupopup id="BMB_bookmarksToolbarPopup"
- placespopup="true"
- context="placesContext"
- onpopupshowing="if (!this.parentNode._placesView)
- new PlacesMenu(event, 'place:folder=TOOLBAR',
- PlacesUIUtils.getViewForNode(this.parentNode.parentNode).options);">
- <menuitem id="BMB_viewBookmarksToolbar"
- placesanonid="view-toolbar"
- toolbarId="PersonalToolbar"
- type="checkbox"
- oncommand="onViewToolbarCommand(event)"
- label="&viewBookmarksToolbar.label;"/>
- <menuseparator/>
- <!-- Bookmarks toolbar items -->
- </menupopup>
- </menu>
- <menu id="BMB_unsortedBookmarks"
- class="menu-iconic bookmark-item subviewbutton"
- label="&bookmarksMenuButton.other.label;"
- container="true">
- <menupopup id="BMB_unsortedBookmarksPopup"
- placespopup="true"
- context="placesContext"
- onpopupshowing="if (!this.parentNode._placesView)
- new PlacesMenu(event, 'place:folder=UNFILED_BOOKMARKS',
- PlacesUIUtils.getViewForNode(this.parentNode.parentNode).options);"/>
- </menu>
- <menu id="BMB_mobileBookmarks"
- class="menu-iconic bookmark-item subviewbutton"
- label="&bookmarksMenuButton.mobile.label;"
- hidden="true"
- container="true">
- <menupopup id="BMB_mobileBookmarksPopup"
- placespopup="true"
- context="placesContext"
- onpopupshowing="if (!this.parentNode._placesView)
- new PlacesMenu(event, 'place:folder=MOBILE_BOOKMARKS',
- PlacesUIUtils.getViewForNode(this.parentNode.parentNode).options);"/>
- </menu>
-
- <menuseparator/>
- <!-- Bookmarks menu items will go here -->
- <menuitem id="BMB_bookmarksShowAll"
- class="subviewbutton panel-subview-footer"
- label="&showAllBookmarks2.label;"
- command="Browser:ShowAllBookmarks"
- key="manBookmarkKb"/>
- </menupopup>
- </toolbarbutton>
-
<!-- This is a placeholder for the Downloads Indicator. It is visible
during the customization of the toolbar, in the palette, and before
the Downloads Indicator overlay is loaded. -->
<toolbarbutton id="downloads-button"
class="toolbarbutton-1 chromeclass-toolbar-additional badged-button"
key="key_openDownloads"
oncommand="DownloadsIndicatorView.onCommand(event);"
ondrop="DownloadsIndicatorView.onDrop(event);"
ondragover="DownloadsIndicatorView.onDragOver(event);"
ondragenter="DownloadsIndicatorView.onDragOver(event);"
label="&downloads.label;"
removable="true"
cui-areatype="toolbar"
tooltip="dynamic-shortcut-tooltip"/>
+
+ <toolbarbutton id="library-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
+ removable="true"
+ oncommand="PanelUI.showSubView('appMenu-libraryView', this, null, event);"
+ closemenu="none"
+ label="&places.library.title;">
+ <box class="toolbarbutton-animatable-box">
+ <image class="toolbarbutton-animatable-image"/>
+ </box>
+ </toolbarbutton>
+
</hbox>
<toolbarbutton id="nav-bar-overflow-button"
class="toolbarbutton-1 chromeclass-toolbar-additional overflow-button"
skipintoolbarset="true"
tooltiptext="&navbarOverflow.label;">
<box class="toolbarbutton-animatable-box">
<image class="toolbarbutton-animatable-image"/>
@@ -1162,23 +1075,112 @@
ondragexit="newWindowButtonObserver.onDragExit(event)"/>
<toolbarbutton id="fullscreen-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
observes="View:FullScreen"
type="checkbox"
label="&fullScreenCmd.label;"
tooltip="dynamic-shortcut-tooltip"/>
- <toolbarbutton id="library-button" class="toolbarbutton-1 chromeclass-toolbar-additional"
- oncommand="PanelUI.showSubView('appMenu-libraryView', this, null, event);"
- closemenu="none"
- label="&places.library.title;">
- <box class="toolbarbutton-animatable-box">
- <image class="toolbarbutton-animatable-image"/>
- </box>
+ <toolbarbutton id="bookmarks-menu-button"
+ class="toolbarbutton-1 chromeclass-toolbar-additional"
+ removable="true"
+ type="menu"
+ label="&bookmarksMenuButton.label;"
+ tooltip="dynamic-shortcut-tooltip"
+ anchor="dropmarker"
+ ondragenter="PlacesMenuDNDHandler.onDragEnter(event);"
+ ondragover="PlacesMenuDNDHandler.onDragOver(event);"
+ ondragleave="PlacesMenuDNDHandler.onDragLeave(event);"
+ ondrop="PlacesMenuDNDHandler.onDrop(event);"
+ cui-areatype="toolbar"
+ oncommand="BookmarkingUI.onCommand(event);">
+ <observes element="bookmarkThisPageBroadcaster" attribute="starred"/>
+ <observes element="bookmarkThisPageBroadcaster" attribute="buttontooltiptext"/>
+ <menupopup id="BMB_bookmarksPopup"
+ class="cui-widget-panel cui-widget-panelview cui-widget-panelWithFooter PanelUI-subView"
+ placespopup="true"
+ context="placesContext"
+ openInTabs="children"
+ oncommand="BookmarksEventHandler.onCommand(event);"
+ onclick="BookmarksEventHandler.onClick(event, this.parentNode._placesView);"
+ onpopupshowing="BookmarkingUI.onPopupShowing(event);
+ BookmarkingUI.attachPlacesView(event, this);"
+ tooltip="bhTooltip" popupsinherittooltip="true">
+ <menuitem id="BMB_viewBookmarksSidebar"
+ class="subviewbutton"
+ label="&viewBookmarksSidebar2.label;"
+ type="checkbox"
+ oncommand="SidebarUI.toggle('viewBookmarksSidebar');">
+ <observes element="viewBookmarksSidebar" attribute="checked"/>
+ </menuitem>
+ <!-- NB: temporary solution for bug 985024, this should go away soon. -->
+ <menuitem id="BMB_bookmarksShowAllTop"
+ class="menuitem-iconic subviewbutton"
+ label="&showAllBookmarks2.label;"
+ command="Browser:ShowAllBookmarks"
+ key="manBookmarkKb"/>
+ <menuseparator/>
+ <menuitem label="&recentBookmarks.label;"
+ id="BMB_recentBookmarks"
+ disabled="true"
+ class="menuitem-iconic subviewbutton"/>
+ <menuseparator/>
+ <menu id="BMB_bookmarksToolbar"
+ class="menu-iconic bookmark-item subviewbutton"
+ label="&personalbarCmd.label;"
+ container="true">
+ <menupopup id="BMB_bookmarksToolbarPopup"
+ placespopup="true"
+ context="placesContext"
+ onpopupshowing="if (!this.parentNode._placesView)
+ new PlacesMenu(event, 'place:folder=TOOLBAR',
+ PlacesUIUtils.getViewForNode(this.parentNode.parentNode).options);">
+ <menuitem id="BMB_viewBookmarksToolbar"
+ placesanonid="view-toolbar"
+ toolbarId="PersonalToolbar"
+ type="checkbox"
+ oncommand="onViewToolbarCommand(event)"
+ label="&viewBookmarksToolbar.label;"/>
+ <menuseparator/>
+ <!-- Bookmarks toolbar items -->
+ </menupopup>
+ </menu>
+ <menu id="BMB_unsortedBookmarks"
+ class="menu-iconic bookmark-item subviewbutton"
+ label="&bookmarksMenuButton.other.label;"
+ container="true">
+ <menupopup id="BMB_unsortedBookmarksPopup"
+ placespopup="true"
+ context="placesContext"
+ onpopupshowing="if (!this.parentNode._placesView)
+ new PlacesMenu(event, 'place:folder=UNFILED_BOOKMARKS',
+ PlacesUIUtils.getViewForNode(this.parentNode.parentNode).options);"/>
+ </menu>
+ <menu id="BMB_mobileBookmarks"
+ class="menu-iconic bookmark-item subviewbutton"
+ label="&bookmarksMenuButton.mobile.label;"
+ hidden="true"
+ container="true">
+ <menupopup id="BMB_mobileBookmarksPopup"
+ placespopup="true"
+ context="placesContext"
+ onpopupshowing="if (!this.parentNode._placesView)
+ new PlacesMenu(event, 'place:folder=MOBILE_BOOKMARKS',
+ PlacesUIUtils.getViewForNode(this.parentNode.parentNode).options);"/>
+ </menu>
+
+ <menuseparator/>
+ <!-- Bookmarks menu items will go here -->
+ <menuitem id="BMB_bookmarksShowAll"
+ class="subviewbutton panel-subview-footer"
+ label="&showAllBookmarks2.label;"
+ command="Browser:ShowAllBookmarks"
+ key="manBookmarkKb"/>
+ </menupopup>
</toolbarbutton>
</toolbarpalette>
</toolbox>
<hbox id="fullscr-toggler" hidden="true"/>
<deck id="content-deck" flex="1">
<hbox flex="1" id="browser">
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -54,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 = 8;
+var kVersion = 9;
/**
* 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
@@ -189,32 +189,34 @@ var CustomizableUIInternal = {
anchor: "nav-bar-overflow-button",
}, true);
let navbarPlacements = [
"back-button",
"forward-button",
"stop-reload-button",
"home-button",
+ "spring",
"urlbar-container",
"search-container",
- "bookmarks-menu-button",
+ "spring",
"downloads-button",
+ "library-button",
"sidebar-button",
];
if (AppConstants.MOZ_DEV_EDITION) {
navbarPlacements.splice(2, 0, "developer-button");
}
// Place this last, when createWidget is called for pocket, it will
// append to the toolbar.
- if (Services.prefs.getPrefType("extensions.pocket.enabled") != Services.prefs.PREF_INVALID &&
- Services.prefs.getBoolPref("extensions.pocket.enabled")) {
- navbarPlacements.push("pocket-button");
+ if (Services.prefs.getBoolPref("extensions.pocket.enabled", false) &&
+ Services.prefs.getBoolPref("extensions.pocket.disablePageAction", false)) {
+ navbarPlacements.push("pocket-button");
}
this.registerArea(CustomizableUI.AREA_NAVBAR, {
legacy: true,
type: CustomizableUI.TYPE_TOOLBAR,
overflowable: true,
defaultPlacements: navbarPlacements,
defaultCollapsed: false,
@@ -388,16 +390,50 @@ var CustomizableUIInternal = {
defaultPlacements.push("webcompat-reporter-button");
}
}
savedPanelPlacements = savedPanelPlacements.filter(id => defaultPlacements.includes(id));
if (savedPanelPlacements.length) {
gSavedState.placements[this.AREA_FIXED_OVERFLOW_PANEL] = savedPanelPlacements;
}
}
+
+ if (currentVersion < 9 && gSavedState.placements && gSavedState.placements["nav-bar"]) {
+ let placements = gSavedState.placements["nav-bar"];
+ if (placements.includes("urlbar-container")) {
+ let urlbarIndex = placements.indexOf("urlbar-container");
+ let secondSpringIndex = urlbarIndex + 1;
+ // Insert if there isn't already a spring before the urlbar
+ if (urlbarIndex == 0 || !placements[urlbarIndex - 1].startsWith(kSpecialWidgetPfx + "spring")) {
+ placements.splice(urlbarIndex, 0, "spring");
+ // The url bar is now 1 index later, so increment the insertion point for
+ // the second spring.
+ secondSpringIndex++;
+ }
+ // If the search container is present, insert after the search container
+ // instead of after the url bar
+ let searchContainerIndex = placements.indexOf("search-container");
+ if (searchContainerIndex != -1) {
+ secondSpringIndex = searchContainerIndex + 1;
+ }
+ if (secondSpringIndex == placements.length ||
+ !placements[secondSpringIndex].startsWith(kSpecialWidgetPfx + "spring")) {
+ placements.splice(secondSpringIndex, 0, "spring");
+ }
+ }
+
+ // Finally, replace the bookmarks menu button with the library one if present
+ if (placements.includes("bookmarks-menu-button")) {
+ let bmbIndex = placements.indexOf("bookmarks-menu-button");
+ placements.splice(bmbIndex, 1);
+ let downloadButtonIndex = placements.indexOf("downloads-button");
+ let libraryIndex = downloadButtonIndex == -1 ? bmbIndex : (downloadButtonIndex + 1);
+ placements.splice(libraryIndex, 0, "library-button");
+ }
+ }
},
/**
* _markObsoleteBuiltinButtonsSeen
* when upgrading, ensure obsoleted buttons are in seen state.
*/
_markObsoleteBuiltinButtonsSeen() {
if (!gSavedState)
@@ -712,17 +748,18 @@ var CustomizableUIInternal = {
try {
let currentNode = container.firstChild;
let placementsToRemove = new Set();
for (let id of aPlacements) {
while (currentNode && currentNode.getAttribute("skipintoolbarset") == "true") {
currentNode = currentNode.nextSibling;
}
- if (currentNode && currentNode.id == id) {
+ if (currentNode &&
+ (currentNode.id == id || this.matchingSpecials(id, currentNode.id))) {
currentNode = currentNode.nextSibling;
continue;
}
if (this.isSpecialWidget(id) && areaIsPanel) {
placementsToRemove.add(id);
continue;
}
@@ -1231,16 +1268,22 @@ var CustomizableUIInternal = {
isSpecialWidget(aId) {
return (aId.startsWith(kSpecialWidgetPfx) ||
aId.startsWith("separator") ||
aId.startsWith("spring") ||
aId.startsWith("spacer"));
},
+ matchingSpecials(aId1, aId2) {
+ return this.isSpecialWidget(aId1) &&
+ this.isSpecialWidget(aId2) &&
+ aId1.match(/spring|spacer|separator/)[0] == aId2.match(/spring|spacer|separator/)[0];
+ },
+
ensureSpecialWidgetId(aId) {
let nodeType = aId.match(/spring|spacer|separator/)[0];
// If the ID we were passed isn't a generated one, generate one now:
if (nodeType == aId) {
// Ids are differentiated through a unique count suffix.
return kSpecialWidgetPfx + aId + (++gNewElementCount);
}
return aId;
@@ -2803,17 +2846,18 @@ var CustomizableUIInternal = {
log.debug("Checking default state for " + areaId + ":\n" + currentPlacements.join(",") +
"\nvs.\n" + defaultPlacements.join(","));
if (currentPlacements.length != defaultPlacements.length) {
return false;
}
for (let i = 0; i < currentPlacements.length; ++i) {
- if (currentPlacements[i] != defaultPlacements[i]) {
+ if (currentPlacements[i] != defaultPlacements[i] &&
+ !this.matchingSpecials(currentPlacements[i], defaultPlacements[i])) {
log.debug("Found " + currentPlacements[i] + " in " + areaId + " where " +
defaultPlacements[i] + " was expected!");
return false;
}
}
}
if (Services.prefs.prefHasUserValue(kPrefUIDensity)) {
--- a/browser/components/customizableui/test/browser_1003588_no_specials_in_panel.js
+++ b/browser/components/customizableui/test/browser_1003588_no_specials_in_panel.js
@@ -56,17 +56,17 @@ add_task(async function checkAddingToToo
let oldNumberOfItems = previousPlacements.length;
if (getAreaWidgetIds(area).length != oldNumberOfItems) {
CustomizableUI.reset();
}
});
add_task(async function checkDragging() {
- let startArea = CustomizableUI.AREA_NAVBAR;
+ let startArea = CustomizableUI.AREA_TABSTRIP;
let targetArea = CustomizableUI.AREA_FIXED_OVERFLOW_PANEL;
let startingToolbarPlacements = getAreaWidgetIds(startArea);
let startingTargetPlacements = getAreaWidgetIds(targetArea);
CustomizableUI.addWidgetToArea("separator", startArea);
CustomizableUI.addWidgetToArea("spring", startArea);
CustomizableUI.addWidgetToArea("spacer", startArea);
--- a/browser/components/customizableui/test/browser_984455_bookmarks_items_reparenting.js
+++ b/browser/components/customizableui/test/browser_984455_bookmarks_items_reparenting.js
@@ -184,18 +184,20 @@ function checkNotOverflowing(aID) {
"Item with ID " + aID + " should not have overflowedItem attribute");
}
/**
* Test that overflowing the bookmarks menu button doesn't break the
* context menus for the Unsorted and Bookmarks Toolbar menu items.
*/
add_task(async function testOverflowingBookmarksButtonContextMenu() {
+ ok(CustomizableUI.inDefaultState, "Should start in default state.");
+ CustomizableUI.removeWidgetFromArea("library-button", CustomizableUI.AREA_NAVBAR);
+ CustomizableUI.addWidgetToArea(kBookmarksButton, CustomizableUI.AREA_NAVBAR);
ok(!gNavBar.hasAttribute("overflowing"), "Should start with a non-overflowing toolbar.");
- ok(CustomizableUI.inDefaultState, "Should start in default state.");
// Open the Unsorted and Bookmarks Toolbar context menus and ensure
// that they have views attached.
await checkSpecialContextMenus();
await overflowEverything();
checkOverflowing(kBookmarksButton);
--- a/browser/components/places/tests/browser/browser_toolbarbutton_menu_context.js
+++ b/browser/components/places/tests/browser/browser_toolbarbutton_menu_context.js
@@ -1,24 +1,26 @@
+CustomizableUI.addWidgetToArea("bookmarks-menu-button", CustomizableUI.AREA_NAVBAR, 4);
var bookmarksMenuButton = document.getElementById("bookmarks-menu-button");
var BMB_menuPopup = document.getElementById("BMB_bookmarksPopup");
var BMB_showAllBookmarks = document.getElementById("BMB_bookmarksShowAll");
var contextMenu = document.getElementById("placesContext");
var newBookmarkItem = document.getElementById("placesContext_new:bookmark");
waitForExplicitFinish();
add_task(async function testPopup() {
info("Checking popup context menu before moving the bookmarks button");
await checkPopupContextMenu();
let pos = CustomizableUI.getPlacementOfWidget("bookmarks-menu-button").position;
let target = CustomizableUI.AREA_FIXED_OVERFLOW_PANEL;
CustomizableUI.addWidgetToArea("bookmarks-menu-button", target);
CustomizableUI.addWidgetToArea("bookmarks-menu-button", CustomizableUI.AREA_NAVBAR, pos);
info("Checking popup context menu after moving the bookmarks button");
await checkPopupContextMenu();
+ CustomizableUI.reset();
});
async function checkPopupContextMenu() {
let clickTarget = bookmarksMenuButton;
BMB_menuPopup.setAttribute("style", "transition: none;");
let popupShownPromise = onPopupEvent(BMB_menuPopup, "shown");
EventUtils.synthesizeMouseAtCenter(clickTarget, {});
info("Waiting for bookmarks menu to be shown.");