Bug 338318 UI for spellcheck in browser window (form fields)

p=me r=neil sr=jag


git-svn-id: svn://10.0.0.236/trunk@212274 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bugzilla%arlen.demon.co.uk
2006-09-24 23:38:43 +00:00
parent 18bf283f08
commit d91df1e9cf
12 changed files with 196 additions and 11 deletions

View File

@@ -177,7 +177,8 @@
</ol>
<p>The Languages preferences panel allows you to choose the languages and
character encoding for displaying web pages:</p>
character encoding for displaying web pages and choose if and how your typing
is spell checked:</p>
<ul>
<li><strong>Languages for Web Pages</strong>:
@@ -198,6 +199,12 @@
pages.</li>
</ul>
</li>
<li><strong>Spelling:</strong>
<ul>
<li><strong>When typing check my spelling</strong>: Use the drop-down
list to select if and how your typing is spell checked.</li>
</ul>
</li>
</ul>
<p>[<a href="#navigator_preferences">Return to beginning of section</a>]</p>

View File

@@ -190,6 +190,13 @@ pref("news.directory", "");
pref("browser.editor.disabled", false);
pref("spellchecker.dictionary", "");
// this will automatically enable inline spellchecking (if it is available) for
// editable elements in HTML
// 0 = spellcheck nothing
// 1 = check multi-line controls [default]
// 2 = check multi/single line controls
pref("layout.spellcheckDefault", 1);
// App-specific update preferences
// Whether or not app updates are enabled - false initally for SeaMonkey

View File

@@ -50,6 +50,7 @@
// Global variable that caches the default search engine info
var gDefaultEngine = null;
</script>
<script type="application/x-javascript" src="chrome://global/content/inlineSpellCheckUI.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/nsContextMenu.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/contentAreaUtils.js"/>
@@ -71,6 +72,14 @@
oncommand="gContextMenu.allowPopupWindows();"/>
<menuseparator id="context-sep-popup"/>
<menuitem id="spell-no-suggestions"
disabled="true"
label="&spellNoSuggestions.label;"/>
<menuitem id="spell-add-to-dictionary"
label="&spellAddToDictionary.label;"
accesskey="&spellAddToDictionary.accesskey;"
oncommand="InlineSpellCheckerUI.addToDictionary();"/>
<menuseparator id="spell-suggestions-separator"/>
<menuitem id="context-openlink"
label="&openLinkCmd.label;"
accesskey="&openLinkCmd.accesskey;"
@@ -251,6 +260,27 @@
label="&metadataCmd.label;"
accesskey="&metadataCmd.accesskey;"
oncommand="gContextMenu.showMetadata();"/>
<menuseparator id="spell-separator"/>
<menuitem id="spell-check-enabled"
label="&spellEnable.label;"
type="checkbox"
accesskey="&spellEnable.accesskey;"
oncommand="InlineSpellCheckerUI.toggleEnabled();"/>
<menuitem id="spell-add-dictionaries-main"
label="&spellAddDictionaries.label;"
accesskey="&spellAddDictionaries.accesskey;"
oncommand="gContextMenu.addDictionaries();"/>
<menu id="spell-dictionaries"
label="&spellDictionaries.label;"
accesskey="&spellDictionaries.accesskey;">
<menupopup id="spell-dictionaries-menu">
<menuseparator id="spell-language-separator"/>
<menuitem id="spell-add-dictionaries"
label="&spellAddDictionaries.label;"
accesskey="&spellAddDictionaries.accesskey;"
oncommand="gContextMenu.addDictionaries();"/>
</menupopup>
</menu>
<menuseparator hidden="true" id="context-sep-bidi"/>
<menuitem hidden="true" id="context-bidi-text-direction-toggle"
label="&bidiSwitchTextDirectionItem.label;"

View File

