Changeset 100890 in webkit
- Timestamp:
- Nov 21, 2011 1:20:57 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r100886 r100890 1 2011-11-21 Shinya Kawanaka <shinyak@google.com> 2 3 Refactoring: SpellChecker::requestCheckingFor should take Range instead of Node. 4 https://bugs.webkit.org/show_bug.cgi?id=72847 5 6 Reviewed by Hajime Morita. 7 8 Covered by existing test. 9 10 * editing/Editor.cpp: 11 (WebCore::Editor::replaceSelectionWithFragment): 12 Passes Range to requestCheckingFor instead of Node. 13 * editing/SpellChecker.cpp: 14 Changed argument type from Node to Range. 15 The corresponding changes are also done in dependent methods. 16 (WebCore::SpellChecker::initRequest): 17 (WebCore::SpellChecker::clearRequest): 18 (WebCore::SpellChecker::canCheckAsynchronously): 19 (WebCore::SpellChecker::isBusy): 20 (WebCore::SpellChecker::isValid): 21 (WebCore::SpellChecker::isCheckable): 22 (WebCore::SpellChecker::requestCheckingFor): 23 Changed argument type from Node to Range. 24 (WebCore::SpellChecker::doRequestCheckingFor): 25 (WebCore::SpellChecker::didCheck): 26 * editing/SpellChecker.h: 27 1 28 2011-11-20 Kenichi Ishibashi <bashi@chromium.org> 2 29 -
trunk/Source/WebCore/editing/Editor.cpp
r100874 r100890 414 414 415 415 Node* nodeToCheck = m_frame->selection()->rootEditableElement(); 416 if (m_spellChecker->canCheckAsynchronously(nodeToCheck)) 417 m_spellChecker->requestCheckingFor(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), nodeToCheck); 416 if (!nodeToCheck) 417 return; 418 419 m_spellChecker->requestCheckingFor(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), 420 Range::create(m_frame->document(), firstPositionInNode(nodeToCheck), lastPositionInNode(nodeToCheck))); 418 421 } 419 422 -
trunk/Source/WebCore/editing/SpellChecker.cpp
r95901 r100890 40 40 #include "Settings.h" 41 41 #include "TextCheckerClient.h" 42 #include "TextCheckingHelper.h" 42 43 #include "TextIterator.h" 43 44 #include "htmlediting.h" … … 63 64 } 64 65 65 bool SpellChecker::initRequest( Node* node)66 { 67 ASSERT(canCheckAsynchronously( node));68 69 String text = node->textContent();66 bool SpellChecker::initRequest(PassRefPtr<Range> range) 67 { 68 ASSERT(canCheckAsynchronously(range.get())); 69 70 String text = range->text(); 70 71 if (!text.length()) 71 72 return false; 72 73 73 m_request Node = node;74 m_requestRange = range; 74 75 m_requestText = text; 75 76 m_requestSequence++; … … 80 81 void SpellChecker::clearRequest() 81 82 { 82 m_request Node.clear();83 m_requestRange.clear(); 83 84 m_requestText = String(); 84 85 } … … 89 90 } 90 91 91 bool SpellChecker::canCheckAsynchronously( Node* node) const92 { 93 return client() && isCheckable( node) && isAsynchronousEnabled() && !isBusy();92 bool SpellChecker::canCheckAsynchronously(Range* range) const 93 { 94 return client() && isCheckable(range) && isAsynchronousEnabled() && !isBusy(); 94 95 } 95 96 96 97 bool SpellChecker::isBusy() const 97 98 { 98 return m_request Node.get();99 return m_requestRange.get(); 99 100 } 100 101 101 102 bool SpellChecker::isValid(int sequence) const 102 103 { 103 return m_requestNode.get() && m_requestText.length() && m_requestSequence == sequence; 104 } 105 106 bool SpellChecker::isCheckable(Node* node) const 107 { 108 return node && node->renderer(); 109 } 110 111 void SpellChecker::requestCheckingFor(TextCheckingTypeMask mask, Node* node) 112 { 113 ASSERT(canCheckAsynchronously(node)); 114 115 if (!initRequest(node)) 104 return m_requestRange.get() && m_requestText.length() && m_requestSequence == sequence; 105 } 106 107 bool SpellChecker::isCheckable(Range* range) const 108 { 109 return range && range->firstNode() && range->firstNode()->renderer(); 110 } 111 112 void SpellChecker::requestCheckingFor(TextCheckingTypeMask mask, PassRefPtr<Range> range) 113 { 114 if (!canCheckAsynchronously(range.get())) 115 return; 116 117 doRequestCheckingFor(mask, range); 118 } 119 120 void SpellChecker::doRequestCheckingFor(TextCheckingTypeMask mask, PassRefPtr<Range> range) 121 { 122 ASSERT(canCheckAsynchronously(range.get())); 123 124 if (!initRequest(range)) 116 125 return; 117 126 client()->requestCheckingOfString(this, m_requestSequence, mask, m_requestText); … … 154 163 return; 155 164 156 if (! m_requestNode->renderer()) {165 if (!isCheckable(m_requestRange.get())) { 157 166 clearRequest(); 158 167 return; … … 160 169 161 170 int startOffset = 0; 162 PositionIterator start = firstPositionInOrBeforeNode(m_requestNode.get());171 PositionIterator start = m_requestRange->startPosition(); 163 172 for (size_t i = 0; i < results.size(); ++i) { 164 173 if (results[i].type != TextCheckingTypeSpelling && results[i].type != TextCheckingTypeGrammar) … … 178 187 // JavaScript applications, retrieve the words in the specified region and compare them with 179 188 // the original ones. 180 RefPtr<Range> range = Range::create(m_request Node->document(), start, end);189 RefPtr<Range> range = Range::create(m_requestRange->ownerDocument(), start, end); 181 190 // FIXME: Use textContent() compatible string conversion. 182 191 String destination = range->text(); 183 192 String source = m_requestText.substring(results[i].location, results[i].length); 184 193 if (destination == source) 185 m_request Node->document()->markers()->addMarker(range.get(), toMarkerType(results[i].type));194 m_requestRange->ownerDocument()->markers()->addMarker(range.get(), toMarkerType(results[i].type)); 186 195 187 196 startOffset = results[i].location; -
trunk/Source/WebCore/editing/SpellChecker.h
r95901 r100890 39 39 class TextCheckerClient; 40 40 struct TextCheckingResult; 41 class Range; 41 42 42 43 class SpellChecker { … … 47 48 48 49 bool isAsynchronousEnabled() const; 49 bool canCheckAsynchronously( Node*) const;50 bool canCheckAsynchronously(Range*) const; 50 51 bool isBusy() const; 51 52 bool isValid(int sequence) const; 52 bool isCheckable( Node*) const;53 void requestCheckingFor(TextCheckingTypeMask, Node*);53 bool isCheckable(Range*) const; 54 void requestCheckingFor(TextCheckingTypeMask, PassRefPtr<Range>); 54 55 void didCheck(int sequence, const Vector<TextCheckingResult>&); 55 56 56 57 private: 57 bool initRequest( Node*);58 bool initRequest(PassRefPtr<Range>); 58 59 void clearRequest(); 60 void doRequestCheckingFor(TextCheckingTypeMask, PassRefPtr<Range>); 59 61 TextCheckerClient* client() const; 60 62 61 63 Frame* m_frame; 62 64 63 RefPtr< Node> m_requestNode;65 RefPtr<Range> m_requestRange; 64 66 String m_requestText; 65 67 int m_requestSequence;
Note: See TracChangeset
for help on using the changeset viewer.