Bug 782850 fix nsContextMenu to work in social content panels, r=felipe

This commit is contained in:
Shane Caraveo 2013-01-26 16:48:54 -08:00
parent 190192f69c
commit 5b652811b3
11 changed files with 51 additions and 25 deletions

View File

@ -184,7 +184,7 @@
<menuitem id="context-reload"
label="&reloadCmd.label;"
accesskey="&reloadCmd.accesskey;"
command="Browser:ReloadOrDuplicate"
oncommand="gContextMenu.reload(event);"
onclick="checkForMiddleClick(this, event);"/>
<menuitem id="context-stop"
label="&stopCmd.label;"

View File

@ -1107,6 +1107,7 @@
persist="width">
<browser id="social-sidebar-browser"
type="content"
context="contentAreaContextMenu"
disableglobalhistory="true"
flex="1"
style="min-width: 14em; width: 18em; max-width: 36em;"/>

View File

@ -4,22 +4,20 @@
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
function nsContextMenu(aXulMenu, aBrowser, aIsShift) {
function nsContextMenu(aXulMenu, aIsShift) {
this.shouldDisplay = true;
this.initMenu(aBrowser, aXulMenu, aIsShift);
this.initMenu(aXulMenu, aIsShift);
}
// Prototype for nsContextMenu "class."
nsContextMenu.prototype = {
initMenu: function CM_initMenu(aBrowser, aXulMenu, aIsShift) {
initMenu: function CM_initMenu(aXulMenu, aIsShift) {
// Get contextual info.
this.setTarget(document.popupNode, document.popupRangeParent,
document.popupRangeOffset);
if (!this.shouldDisplay)
return;
this.browser = aBrowser;
this.hasPageMenu = false;
if (!aIsShift) {
this.hasPageMenu = PageMenu.maybeBuildAndAttachMenu(this.target,
@ -154,13 +152,20 @@ nsContextMenu.prototype = {
initNavigationItems: function CM_initNavigationItems() {
var shouldShow = !(this.isContentSelected || this.onLink || this.onImage ||
this.onCanvas || this.onVideo || this.onAudio ||
this.onTextInput);
this.onTextInput || this.onSocial);
this.showItem("context-back", shouldShow);
this.showItem("context-forward", shouldShow);
var shouldShowReload = XULBrowserWindow.stopCommand.getAttribute("disabled") == "true";
this.showItem("context-reload", shouldShow && shouldShowReload);
this.showItem("context-stop", shouldShow && !shouldShowReload);
this.showItem("context-sep-stop", shouldShow);
let stopped = XULBrowserWindow.stopCommand.getAttribute("disabled") == "true";
let stopReloadItem = "";
if (shouldShow || this.onSocial) {
stopReloadItem = (stopped || this.onSocial) ? "reload" : "stop";
}
this.showItem("context-reload", stopReloadItem == "reload");
this.showItem("context-stop", stopReloadItem == "stop");
this.showItem("context-sep-stop", !!stopReloadItem);
// XXX: Stop is determined in browser.js; the canStop broadcaster is broken
//this.setItemAttrFromNode( "context-stop", "disabled", "canStop" );
@ -211,7 +216,7 @@ nsContextMenu.prototype = {
this.onImage || this.onCanvas ||
this.onVideo || this.onAudio ||
this.onLink || this.onTextInput);
var showInspect = gPrefService.getBoolPref("devtools.inspector.enabled");
var showInspect = !this.onSocial && gPrefService.getBoolPref("devtools.inspector.enabled");
this.showItem("context-viewsource", shouldShow);
this.showItem("context-viewinfo", shouldShow);
this.showItem("inspect-separator", showInspect);
@ -268,8 +273,9 @@ nsContextMenu.prototype = {
// Use "Bookmark This Link" if on a link.
this.showItem("context-bookmarkpage",
!(this.isContentSelected || this.onTextInput || this.onLink ||
this.onImage || this.onVideo || this.onAudio));
this.showItem("context-bookmarklink", (this.onLink && !this.onMailtoLink) || this.onPlainTextLink);
this.onImage || this.onVideo || this.onAudio || this.onSocial));
this.showItem("context-bookmarklink", (this.onLink && !this.onMailtoLink &&
!this.onSocial) || this.onPlainTextLink);
this.showItem("context-searchselect", isTextSelected);
this.showItem("context-keywordfield",
this.onTextInput && this.onKeywordField);
@ -474,6 +480,13 @@ nsContextMenu.prototype = {
// Remember the node that was clicked.
this.target = aNode;
this.browser = this.target.ownerDocument.defaultView
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.chromeEventHandler;
this.onSocial = !!this.browser.getAttribute("origin");
// Check if we are in a synthetic document (stand alone image, video, etc.).
this.inSyntheticDoc = this.target.ownerDocument.mozSyntheticDocument;
// First, do checks for nodes that never have children.
@ -763,6 +776,18 @@ nsContextMenu.prototype = {
referrerURI: referrer ? makeURI(referrer) : null });
},
reload: function(event) {
if (this.onSocial) {
// full reload of social provider
Social.enabled = false;
Services.tm.mainThread.dispatch(function() {
Social.enabled = true;
}, Components.interfaces.nsIThread.DISPATCH_NORMAL);
} else {
BrowserReloadOrDuplicate(event);
}
},
// View Partial Source
viewPartialSource: function(aContext) {
var focusedWindow = document.commandDispatcher.focusedWindow;

View File

@ -15,6 +15,7 @@
oncommand="document.getBindingParent(this).close();"/>
</xul:hbox>
<xul:iframe anonid="iframe" class="chat-frame" flex="1"
context="contentAreaContextMenu"
xbl:inherits="src,origin,collapsed=minimized" type="content"/>
</content>

View File

@ -19,7 +19,7 @@ function onPageShow() {
document.popupNode = frame.document.body;
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
var contextMenu = new nsContextMenu(contentAreaContextMenu);
ok(document.getElementById("frame-sep").hidden, "'frame-sep' should be hidden if the selection contains only spaces");
finish();

View File

@ -32,7 +32,7 @@ function test1Setup() {
document.popupNode = badFrame.document.firstChild;
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
var contextMenu = new nsContextMenu(contentAreaContextMenu);
// We'd like to use another load listener here, but error pages don't fire load events
contextMenu.showOnlyThisFrame();
@ -69,7 +69,7 @@ function test2Setup() {
document.popupNode = badFrame.document.firstChild;
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
var contextMenu = new nsContextMenu(contentAreaContextMenu);
gBrowser.tabContainer.addEventListener("TabOpen", function (event) {
test2tab = event.target;
@ -105,7 +105,7 @@ function test3Setup() {
document.popupNode = badFrame.document.firstChild;
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
var contextMenu = new nsContextMenu(contentAreaContextMenu);
Services.ww.registerNotification(function (aSubject, aTopic, aData) {
if (aTopic == "domwindowopened")

View File

@ -16,7 +16,7 @@ function test() {
document.popupNode = element;
let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
let contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
let contextMenu = new nsContextMenu(contentAreaContextMenu);
is(contextMenu.shouldDisplay, expected, "context menu behavior for <input type=" + type + "> is wrong");
};
@ -26,7 +26,7 @@ function test() {
document.popupNode = element;
let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
let contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
let contextMenu = new nsContextMenu(contentAreaContextMenu);
is(contextMenu.shouldDisplay, expected, "context menu behavior for <" + tag + "> is wrong");
};

View File

@ -102,6 +102,6 @@ function test() {
function initContextMenu(aNode) {
document.popupNode = aNode;
let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
let contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
let contextMenu = new nsContextMenu(contentAreaContextMenu);
return contextMenu;
}

View File

@ -14,7 +14,7 @@ function setSelection(el1, el2, index1, index2) {
function initContextMenu(aNode) {
document.popupNode = aNode;
let contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
let contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
let contextMenu = new nsContextMenu(contentAreaContextMenu);
return contextMenu;
}

View File

@ -50,7 +50,7 @@
<menupopup id="contentAreaContextMenu" pagemenu="start"
onpopupshowing="if (event.target != this)
return true;
gContextMenu = new nsContextMenu(this, getPanelBrowser(), event.shiftKey);
gContextMenu = new nsContextMenu(this, event.shiftKey);
if (gContextMenu.shouldDisplay)
document.popupNode = this.triggerNode;
return gContextMenu.shouldDisplay;"

View File

@ -92,7 +92,7 @@ function testBreadcrumbs(node)
function _clickOnInspectMenuItem(node) {
document.popupNode = node;
var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
var contextMenu = new nsContextMenu(contentAreaContextMenu, gBrowser);
var contextMenu = new nsContextMenu(contentAreaContextMenu);
return contextMenu.inspectNode();
}
@ -142,4 +142,3 @@ function test()
content.location = "data:text/html,basic tests for inspector";
}