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_test_proxy.h" | 8 #include "components/test_runner/web_test_proxy.h" |
9 #include "gin/arguments.h" | 9 #include "gin/arguments.h" |
10 #include "gin/handle.h" | 10 #include "gin/handle.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 void TextInputController::SetComposition(const std::string& text) { | 250 void TextInputController::SetComposition(const std::string& text) { |
251 // Sends a keydown event with key code = 0xE5 to emulate input method | 251 // Sends a keydown event with key code = 0xE5 to emulate input method |
252 // behavior. | 252 // behavior. |
253 blink::WebKeyboardEvent key_down; | 253 blink::WebKeyboardEvent key_down; |
254 key_down.type = blink::WebInputEvent::RawKeyDown; | 254 key_down.type = blink::WebInputEvent::RawKeyDown; |
255 key_down.modifiers = 0; | 255 key_down.modifiers = 0; |
256 key_down.windowsKeyCode = 0xE5; // VKEY_PROCESSKEY | 256 key_down.windowsKeyCode = 0xE5; // VKEY_PROCESSKEY |
257 key_down.setKeyIdentifierFromWindowsKeyCode(); | 257 key_down.setKeyIdentifierFromWindowsKeyCode(); |
258 view()->handleInputEvent(key_down); | 258 view()->handleInputEvent(key_down); |
259 | 259 |
260 // The value returned by std::string::length() may not correspond to the | |
261 // actual number of encoded characters in sequences of multi-byte or | |
262 // variable-length characters. | |
263 blink::WebString newText = blink::WebString::fromUTF8(text); | |
264 size_t textLength = base::string16(newText).length(); | |
tkent
2016/07/04 00:51:49
Doesn't newText.length() work?
yabinh
2016/07/04 01:03:22
No, it doesn't.
For "عالم", its length is 4. But n
tkent
2016/07/04 01:08:16
It shouldn't happen. It implies WebString has a s
| |
265 | |
260 std::vector<blink::WebCompositionUnderline> underlines; | 266 std::vector<blink::WebCompositionUnderline> underlines; |
261 underlines.push_back(blink::WebCompositionUnderline(0, text.length(), | 267 underlines.push_back(blink::WebCompositionUnderline( |
262 SK_ColorBLACK, false, | 268 0, textLength, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
263 SK_ColorTRANSPARENT)); | |
264 view()->setComposition( | 269 view()->setComposition( |
265 blink::WebString::fromUTF8(text), | 270 newText, blink::WebVector<blink::WebCompositionUnderline>(underlines), |
266 blink::WebVector<blink::WebCompositionUnderline>(underlines), | 271 textLength, textLength); |
267 text.length(), text.length()); | |
268 } | 272 } |
269 | 273 |
270 blink::WebView* TextInputController::view() { | 274 blink::WebView* TextInputController::view() { |
271 return web_test_proxy_base_->web_view(); | 275 return web_test_proxy_base_->web_view(); |
272 } | 276 } |
273 | 277 |
274 } // namespace test_runner | 278 } // namespace test_runner |
OLD | NEW |