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

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: Added an interactive ui test 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"
11 #include "ui/gfx/range/range.h"
10 12
11 namespace content { 13 namespace content {
12 14
13 namespace { 15 namespace {
14 16
15 bool AreDifferentTextInputStates(const content::TextInputState& old_state, 17 bool AreDifferentTextInputStates(const content::TextInputState& old_state,
16 const content::TextInputState& new_state) { 18 const content::TextInputState& new_state) {
17 #if defined(USE_AURA) 19 #if defined(USE_AURA)
18 return old_state.type != new_state.type || old_state.mode != new_state.mode || 20 return old_state.type != new_state.type || old_state.mode != new_state.mode ||
19 old_state.flags != new_state.flags || 21 old_state.flags != new_state.flags ||
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 59
58 gfx::Rect TextInputManager::GetSelectionBoundsRect() { 60 gfx::Rect TextInputManager::GetSelectionBoundsRect() {
59 if (!active_view_) 61 if (!active_view_)
60 return gfx::Rect(); 62 return gfx::Rect();
61 63
62 return gfx::RectBetweenSelectionBounds( 64 return gfx::RectBetweenSelectionBounds(
63 selection_region_map_[active_view_].anchor, 65 selection_region_map_[active_view_].anchor,
64 selection_region_map_[active_view_].focus); 66 selection_region_map_[active_view_].focus);
65 } 67 }
66 68
69 const TextInputManager::TextSelection* TextInputManager::GetTextSelection(
70 RenderWidgetHostViewBase* view) {
71 DCHECK(!view || IsRegistered(view));
72 if (!view)
73 view = active_view_;
74 return !!view ? &text_selection_map_[view] : nullptr;
75 }
76
67 void TextInputManager::UpdateTextInputState( 77 void TextInputManager::UpdateTextInputState(
68 RenderWidgetHostViewBase* view, 78 RenderWidgetHostViewBase* view,
69 const TextInputState& text_input_state) { 79 const TextInputState& text_input_state) {
70 DCHECK(IsRegistered(view)); 80 DCHECK(IsRegistered(view));
71 81
72 // Since |view| is registgered, we already have a previous value for its 82 // Since |view| is registgered, we already have a previous value for its
73 // TextInputState. 83 // TextInputState.
74 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], 84 bool changed = AreDifferentTextInputStates(text_input_state_map_[view],
75 text_input_state); 85 text_input_state);
76 86
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 return; 151 return;
142 152
143 selection_region_map_[view].anchor = anchor_bound; 153 selection_region_map_[view].anchor = anchor_bound;
144 selection_region_map_[view].focus = focus_bound; 154 selection_region_map_[view].focus = focus_bound;
145 155
146 FOR_EACH_OBSERVER(Observer, observer_list_, 156 FOR_EACH_OBSERVER(Observer, observer_list_,
147 OnSelectionBoundsChanged(this, view)); 157 OnSelectionBoundsChanged(this, view));
148 #endif 158 #endif
149 } 159 }
150 160
161 void TextInputManager::SelectionChanged(RenderWidgetHostViewBase* view,
162 const base::string16& text,
163 size_t offset,
164 const gfx::Range& range) {
165 DCHECK(IsRegistered(view));
166
167 text_selection_map_[view].text = text;
168 text_selection_map_[view].offset = offset;
169 text_selection_map_[view].range.set_start(range.start());
170 text_selection_map_[view].range.set_end(range.end());
171
172 FOR_EACH_OBSERVER(Observer, observer_list_,
173 OnTextSelectionChanged(this, view));
174 }
175
151 void TextInputManager::Register(RenderWidgetHostViewBase* view) { 176 void TextInputManager::Register(RenderWidgetHostViewBase* view) {
152 DCHECK(!IsRegistered(view)); 177 DCHECK(!IsRegistered(view));
153 178
154 text_input_state_map_[view] = TextInputState(); 179 text_input_state_map_[view] = TextInputState();
155 } 180 }
156 181
157 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { 182 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) {
158 DCHECK(IsRegistered(view)); 183 DCHECK(IsRegistered(view));
159 184
160 text_input_state_map_.erase(view); 185 text_input_state_map_.erase(view);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 FOR_EACH_OBSERVER( 218 FOR_EACH_OBSERVER(
194 Observer, observer_list_, 219 Observer, observer_list_,
195 OnUpdateTextInputStateCalled(this, updated_view, did_update_state)); 220 OnUpdateTextInputStateCalled(this, updated_view, did_update_state));
196 } 221 }
197 222
198 TextInputManager::SelectionRegion::SelectionRegion() {} 223 TextInputManager::SelectionRegion::SelectionRegion() {}
199 224
200 TextInputManager::SelectionRegion::SelectionRegion( 225 TextInputManager::SelectionRegion::SelectionRegion(
201 const SelectionRegion& other) = default; 226 const SelectionRegion& other) = default;
202 227
203 } // namespace content 228 TextInputManager::TextSelection::TextSelection()
229 : offset(0), range(gfx::Range::InvalidRange()), text(base::string16()) {}
230
231 TextInputManager::TextSelection::TextSelection(const TextSelection& other) =
232 default;
233
234 TextInputManager::TextSelection::~TextSelection() {}
235
236 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698