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

Side by Side Diff: Source/WebCore/editing/SpellChecker.cpp

Issue 7005023: Merge 86132 - 2011-05-10 MORITA Hajime <morrita@google.com> (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/742/
Patch Set: Created 9 years, 7 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 unified diff | Download patch
« no previous file with comments | « Source/WebCore/editing/SpellChecker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 15 matching lines...) Expand all
26 #include "config.h" 26 #include "config.h"
27 #include "SpellChecker.h" 27 #include "SpellChecker.h"
28 28
29 #include "Document.h" 29 #include "Document.h"
30 #include "DocumentMarkerController.h" 30 #include "DocumentMarkerController.h"
31 #include "EditorClient.h" 31 #include "EditorClient.h"
32 #include "Frame.h" 32 #include "Frame.h"
33 #include "HTMLInputElement.h" 33 #include "HTMLInputElement.h"
34 #include "HTMLTextAreaElement.h" 34 #include "HTMLTextAreaElement.h"
35 #include "Node.h" 35 #include "Node.h"
36 #include "Page.h"
36 #include "PositionIterator.h" 37 #include "PositionIterator.h"
37 #include "Range.h" 38 #include "Range.h"
38 #include "RenderObject.h" 39 #include "RenderObject.h"
39 #include "Settings.h" 40 #include "Settings.h"
40 #include "TextCheckerClient.h" 41 #include "TextCheckerClient.h"
41 #include "TextIterator.h" 42 #include "TextIterator.h"
42 #include "htmlediting.h" 43 #include "htmlediting.h"
43 44
44 namespace WebCore { 45 namespace WebCore {
45 46
46 SpellChecker::SpellChecker(Frame* frame, TextCheckerClient* client) 47 SpellChecker::SpellChecker(Frame* frame)
47 : m_frame(frame) 48 : m_frame(frame)
48 , m_client(client)
49 , m_requestSequence(0) 49 , m_requestSequence(0)
50 { 50 {
51 } 51 }
52 52
53 SpellChecker::~SpellChecker() 53 SpellChecker::~SpellChecker()
54 { 54 {
55 } 55 }
56 56
57 TextCheckerClient* SpellChecker::client() const
58 {
59 Page* page = m_frame->page();
60 if (!page)
61 return 0;
62 return page->editorClient()->textChecker();
63 }
64
57 bool SpellChecker::initRequest(Node* node) 65 bool SpellChecker::initRequest(Node* node)
58 { 66 {
59 ASSERT(canCheckAsynchronously(node)); 67 ASSERT(canCheckAsynchronously(node));
60 68
61 String text = node->textContent(); 69 String text = node->textContent();
62 if (!text.length()) 70 if (!text.length())
63 return false; 71 return false;
64 72
65 m_requestNode = node; 73 m_requestNode = node;
66 m_requestText = text; 74 m_requestText = text;
67 m_requestSequence++; 75 m_requestSequence++;
68 76
69 return true; 77 return true;
70 } 78 }
71 79
72 void SpellChecker::clearRequest() 80 void SpellChecker::clearRequest()
73 { 81 {
74 m_requestNode.clear(); 82 m_requestNode.clear();
75 m_requestText = String(); 83 m_requestText = String();
76 } 84 }
77 85
78 bool SpellChecker::isAsynchronousEnabled() const 86 bool SpellChecker::isAsynchronousEnabled() const
79 { 87 {
80 return m_frame->settings() && m_frame->settings()->asynchronousSpellChecking Enabled(); 88 return m_frame->settings() && m_frame->settings()->asynchronousSpellChecking Enabled();
81 } 89 }
82 90
83 bool SpellChecker::canCheckAsynchronously(Node* node) const 91 bool SpellChecker::canCheckAsynchronously(Node* node) const
84 { 92 {
85 return isCheckable(node) && isAsynchronousEnabled() && !isBusy(); 93 return client() && isCheckable(node) && isAsynchronousEnabled() && !isBusy() ;
86 } 94 }
87 95
88 bool SpellChecker::isBusy() const 96 bool SpellChecker::isBusy() const
89 { 97 {
90 return m_requestNode.get(); 98 return m_requestNode.get();
91 } 99 }
92 100
93 bool SpellChecker::isValid(int sequence) const 101 bool SpellChecker::isValid(int sequence) const
94 { 102 {
95 return m_requestNode.get() && m_requestText.length() && m_requestSequence == sequence; 103 return m_requestNode.get() && m_requestText.length() && m_requestSequence == sequence;
96 } 104 }
97 105
98 bool SpellChecker::isCheckable(Node* node) const 106 bool SpellChecker::isCheckable(Node* node) const
99 { 107 {
100 return node && node->renderer(); 108 return node && node->renderer();
101 } 109 }
102 110
103 void SpellChecker::requestCheckingFor(TextCheckingTypeMask mask, Node* node) 111 void SpellChecker::requestCheckingFor(TextCheckingTypeMask mask, Node* node)
104 { 112 {
105 ASSERT(canCheckAsynchronously(node)); 113 ASSERT(canCheckAsynchronously(node));
106 114
107 if (!initRequest(node)) 115 if (!initRequest(node))
108 return; 116 return;
109 m_client->requestCheckingOfString(this, m_requestSequence, mask, m_requestTe xt); 117 client()->requestCheckingOfString(this, m_requestSequence, mask, m_requestTe xt);
110 } 118 }
111 119
112 static bool forwardIterator(PositionIterator& iterator, int distance) 120 static bool forwardIterator(PositionIterator& iterator, int distance)
113 { 121 {
114 int remaining = distance; 122 int remaining = distance;
115 while (!iterator.atEnd()) { 123 while (!iterator.atEnd()) {
116 if (iterator.node()->isCharacterDataNode()) { 124 if (iterator.node()->isCharacterDataNode()) {
117 int length = lastOffsetForEditing(iterator.node()); 125 int length = lastOffsetForEditing(iterator.node());
118 int last = length - iterator.offsetInLeafNode(); 126 int last = length - iterator.offsetInLeafNode();
119 if (remaining < last) { 127 if (remaining < last) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 m_requestNode->document()->markers()->addMarker(range.get(), toMarke rType(results[i].type)); 185 m_requestNode->document()->markers()->addMarker(range.get(), toMarke rType(results[i].type));
178 186
179 startOffset = results[i].location; 187 startOffset = results[i].location;
180 } 188 }
181 189
182 clearRequest(); 190 clearRequest();
183 } 191 }
184 192
185 193
186 } // namespace WebCore 194 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/WebCore/editing/SpellChecker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698