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

Side by Side Diff: content/browser/renderer_host/text_input_manager.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: Addressing creis@'s comments 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/browser/renderer_host/text_input_manager.h" 5 #include "content/browser/renderer_host/text_input_manager.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_base.h" 8 #include "content/browser/renderer_host/render_widget_host_view_base.h"
9 #include "content/common/view_messages.h"
9 10
10 namespace content { 11 namespace content {
11 12
12 namespace { 13 namespace {
13 14
14 bool AreDifferentTextInputStates(const content::TextInputState& old_state, 15 bool AreDifferentTextInputStates(const content::TextInputState& old_state,
15 const content::TextInputState& new_state) { 16 const content::TextInputState& new_state) {
16 #if defined(USE_AURA) 17 #if defined(USE_AURA)
17 return old_state.type != new_state.type || old_state.mode != new_state.mode || 18 return old_state.type != new_state.type || old_state.mode != new_state.mode ||
18 old_state.flags != new_state.flags || 19 old_state.flags != new_state.flags ||
(...skipping 28 matching lines...) Expand all
47 const TextInputState* TextInputManager::GetTextInputState() { 48 const TextInputState* TextInputManager::GetTextInputState() {
48 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr; 49 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr;
49 } 50 }
50 51
51 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const { 52 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const {
52 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>( 53 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>(
53 active_view_->GetRenderWidgetHost()) 54 active_view_->GetRenderWidgetHost())
54 : nullptr; 55 : nullptr;
55 } 56 }
56 57
58 gfx::Rect TextInputManager::GetSelectionBoundsRect() {
59 if (!active_view_)
60 return gfx::Rect();
61
62 return gfx::RectBetweenSelectionBounds(
63 selection_region_map_[active_view_].anchor,
64 selection_region_map_[active_view_].focus);
65 }
66
57 void TextInputManager::UpdateTextInputState( 67 void TextInputManager::UpdateTextInputState(
58 RenderWidgetHostViewBase* view, 68 RenderWidgetHostViewBase* view,
59 const TextInputState& text_input_state) { 69 const TextInputState& text_input_state) {
60 DCHECK(IsRegistered(view)); 70 DCHECK(IsRegistered(view));
61 71
62 // Since |view| is registgered, we already have a previous value for its 72 // Since |view| is registgered, we already have a previous value for its
63 // TextInputState. 73 // TextInputState.
64 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], 74 bool changed = AreDifferentTextInputStates(text_input_state_map_[view],
65 text_input_state); 75 text_input_state);
66 76
(...skipping 10 matching lines...) Expand all
77 87
78 NotifyObserversAboutInputStateUpdate(view, changed); 88 NotifyObserversAboutInputStateUpdate(view, changed);
79 } 89 }
80 90
81 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { 91 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) {
82 DCHECK(IsRegistered(view)); 92 DCHECK(IsRegistered(view));
83 FOR_EACH_OBSERVER(Observer, observer_list_, 93 FOR_EACH_OBSERVER(Observer, observer_list_,
84 OnImeCancelComposition(this, view)); 94 OnImeCancelComposition(this, view));
85 } 95 }
86 96
97 void TextInputManager::SelectionBoundsChanged(
98 RenderWidgetHostViewBase* view,
99 const ViewHostMsg_SelectionBounds_Params& params) {
100 DCHECK(IsRegistered(view));
101
102 // TODO(ekaramad): Implement the logic for other platforms (crbug.com/578168).
103 #if defined(USE_AURA)
104 gfx::SelectionBound anchor_bound, focus_bound;
105 // Converting the points to the |view|'s root coordinate space (for child
106 // frame views).
107 anchor_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace(
108 params.anchor_rect.origin())),
109 gfx::PointF(view->TransformPointToRootCoordSpace(
110 params.anchor_rect.bottom_left())));
111 focus_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace(
112 params.focus_rect.origin())),
113 gfx::PointF(view->TransformPointToRootCoordSpace(
114 params.focus_rect.bottom_left())));
115
116 if (params.anchor_rect == params.focus_rect) {
117 anchor_bound.set_type(gfx::SelectionBound::CENTER);
118 focus_bound.set_type(gfx::SelectionBound::CENTER);
119 } else {
120 // Whether text is LTR at the anchor handle.
121 bool anchor_LTR = params.anchor_dir == blink::WebTextDirectionLeftToRight;
122 // Whether text is LTR at the focus handle.
123 bool focus_LTR = params.focus_dir == blink::WebTextDirectionLeftToRight;
124
125 if ((params.is_anchor_first && anchor_LTR) ||
126 (!params.is_anchor_first && !anchor_LTR)) {
127 anchor_bound.set_type(gfx::SelectionBound::LEFT);
128 } else {
129 anchor_bound.set_type(gfx::SelectionBound::RIGHT);
130 }
131 if ((params.is_anchor_first && focus_LTR) ||
132 (!params.is_anchor_first && !focus_LTR)) {
133 focus_bound.set_type(gfx::SelectionBound::RIGHT);
134 } else {
135 focus_bound.set_type(gfx::SelectionBound::LEFT);
136 }
137 }
138
139 if (anchor_bound == selection_region_map_[view].anchor &&
140 focus_bound == selection_region_map_[view].focus)
141 return;
142
143 selection_region_map_[view].anchor = anchor_bound;
144 selection_region_map_[view].focus = focus_bound;
145
146 FOR_EACH_OBSERVER(Observer, observer_list_,
147 OnSelectionBoundsChanged(this, view));
148 #endif
149 }
150
87 void TextInputManager::Register(RenderWidgetHostViewBase* view) { 151 void TextInputManager::Register(RenderWidgetHostViewBase* view) {
88 DCHECK(!IsRegistered(view)); 152 DCHECK(!IsRegistered(view));
89 153
90 text_input_state_map_[view] = TextInputState(); 154 text_input_state_map_[view] = TextInputState();
91 } 155 }
92 156
93 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { 157 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) {
94 DCHECK(IsRegistered(view)); 158 DCHECK(IsRegistered(view));
95 159
96 text_input_state_map_.erase(view); 160 text_input_state_map_.erase(view);
(...skipping 27 matching lines...) Expand all
124 } 188 }
125 189
126 void TextInputManager::NotifyObserversAboutInputStateUpdate( 190 void TextInputManager::NotifyObserversAboutInputStateUpdate(
127 RenderWidgetHostViewBase* updated_view, 191 RenderWidgetHostViewBase* updated_view,
128 bool did_update_state) { 192 bool did_update_state) {
129 FOR_EACH_OBSERVER( 193 FOR_EACH_OBSERVER(
130 Observer, observer_list_, 194 Observer, observer_list_,
131 OnUpdateTextInputStateCalled(this, updated_view, did_update_state)); 195 OnUpdateTextInputStateCalled(this, updated_view, did_update_state));
132 } 196 }
133 197
198 TextInputManager::SelectionRegion::SelectionRegion() {}
199
200 TextInputManager::SelectionRegion::SelectionRegion(
201 const SelectionRegion& other) = default;
202
134 } // namespace content 203 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/text_input_manager.h ('k') | content/public/test/text_input_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698