| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/public/test/text_input_test_utils.h" | 5 #include "content/public/test/text_input_test_utils.h" |
| 6 | 6 |
| 7 #include <unordered_set> | 7 #include <unordered_set> |
| 8 | 8 |
| 9 #include "content/browser/frame_host/render_frame_host_impl.h" | 9 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 10 #include "content/browser/renderer_host/render_widget_host_impl.h" | 10 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 void set_on_ime_composition_range_changed_callback( | 65 void set_on_ime_composition_range_changed_callback( |
| 66 const base::Closure& callback) { | 66 const base::Closure& callback) { |
| 67 on_ime_composition_range_changed_callback_ = callback; | 67 on_ime_composition_range_changed_callback_ = callback; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void set_on_text_selection_changed_callback(const base::Closure& callback) { | 70 void set_on_text_selection_changed_callback(const base::Closure& callback) { |
| 71 on_text_selection_changed_callback_ = callback; | 71 on_text_selection_changed_callback_ = callback; |
| 72 } | 72 } |
| 73 | 73 |
| 74 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } | 74 RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } |
| 75 | 75 |
| 76 bool text_input_state_changed() const { return text_input_state_changed_; } | 76 bool text_input_state_changed() const { return text_input_state_changed_; } |
| 77 | 77 |
| 78 TextInputManager* text_input_manager() const { return text_input_manager_; } | 78 TextInputManager* text_input_manager() const { return text_input_manager_; } |
| 79 | 79 |
| 80 // TextInputManager::Observer implementations. | 80 // TextInputManager::Observer implementations. |
| 81 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, | 81 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, |
| 82 RenderWidgetHostViewBase* updated_view, | 82 RenderWidgetHostViewBase* updated_view, |
| 83 bool did_change_state) override { | 83 bool did_change_state) override { |
| 84 if (text_input_manager_ != text_input_manager) | 84 if (text_input_manager_ != text_input_manager) |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 manager->GetActiveWidget()->Send(new InputMsg_RequestCompositionUpdate( | 255 manager->GetActiveWidget()->Send(new InputMsg_RequestCompositionUpdate( |
| 256 manager->GetActiveWidget()->GetRoutingID(), true, false)); | 256 manager->GetActiveWidget()->GetRoutingID(), true, false)); |
| 257 return true; | 257 return true; |
| 258 } | 258 } |
| 259 | 259 |
| 260 bool DoesFrameHaveFocusedEditableElement(RenderFrameHost* frame) { | 260 bool DoesFrameHaveFocusedEditableElement(RenderFrameHost* frame) { |
| 261 return static_cast<RenderFrameHostImpl*>(frame) | 261 return static_cast<RenderFrameHostImpl*>(frame) |
| 262 ->has_focused_editable_element(); | 262 ->has_focused_editable_element(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void SendImeCommitTextToWidget( |
| 266 RenderWidgetHost* rwh, |
| 267 const base::string16& text, |
| 268 const std::vector<ui::CompositionUnderline>& underlines, |
| 269 const gfx::Range& replacement_range, |
| 270 int relative_cursor_pos) { |
| 271 std::vector<blink::WebCompositionUnderline> web_composition_underlines; |
| 272 for (auto underline : underlines) { |
| 273 web_composition_underlines.emplace_back( |
| 274 static_cast<int>(underline.start_offset), |
| 275 static_cast<int>(underline.end_offset), underline.color, |
| 276 underline.thick, underline.background_color); |
| 277 } |
| 278 RenderWidgetHostImpl::From(rwh)->ImeCommitText( |
| 279 text, web_composition_underlines, replacement_range, relative_cursor_pos); |
| 280 } |
| 281 |
| 265 size_t GetRegisteredViewsCountFromTextInputManager(WebContents* web_contents) { | 282 size_t GetRegisteredViewsCountFromTextInputManager(WebContents* web_contents) { |
| 266 std::unordered_set<RenderWidgetHostView*> views; | 283 std::unordered_set<RenderWidgetHostView*> views; |
| 267 TextInputManager* manager = | 284 TextInputManager* manager = |
| 268 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager(); | 285 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager(); |
| 269 return !!manager ? manager->GetRegisteredViewsCountForTesting() : 0; | 286 return !!manager ? manager->GetRegisteredViewsCountForTesting() : 0; |
| 270 } | 287 } |
| 271 | 288 |
| 272 RenderWidgetHostView* GetActiveViewFromWebContents(WebContents* web_contents) { | 289 RenderWidgetHostView* GetActiveViewFromWebContents(WebContents* web_contents) { |
| 273 return static_cast<WebContentsImpl*>(web_contents) | 290 return static_cast<WebContentsImpl*>(web_contents) |
| 274 ->GetTextInputManager() | 291 ->GetTextInputManager() |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 return false; | 335 return false; |
| 319 *value = state->value; | 336 *value = state->value; |
| 320 return true; | 337 return true; |
| 321 } | 338 } |
| 322 | 339 |
| 323 const RenderWidgetHostView* TextInputManagerTester::GetActiveView() { | 340 const RenderWidgetHostView* TextInputManagerTester::GetActiveView() { |
| 324 DCHECK(observer_->text_input_manager()); | 341 DCHECK(observer_->text_input_manager()); |
| 325 return observer_->text_input_manager()->active_view_for_testing(); | 342 return observer_->text_input_manager()->active_view_for_testing(); |
| 326 } | 343 } |
| 327 | 344 |
| 328 const RenderWidgetHostView* TextInputManagerTester::GetUpdatedView() { | 345 RenderWidgetHostView* TextInputManagerTester::GetUpdatedView() { |
| 329 return observer_->GetUpdatedView(); | 346 return observer_->GetUpdatedView(); |
| 330 } | 347 } |
| 331 | 348 |
| 332 bool TextInputManagerTester::GetCurrentTextSelectionLength(size_t* length) { | 349 bool TextInputManagerTester::GetCurrentTextSelectionLength(size_t* length) { |
| 333 DCHECK(observer_->text_input_manager()); | 350 DCHECK(observer_->text_input_manager()); |
| 334 | 351 |
| 335 if (!observer_->text_input_manager()->GetActiveWidget()) | 352 if (!observer_->text_input_manager()->GetActiveWidget()) |
| 336 return false; | 353 return false; |
| 337 | 354 |
| 338 *length = observer_->text_input_manager()->GetTextSelection()->text.size(); | 355 *length = observer_->text_input_manager()->GetTextSelection()->text.size(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 | 424 |
| 408 #ifdef USE_AURA | 425 #ifdef USE_AURA |
| 409 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( | 426 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( |
| 410 web_contents->GetRenderWidgetHostView()); | 427 web_contents->GetRenderWidgetHostView()); |
| 411 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); | 428 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); |
| 412 #endif | 429 #endif |
| 413 return observer; | 430 return observer; |
| 414 } | 431 } |
| 415 | 432 |
| 416 } // namespace content | 433 } // namespace content |
| OLD | NEW |