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

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: Fixed Compile Errors 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
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_impl.h" 7 #include "content/browser/renderer_host/render_widget_host_impl.h"
8 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 8 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
9 #include "content/browser/renderer_host/render_widget_host_view_base.h" 9 #include "content/browser/renderer_host/render_widget_host_view_base.h"
10 #include "content/browser/renderer_host/render_widget_host_view_base_observer.h" 10 #include "content/browser/renderer_host/render_widget_host_view_base_observer.h"
11 #include "content/browser/renderer_host/text_input_manager.h" 11 #include "content/browser/renderer_host/text_input_manager.h"
12 #include "content/browser/web_contents/web_contents_impl.h" 12 #include "content/browser/web_contents/web_contents_impl.h"
13 #include "content/common/text_input_state.h" 13 #include "content/common/text_input_state.h"
14 #include "content/common/view_messages.h"
14 #include "content/public/browser/render_widget_host_view.h" 15 #include "content/public/browser/render_widget_host_view.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_observer.h" 17 #include "content/public/browser/web_contents_observer.h"
17 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
18 #include "ui/base/ime/input_method.h" 19 #include "ui/base/ime/input_method.h"
19 #include "ui/base/ime/input_method_observer.h" 20 #include "ui/base/ime/input_method_observer.h"
20 21
21 namespace ui { 22 namespace ui {
22 class TextInputClient; 23 class TextInputClient;
23 } 24 }
24 25
25 namespace content { 26 namespace content {
26 27
28 namespace {
29 void DefaultTextInputManagerObserverCallback(TextInputManagerTester* tester) {}
30 TextInputManagerTester::Callback default_text_input_manager_observer_callback =
31 base::Bind(&DefaultTextInputManagerObserverCallback);
32 } // namespace
33
27 // This class is an observer of TextInputManager associated with the provided 34 // This class is an observer of TextInputManager associated with the provided
28 // WebContents. An instance of this class is used in TextInputManagerTester to 35 // WebContents. An instance of this class is used in TextInputManagerTester to
29 // expose the required API for testing outside of content/. 36 // expose the required API for testing outside of content/.
30 class TextInputManagerTester::InternalObserver 37 class TextInputManagerTester::InternalObserver
31 : public TextInputManager::Observer, 38 : public TextInputManager::Observer,
32 public WebContentsObserver { 39 public WebContentsObserver {
33 public: 40 public:
34 InternalObserver(WebContents* web_contents, TextInputManagerTester* tester) 41 InternalObserver(WebContents* web_contents, TextInputManagerTester* tester)
35 : WebContentsObserver(web_contents), 42 : WebContentsObserver(web_contents),
36 tester_(tester), 43 tester_(tester),
37 updated_view_(nullptr), 44 updated_view_(nullptr),
38 text_input_state_changed_(false) { 45 text_input_state_changed_(false),
46 update_text_input_state_callback_(
47 default_text_input_manager_observer_callback),
48 on_selection_bounds_changed_callback_(
49 default_text_input_manager_observer_callback) {
39 text_input_manager_ = 50 text_input_manager_ =
40 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager(); 51 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager();
41 DCHECK(!!text_input_manager_); 52 DCHECK(!!text_input_manager_);
42 text_input_manager_->AddObserver(this); 53 text_input_manager_->AddObserver(this);
43 } 54 }
44 55
45 ~InternalObserver() override { 56 ~InternalObserver() override {
46 if (text_input_manager_) 57 if (text_input_manager_)
47 text_input_manager_->RemoveObserver(this); 58 text_input_manager_->RemoveObserver(this);
48 } 59 }
49 60
50 void set_update_text_input_state_called_callback( 61 void set_update_text_input_state_called_callback(
51 const TextInputManagerTester::Callback& callback) { 62 const TextInputManagerTester::Callback& callback) {
52 update_text_input_state_callback_ = callback; 63 update_text_input_state_callback_ = callback;
53 } 64 }
54 65
66 void set_on_selection_bounds_changed_callback(
67 const TextInputManagerTester::Callback& callback) {
68 on_selection_bounds_changed_callback_ = callback;
69 }
70
55 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } 71 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; }
56 72
57 bool text_input_state_changed() const { return text_input_state_changed_; } 73 bool text_input_state_changed() const { return text_input_state_changed_; }
58 74
59 TextInputManager* text_input_manager() const { return text_input_manager_; } 75 TextInputManager* text_input_manager() const { return text_input_manager_; }
60 76
61 // TextInputManager::Observer implementations. 77 // TextInputManager::Observer implementations.
62 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, 78 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager,
63 RenderWidgetHostViewBase* updated_view, 79 RenderWidgetHostViewBase* updated_view,
64 bool did_change_state) override { 80 bool did_change_state) override {
65 if (text_input_manager_ != text_input_manager) 81 if (text_input_manager_ != text_input_manager)
66 return; 82 return;
67 text_input_state_changed_ = did_change_state; 83 text_input_state_changed_ = did_change_state;
68 updated_view_ = updated_view; 84 updated_view_ = updated_view;
69 update_text_input_state_callback_.Run(tester_); 85 update_text_input_state_callback_.Run(tester_);
70 } 86 }
71 87
88 void OnSelectionBoundsChanged(
89 TextInputManager* text_input_manager_,
90 RenderWidgetHostViewBase* updated_view) override {
91 updated_view_ = updated_view;
92 on_selection_bounds_changed_callback_.Run(tester_);
93 }
94
72 // WebContentsObserver implementation. 95 // WebContentsObserver implementation.
73 void WebContentsDestroyed() override { text_input_manager_ = nullptr; } 96 void WebContentsDestroyed() override { text_input_manager_ = nullptr; }
74 97
75 private: 98 private:
76 TextInputManagerTester* tester_; 99 TextInputManagerTester* tester_;
77 TextInputManager* text_input_manager_; 100 TextInputManager* text_input_manager_;
78 RenderWidgetHostViewBase* updated_view_; 101 RenderWidgetHostViewBase* updated_view_;
79 bool text_input_state_changed_; 102 bool text_input_state_changed_;
80 TextInputManagerTester::Callback update_text_input_state_callback_; 103 TextInputManagerTester::Callback update_text_input_state_callback_;
104 TextInputManagerTester::Callback on_selection_bounds_changed_callback_;
81 105
82 DISALLOW_COPY_AND_ASSIGN(InternalObserver); 106 DISALLOW_COPY_AND_ASSIGN(InternalObserver);
83 }; 107 };
84 108
85 // This class observes the lifetime of a RenderWidgetHostView. An instance of 109 // This class observes the lifetime of a RenderWidgetHostView. An instance of
86 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose 110 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose
87 // the required observer API for testing outside of content/. 111 // the required observer API for testing outside of content/.
88 class TestRenderWidgetHostViewDestructionObserver::InternalObserver 112 class TestRenderWidgetHostViewDestructionObserver::InternalObserver
89 : public RenderWidgetHostViewBaseObserver { 113 : public RenderWidgetHostViewBaseObserver {
90 public: 114 public:
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 TextInputManagerTester::TextInputManagerTester(WebContents* web_contents) 233 TextInputManagerTester::TextInputManagerTester(WebContents* web_contents)
210 : observer_(new InternalObserver(web_contents, this)) {} 234 : observer_(new InternalObserver(web_contents, this)) {}
211 235
212 TextInputManagerTester::~TextInputManagerTester() {} 236 TextInputManagerTester::~TextInputManagerTester() {}
213 237
214 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback( 238 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback(
215 const Callback& callback) { 239 const Callback& callback) {
216 observer_->set_update_text_input_state_called_callback(callback); 240 observer_->set_update_text_input_state_called_callback(callback);
217 } 241 }
218 242
243 void TextInputManagerTester::SetOnSelectionBoundsChangedCallback(
244 const Callback& callback) {
245 observer_->set_on_selection_bounds_changed_callback(callback);
246 }
247
219 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) { 248 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) {
220 DCHECK(observer_->text_input_manager()); 249 DCHECK(observer_->text_input_manager());
221 const TextInputState* state = 250 const TextInputState* state =
222 observer_->text_input_manager()->GetTextInputState(); 251 observer_->text_input_manager()->GetTextInputState();
223 if (!state) 252 if (!state)
224 return false; 253 return false;
225 *type = state->type; 254 *type = state->type;
226 return true; 255 return true;
227 } 256 }
228 257
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 346
318 #ifdef USE_AURA 347 #ifdef USE_AURA
319 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( 348 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>(
320 web_contents->GetRenderWidgetHostView()); 349 web_contents->GetRenderWidgetHostView());
321 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); 350 observer.reset(new InputMethodObserverAura(view->GetInputMethod()));
322 #endif 351 #endif
323 return observer; 352 return observer;
324 } 353 }
325 354
326 } // namespace content 355 } // namespace content
OLDNEW
« content/public/test/text_input_test_utils.h ('K') | « content/public/test/text_input_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698