1 /* vim: set ts=2 sw=2 sts=2 tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 var { InlineSpellChecker, SpellCheckHelper } = ChromeUtils.import(
9 "resource://gre/modules/InlineSpellChecker.jsm"
12 var EXPORTED_SYMBOLS = ["InlineSpellCheckerContent"];
14 var InlineSpellCheckerContent = {
18 initContextMenu(event, editFlags, actor) {
22 if (!(editFlags & (SpellCheckHelper.TEXTAREA | SpellCheckHelper.INPUT))) {
23 // Get the editor off the window.
24 let win = event.target.ownerGlobal;
25 let editingSession = win.docShell.editingSession;
26 spellChecker = this._spellChecker = new InlineSpellChecker(
27 editingSession.getEditorForWindow(win)
30 // Use the element's editor.
31 spellChecker = this._spellChecker = new InlineSpellChecker(
32 event.composedTarget.editor
36 this._spellChecker.initFromEvent(event.rangeParent, event.rangeOffset);
38 if (!spellChecker.canSpellCheck) {
41 initialSpellCheckPending: true,
42 enableRealTimeSpell: false,
46 if (!spellChecker.mInlineSpellChecker.enableRealTimeSpell) {
49 initialSpellCheckPending: spellChecker.initialSpellCheckPending,
50 enableRealTimeSpell: false,
54 if (spellChecker.initialSpellCheckPending) {
57 initialSpellCheckPending: true,
58 enableRealTimeSpell: true,
62 let realSpellChecker = spellChecker.mInlineSpellChecker.spellChecker;
63 let dictionaryList = realSpellChecker.GetDictionaryList();
66 canSpellCheck: spellChecker.canSpellCheck,
67 initialSpellCheckPending: spellChecker.initialSpellCheckPending,
68 enableRealTimeSpell: spellChecker.enabled,
69 overMisspelling: spellChecker.overMisspelling,
70 misspelling: spellChecker.mMisspelling,
71 spellSuggestions: this._generateSpellSuggestions(),
72 currentDictionary: spellChecker.mInlineSpellChecker.spellChecker.GetCurrentDictionary(),
79 this._spellChecker = null;
82 _generateSpellSuggestions() {
83 let spellChecker = this._spellChecker.mInlineSpellChecker.spellChecker;
85 spellChecker.CheckCurrentWord(this._spellChecker.mMisspelling);
90 let suggestions = new Array(5);
91 for (let i = 0; i < 5; ++i) {
92 suggestions[i] = spellChecker.GetSuggestedWord();
93 if (suggestions[i].length === 0) {
94 suggestions.length = i;
99 this._spellChecker.mSpellSuggestions = suggestions;
103 selectDictionary(localeCode) {
104 this._spellChecker.selectDictionary(localeCode);
107 replaceMisspelling(index) {
108 this._spellChecker.replaceMisspelling(index);
112 this._spellChecker.toggleEnabled();
116 this._spellChecker.mInlineSpellChecker.enableRealTimeSpell = true;