Bug 855683 - We should support insertItem, r=mconley

This commit is contained in:
Gijs Kruitbosch 2013-05-09 13:46:21 +02:00
parent 427e1def36
commit 9a75820e7d
2 changed files with 47 additions and 8 deletions

View File

@ -57,6 +57,35 @@
]]></body>
</method>
<method name="insertItem">
<parameter name="aId"/>
<parameter name="aBeforeElt"/>
<parameter name="aWrapper"/>
<body><![CDATA[
if (aWrapper) {
Cu.reportError("Can't insert " + aId + ": using insertItem " +
"no longer supports wrapper elements.");
return null;
}
// Hack, the customizable UI code makes this be the last position
let pos = null;
if (aBeforeElt) {
let beforeInfo = CustomizableUI.getPlacementOfWidget(aBeforeElt.id);
if (beforeInfo.area != this.id) {
Cu.reportError("Can't insert " + aId + " before " +
aBeforeElt.id + " which isn't in this area (" +
this.id + ").");
return null;
}
pos = beforeInfo.position;
}
CustomizableUI.addWidgetToArea(aId, this.id, pos);
return this.ownerDocument.getElementById(aId);
]]></body>
</method>
<property name="toolbarName"
onget="return this.getAttribute('toolbarname');"
onset="this.setAttribute('toolbarname', val); return val;"/>

View File

@ -610,7 +610,8 @@ let CustomizableUIInternal = {
this.ensureButtonClosesPanel(widgetNode);
}
let nextNode = container.querySelector("#" + nextNodeId);
let nextNode = nextNodeId ? container.querySelector(idToSelector(nextNodeId))
: null;
container.insertBefore(widgetNode, nextNode);
this._addParentFlex(widgetNode);
}
@ -657,13 +658,16 @@ let CustomizableUIInternal = {
for (let areaNode of areaNodes) {
let container = areaNode.customizationTarget;
let widgetNode = container.ownerDocument.getElementById(aWidgetId);
let [provider, widgetNode] = this.getWidgetNode(aWidgetId,
container.ownerDocument,
areaNode.toolbox);
if (!widgetNode) {
ERROR("Widget not found, unable to move");
continue;
}
let nextNode = container.querySelector("#" + nextNodeId);
let nextNode = nextNodeId ? container.querySelector(idToSelector(nextNodeId))
: null;
container.insertBefore(widgetNode, nextNode);
}
},
@ -756,7 +760,7 @@ let CustomizableUIInternal = {
if (aToolbox.palette) {
// Attempt to locate a node with a matching ID within
// the palette.
return aToolbox.palette.querySelector("#" + aId);
return aToolbox.palette.querySelector(idToSelector(aId));
}
return null;
},
@ -990,10 +994,12 @@ let CustomizableUIInternal = {
}
let placements = gPlacements.get(oldPlacement.area);
if (aPosition < 0) {
if (typeof aPosition != "number") {
aPosition = placements.length;
} else if (aPosition < 0) {
aPosition = 0;
} else if (aPosition > placements.length - 1) {
aPosition = placements.length - 1;
} else if (aPosition > placements.length) {
aPosition = placements.length;
}
if (aPosition == oldPlacement.position) {
@ -1736,7 +1742,7 @@ function XULWidgetGroupWrapper(aWidgetId) {
if (!instance) {
// Toolbar palettes aren't part of the document, so elements in there
// won't be found via document.getElementById().
instance = aWindow.gNavToolbox.palette.querySelector("#" + aWidgetId);
instance = aWindow.gNavToolbox.palette.querySelector(idToSelector(aWidgetId));
}
let wrapper = gWrapperCache.get(instance);
@ -1766,5 +1772,9 @@ function XULWidgetSingleWrapper(aWidgetId, aNode) {
Object.freeze(this);
}
// When IDs contain special characters, we need to escape them for use with querySelector:
function idToSelector(aId) {
return "#" + aId.replace(/[ !"'#$%&\(\)*+\-,.\/:;<=>?@\[\\\]^`{|}~]/g, '\\$&');
}
CustomizableUIInternal.initialize();