From ef3b15bfe4835430834b33f7d9caa622568bfa7b Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 15 Aug 2013 15:06:54 -0400 Subject: [PATCH] Bug 905176 - Don't show the Check Spelling menu item for spellcheck=false contenteditable elements; r=mconley --- browser/base/content/nsContextMenu.js | 31 +++++++++++++++++-- .../base/content/test/contextmenu_common.js | 3 +- .../base/content/test/subtst_contextmenu.html | 1 + .../base/content/test/test_contextmenu.html | 21 ++++++++++++- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js index 2a332cd51bf8..2497dd4462a4 100644 --- a/browser/base/content/nsContextMenu.js +++ b/browser/base/content/nsContextMenu.js @@ -350,7 +350,7 @@ nsContextMenu.prototype = { }, initSpellingItems: function() { - var canSpell = InlineSpellCheckerUI.canSpellCheck; + var canSpell = InlineSpellCheckerUI.canSpellCheck && this.canSpellCheck; var onMisspelling = InlineSpellCheckerUI.overMisspelling; var showUndo = canSpell && InlineSpellCheckerUI.canUndo(); this.showItem("spell-check-enabled", canSpell); @@ -375,7 +375,7 @@ nsContextMenu.prototype = { this.showItem("spell-no-suggestions", false); // dictionary list - this.showItem("spell-dictionaries", InlineSpellCheckerUI.enabled); + this.showItem("spell-dictionaries", canSpell && InlineSpellCheckerUI.enabled); if (canSpell) { var dictMenu = document.getElementById("spell-dictionaries-menu"); var dictSep = document.getElementById("spell-language-separator"); @@ -547,6 +547,7 @@ nsContextMenu.prototype = { this.onEditableArea = false; this.isDesignMode = false; this.onCTPPlugin = false; + this.canSpellCheck = false; // Remember the node that was clicked. this.target = aNode; @@ -648,6 +649,13 @@ nsContextMenu.prototype = { this.target.mozMatchesSelector(":-moz-handler-clicktoplay")) { this.onCTPPlugin = true; } + + this.canSpellCheck = this._isSpellCheckEnabled(this.target); + } + else if (this.target.nodeType == Node.TEXT_NODE) { + // For text nodes, look at the parent node to determine the spellcheck attribute. + this.canSpellCheck = this.target.parentNode && + this._isSpellCheckEnabled(this.target); } // Second, bubble out, looking for items of interest that can have childen. @@ -749,7 +757,7 @@ nsContextMenu.prototype = { this.isDesignMode = true; this.onEditableArea = true; InlineSpellCheckerUI.init(editingSession.getEditorForWindow(win)); - var canSpell = InlineSpellCheckerUI.canSpellCheck; + var canSpell = InlineSpellCheckerUI.canSpellCheck && this.canSpellCheck; InlineSpellCheckerUI.initFromEvent(aRangeParent, aRangeOffset); this.showItem("spell-check-enabled", canSpell); this.showItem("spell-separator", canSpell); @@ -802,6 +810,23 @@ nsContextMenu.prototype = { return aRemotePrincipal; }, + _isSpellCheckEnabled: function(aNode) { + // We can always force-enable spellchecking on textboxes + if (this.isTargetATextBox(aNode)) { + return true; + } + // We can never spell check something which is not content editable + var editable = aNode.isContentEditable; + if (!editable && aNode.ownerDocument) { + editable = aNode.ownerDocument.designMode == "on"; + } + if (!editable) { + return false; + } + // Otherwise make sure that nothing in the parent chain disables spellchecking + return aNode.spellcheck; + }, + // Open linked-to URL in a new window. openLink : function () { var doc = this.target.ownerDocument; diff --git a/browser/base/content/test/contextmenu_common.js b/browser/base/content/test/contextmenu_common.js index 1c32111c29db..20ad58b1db53 100644 --- a/browser/base/content/test/contextmenu_common.js +++ b/browser/base/content/test/contextmenu_common.js @@ -57,7 +57,8 @@ function getVisibleMenuItems(aMenu, aData) { } else if (isGenerated) { items.push("+" + label); } else if (item.id.indexOf("spell-check-dictionary-") != 0 && - item.id != "spell-no-suggestions") { + item.id != "spell-no-suggestions" && + item.id != "spell-add-dictionaries-main") { ok(key, "menuitem " + item.id + " has an access key"); if (accessKeys[key]) ok(false, "menuitem " + item.id + " has same accesskey as " + accessKeys[key]); diff --git a/browser/base/content/test/subtst_contextmenu.html b/browser/base/content/test/subtst_contextmenu.html index 0a2c3fe7504d..baeb3441ea03 100644 --- a/browser/base/content/test/subtst_contextmenu.html +++ b/browser/base/content/test/subtst_contextmenu.html @@ -23,6 +23,7 @@ Browser context menu subtest.
chssseefsbbbie
+
test
DOM full screen FTW

I've got a context menu!

diff --git a/browser/base/content/test/test_contextmenu.html b/browser/base/content/test/test_contextmenu.html index 696c02c30be3..76ad57b2d005 100644 --- a/browser/base/content/test/test_contextmenu.html +++ b/browser/base/content/test/test_contextmenu.html @@ -754,6 +754,23 @@ function runTest(testNum) { "context-viewsource", true, "context-viewinfo", true ].concat(inspectItems)); + closeContextMenu(); + openContextMenuFor(inputspellfalse, false, true); // Invoke context menu for next test. + break; + + case 30: + // Context menu for text input field with spellcheck=false + checkContextMenu(["context-undo", false, + "---", null, + "context-cut", false, + "context-copy", false, + "context-paste", null, // ignore clipboard state + "context-delete", false, + "---", null, + "context-selectall", true, + "---", null, + "spell-add-dictionaries-main", true, + ].concat(inspectItems)); // finish test subwindow.close(); @@ -782,7 +799,7 @@ var text, link, mailto, input, img, canvas, video_ok, video_bad, video_bad2, iframe, video_in_iframe, image_in_iframe, textarea, contenteditable, pagemenu, dom_full_screen, plainTextItems, audio_in_video, selecttext, selecttextlink, imagelink, select_inputtext, select_inputtext_password, - plugin, longdesc, iframe; + plugin, longdesc, iframe, inputspellfalse; function startTest() { chromeWin = SpecialPowers.wrap(subwindow) @@ -823,6 +840,8 @@ function startTest() { textarea = subwindow.document.getElementById("test-textarea"); contenteditable = subwindow.document.getElementById("test-contenteditable"); contenteditable.focus(); // content editable needs to be focused to enable spellcheck + inputspellfalse = subwindow.document.getElementById("test-contenteditable-spellcheck-false"); + inputspellfalse.focus(); // content editable needs to be focused to enable spellcheck pagemenu = subwindow.document.getElementById("test-pagemenu"); dom_full_screen = subwindow.document.getElementById("test-dom-full-screen"); selecttext = subwindow.document.getElementById("test-select-text");