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

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

Issue 2130133004: Tracking text selection on the browser side in OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added an interactive ui test 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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 void set_update_text_input_state_called_callback( 52 void set_update_text_input_state_called_callback(
53 const base::Closure& 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) { 57 void set_on_selection_bounds_changed_callback(const base::Closure& callback) {
58 on_selection_bounds_changed_callback_ = callback; 58 on_selection_bounds_changed_callback_ = callback;
59 } 59 }
60 60
61 void set_on_text_selection_changed_callback(const base::Closure& callback) {
62 on_text_selection_changed_callback_ = callback;
63 }
64
61 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } 65 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; }
62 66
63 bool text_input_state_changed() const { return text_input_state_changed_; } 67 bool text_input_state_changed() const { return text_input_state_changed_; }
64 68
65 TextInputManager* text_input_manager() const { return text_input_manager_; } 69 TextInputManager* text_input_manager() const { return text_input_manager_; }
66 70
67 // TextInputManager::Observer implementations. 71 // TextInputManager::Observer implementations.
68 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, 72 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager,
69 RenderWidgetHostViewBase* updated_view, 73 RenderWidgetHostViewBase* updated_view,
70 bool did_change_state) override { 74 bool did_change_state) override {
71 if (text_input_manager_ != text_input_manager) 75 if (text_input_manager_ != text_input_manager)
72 return; 76 return;
73 text_input_state_changed_ = did_change_state; 77 text_input_state_changed_ = did_change_state;
74 updated_view_ = updated_view; 78 updated_view_ = updated_view;
75 if (!update_text_input_state_callback_.is_null()) 79 if (!update_text_input_state_callback_.is_null())
76 update_text_input_state_callback_.Run(); 80 update_text_input_state_callback_.Run();
77 } 81 }
78 82
79 void OnSelectionBoundsChanged( 83 void OnSelectionBoundsChanged(
80 TextInputManager* text_input_manager_, 84 TextInputManager* text_input_manager_,
81 RenderWidgetHostViewBase* updated_view) override { 85 RenderWidgetHostViewBase* updated_view) override {
82 updated_view_ = updated_view; 86 updated_view_ = updated_view;
83 if (!on_selection_bounds_changed_callback_.is_null()) 87 if (!on_selection_bounds_changed_callback_.is_null())
84 on_selection_bounds_changed_callback_.Run(); 88 on_selection_bounds_changed_callback_.Run();
85 } 89 }
86 90
91 void OnTextSelectionChanged(TextInputManager* text_input_manager,
92 RenderWidgetHostViewBase* updated_view) override {
93 updated_view_ = updated_view;
94 if (!on_text_selection_changed_callback_.is_null())
95 on_text_selection_changed_callback_.Run();
96 }
97
87 // WebContentsObserver implementation. 98 // WebContentsObserver implementation.
88 void WebContentsDestroyed() override { text_input_manager_ = nullptr; } 99 void WebContentsDestroyed() override { text_input_manager_ = nullptr; }
89 100
90 private: 101 private:
91 TextInputManager* text_input_manager_; 102 TextInputManager* text_input_manager_;
92 RenderWidgetHostViewBase* updated_view_; 103 RenderWidgetHostViewBase* updated_view_;
93 bool text_input_state_changed_; 104 bool text_input_state_changed_;
94 base::Closure update_text_input_state_callback_; 105 base::Closure update_text_input_state_callback_;
95 base::Closure on_selection_bounds_changed_callback_; 106 base::Closure on_selection_bounds_changed_callback_;
107 base::Closure on_text_selection_changed_callback_;
96 108
97 DISALLOW_COPY_AND_ASSIGN(InternalObserver); 109 DISALLOW_COPY_AND_ASSIGN(InternalObserver);
98 }; 110 };
99 111
100 // This class observes the lifetime of a RenderWidgetHostView. An instance of 112 // This class observes the lifetime of a RenderWidgetHostView. An instance of
101 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose 113 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose
102 // the required observer API for testing outside of content/. 114 // the required observer API for testing outside of content/.
103 class TestRenderWidgetHostViewDestructionObserver::InternalObserver 115 class TestRenderWidgetHostViewDestructionObserver::InternalObserver
104 : public RenderWidgetHostViewBaseObserver { 116 : public RenderWidgetHostViewBaseObserver {
105 public: 117 public:
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback( 249 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback(
238 const base::Closure& callback) { 250 const base::Closure& callback) {
239 observer_->set_update_text_input_state_called_callback(callback); 251 observer_->set_update_text_input_state_called_callback(callback);
240 } 252 }
241 253
242 void TextInputManagerTester::SetOnSelectionBoundsChangedCallback( 254 void TextInputManagerTester::SetOnSelectionBoundsChangedCallback(
243 const base::Closure& callback) { 255 const base::Closure& callback) {
244 observer_->set_on_selection_bounds_changed_callback(callback); 256 observer_->set_on_selection_bounds_changed_callback(callback);
245 } 257 }
246 258
259 void TextInputManagerTester::SetOnTextSelectionChangedCallback(
260 const base::Closure& callback) {
261 observer_->set_on_text_selection_changed_callback(callback);
262 }
263
247 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) { 264 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) {
248 DCHECK(observer_->text_input_manager()); 265 DCHECK(observer_->text_input_manager());
249 const TextInputState* state = 266 const TextInputState* state =
250 observer_->text_input_manager()->GetTextInputState(); 267 observer_->text_input_manager()->GetTextInputState();
251 if (!state) 268 if (!state)
252 return false; 269 return false;
253 *type = state->type; 270 *type = state->type;
254 return true; 271 return true;
255 } 272 }
256 273
257 bool TextInputManagerTester::GetTextInputValue(std::string* value) { 274 bool TextInputManagerTester::GetTextInputValue(std::string* value) {
258 DCHECK(observer_->text_input_manager()); 275 DCHECK(observer_->text_input_manager());
259 const TextInputState* state = 276 const TextInputState* state =
260 observer_->text_input_manager()->GetTextInputState(); 277 observer_->text_input_manager()->GetTextInputState();
261 if (!state) 278 if (!state)
262 return false; 279 return false;
263 *value = state->value; 280 *value = state->value;
264 return true; 281 return true;
265 } 282 }
266 283
267 const RenderWidgetHostView* TextInputManagerTester::GetActiveView() { 284 const RenderWidgetHostView* TextInputManagerTester::GetActiveView() {
268 DCHECK(observer_->text_input_manager()); 285 DCHECK(observer_->text_input_manager());
269 return observer_->text_input_manager()->active_view_for_testing(); 286 return observer_->text_input_manager()->active_view_for_testing();
270 } 287 }
271 288
272 const RenderWidgetHostView* TextInputManagerTester::GetUpdatedView() { 289 const RenderWidgetHostView* TextInputManagerTester::GetUpdatedView() {
273 return observer_->GetUpdatedView(); 290 return observer_->GetUpdatedView();
274 } 291 }
275 292
293 bool TextInputManagerTester::GetCurrentTextSelectionLength(size_t* length) {
294 DCHECK(observer_->text_input_manager());
295
296 if (!observer_->text_input_manager()->GetActiveWidget())
297 return false;
298
299 *length = observer_->text_input_manager()->GetTextSelection()->text.size();
300 return true;
301 }
302
276 bool TextInputManagerTester::IsTextInputStateChanged() { 303 bool TextInputManagerTester::IsTextInputStateChanged() {
277 return observer_->text_input_state_changed(); 304 return observer_->text_input_state_changed();
278 } 305 }
279 306
280 TestRenderWidgetHostViewDestructionObserver:: 307 TestRenderWidgetHostViewDestructionObserver::
281 TestRenderWidgetHostViewDestructionObserver(RenderWidgetHostView* view) 308 TestRenderWidgetHostViewDestructionObserver(RenderWidgetHostView* view)
282 : observer_( 309 : observer_(
283 new InternalObserver(static_cast<RenderWidgetHostViewBase*>(view))) {} 310 new InternalObserver(static_cast<RenderWidgetHostViewBase*>(view))) {}
284 311
285 TestRenderWidgetHostViewDestructionObserver:: 312 TestRenderWidgetHostViewDestructionObserver::
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 std::unique_ptr<TestInputMethodObserver> observer; 371 std::unique_ptr<TestInputMethodObserver> observer;
345 372
346 #ifdef USE_AURA 373 #ifdef USE_AURA
347 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( 374 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>(
348 web_contents->GetRenderWidgetHostView()); 375 web_contents->GetRenderWidgetHostView());
349 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); 376 observer.reset(new InputMethodObserverAura(view->GetInputMethod()));
350 #endif 377 #endif
351 return observer; 378 return observer;
352 } 379 }
353 380
354 } // namespace content 381 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698