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

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

Issue 2130133004: Tracking text selection on the browser side in OOPIF. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased 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 "base/strings/string16.h"
7 #include "content/browser/renderer_host/render_widget_host_impl.h" 8 #include "content/browser/renderer_host/render_widget_host_impl.h"
8 #include "content/browser/renderer_host/render_widget_host_view_base.h" 9 #include "content/browser/renderer_host/render_widget_host_view_base.h"
9 #include "content/common/view_messages.h" 10 #include "content/common/view_messages.h"
10 #include "ui/gfx/geometry/rect.h" 11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/range/range.h"
11 13
12 namespace content { 14 namespace content {
13 15
14 namespace { 16 namespace {
15 17
16 bool AreDifferentTextInputStates(const content::TextInputState& old_state, 18 bool AreDifferentTextInputStates(const content::TextInputState& old_state,
17 const content::TextInputState& new_state) { 19 const content::TextInputState& new_state) {
18 #if defined(USE_AURA) 20 #if defined(USE_AURA)
19 return old_state.type != new_state.type || old_state.mode != new_state.mode || 21 return old_state.type != new_state.type || old_state.mode != new_state.mode ||
20 old_state.flags != new_state.flags || 22 old_state.flags != new_state.flags ||
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 selection_region_map_[active_view_].focus); 67 selection_region_map_[active_view_].focus);
66 } 68 }
67 69
68 const std::vector<gfx::Rect>* 70 const std::vector<gfx::Rect>*
69 TextInputManager::GetCompositionCharacterBounds() { 71 TextInputManager::GetCompositionCharacterBounds() {
70 return !!active_view_ 72 return !!active_view_
71 ? &composition_range_info_map_[active_view_].character_bounds 73 ? &composition_range_info_map_[active_view_].character_bounds
72 : nullptr; 74 : nullptr;
73 } 75 }
74 76
77 const TextInputManager::TextSelection* TextInputManager::GetTextSelection(
78 RenderWidgetHostViewBase* view) {
79 DCHECK(!view || IsRegistered(view));
80 if (!view)
81 view = active_view_;
82 return !!view ? &text_selection_map_[view] : nullptr;
83 }
84
75 void TextInputManager::UpdateTextInputState( 85 void TextInputManager::UpdateTextInputState(
76 RenderWidgetHostViewBase* view, 86 RenderWidgetHostViewBase* view,
77 const TextInputState& text_input_state) { 87 const TextInputState& text_input_state) {
78 DCHECK(IsRegistered(view)); 88 DCHECK(IsRegistered(view));
79 89
80 // Since |view| is registgered, we already have a previous value for its 90 // Since |view| is registgered, we already have a previous value for its
81 // TextInputState. 91 // TextInputState.
82 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], 92 bool changed = AreDifferentTextInputStates(text_input_state_map_[view],
83 text_input_state); 93 text_input_state);
84 94
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // before being stored. 177 // before being stored.
168 for (auto rect : character_bounds) { 178 for (auto rect : character_bounds) {
169 composition_range_info_map_[view].character_bounds.emplace_back(gfx::Rect( 179 composition_range_info_map_[view].character_bounds.emplace_back(gfx::Rect(
170 view->TransformPointToRootCoordSpace(rect.origin()), rect.size())); 180 view->TransformPointToRootCoordSpace(rect.origin()), rect.size()));
171 } 181 }
172 182
173 FOR_EACH_OBSERVER(Observer, observer_list_, 183 FOR_EACH_OBSERVER(Observer, observer_list_,
174 OnImeCompositionRangeChanged(this, view)); 184 OnImeCompositionRangeChanged(this, view));
175 } 185 }
176 186
187 void TextInputManager::SelectionChanged(RenderWidgetHostViewBase* view,
188 const base::string16& text,
189 size_t offset,
190 const gfx::Range& range) {
191 DCHECK(IsRegistered(view));
192
193 text_selection_map_[view].text = text;
194 text_selection_map_[view].offset = offset;
195 text_selection_map_[view].range.set_start(range.start());
196 text_selection_map_[view].range.set_end(range.end());
197
198 FOR_EACH_OBSERVER(Observer, observer_list_,
199 OnTextSelectionChanged(this, view));
200 }
201
177 void TextInputManager::Register(RenderWidgetHostViewBase* view) { 202 void TextInputManager::Register(RenderWidgetHostViewBase* view) {
178 DCHECK(!IsRegistered(view)); 203 DCHECK(!IsRegistered(view));
179 204
180 text_input_state_map_[view] = TextInputState(); 205 text_input_state_map_[view] = TextInputState();
181 } 206 }
182 207
183 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { 208 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) {
184 DCHECK(IsRegistered(view)); 209 DCHECK(IsRegistered(view));
185 210
186 text_input_state_map_.erase(view); 211 text_input_state_map_.erase(view);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 TextInputManager::SelectionRegion::SelectionRegion( 251 TextInputManager::SelectionRegion::SelectionRegion(
227 const SelectionRegion& other) = default; 252 const SelectionRegion& other) = default;
228 253
229 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {} 254 TextInputManager::CompositionRangeInfo::CompositionRangeInfo() {}
230 255
231 TextInputManager::CompositionRangeInfo::CompositionRangeInfo( 256 TextInputManager::CompositionRangeInfo::CompositionRangeInfo(
232 const CompositionRangeInfo& other) = default; 257 const CompositionRangeInfo& other) = default;
233 258
234 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {} 259 TextInputManager::CompositionRangeInfo::~CompositionRangeInfo() {}
235 260
261 TextInputManager::TextSelection::TextSelection()
262 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {}
263
264 TextInputManager::TextSelection::TextSelection(const TextSelection& other) =
265 default;
266
267 TextInputManager::TextSelection::~TextSelection() {}
268
236 } // namespace content 269 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698