void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &wordStart, const VisibleSelection& selectionAfterTyping) { if (unifiedTextCheckerEnabled()) { TextCheckingTypeMask textCheckingOptions = 0; if (isContinuousSpellCheckingEnabled()) textCheckingOptions |= TextCheckingTypeSpelling; if (!(textCheckingOptions & TextCheckingTypeSpelling)) return; if (isGrammarCheckingEnabled()) textCheckingOptions |= TextCheckingTypeGrammar; VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)); if (textCheckingOptions & TextCheckingTypeGrammar) { VisibleSelection selectedSentence = VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart)); markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), selectedSentence.toNormalizedRange().get()); } else { markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), adjacentWords.toNormalizedRange().get()); } return; } if (!isContinuousSpellCheckingEnabled()) return; // Check spelling of one word RefPtr<Range> misspellingRange = nullptr; markMisspellings(VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)), misspellingRange); // Autocorrect the misspelled word. if (!misspellingRange) return; // Get the misspelled word. const String misspelledWord = plainText(misspellingRange.get()); String autocorrectedString = textChecker().getAutoCorrectSuggestionForMisspelledWord(misspelledWord); // If autocorrected word is non empty, replace the misspelled word by this word. if (!autocorrectedString.isEmpty()) { VisibleSelection newSelection(misspellingRange.get(), DOWNSTREAM); if (newSelection != m_frame.selection().selection()) { m_frame.selection().setSelection(newSelection); } m_frame.editor().replaceSelectionWithText(autocorrectedString, false, false); // Reset the charet one character further. m_frame.selection().moveTo(m_frame.selection().selection().visibleEnd()); m_frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity); } if (!isGrammarCheckingEnabled()) return; // Check grammar of entire sentence markBadGrammar(VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart))); }
void EditorClientImpl::toggleContinuousSpellChecking() { if (isContinuousSpellCheckingEnabled()) m_spellCheckThisFieldStatus = SpellCheckForcedOff; else m_spellCheckThisFieldStatus = SpellCheckForcedOn; }
void SpellChecker::markMisspellingsOrBadGrammar(const VisibleSelection& selection, bool checkSpelling, RefPtr<Range>& firstMisspellingRange) { // This function is called with a selection already expanded to word boundaries. // Might be nice to assert that here. // This function is used only for as-you-type checking, so if that's off we do nothing. Note that // grammar checking can only be on if spell checking is also on. if (!isContinuousSpellCheckingEnabled()) return; RefPtr<Range> searchRange(selection.toNormalizedRange()); if (!searchRange) return; // If we're not in an editable node, bail. Node* editableNode = searchRange->startContainer(); if (!editableNode || !editableNode->hasEditableStyle()) return; if (!isSpellCheckingEnabledFor(editableNode)) return; TextCheckingHelper checker(spellCheckerClient(), searchRange); if (checkSpelling) checker.markAllMisspellings(firstMisspellingRange); else if (isGrammarCheckingEnabled()) checker.markAllBadGrammar(); }
void EditorClientBlackBerry::toggleContinuousSpellChecking() { // Use the current state to determine how to toggle, if it hasn't // been explicitly set, it will toggle based on the field type. if (isContinuousSpellCheckingEnabled()) m_spellCheckState = SpellCheckOff; else m_spellCheckState = SpellCheckOn; }
void SpellChecker::toggleContinuousSpellChecking() { spellCheckerClient().toggleContinuousSpellChecking(); if (isContinuousSpellCheckingEnabled()) return; LocalFrame* frame = m_frame.page()->mainFrame(); for (Node* node = &frame->document()->rootNode(); node; node = NodeTraversal::next(*node)) { node->setAlreadySpellChecked(false); } }
void SpellChecker::didBeginEditing(Element* element) { if (isContinuousSpellCheckingEnabled() && unifiedTextCheckerEnabled()) { if (!element->isAlreadySpellChecked()) { // We always recheck textfields because markers are removed from them on blur. VisibleSelection selection = VisibleSelection::selectionFromContentsOfNode(element); markMisspellingsAndBadGrammar(selection); element->setAlreadySpellChecked(true); } } }
void EditorClientImpl::toggleContinuousSpellChecking() { if (isContinuousSpellCheckingEnabled()) m_spellCheckThisFieldStatus = SpellCheckForcedOff; else m_spellCheckThisFieldStatus = SpellCheckForcedOn; WebFrameImpl* webframe = WebFrameImpl::fromFrame( m_webView->focusedWebCoreFrame()); if (webframe) webframe->client()->didToggleContinuousSpellChecking(webframe); }
void SpellChecker::spellCheckOldSelection(const VisibleSelection& oldSelection, const VisibleSelection& newAdjacentWords) { VisiblePosition oldStart(oldSelection.visibleStart()); VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary)); if (oldAdjacentWords != newAdjacentWords) { if (isContinuousSpellCheckingEnabled() && isGrammarCheckingEnabled()) { VisibleSelection selectedSentence = VisibleSelection(startOfSentence(oldStart), endOfSentence(oldStart)); markMisspellingsAndBadGrammar(oldAdjacentWords, true, selectedSentence); } else { markMisspellingsAndBadGrammar(oldAdjacentWords, false, oldAdjacentWords); } } }
String EditorClientImpl::getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord) { if (!(isContinuousSpellCheckingEnabled() && m_webView->client())) return String(); // Do not autocorrect words with capital letters in it except the // first letter. This will remove cases changing "IMB" to "IBM". for (size_t i = 1; i < misspelledWord.length(); i++) { if (u_isupper(static_cast<UChar32>(misspelledWord[i]))) return String(); } return m_webView->client()->autoCorrectWord(WebString(misspelledWord)); }
void EditorClientImpl::toggleContinuousSpellChecking() { if (isContinuousSpellCheckingEnabled()) { m_spellCheckThisFieldStatus = SpellCheckForcedOff; } else { m_spellCheckThisFieldStatus = SpellCheckForcedOn; const Frame* frame = m_webView->focusedWebCoreFrame(); if (frame) { VisibleSelection frameSelection = frame->selection()->selection(); Element* rootEditableElement = frameSelection.rootEditableElement(); // If a selection is in an editable element spell check its content. if (rootEditableElement) { VisibleSelection selection = VisibleSelection::selectionFromContentsOfNode(rootEditableElement); frame->editor()->markMisspellingsAndBadGrammar(selection); } } } }
void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection) { if (unifiedTextCheckerEnabled()) { if (!isContinuousSpellCheckingEnabled()) return; // markMisspellingsAndBadGrammar() is triggered by selection change, in which case we check spelling and grammar, but don't autocorrect misspellings. TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling; if (markGrammar && isGrammarCheckingEnabled()) textCheckingOptions |= TextCheckingTypeGrammar; markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSelection.toNormalizedRange().get(), grammarSelection.toNormalizedRange().get()); return; } RefPtr<Range> firstMisspellingRange = nullptr; markMisspellings(spellingSelection, firstMisspellingRange); if (markGrammar) markBadGrammar(grammarSelection); }
void EditorClientImpl::toggleContinuousSpellChecking() { if (isContinuousSpellCheckingEnabled()) { m_spellCheckThisFieldStatus = SpellCheckForcedOff; if (Page* page = m_webView->page()) { for (Frame* frame = page->mainFrame(); frame && frame->document(); frame = frame->tree()->traverseNext()) { frame->document()->markers()->removeMarkers(DocumentMarker::MisspellingMarkers()); } } } else { m_spellCheckThisFieldStatus = SpellCheckForcedOn; if (Frame* frame = m_webView->focusedWebCoreFrame()) { VisibleSelection frameSelection = frame->selection().selection(); // If a selection is in an editable element spell check its content. if (Element* rootEditableElement = frameSelection.rootEditableElement()) { frame->editor().elementDidBeginEditing(rootEditableElement); } } } }
void SpellChecker::markMisspellingsAfterLineBreak(const VisibleSelection& wordSelection) { if (unifiedTextCheckerEnabled()) { TextCheckingTypeMask textCheckingOptions = 0; if (isContinuousSpellCheckingEnabled()) textCheckingOptions |= TextCheckingTypeSpelling; if (isGrammarCheckingEnabled()) textCheckingOptions |= TextCheckingTypeGrammar; VisibleSelection wholeParagraph( startOfParagraph(wordSelection.visibleStart()), endOfParagraph(wordSelection.visibleEnd())); markAllMisspellingsAndBadGrammarInRanges( textCheckingOptions, wordSelection.toNormalizedRange().get(), wholeParagraph.toNormalizedRange().get()); } else { RefPtr<Range> misspellingRange = wordSelection.firstRange(); markMisspellings(wordSelection, misspellingRange); } }
void EditorClientImpl::checkSpellingOfString(const UChar* text, int length, int* misspellingLocation, int* misspellingLength) { // SpellCheckWord will write (0, 0) into the output vars, which is what our // caller expects if the word is spelled correctly. int spellLocation = -1; int spellLength = 0; // Check to see if the provided text is spelled correctly. if (isContinuousSpellCheckingEnabled() && m_webView->spellCheckClient()) m_webView->spellCheckClient()->spellCheck(WebString(text, length), spellLocation, spellLength, 0); else { spellLocation = 0; spellLength = 0; } // Note: the Mac code checks if the pointers are null before writing to them, // so we do too. if (misspellingLocation) *misspellingLocation = spellLocation; if (misspellingLength) *misspellingLength = spellLength; }
void Editor::markMisspellingsAfterTypingToPosition(const VisiblePosition& p) { if (!isContinuousSpellCheckingEnabled()) return; }
void WebLocalFrameImpl::enableContinuousSpellChecking(bool enable) { if (enable == isContinuousSpellCheckingEnabled()) return; frame()->spellChecker().toggleContinuousSpellChecking(); }
void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection &movingSelection) { markMisspellingsAndBadGrammar(movingSelection, isContinuousSpellCheckingEnabled() && isGrammarCheckingEnabled(), movingSelection); }