Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Unified Diff: third_party/WebKit/Source/core/editing/spellcheck/TextCheckingParagraph.cpp

Issue 2247003005: Eliminate class TextCheckingHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@CleanupUnifiedTextChecker
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/spellcheck/TextCheckingParagraph.cpp
diff --git a/third_party/WebKit/Source/core/editing/spellcheck/TextCheckingHelper.cpp b/third_party/WebKit/Source/core/editing/spellcheck/TextCheckingParagraph.cpp
similarity index 53%
rename from third_party/WebKit/Source/core/editing/spellcheck/TextCheckingHelper.cpp
rename to third_party/WebKit/Source/core/editing/spellcheck/TextCheckingParagraph.cpp
index 4af7115c45741184e3e8280495ed578377055952..90d380a501657f36a3c0788e4a6bfffb17206267 100644
--- a/third_party/WebKit/Source/core/editing/spellcheck/TextCheckingHelper.cpp
+++ b/third_party/WebKit/Source/core/editing/spellcheck/TextCheckingParagraph.cpp
@@ -24,7 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "core/editing/spellcheck/TextCheckingHelper.h"
+#include "core/editing/spellcheck/TextCheckingParagraph.h"
#include "core/dom/Document.h"
#include "core/dom/Range.h"
@@ -32,50 +32,9 @@
#include "core/editing/VisibleUnits.h"
#include "core/editing/iterators/CharacterIterator.h"
#include "core/editing/iterators/WordAwareIterator.h"
-#include "core/editing/markers/DocumentMarkerController.h"
-#include "core/frame/LocalFrame.h"
-#include "core/frame/Settings.h"
-#include "core/page/SpellCheckerClient.h"
-#include "platform/text/TextBreakIterator.h"
-#include "platform/text/TextCheckerClient.h"
namespace blink {
-static void findMisspellings(TextCheckerClient& client, const String& text, Vector<TextCheckingResult>& results)
yosin_UTC9 2016/08/16 06:04:06 Let's move class here, then re-factor.
-{
- Vector<UChar> characters;
- text.appendTo(characters);
- unsigned length = text.length();
-
- TextBreakIterator* iterator = wordBreakIterator(characters.data(), length);
- if (!iterator)
- return;
-
- int wordStart = iterator->current();
- while (0 <= wordStart) {
- int wordEnd = iterator->next();
- if (wordEnd < 0)
- break;
- int wordLength = wordEnd - wordStart;
- int misspellingLocation = -1;
- int misspellingLength = 0;
- client.checkSpellingOfString(String(characters.data() + wordStart, wordLength), &misspellingLocation, &misspellingLength);
- if (0 < misspellingLength) {
- DCHECK_LE(0, misspellingLocation);
- DCHECK_LE(misspellingLocation, wordLength);
- DCHECK_LT(0, misspellingLength);
- DCHECK_LE(misspellingLocation + misspellingLength, wordLength);
- TextCheckingResult misspelling;
- misspelling.decoration = TextDecorationTypeSpelling;
- misspelling.location = wordStart + misspellingLocation;
- misspelling.length = misspellingLength;
- results.append(misspelling);
- }
-
- wordStart = wordEnd;
- }
-}
-
static EphemeralRange expandToParagraphBoundary(const EphemeralRange& range)
{
const VisiblePosition& start = createVisiblePosition(range.startPosition());
@@ -221,88 +180,4 @@ int TextCheckingParagraph::checkingLength() const
return m_checkingLength;
}
-TextCheckingHelper::TextCheckingHelper(SpellCheckerClient& client, const Position& start, const Position& end)
- : m_client(&client)
- , m_start(start)
- , m_end(end)
-{
-}
-
-TextCheckingHelper::~TextCheckingHelper()
-{
-}
-
-String TextCheckingHelper::findFirstMisspellingOrBadGrammar(int& outFirstFoundOffset)
-{
- String firstFoundItem;
- String misspelledWord;
-
- // Initialize out parameter; it will be updated if we find something to return.
- outFirstFoundOffset = 0;
-
- // Expand the search range to encompass entire paragraphs, since text checking needs that much context.
- // Determine the character offset from the start of the paragraph to the start of the original search range,
- // since we will want to ignore results in this area.
- Position paragraphStart = startOfParagraph(createVisiblePosition(m_start)).toParentAnchoredPosition();
- Position paragraphEnd = m_end;
- int totalRangeLength = TextIterator::rangeLength(paragraphStart, paragraphEnd);
- paragraphEnd = endOfParagraph(createVisiblePosition(m_start)).toParentAnchoredPosition();
-
- int rangeStartOffset = TextIterator::rangeLength(paragraphStart, m_start);
- int totalLengthProcessed = 0;
-
- bool firstIteration = true;
- bool lastIteration = false;
- while (totalLengthProcessed < totalRangeLength) {
- // Iterate through the search range by paragraphs, checking each one for spelling.
- int currentLength = TextIterator::rangeLength(paragraphStart, paragraphEnd);
- int currentStartOffset = firstIteration ? rangeStartOffset : 0;
- int currentEndOffset = currentLength;
- if (inSameParagraph(createVisiblePosition(paragraphStart), createVisiblePosition(m_end))) {
- // Determine the character offset from the end of the original search range to the end of the paragraph,
- // since we will want to ignore results in this area.
- currentEndOffset = TextIterator::rangeLength(paragraphStart, m_end);
- lastIteration = true;
- }
- if (currentStartOffset < currentEndOffset) {
- String paragraphString = plainText(EphemeralRange(paragraphStart, paragraphEnd));
- if (paragraphString.length() > 0) {
- int spellingLocation = 0;
-
- Vector<TextCheckingResult> results;
- findMisspellings(m_client->textChecker(), paragraphString, results);
-
- for (unsigned i = 0; i < results.size(); i++) {
- const TextCheckingResult* result = &results[i];
- if (result->decoration == TextDecorationTypeSpelling && result->location >= currentStartOffset && result->location + result->length <= currentEndOffset) {
- DCHECK_GT(result->length, 0);
- DCHECK_GE(result->location, 0);
- spellingLocation = result->location;
- misspelledWord = paragraphString.substring(result->location, result->length);
- DCHECK(misspelledWord.length());
- break;
- }
- }
-
- if (!misspelledWord.isEmpty()) {
- int spellingOffset = spellingLocation - currentStartOffset;
- if (!firstIteration)
- spellingOffset += TextIterator::rangeLength(m_start, paragraphStart);
- outFirstFoundOffset = spellingOffset;
- firstFoundItem = misspelledWord;
- break;
- }
- }
- }
- if (lastIteration || totalLengthProcessed + currentLength >= totalRangeLength)
- break;
- VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePosition(paragraphEnd));
- paragraphStart = newParagraphStart.toParentAnchoredPosition();
- paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition();
- firstIteration = false;
- totalLengthProcessed += currentLength;
- }
- return firstFoundItem;
-}
-
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698