| OLD | NEW |
| 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_view_test_proxy.h" | 8 #include "components/test_runner/web_view_test_proxy.h" |
| 9 #include "gin/arguments.h" | 9 #include "gin/arguments.h" |
| 10 #include "gin/handle.h" | 10 #include "gin/handle.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 276 |
| 277 void TextInputController::SetComposition(const std::string& text) { | 277 void TextInputController::SetComposition(const std::string& text) { |
| 278 // Sends a keydown event with key code = 0xE5 to emulate input method | 278 // Sends a keydown event with key code = 0xE5 to emulate input method |
| 279 // behavior. | 279 // behavior. |
| 280 blink::WebKeyboardEvent key_down; | 280 blink::WebKeyboardEvent key_down; |
| 281 key_down.type = blink::WebInputEvent::RawKeyDown; | 281 key_down.type = blink::WebInputEvent::RawKeyDown; |
| 282 key_down.modifiers = 0; | 282 key_down.modifiers = 0; |
| 283 key_down.windowsKeyCode = 0xE5; // VKEY_PROCESSKEY | 283 key_down.windowsKeyCode = 0xE5; // VKEY_PROCESSKEY |
| 284 view()->handleInputEvent(key_down); | 284 view()->handleInputEvent(key_down); |
| 285 | 285 |
| 286 // The value returned by std::string::length() may not correspond to the |
| 287 // actual number of encoded characters in sequences of multi-byte or |
| 288 // variable-length characters. |
| 289 blink::WebString newText = blink::WebString::fromUTF8(text); |
| 290 size_t textLength = newText.length(); |
| 291 |
| 286 std::vector<blink::WebCompositionUnderline> underlines; | 292 std::vector<blink::WebCompositionUnderline> underlines; |
| 287 underlines.push_back(blink::WebCompositionUnderline(0, text.length(), | 293 underlines.push_back(blink::WebCompositionUnderline( |
| 288 SK_ColorBLACK, false, | 294 0, textLength, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
| 289 SK_ColorTRANSPARENT)); | |
| 290 view()->setComposition( | 295 view()->setComposition( |
| 291 blink::WebString::fromUTF8(text), | 296 newText, blink::WebVector<blink::WebCompositionUnderline>(underlines), |
| 292 blink::WebVector<blink::WebCompositionUnderline>(underlines), | 297 textLength, textLength); |
| 293 text.length(), text.length()); | |
| 294 } | 298 } |
| 295 | 299 |
| 296 blink::WebView* TextInputController::view() { | 300 blink::WebView* TextInputController::view() { |
| 297 return web_view_test_proxy_base_->web_view(); | 301 return web_view_test_proxy_base_->web_view(); |
| 298 } | 302 } |
| 299 | 303 |
| 300 } // namespace test_runner | 304 } // namespace test_runner |
| OLD | NEW |