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

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

Issue 2132633002: Tracking composition range on the browser side (Aura) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing creis@'s comments and changing a test method 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/common/view_messages.h"
17 #include "content/public/browser/render_widget_host_view.h" 17 #include "content/public/browser/render_widget_host_view.h"
18 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_observer.h" 19 #include "content/public/browser/web_contents_observer.h"
20 #include "content/public/test/test_utils.h" 20 #include "content/public/test/test_utils.h"
21 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
22 #include "ui/base/ime/composition_underline.h"
21 #include "ui/base/ime/input_method.h" 23 #include "ui/base/ime/input_method.h"
22 #include "ui/base/ime/input_method_observer.h" 24 #include "ui/base/ime/input_method_observer.h"
23 25
24 namespace ui { 26 namespace ui {
25 class TextInputClient; 27 class TextInputClient;
26 } 28 }
27 29
28 namespace content { 30 namespace content {
29 31
30 // This class is an observer of TextInputManager associated with the provided 32 // This class is an observer of TextInputManager associated with the provided
(...skipping 20 matching lines...) Expand all
51 53
52 void set_update_text_input_state_called_callback( 54 void set_update_text_input_state_called_callback(
53 const base::Closure& callback) { 55 const base::Closure& callback) {
54 update_text_input_state_callback_ = callback; 56 update_text_input_state_callback_ = callback;
55 } 57 }
56 58
57 void set_on_selection_bounds_changed_callback(const base::Closure& callback) { 59 void set_on_selection_bounds_changed_callback(const base::Closure& callback) {
58 on_selection_bounds_changed_callback_ = callback; 60 on_selection_bounds_changed_callback_ = callback;
59 } 61 }
60 62
63 void set_on_ime_composition_range_changed_callback(
64 const base::Closure& callback) {
65 on_ime_composition_range_changed_callback_ = callback;
66 }
67
61 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } 68 const RenderWidgetHostView* GetUpdatedView() const { return updated_view_; }
62 69
63 bool text_input_state_changed() const { return text_input_state_changed_; } 70 bool text_input_state_changed() const { return text_input_state_changed_; }
64 71
65 TextInputManager* text_input_manager() const { return text_input_manager_; } 72 TextInputManager* text_input_manager() const { return text_input_manager_; }
66 73
67 // TextInputManager::Observer implementations. 74 // TextInputManager::Observer implementations.
68 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, 75 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager,
69 RenderWidgetHostViewBase* updated_view, 76 RenderWidgetHostViewBase* updated_view,
70 bool did_change_state) override { 77 bool did_change_state) override {
71 if (text_input_manager_ != text_input_manager) 78 if (text_input_manager_ != text_input_manager)
72 return; 79 return;
73 text_input_state_changed_ = did_change_state; 80 text_input_state_changed_ = did_change_state;
74 updated_view_ = updated_view; 81 updated_view_ = updated_view;
75 if (!update_text_input_state_callback_.is_null()) 82 if (!update_text_input_state_callback_.is_null())
76 update_text_input_state_callback_.Run(); 83 update_text_input_state_callback_.Run();
77 } 84 }
78 85
79 void OnSelectionBoundsChanged( 86 void OnSelectionBoundsChanged(
80 TextInputManager* text_input_manager_, 87 TextInputManager* text_input_manager_,
81 RenderWidgetHostViewBase* updated_view) override { 88 RenderWidgetHostViewBase* updated_view) override {
82 updated_view_ = updated_view; 89 updated_view_ = updated_view;
83 if (!on_selection_bounds_changed_callback_.is_null()) 90 if (!on_selection_bounds_changed_callback_.is_null())
84 on_selection_bounds_changed_callback_.Run(); 91 on_selection_bounds_changed_callback_.Run();
85 } 92 }
86 93
94 void OnImeCompositionRangeChanged(
95 TextInputManager* text_input_manager,
96 RenderWidgetHostViewBase* updated_view) override {
97 updated_view_ = updated_view;
98 if (!on_ime_composition_range_changed_callback_.is_null())
99 on_ime_composition_range_changed_callback_.Run();
100 }
101
87 // WebContentsObserver implementation. 102 // WebContentsObserver implementation.
88 void WebContentsDestroyed() override { text_input_manager_ = nullptr; } 103 void WebContentsDestroyed() override { text_input_manager_ = nullptr; }
89 104
90 private: 105 private:
91 TextInputManager* text_input_manager_; 106 TextInputManager* text_input_manager_;
92 RenderWidgetHostViewBase* updated_view_; 107 RenderWidgetHostViewBase* updated_view_;
93 bool text_input_state_changed_; 108 bool text_input_state_changed_;
94 base::Closure update_text_input_state_callback_; 109 base::Closure update_text_input_state_callback_;
95 base::Closure on_selection_bounds_changed_callback_; 110 base::Closure on_selection_bounds_changed_callback_;
111 base::Closure on_ime_composition_range_changed_callback_;
96 112
97 DISALLOW_COPY_AND_ASSIGN(InternalObserver); 113 DISALLOW_COPY_AND_ASSIGN(InternalObserver);
98 }; 114 };
99 115
100 // This class observes the lifetime of a RenderWidgetHostView. An instance of 116 // This class observes the lifetime of a RenderWidgetHostView. An instance of
101 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose 117 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose
102 // the required observer API for testing outside of content/. 118 // the required observer API for testing outside of content/.
103 class TestRenderWidgetHostViewDestructionObserver::InternalObserver 119 class TestRenderWidgetHostViewDestructionObserver::InternalObserver
104 : public RenderWidgetHostViewBaseObserver { 120 : public RenderWidgetHostViewBaseObserver {
105 public: 121 public:
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 RenderWidgetHostViewBase* view_base = 225 RenderWidgetHostViewBase* view_base =
210 static_cast<RenderWidgetHostViewBase*>(view); 226 static_cast<RenderWidgetHostViewBase*>(view);
211 if (!manager || !manager->IsRegistered(view_base)) 227 if (!manager || !manager->IsRegistered(view_base))
212 return false; 228 return false;
213 229
214 *type = manager->GetTextInputTypeForViewForTesting(view_base); 230 *type = manager->GetTextInputTypeForViewForTesting(view_base);
215 231
216 return true; 232 return true;
217 } 233 }
218 234
235 void SetCompositionForRenderWidgetHost(
236 RenderWidgetHost* render_widget_host,
237 const base::string16& text,
238 const std::vector<ui::CompositionUnderline>& underlines,
239 const gfx::Range& replacement_range,
240 int selection_start,
241 int selection_end) {
242 std::vector<blink::WebCompositionUnderline> web_underlines;
243 for (auto underline : underlines) {
244 web_underlines.emplace_back(blink::WebCompositionUnderline(
245 underline.start_offset, underline.end_offset, underline.color,
246 underline.thick, underline.background_color));
247 }
248
249 static_cast<RenderWidgetHostImpl*>(render_widget_host)
250 ->ImeSetComposition(text, web_underlines, replacement_range,
251 selection_start, selection_end);
252 }
253
219 size_t GetRegisteredViewsCountFromTextInputManager(WebContents* web_contents) { 254 size_t GetRegisteredViewsCountFromTextInputManager(WebContents* web_contents) {
220 std::unordered_set<RenderWidgetHostView*> views; 255 std::unordered_set<RenderWidgetHostView*> views;
221 TextInputManager* manager = 256 TextInputManager* manager =
222 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager(); 257 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager();
223 return !!manager ? manager->GetRegisteredViewsCountForTesting() : 0; 258 return !!manager ? manager->GetRegisteredViewsCountForTesting() : 0;
224 } 259 }
225 260
226 RenderWidgetHostView* GetActiveViewFromWebContents(WebContents* web_contents) { 261 RenderWidgetHostView* GetActiveViewFromWebContents(WebContents* web_contents) {
227 return static_cast<WebContentsImpl*>(web_contents) 262 return static_cast<WebContentsImpl*>(web_contents)
228 ->GetTextInputManager() 263 ->GetTextInputManager()
229 ->active_view_for_testing(); 264 ->active_view_for_testing();
230 } 265 }
231 266
232 TextInputManagerTester::TextInputManagerTester(WebContents* web_contents) 267 TextInputManagerTester::TextInputManagerTester(WebContents* web_contents)
233 : observer_(new InternalObserver(web_contents, this)) {} 268 : observer_(new InternalObserver(web_contents, this)) {}
234 269
235 TextInputManagerTester::~TextInputManagerTester() {} 270 TextInputManagerTester::~TextInputManagerTester() {}
236 271
237 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback( 272 void TextInputManagerTester::SetUpdateTextInputStateCalledCallback(
238 const base::Closure& callback) { 273 const base::Closure& callback) {
239 observer_->set_update_text_input_state_called_callback(callback); 274 observer_->set_update_text_input_state_called_callback(callback);
240 } 275 }
241 276
242 void TextInputManagerTester::SetOnSelectionBoundsChangedCallback( 277 void TextInputManagerTester::SetOnSelectionBoundsChangedCallback(
243 const base::Closure& callback) { 278 const base::Closure& callback) {
244 observer_->set_on_selection_bounds_changed_callback(callback); 279 observer_->set_on_selection_bounds_changed_callback(callback);
245 } 280 }
246 281
282 void TextInputManagerTester::SetOnImeCompositionRangeChangedCallback(
283 const base::Closure& callback) {
284 observer_->set_on_ime_composition_range_changed_callback(callback);
285 }
286
247 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) { 287 bool TextInputManagerTester::GetTextInputType(ui::TextInputType* type) {
248 DCHECK(observer_->text_input_manager()); 288 DCHECK(observer_->text_input_manager());
249 const TextInputState* state = 289 const TextInputState* state =
250 observer_->text_input_manager()->GetTextInputState(); 290 observer_->text_input_manager()->GetTextInputState();
251 if (!state) 291 if (!state)
252 return false; 292 return false;
253 *type = state->type; 293 *type = state->type;
254 return true; 294 return true;
255 } 295 }
256 296
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 std::unique_ptr<TestInputMethodObserver> observer; 384 std::unique_ptr<TestInputMethodObserver> observer;
345 385
346 #ifdef USE_AURA 386 #ifdef USE_AURA
347 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( 387 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>(
348 web_contents->GetRenderWidgetHostView()); 388 web_contents->GetRenderWidgetHostView());
349 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); 389 observer.reset(new InputMethodObserverAura(view->GetInputMethod()));
350 #endif 390 #endif
351 return observer; 391 return observer;
352 } 392 }
353 393
354 } // namespace content 394 } // 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