| 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" |
| 11 #include "gin/object_template_builder.h" | 11 #include "gin/object_template_builder.h" |
| 12 #include "gin/wrappable.h" | 12 #include "gin/wrappable.h" |
| 13 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 13 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
| 14 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
| 14 #include "third_party/WebKit/public/web/WebInputEvent.h" | 15 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 16 #include "third_party/WebKit/public/web/WebInputMethodController.h" |
| 15 #include "third_party/WebKit/public/web/WebKit.h" | 17 #include "third_party/WebKit/public/web/WebKit.h" |
| 16 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 18 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 17 #include "third_party/WebKit/public/web/WebRange.h" | 19 #include "third_party/WebKit/public/web/WebRange.h" |
| 18 #include "third_party/WebKit/public/web/WebView.h" | 20 #include "third_party/WebKit/public/web/WebView.h" |
| 19 #include "third_party/skia/include/core/SkColor.h" | 21 #include "third_party/skia/include/core/SkColor.h" |
| 20 #include "v8/include/v8.h" | 22 #include "v8/include/v8.h" |
| 21 | 23 |
| 22 namespace test_runner { | 24 namespace test_runner { |
| 23 | 25 |
| 24 class TextInputControllerBindings | 26 class TextInputControllerBindings |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 : web_view_test_proxy_base_(web_view_test_proxy_base), | 155 : web_view_test_proxy_base_(web_view_test_proxy_base), |
| 154 weak_factory_(this) {} | 156 weak_factory_(this) {} |
| 155 | 157 |
| 156 TextInputController::~TextInputController() {} | 158 TextInputController::~TextInputController() {} |
| 157 | 159 |
| 158 void TextInputController::Install(blink::WebLocalFrame* frame) { | 160 void TextInputController::Install(blink::WebLocalFrame* frame) { |
| 159 TextInputControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); | 161 TextInputControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); |
| 160 } | 162 } |
| 161 | 163 |
| 162 void TextInputController::InsertText(const std::string& text) { | 164 void TextInputController::InsertText(const std::string& text) { |
| 163 view()->commitText(blink::WebString::fromUTF8(text), 0); | 165 inputMethodController()->commitText(blink::WebString::fromUTF8(text), 0); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void TextInputController::UnmarkText() { | 168 void TextInputController::UnmarkText() { |
| 167 view()->finishComposingText(blink::WebWidget::KeepSelection); | 169 inputMethodController()->finishComposingText( |
| 170 blink::WebInputMethodController::KeepSelection); |
| 168 } | 171 } |
| 169 | 172 |
| 170 void TextInputController::DoCommand(const std::string& text) { | 173 void TextInputController::DoCommand(const std::string& text) { |
| 171 if (view()->mainFrame()) { | 174 if (view()->mainFrame()) { |
| 172 if (!view()->mainFrame()->toWebLocalFrame()) { | 175 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 173 CHECK(false) << "This function cannot be called if the main frame is not" | 176 CHECK(false) << "This function cannot be called if the main frame is not" |
| 174 "a local frame."; | 177 "a local frame."; |
| 175 } | 178 } |
| 176 view()->mainFrame()->toWebLocalFrame()->executeCommand( | 179 view()->mainFrame()->toWebLocalFrame()->executeCommand( |
| 177 blink::WebString::fromUTF8(text)); | 180 blink::WebString::fromUTF8(text)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 196 } | 199 } |
| 197 underline.thick = true; | 200 underline.thick = true; |
| 198 underlines.push_back(underline); | 201 underlines.push_back(underline); |
| 199 if (start + length < static_cast<int>(web_text.length())) { | 202 if (start + length < static_cast<int>(web_text.length())) { |
| 200 underline.startOffset = underline.endOffset; | 203 underline.startOffset = underline.endOffset; |
| 201 underline.endOffset = web_text.length(); | 204 underline.endOffset = web_text.length(); |
| 202 underline.thick = false; | 205 underline.thick = false; |
| 203 underlines.push_back(underline); | 206 underlines.push_back(underline); |
| 204 } | 207 } |
| 205 | 208 |
| 206 view()->setComposition(web_text, underlines, start, start + length); | 209 inputMethodController()->setComposition(web_text, underlines, start, |
| 210 start + length); |
| 207 } | 211 } |
| 208 | 212 |
| 209 bool TextInputController::HasMarkedText() { | 213 bool TextInputController::HasMarkedText() { |
| 210 if (!view()->mainFrame()) | 214 if (!view()->mainFrame()) |
| 211 return false; | 215 return false; |
| 212 | 216 |
| 213 if (!view()->mainFrame()->toWebLocalFrame()) { | 217 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 214 CHECK(false) << "This function cannot be called if the main frame is not" | 218 CHECK(false) << "This function cannot be called if the main frame is not" |
| 215 "a local frame."; | 219 "a local frame."; |
| 216 } | 220 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 289 |
| 286 // The value returned by std::string::length() may not correspond to the | 290 // The value returned by std::string::length() may not correspond to the |
| 287 // actual number of encoded characters in sequences of multi-byte or | 291 // actual number of encoded characters in sequences of multi-byte or |
| 288 // variable-length characters. | 292 // variable-length characters. |
| 289 blink::WebString newText = blink::WebString::fromUTF8(text); | 293 blink::WebString newText = blink::WebString::fromUTF8(text); |
| 290 size_t textLength = newText.length(); | 294 size_t textLength = newText.length(); |
| 291 | 295 |
| 292 std::vector<blink::WebCompositionUnderline> underlines; | 296 std::vector<blink::WebCompositionUnderline> underlines; |
| 293 underlines.push_back(blink::WebCompositionUnderline( | 297 underlines.push_back(blink::WebCompositionUnderline( |
| 294 0, textLength, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); | 298 0, textLength, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
| 295 view()->setComposition( | 299 inputMethodController()->setComposition( |
| 296 newText, blink::WebVector<blink::WebCompositionUnderline>(underlines), | 300 newText, blink::WebVector<blink::WebCompositionUnderline>(underlines), |
| 297 textLength, textLength); | 301 textLength, textLength); |
| 298 } | 302 } |
| 299 | 303 |
| 300 blink::WebView* TextInputController::view() { | 304 blink::WebView* TextInputController::view() { |
| 301 return web_view_test_proxy_base_->web_view(); | 305 return web_view_test_proxy_base_->web_view(); |
| 302 } | 306 } |
| 303 | 307 |
| 308 blink::WebInputMethodController* TextInputController::inputMethodController() { |
| 309 blink::WebLocalFrame* mainFrame = view()->mainFrame()->toWebLocalFrame(); |
| 310 if (!mainFrame) { |
| 311 CHECK(false) << "WebView does not have a local main frame and" |
| 312 " cannot handle input method controller tasks."; |
| 313 } |
| 314 return mainFrame->frameWidget()->getActiveWebInputMethodController(); |
| 315 } |
| 316 |
| 304 } // namespace test_runner | 317 } // namespace test_runner |
| OLD | NEW |