OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/editing/spellcheck/HotModeSpellCheckRequester.h" | 5 #include "core/editing/spellcheck/HotModeSpellCheckRequester.h" |
6 | 6 |
7 #include "core/editing/EditingUtilities.h" | 7 #include "core/editing/EditingUtilities.h" |
8 #include "core/editing/Editor.h" | 8 #include "core/editing/Editor.h" |
9 #include "core/editing/VisiblePosition.h" | 9 #include "core/editing/VisiblePosition.h" |
10 #include "core/editing/commands/CompositeEditCommand.h" | 10 #include "core/editing/commands/CompositeEditCommand.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 const int fullLength = TextIterator::rangeLength(fullRange.startPosition(), | 66 const int fullLength = TextIterator::rangeLength(fullRange.startPosition(), |
67 fullRange.endPosition()); | 67 fullRange.endPosition()); |
68 if (fullLength <= kHotModeChunkSize) | 68 if (fullLength <= kHotModeChunkSize) |
69 return fullRange; | 69 return fullRange; |
70 | 70 |
71 TextIteratorBehavior behavior = TextIteratorBehavior::Builder() | 71 TextIteratorBehavior behavior = TextIteratorBehavior::Builder() |
72 .setEmitsObjectReplacementCharacter(true) | 72 .setEmitsObjectReplacementCharacter(true) |
73 .build(); | 73 .build(); |
74 BackwardsCharacterIterator backwardIterator(fullRange.startPosition(), | 74 BackwardsCharacterIterator backwardIterator(fullRange.startPosition(), |
75 position, behavior); | 75 position, behavior); |
76 backwardIterator.advance(kHotModeChunkSize / 2); | 76 if (!backwardIterator.atEnd()) |
| 77 backwardIterator.advance(kHotModeChunkSize / 2); |
77 const Position& chunkStart = backwardIterator.endPosition(); | 78 const Position& chunkStart = backwardIterator.endPosition(); |
78 CharacterIterator forwardIterator(position, fullRange.endPosition(), | 79 CharacterIterator forwardIterator(position, fullRange.endPosition(), |
79 behavior); | 80 behavior); |
80 forwardIterator.advance(kHotModeChunkSize / 2); | 81 if (!forwardIterator.atEnd()) |
| 82 forwardIterator.advance(kHotModeChunkSize / 2); |
81 const Position& chunkEnd = forwardIterator.endPosition(); | 83 const Position& chunkEnd = forwardIterator.endPosition(); |
82 return expandRangeToSentenceBoundary(EphemeralRange(chunkStart, chunkEnd)); | 84 return expandRangeToSentenceBoundary(EphemeralRange(chunkStart, chunkEnd)); |
83 } | 85 } |
84 | 86 |
85 } // namespace | 87 } // namespace |
86 | 88 |
87 HotModeSpellCheckRequester::HotModeSpellCheckRequester( | 89 HotModeSpellCheckRequester::HotModeSpellCheckRequester( |
88 SpellCheckRequester& requester) | 90 SpellCheckRequester& requester) |
89 : m_requester(requester) {} | 91 : m_requester(requester) {} |
90 | 92 |
91 void HotModeSpellCheckRequester::checkSpellingAt(const Position& position) { | 93 void HotModeSpellCheckRequester::checkSpellingAt(const Position& position) { |
92 const Element* rootEditable = rootEditableElementOf(position); | 94 const Element* rootEditable = rootEditableElementOf(position); |
93 if (!rootEditable || !rootEditable->isConnected()) | 95 if (!rootEditable || !rootEditable->isConnected()) |
94 return; | 96 return; |
95 | 97 |
96 if (m_processedRootEditables.contains(rootEditable)) | 98 if (m_processedRootEditables.contains(rootEditable)) |
97 return; | 99 return; |
98 m_processedRootEditables.push_back(rootEditable); | 100 m_processedRootEditables.push_back(rootEditable); |
99 | 101 |
100 if (!shouldCheckRootEditableInHotMode(*rootEditable, position)) | 102 if (!shouldCheckRootEditableInHotMode(*rootEditable, position)) |
101 return; | 103 return; |
102 | 104 |
103 SpellCheckRequest* request = SpellCheckRequest::create( | 105 SpellCheckRequest* request = SpellCheckRequest::create( |
104 calculateHotModeCheckingRange(*rootEditable, position)); | 106 calculateHotModeCheckingRange(*rootEditable, position)); |
105 m_requester->requestCheckingFor(request); | 107 m_requester->requestCheckingFor(request); |
106 } | 108 } |
107 | 109 |
108 } // namespace blink | 110 } // namespace blink |
OLD | NEW |