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

Side by Side Diff: content/browser/renderer_host/text_input_manager.cc

Issue 2213503002: Tracking SelectionBounds for all RenderWidgets on the Browser Side (Mac) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a crash Created 4 years, 4 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 "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "content/browser/renderer_host/render_widget_host_impl.h" 8 #include "content/browser/renderer_host/render_widget_host_impl.h"
9 #include "content/browser/renderer_host/render_widget_host_view_base.h" 9 #include "content/browser/renderer_host/render_widget_host_view_base.h"
10 #include "content/common/view_messages.h" 10 #include "content/common/view_messages.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const { 54 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const {
55 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>( 55 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>(
56 active_view_->GetRenderWidgetHost()) 56 active_view_->GetRenderWidgetHost())
57 : nullptr; 57 : nullptr;
58 } 58 }
59 59
60 const TextInputState* TextInputManager::GetTextInputState() const { 60 const TextInputState* TextInputManager::GetTextInputState() const {
61 return !!active_view_ ? &text_input_state_map_.at(active_view_) : nullptr; 61 return !!active_view_ ? &text_input_state_map_.at(active_view_) : nullptr;
62 } 62 }
63 63
64 gfx::Rect TextInputManager::GetSelectionBoundsRect() const {
65 if (!active_view_)
66 return gfx::Rect();
67
68 return gfx::RectBetweenSelectionBounds(
69 selection_region_map_.at(active_view_).anchor,
70 selection_region_map_.at(active_view_).focus);
71 }
72
73 const std::vector<gfx::Rect>* TextInputManager::GetCompositionCharacterBounds() 64 const std::vector<gfx::Rect>* TextInputManager::GetCompositionCharacterBounds()
74 const { 65 const {
75 return !!active_view_ 66 return !!active_view_
76 ? &composition_range_info_map_.at(active_view_).character_bounds 67 ? &composition_range_info_map_.at(active_view_).character_bounds
77 : nullptr; 68 : nullptr;
78 } 69 }
79 70
80 const TextInputManager::TextSelection* TextInputManager::GetTextSelection( 71 const TextInputManager::TextSelection* TextInputManager::GetTextSelection(
81 RenderWidgetHostViewBase* view) const { 72 RenderWidgetHostViewBase* view) const {
82 DCHECK(!view || IsRegistered(view)); 73 DCHECK(!view || IsRegistered(view));
83 if (!view) 74 if (!view)
84 view = active_view_; 75 view = active_view_;
85 return !!view ? &text_selection_map_.at(view) : nullptr; 76 return !!view ? &text_selection_map_.at(view) : nullptr;
86 } 77 }
87 78
79 #if defined(USE_AURA)
80 gfx::Rect TextInputManager::GetSelectionBoundsRect() const {
81 if (!active_view_)
82 return gfx::Rect();
83
84 return gfx::RectBetweenSelectionBounds(
85 selection_region_map_.at(active_view_).anchor,
86 selection_region_map_.at(active_view_).focus);
87 }
88
89 #elif defined(OS_MACOSX)
90 const gfx::Rect* TextInputManager::GetCaretRect(
91 RenderWidgetHostImpl* widget) const {
92 RenderWidgetHostViewBase* view = widget->GetView();
93 DCHECK(IsRegistered(view));
94 return &selection_region_map_.at(view).caret_rect;
95 }
96
97 const gfx::Rect* TextInputManager::GetFirstSelectionRect(
98 RenderWidgetHostImpl* widget) const {
99 RenderWidgetHostViewBase* view = widget->GetView();
100 DCHECK(IsRegistered(view));
101 return &selection_region_map_.at(view).first_selection_rect;
102 }
103 #endif
104
88 void TextInputManager::UpdateTextInputState( 105 void TextInputManager::UpdateTextInputState(
89 RenderWidgetHostViewBase* view, 106 RenderWidgetHostViewBase* view,
90 const TextInputState& text_input_state) { 107 const TextInputState& text_input_state) {
91 DCHECK(IsRegistered(view)); 108 DCHECK(IsRegistered(view));
92 109
93 if (text_input_state.type == ui::TEXT_INPUT_TYPE_NONE && 110 if (text_input_state.type == ui::TEXT_INPUT_TYPE_NONE &&
94 active_view_ != view) { 111 active_view_ != view) {
95 // We reached here because an IPC is received to reset the TextInputState 112 // We reached here because an IPC is received to reset the TextInputState
96 // for |view|. But |view| != |active_view_|, which suggests that at least 113 // for |view|. But |view| != |active_view_|, which suggests that at least
97 // one other view has become active and we have received the corresponding 114 // one other view has become active and we have received the corresponding
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 156
140 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { 157 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) {
141 DCHECK(IsRegistered(view)); 158 DCHECK(IsRegistered(view));
142 FOR_EACH_OBSERVER(Observer, observer_list_, 159 FOR_EACH_OBSERVER(Observer, observer_list_,
143 OnImeCancelComposition(this, view)); 160 OnImeCancelComposition(this, view));
144 } 161 }
145 162
146 void TextInputManager::SelectionBoundsChanged( 163 void TextInputManager::SelectionBoundsChanged(
147 RenderWidgetHostViewBase* view, 164 RenderWidgetHostViewBase* view,
148 const ViewHostMsg_SelectionBounds_Params& params) { 165 const ViewHostMsg_SelectionBounds_Params& params) {
166 #if !defined(OS_ANDROID)
149 DCHECK(IsRegistered(view)); 167 DCHECK(IsRegistered(view));
150 168 // Converting the anchor point to root's coordinate space (for child frame
151 // TODO(ekaramad): Implement the logic for other platforms (crbug.com/578168). 169 // views).
170 gfx::Point anchor_origin_transformed =
171 view->TransformPointToRootCoordSpace(params.anchor_rect.origin());
152 #if defined(USE_AURA) 172 #if defined(USE_AURA)
153 gfx::SelectionBound anchor_bound, focus_bound; 173 gfx::SelectionBound anchor_bound, focus_bound;
154 // Converting the points to the |view|'s root coordinate space (for child 174
155 // frame views). 175 anchor_bound.SetEdge(gfx::PointF(anchor_origin_transformed),
156 anchor_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace(
157 params.anchor_rect.origin())),
158 gfx::PointF(view->TransformPointToRootCoordSpace( 176 gfx::PointF(view->TransformPointToRootCoordSpace(
159 params.anchor_rect.bottom_left()))); 177 params.anchor_rect.bottom_left())));
160 focus_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace( 178 focus_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace(
161 params.focus_rect.origin())), 179 params.focus_rect.origin())),
162 gfx::PointF(view->TransformPointToRootCoordSpace( 180 gfx::PointF(view->TransformPointToRootCoordSpace(
163 params.focus_rect.bottom_left()))); 181 params.focus_rect.bottom_left())));
164 182
165 if (params.anchor_rect == params.focus_rect) { 183 if (params.anchor_rect == params.focus_rect) {
166 anchor_bound.set_type(gfx::SelectionBound::CENTER); 184 anchor_bound.set_type(gfx::SelectionBound::CENTER);
167 focus_bound.set_type(gfx::SelectionBound::CENTER); 185 focus_bound.set_type(gfx::SelectionBound::CENTER);
(...skipping 16 matching lines...) Expand all
184 focus_bound.set_type(gfx::SelectionBound::LEFT); 202 focus_bound.set_type(gfx::SelectionBound::LEFT);
185 } 203 }
186 } 204 }
187 205
188 if (anchor_bound == selection_region_map_[view].anchor && 206 if (anchor_bound == selection_region_map_[view].anchor &&
189 focus_bound == selection_region_map_[view].focus) 207 focus_bound == selection_region_map_[view].focus)
190 return; 208 return;
191 209
192 selection_region_map_[view].anchor = anchor_bound; 210 selection_region_map_[view].anchor = anchor_bound;
193 selection_region_map_[view].focus = focus_bound; 211 selection_region_map_[view].focus = focus_bound;
194 212 #else
213 if (params.anchor_rect == params.focus_rect) {
214 selection_region_map_[view].caret_rect.set_origin(
215 anchor_origin_transformed);
216 selection_region_map_[view].caret_rect.set_size(params.anchor_rect.size());
217 }
218 selection_region_map_[view].first_selection_rect.set_origin(
219 anchor_origin_transformed);
220 selection_region_map_[view].first_selection_rect.set_size(
221 params.anchor_rect.size());
222 #endif // USE_AURA
195 FOR_EACH_OBSERVER(Observer, observer_list_, 223 FOR_EACH_OBSERVER(Observer, observer_list_,
196 OnSelectionBoundsChanged(this, view)); 224 OnSelectionBoundsChanged(this, view));
197 #endif 225 #endif // !OS_ANDROID
198 } 226 }
199 227
200 void TextInputManager::ImeCompositionRangeChanged( 228 void TextInputManager::ImeCompositionRangeChanged(
201 RenderWidgetHostViewBase* view, 229 RenderWidgetHostViewBase* view,
202 const gfx::Range& range, 230 const gfx::Range& range,
203 const std::vector<gfx::Rect>& character_bounds) { 231 const std::vector<gfx::Rect>& character_bounds) {
204 DCHECK(IsRegistered(view)); 232 DCHECK(IsRegistered(view));
205 composition_range_info_map_[view].character_bounds.clear(); 233 composition_range_info_map_[view].character_bounds.clear();
206 234
207 // The values for the bounds should be converted to root view's coordinates 235 // The values for the bounds should be converted to root view's coordinates
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 326
299 TextInputManager::TextSelection::TextSelection() 327 TextInputManager::TextSelection::TextSelection()
300 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} 328 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {}
301 329
302 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = 330 TextInputManager::TextSelection::TextSelection(const TextSelection& other) =
303 default; 331 default;
304 332
305 TextInputManager::TextSelection::~TextSelection() {} 333 TextInputManager::TextSelection::~TextSelection() {}
306 334
307 } // namespace content 335 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698