1683// Helper function to determine whether text is a single word.
1684static bool isASingleWord(const String& text)
1685{
1686 TextBreakIterator* it = wordBreakIterator(text.characters(), text.length());
1687 return it && textBreakNext(it) == static_cast<int>(text.length());
1688}
1689
1690bool Editor::isWordMisspelledAtCaret(Node* clickedNode) const
1691{
1692 // Don't do anything if the spelling for the node is forbidden.
1693 if (!isContinuousSpellCheckingEnabled() || !clickedNode || !isSpellCheckingEnabledFor(clickedNode))
1694 return false;
1695
1696 VisibleSelection selection = m_frame->selection()->selection();
1697 if (!selection.isContentEditable() || !selection.isCaret())
1698 return false;
1699
1700 // Get selected text to check for multiple word selection.
1701 String selectedString = selectedText().stripWhiteSpace();
1702
1703 // If some text was already selected, we don't change the selection.
1704 if (!selectedString.isEmpty()) {
1705 // Don't provide suggestions for multiple words.
1706 if (!isASingleWord(selectedString))
1707 return false;
1708 }
1709
1710 // Get the word arround the caret.
1711 selection.expandUsingGranularity(WordGranularity);
1712 RefPtr<Range> range = selection.toNormalizedRange();
1713 ASSERT(range);
1714 String word = selection.toNormalizedRange()->text();
1715 int wordLength = word.length();
1716
1717 if (word.isEmpty() || !client())
1718 return false;
1719
1720 int misspellingLocation = -1;
1721 int misspellingLength = 0;
1722 textChecker()->checkSpellingOfString(word.characters(), wordLength, &misspellingLocation, &misspellingLength);
1723
1724 return misspellingLength == wordLength ? true : false;
1725}
1726