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

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

Issue 2954963003: Request Composition Range Updates for Focused GuestViews based on BrowserPlugins (Closed)
Patch Set: Created 3 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') | no next file » | 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/frame_host/render_frame_host_impl.h" 9 #include "content/browser/frame_host/render_frame_host_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h" 10 #include "content/browser/renderer_host/render_widget_host_impl.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 void set_on_ime_composition_range_changed_callback( 65 void set_on_ime_composition_range_changed_callback(
66 const base::Closure& callback) { 66 const base::Closure& callback) {
67 on_ime_composition_range_changed_callback_ = callback; 67 on_ime_composition_range_changed_callback_ = callback;
68 } 68 }
69 69
70 void set_on_text_selection_changed_callback(const base::Closure& callback) { 70 void set_on_text_selection_changed_callback(const base::Closure& callback) {
71 on_text_selection_changed_callback_ = callback; 71 on_text_selection_changed_callback_ = callback;
72 } 72 }
73 73
74 const gfx::Range* last_composition_range() const {
75 return last_composition_range_.get();
76 }
77
74 RenderWidgetHostView* GetUpdatedView() const { return updated_view_; } 78 RenderWidgetHostView* GetUpdatedView() const { return updated_view_; }
75 79
76 bool text_input_state_changed() const { return text_input_state_changed_; } 80 bool text_input_state_changed() const { return text_input_state_changed_; }
77 81
78 TextInputManager* text_input_manager() const { return text_input_manager_; } 82 TextInputManager* text_input_manager() const { return text_input_manager_; }
79 83
80 // TextInputManager::Observer implementations. 84 // TextInputManager::Observer implementations.
81 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager, 85 void OnUpdateTextInputStateCalled(TextInputManager* text_input_manager,
82 RenderWidgetHostViewBase* updated_view, 86 RenderWidgetHostViewBase* updated_view,
83 bool did_change_state) override { 87 bool did_change_state) override {
(...skipping 10 matching lines...) Expand all
94 RenderWidgetHostViewBase* updated_view) override { 98 RenderWidgetHostViewBase* updated_view) override {
95 updated_view_ = updated_view; 99 updated_view_ = updated_view;
96 if (!on_selection_bounds_changed_callback_.is_null()) 100 if (!on_selection_bounds_changed_callback_.is_null())
97 on_selection_bounds_changed_callback_.Run(); 101 on_selection_bounds_changed_callback_.Run();
98 } 102 }
99 103
100 void OnImeCompositionRangeChanged( 104 void OnImeCompositionRangeChanged(
101 TextInputManager* text_input_manager, 105 TextInputManager* text_input_manager,
102 RenderWidgetHostViewBase* updated_view) override { 106 RenderWidgetHostViewBase* updated_view) override {
103 updated_view_ = updated_view; 107 updated_view_ = updated_view;
108 const gfx::Range* range =
109 text_input_manager_->GetCompositionRangeForTesting();
110 DCHECK(range);
111 last_composition_range_.reset(new gfx::Range(range->start(), range->end()));
104 if (!on_ime_composition_range_changed_callback_.is_null()) 112 if (!on_ime_composition_range_changed_callback_.is_null())
105 on_ime_composition_range_changed_callback_.Run(); 113 on_ime_composition_range_changed_callback_.Run();
106 } 114 }
107 115
108 void OnTextSelectionChanged(TextInputManager* text_input_manager, 116 void OnTextSelectionChanged(TextInputManager* text_input_manager,
109 RenderWidgetHostViewBase* updated_view) override { 117 RenderWidgetHostViewBase* updated_view) override {
110 updated_view_ = updated_view; 118 updated_view_ = updated_view;
111 if (!on_text_selection_changed_callback_.is_null()) 119 if (!on_text_selection_changed_callback_.is_null())
112 on_text_selection_changed_callback_.Run(); 120 on_text_selection_changed_callback_.Run();
113 } 121 }
114 122
115 // WebContentsObserver implementation. 123 // WebContentsObserver implementation.
116 void WebContentsDestroyed() override { text_input_manager_ = nullptr; } 124 void WebContentsDestroyed() override { text_input_manager_ = nullptr; }
117 125
118 private: 126 private:
119 TextInputManager* text_input_manager_; 127 TextInputManager* text_input_manager_;
120 RenderWidgetHostViewBase* updated_view_; 128 RenderWidgetHostViewBase* updated_view_;
121 bool text_input_state_changed_; 129 bool text_input_state_changed_;
130 std::unique_ptr<gfx::Range> last_composition_range_;
122 base::Closure update_text_input_state_callback_; 131 base::Closure update_text_input_state_callback_;
123 base::Closure on_selection_bounds_changed_callback_; 132 base::Closure on_selection_bounds_changed_callback_;
124 base::Closure on_ime_composition_range_changed_callback_; 133 base::Closure on_ime_composition_range_changed_callback_;
125 base::Closure on_text_selection_changed_callback_; 134 base::Closure on_text_selection_changed_callback_;
126 135
127 DISALLOW_COPY_AND_ASSIGN(InternalObserver); 136 DISALLOW_COPY_AND_ASSIGN(InternalObserver);
128 }; 137 };
129 138
130 // This class observes the lifetime of a RenderWidgetHostView. An instance of 139 // This class observes the lifetime of a RenderWidgetHostView. An instance of
131 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose 140 // this class is used in TestRenderWidgetHostViewDestructionObserver to expose
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 for (auto underline : underlines) { 281 for (auto underline : underlines) {
273 web_composition_underlines.emplace_back( 282 web_composition_underlines.emplace_back(
274 static_cast<int>(underline.start_offset), 283 static_cast<int>(underline.start_offset),
275 static_cast<int>(underline.end_offset), underline.color, 284 static_cast<int>(underline.end_offset), underline.color,
276 underline.thick, underline.background_color); 285 underline.thick, underline.background_color);
277 } 286 }
278 RenderWidgetHostImpl::From(rwh)->ImeCommitText( 287 RenderWidgetHostImpl::From(rwh)->ImeCommitText(
279 text, web_composition_underlines, replacement_range, relative_cursor_pos); 288 text, web_composition_underlines, replacement_range, relative_cursor_pos);
280 } 289 }
281 290
291 void SendImeSetCompositionTextToWidget(
292 RenderWidgetHost* rwh,
293 const base::string16& text,
294 const std::vector<ui::CompositionUnderline>& underlines,
295 const gfx::Range& replacement_range,
296 int selection_start,
297 int selection_end) {
298 std::vector<blink::WebCompositionUnderline> web_composition_underlines;
299 for (auto underline : underlines) {
300 web_composition_underlines.emplace_back(
301 static_cast<int>(underline.start_offset),
302 static_cast<int>(underline.end_offset), underline.color,
303 underline.thick, underline.background_color);
304 }
305 RenderWidgetHostImpl::From(rwh)->ImeSetComposition(
306 text, web_composition_underlines, replacement_range, selection_start,
307 selection_end);
308 }
309
282 size_t GetRegisteredViewsCountFromTextInputManager(WebContents* web_contents) { 310 size_t GetRegisteredViewsCountFromTextInputManager(WebContents* web_contents) {
283 std::unordered_set<RenderWidgetHostView*> views; 311 std::unordered_set<RenderWidgetHostView*> views;
284 TextInputManager* manager = 312 TextInputManager* manager =
285 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager(); 313 static_cast<WebContentsImpl*>(web_contents)->GetTextInputManager();
286 return !!manager ? manager->GetRegisteredViewsCountForTesting() : 0; 314 return !!manager ? manager->GetRegisteredViewsCountForTesting() : 0;
287 } 315 }
288 316
289 RenderWidgetHostView* GetActiveViewFromWebContents(WebContents* web_contents) { 317 RenderWidgetHostView* GetActiveViewFromWebContents(WebContents* web_contents) {
290 return static_cast<WebContentsImpl*>(web_contents) 318 return static_cast<WebContentsImpl*>(web_contents)
291 ->GetTextInputManager() 319 ->GetTextInputManager()
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 bool TextInputManagerTester::GetCurrentTextSelectionLength(size_t* length) { 377 bool TextInputManagerTester::GetCurrentTextSelectionLength(size_t* length) {
350 DCHECK(observer_->text_input_manager()); 378 DCHECK(observer_->text_input_manager());
351 379
352 if (!observer_->text_input_manager()->GetActiveWidget()) 380 if (!observer_->text_input_manager()->GetActiveWidget())
353 return false; 381 return false;
354 382
355 *length = observer_->text_input_manager()->GetTextSelection()->text().size(); 383 *length = observer_->text_input_manager()->GetTextSelection()->text().size();
356 return true; 384 return true;
357 } 385 }
358 386
387 bool TextInputManagerTester::GetLastCompositionRangeLength(uint32_t* length) {
388 if (!observer_->last_composition_range())
389 return false;
390 *length = observer_->last_composition_range()->length();
391 return true;
392 }
393
359 bool TextInputManagerTester::IsTextInputStateChanged() { 394 bool TextInputManagerTester::IsTextInputStateChanged() {
360 return observer_->text_input_state_changed(); 395 return observer_->text_input_state_changed();
361 } 396 }
362 397
363 TestRenderWidgetHostViewDestructionObserver:: 398 TestRenderWidgetHostViewDestructionObserver::
364 TestRenderWidgetHostViewDestructionObserver(RenderWidgetHostView* view) 399 TestRenderWidgetHostViewDestructionObserver(RenderWidgetHostView* view)
365 : observer_( 400 : observer_(
366 new InternalObserver(static_cast<RenderWidgetHostViewBase*>(view))) {} 401 new InternalObserver(static_cast<RenderWidgetHostViewBase*>(view))) {}
367 402
368 TestRenderWidgetHostViewDestructionObserver:: 403 TestRenderWidgetHostViewDestructionObserver::
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 459
425 #ifdef USE_AURA 460 #ifdef USE_AURA
426 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>( 461 RenderWidgetHostViewAura* view = static_cast<RenderWidgetHostViewAura*>(
427 web_contents->GetRenderWidgetHostView()); 462 web_contents->GetRenderWidgetHostView());
428 observer.reset(new InputMethodObserverAura(view->GetInputMethod())); 463 observer.reset(new InputMethodObserverAura(view->GetInputMethod()));
429 #endif 464 #endif
430 return observer; 465 return observer;
431 } 466 }
432 467
433 } // namespace content 468 } // namespace content
OLDNEW
« no previous file with comments | « 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