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)
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)
{
DCHECK(range.isNotNull());
......@@ -298,7 +315,7 @@ void SpellChecker::clearMisspellingsAndBadGrammar(const VisibleSelection &moving
void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& selection)
{
if (!isSpellCheckingEnabled())
if (!isSpellCheckingEnabled() || !isSpellCheckingEnabledFor(selection))
return;
const EphemeralRange& range = selection.toNormalizedEphemeralRange();
......@@ -310,9 +327,6 @@ void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection& selecti
if (!editableNode || !hasEditableStyle(*editableNode))
return;
if (!isSpellCheckingEnabledFor(editableNode))
return;
chunkAndMarkAllMisspellingsAndBadGrammar(range);
}
......@@ -386,38 +400,17 @@ void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word
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;
const Element* focusedElement = node->isElementNode() ? toElement(node) : node->parentElement();
const Element* focusedElement = focusedNode->isElementNode() ? toElement(focusedNode) : focusedNode->parentElement();
if (!focusedElement)
return false;
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)
{
TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterReplaceSelectionCommand");
......@@ -830,7 +823,7 @@ void SpellChecker::cancelCheck()
void SpellChecker::requestTextChecking(const Element& element)
{
if (!isSpellCheckingEnabledFor(&element))
if (!element.isSpellCheckingEnabled())
return;
const EphemeralRange rangeToCheck = EphemeralRange::rangeOfContents(element);
m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextCheckingProcessBatch, rangeToCheck));
......
......@@ -60,8 +60,6 @@ public:
void toggleSpellCheckingEnabled();
void ignoreSpelling();
bool isSpellCheckingEnabledInFocusedNode() const;
bool isSpellCheckingEnabledFor(const Node*) const;
static bool isSpellCheckingEnabledFor(const VisibleSelection&);
void markMisspellingsAfterApplyingCommand(const CompositeEditCommand&);
void markAndReplaceFor(SpellCheckRequest*, const Vector<TextCheckingResult>&);
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