Commit 26470a9d authored by xiaochengh's avatar xiaochengh Committed by Commit bot

Cleanup overloads of isSpellCheckingEnabledFor

This patch cleans up the two overloads of the function as follows:

SpellChecker::isSpellCheckingEnabledFor(const VisibleSelection&) is changed
into a static function in SpellChecker.cpp since it does not have call site
outside SpellChecker.

SpellChecker::isSpellCheckingEnabledFor(const Node*) is absorbed by is wrapper
SpellChecker::isSpellCheckingEnabledInFocusedNode().

BUG=n/a
TEST=n/a; no behavior change

Review-Url: https://codereview.chromium.org/2273253002
Cr-Commit-Position: refs/heads/master@{#414333}
parent db74e2bf
...@@ -76,6 +76,23 @@ bool isSelectionInTextFormControl(const VisibleSelection& selection) ...@@ -76,6 +76,23 @@ bool isSelectionInTextFormControl(const VisibleSelection& selection)
return !!enclosingTextFormControl(selection.start()); return !!enclosingTextFormControl(selection.start());
} }
static bool isSpellCheckingEnabledFor(const VisibleSelection& selection)
{
if (selection.isNone())
return false;
// TODO(tkent): The following password type check should be done in
// HTMLElement::spellcheck(). crbug.com/371567
if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection.start())) {
if (isHTMLInputElement(textControl) && toHTMLInputElement(textControl)->type() == InputTypeNames::password)
return false;
}
if (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*selection.start().anchorNode())) {
if (element->isSpellCheckingEnabled())
return true;
}
return false;
}
static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range) static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range)
{ {
DCHECK(range.isNotNull()); DCHECK(range.isNotNull());
...@@ -298,7 +315,7 @@ void SpellChecker::clearMisspellingsAndBadGrammar(const VisibleSelection &moving ...@@ -298,7 +315,7 @@ void SpellChecker::clearMisspellingsAndBadGrammar(const VisibleSelection &moving
void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& selection) void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& selection)
{ {
if (!isSpellCheckingEnabled()) if (!isSpellCheckingEnabled() || !isSpellCheckingEnabledFor(selection))
return; return;
const EphemeralRange& range = selection.toNormalizedEphemeralRange(); const EphemeralRange& range = selection.toNormalizedEphemeralRange();
...@@ -310,9 +327,6 @@ void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& selecti ...@@ -310,9 +327,6 @@ void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& selecti
if (!editableNode || !hasEditableStyle(*editableNode)) if (!editableNode || !hasEditableStyle(*editableNode))
return; return;
if (!isSpellCheckingEnabledFor(editableNode))
return;
chunkAndMarkAllMisspellingsAndBadGrammar(range); chunkAndMarkAllMisspellingsAndBadGrammar(range);
} }
...@@ -386,38 +400,17 @@ void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word ...@@ -386,38 +400,17 @@ void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word
markMisspellingsAndBadGrammar(adjacentWords); markMisspellingsAndBadGrammar(adjacentWords);
} }
bool SpellChecker::isSpellCheckingEnabledFor(const Node* node) const bool SpellChecker::isSpellCheckingEnabledInFocusedNode() const
{ {
if (!node) Node* focusedNode = frame().selection().start().anchorNode();
if (!focusedNode)
return false; return false;
const Element* focusedElement = node->isElementNode() ? toElement(node) : node->parentElement(); const Element* focusedElement = focusedNode->isElementNode() ? toElement(focusedNode) : focusedNode->parentElement();
if (!focusedElement) if (!focusedElement)
return false; return false;
return focusedElement->isSpellCheckingEnabled(); return focusedElement->isSpellCheckingEnabled();
} }
bool SpellChecker::isSpellCheckingEnabledInFocusedNode() const
{
return isSpellCheckingEnabledFor(frame().selection().start().anchorNode());
}
bool SpellChecker::isSpellCheckingEnabledFor(const VisibleSelection& selection)
{
if (selection.isNone())
return false;
// TODO(tkent): The following password type check should be done in
// HTMLElement::spellcheck(). crbug.com/371567
if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection.start())) {
if (isHTMLInputElement(textControl) && toHTMLInputElement(textControl)->type() == InputTypeNames::password)
return false;
}
if (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*selection.start().anchorNode())) {
if (element->spellcheck())
return true;
}
return false;
}
void SpellChecker::markMisspellingsAfterReplaceSelectionCommand(const ReplaceSelectionCommand& cmd) void SpellChecker::markMisspellingsAfterReplaceSelectionCommand(const ReplaceSelectionCommand& cmd)
{ {
TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterReplaceSelectionCommand"); TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterReplaceSelectionCommand");
...@@ -830,7 +823,7 @@ void SpellChecker::cancelCheck() ...@@ -830,7 +823,7 @@ void SpellChecker::cancelCheck()
void SpellChecker::requestTextChecking(const Element& element) void SpellChecker::requestTextChecking(const Element& element)
{ {
if (!isSpellCheckingEnabledFor(&element)) if (!element.isSpellCheckingEnabled())
return; return;
const EphemeralRange rangeToCheck = EphemeralRange::rangeOfContents(element); const EphemeralRange rangeToCheck = EphemeralRange::rangeOfContents(element);
m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextCheckingProcessBatch, rangeToCheck)); m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextCheckingProcessBatch, rangeToCheck));
......
...@@ -60,8 +60,6 @@ public: ...@@ -60,8 +60,6 @@ public:
void toggleSpellCheckingEnabled(); void toggleSpellCheckingEnabled();
void ignoreSpelling(); void ignoreSpelling();
bool isSpellCheckingEnabledInFocusedNode() const; bool isSpellCheckingEnabledInFocusedNode() const;
bool isSpellCheckingEnabledFor(const Node*) const;
static bool isSpellCheckingEnabledFor(const VisibleSelection&);
void markMisspellingsAfterApplyingCommand(const CompositeEditCommand&); void markMisspellingsAfterApplyingCommand(const CompositeEditCommand&);
void markAndReplaceFor(SpellCheckRequest*, const Vector<TextCheckingResult>&); void markAndReplaceFor(SpellCheckRequest*, const Vector<TextCheckingResult>&);
void advanceToNextMisspelling(bool startBeforeSelection = false); void advanceToNextMisspelling(bool startBeforeSelection = false);
......
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