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

Side by Side Diff: content/browser/renderer_host/input/touch_selection_controller.cc

Issue 432833002: Prevent repeated taps from resetting insertion handle position (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/input/touch_selection_controller.h" 5 #include "content/browser/renderer_host/input/touch_selection_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/WebKit/public/web/WebInputEvent.h" 8 #include "third_party/WebKit/public/web/WebInputEvent.h"
9 9
10 namespace content { 10 namespace content {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 end_selection_handle_->WillHandleTouchEvent(event); 103 end_selection_handle_->WillHandleTouchEvent(event);
104 } 104 }
105 105
106 return false; 106 return false;
107 } 107 }
108 108
109 void TouchSelectionController::OnLongPressEvent() { 109 void TouchSelectionController::OnLongPressEvent() {
110 last_input_event_type_ = LONG_PRESS; 110 last_input_event_type_ = LONG_PRESS;
111 ShowSelectionHandlesAutomatically(); 111 ShowSelectionHandlesAutomatically();
112 ShowInsertionHandleAutomatically(); 112 ShowInsertionHandleAutomatically();
113 ResetCachedValues(); 113 ResetCachedValuesIfInactive();
114 } 114 }
115 115
116 void TouchSelectionController::OnTapEvent() { 116 void TouchSelectionController::OnTapEvent() {
117 last_input_event_type_ = TAP; 117 last_input_event_type_ = TAP;
118 activate_selection_automatically_ = false; 118 activate_selection_automatically_ = false;
119 DeactivateSelection(); 119 DeactivateSelection();
120 ShowInsertionHandleAutomatically(); 120 ShowInsertionHandleAutomatically();
121 ResetCachedValues(); 121 ResetCachedValuesIfInactive();
122 } 122 }
123 123
124 void TouchSelectionController::HideAndDisallowShowingAutomatically() { 124 void TouchSelectionController::HideAndDisallowShowingAutomatically() {
125 last_input_event_type_ = INPUT_EVENT_TYPE_NONE; 125 last_input_event_type_ = INPUT_EVENT_TYPE_NONE;
126 DeactivateInsertion(); 126 DeactivateInsertion();
127 DeactivateSelection(); 127 DeactivateSelection();
128 activate_insertion_automatically_ = false; 128 activate_insertion_automatically_ = false;
129 activate_selection_automatically_ = false; 129 activate_selection_automatically_ = false;
130 } 130 }
131 131
132 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { 132 void TouchSelectionController::SetTemporarilyHidden(bool hidden) {
133 if (temporarily_hidden_ == hidden) 133 if (temporarily_hidden_ == hidden)
134 return; 134 return;
135 temporarily_hidden_ = hidden; 135 temporarily_hidden_ = hidden;
136 136
137 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); 137 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true);
138 if (is_selection_active_) { 138 if (is_selection_active_) {
139 start_selection_handle_->SetVisible(GetStartVisible(), animation_style); 139 start_selection_handle_->SetVisible(GetStartVisible(), animation_style);
140 end_selection_handle_->SetVisible(GetEndVisible(), animation_style); 140 end_selection_handle_->SetVisible(GetEndVisible(), animation_style);
141 } 141 }
142 if (is_insertion_active_) 142 if (is_insertion_active_)
143 insertion_handle_->SetVisible(GetStartVisible(), animation_style); 143 insertion_handle_->SetVisible(GetStartVisible(), animation_style);
144 } 144 }
145 145
146 void TouchSelectionController::OnSelectionEditable(bool editable) { 146 void TouchSelectionController::OnSelectionEditable(bool editable) {
147 if (selection_editable_ == editable) 147 if (selection_editable_ == editable)
148 return; 148 return;
149 selection_editable_ = editable; 149 selection_editable_ = editable;
150 ResetCachedValues(); 150 ResetCachedValuesIfInactive();
151 if (!selection_editable_) 151 if (!selection_editable_)
152 DeactivateInsertion(); 152 DeactivateInsertion();
153 } 153 }
154 154
155 void TouchSelectionController::OnSelectionEmpty(bool empty) { 155 void TouchSelectionController::OnSelectionEmpty(bool empty) {
156 if (selection_empty_ == empty) 156 if (selection_empty_ == empty)
157 return; 157 return;
158 selection_empty_ = empty; 158 selection_empty_ = empty;
159 ResetCachedValues(); 159 ResetCachedValuesIfInactive();
160 } 160 }
161 161
162 bool TouchSelectionController::Animate(base::TimeTicks frame_time) { 162 bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
163 if (is_insertion_active_) 163 if (is_insertion_active_)
164 return insertion_handle_->Animate(frame_time); 164 return insertion_handle_->Animate(frame_time);
165 165
166 if (is_selection_active_) { 166 if (is_selection_active_) {
167 bool needs_animate = start_selection_handle_->Animate(frame_time); 167 bool needs_animate = start_selection_handle_->Animate(frame_time);
168 needs_animate |= end_selection_handle_->Animate(frame_time); 168 needs_animate |= end_selection_handle_->Animate(frame_time);
169 return needs_animate; 169 return needs_animate;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 213 }
214 214
215 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() { 215 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() {
216 return client_->CreateDrawable(); 216 return client_->CreateDrawable();
217 } 217 }
218 218
219 void TouchSelectionController::ShowInsertionHandleAutomatically() { 219 void TouchSelectionController::ShowInsertionHandleAutomatically() {
220 if (activate_insertion_automatically_) 220 if (activate_insertion_automatically_)
221 return; 221 return;
222 activate_insertion_automatically_ = true; 222 activate_insertion_automatically_ = true;
223 if (!is_insertion_active_ && !is_selection_active_) 223 ResetCachedValuesIfInactive();
224 ResetCachedValues();
225 } 224 }
226 225
227 void TouchSelectionController::ShowSelectionHandlesAutomatically() { 226 void TouchSelectionController::ShowSelectionHandlesAutomatically() {
228 if (activate_selection_automatically_) 227 if (activate_selection_automatically_)
229 return; 228 return;
230 activate_selection_automatically_ = true; 229 activate_selection_automatically_ = true;
231 if (!is_insertion_active_ && !is_selection_active_) 230 ResetCachedValuesIfInactive();
232 ResetCachedValues();
233 } 231 }
234 232
235 void TouchSelectionController::OnInsertionChanged() { 233 void TouchSelectionController::OnInsertionChanged() {
236 DeactivateSelection(); 234 DeactivateSelection();
237 235
238 if (last_input_event_type_ == TAP && selection_empty_) { 236 if (last_input_event_type_ == TAP && selection_empty_) {
239 HideAndDisallowShowingAutomatically(); 237 HideAndDisallowShowingAutomatically();
240 return; 238 return;
241 } 239 }
242 240
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 if (!is_selection_active_) 319 if (!is_selection_active_)
322 return; 320 return;
323 DCHECK(start_selection_handle_); 321 DCHECK(start_selection_handle_);
324 DCHECK(end_selection_handle_); 322 DCHECK(end_selection_handle_);
325 start_selection_handle_->SetEnabled(false); 323 start_selection_handle_->SetEnabled(false);
326 end_selection_handle_->SetEnabled(false); 324 end_selection_handle_->SetEnabled(false);
327 is_selection_active_ = false; 325 is_selection_active_ = false;
328 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF()); 326 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF());
329 } 327 }
330 328
331 void TouchSelectionController::ResetCachedValues() { 329 void TouchSelectionController::ResetCachedValuesIfInactive() {
330 if (is_insertion_active_ || is_selection_active_)
331 return;
332
332 start_rect_ = gfx::RectF(); 333 start_rect_ = gfx::RectF();
333 end_rect_ = gfx::RectF(); 334 end_rect_ = gfx::RectF();
334 start_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; 335 start_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED;
335 end_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; 336 end_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED;
336 start_visible_ = false; 337 start_visible_ = false;
337 end_visible_ = false; 338 end_visible_ = false;
338 } 339 }
339 340
340 gfx::PointF TouchSelectionController::GetStartPosition() const { 341 gfx::PointF TouchSelectionController::GetStartPosition() const {
341 return start_rect_.bottom_left(); 342 return start_rect_.bottom_left();
(...skipping 20 matching lines...) Expand all
362 } 363 }
363 364
364 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( 365 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle(
365 bool was_active) const { 366 bool was_active) const {
366 return was_active && client_->SupportsAnimation() 367 return was_active && client_->SupportsAnimation()
367 ? TouchHandle::ANIMATION_SMOOTH 368 ? TouchHandle::ANIMATION_SMOOTH
368 : TouchHandle::ANIMATION_NONE; 369 : TouchHandle::ANIMATION_NONE;
369 } 370 }
370 371
371 } // namespace content 372 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698