| 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" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 void TextInputController::UnmarkText() { | 177 void TextInputController::UnmarkText() { |
| 178 if (auto* controller = GetInputMethodController()) { | 178 if (auto* controller = GetInputMethodController()) { |
| 179 controller->finishComposingText( | 179 controller->finishComposingText( |
| 180 blink::WebInputMethodController::KeepSelection); | 180 blink::WebInputMethodController::KeepSelection); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 void TextInputController::DoCommand(const std::string& text) { | 184 void TextInputController::DoCommand(const std::string& text) { |
| 185 if (view()->mainFrame()) { | 185 if (view()->mainFrame()) { |
| 186 if (!view()->mainFrame()->toWebLocalFrame()) { | 186 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 187 CHECK(false) << "This function cannot be called if the main frame is not" | 187 // This function cannot be called if the main frame is nota local frame. |
| 188 "a local frame."; | 188 CHECK(false); |
| 189 } | 189 } |
| 190 view()->mainFrame()->toWebLocalFrame()->executeCommand( | 190 view()->mainFrame()->toWebLocalFrame()->executeCommand( |
| 191 blink::WebString::fromUTF8(text)); | 191 blink::WebString::fromUTF8(text)); |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 void TextInputController::SetMarkedText(const std::string& text, | 195 void TextInputController::SetMarkedText(const std::string& text, |
| 196 int start, | 196 int start, |
| 197 int length) { | 197 int length) { |
| 198 blink::WebString web_text(blink::WebString::fromUTF8(text)); | 198 blink::WebString web_text(blink::WebString::fromUTF8(text)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 220 if (auto* controller = GetInputMethodController()) { | 220 if (auto* controller = GetInputMethodController()) { |
| 221 controller->setComposition(web_text, underlines, start, start + length); | 221 controller->setComposition(web_text, underlines, start, start + length); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 bool TextInputController::HasMarkedText() { | 225 bool TextInputController::HasMarkedText() { |
| 226 if (!view()->mainFrame()) | 226 if (!view()->mainFrame()) |
| 227 return false; | 227 return false; |
| 228 | 228 |
| 229 if (!view()->mainFrame()->toWebLocalFrame()) { | 229 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 230 CHECK(false) << "This function cannot be called if the main frame is not" | 230 // This function cannot be called if the main frame is nota local frame. |
| 231 "a local frame."; | 231 CHECK(false); |
| 232 } | 232 } |
| 233 | 233 |
| 234 return view()->mainFrame()->toWebLocalFrame()->hasMarkedText(); | 234 return view()->mainFrame()->toWebLocalFrame()->hasMarkedText(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 std::vector<int> TextInputController::MarkedRange() { | 237 std::vector<int> TextInputController::MarkedRange() { |
| 238 if (!view()->mainFrame()) | 238 if (!view()->mainFrame()) |
| 239 return std::vector<int>(); | 239 return std::vector<int>(); |
| 240 | 240 |
| 241 if (!view()->mainFrame()->toWebLocalFrame()) { | 241 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 242 CHECK(false) << "This function cannot be called if the main frame is not" | 242 // This function cannot be called if the main frame is nota local frame. |
| 243 "a local frame."; | 243 CHECK(false); |
| 244 } | 244 } |
| 245 | 245 |
| 246 blink::WebRange range = view()->mainFrame()->toWebLocalFrame()->markedRange(); | 246 blink::WebRange range = view()->mainFrame()->toWebLocalFrame()->markedRange(); |
| 247 std::vector<int> int_array(2); | 247 std::vector<int> int_array(2); |
| 248 int_array[0] = range.startOffset(); | 248 int_array[0] = range.startOffset(); |
| 249 int_array[1] = range.endOffset(); | 249 int_array[1] = range.endOffset(); |
| 250 | 250 |
| 251 return int_array; | 251 return int_array; |
| 252 } | 252 } |
| 253 | 253 |
| 254 std::vector<int> TextInputController::SelectedRange() { | 254 std::vector<int> TextInputController::SelectedRange() { |
| 255 if (!view()->mainFrame()) | 255 if (!view()->mainFrame()) |
| 256 return std::vector<int>(); | 256 return std::vector<int>(); |
| 257 | 257 |
| 258 if (!view()->mainFrame()->toWebLocalFrame()) { | 258 if (!view()->mainFrame()->toWebLocalFrame()) { |
| 259 CHECK(false) << "This function cannot be called if the main frame is not" | 259 // This function cannot be called if the main frame is nota local frame. |
| 260 "a local frame."; | 260 CHECK(false); |
| 261 } | 261 } |
| 262 | 262 |
| 263 blink::WebRange range = | 263 blink::WebRange range = |
| 264 view()->mainFrame()->toWebLocalFrame()->selectionRange(); | 264 view()->mainFrame()->toWebLocalFrame()->selectionRange(); |
| 265 if (range.isNull()) | 265 if (range.isNull()) |
| 266 return std::vector<int>(); | 266 return std::vector<int>(); |
| 267 std::vector<int> int_array(2); | 267 std::vector<int> int_array(2); |
| 268 int_array[0] = range.startOffset(); | 268 int_array[0] = range.startOffset(); |
| 269 int_array[1] = range.endOffset(); | 269 int_array[1] = range.endOffset(); |
| 270 | 270 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 return web_view_test_proxy_base_->web_view(); | 324 return web_view_test_proxy_base_->web_view(); |
| 325 } | 325 } |
| 326 | 326 |
| 327 blink::WebInputMethodController* | 327 blink::WebInputMethodController* |
| 328 TextInputController::GetInputMethodController() { | 328 TextInputController::GetInputMethodController() { |
| 329 if (!view()->mainFrame()) | 329 if (!view()->mainFrame()) |
| 330 return nullptr; | 330 return nullptr; |
| 331 | 331 |
| 332 blink::WebLocalFrame* mainFrame = view()->mainFrame()->toWebLocalFrame(); | 332 blink::WebLocalFrame* mainFrame = view()->mainFrame()->toWebLocalFrame(); |
| 333 if (!mainFrame) { | 333 if (!mainFrame) { |
| 334 CHECK(false) << "WebView does not have a local main frame and" | 334 // WebView does not have a local main frame and cannot handle input method |
| 335 " cannot handle input method controller tasks."; | 335 // controller tasks. |
| 336 CHECK(false); |
| 336 } | 337 } |
| 337 return mainFrame->frameWidget()->getActiveWebInputMethodController(); | 338 return mainFrame->frameWidget()->getActiveWebInputMethodController(); |
| 338 } | 339 } |
| 339 | 340 |
| 340 } // namespace test_runner | 341 } // namespace test_runner |
| OLD | NEW |