| 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/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 10 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 10 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 void set_on_selection_bounds_changed_callback(const base::Closure& callback) { | 59 void set_on_selection_bounds_changed_callback(const base::Closure& callback) { |
| 60 on_selection_bounds_changed_callback_ = callback; | 60 on_selection_bounds_changed_callback_ = callback; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void set_on_ime_composition_range_changed_callback( | 63 void set_on_ime_composition_range_changed_callback( |
| 64 const base::Closure& callback) { | 64 const base::Closure& callback) { |
| 65 on_ime_composition_range_changed_callback_ = callback; | 65 on_ime_composition_range_changed_callback_ = callback; |
| 66 } | 66 } |
| 67 | 67 |
| 68 void set_on_text_selection_changed_callback(const base::Closure& callback) { |
| 69 on_text_selection_changed_callback_ = callback; |
| 70 } |
| 71 |
| 68 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } | 72 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } |
| 69 | 73 |
| 70 bool text_input_state_changed() const { return text_input_state_changed_; } | 74 bool text_input_state_changed() const { return text_input_state_changed_; } |
| 71 | 75 |
| 72 TextInputManager* text_input_manager() const { return text_input_manager_; } | 76 TextInputManager* text_input_manager() const { return text_input_manager_; } |
| 73 | 77 |
| 74 // TextInputManager::Observer implementations. | 78 // TextInputManager::Observer implementations. |
| 75 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, | 79 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, |
| 76 RenderWidgetHostViewBase* updated_view, | 80 RenderWidgetHostViewBase* updated_view, |
| 77 bool did_change_state) override { | 81 bool did_change_state) override { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 92 } | 96 } |
| 93 | 97 |
| 94 void OnImeCompositionRangeChanged( | 98 void OnImeCompositionRangeChanged( |
| 95 TextInputManager* text_input_manager, | 99 TextInputManager* text_input_manager, |
| 96 RenderWidgetHostViewBase* updated_view) override { | 100 RenderWidgetHostViewBase* updated_view) override { |
| 97 updated_view_ = updated_view; | 101 updated_view_ = updated_view; |
| 98 if (!on_ime_composition_range_changed_callback_.is_null()) | 102 if (!on_ime_composition_range_changed_callback_.is_null()) |
| 99 on_ime_composition_range_changed_callback_.Run(); | 103 on_ime_composition_range_changed_callback_.Run(); |
| 100 } | 104 } |
| 101 | 105 |
| 106 void OnTextSelectionChanged(TextInputManager* text_input_manager, |
| 107 RenderWidgetHostViewBase* updated_view) override { |
| 108 updated_view_ = updated_view; |
| 109 if (!on_text_selection_changed_callback_.is_null()) |
| 110 on_text_selection_changed_callback_.Run(); |
| 111 } |
| 112 |
| 102 // WebContentsObserver implementation. | 113 // WebContentsObserver implementation. |
| 103 void WebContentsDestroyed() override { text_input_manager_ = nullptr; } | 114 void WebContentsDestroyed() override { text_input_manager_ = nullptr; } |
| 104 | 115 |
| 105 private: | 116 private: |
| 106 TextInputManager* text_input_manager_; | 117 TextInputManager* text_input_manager_; |
| 107 RenderWidgetHostViewBase* updated_view_; | 118 RenderWidgetHostViewBase* updated_view_; |
| 108 bool text_input_state_changed_; | 119 bool text_input_state_changed_; |
| 109 base::Closure update_text_input_state_callback_; | 120 base::Closure update_text_input_state_callback_; |
| 110 base::Closure on_selection_bounds_changed_callback_; | 121 base::Closure on_selection_bounds_changed_callback_; |
| 111 base::Closure on_ime_composition_range_changed_callback_; | 122 base::Closure on_ime_composition_range_changed_callback_; |
| 123 base::Closure on_text_selection_changed_callback_; |
| 112 | 124 |
| 113 DISALLOW_COPY_AND_ASSIGN(InternalObserver); | 125 DISALLOW_COPY_AND_ASSIGN(InternalObserver); |
| 114 }; | 126 }; |
| 115 | 127 |
| 116 // This class observes the lifetime of a RenderWidgetHostView. An instance of | 128 // This class observes the lifetime of a RenderWidgetHostView. An instance of |
| 117 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose | 129 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose |
| 118 // the required observer API for testing outside of content/. | 130 // the required observer API for testing outside of content/. |
| 119 class TestRenderWidgetHostViewDestructionObserver::InternalObserver | 131 class TestRenderWidgetHostViewDestructionObserver::InternalObserver |
| 120 : public RenderWidgetHostViewBaseObserver { | 132 : public RenderWidgetHostViewBaseObserver { |
| 121 public: | 133 public: |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 void TextInputManagerTester::SetOnSelectionBoundsChangedCallback( | 289 void TextInputManagerTester::SetOnSelectionBoundsChangedCallback( |
| 278 const base::Closure& callback) { | 290 const base::Closure& callback) { |
| 279 observer_->set_on_selection_bounds_changed_callback(callback); | 291 observer_->set_on_selection_bounds_changed_callback(callback); |
| 280 } | 292 } |
| 281 | 293 |
| 282 void TextInputManagerTester::SetOnImeCompositionRangeChangedCallback( | 294 void TextInputManagerTester::SetOnImeCompositionRangeChangedCallback( |
| 283 const base::Closure& callback) { | 295 const base::Closure& callback) { |
| 284 observer_->set_on_ime_composition_range_changed_callback(callback); | 296 observer_->set_on_ime_composition_range_changed_callback(callback); |
| 285 } | 297 } |
| 286 | 298 |
| 299 void TextInputManagerTester::SetOnTextSelectionChangedCallback( |
| 300 const base::Closure& callback) { |
| 301 observer_->set_on_text_selection_changed_callback(callback); |
| 302 } |
| 303 |
| 287 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) { | 304 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) { |
| 288 DCHECK(observer_->text_input_manager()); | 305 DCHECK(observer_->text_input_manager()); |
| 289 const TextInputState* state = | 306 const TextInputState* state = |
| 290 observer_->text_input_manager()->GetTextInputState(); | 307 observer_->text_input_manager()->GetTextInputState(); |
| 291 if (!state) | 308 if (!state) |
| 292 return false; | 309 return false; |
| 293 *type = state->type; | 310 *type = state->type; |
| 294 return true; | 311 return true; |
| 295 } | 312 } |
| 296 | 313 |
| 297 bool TextInputManagerTester::GetTextInputValue(std::string* value) { | 314 bool TextInputManagerTester::GetTextInputValue(std::string* value) { |
| 298 DCHECK(observer_->text_input_manager()); | 315 DCHECK(observer_->text_input_manager()); |
| 299 const TextInputState* state = | 316 const TextInputState* state = |
| 300 observer_->text_input_manager()->GetTextInputState(); | 317 observer_->text_input_manager()->GetTextInputState(); |
| 301 if (!state) | 318 if (!state) |
| 302 return false; | 319 return false; |
| 303 *value = state->value; | 320 *value = state->value; |
| 304 return true; | 321 return true; |
| 305 } | 322 } |
| 306 | 323 |
| 307 const RenderWidgetHostView* TextInputManagerTester::GetActiveView() { | 324 const RenderWidgetHostView* TextInputManagerTester::GetActiveView() { |
| 308 DCHECK(observer_->text_input_manager()); | 325 DCHECK(observer_->text_input_manager()); |
| 309 return observer_->text_input_manager()->active_view_for_testing(); | 326 return observer_->text_input_manager()->active_view_for_testing(); |
| 310 } | 327 } |
| 311 | 328 |
| 312 const RenderWidgetHostView* TextInputManagerTester::GetUpdatedView() { | 329 const RenderWidgetHostView* TextInputManagerTester::GetUpdatedView() { |
| 313 return observer_->GetUpdatedView(); | 330 return observer_->GetUpdatedView(); |
| 314 } | 331 } |
| 315 | 332 |
| 333 bool TextInputManagerTester::GetCurrentTextSelectionLength(size_t* length) { |
| 334 DCHECK(observer_->text_input_manager()); |
| 335 |
| 336 if (!observer_->text_input_manager()->GetActiveWidget()) |
| 337 return false; |
| 338 |
| 339 *length = observer_->text_input_manager()->GetTextSelection()->text.size(); |
| 340 return true; |
| 341 } |
| 342 |
| 316 bool TextInputManagerTester::IsTextInputStateChanged() { | 343 bool TextInputManagerTester::IsTextInputStateChanged() { |
| 317 return observer_->text_input_state_changed(); | 344 return observer_->text_input_state_changed(); |
| 318 } | 345 } |
| 319 | 346 |
| 320 TestRenderWidgetHostViewDestructionObserver:: | 347 TestRenderWidgetHostViewDestructionObserver:: |
| 321 TestRenderWidgetHostViewDestructionObserver(RenderWidgetHostView* view) | 348 TestRenderWidgetHostViewDestructionObserver(RenderWidgetHostView* view) |
| 322 : observer_( | 349 : observer_( |
| 323 new InternalObserver(static_cast<RenderWidgetHostViewBase*>(view))) {} | 350 new InternalObserver(static_cast<RenderWidgetHostViewBase*>(view))) {} |
| 324 | 351 |
| 325 TestRenderWidgetHostViewDestructionObserver:: | 352 TestRenderWidgetHostViewDestructionObserver:: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 | 412 |
| 386 #ifdef USE_AURA | 413 #ifdef USE_AURA |
| 387 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( | 414 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( |
| 388 web_contents->GetRenderWidgetHostView()); | 415 web_contents->GetRenderWidgetHostView()); |
| 389 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); | 416 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); |
| 390 #endif | 417 #endif |
| 391 return observer; | 418 return observer; |
| 392 } | 419 } |
| 393 | 420 |
| 394 } // namespace content | 421 } // namespace content |
| OLD | NEW |