Bug 980155 - [Australis] Initialization of overflowable toolbars breaks when adding them dynamically. r=Gijs r=jaws

This commit is contained in:
Blair McBride 2014-03-07 05:19:00 -05:00
parent f26bcb9aac
commit 5e1e03e41e
5 changed files with 108 additions and 3 deletions

View File

@ -631,6 +631,7 @@
overflowable="true"
overflowbutton="nav-bar-overflow-button"
overflowtarget="widget-overflow-list"
overflowpanel="widget-overflow"
context="toolbar-context-menu">
<hbox id="nav-bar-customization-target" flex="1">

View File

@ -3455,7 +3455,12 @@ function OverflowableToolbar(aToolbarNode) {
this._list.toolbox = this._toolbar.toolbox;
this._list.customizationTarget = this._list;
Services.obs.addObserver(this, "browser-delayed-startup-finished", false);
let window = this._toolbar.ownerDocument.defaultView;
if (window.gBrowserInit.delayedStartupFinished) {
this.init();
} else {
Services.obs.addObserver(this, "browser-delayed-startup-finished", false);
}
}
OverflowableToolbar.prototype = {
@ -3481,7 +3486,8 @@ OverflowableToolbar.prototype = {
this._chevron = doc.getElementById(chevronId);
this._chevron.addEventListener("command", this);
this._panel = doc.getElementById("widget-overflow");
let panelId = this._toolbar.getAttribute("overflowpanel");
this._panel = doc.getElementById(panelId);
this._panel.addEventListener("popuphiding", this);
CustomizableUIInternal.addPanelCloseListeners(this._panel);

View File

@ -74,5 +74,6 @@ skip-if = os == "linux"
[browser_973932_addonbar_currentset.js]
[browser_975719_customtoolbars_behaviour.js]
[browser_978084_dragEnd_after_move.js]
[browser_980155_add_overflow_toolbar.js]
[browser_981418-widget-onbeforecreated-handler.js]
[browser_panel_toggle.js]

View File

@ -0,0 +1,51 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const kToolbarName = "test-new-overflowable-toolbar";
const kTestWidgetPrefix = "test-widget-for-overflowable-toolbar-";
add_task(function addOverflowingToolbar() {
let originalWindowWidth = window.outerWidth;
let widgetIds = [];
for (let i = 0; i < 10; i++) {
let id = kTestWidgetPrefix + i;
widgetIds.push(id);
let spec = {id: id, type: "button", removable: true, label: "test", tooltiptext: "" + i};
CustomizableUI.createWidget(spec);
}
let toolbarNode = createOverflowableToolbarWithPlacements(kToolbarName, widgetIds);
assertAreaPlacements(kToolbarName, widgetIds);
for (let id of widgetIds) {
document.getElementById(id).style.minWidth = "200px";
}
isnot(toolbarNode.overflowable, null, "Toolbar should have overflowable controller");
isnot(toolbarNode.customizationTarget, null, "Toolbar should have customization target");
isnot(toolbarNode.customizationTarget, toolbarNode, "Customization target should not be toolbar node");
let oldChildCount = toolbarNode.customizationTarget.childElementCount;
let overflowableList = document.getElementById(kToolbarName + "-overflow-list");
let oldOverflowCount = overflowableList.childElementCount;
isnot(oldChildCount, 0, "Toolbar should have non-overflowing widgets");
window.resizeTo(400, window.outerHeight);
yield waitForCondition(() => toolbarNode.hasAttribute("overflowing"));
ok(toolbarNode.hasAttribute("overflowing"), "Should have an overflowing toolbar.");
ok(toolbarNode.customizationTarget.childElementCount < oldChildCount, "Should have fewer children.");
ok(overflowableList.childElementCount > oldOverflowCount, "Should have more overflowed widgets.");
window.resizeTo(originalWindowWidth, window.outerHeight);
});
add_task(function asyncCleanup() {
removeCustomToolbars();
yield resetCustomization();
});

View File

@ -45,11 +45,57 @@ function createToolbarWithPlacements(id, placements = []) {
return tb;
}
function createOverflowableToolbarWithPlacements(id, placements) {
gAddedToolbars.add(id);
let tb = document.createElementNS(kNSXUL, "toolbar");
tb.id = id;
tb.setAttribute("customizationtarget", id + "-target");
let customizationtarget = document.createElementNS(kNSXUL, "hbox");
customizationtarget.id = id + "-target";
customizationtarget.setAttribute("flex", "1");
tb.appendChild(customizationtarget);
let overflowPanel = document.createElementNS(kNSXUL, "panel");
overflowPanel.id = id + "-overflow";
document.getElementById("mainPopupSet").appendChild(overflowPanel);
let overflowList = document.createElementNS(kNSXUL, "vbox");
overflowList.id = id + "-overflow-list";
overflowPanel.appendChild(overflowList);
let chevron = document.createElementNS(kNSXUL, "toolbarbutton");
chevron.id = id + "-chevron";
tb.appendChild(chevron);
CustomizableUI.registerArea(id, {
type: CustomizableUI.TYPE_TOOLBAR,
defaultPlacements: placements,
overflowable: true,
});
tb.setAttribute("customizable", "true");
tb.setAttribute("overflowable", "true");
tb.setAttribute("overflowpanel", overflowPanel.id);
tb.setAttribute("overflowtarget", overflowList.id);
tb.setAttribute("overflowbutton", chevron.id);
gNavToolbox.appendChild(tb);
return tb;
}
function removeCustomToolbars() {
CustomizableUI.reset();
for (let toolbarId of gAddedToolbars) {
CustomizableUI.unregisterArea(toolbarId, true);
document.getElementById(toolbarId).remove();
let tb = document.getElementById(toolbarId);
if (tb.hasAttribute("overflowpanel")) {
let panel = document.getElementById(tb.getAttribute("overflowpanel"));
if (panel)
panel.remove();
}
tb.remove();
}
gAddedToolbars.clear();
}