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

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: Fixed Compile Errors 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(selection_anchor_map_[active_view_],
63 selection_focus_map_[active_view_]);
64 }
65
57 void TextInputManager::UpdateTextInputState( 66 void TextInputManager::UpdateTextInputState(
58 RenderWidgetHostViewBase* view, 67 RenderWidgetHostViewBase* view,
59 const TextInputState& text_input_state) { 68 const TextInputState& text_input_state) {
60 DCHECK(IsRegistered(view)); 69 DCHECK(IsRegistered(view));
61 70
62 // Since |view| is registgered, we already have a previous value for its 71 // Since |view| is registgered, we already have a previous value for its
63 // TextInputState. 72 // TextInputState.
64 bool changed = AreDifferentTextInputStates(text_input_state_map_[view], 73 bool changed = AreDifferentTextInputStates(text_input_state_map_[view],
65 text_input_state); 74 text_input_state);
66 75
67 text_input_state_map_[view] = text_input_state; 76 text_input_state_map_[view] = text_input_state;
68 77
69 // |active_view_| is only updated when the state for |view| is not none. 78 // |active_view_| is only updated when the state for |view| is not none.
70 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE) 79 if (text_input_state.type != ui::TEXT_INPUT_TYPE_NONE)
71 active_view_ = view; 80 active_view_ = view;
72 81
73 // If the state for |active_view_| is none, then we no longer have an 82 // If the state for |active_view_| is none, then we no longer have an
74 // |active_view_|. 83 // |active_view_|.
75 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE) 84 if (active_view_ == view && text_input_state.type == ui::TEXT_INPUT_TYPE_NONE)
76 active_view_ = nullptr; 85 active_view_ = nullptr;
77 86
78 NotifyObserversAboutInputStateUpdate(view, changed); 87 NotifyObserversAboutInputStateUpdate(view, changed);
79 } 88 }
80 89
90 void TextInputManager::SelectionBoundsChanged(
91 RenderWidgetHostViewBase* view,
92 const ViewHostMsg_SelectionBounds_Params& params) {
93 DCHECK(IsRegistered(view));
94
95 gfx::SelectionBound anchor_bound, focus_bound;
96 anchor_bound.SetEdge(gfx::PointF(params.anchor_rect.origin()),
97 gfx::PointF(params.anchor_rect.bottom_left()));
98 focus_bound.SetEdge(gfx::PointF(params.focus_rect.origin()),
99 gfx::PointF(params.focus_rect.bottom_left()));
100
101 if (params.anchor_rect == params.focus_rect) {
102 anchor_bound.set_type(gfx::SelectionBound::CENTER);
103 focus_bound.set_type(gfx::SelectionBound::CENTER);
104 } else {
105 // Whether text is LTR at the anchor handle.
106 bool anchor_LTR = params.anchor_dir == blink::WebTextDirectionLeftToRight;
107 // Whether text is LTR at the focus handle.
108 bool focus_LTR = params.focus_dir == blink::WebTextDirectionLeftToRight;
109
110 if ((params.is_anchor_first && anchor_LTR) ||
111 (!params.is_anchor_first && !anchor_LTR)) {
112 anchor_bound.set_type(gfx::SelectionBound::LEFT);
113 } else {
114 anchor_bound.set_type(gfx::SelectionBound::RIGHT);
115 }
116 if ((params.is_anchor_first && focus_LTR) ||
117 (!params.is_anchor_first && !focus_LTR)) {
118 focus_bound.set_type(gfx::SelectionBound::RIGHT);
119 } else {
120 focus_bound.set_type(gfx::SelectionBound::LEFT);
121 }
122 }
123
124 if (anchor_bound == selection_anchor_map_[view] &&
125 focus_bound == selection_focus_map_[view])
126 return;
127
128 selection_anchor_map_[view] = anchor_bound;
129 selection_focus_map_[view] = focus_bound;
130
131 FOR_EACH_OBSERVER(Observer, observer_list_,
132 OnSelectionBoundsChanged(this, view));
133 }
134
81 void TextInputManager::Register(RenderWidgetHostViewBase* view) { 135 void TextInputManager::Register(RenderWidgetHostViewBase* view) {
82 DCHECK(!IsRegistered(view)); 136 DCHECK(!IsRegistered(view));
83 137
84 text_input_state_map_[view] = TextInputState(); 138 text_input_state_map_[view] = TextInputState();
85 } 139 }
86 140
87 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) { 141 void TextInputManager::Unregister(RenderWidgetHostViewBase* view) {
88 DCHECK(IsRegistered(view)); 142 DCHECK(IsRegistered(view));
89 143
90 text_input_state_map_.erase(view); 144 text_input_state_map_.erase(view);
(...skipping 18 matching lines...) Expand all
109 163
110 void TextInputManager::NotifyObserversAboutInputStateUpdate( 164 void TextInputManager::NotifyObserversAboutInputStateUpdate(
111 RenderWidgetHostViewBase* updated_view, 165 RenderWidgetHostViewBase* updated_view,
112 bool did_update_state) { 166 bool did_update_state) {
113 FOR_EACH_OBSERVER( 167 FOR_EACH_OBSERVER(
114 Observer, observer_list_, 168 Observer, observer_list_,
115 OnUpdateTextInputStateCalled(this, updated_view, did_update_state)); 169 OnUpdateTextInputStateCalled(this, updated_view, did_update_state));
116 } 170 }
117 171
118 } // namespace content 172 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698