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

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

Issue 2235283003: Track composition range and character bounds on the browser side (Mac) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to fix some crashing tests 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 gfx::Rect TextInputManager::GetSelectionBoundsRect() const { 64 gfx::Rect TextInputManager::GetSelectionBoundsRect() const {
65 if (!active_view_) 65 if (!active_view_)
66 return gfx::Rect(); 66 return gfx::Rect();
67 67
68 return gfx::RectBetweenSelectionBounds( 68 return gfx::RectBetweenSelectionBounds(
69 selection_region_map_.at(active_view_).anchor, 69 selection_region_map_.at(active_view_).anchor,
70 selection_region_map_.at(active_view_).focus); 70 selection_region_map_.at(active_view_).focus);
71 } 71 }
72 72
73 const std::vector<gfx::Rect>* TextInputManager::GetCompositionCharacterBounds() 73 const TextInputManager::CompositionRangeInfo*
74 const { 74 TextInputManager::GetCompositionRangeInfo(
75 return !!active_view_ 75 RenderWidgetHostViewBase* view) const {
76 ? &composition_range_info_map_.at(active_view_).character_bounds 76 DCHECK(!view || IsRegistered(view));
77 : nullptr; 77 if (!view)
78 view = active_view_;
79 return active_view_ ? &composition_range_info_map_.at(active_view_) : nullptr;
78 } 80 }
79 81
80 const TextInputManager::TextSelection* TextInputManager::GetTextSelection( 82 const TextInputManager::TextSelection* TextInputManager::GetTextSelection(
81 RenderWidgetHostViewBase* view) const { 83 RenderWidgetHostViewBase* view) const {
82 DCHECK(!view || IsRegistered(view)); 84 DCHECK(!view || IsRegistered(view));
83 if (!view) 85 if (!view)
84 view = active_view_; 86 view = active_view_;
85 return !!view ? &text_selection_map_.at(view) : nullptr; 87 return !!view ? &text_selection_map_.at(view) : nullptr;
86 } 88 }
87 89
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 return; 192 return;
191 193
192 selection_region_map_[view].anchor = anchor_bound; 194 selection_region_map_[view].anchor = anchor_bound;
193 selection_region_map_[view].focus = focus_bound; 195 selection_region_map_[view].focus = focus_bound;
194 196
195 FOR_EACH_OBSERVER(Observer, observer_list_, 197 FOR_EACH_OBSERVER(Observer, observer_list_,
196 OnSelectionBoundsChanged(this, view)); 198 OnSelectionBoundsChanged(this, view));
197 #endif 199 #endif
198 } 200 }
199 201
202 // 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
204 // #ifdefs for platform specific code (https://crbug.com/602427).
200 void TextInputManager::ImeCompositionRangeChanged( 205 void TextInputManager::ImeCompositionRangeChanged(
201 RenderWidgetHostViewBase* view, 206 RenderWidgetHostViewBase* view,
202 const gfx::Range& range, 207 const gfx::Range& range,
203 const std::vector<gfx::Rect>& character_bounds) { 208 const std::vector<gfx::Rect>& character_bounds) {
204 DCHECK(IsRegistered(view)); 209 DCHECK(IsRegistered(view));
205 composition_range_info_map_[view].character_bounds.clear(); 210 composition_range_info_map_[view].character_bounds.clear();
206 211
207 // The values for the bounds should be converted to root view's coordinates 212 // The values for the bounds should be converted to root view's coordinates
208 // before being stored. 213 // before being stored.
209 for (auto rect : character_bounds) { 214 for (auto rect : character_bounds) {
210 composition_range_info_map_[view].character_bounds.emplace_back(gfx::Rect( 215 composition_range_info_map_[view].character_bounds.emplace_back(gfx::Rect(
211 view->TransformPointToRootCoordSpace(rect.origin()), rect.size())); 216 view->TransformPointToRootCoordSpace(rect.origin()), rect.size()));
212 } 217 }
213 218
219 composition_range_info_map_[view].range.set_start(range.start());
220 composition_range_info_map_[view].range.set_end(range.end());
221
214 FOR_EACH_OBSERVER(Observer, observer_list_, 222 FOR_EACH_OBSERVER(Observer, observer_list_,
215 OnImeCompositionRangeChanged(this, view)); 223 OnImeCompositionRangeChanged(this, view));
216 } 224 }
217 225
218 void TextInputManager::SelectionChanged(RenderWidgetHostViewBase* view, 226 void TextInputManager::SelectionChanged(RenderWidgetHostViewBase* view,
219 const base::string16& text, 227 const base::string16& text,
220 size_t offset, 228 size_t offset,
221 const gfx::Range& range) { 229 const gfx::Range& range) {
222 DCHECK(IsRegistered(view)); 230 DCHECK(IsRegistered(view));
223 231
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 310
303 TextInputManager::TextSelection::TextSelection() 311 TextInputManager::TextSelection::TextSelection()
304 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {} 312 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {}
305 313
306 TextInputManager::TextSelection::TextSelection(const TextSelection& other) = 314 TextInputManager::TextSelection::TextSelection(const TextSelection& other) =
307 default; 315 default;
308 316
309 TextInputManager::TextSelection::~TextSelection() {} 317 TextInputManager::TextSelection::~TextSelection() {}
310 318
311 } // namespace content 319 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/text_input_manager.h ('k') | content/public/test/text_input_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698