Loading browser/base/content/nsContextMenu.js +22 −10 Original line number Diff line number Diff line Loading @@ -92,6 +92,7 @@ nsContextMenu.prototype = { } catch (e) { } this.isTextSelected = this.isTextSelection(); this.isContentSelected = this.isContentSelection(); this.onPlainTextLink = false; // Initialize (disable/remove) menu items. this.initItems(); Loading Loading @@ -132,7 +133,6 @@ nsContextMenu.prototype = { // Time to do some bad things and see if we've highlighted a URL that // isn't actually linked. var onPlainTextLink = false; if (this.isTextSelected && !this.onLink) { // Ok, we have some text, let's figure out if it looks like a URL. let selection = document.commandDispatcher.focusedWindow Loading Loading @@ -190,14 +190,14 @@ nsContextMenu.prototype = { if (uri && uri.host) { this.linkURI = uri; this.linkURL = this.linkURI.spec; onPlainTextLink = true; this.onPlainTextLink = true; } } var shouldShow = this.onSaveableLink || isMailtoInternal || onPlainTextLink; var shouldShow = this.onSaveableLink || isMailtoInternal || this.onPlainTextLink; this.showItem("context-openlink", shouldShow); this.showItem("context-openlinkintab", shouldShow); this.showItem("context-openlinkincurrent", onPlainTextLink); this.showItem("context-openlinkincurrent", this.onPlainTextLink); this.showItem("context-sep-open", shouldShow); }, Loading @@ -222,9 +222,9 @@ nsContextMenu.prototype = { this.showItem("context-savepage", shouldShow); this.showItem("context-sendpage", shouldShow); // Save+Send link depends on whether we're in a link. this.showItem("context-savelink", this.onSaveableLink); this.showItem("context-sendlink", this.onSaveableLink); // Save+Send link depends on whether we're in a link, or selected text matches valid URL pattern. this.showItem("context-savelink", this.onSaveableLink || this.onPlainTextLink); this.showItem("context-sendlink", this.onSaveableLink || this.onPlainTextLink); // Save image depends on having loaded its content, video and audio don't. this.showItem("context-saveimage", this.onLoadedImage || this.onCanvas); Loading Loading @@ -310,7 +310,7 @@ nsContextMenu.prototype = { 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.showItem("context-bookmarklink", (this.onLink && !this.onMailtoLink) || this.onPlainTextLink); this.showItem("context-searchselect", isTextSelected); this.showItem("context-keywordfield", this.onTextInput && this.onKeywordField); Loading Loading @@ -1073,9 +1073,15 @@ nsContextMenu.prototype = { // Save URL of clicked-on link. saveLink: function() { var doc = this.target.ownerDocument; var linkText; // If selected text is found to match valid URL pattern. if (this.onPlainTextLink) linkText = document.commandDispatcher.focusedWindow.getSelection().toString().trim(); else linkText = this.linkText(); urlSecurityCheck(this.linkURL, doc.nodePrincipal); this.saveHelper(this.linkURL, this.linkText(), null, true, doc); this.saveHelper(this.linkURL, linkText, null, true, doc); }, sendLink: function() { Loading Loading @@ -1390,8 +1396,14 @@ nsContextMenu.prototype = { }, bookmarkLink: function CM_bookmarkLink() { var linkText; // If selected text is found to match valid URL pattern. if (this.onPlainTextLink) linkText = document.commandDispatcher.focusedWindow.getSelection().toString().trim(); else linkText = this.linkText(); window.top.PlacesCommandHook.bookmarkLink(PlacesUtils.bookmarksMenuFolderId, this.linkURL, this.linkText()); linkText); }, addBookmarkForFrame: function CM_addBookmarkForFrame() { Loading browser/base/content/test/subtst_contextmenu.html +2 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,8 @@ Browser context menu subtest. <menuitem></menuitem> </menu> </div> <div id="test-select-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</div> <div id="test-select-text-link">http://mozilla.com</div> </body> </html> browser/base/content/test/test_contextmenu.html +52 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ Browser context menu tests. netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm"); Components.utils.import("resource://gre/modules/Services.jsm"); const Cc = Components.classes; const Ci = Components.interfaces; Loading Loading @@ -72,6 +73,16 @@ function invokeItemAction(generatedItemId) ok(!pagemenu.hasAttribute("hopeless"), "attribute got removed"); } function selectText(element) { // Clear any previous selections before selecting new element. subwindow.getSelection().removeAllRanges(); var div = subwindow.document.createRange(); div.setStartBefore(element); div.setEndAfter(element); subwindow.getSelection().addRange(div); } function getVisibleMenuItems(aMenu, aData) { var items = []; var accessKeys = {}; Loading Loading @@ -667,6 +678,45 @@ function runTest(testNum) { "context-viewinfo", true ].concat(inspectItems)); closeContextMenu(); selectText(selecttext); // Select text prior to opening context menu. openContextMenuFor(selecttext); // Invoke context menu for next test. return; case 22: // Context menu for selected text if (Services.appinfo.OS == "Darwin") { // This test is only enabled on Mac due to bug 736399. checkContextMenu(["context-copy", true, "context-selectall", true, "---", null, "context-searchselect", true, "context-viewpartialsource-selection", true ].concat(inspectItems)); } closeContextMenu(); selectText(selecttextlink); // Select text prior to opening context menu. openContextMenuFor(selecttextlink); // Invoke context menu for next test. return; case 23: // Context menu for selected text which matches valid URL pattern if (Services.appinfo.OS == "Darwin") { // This test is only enabled on Mac due to bug 736399. checkContextMenu(["context-openlinkincurrent", true, "context-openlinkintab", true, "context-openlink", true, "---", null, "context-bookmarklink", true, "context-savelink", true, "context-sendlink", true, "context-copy", true, "context-selectall", true, "---", null, "context-searchselect", true, "context-viewpartialsource-selection", true ].concat(inspectItems)); } closeContextMenu(); subwindow.close(); SimpleTest.finish(); Loading @@ -674,7 +724,6 @@ function runTest(testNum) { /* * Other things that would be nice to test: * - selected text * - spelling / misspelled word (in text input?) * - check state of disabled items * - test execution of menu items (maybe as a separate test?) Loading Loading @@ -734,6 +783,8 @@ function startTest() { contenteditable.focus(); // content editable needs to be focused to enable spellcheck inputspell = subwindow.document.getElementById("test-input-spellcheck"); pagemenu = subwindow.document.getElementById("test-pagemenu"); selecttext = subwindow.document.getElementById("test-select-text"); selecttextlink = subwindow.document.getElementById("test-select-text-link"); contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false); runTest(1); Loading Loading
browser/base/content/nsContextMenu.js +22 −10 Original line number Diff line number Diff line Loading @@ -92,6 +92,7 @@ nsContextMenu.prototype = { } catch (e) { } this.isTextSelected = this.isTextSelection(); this.isContentSelected = this.isContentSelection(); this.onPlainTextLink = false; // Initialize (disable/remove) menu items. this.initItems(); Loading Loading @@ -132,7 +133,6 @@ nsContextMenu.prototype = { // Time to do some bad things and see if we've highlighted a URL that // isn't actually linked. var onPlainTextLink = false; if (this.isTextSelected && !this.onLink) { // Ok, we have some text, let's figure out if it looks like a URL. let selection = document.commandDispatcher.focusedWindow Loading Loading @@ -190,14 +190,14 @@ nsContextMenu.prototype = { if (uri && uri.host) { this.linkURI = uri; this.linkURL = this.linkURI.spec; onPlainTextLink = true; this.onPlainTextLink = true; } } var shouldShow = this.onSaveableLink || isMailtoInternal || onPlainTextLink; var shouldShow = this.onSaveableLink || isMailtoInternal || this.onPlainTextLink; this.showItem("context-openlink", shouldShow); this.showItem("context-openlinkintab", shouldShow); this.showItem("context-openlinkincurrent", onPlainTextLink); this.showItem("context-openlinkincurrent", this.onPlainTextLink); this.showItem("context-sep-open", shouldShow); }, Loading @@ -222,9 +222,9 @@ nsContextMenu.prototype = { this.showItem("context-savepage", shouldShow); this.showItem("context-sendpage", shouldShow); // Save+Send link depends on whether we're in a link. this.showItem("context-savelink", this.onSaveableLink); this.showItem("context-sendlink", this.onSaveableLink); // Save+Send link depends on whether we're in a link, or selected text matches valid URL pattern. this.showItem("context-savelink", this.onSaveableLink || this.onPlainTextLink); this.showItem("context-sendlink", this.onSaveableLink || this.onPlainTextLink); // Save image depends on having loaded its content, video and audio don't. this.showItem("context-saveimage", this.onLoadedImage || this.onCanvas); Loading Loading @@ -310,7 +310,7 @@ nsContextMenu.prototype = { 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.showItem("context-bookmarklink", (this.onLink && !this.onMailtoLink) || this.onPlainTextLink); this.showItem("context-searchselect", isTextSelected); this.showItem("context-keywordfield", this.onTextInput && this.onKeywordField); Loading Loading @@ -1073,9 +1073,15 @@ nsContextMenu.prototype = { // Save URL of clicked-on link. saveLink: function() { var doc = this.target.ownerDocument; var linkText; // If selected text is found to match valid URL pattern. if (this.onPlainTextLink) linkText = document.commandDispatcher.focusedWindow.getSelection().toString().trim(); else linkText = this.linkText(); urlSecurityCheck(this.linkURL, doc.nodePrincipal); this.saveHelper(this.linkURL, this.linkText(), null, true, doc); this.saveHelper(this.linkURL, linkText, null, true, doc); }, sendLink: function() { Loading Loading @@ -1390,8 +1396,14 @@ nsContextMenu.prototype = { }, bookmarkLink: function CM_bookmarkLink() { var linkText; // If selected text is found to match valid URL pattern. if (this.onPlainTextLink) linkText = document.commandDispatcher.focusedWindow.getSelection().toString().trim(); else linkText = this.linkText(); window.top.PlacesCommandHook.bookmarkLink(PlacesUtils.bookmarksMenuFolderId, this.linkURL, this.linkText()); linkText); }, addBookmarkForFrame: function CM_addBookmarkForFrame() { Loading
browser/base/content/test/subtst_contextmenu.html +2 −0 Original line number Diff line number Diff line Loading @@ -58,6 +58,8 @@ Browser context menu subtest. <menuitem></menuitem> </menu> </div> <div id="test-select-text">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</div> <div id="test-select-text-link">http://mozilla.com</div> </body> </html>
browser/base/content/test/test_contextmenu.html +52 −1 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ Browser context menu tests. netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm"); Components.utils.import("resource://gre/modules/Services.jsm"); const Cc = Components.classes; const Ci = Components.interfaces; Loading Loading @@ -72,6 +73,16 @@ function invokeItemAction(generatedItemId) ok(!pagemenu.hasAttribute("hopeless"), "attribute got removed"); } function selectText(element) { // Clear any previous selections before selecting new element. subwindow.getSelection().removeAllRanges(); var div = subwindow.document.createRange(); div.setStartBefore(element); div.setEndAfter(element); subwindow.getSelection().addRange(div); } function getVisibleMenuItems(aMenu, aData) { var items = []; var accessKeys = {}; Loading Loading @@ -667,6 +678,45 @@ function runTest(testNum) { "context-viewinfo", true ].concat(inspectItems)); closeContextMenu(); selectText(selecttext); // Select text prior to opening context menu. openContextMenuFor(selecttext); // Invoke context menu for next test. return; case 22: // Context menu for selected text if (Services.appinfo.OS == "Darwin") { // This test is only enabled on Mac due to bug 736399. checkContextMenu(["context-copy", true, "context-selectall", true, "---", null, "context-searchselect", true, "context-viewpartialsource-selection", true ].concat(inspectItems)); } closeContextMenu(); selectText(selecttextlink); // Select text prior to opening context menu. openContextMenuFor(selecttextlink); // Invoke context menu for next test. return; case 23: // Context menu for selected text which matches valid URL pattern if (Services.appinfo.OS == "Darwin") { // This test is only enabled on Mac due to bug 736399. checkContextMenu(["context-openlinkincurrent", true, "context-openlinkintab", true, "context-openlink", true, "---", null, "context-bookmarklink", true, "context-savelink", true, "context-sendlink", true, "context-copy", true, "context-selectall", true, "---", null, "context-searchselect", true, "context-viewpartialsource-selection", true ].concat(inspectItems)); } closeContextMenu(); subwindow.close(); SimpleTest.finish(); Loading @@ -674,7 +724,6 @@ function runTest(testNum) { /* * Other things that would be nice to test: * - selected text * - spelling / misspelled word (in text input?) * - check state of disabled items * - test execution of menu items (maybe as a separate test?) Loading Loading @@ -734,6 +783,8 @@ function startTest() { contenteditable.focus(); // content editable needs to be focused to enable spellcheck inputspell = subwindow.document.getElementById("test-input-spellcheck"); pagemenu = subwindow.document.getElementById("test-pagemenu"); selecttext = subwindow.document.getElementById("test-select-text"); selecttextlink = subwindow.document.getElementById("test-select-text-link"); contextMenu.addEventListener("popupshown", function() { runTest(++testNum); }, false); runTest(1); Loading