Bug 982027 - moving item around in Australis' customize mode shouldn't remove custom context menu, r=jaws

--HG--
extra : rebase_source : 5d756bcfe2a7906f15d69405b8b23070ac293ec9
This commit is contained in:
Gijs Kruitbosch 2014-03-11 12:29:25 +00:00
parent 88ad61a22a
commit 82578a68e9
2 changed files with 51 additions and 14 deletions

View File

@ -666,7 +666,7 @@ CustomizeMode.prototype = {
// while still getting rid of the need for overlays.
makePaletteItem: function(aWidget, aPlace) {
let widgetNode = aWidget.forWindow(this.window).node;
let wrapper = this.createWrapper(widgetNode, aPlace);
let wrapper = this.createOrUpdateWrapper(widgetNode, aPlace);
wrapper.appendChild(widgetNode);
return wrapper;
},
@ -728,7 +728,8 @@ CustomizeMode.prototype = {
if (!this.isCustomizableItem(aNode)) {
return aNode;
}
let wrapper = this.createWrapper(aNode, aPlace);
let wrapper = this.createOrUpdateWrapper(aNode, aPlace);
// It's possible that this toolbar node is "mid-flight" and doesn't have
// a parent, in which case we skip replacing it. This can happen if a
// toolbar item has been dragged into the palette. In that case, we tell
@ -741,13 +742,19 @@ CustomizeMode.prototype = {
return wrapper;
},
createWrapper: function(aNode, aPlace) {
let wrapper = this.document.createElement("toolbarpaletteitem");
createOrUpdateWrapper: function(aNode, aPlace, aIsUpdate) {
let wrapper;
if (aIsUpdate && aNode.parentNode && aNode.parentNode.localName == "toolbarpaletteitem") {
wrapper = aNode.parentNode;
aPlace = wrapper.getAttribute("place");
} else {
wrapper = this.document.createElement("toolbarpaletteitem");
// "place" is used by toolkit to add the toolbarpaletteitem-palette
// binding to a toolbarpaletteitem, which gives it a label node for when
// it's sitting in the palette.
wrapper.setAttribute("place", aPlace);
}
// "place" is used by toolkit to add the toolbarpaletteitem-palette
// binding to a toolbarpaletteitem, which gives it a label node for when
// it's sitting in the palette.
wrapper.setAttribute("place", aPlace);
// Ensure the wrapped item doesn't look like it's in any special state, and
// can't be interactved with when in the customization palette.
@ -802,8 +809,11 @@ CustomizeMode.prototype = {
aNode.removeAttribute(contextMenuAttrName);
}
wrapper.addEventListener("mousedown", this);
wrapper.addEventListener("mouseup", this);
// Only add listeners for newly created wrappers:
if (!aIsUpdate) {
wrapper.addEventListener("mousedown", this);
wrapper.addEventListener("mouseup", this);
}
return wrapper;
},
@ -1745,10 +1755,7 @@ CustomizeMode.prototype = {
if (targetArea != currentArea) {
this.unwrapToolbarItem(aDraggedItem.parentNode);
// Put the item back into its previous position.
if (currentSibling)
currentParent.insertBefore(aDraggedItem, currentSibling);
else
currentParent.appendChild(aDraggedItem);
currentParent.insertBefore(aDraggedItem, currentSibling);
// restore the areaType
if (areaType) {
if (currentType === false)
@ -1756,6 +1763,7 @@ CustomizeMode.prototype = {
else
aDraggedItem.setAttribute(kAreaType, currentType);
}
this.createOrUpdateWrapper(aDraggedItem, null, true);
CustomizableUI.onWidgetDrag(aDraggedItem.id);
} else {
aDraggedItem.parentNode.hidden = true;

View File

@ -340,3 +340,32 @@ add_task(function() {
yield hiddenPromise;
});
// Bug 982027 - moving icon around removes custom context menu.
add_task(function() {
let widgetId = "custom-context-menu-toolbarbutton";
let expectedContext = "myfancycontext";
let widget = createDummyXULButton(widgetId, "Test ctxt menu");
widget.setAttribute("context", expectedContext);
CustomizableUI.addWidgetToArea(widgetId, CustomizableUI.AREA_NAVBAR);
is(widget.getAttribute("context"), expectedContext, "Should have context menu when added to the toolbar.");
yield startCustomizing();
is(widget.getAttribute("context"), "", "Should not have own context menu in the toolbar now that we're customizing.");
is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped when in toolbar.");
let panel = PanelUI.contents;
simulateItemDrag(widget, panel);
is(widget.getAttribute("context"), "", "Should not have own context menu when in the panel.");
is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're in the panel.");
simulateItemDrag(widget, document.getElementById("nav-bar").customizationTarget);
is(widget.getAttribute("context"), "", "Should not have own context menu when back in toolbar because we're still customizing.");
is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're back in the toolbar.");
yield endCustomizing();
is(widget.getAttribute("context"), expectedContext, "Should have context menu again now that we're out of customize mode.");
CustomizableUI.removeWidgetFromArea(widgetId);
widget.remove();
ok(CustomizableUI.inDefaultState, "Should be in default state after removing button.");
});