Bug 905176 - Don't show the Check Spelling menu item for spellcheck=false contenteditable elements; r=mconley

This commit is contained in:
Ehsan Akhgari 2013-08-15 15:06:54 -04:00
Родитель 90a90ba3b4
Коммит ef3b15bfe4
4 изменённых файлов: 51 добавлений и 5 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -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]);

Просмотреть файл

@ -23,6 +23,7 @@ Browser context menu subtest.
<iframe id="test-image-in-iframe" src="ctxmenu-image.png" width="98" height="98" style="border: 1px solid black"></iframe>
<textarea id="test-textarea">chssseesbbbie</textarea> <!-- a weird word which generates only one suggestion -->
<div id="test-contenteditable" contenteditable="true">chssseefsbbbie</div> <!-- a more weird word which generates no suggestions -->
<div id="test-contenteditable-spellcheck-false" contenteditable="true" spellcheck="false">test</div> <!-- No Check Spelling menu item -->
<div id="test-dom-full-screen">DOM full screen FTW</div>
<div contextmenu="myMenu">
<p id="test-pagemenu" hopeless="true">I've got a context menu!</p>

Просмотреть файл

@ -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");