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
endOfParagraph(wordSelection.visibleEnd()));
markAllMisspellingsAndBadGrammarInRanges(
textCheckingOptions, wordSelection.toNormalizedRange().get(),
wholeParagraph.toNormalizedRange().get());
textCheckingOptions, wordSelection.toNormalizedEphemeralRange(),
wholeParagraph.toNormalizedEphemeralRange());
} else {
RefPtrWillBeRawPtr<Range> misspellingRange = nullptr;
markMisspellings(wordSelection, misspellingRange);
......@@ -390,9 +390,9 @@ void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word
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());
markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedEphemeralRange(), selectedSentence.toNormalizedEphemeralRange());
} else {
markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedRange().get(), adjacentWords.toNormalizedRange().get());
markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, adjacentWords.toNormalizedEphemeralRange(), adjacentWords.toNormalizedEphemeralRange());
}
return;
}
......@@ -468,25 +468,25 @@ void SpellChecker::markBadGrammar(const VisibleSelection& selection)
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());
bool shouldMarkGrammar = textCheckingOptions & TextCheckingTypeGrammar;
// This function is called with selections already expanded to word boundaries.
if (!spellingRange || (shouldMarkGrammar && !grammarRange))
if (spellingRange.isNull() || (shouldMarkGrammar && grammarRange.isNull()))
return;
// If we're not in an editable node, bail.
Node* editableNode = spellingRange->startContainer();
Node* editableNode = spellingRange.startPosition().computeContainerNode();
if (!editableNode || !editableNode->hasEditableStyle())
return;
if (!isSpellCheckingEnabledFor(editableNode))
return;
Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange;
RefPtrWillBeRawPtr<Range> rangeToCheck = createRange(shouldMarkGrammar ? grammarRange : spellingRange);
TextCheckingParagraph fullParagraphToCheck(rangeToCheck);
bool asynchronous = frame().settings() && frame().settings()->asynchronousSpellCheckingEnabled();
......@@ -643,7 +643,7 @@ void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& spellin
TextCheckingTypeMask textCheckingOptions = TextCheckingTypeSpelling;
if (markGrammar && isGrammarCheckingEnabled())
textCheckingOptions |= TextCheckingTypeGrammar;
markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSelection.toNormalizedRange().get(), grammarSelection.toNormalizedRange().get());
markAllMisspellingsAndBadGrammarInRanges(textCheckingOptions, spellingSelection.toNormalizedEphemeralRange(), grammarSelection.toNormalizedEphemeralRange());
return;
}
......
......@@ -67,7 +67,7 @@ public:
void markBadGrammar(const VisibleSelection&);
void markMisspellingsAndBadGrammar(const VisibleSelection& spellingSelection, bool markGrammar, const VisibleSelection& grammarSelection);
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 showSpellingGuessPanel();
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