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

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

Issue 2057803002: Tracking SelectionBounds for all RenderWidgets on the Browser Side (Aura Only) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a unit 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 "content/browser/renderer_host/render_widget_host_impl.h" 7 #include "content/browser/renderer_host/render_widget_host_impl.h"
8 #include "content/browser/renderer_host/render_widget_host_view_base.h" 8 #include "content/browser/renderer_host/render_widget_host_view_base.h"
9 #include "content/common/view_messages.h"
9 10
10 namespace content { 11 namespace content {
11 12
12 namespace { 13 namespace {
13 14
14 bool AreDifferentTextInputStates(const content::TextInputState& old_state, 15 bool AreDifferentTextInputStates(const content::TextInputState& old_state,
15 const content::TextInputState& new_state) { 16 const content::TextInputState& new_state) {
16 #if defined(USE_AURA) 17 #if defined(USE_AURA)
17 return old_state.type != new_state.type || old_state.mode != new_state.mode || 18 return old_state.type != new_state.type || old_state.mode != new_state.mode ||
18 old_state.flags != new_state.flags || 19 old_state.flags != new_state.flags ||
(...skipping 28 matching lines...) Expand all
47 const TextInputState* TextInputManager::GetTextInputState() { 48 const TextInputState* TextInputManager::GetTextInputState() {
48 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr; 49 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr;
49 } 50 }
50 51
51 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const { 52 RenderWidgetHostImpl* TextInputManager::GetActiveWidget() const {
52 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>( 53 return !!active_view_ ? static_cast<RenderWidgetHostImpl*>(
53 active_view_->GetRenderWidgetHost()) 54 active_view_->GetRenderWidgetHost())
54 : nullptr; 55 : nullptr;
55 } 56 }
56 57
58 gfx::Rect TextInputManager::GetSelectionBoundsRect() {
59 if (!active_view_)
60 return gfx::Rect();
61
62 return gfx::RectBetweenSelectionBounds(
63 selection_region_map_[active_view_].anchor,
64 selection_region_map_[active_view_].focus);
65 }
66
57 void TextInputManager::UpdateTextInputState( 67 void TextInputManager::UpdateTextInputState(
58 RenderWidgetHostViewBase* view, 68 RenderWidgetHostViewBase* view,
59 const TextInputState& text_input_state) { 69 const TextInputState& text_input_state) {
60 DCHECK(IsRegistered(view)); 70 DCHECK(IsRegistered(view));
61 71
62 // Since |view| is registgered, we already have a previous value for its 72 // Since |view| is registgered, we already have a previous value for its
63 // TextInputState. 73 // TextInputState.
64 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], 74 bool changed = AreDifferentTextInputStates(text_input_state_map_[view],
65 text_input_state); 75 text_input_state);
66 76
(...skipping 10 matching lines...) Expand all
77 87
78 NotifyObserversAboutInputStateUpdate(view, changed); 88 NotifyObserversAboutInputStateUpdate(view, changed);
79 } 89 }
80 90
81 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) { 91 void TextInputManager::ImeCancelComposition(RenderWidgetHostViewBase* view) {
82 DCHECK(IsRegistered(view)); 92 DCHECK(IsRegistered(view));
83 FOR_EACH_OBSERVER(Observer, observer_list_, 93 FOR_EACH_OBSERVER(Observer, observer_list_,
84 OnImeCancelComposition(this, view)); 94 OnImeCancelComposition(this, view));
85 } 95 }
86 96
97 void TextInputManager::SelectionBoundsChanged(
98 RenderWidgetHostViewBase* view,
99 const ViewHostMsg_SelectionBounds_Params& params) {
100 DCHECK(IsRegistered(view));
101 // TODO(ekaramad): Implement the logic for other platforms (crbug.com/578168).
Charlie Reis 2016/07/06 18:42:36 nit: Blank line before.
EhsanK 2016/07/06 19:15:34 Done.
102 #if defined(USE_AURA)
103 gfx::SelectionBound anchor_bound, focus_bound;
104 // Converting the points to the |view|'s root coordinate space (for child
105 // frame views).
106 anchor_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace(
107 params.anchor_rect.origin())),
108 gfx::PointF(view->TransformPointToRootCoordSpace(
109 params.anchor_rect.bottom_left())));
110 focus_bound.SetEdge(gfx::PointF(view->TransformPointToRootCoordSpace(
111 params.focus_rect.origin())),
112 gfx::PointF(view->TransformPointToRootCoordSpace(
113 params.focus_rect.bottom_left())));
114
115 if (params.anchor_rect == params.focus_rect) {
116 anchor_bound.set_type(gfx::SelectionBound::CENTER);
117 focus_bound.set_type(gfx::SelectionBound::CENTER);
118 } else {
119 // Whether text is LTR at the anchor handle.
120 bool anchor_LTR = params.anchor_dir == blink::WebTextDirectionLeftToRight;
121 // Whether text is LTR at the focus handle.
122 bool focus_LTR = params.focus_dir == blink::WebTextDirectionLeftToRight;
123
124 if ((params.is_anchor_first && anchor_LTR) ||
125 (!params.is_anchor_first && !anchor_LTR)) {
126 anchor_bound.set_type(gfx::SelectionBound::LEFT);
127 } else {
128 anchor_bound.set_type(gfx::SelectionBound::RIGHT);
129 }
130 if ((params.is_anchor_first && focus_LTR) ||
131 (!params.is_anchor_first && !focus_LTR)) {
132 focus_bound.set_type(gfx::SelectionBound::RIGHT);
133 } else {
134 focus_bound.set_type(gfx::SelectionBound::LEFT);
135 }
136 }
137
138 if (anchor_bound == selection_region_map_[view].anchor &&
139 focus_bound == selection_region_map_[view].focus)
140 return;
141
142 selection_region_map_[view].anchor = anchor_bound;
143 selection_region_map_[view].focus = focus_bound;
144
145 FOR_EACH_OBSERVER(Observer, observer_list_,
146 OnSelectionBoundsChanged(this, view));
147 #endif
148 }
149
87 void TextInputManager::Register(RenderWidgetHostViewBase* view) { 150 void TextInputManager::Register(RenderWidgetHostViewBase* view) {
88 DCHECK(!IsRegistered(view)); 151 DCHECK(!IsRegistered(view));
89 152
90 text_input_state_map_[view] = TextInputState(); 153 text_input_state_map_[view] = TextInputState();
91 } 154 }
92 155
93 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { 156 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) {
94 DCHECK(IsRegistered(view)); 157 DCHECK(IsRegistered(view));
95 158
96 text_input_state_map_.erase(view); 159 text_input_state_map_.erase(view);
(...skipping 27 matching lines...) Expand all
124 } 187 }
125 188
126 void TextInputManager::NotifyObserversAboutInputStateUpdate( 189 void TextInputManager::NotifyObserversAboutInputStateUpdate(
127 RenderWidgetHostViewBase* updated_view, 190 RenderWidgetHostViewBase* updated_view,
128 bool did_update_state) { 191 bool did_update_state) {
129 FOR_EACH_OBSERVER( 192 FOR_EACH_OBSERVER(
130 Observer, observer_list_, 193 Observer, observer_list_,
131 OnUpdateTextInputStateCalled(this, updated_view, did_update_state)); 194 OnUpdateTextInputStateCalled(this, updated_view, did_update_state));
132 } 195 }
133 196
197 TextInputManager::SelectionRegion::SelectionRegion() {}
198
199 TextInputManager::SelectionRegion::SelectionRegion(
200 const SelectionRegion& other) = default;
201
134 } // namespace content 202 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698