@@ -89,8 +89,9 @@ nsContextMenu.prototype = {
return;
}
// Get contextual info.
this.setTarget( document.popupNode );
this.setTarget( document.popupNode, document.popupRangeParent,
document.popupRangeOffset );
this.isTextSelected = this.isTextSelection();
this.initPopupURL();
@@ -103,6 +104,7 @@ nsContextMenu.prototype = {
this.initNavigationItems();
this.initViewItems();
this.initMiscItems();
this.initSpellingItems();
this.initSaveItems();
this.initClipboardItems();
this.initMetadataItems();
@@ -219,6 +221,40 @@ nsContextMenu.prototype = {
this.showItem( "context-bidi-text-direction-toggle", this.onTextInput && gShowBiDi);
this.showItem( "context-bidi-page-direction-toggle", !this.onTextInput && gShowBiDi);
},
initSpellingItems : function () {
var canSpell = InlineSpellCheckerUI.canSpellCheck;
var onMisspelling = InlineSpellCheckerUI.overMisspelling;
this.showItem("spell-check-enabled", canSpell);
this.showItem("spell-separator", canSpell || this.possibleSpellChecking);
if (canSpell)
document.getElementById("spell-check-enabled").setAttribute("checked",
InlineSpellCheckerUI.enabled);
this.showItem("spell-add-to-dictionary", onMisspelling);
// suggestion list
this.showItem("spell-suggestions-separator", onMisspelling);
if (onMisspelling) {
var menu = document.getElementById("contentAreaContextMenu");
var suggestionsSeparator = document.getElementById("spell-add-to-dictionary");
var numsug = InlineSpellCheckerUI.addSuggestionsToMenu(menu, suggestionsSeparator, 5);
this.showItem("spell-no-suggestions", numsug == 0);
} else {
this.showItem("spell-no-suggestions", false);
}
// dictionary list
this.showItem("spell-dictionaries", InlineSpellCheckerUI.enabled);
if (canSpell) {
var dictMenu = document.getElementById("spell-dictionaries-menu");
var dictSep = document.getElementById("spell-language-separator");
InlineSpellCheckerUI.addDictionaryListToMenu(dictMenu, dictSep);
}
// when there is no spellchecker but we might be able to spellcheck
// add the add to dictionaries item. This will ensure that people
// with no dictionaries will be able to download them
this.showItem("spell-add-dictionaries-main", !canSpell && this.possibleSpellChecking);
},
initClipboardItems : function () {
// Copy depends on whether there is selected text.
@@ -236,7 +272,7 @@ nsContextMenu.prototype = {
this.showItem( "context-paste", this.onTextInput );
this.showItem( "context-delete", this.onTextInput );
this.showItem( "context-sep-paste", this.onTextInput );
this.showItem( "context-selectall", true );
this.showItem( "context-selectall", !( this.onLink || this.onImage ) );
this.showItem( "context-sep-selectall", this.isTextSelected && !this.onTextInput );
// In a text area there will be nothing after select all, so we don't want a sep
// Otherwise, if there's text selected then there are extra menu items
@@ -263,7 +299,7 @@ nsContextMenu.prototype = {
this.showItem( "context-metadata", this.onMetaDataItem );
},
// Set various context menu attributes based on the state of the world.
setTarget : function ( node ) {
setTarget : function ( node, rangeParent, rangeOffset ) {
// Initialize contextual info.
this.onImage = false;
this.onLoadedImage = false;
@@ -276,6 +312,7 @@ nsContextMenu.prototype = {
this.inFrame = false;
this.hasBGImage = false;
this.bgImageURL = "";
this.possibleSpellChecking = false;
// Remember the node that was clicked.
this.target = node;
@@ -284,6 +321,35 @@ nsContextMenu.prototype = {
.getService(Components.interfaces.nsIPrefBranch)
.getBoolPref("browser.download.autoDownload");
// Clear any old spellchecking items from the menu, this used to
// be in the menu hiding code but wasn't getting called in all
// situations. Here, we can ensure it gets cleaned up any time the
// menu is shown. Note: must be before uninit because that clears the
// internal vars
InlineSpellCheckerUI.clearSuggestionsFromMenu();
InlineSpellCheckerUI.clearDictionaryListFromMenu();
InlineSpellCheckerUI.uninit();
// if the document is editable, show context menu like in text inputs
var win = this.target.ownerDocument.defaultView;
if (win) {
var editingSession = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIEditingSession);
if (editingSession.windowIsEditable(win)) {
this.onTextInput = true;
this.possibleSpellChecking = true;
InlineSpellCheckerUI.init(editingSession.getEditorForWindow(win));
var canSpell = InlineSpellCheckerUI.canSpellCheck;
InlineSpellCheckerUI.initFromEvent(rangeParent, rangeOffset);
this.showItem("spell-check-enabled", canSpell);
this.showItem("spell-separator", canSpell);
return;
}
}
// See if the user clicked on an image.
if ( this.target.nodeType == Node.ELEMENT_NODE ) {
if ( this.target instanceof Components.interfaces.nsIImageLoadingContent && this.target.currentURI ) {
@@ -296,10 +362,20 @@ nsContextMenu.prototype = {
if ( this.target.ownerDocument instanceof ImageDocument )
this.onStandaloneImage = true;
} else if ( this.target instanceof HTMLInputElement ) {
type = this.target.getAttribute("type");
this.onTextInput = this.isTargetATextBox(this.target);
this.onTextInput = this.isTargetATextBox(this.target);
// allow spellchecking UI on all writable text boxes except passwords
if (!this.target.readOnly && !this.target.disabled && this.target.type == "text") {
this.possibleSpellChecking = true;
InlineSpellCheckerUI.init(this.target.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor);
InlineSpellCheckerUI.initFromEvent(rangeParent, rangeOffset);
}
} else if ( this.target instanceof HTMLTextAreaElement ) {
this.onTextInput = true;
this.onTextInput = true;
if (!this.target.readOnly && !this.target.disabled) {
this.possibleSpellChecking = true;
InlineSpellCheckerUI.init(this.target.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor);
InlineSpellCheckerUI.initFromEvent(rangeParent, rangeOffset);
}
} else if ( this.target instanceof HTMLHtmlElement ) {
// pages with multiple <body>s are lame. we'll teach them a lesson.
var bodyElt = this.target.ownerDocument.getElementsByTagName("body")[0];
@@ -863,6 +939,16 @@ nsContextMenu.prototype = {
}
}
return false;
},
addDictionaries : function()
{
try {
var url = pref.getComplexValue("editor.spellcheckers.url",
Components.interfaces.nsIPrefLocalizedString).data;
window.openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", url);
}
catch (ex) {}
}
};

View File

@@ -50,7 +50,7 @@
<script type="application/x-javascript" src="chrome://global/content/strres.js"/>
<script type="application/x-javascript">
<![CDATA[
var _elementIDs = ["active_languages", "DefaultCharsetList"];
var _elementIDs = ["active_languages", "DefaultCharsetList", "spellcheckDefault"];
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.notifyObservers(null, "charsetmenu-selected", "other");
]]>
@@ -111,4 +111,18 @@
</menulist>
</hbox>
</groupbox>
<groupbox align="start">
<caption label="&spelling.label;"/>
<hbox align="center">
<label value="&checkSpelling.label;" accesskey="&checkSpelling.accesskey;"
control="spellcheckDefault"/>
<menulist id="spellcheckDefault" prefstring="layout.spellcheckDefault">
<menupopup>
<menuitem value="0" label="&dontCheckSpelling.label;"/>
<menuitem value="1" label="&multilineCheckSpelling.label;"/>
<menuitem value="2" label="&alwaysCheckSpelling.label;"/>
</menupopup>
</menulist>
</hbox>
</groupbox>
</page>

View File

@@ -99,4 +99,12 @@
<!ENTITY bidiSwitchPageDirectionItem.accesskey "g">
<!ENTITY bidiSwitchTextDirectionItem.label "Switch Text Direction">
<!ENTITY bidiSwitchTextDirectionItem.accesskey "w">
<!ENTITY spellAddToDictionary.label "Add to dictionary">
<!ENTITY spellAddToDictionary.accesskey "t">
<!ENTITY spellEnable.label "Spell check this field">
<!ENTITY spellEnable.accesskey "S">
<!ENTITY spellNoSuggestions.label "(No spelling suggestions)">
<!ENTITY spellDictionaries.label "Languages">
<!ENTITY spellDictionaries.accesskey "L">
<!ENTITY spellAddDictionaries.label "Download more dictionaries...">
<!ENTITY spellAddDictionaries.accesskey "D">

View File

@@ -177,7 +177,8 @@
</ol>
<p>The Languages preferences panel allows you to choose the languages and
character encoding for displaying web pages:</p>
character encoding for displaying web pages and choose if and how your typing
is spell checked:</p>
<ul>
<li><strong>Languages for Web Pages</strong>:
@@ -198,6 +199,12 @@
pages.</li>
</ul>
</li>
<li><strong>Spelling:</strong>
<ul>
<li><strong>When typing check my spelling</strong>: Use the drop-down
list to select if and how your typing is spell checked.</li>
</ul>
</li>
</ul>
<p>[<a href="#navigator_preferences">Return to beginning of section</a>]</p>

View File

@@ -37,3 +37,9 @@
<!ENTITY languages.customize.moveDown.label "Move Down">
<!ENTITY languages.customize.moveDown.accesskey "d">
<!ENTITY spelling.label "Spelling">
<!ENTITY checkSpelling.label "When typing check my spelling:">
<!ENTITY checkSpelling.accesskey "W">
<!ENTITY dontCheckSpelling.label "Never">
<!ENTITY multilineCheckSpelling.label "In multiline boxes">
<!ENTITY alwaysCheckSpelling.label "All boxes">

View File

@@ -62,6 +62,12 @@
list-style-image: url("chrome://communicator/skin/icons/online.gif");
}
/* ::::: spell checker ::::: */
.spell-suggestion {
font-weight: bold;
}
/* ::::: directional button icons ::::: */
.up {

View File

@@ -57,6 +57,12 @@
list-style-image: url("chrome://communicator/skin/icons/online.gif");
}
/* ::::: spell checker ::::: */
.spell-suggestion {
font-weight: bold;
}
/* ::::: directional button icons ::::: */
.up {

View File

@@ -189,6 +189,13 @@ pref("news.directory", "");
pref("browser.editor.disabled", false);
pref("spellchecker.dictionary", "");
// this will automatically enable inline spellchecking (if it is available) for
// editable elements in HTML
// 0 = spellcheck nothing
// 1 = check multi-line controls [default]
// 2 = check multi/single line controls
pref("layout.spellcheckDefault", 1);
pref("extensions.getMoreLocalesURL", "chrome://branding/locale/brand.properties");
pref("xpinstall.dialog.confirm", "chrome://communicator/content/xpinstall/institems.xul");

View File

@@ -25,6 +25,7 @@ toolkit.jar:
content/global/nsTransferable.js (resources/content/nsTransferable.js)
content/global/nsUserSettings.js (resources/content/nsUserSettings.js)
content/global/xul.css (resources/content/xul.css)
* content/global/inlineSpellCheckUI.js (/toolkit/content/inlineSpellCheckUI.js)
content/global/plugins.html (/toolkit/content/plugins.html)
content/global/plugins.css (/toolkit/content/plugins.css)
content/global/printdialog.xul (resources/content/printdialog.xul)