Commit 0b7cac5b authored by yosin@chromium.org's avatar yosin@chromium.org

Make SpellChecker::markAllMisspellingsAndBadGrammarInRanges() to take EphemeralRange

This patch changes |markAllMisspellingsAndBadGrammarInRanges()| member function
of |SpellChecker| class to take |EphemeralRange| instead of |Range| to avoid
registering temporary |Range| object into |Document|.

This patch is also a preparation of making selection to handle granularity for
web component, http://crrev.com/1277863002 to reduce DOM position dependency
from |VisibleSelection| for ease of templatization of |VisibleSelection|.

BUG=388681, 513568
TEST=n/a; no behavior changes

Review URL: https://codereview.chromium.org/1313863002

git-svn-id: svn://svn.chromium.org/blink/trunk@201117 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent f60b6cfb
...@@ -363,8 +363,8 @@ void SpellChecker::markMisspellingsAfterLineBreak(const VisibleSelection& wordSe ...@@ -363,8 +363,8 @@ void SpellChecker::markMisspellingsAfterLineBreak(const VisibleSelection& wordSe
endOfParagraph(wordSelection.visibleEnd())); endOfParagraph(wordSelection.visibleEnd()));
markAllMisspellingsAndBadGrammarInRanges( markAllMisspellingsAndBadGrammarInRanges(
textCheckingOptions, wordSelection.toNormalizedRange().get(), textCheckingOptions, wordSelection.toNormalizedEphemeralRange(),
wholeParagraph.toNormalizedRange().get()); wholeParagraph.toNormalizedEphemeralRange());
} else { } else {
RefPtrWillBeRawPtr<Range> misspellingRange = nullptr; RefPtrWillBeRawPtr<Range> misspellingRange = nullptr;
markMisspellings(wordSelection, misspellingRange); markMisspellings(wordSelection, misspellingRange);
...@@ -390,9 +390,9 @@ void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word ...@@ -390,9 +390,9 @@ void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word
VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)); VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary));
if (textCheckingOptions & TextCheckingTypeGrammar) { if (textCheckingOptions & TextCheckingTypeGrammar) {
VisibleSelection selectedSentence = VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart)); VisibleSelection selectedSentence = VisibleSelection(startOfSentence(wordStart), endOfSentence(wordStart));
markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), selectedSentence.toNormalizedRange().get()); markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedEphemeralRange(), selectedSentence.toNormalizedEphemeralRange());
} else { } else {
markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), adjacentWords.toNormalizedRange().get()); markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedEphemeralRange(), adjacentWords.toNormalizedEphemeralRange());
} }
return; return;
} }
...@@ -468,25 +468,25 @@ void SpellChecker::markBadGrammar(const VisibleSelection& selection) ...@@ -468,25 +468,25 @@ void SpellChecker::markBadGrammar(const VisibleSelection& selection)
markMisspellingsOrBadGrammar(selection, false, firstMisspellingRange); markMisspellingsOrBadGrammar(selection, false, firstMisspellingRange);
} }
void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, Range* spellingRange, Range* grammarRange) void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask textCheckingOptions, const EphemeralRange& spellingRange, const EphemeralRange& grammarRange)
{ {
ASSERT(unifiedTextCheckerEnabled()); ASSERT(unifiedTextCheckerEnabled());
bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar; bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar;
// This function is called with selections already expanded to word boundaries. // This function is called with selections already expanded to word boundaries.
if (!spellingRange || (shouldMarkGrammar && !grammarRange)) if (spellingRange.isNull() || (shouldMarkGrammar && grammarRange.isNull()))
return; return;
// If we're not in an editable node, bail. // If we're not in an editable node, bail.
Node* editableNode = spellingRange->startContainer(); Node* editableNode = spellingRange.startPosition().computeContainerNode();
if (!editableNode || !editableNode->hasEditableStyle()) if (!editableNode || !editableNode->hasEditableStyle())
return; return;
if (!isSpellCheckingEnabledFor(editableNode)) if (!isSpellCheckingEnabledFor(editableNode))
return; return;
Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange; RefPtrWillBeRawPtr<Range> rangeToCheck = createRange(shouldMarkGrammar ? grammarRange : spellingRange);
TextCheckingParagraph fullParagraphToCheck(rangeToCheck); TextCheckingParagraph fullParagraphToCheck(rangeToCheck);
bool asynchronous = frame().settings() && frame().settings()->asynchronousSpellCheckingEnabled(); bool asynchronous = frame().settings() && frame().settings()->asynchronousSpellCheckingEnabled();
...@@ -643,7 +643,7 @@ void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& spellin ...@@ -643,7 +643,7 @@ void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& spellin
TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling; TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling;
if (markGrammar && isGrammarCheckingEnabled()) if (markGrammar && isGrammarCheckingEnabled())
textCheckingOptions |= TextCheckingTypeGrammar; textCheckingOptions |= TextCheckingTypeGrammar;
markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSelection.toNormalizedRange().get(), grammarSelection.toNormalizedRange().get()); markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSelection.toNormalizedEphemeralRange(), grammarSelection.toNormalizedEphemeralRange());
return; return;
} }
......
...@@ -67,7 +67,7 @@ public: ...@@ -67,7 +67,7 @@ public:
void markBadGrammar(const VisibleSelection&); void markBadGrammar(const VisibleSelection&);
void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection); void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection);
void markAndReplaceFor(PassRefPtrWillBeRawPtr<SpellCheckRequest>, const Vector<TextCheckingResult>&); void markAndReplaceFor(PassRefPtrWillBeRawPtr<SpellCheckRequest>, const Vector<TextCheckingResult>&);
void markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask, Range* spellingRange, Range* grammarRange); void markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask, const EphemeralRange& spellingRange, const EphemeralRange& grammarRange);
void advanceToNextMisspelling(bool startBeforeSelection = false); void advanceToNextMisspelling(bool startBeforeSelection = false);
void showSpellingGuessPanel(); void showSpellingGuessPanel();
void didBeginEditing(Element*); void didBeginEditing(Element*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment