mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-30 13:45:27 +00:00
61572eda35
--HG-- rename : toolkit/mozapps/shared/CertUtils.jsm => toolkit/modules/CertUtils.jsm rename : toolkit/content/DeferredTask.jsm => toolkit/modules/DeferredTask.jsm rename : toolkit/content/Deprecated.jsm => toolkit/modules/Deprecated.jsm rename : toolkit/content/Dict.jsm => toolkit/modules/Dict.jsm rename : toolkit/mozapps/shared/FileUtils.jsm => toolkit/modules/FileUtils.jsm rename : toolkit/content/Geometry.jsm => toolkit/modules/Geometry.jsm rename : toolkit/content/InlineSpellChecker.jsm => toolkit/modules/InlineSpellChecker.jsm rename : toolkit/content/LightweightThemeConsumer.jsm => toolkit/modules/LightweightThemeConsumer.jsm rename : toolkit/content/PageMenu.jsm => toolkit/modules/PageMenu.jsm rename : toolkit/content/PopupNotifications.jsm => toolkit/modules/PopupNotifications.jsm rename : toolkit/content/PrivateBrowsingUtils.jsm => toolkit/modules/PrivateBrowsingUtils.jsm rename : toolkit/content/PropertyListUtils.jsm => toolkit/modules/PropertyListUtils.jsm rename : toolkit/content/Services.jsm => toolkit/modules/Services.jsm rename : toolkit/content/Task.jsm => toolkit/modules/Task.jsm rename : toolkit/content/Troubleshoot.jsm => toolkit/modules/Troubleshoot.jsm rename : toolkit/content/UpdateChannel.jsm => toolkit/modules/UpdateChannel.jsm rename : toolkit/content/WindowDraggingUtils.jsm => toolkit/modules/WindowDraggingUtils.jsm rename : toolkit/content/debug.js => toolkit/modules/debug.js rename : toolkit/content/tests/browser/browser_DeferredTask.js => toolkit/modules/tests/browser/browser_DeferredTask.js rename : toolkit/content/tests/browser/browser_Deprecated.js => toolkit/modules/tests/browser/browser_Deprecated.js rename : toolkit/content/tests/browser/browser_Geometry.js => toolkit/modules/tests/browser/browser_Geometry.js rename : toolkit/content/tests/browser/browser_InlineSpellChecker.js => toolkit/modules/tests/browser/browser_InlineSpellChecker.js rename : toolkit/content/tests/browser/browser_Services.js => toolkit/modules/tests/browser/browser_Services.js rename : toolkit/content/tests/browser/browser_Troubleshoot.js => toolkit/modules/tests/browser/browser_Troubleshoot.js rename : toolkit/mozapps/shared/test/chrome/Makefile.in => toolkit/modules/tests/chrome/Makefile.in rename : toolkit/mozapps/shared/test/chrome/moz.build => toolkit/modules/tests/chrome/moz.build rename : toolkit/mozapps/shared/test/chrome/test_bug544442_checkCert.xul => toolkit/modules/tests/chrome/test_bug544442_checkCert.xul rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListBinary.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListBinary.plist rename : toolkit/content/tests/unit/propertyLists/bug710259_propertyListXML.plist => toolkit/modules/tests/xpcshell/propertyLists/bug710259_propertyListXML.plist rename : toolkit/mozapps/shared/test/unit/test_FileUtils.js => toolkit/modules/tests/xpcshell/test_FileUtils.js rename : toolkit/content/tests/unit/test_dict.js => toolkit/modules/tests/xpcshell/test_dict.js rename : toolkit/content/tests/unit/test_propertyListsUtils.js => toolkit/modules/tests/xpcshell/test_propertyListsUtils.js rename : toolkit/mozapps/shared/test/unit/test_readCertPrefs.js => toolkit/modules/tests/xpcshell/test_readCertPrefs.js rename : toolkit/content/tests/unit/test_task.js => toolkit/modules/tests/xpcshell/test_task.js
140 lines
3.5 KiB
JavaScript
140 lines
3.5 KiB
JavaScript
/* 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/. */
|
|
|
|
this.EXPORTED_SYMBOLS = ["PageMenu"];
|
|
|
|
this.PageMenu = function PageMenu() {
|
|
}
|
|
|
|
PageMenu.prototype = {
|
|
PAGEMENU_ATTR: "pagemenu",
|
|
GENERATEDITEMID_ATTR: "generateditemid",
|
|
|
|
popup: null,
|
|
builder: null,
|
|
|
|
maybeBuildAndAttachMenu: function(aTarget, aPopup) {
|
|
var pageMenu = null;
|
|
var target = aTarget;
|
|
while (target) {
|
|
var contextMenu = target.contextMenu;
|
|
if (contextMenu) {
|
|
pageMenu = contextMenu;
|
|
break;
|
|
}
|
|
target = target.parentNode;
|
|
}
|
|
|
|
if (!pageMenu) {
|
|
return false;
|
|
}
|
|
|
|
var insertionPoint = this.getInsertionPoint(aPopup);
|
|
if (!insertionPoint) {
|
|
return false;
|
|
}
|
|
|
|
pageMenu.QueryInterface(Components.interfaces.nsIHTMLMenu);
|
|
pageMenu.sendShowEvent();
|
|
// the show event is not cancelable, so no need to check a result here
|
|
|
|
var fragment = aPopup.ownerDocument.createDocumentFragment();
|
|
|
|
var builder = pageMenu.createBuilder();
|
|
if (!builder) {
|
|
return false;
|
|
}
|
|
builder.QueryInterface(Components.interfaces.nsIXULContextMenuBuilder);
|
|
builder.init(fragment, this.GENERATEDITEMID_ATTR);
|
|
|
|
pageMenu.build(builder);
|
|
|
|
var pos = insertionPoint.getAttribute(this.PAGEMENU_ATTR);
|
|
if (pos == "start") {
|
|
insertionPoint.insertBefore(fragment,
|
|
insertionPoint.firstChild);
|
|
} else {
|
|
insertionPoint.appendChild(fragment);
|
|
}
|
|
|
|
this.builder = builder;
|
|
this.popup = aPopup;
|
|
|
|
this.popup.addEventListener("command", this);
|
|
this.popup.addEventListener("popuphidden", this);
|
|
|
|
return true;
|
|
},
|
|
|
|
handleEvent: function(event) {
|
|
var type = event.type;
|
|
var target = event.target;
|
|
if (type == "command" && target.hasAttribute(this.GENERATEDITEMID_ATTR)) {
|
|
this.builder.click(target.getAttribute(this.GENERATEDITEMID_ATTR));
|
|
} else if (type == "popuphidden" && this.popup == target) {
|
|
this.removeGeneratedContent(this.popup);
|
|
|
|
this.popup.removeEventListener("popuphidden", this);
|
|
this.popup.removeEventListener("command", this);
|
|
|
|
this.popup = null;
|
|
this.builder = null;
|
|
}
|
|
},
|
|
|
|
getImmediateChild: function(element, tag) {
|
|
var child = element.firstChild;
|
|
while (child) {
|
|
if (child.localName == tag) {
|
|
return child;
|
|
}
|
|
child = child.nextSibling;
|
|
}
|
|
return null;
|
|
},
|
|
|
|
getInsertionPoint: function(aPopup) {
|
|
if (aPopup.hasAttribute(this.PAGEMENU_ATTR))
|
|
return aPopup;
|
|
|
|
var element = aPopup.firstChild;
|
|
while (element) {
|
|
if (element.localName == "menu") {
|
|
var popup = this.getImmediateChild(element, "menupopup");
|
|
if (popup) {
|
|
var result = this.getInsertionPoint(popup);
|
|
if (result) {
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
element = element.nextSibling;
|
|
}
|
|
|
|
return null;
|
|
},
|
|
|
|
removeGeneratedContent: function(aPopup) {
|
|
var ungenerated = [];
|
|
ungenerated.push(aPopup);
|
|
|
|
var count;
|
|
while (0 != (count = ungenerated.length)) {
|
|
var last = count - 1;
|
|
var element = ungenerated[last];
|
|
ungenerated.splice(last, 1);
|
|
|
|
var i = element.childNodes.length;
|
|
while (i-- > 0) {
|
|
var child = element.childNodes[i];
|
|
if (!child.hasAttribute(this.GENERATEDITEMID_ATTR)) {
|
|
ungenerated.push(child);
|
|
continue;
|
|
}
|
|
element.removeChild(child);
|
|
}
|
|
}
|
|
}
|
|
}
|