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

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: Removing some #ifdefs 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 { 64 const TextInputManager::SelectionRegion* TextInputManager::GetSelectionRegion(
65 if (!active_view_) 65 RenderWidgetHostViewBase* view) const {
66 return gfx::Rect(); 66 DCHECK(!view || IsRegistered(view));
67 67 if (!view)
68 return gfx::RectBetweenSelectionBounds( 68 view = active_view_;
69 selection_region_map_.at(active_view_).anchor, 69 return view ? &selection_region_map_.at(view) : nullptr;
70 selection_region_map_.at(active_view_).focus);
71 } 70 }
72 71
73 const TextInputManager::CompositionRangeInfo* 72 const TextInputManager::CompositionRangeInfo*
74 TextInputManager::GetCompositionRangeInfo( 73 TextInputManager::GetCompositionRangeInfo(
75 RenderWidgetHostViewBase* view) const { 74 RenderWidgetHostViewBase* view) const {
76 DCHECK(!view || IsRegistered(view)); 75 DCHECK(!view || IsRegistered(view));
77 if (!view) 76 if (!view)
78 view = active_view_; 77 view = active_view_;
79 return active_view_ ? &composition_range_info_map_.at(active_view_) : nullptr; 78 return active_view_ ? &composition_range_info_map_.at(active_view_) : nullptr;
80 } 79 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { 141 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) {
143 DCHECK(IsRegistered(view)); 142 DCHECK(IsRegistered(view));
144 FOR_EACH_OBSERVER(Observer, observer_list_, 143 FOR_EACH_OBSERVER(Observer, observer_list_,
145 OnImeCancelComposition(this, view)); 144 OnImeCancelComposition(this, view));
146 } 145 }
147 146
148 void TextInputManager::SelectionBoundsChanged( 147 void TextInputManager::SelectionBoundsChanged(
149 RenderWidgetHostViewBase* view, 148 RenderWidgetHostViewBase* view,
150 const ViewHostMsg_SelectionBounds_Params& params) { 149 const ViewHostMsg_SelectionBounds_Params& params) {
151 DCHECK(IsRegistered(view)); 150 DCHECK(IsRegistered(view));
152 151 // Converting the anchor point to root's coordinate space (for child frame
153 // TODO(ekaramad): Implement the logic for other platforms (crbug.com/578168). 152 // views).
153 gfx::Point anchor_origin_transformed =
154 view->TransformPointToRootCoordSpace(params.anchor_rect.origin());
154 #if defined(USE_AURA) 155 #if defined(USE_AURA)
155 gfx::SelectionBound anchor_bound, focus_bound; 156 gfx::SelectionBound anchor_bound, focus_bound;
156 // Converting the points to the |view|'s root coordinate space (for child 157
157 // frame views). 158 anchor_bound.SetEdge(gfx::PointF(anchor_origin_transformed),
158 anchor_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace(
159 params.anchor_rect.origin())),
160 gfx::PointF(view->TransformPointToRootCoordSpace( 159 gfx::PointF(view->TransformPointToRootCoordSpace(
161 params.anchor_rect.bottom_left()))); 160 params.anchor_rect.bottom_left())));
162 focus_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace( 161 focus_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace(
163 params.focus_rect.origin())), 162 params.focus_rect.origin())),
164 gfx::PointF(view->TransformPointToRootCoordSpace( 163 gfx::PointF(view->TransformPointToRootCoordSpace(
165 params.focus_rect.bottom_left()))); 164 params.focus_rect.bottom_left())));
166 165
167 if (params.anchor_rect == params.focus_rect) { 166 if (params.anchor_rect == params.focus_rect) {
168 anchor_bound.set_type(gfx::SelectionBound::CENTER); 167 anchor_bound.set_type(gfx::SelectionBound::CENTER);
169 focus_bound.set_type(gfx::SelectionBound::CENTER); 168 focus_bound.set_type(gfx::SelectionBound::CENTER);
(...skipping 16 matching lines...) Expand all
186 focus_bound.set_type(gfx::SelectionBound::LEFT); 185 focus_bound.set_type(gfx::SelectionBound::LEFT);
187 } 186 }
188 } 187 }
189 188
190 if (anchor_bound == selection_region_map_[view].anchor && 189 if (anchor_bound == selection_region_map_[view].anchor &&
191 focus_bound == selection_region_map_[view].focus) 190 focus_bound == selection_region_map_[view].focus)
192 return; 191 return;
193 192
194 selection_region_map_[view].anchor = anchor_bound; 193 selection_region_map_[view].anchor = anchor_bound;
195 selection_region_map_[view].focus = focus_bound; 194 selection_region_map_[view].focus = focus_bound;
196 195 #else
196 if (params.anchor_rect == params.focus_rect) {
erikchen 2016/08/17 23:31:16 When this condition evaluates to false, why don't
EhsanK 2016/08/22 14:48:28 Sadly, I don't know of any. But here is what I fig
197 selection_region_map_[view].caret_rect.set_origin(
198 anchor_origin_transformed);
199 selection_region_map_[view].caret_rect.set_size(params.anchor_rect.size());
200 }
201 selection_region_map_[view].first_selection_rect.set_origin(
202 anchor_origin_transformed);
203 selection_region_map_[view].first_selection_rect.set_size(
204 params.anchor_rect.size());
205 #endif // USE_AURA
197 FOR_EACH_OBSERVER(Observer, observer_list_, 206 FOR_EACH_OBSERVER(Observer, observer_list_,
198 OnSelectionBoundsChanged(this, view)); 207 OnSelectionBoundsChanged(this, view));
199 #endif
200 } 208 }
201 209
202 // TODO(ekaramad): We use |range| only on Mac OS; but we still track its value 210 // TODO(ekaramad): We use |range| only on Mac OS; but we still track its value
203 // here for other platforms. See if there is a nice way around this with minimal 211 // here for other platforms. See if there is a nice way around this with minimal
204 // #ifdefs for platform specific code (https://crbug.com/602427). 212 // #ifdefs for platform specific code (https://crbug.com/602427).
205 void TextInputManager::ImeCompositionRangeChanged( 213 void TextInputManager::ImeCompositionRangeChanged(
206 RenderWidgetHostViewBase* view, 214 RenderWidgetHostViewBase* view,
207 const gfx::Range& range, 215 const gfx::Range& range,
208 const std::vector<gfx::Rect>& character_bounds) { 216 const std::vector<gfx::Rect>& character_bounds) {
209 DCHECK(IsRegistered(view)); 217 DCHECK(IsRegistered(view));
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 318
311 TextInputManager::TextSelection::TextSelection() 319 TextInputManager::TextSelection::TextSelection()
312 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} 320 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {}
313 321
314 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = 322 TextInputManager::TextSelection::TextSelection(const TextSelection& other) =
315 default; 323 default;
316 324
317 TextInputManager::TextSelection::~TextSelection() {} 325 TextInputManager::TextSelection::~TextSelection() {}
318 326
319 } // namespace content 327 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698