Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: content/public/test/text_input_test_utils.cc

Issue 2057803002: Tracking SelectionBounds for all RenderWidgets on the Browser Side (Aura Only) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/renderer_host/render_widget_host_view_aura.h" 7 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
8 #include "content/browser/renderer_host/render_widget_host_view_base.h" 8 #include "content/browser/renderer_host/render_widget_host_view_base.h"
9 #include "content/browser/renderer_host/render_widget_host_view_base_observer.h" 9 #include "content/browser/renderer_host/render_widget_host_view_base_observer.h"
10 #include "content/browser/renderer_host/text_input_manager.h" 10 #include "content/browser/renderer_host/text_input_manager.h"
11 #include "content/browser/web_contents/web_contents_impl.h" 11 #include "content/browser/web_contents/web_contents_impl.h"
12 #include "content/common/text_input_state.h" 12 #include "content/common/text_input_state.h"
13 #include "content/common/view_messages.h"
13 #include "content/public/browser/render_widget_host_view.h" 14 #include "content/public/browser/render_widget_host_view.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/test/test_utils.h" 17 #include "content/public/test/test_utils.h"
17 #include "ui/base/ime/input_method.h" 18 #include "ui/base/ime/input_method.h"
18 #include "ui/base/ime/input_method_observer.h" 19 #include "ui/base/ime/input_method_observer.h"
19 20
20 namespace ui { 21 namespace ui {
21 class TextInputClient; 22 class TextInputClient;
22 } 23 }
23 24
24 namespace content { 25 namespace content {
25 26
27 namespace {
28 void DefaultTextInputManagerObserverCallback(TextInputManagerTester* tester) {}
29 TextInputManagerTester::Callback default_text_input_manager_observer_callback =
30 base::Bind(&DefaultTextInputManagerObserverCallback);
EhsanK 2016/06/27 17:18:13 This is to avoid crashes in the observers in 'site
31 } // namespace
32
26 // This class is an observer of TextInputManager associated with the provided 33 // This class is an observer of TextInputManager associated with the provided
27 // WebContents. An instance of this class is used in TextInputManagerTester to 34 // WebContents. An instance of this class is used in TextInputManagerTester to
28 // expose the required API for testing outside of content/. 35 // expose the required API for testing outside of content/.
29 class TextInputManagerTester::InternalObserver 36 class TextInputManagerTester::InternalObserver
30 : public TextInputManager::Observer, 37 : public TextInputManager::Observer,
31 public WebContentsObserver { 38 public WebContentsObserver {
32 public: 39 public:
33 InternalObserver(WebContents* web_contents, TextInputManagerTester* tester) 40 InternalObserver(WebContents* web_contents, TextInputManagerTester* tester)
34 : WebContentsObserver(web_contents), 41 : WebContentsObserver(web_contents),
35 tester_(tester), 42 tester_(tester),
36 updated_view_(nullptr), 43 updated_view_(nullptr),
37 text_input_state_changed_(false) { 44 text_input_state_changed_(false),
45 update_text_input_state_callback_(
46 default_text_input_manager_observer_callback),
47 on_selection_bounds_changed_callback_(
48 default_text_input_manager_observer_callback) {
38 text_input_manager_ = 49 text_input_manager_ =
39 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager(); 50 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager();
40 DCHECK(!!text_input_manager_); 51 DCHECK(!!text_input_manager_);
41 text_input_manager_->AddObserver(this); 52 text_input_manager_->AddObserver(this);
42 } 53 }
43 54
44 ~InternalObserver() override { 55 ~InternalObserver() override {
45 if (text_input_manager_) 56 if (text_input_manager_)
46 text_input_manager_->RemoveObserver(this); 57 text_input_manager_->RemoveObserver(this);
47 } 58 }
48 59
49 void set_update_text_input_state_called_callback( 60 void set_update_text_input_state_called_callback(
50 const TextInputManagerTester::Callback& callback) { 61 const TextInputManagerTester::Callback& callback) {
51 update_text_input_state_callback_ = callback; 62 update_text_input_state_callback_ = callback;
52 } 63 }
53 64
65 void set_on_selection_bounds_changed_callback(
66 const TextInputManagerTester::Callback& callback) {
67 on_selection_bounds_changed_callback_ = callback;
68 }
69
54 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } 70 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; }
55 71
56 bool text_input_state_changed() const { return text_input_state_changed_; } 72 bool text_input_state_changed() const { return text_input_state_changed_; }
57 73
58 TextInputManager* text_input_manager() const { return text_input_manager_; } 74 TextInputManager* text_input_manager() const { return text_input_manager_; }
59 75
60 // TextInputManager::Observer implementations. 76 // TextInputManager::Observer implementations.
61 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, 77 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager,
62 RenderWidgetHostViewBase* updated_view, 78 RenderWidgetHostViewBase* updated_view,
63 bool did_change_state) override { 79 bool did_change_state) override {
64 if (text_input_manager_ != text_input_manager) 80 if (text_input_manager_ != text_input_manager)
65 return; 81 return;
66 text_input_state_changed_ = did_change_state; 82 text_input_state_changed_ = did_change_state;
67 updated_view_ = updated_view; 83 updated_view_ = updated_view;
68 update_text_input_state_callback_.Run(tester_); 84 update_text_input_state_callback_.Run(tester_);
69 } 85 }
70 86
87 void OnSelectionBoundsChanged(TextInputManager* text_input_manager_,
88 RenderWidgetHostViewBase* updated_view) {
89 updated_view_ = updated_view;
90 on_selection_bounds_changed_callback_.Run(tester_);
91 }
92
71 // WebContentsObserver implementation. 93 // WebContentsObserver implementation.
72 void WebContentsDestroyed() override { text_input_manager_ = nullptr; } 94 void WebContentsDestroyed() override { text_input_manager_ = nullptr; }
73 95
74 private: 96 private:
75 TextInputManagerTester* tester_; 97 TextInputManagerTester* tester_;
76 TextInputManager* text_input_manager_; 98 TextInputManager* text_input_manager_;
77 RenderWidgetHostViewBase* updated_view_; 99 RenderWidgetHostViewBase* updated_view_;
78 bool text_input_state_changed_; 100 bool text_input_state_changed_;
79 TextInputManagerTester::Callback update_text_input_state_callback_; 101 TextInputManagerTester::Callback update_text_input_state_callback_;
102 TextInputManagerTester::Callback on_selection_bounds_changed_callback_;
80 103
81 DISALLOW_COPY_AND_ASSIGN(InternalObserver); 104 DISALLOW_COPY_AND_ASSIGN(InternalObserver);
82 }; 105 };
83 106
84 // This class observes the lifetime of a RenderWidgetHostView. An instance of 107 // This class observes the lifetime of a RenderWidgetHostView. An instance of
85 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose 108 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose
86 // the required observer API for testing outside of content/. 109 // the required observer API for testing outside of content/.
87 class TestRenderWidgetHostViewDestructionObserver::InternalObserver 110 class TestRenderWidgetHostViewDestructionObserver::InternalObserver
88 : public RenderWidgetHostViewBaseObserver { 111 : public RenderWidgetHostViewBaseObserver {
89 public: 112 public:
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 TextInputManagerTester::TextInputManagerTester(WebContents* web_contents) 231 TextInputManagerTester::TextInputManagerTester(WebContents* web_contents)
209 : observer_(new InternalObserver(web_contents, this)) {} 232 : observer_(new InternalObserver(web_contents, this)) {}
210 233
211 TextInputManagerTester::~TextInputManagerTester() {} 234 TextInputManagerTester::~TextInputManagerTester() {}
212 235
213 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback( 236 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback(
214 const Callback& callback) { 237 const Callback& callback) {
215 observer_->set_update_text_input_state_called_callback(callback); 238 observer_->set_update_text_input_state_called_callback(callback);
216 } 239 }
217 240
241 void TextInputManagerTester::SetOnSelectionBoundsChangedCallback(
242 const Callback& callback) {
243 observer_->set_on_selection_bounds_changed_callback(callback);
244 }
245
218 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) { 246 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) {
219 DCHECK(observer_->text_input_manager()); 247 DCHECK(observer_->text_input_manager());
220 const TextInputState* state = 248 const TextInputState* state =
221 observer_->text_input_manager()->GetTextInputState(); 249 observer_->text_input_manager()->GetTextInputState();
222 if (!state) 250 if (!state)
223 return false; 251 return false;
224 *type = state->type; 252 *type = state->type;
225 return true; 253 return true;
226 } 254 }
227 255
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 344
317 #ifdef USE_AURA 345 #ifdef USE_AURA
318 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( 346 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>(
319 web_contents->GetRenderWidgetHostView()); 347 web_contents->GetRenderWidgetHostView());
320 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); 348 observer.reset(new InputMethodObserverAura(view->GetInputMethod()));
321 #endif 349 #endif
322 return observer; 350 return observer;
323 } 351 }
324 352
325 } // namespace content 353 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698