| 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_delegate.h" | 8 #include "components/test_runner/web_test_delegate.h" |
| 9 #include "components/test_runner/web_view_test_proxy.h" | 9 #include "components/test_runner/web_view_test_proxy.h" |
| 10 #include "gin/arguments.h" | 10 #include "gin/arguments.h" |
| 11 #include "gin/handle.h" | 11 #include "gin/handle.h" |
| 12 #include "gin/object_template_builder.h" | 12 #include "gin/object_template_builder.h" |
| 13 #include "gin/wrappable.h" | 13 #include "gin/wrappable.h" |
| 14 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 14 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 15 #include "third_party/WebKit/public/platform/WebInputEventResult.h" |
| 15 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 16 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
| 16 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 17 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
| 17 #include "third_party/WebKit/public/web/WebInputMethodController.h" | 18 #include "third_party/WebKit/public/web/WebInputMethodController.h" |
| 18 #include "third_party/WebKit/public/web/WebKit.h" | 19 #include "third_party/WebKit/public/web/WebKit.h" |
| 19 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 20 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 20 #include "third_party/WebKit/public/web/WebRange.h" | 21 #include "third_party/WebKit/public/web/WebRange.h" |
| 21 #include "third_party/WebKit/public/web/WebView.h" | 22 #include "third_party/WebKit/public/web/WebView.h" |
| 22 #include "third_party/skia/include/core/SkColor.h" | 23 #include "third_party/skia/include/core/SkColor.h" |
| 23 #include "v8/include/v8.h" | 24 #include "v8/include/v8.h" |
| 24 | 25 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 : web_view_test_proxy_base_(web_view_test_proxy_base), | 162 : web_view_test_proxy_base_(web_view_test_proxy_base), |
| 162 weak_factory_(this) {} | 163 weak_factory_(this) {} |
| 163 | 164 |
| 164 TextInputController::~TextInputController() {} | 165 TextInputController::~TextInputController() {} |
| 165 | 166 |
| 166 void TextInputController::Install(blink::WebLocalFrame* frame) { | 167 void TextInputController::Install(blink::WebLocalFrame* frame) { |
| 167 TextInputControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); | 168 TextInputControllerBindings::Install(weak_factory_.GetWeakPtr(), frame); |
| 168 } | 169 } |
| 169 | 170 |
| 170 void TextInputController::InsertText(const std::string& text) { | 171 void TextInputController::InsertText(const std::string& text) { |
| 171 inputMethodController()->commitText(blink::WebString::fromUTF8(text), 0); | 172 if (auto* controller = GetInputMethodController()) { |
| 173 controller->commitText(blink::WebString::fromUTF8(text), 0); |
| 174 } |
| 172 } | 175 } |
| 173 | 176 |
| 174 void TextInputController::UnmarkText() { | 177 void TextInputController::UnmarkText() { |
| 175 inputMethodController()->finishComposingText( | 178 if (auto* controller = GetInputMethodController()) { |
| 176 blink::WebInputMethodController::KeepSelection); | 179 controller->finishComposingText( |
| 180 blink::WebInputMethodController::KeepSelection); |
| 181 } |
| 177 } | 182 } |
| 178 | 183 |
| 179 void TextInputController::DoCommand(const std::string& text) { | 184 void TextInputController::DoCommand(const std::string& text) { |
| 180 if (view()->mainFrame()) { | 185 if (view()->mainFrame()) { |
| 181 if (!view()->mainFrame()->toWebLocalFrame()) { | 186 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 182 CHECK(false) << "This function cannot be called if the main frame is not" | 187 CHECK(false) << "This function cannot be called if the main frame is not" |
| 183 "a local frame."; | 188 "a local frame."; |
| 184 } | 189 } |
| 185 view()->mainFrame()->toWebLocalFrame()->executeCommand( | 190 view()->mainFrame()->toWebLocalFrame()->executeCommand( |
| 186 blink::WebString::fromUTF8(text)); | 191 blink::WebString::fromUTF8(text)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 205 } | 210 } |
| 206 underline.thick = true; | 211 underline.thick = true; |
| 207 underlines.push_back(underline); | 212 underlines.push_back(underline); |
| 208 if (start + length < static_cast<int>(web_text.length())) { | 213 if (start + length < static_cast<int>(web_text.length())) { |
| 209 underline.startOffset = underline.endOffset; | 214 underline.startOffset = underline.endOffset; |
| 210 underline.endOffset = web_text.length(); | 215 underline.endOffset = web_text.length(); |
| 211 underline.thick = false; | 216 underline.thick = false; |
| 212 underlines.push_back(underline); | 217 underlines.push_back(underline); |
| 213 } | 218 } |
| 214 | 219 |
| 215 inputMethodController()->setComposition(web_text, underlines, start, | 220 if (auto* controller = GetInputMethodController()) { |
| 216 start + length); | 221 controller->setComposition(web_text, underlines, start, start + length); |
| 222 } |
| 217 } | 223 } |
| 218 | 224 |
| 219 bool TextInputController::HasMarkedText() { | 225 bool TextInputController::HasMarkedText() { |
| 220 if (!view()->mainFrame()) | 226 if (!view()->mainFrame()) |
| 221 return false; | 227 return false; |
| 222 | 228 |
| 223 if (!view()->mainFrame()->toWebLocalFrame()) { | 229 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 224 CHECK(false) << "This function cannot be called if the main frame is not" | 230 CHECK(false) << "This function cannot be called if the main frame is not" |
| 225 "a local frame."; | 231 "a local frame."; |
| 226 } | 232 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 301 |
| 296 // The value returned by std::string::length() may not correspond to the | 302 // The value returned by std::string::length() may not correspond to the |
| 297 // actual number of encoded characters in sequences of multi-byte or | 303 // actual number of encoded characters in sequences of multi-byte or |
| 298 // variable-length characters. | 304 // variable-length characters. |
| 299 blink::WebString newText = blink::WebString::fromUTF8(text); | 305 blink::WebString newText = blink::WebString::fromUTF8(text); |
| 300 size_t textLength = newText.length(); | 306 size_t textLength = newText.length(); |
| 301 | 307 |
| 302 std::vector<blink::WebCompositionUnderline> underlines; | 308 std::vector<blink::WebCompositionUnderline> underlines; |
| 303 underlines.push_back(blink::WebCompositionUnderline( | 309 underlines.push_back(blink::WebCompositionUnderline( |
| 304 0, textLength, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); | 310 0, textLength, SK_ColorBLACK, false, SK_ColorTRANSPARENT)); |
| 305 inputMethodController()->setComposition( | 311 if (auto* controller = GetInputMethodController()) { |
| 306 newText, blink::WebVector<blink::WebCompositionUnderline>(underlines), | 312 controller->setComposition( |
| 307 textLength, textLength); | 313 newText, blink::WebVector<blink::WebCompositionUnderline>(underlines), |
| 314 textLength, textLength); |
| 315 } |
| 308 } | 316 } |
| 309 | 317 |
| 310 void TextInputController::ForceTextInputStateUpdate() { | 318 void TextInputController::ForceTextInputStateUpdate() { |
| 311 web_view_test_proxy_base_->delegate()->ForceTextInputStateUpdate( | 319 web_view_test_proxy_base_->delegate()->ForceTextInputStateUpdate( |
| 312 view()->mainFrame()); | 320 view()->mainFrame()); |
| 313 } | 321 } |
| 314 | 322 |
| 315 blink::WebView* TextInputController::view() { | 323 blink::WebView* TextInputController::view() { |
| 316 return web_view_test_proxy_base_->web_view(); | 324 return web_view_test_proxy_base_->web_view(); |
| 317 } | 325 } |
| 318 | 326 |
| 319 blink::WebInputMethodController* TextInputController::inputMethodController() { | 327 blink::WebInputMethodController* |
| 328 TextInputController::GetInputMethodController() { |
| 329 if (!view()->mainFrame()) |
| 330 return nullptr; |
| 331 |
| 320 blink::WebLocalFrame* mainFrame = view()->mainFrame()->toWebLocalFrame(); | 332 blink::WebLocalFrame* mainFrame = view()->mainFrame()->toWebLocalFrame(); |
| 321 if (!mainFrame) { | 333 if (!mainFrame) { |
| 322 CHECK(false) << "WebView does not have a local main frame and" | 334 CHECK(false) << "WebView does not have a local main frame and" |
| 323 " cannot handle input method controller tasks."; | 335 " cannot handle input method controller tasks."; |
| 324 } | 336 } |
| 325 return mainFrame->frameWidget()->getActiveWebInputMethodController(); | 337 return mainFrame->frameWidget()->getActiveWebInputMethodController(); |
| 326 } | 338 } |
| 327 | 339 |
| 328 } // namespace test_runner | 340 } // namespace test_runner |
| OLD | NEW |