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

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: Removed |selection_anchor_| and |selection_focus_| from RenderWidgetHostViewAura. 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 <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
30 namespace {
31 void DefaultTextInputManagerObserverCallback(TextInputManagerTester* tester) {}
32 TextInputManagerTester::Callback default_text_input_manager_observer_callback =
33 base::Bind(&DefaultTextInputManagerObserverCallback);
Charlie Reis 2016/06/29 20:18:37 We should not be adding new statically allocated o
EhsanK 2016/06/30 00:24:45 I understand. In initial patches of TextInputMana
Charlie Reis 2016/06/30 20:27:21 I don't remember the objections to that approach,
EhsanK 2016/06/30 21:01:14 In that sense, I think it might look more readable
34 } // namespace
35
29 // This class is an observer of TextInputManager associated with the provided 36 // This class is an observer of TextInputManager associated with the provided
30 // WebContents. An instance of this class is used in TextInputManagerTester to 37 // WebContents. An instance of this class is used in TextInputManagerTester to
31 // expose the required API for testing outside of content/. 38 // expose the required API for testing outside of content/.
32 class TextInputManagerTester::InternalObserver 39 class TextInputManagerTester::InternalObserver
33 : public TextInputManager::Observer, 40 : public TextInputManager::Observer,
34 public WebContentsObserver { 41 public WebContentsObserver {
35 public: 42 public:
36 InternalObserver(WebContents* web_contents, TextInputManagerTester* tester) 43 InternalObserver(WebContents* web_contents, TextInputManagerTester* tester)
37 : WebContentsObserver(web_contents), 44 : WebContentsObserver(web_contents),
38 tester_(tester), 45 tester_(tester),
39 updated_view_(nullptr), 46 updated_view_(nullptr),
40 text_input_state_changed_(false) { 47 text_input_state_changed_(false),
48 update_text_input_state_callback_(
49 default_text_input_manager_observer_callback),
50 on_selection_bounds_changed_callback_(
51 default_text_input_manager_observer_callback) {
41 text_input_manager_ = 52 text_input_manager_ =
42 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager(); 53 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager();
43 DCHECK(!!text_input_manager_); 54 DCHECK(!!text_input_manager_);
44 text_input_manager_->AddObserver(this); 55 text_input_manager_->AddObserver(this);
45 } 56 }
46 57
47 ~InternalObserver() override { 58 ~InternalObserver() override {
48 if (text_input_manager_) 59 if (text_input_manager_)
49 text_input_manager_->RemoveObserver(this); 60 text_input_manager_->RemoveObserver(this);
50 } 61 }
51 62
52 void set_update_text_input_state_called_callback( 63 void set_update_text_input_state_called_callback(
53 const TextInputManagerTester::Callback& callback) { 64 const TextInputManagerTester::Callback& callback) {
54 update_text_input_state_callback_ = callback; 65 update_text_input_state_callback_ = callback;
55 } 66 }
56 67
68 void set_on_selection_bounds_changed_callback(
69 const TextInputManagerTester::Callback& callback) {
70 on_selection_bounds_changed_callback_ = callback;
71 }
72
57 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } 73 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; }
58 74
59 bool text_input_state_changed() const { return text_input_state_changed_; } 75 bool text_input_state_changed() const { return text_input_state_changed_; }
60 76
61 TextInputManager* text_input_manager() const { return text_input_manager_; } 77 TextInputManager* text_input_manager() const { return text_input_manager_; }
62 78
63 // TextInputManager::Observer implementations. 79 // TextInputManager::Observer implementations.
64 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, 80 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager,
65 RenderWidgetHostViewBase* updated_view, 81 RenderWidgetHostViewBase* updated_view,
66 bool did_change_state) override { 82 bool did_change_state) override {
67 if (text_input_manager_ != text_input_manager) 83 if (text_input_manager_ != text_input_manager)
68 return; 84 return;
69 text_input_state_changed_ = did_change_state; 85 text_input_state_changed_ = did_change_state;
70 updated_view_ = updated_view; 86 updated_view_ = updated_view;
71 update_text_input_state_callback_.Run(tester_); 87 update_text_input_state_callback_.Run(tester_);
72 } 88 }
73 89
90 void OnSelectionBoundsChanged(
91 TextInputManager* text_input_manager_,
92 RenderWidgetHostViewBase* updated_view) override {
93 updated_view_ = updated_view;
94 on_selection_bounds_changed_callback_.Run(tester_);
95 }
96
74 // WebContentsObserver implementation. 97 // WebContentsObserver implementation.
75 void WebContentsDestroyed() override { text_input_manager_ = nullptr; } 98 void WebContentsDestroyed() override { text_input_manager_ = nullptr; }
76 99
77 private: 100 private:
78 TextInputManagerTester* tester_; 101 TextInputManagerTester* tester_;
79 TextInputManager* text_input_manager_; 102 TextInputManager* text_input_manager_;
80 RenderWidgetHostViewBase* updated_view_; 103 RenderWidgetHostViewBase* updated_view_;
81 bool text_input_state_changed_; 104 bool text_input_state_changed_;
82 TextInputManagerTester::Callback update_text_input_state_callback_; 105 TextInputManagerTester::Callback update_text_input_state_callback_;
106 TextInputManagerTester::Callback on_selection_bounds_changed_callback_;
83 107
84 DISALLOW_COPY_AND_ASSIGN(InternalObserver); 108 DISALLOW_COPY_AND_ASSIGN(InternalObserver);
85 }; 109 };
86 110
87 // This class observes the lifetime of a RenderWidgetHostView. An instance of 111 // This class observes the lifetime of a RenderWidgetHostView. An instance of
88 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose 112 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose
89 // the required observer API for testing outside of content/. 113 // the required observer API for testing outside of content/.
90 class TestRenderWidgetHostViewDestructionObserver::InternalObserver 114 class TestRenderWidgetHostViewDestructionObserver::InternalObserver
91 : public RenderWidgetHostViewBaseObserver { 115 : public RenderWidgetHostViewBaseObserver {
92 public: 116 public:
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 TextInputManagerTester::TextInputManagerTester(WebContents* web_contents) 243 TextInputManagerTester::TextInputManagerTester(WebContents* web_contents)
220 : observer_(new InternalObserver(web_contents, this)) {} 244 : observer_(new InternalObserver(web_contents, this)) {}
221 245
222 TextInputManagerTester::~TextInputManagerTester() {} 246 TextInputManagerTester::~TextInputManagerTester() {}
223 247
224 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback( 248 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback(
225 const Callback& callback) { 249 const Callback& callback) {
226 observer_->set_update_text_input_state_called_callback(callback); 250 observer_->set_update_text_input_state_called_callback(callback);
227 } 251 }
228 252
253 void TextInputManagerTester::SetOnSelectionBoundsChangedCallback(
254 const Callback& callback) {
255 observer_->set_on_selection_bounds_changed_callback(callback);
256 }
257
229 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) { 258 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) {
230 DCHECK(observer_->text_input_manager()); 259 DCHECK(observer_->text_input_manager());
231 const TextInputState* state = 260 const TextInputState* state =
232 observer_->text_input_manager()->GetTextInputState(); 261 observer_->text_input_manager()->GetTextInputState();
233 if (!state) 262 if (!state)
234 return false; 263 return false;
235 *type = state->type; 264 *type = state->type;
236 return true; 265 return true;
237 } 266 }
238 267
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 356
328 #ifdef USE_AURA 357 #ifdef USE_AURA
329 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( 358 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>(
330 web_contents->GetRenderWidgetHostView()); 359 web_contents->GetRenderWidgetHostView());
331 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); 360 observer.reset(new InputMethodObserverAura(view->GetInputMethod()));
332 #endif 361 #endif
333 return observer; 362 return observer;
334 } 363 }
335 364
336 } // namespace content 365 } // 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