| 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(blink::WebWidget::KeepSelection); |
| 168 } | 170 } |
| 169 | 171 |
| 170 void TextInputController::DoCommand(const std::string& text) { | 172 void TextInputController::DoCommand(const std::string& text) { |
| 171 if (view()->mainFrame()) { | 173 if (view()->mainFrame()) { |
| 172 if (!view()->mainFrame()->toWebLocalFrame()) { | 174 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 173 CHECK(false) << "This function cannot be called if the main frame is not" | 175 CHECK(false) << "This function cannot be called if the main frame is not" |
| 174 "a local frame."; | 176 "a local frame."; |
| 175 } | 177 } |
| 176 view()->mainFrame()->toWebLocalFrame()->executeCommand( | 178 view()->mainFrame()->toWebLocalFrame()->executeCommand( |
| 177 blink::WebString::fromUTF8(text)); | 179 blink::WebString::fromUTF8(text)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 196 } | 198 } |
| 197 underline.thick = true; | 199 underline.thick = true; |
| 198 underlines.push_back(underline); | 200 underlines.push_back(underline); |
| 199 if (start + length < static_cast<int>(web_text.length())) { | 201 if (start + length < static_cast<int>(web_text.length())) { |
| 200 underline.startOffset = underline.endOffset; | 202 underline.startOffset = underline.endOffset; |
| 201 underline.endOffset = web_text.length(); | 203 underline.endOffset = web_text.length(); |
| 202 underline.thick = false; | 204 underline.thick = false; |
| 203 underlines.push_back(underline); | 205 underlines.push_back(underline); |
| 204 } | 206 } |
| 205 | 207 |
| 206 view()->setComposition(web_text, underlines, start, start + length); | 208 inputMethodController()->setComposition(web_text, underlines, start, |
| 209 start + length); |
| 207 } | 210 } |
| 208 | 211 |
| 209 bool TextInputController::HasMarkedText() { | 212 bool TextInputController::HasMarkedText() { |
| 210 if (!view()->mainFrame()) | 213 if (!view()->mainFrame()) |
| 211 return false; | 214 return false; |
| 212 | 215 |
| 213 if (!view()->mainFrame()->toWebLocalFrame()) { | 216 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 214 CHECK(false) << "This function cannot be called if the main frame is not" | 217 CHECK(false) << "This function cannot be called if the main frame is not" |
| 215 "a local frame."; | 218 "a local frame."; |
| 216 } | 219 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 288 |
| 286 // The value returned by std::string::length() may not correspond to the | 289 // The value returned by std::string::length() may not correspond to the |
| 287 // actual number of encoded characters in sequences of multi-byte or | 290 // actual number of encoded characters in sequences of multi-byte or |
| 288 // variable-length characters. | 291 // variable-length characters. |
| 289 blink::WebString newText = blink::WebString::fromUTF8(text); | 292 blink::WebString newText = blink::WebString::fromUTF8(text); |
| 290 size_t textLength = newText.length(); | 293 size_t textLength = newText.length(); |
| 291 | 294 |
| 292 std::vector<blink::WebCompositionUnderline> underlines; | 295 std::vector<blink::WebCompositionUnderline> underlines; |
| 293 underlines.push_back(blink::WebCompositionUnderline( | 296 underlines.push_back(blink::WebCompositionUnderline( |
| 294 0, textLength, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); | 297 0, textLength, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
| 295 view()->setComposition( | 298 inputMethodController()->setComposition( |
| 296 newText, blink::WebVector<blink::WebCompositionUnderline>(underlines), | 299 newText, blink::WebVector<blink::WebCompositionUnderline>(underlines), |
| 297 textLength, textLength); | 300 textLength, textLength); |
| 298 } | 301 } |
| 299 | 302 |
| 300 blink::WebView* TextInputController::view() { | 303 blink::WebView* TextInputController::view() { |
| 301 return web_view_test_proxy_base_->web_view(); | 304 return web_view_test_proxy_base_->web_view(); |
| 302 } | 305 } |
| 303 | 306 |
| 307 blink::WebInputMethodController* TextInputController::inputMethodController() { |
| 308 blink::WebLocalFrame* mainFrame = view()->mainFrame()->toWebLocalFrame(); |
| 309 if (!mainFrame) { |
| 310 CHECK(false) << "WebView does not have a local main frame and" |
| 311 " cannot handle input method controller tasks."; |
| 312 } |
| 313 return mainFrame->frameWidget()->getActiveWebInputMethodController(); |
| 314 } |
| 315 |
| 304 } // namespace test_runner | 316 } // namespace test_runner |
| OLD | NEW |