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

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: Addressing creis@'s comments Created 4 years, 5 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
« no previous file with comments | « content/public/test/text_input_test_utils.h ('k') | content/test/test_render_view_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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"
11 #include "content/browser/renderer_host/render_widget_host_view_base.h" 11 #include "content/browser/renderer_host/render_widget_host_view_base.h"
12 #include "content/browser/renderer_host/render_widget_host_view_base_observer.h" 12 #include "content/browser/renderer_host/render_widget_host_view_base_observer.h"
13 #include "content/browser/renderer_host/text_input_manager.h" 13 #include "content/browser/renderer_host/text_input_manager.h"
14 #include "content/browser/web_contents/web_contents_impl.h" 14 #include "content/browser/web_contents/web_contents_impl.h"
15 #include "content/common/text_input_state.h" 15 #include "content/common/text_input_state.h"
16 #include "content/common/view_messages.h"
16 #include "content/public/browser/render_widget_host_view.h" 17 #include "content/public/browser/render_widget_host_view.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
19 #include "content/public/test/test_utils.h" 20 #include "content/public/test/test_utils.h"
20 #include "ui/base/ime/input_method.h" 21 #include "ui/base/ime/input_method.h"
21 #include "ui/base/ime/input_method_observer.h" 22 #include "ui/base/ime/input_method_observer.h"
22 23
23 namespace ui { 24 namespace ui {
24 class TextInputClient; 25 class TextInputClient;
25 } 26 }
26 27
27 namespace content { 28 namespace content {
28 29
29 // This class is an observer of TextInputManager associated with the provided 30 // This class is an observer of TextInputManager associated with the provided
30 // WebContents. An instance of this class is used in TextInputManagerTester to 31 // WebContents. An instance of this class is used in TextInputManagerTester to
31 // expose the required API for testing outside of content/. 32 // expose the required API for testing outside of content/.
32 class TextInputManagerTester::InternalObserver 33 class TextInputManagerTester::InternalObserver
33 : public TextInputManager::Observer, 34 : public TextInputManager::Observer,
34 public WebContentsObserver { 35 public WebContentsObserver {
35 public: 36 public:
36 InternalObserver(WebContents* web_contents, TextInputManagerTester* tester) 37 InternalObserver(WebContents* web_contents, TextInputManagerTester* tester)
37 : WebContentsObserver(web_contents), 38 : WebContentsObserver(web_contents),
38 tester_(tester),
39 updated_view_(nullptr), 39 updated_view_(nullptr),
40 text_input_state_changed_(false) { 40 text_input_state_changed_(false) {
41 text_input_manager_ = 41 text_input_manager_ =
42 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager(); 42 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager();
43 DCHECK(!!text_input_manager_); 43 DCHECK(!!text_input_manager_);
44 text_input_manager_->AddObserver(this); 44 text_input_manager_->AddObserver(this);
45 } 45 }
46 46
47 ~InternalObserver() override { 47 ~InternalObserver() override {
48 if (text_input_manager_) 48 if (text_input_manager_)
49 text_input_manager_->RemoveObserver(this); 49 text_input_manager_->RemoveObserver(this);
50 } 50 }
51 51
52 void set_update_text_input_state_called_callback( 52 void set_update_text_input_state_called_callback(
53 const TextInputManagerTester::Callback& callback) { 53 const base::Closure& callback) {
54 update_text_input_state_callback_ = callback; 54 update_text_input_state_callback_ = callback;
55 } 55 }
56 56
57 void set_on_selection_bounds_changed_callback(const base::Closure& callback) {
58 on_selection_bounds_changed_callback_ = callback;
59 }
60
57 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } 61 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; }
58 62
59 bool text_input_state_changed() const { return text_input_state_changed_; } 63 bool text_input_state_changed() const { return text_input_state_changed_; }
60 64
61 TextInputManager* text_input_manager() const { return text_input_manager_; } 65 TextInputManager* text_input_manager() const { return text_input_manager_; }
62 66
63 // TextInputManager::Observer implementations. 67 // TextInputManager::Observer implementations.
64 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, 68 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager,
65 RenderWidgetHostViewBase* updated_view, 69 RenderWidgetHostViewBase* updated_view,
66 bool did_change_state) override { 70 bool did_change_state) override {
67 if (text_input_manager_ != text_input_manager) 71 if (text_input_manager_ != text_input_manager)
68 return; 72 return;
69 text_input_state_changed_ = did_change_state; 73 text_input_state_changed_ = did_change_state;
70 updated_view_ = updated_view; 74 updated_view_ = updated_view;
71 update_text_input_state_callback_.Run(tester_); 75 if (!update_text_input_state_callback_.is_null())
76 update_text_input_state_callback_.Run();
77 }
78
79 void OnSelectionBoundsChanged(
80 TextInputManager* text_input_manager_,
81 RenderWidgetHostViewBase* updated_view) override {
82 updated_view_ = updated_view;
83 if (!on_selection_bounds_changed_callback_.is_null())
84 on_selection_bounds_changed_callback_.Run();
72 } 85 }
73 86
74 // WebContentsObserver implementation. 87 // WebContentsObserver implementation.
75 void WebContentsDestroyed() override { text_input_manager_ = nullptr; } 88 void WebContentsDestroyed() override { text_input_manager_ = nullptr; }
76 89
77 private: 90 private:
78 TextInputManagerTester* tester_;
79 TextInputManager* text_input_manager_; 91 TextInputManager* text_input_manager_;
80 RenderWidgetHostViewBase* updated_view_; 92 RenderWidgetHostViewBase* updated_view_;
81 bool text_input_state_changed_; 93 bool text_input_state_changed_;
82 TextInputManagerTester::Callback update_text_input_state_callback_; 94 base::Closure update_text_input_state_callback_;
95 base::Closure on_selection_bounds_changed_callback_;
83 96
84 DISALLOW_COPY_AND_ASSIGN(InternalObserver); 97 DISALLOW_COPY_AND_ASSIGN(InternalObserver);
85 }; 98 };
86 99
87 // This class observes the lifetime of a RenderWidgetHostView. An instance of 100 // This class observes the lifetime of a RenderWidgetHostView. An instance of
88 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose 101 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose
89 // the required observer API for testing outside of content/. 102 // the required observer API for testing outside of content/.
90 class TestRenderWidgetHostViewDestructionObserver::InternalObserver 103 class TestRenderWidgetHostViewDestructionObserver::InternalObserver
91 : public RenderWidgetHostViewBaseObserver { 104 : public RenderWidgetHostViewBaseObserver {
92 public: 105 public:
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 ->GetTextInputManager() 228 ->GetTextInputManager()
216 ->active_view_for_testing(); 229 ->active_view_for_testing();
217 } 230 }
218 231
219 TextInputManagerTester::TextInputManagerTester(WebContents* web_contents) 232 TextInputManagerTester::TextInputManagerTester(WebContents* web_contents)
220 : observer_(new InternalObserver(web_contents, this)) {} 233 : observer_(new InternalObserver(web_contents, this)) {}
221 234
222 TextInputManagerTester::~TextInputManagerTester() {} 235 TextInputManagerTester::~TextInputManagerTester() {}
223 236
224 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback( 237 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback(
225 const Callback& callback) { 238 const base::Closure& callback) {
226 observer_->set_update_text_input_state_called_callback(callback); 239 observer_->set_update_text_input_state_called_callback(callback);
227 } 240 }
228 241
242 void TextInputManagerTester::SetOnSelectionBoundsChangedCallback(
243 const base::Closure& callback) {
244 observer_->set_on_selection_bounds_changed_callback(callback);
245 }
246
229 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) { 247 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) {
230 DCHECK(observer_->text_input_manager()); 248 DCHECK(observer_->text_input_manager());
231 const TextInputState* state = 249 const TextInputState* state =
232 observer_->text_input_manager()->GetTextInputState(); 250 observer_->text_input_manager()->GetTextInputState();
233 if (!state) 251 if (!state)
234 return false; 252 return false;
235 *type = state->type; 253 *type = state->type;
236 return true; 254 return true;
237 } 255 }
238 256
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 345
328 #ifdef USE_AURA 346 #ifdef USE_AURA
329 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( 347 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>(
330 web_contents->GetRenderWidgetHostView()); 348 web_contents->GetRenderWidgetHostView());
331 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); 349 observer.reset(new InputMethodObserverAura(view->GetInputMethod()));
332 #endif 350 #endif
333 return observer; 351 return observer;
334 } 352 }
335 353
336 } // namespace content 354 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/text_input_test_utils.h ('k') | content/test/test_render_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698