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

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: Created 4 years, 6 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_view_base.h" 7 #include "content/browser/renderer_host/render_widget_host_view_base.h"
8 #include "content/common/view_messages.h"
8 9
9 namespace content { 10 namespace content {
10 11
11 namespace { 12 namespace {
12 13
13 bool AreDifferentTextInputStates(const content::TextInputState& old_state, 14 bool AreDifferentTextInputStates(const content::TextInputState& old_state,
14 const content::TextInputState& new_state) { 15 const content::TextInputState& new_state) {
15 #if defined(USE_AURA) 16 #if defined(USE_AURA)
16 return old_state.type != new_state.type || old_state.mode != new_state.mode || 17 return old_state.type != new_state.type || old_state.mode != new_state.mode ||
17 old_state.flags != new_state.flags || 18 old_state.flags != new_state.flags ||
(...skipping 26 matching lines...) Expand all
44 } 45 }
45 46
46 const TextInputState* TextInputManager::GetTextInputState() { 47 const TextInputState* TextInputManager::GetTextInputState() {
47 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr; 48 return !!active_view_ ? &text_input_state_map_[active_view_] : nullptr;
48 } 49 }
49 50
50 RenderWidgetHostViewBase* TextInputManager::GetActiveView() const { 51 RenderWidgetHostViewBase* TextInputManager::GetActiveView() const {
51 return active_view_; 52 return active_view_;
52 } 53 }
53 54
55 gfx::Rect TextInputManager::GetSelectionBoundsRect() {
56 if (!active_view_)
57 return gfx::Rect();
58
59 return gfx::RectBetweenSelectionBounds(selection_anchor_map_[active_view_],
60 selection_focus_map_[active_view_]);
61 }
62
54 void TextInputManager::UpdateTextInputState( 63 void TextInputManager::UpdateTextInputState(
55 RenderWidgetHostViewBase* view, 64 RenderWidgetHostViewBase* view,
56 const TextInputState& text_input_state) { 65 const TextInputState& text_input_state) {
57 DCHECK(IsRegistered(view)); 66 DCHECK(IsRegistered(view));
58 67
59 // Since |view| is registgered, we already have a previous value for its 68 // Since |view| is registgered, we already have a previous value for its
60 // TextInputState. 69 // TextInputState.
61 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], 70 bool changed = AreDifferentTextInputStates(text_input_state_map_[view],
62 text_input_state); 71 text_input_state);
63 72
64 text_input_state_map_[view] = text_input_state; 73 text_input_state_map_[view] = text_input_state;
65 74
66 // |active_view_| is only updated when the state for |view| is not none. 75 // |active_view_| is only updated when the state for |view| is not none.
67 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE) 76 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE)
68 active_view_ = view; 77 active_view_ = view;
69 78
70 // If the state for |active_view_| is none, then we no longer have an 79 // If the state for |active_view_| is none, then we no longer have an
71 // |active_view_|. 80 // |active_view_|.
72 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE) 81 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE)
73 active_view_ = nullptr; 82 active_view_ = nullptr;
74 83
75 NotifyObserversAboutInputStateUpdate(view, changed); 84 NotifyObserversAboutInputStateUpdate(view, changed);
76 } 85 }
77 86
87 void TextInputManager::SelectionBoundsChanged(
EhsanK 2016/06/27 17:18:13 This will change when we add the same logic for Ma
88 RenderWidgetHostViewBase* view,
89 const ViewHostMsg_SelectionBounds_Params& params) {
90 DCHECK(IsRegistered(view));
91
92 gfx::SelectionBound anchor_bound, focus_bound;
93 anchor_bound.SetEdge(gfx::PointF(params.anchor_rect.origin()),
94 gfx::PointF(params.anchor_rect.bottom_left()));
95 focus_bound.SetEdge(gfx::PointF(params.focus_rect.origin()),
96 gfx::PointF(params.focus_rect.bottom_left()));
97
98 if (params.anchor_rect == params.focus_rect) {
99 anchor_bound.set_type(gfx::SelectionBound::CENTER);
100 focus_bound.set_type(gfx::SelectionBound::CENTER);
101 } else {
102 // Whether text is LTR at the anchor handle.
103 bool anchor_LTR = params.anchor_dir == blink::WebTextDirectionLeftToRight;
104 // Whether text is LTR at the focus handle.
105 bool focus_LTR = params.focus_dir == blink::WebTextDirectionLeftToRight;
106
107 if ((params.is_anchor_first && anchor_LTR) ||
108 (!params.is_anchor_first && !anchor_LTR)) {
109 anchor_bound.set_type(gfx::SelectionBound::LEFT);
110 } else {
111 anchor_bound.set_type(gfx::SelectionBound::RIGHT);
112 }
113 if ((params.is_anchor_first && focus_LTR) ||
114 (!params.is_anchor_first && !focus_LTR)) {
115 focus_bound.set_type(gfx::SelectionBound::RIGHT);
116 } else {
117 focus_bound.set_type(gfx::SelectionBound::LEFT);
118 }
119 }
120
121 if (anchor_bound == selection_anchor_map_[view] &&
122 focus_bound == selection_focus_map_[view])
123 return;
124
125 selection_anchor_map_[view] = anchor_bound;
126 selection_focus_map_[view] = focus_bound;
127
128 FOR_EACH_OBSERVER(Observer, observer_list_,
129 OnSelectionBoundsChanged(this, view));
130 }
131
78 void TextInputManager::Register(RenderWidgetHostViewBase* view) { 132 void TextInputManager::Register(RenderWidgetHostViewBase* view) {
79 DCHECK(!IsRegistered(view)); 133 DCHECK(!IsRegistered(view));
80 134
81 text_input_state_map_[view] = TextInputState(); 135 text_input_state_map_[view] = TextInputState();
82 } 136 }
83 137
84 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { 138 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) {
85 DCHECK(IsRegistered(view)); 139 DCHECK(IsRegistered(view));
86 140
87 text_input_state_map_.erase(view); 141 text_input_state_map_.erase(view);
(...skipping 18 matching lines...) Expand all
106 160
107 void TextInputManager::NotifyObserversAboutInputStateUpdate( 161 void TextInputManager::NotifyObserversAboutInputStateUpdate(
108 RenderWidgetHostViewBase* updated_view, 162 RenderWidgetHostViewBase* updated_view,
109 bool did_update_state) { 163 bool did_update_state) {
110 FOR_EACH_OBSERVER( 164 FOR_EACH_OBSERVER(
111 Observer, observer_list_, 165 Observer, observer_list_,
112 OnUpdateTextInputStateCalled(this, updated_view, did_update_state)); 166 OnUpdateTextInputStateCalled(this, updated_view, did_update_state));
113 } 167 }
114 168
115 } // namespace content 169 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698