mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 469434 - Links in "view source" should have "copy link location" in context menu; r=dao
This commit is contained in:
parent
2cc3de416d
commit
30543d19e0
@ -111,10 +111,19 @@
|
||||
<key id="key_textZoomReset2" key="&textReset.commandkey2;" command="cmd_textZoomReset" modifiers="accel"/>
|
||||
</keyset>
|
||||
|
||||
<menupopup id="viewSourceContextMenu">
|
||||
<menupopup id="viewSourceContextMenu"
|
||||
onpopupshowing="contextMenuShowing();">
|
||||
<menuitem id="cMenu_findAgain"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="cMenu_copy"/>
|
||||
<menuitem id="context-copyLink"
|
||||
label="©LinkCmd.label;"
|
||||
accesskey="©LinkCmd.accesskey;"
|
||||
oncommand="contextMenuCopyLinkOrEmail();"/>
|
||||
<menuitem id="context-copyEmail"
|
||||
label="©EmailCmd.label;"
|
||||
accesskey="©EmailCmd.accesskey;"
|
||||
oncommand="contextMenuCopyLinkOrEmail();"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="cMenu_selectAll"/>
|
||||
</menupopup>
|
||||
|
@ -47,7 +47,8 @@ var gGoToLine = 0;
|
||||
|
||||
[
|
||||
["gBrowser", "content"],
|
||||
["gViewSourceBundle", "viewSourceBundle"]
|
||||
["gViewSourceBundle", "viewSourceBundle"],
|
||||
["gContextMenu", "viewSourceContextMenu"]
|
||||
].forEach(function ([name, id]) {
|
||||
window.__defineGetter__(name, function () {
|
||||
var element = document.getElementById(id);
|
||||
@ -797,3 +798,25 @@ function FillInHTMLTooltip(tipElement)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
function contextMenuShowing() {
|
||||
var isLink = false;
|
||||
var isEmail = false;
|
||||
if (gContextMenu.triggerNode && gContextMenu.triggerNode.localName == 'a') {
|
||||
if (gContextMenu.triggerNode.href.indexOf('view-source:') == 0)
|
||||
isLink = true;
|
||||
if (gContextMenu.triggerNode.href.indexOf('mailto:') == 0)
|
||||
isEmail = true;
|
||||
}
|
||||
document.getElementById('context-copyLink').hidden = !isLink;
|
||||
document.getElementById('context-copyEmail').hidden = !isEmail;
|
||||
}
|
||||
|
||||
function contextMenuCopyLinkOrEmail() {
|
||||
if (!gContextMenu.triggerNode)
|
||||
return;
|
||||
|
||||
var href = gContextMenu.triggerNode.href;
|
||||
var clipboard = Cc['@mozilla.org/widget/clipboardhelper;1'].
|
||||
getService(Ci.nsIClipboardHelper);
|
||||
clipboard.copyString(href.substring(href.indexOf(':') + 1));
|
||||
}
|
||||
|
@ -144,7 +144,8 @@
|
||||
|
||||
<tooltip id="aHTMLTooltip" onpopupshowing="return FillInHTMLTooltip(document.tooltipNode);"/>
|
||||
|
||||
<menupopup id="viewSourceContextMenu">
|
||||
<menupopup id="viewSourceContextMenu"
|
||||
onpopupshowing="contextMenuShowing();">
|
||||
<menuitem id="context-back"
|
||||
label="&backCmd.label;"
|
||||
accesskey="&backCmd.accesskey;"
|
||||
@ -159,6 +160,14 @@
|
||||
<menuitem id="cMenu_findAgain"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="cMenu_copy"/>
|
||||
<menuitem id="context-copyLink"
|
||||
label="©LinkCmd.label;"
|
||||
accesskey="©LinkCmd.accesskey;"
|
||||
oncommand="contextMenuCopyLinkOrEmail();"/>
|
||||
<menuitem id="context-copyEmail"
|
||||
label="©EmailCmd.label;"
|
||||
accesskey="©EmailCmd.accesskey;"
|
||||
oncommand="contextMenuCopyLinkOrEmail();"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="cMenu_selectAll"/>
|
||||
</menupopup>
|
||||
|
@ -47,6 +47,7 @@ include $(topsrcdir)/config/rules.mk
|
||||
_BROWSER_CHROME_FILES = \
|
||||
browser_bug699356.js \
|
||||
browser_bug713810.js \
|
||||
browser_contextmenu.js \
|
||||
browser_viewsourceprefs.js \
|
||||
browser_viewsourceprefs_nonhtml.js \
|
||||
head.js \
|
||||
|
@ -0,0 +1,85 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
let source = "data:text/html,text<link%20href='http://example.com/'%20/>more%20text<a%20href='mailto:abc@def.ghi'>email</a>";
|
||||
let gViewSourceWindow, gContextMenu, gCopyLinkMenuItem, gCopyEmailMenuItem;
|
||||
|
||||
let expectedData = [];
|
||||
let currentTest = 0;
|
||||
let partialTestRunning = false;
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
openViewSourceWindow(source, onViewSourceWindowOpen);
|
||||
}
|
||||
|
||||
function onViewSourceWindowOpen(aWindow) {
|
||||
gViewSourceWindow = aWindow;
|
||||
|
||||
gContextMenu = aWindow.document.getElementById("viewSourceContextMenu");
|
||||
gCopyLinkMenuItem = aWindow.document.getElementById("context-copyLink");
|
||||
gCopyEmailMenuItem = aWindow.document.getElementById("context-copyEmail");
|
||||
|
||||
let aTags = aWindow.gBrowser.contentDocument.querySelectorAll("a[href]");
|
||||
is(aTags[0].href, "view-source:http://example.com/", "Link has correct href");
|
||||
is(aTags[1].href, "mailto:abc@def.ghi", "Link has correct href");
|
||||
let spanTag = aWindow.gBrowser.contentDocument.querySelector("span");
|
||||
|
||||
expectedData.push([aTags[0], true, false, "http://example.com/"]);
|
||||
expectedData.push([aTags[1], false, true, "abc@def.ghi"]);
|
||||
expectedData.push([spanTag, false, false, null]);
|
||||
|
||||
waitForFocus(runNextTest, aWindow);
|
||||
}
|
||||
|
||||
function runNextTest() {
|
||||
if (currentTest == expectedData.length) {
|
||||
closeViewSourceWindow(gViewSourceWindow, function() {
|
||||
if (partialTestRunning) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
partialTestRunning = true;
|
||||
currentTest = 0;
|
||||
expectedData = [];
|
||||
waitForFocus(function() {
|
||||
openDocumentSelect(source, "body", onViewSourceWindowOpen);
|
||||
}, window);
|
||||
});
|
||||
return;
|
||||
}
|
||||
let test = expectedData[currentTest++];
|
||||
checkMenuItems(test[0], test[1], test[2], test[3]);
|
||||
}
|
||||
|
||||
function checkMenuItems(popupNode, copyLinkExpected, copyEmailExpected, expectedClipboardContent) {
|
||||
popupNode.scrollIntoView();
|
||||
|
||||
let cachedEvent = null;
|
||||
let mouseFn = function(event) {
|
||||
cachedEvent = event;
|
||||
};
|
||||
|
||||
gViewSourceWindow.gBrowser.contentWindow.addEventListener("mousedown", mouseFn, false);
|
||||
EventUtils.synthesizeMouseAtCenter(popupNode, { button: 2 }, gViewSourceWindow.gBrowser.contentWindow);
|
||||
gViewSourceWindow.gBrowser.contentWindow.removeEventListener("mousedown", mouseFn, false);
|
||||
|
||||
gContextMenu.openPopup(popupNode, "after_start", 0, 0, false, false, cachedEvent);
|
||||
|
||||
is(gCopyLinkMenuItem.hidden, !copyLinkExpected, "Copy link menuitem is " + (copyLinkExpected ? "not hidden" : "hidden"));
|
||||
is(gCopyEmailMenuItem.hidden, !copyEmailExpected, "Copy email menuitem is " + (copyEmailExpected ? "not hidden" : "hidden"));
|
||||
|
||||
if (!copyLinkExpected && !copyEmailExpected) {
|
||||
runNextTest();
|
||||
return;
|
||||
}
|
||||
|
||||
waitForClipboard(expectedClipboardContent, function() {
|
||||
if (copyLinkExpected)
|
||||
gCopyLinkMenuItem.doCommand();
|
||||
else
|
||||
gCopyEmailMenuItem.doCommand();
|
||||
gContextMenu.hidePopup();
|
||||
}, runNextTest, runNextTest);
|
||||
}
|
@ -45,14 +45,14 @@ registerCleanupFunction(function() {
|
||||
});
|
||||
|
||||
function openDocument(aURI, aCallback) {
|
||||
let tab = window.gBrowser.addTab(aURI);
|
||||
let tab = gBrowser.addTab(aURI);
|
||||
let browser = tab.linkedBrowser;
|
||||
browser.addEventListener("DOMContentLoaded", function pageLoadedListener() {
|
||||
browser.removeEventListener("DOMContentLoaded", pageLoadedListener, false);
|
||||
aCallback(tab);
|
||||
}, false);
|
||||
registerCleanupFunction(function() {
|
||||
window.gBrowser.removeTab(tab);
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -74,3 +74,8 @@ you can use these alternative items. Otherwise, their values should be empty. -
|
||||
<!ENTITY forwardCmd.accesskey "F">
|
||||
<!ENTITY goBackCmd.commandKey "[">
|
||||
<!ENTITY goForwardCmd.commandKey "]">
|
||||
|
||||
<!ENTITY copyLinkCmd.label "Copy Link Location">
|
||||
<!ENTITY copyLinkCmd.accesskey "L">
|
||||
<!ENTITY copyEmailCmd.label "Copy Email Address">
|
||||
<!ENTITY copyEmailCmd.accesskey "E">
|
||||
|
Loading…
Reference in New Issue
Block a user