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

Side by Side Diff: components/test_runner/text_input_controller.cc

Issue 2333813002: Introduce WebInputMethodController to blink (Closed)
Patch Set: Explicitly asking for TextInputState updates Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/test_runner/text_input_controller.h" 5 #include "components/test_runner/text_input_controller.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "components/test_runner/web_test_delegate.h"
8 #include "components/test_runner/web_view_test_proxy.h" 9 #include "components/test_runner/web_view_test_proxy.h"
9 #include "gin/arguments.h" 10 #include "gin/arguments.h"
10 #include "gin/handle.h" 11 #include "gin/handle.h"
11 #include "gin/object_template_builder.h" 12 #include "gin/object_template_builder.h"
12 #include "gin/wrappable.h" 13 #include "gin/wrappable.h"
13 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 14 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
15 #include "third_party/WebKit/public/web/WebFrameWidget.h"
14 #include "third_party/WebKit/public/web/WebInputEvent.h" 16 #include "third_party/WebKit/public/web/WebInputEvent.h"
17 #include "third_party/WebKit/public/web/WebInputMethodController.h"
15 #include "third_party/WebKit/public/web/WebKit.h" 18 #include "third_party/WebKit/public/web/WebKit.h"
16 #include "third_party/WebKit/public/web/WebLocalFrame.h" 19 #include "third_party/WebKit/public/web/WebLocalFrame.h"
17 #include "third_party/WebKit/public/web/WebRange.h" 20 #include "third_party/WebKit/public/web/WebRange.h"
18 #include "third_party/WebKit/public/web/WebView.h" 21 #include "third_party/WebKit/public/web/WebView.h"
19 #include "third_party/skia/include/core/SkColor.h" 22 #include "third_party/skia/include/core/SkColor.h"
20 #include "v8/include/v8.h" 23 #include "v8/include/v8.h"
21 24
22 namespace test_runner { 25 namespace test_runner {
23 26
24 class TextInputControllerBindings 27 class TextInputControllerBindings
(...skipping 16 matching lines...) Expand all
41 void InsertText(const std::string& text); 44 void InsertText(const std::string& text);
42 void UnmarkText(); 45 void UnmarkText();
43 void DoCommand(const std::string& text); 46 void DoCommand(const std::string& text);
44 void SetMarkedText(const std::string& text, int start, int length); 47 void SetMarkedText(const std::string& text, int start, int length);
45 bool HasMarkedText(); 48 bool HasMarkedText();
46 std::vector<int> MarkedRange(); 49 std::vector<int> MarkedRange();
47 std::vector<int> SelectedRange(); 50 std::vector<int> SelectedRange();
48 std::vector<int> FirstRectForCharacterRange(unsigned location, 51 std::vector<int> FirstRectForCharacterRange(unsigned location,
49 unsigned length); 52 unsigned length);
50 void SetComposition(const std::string& text); 53 void SetComposition(const std::string& text);
54 void ForceTextInputStateUpdate();
51 55
52 base::WeakPtr<TextInputController> controller_; 56 base::WeakPtr<TextInputController> controller_;
53 57
54 DISALLOW_COPY_AND_ASSIGN(TextInputControllerBindings); 58 DISALLOW_COPY_AND_ASSIGN(TextInputControllerBindings);
55 }; 59 };
56 60
57 gin::WrapperInfo TextInputControllerBindings::kWrapperInfo = { 61 gin::WrapperInfo TextInputControllerBindings::kWrapperInfo = {
58 gin::kEmbedderNativeGin}; 62 gin::kEmbedderNativeGin};
59 63
60 // static 64 // static
(...skipping 28 matching lines...) Expand all
89 isolate) 93 isolate)
90 .SetMethod("insertText", &TextInputControllerBindings::InsertText) 94 .SetMethod("insertText", &TextInputControllerBindings::InsertText)
91 .SetMethod("unmarkText", &TextInputControllerBindings::UnmarkText) 95 .SetMethod("unmarkText", &TextInputControllerBindings::UnmarkText)
92 .SetMethod("doCommand", &TextInputControllerBindings::DoCommand) 96 .SetMethod("doCommand", &TextInputControllerBindings::DoCommand)
93 .SetMethod("setMarkedText", &TextInputControllerBindings::SetMarkedText) 97 .SetMethod("setMarkedText", &TextInputControllerBindings::SetMarkedText)
94 .SetMethod("hasMarkedText", &TextInputControllerBindings::HasMarkedText) 98 .SetMethod("hasMarkedText", &TextInputControllerBindings::HasMarkedText)
95 .SetMethod("markedRange", &TextInputControllerBindings::MarkedRange) 99 .SetMethod("markedRange", &TextInputControllerBindings::MarkedRange)
96 .SetMethod("selectedRange", &TextInputControllerBindings::SelectedRange) 100 .SetMethod("selectedRange", &TextInputControllerBindings::SelectedRange)
97 .SetMethod("firstRectForCharacterRange", 101 .SetMethod("firstRectForCharacterRange",
98 &TextInputControllerBindings::FirstRectForCharacterRange) 102 &TextInputControllerBindings::FirstRectForCharacterRange)
99 .SetMethod("setComposition", 103 .SetMethod("setComposition", &TextInputControllerBindings::SetComposition)
100 &TextInputControllerBindings::SetComposition); 104 .SetMethod("forceTextInputStateUpdate",
105 &TextInputControllerBindings::ForceTextInputStateUpdate);
101 } 106 }
102 107
103 void TextInputControllerBindings::InsertText(const std::string& text) { 108 void TextInputControllerBindings::InsertText(const std::string& text) {
104 if (controller_) 109 if (controller_)
105 controller_->InsertText(text); 110 controller_->InsertText(text);
106 } 111 }
107 112
108 void TextInputControllerBindings::UnmarkText() { 113 void TextInputControllerBindings::UnmarkText() {
109 if (controller_) 114 if (controller_)
110 controller_->UnmarkText(); 115 controller_->UnmarkText();
(...skipping 27 matching lines...) Expand all
138 unsigned location, 143 unsigned location,
139 unsigned length) { 144 unsigned length) {
140 return controller_ ? controller_->FirstRectForCharacterRange(location, length) 145 return controller_ ? controller_->FirstRectForCharacterRange(location, length)
141 : std::vector<int>(); 146 : std::vector<int>();
142 } 147 }
143 148
144 void TextInputControllerBindings::SetComposition(const std::string& text) { 149 void TextInputControllerBindings::SetComposition(const std::string& text) {
145 if (controller_) 150 if (controller_)
146 controller_->SetComposition(text); 151 controller_->SetComposition(text);
147 } 152 }
148 153 void TextInputControllerBindings::ForceTextInputStateUpdate() {
154 if (controller_)
155 controller_->ForceTextInputStateUpdate();
156 }
149 // TextInputController --------------------------------------------------------- 157 // TextInputController ---------------------------------------------------------
150 158
151 TextInputController::TextInputController( 159 TextInputController::TextInputController(
152 WebViewTestProxyBase* web_view_test_proxy_base) 160 WebViewTestProxyBase* web_view_test_proxy_base)
153 : web_view_test_proxy_base_(web_view_test_proxy_base), 161 : web_view_test_proxy_base_(web_view_test_proxy_base),
154 weak_factory_(this) {} 162 weak_factory_(this) {}
155 163
156 TextInputController::~TextInputController() {} 164 TextInputController::~TextInputController() {}
157 165
158 void TextInputController::Install(blink::WebLocalFrame* frame) { 166 void TextInputController::Install(blink::WebLocalFrame* frame) {
159 TextInputControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); 167 TextInputControllerBindings::Install(weak_factory_.GetWeakPtr(), frame);
160 } 168 }
161 169
162 void TextInputController::InsertText(const std::string& text) { 170 void TextInputController::InsertText(const std::string& text) {
163 view()->commitText(blink::WebString::fromUTF8(text), 0); 171 inputMethodController()->commitText(blink::WebString::fromUTF8(text), 0);
164 } 172 }
165 173
166 void TextInputController::UnmarkText() { 174 void TextInputController::UnmarkText() {
167 view()->finishComposingText(blink::WebWidget::KeepSelection); 175 inputMethodController()->finishComposingText(
176 blink::WebInputMethodController::KeepSelection);
168 } 177 }
169 178
170 void TextInputController::DoCommand(const std::string& text) { 179 void TextInputController::DoCommand(const std::string& text) {
171 if (view()->mainFrame()) { 180 if (view()->mainFrame()) {
172 if (!view()->mainFrame()->toWebLocalFrame()) { 181 if (!view()->mainFrame()->toWebLocalFrame()) {
173 CHECK(false) << "This function cannot be called if the main frame is not" 182 CHECK(false) << "This function cannot be called if the main frame is not"
174 "a local frame."; 183 "a local frame.";
175 } 184 }
176 view()->mainFrame()->toWebLocalFrame()->executeCommand( 185 view()->mainFrame()->toWebLocalFrame()->executeCommand(
177 blink::WebString::fromUTF8(text)); 186 blink::WebString::fromUTF8(text));
(...skipping 18 matching lines...) Expand all
196 } 205 }
197 underline.thick = true; 206 underline.thick = true;
198 underlines.push_back(underline); 207 underlines.push_back(underline);
199 if (start + length < static_cast<int>(web_text.length())) { 208 if (start + length < static_cast<int>(web_text.length())) {
200 underline.startOffset = underline.endOffset; 209 underline.startOffset = underline.endOffset;
201 underline.endOffset = web_text.length(); 210 underline.endOffset = web_text.length();
202 underline.thick = false; 211 underline.thick = false;
203 underlines.push_back(underline); 212 underlines.push_back(underline);
204 } 213 }
205 214
206 view()->setComposition(web_text, underlines, start, start + length); 215 inputMethodController()->setComposition(web_text, underlines, start,
216 start + length);
207 } 217 }
208 218
209 bool TextInputController::HasMarkedText() { 219 bool TextInputController::HasMarkedText() {
210 if (!view()->mainFrame()) 220 if (!view()->mainFrame())
211 return false; 221 return false;
212 222
213 if (!view()->mainFrame()->toWebLocalFrame()) { 223 if (!view()->mainFrame()->toWebLocalFrame()) {
214 CHECK(false) << "This function cannot be called if the main frame is not" 224 CHECK(false) << "This function cannot be called if the main frame is not"
215 "a local frame."; 225 "a local frame.";
216 } 226 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 295
286 // The value returned by std::string::length() may not correspond to the 296 // The value returned by std::string::length() may not correspond to the
287 // actual number of encoded characters in sequences of multi-byte or 297 // actual number of encoded characters in sequences of multi-byte or
288 // variable-length characters. 298 // variable-length characters.
289 blink::WebString newText = blink::WebString::fromUTF8(text); 299 blink::WebString newText = blink::WebString::fromUTF8(text);
290 size_t textLength = newText.length(); 300 size_t textLength = newText.length();
291 301
292 std::vector<blink::WebCompositionUnderline> underlines; 302 std::vector<blink::WebCompositionUnderline> underlines;
293 underlines.push_back(blink::WebCompositionUnderline( 303 underlines.push_back(blink::WebCompositionUnderline(
294 0, textLength, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); 304 0, textLength, SK_ColorBLACK, false, SK_ColorTRANSPARENT));
295 view()->setComposition( 305 inputMethodController()->setComposition(
296 newText, blink::WebVector<blink::WebCompositionUnderline>(underlines), 306 newText, blink::WebVector<blink::WebCompositionUnderline>(underlines),
297 textLength, textLength); 307 textLength, textLength);
298 } 308 }
299 309
310 void TextInputController::ForceTextInputStateUpdate() {
311 web_view_test_proxy_base_->delegate()->ForceTextInputStateUpdate(
312 view()->mainFrame());
313 }
314
300 blink::WebView* TextInputController::view() { 315 blink::WebView* TextInputController::view() {
301 return web_view_test_proxy_base_->web_view(); 316 return web_view_test_proxy_base_->web_view();
302 } 317 }
303 318
319 blink::WebInputMethodController* TextInputController::inputMethodController() {
320 blink::WebLocalFrame* mainFrame = view()->mainFrame()->toWebLocalFrame();
321 if (!mainFrame) {
322 CHECK(false) << "WebView does not have a local main frame and"
323 " cannot handle input method controller tasks.";
324 }
325 return mainFrame->frameWidget()->getActiveWebInputMethodController();
326 }
327
304 } // namespace test_runner 328 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698