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

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

Issue 434583002: Prevent repeated taps from resetting insertion handle position (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased the patch 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 return end_selection_handle_->WillHandleTouchEvent(event); 113 return end_selection_handle_->WillHandleTouchEvent(event);
114 } 114 }
115 115
116 return false; 116 return false;
117 } 117 }
118 118
119 void TouchSelectionController::OnLongPressEvent() { 119 void TouchSelectionController::OnLongPressEvent() {
120 last_input_event_type_ = LONG_PRESS; 120 last_input_event_type_ = LONG_PRESS;
121 ShowSelectionHandlesAutomatically(); 121 ShowSelectionHandlesAutomatically();
122 ShowInsertionHandleAutomatically(); 122 ShowInsertionHandleAutomatically();
123 ResetCachedValues(); 123 ResetCachedValuesIfInactive();
124 } 124 }
125 125
126 void TouchSelectionController::OnTapEvent() { 126 void TouchSelectionController::OnTapEvent() {
127 last_input_event_type_ = TAP; 127 last_input_event_type_ = TAP;
128 activate_selection_automatically_ = false; 128 activate_selection_automatically_ = false;
129 DeactivateSelection(); 129 DeactivateSelection();
130 ShowInsertionHandleAutomatically(); 130 ShowInsertionHandleAutomatically();
131 ResetCachedValues(); 131 ResetCachedValuesIfInactive();
132 } 132 }
133 133
134 void TouchSelectionController::HideAndDisallowShowingAutomatically() { 134 void TouchSelectionController::HideAndDisallowShowingAutomatically() {
135 last_input_event_type_ = INPUT_EVENT_TYPE_NONE; 135 last_input_event_type_ = INPUT_EVENT_TYPE_NONE;
136 DeactivateInsertion(); 136 DeactivateInsertion();
137 DeactivateSelection(); 137 DeactivateSelection();
138 activate_insertion_automatically_ = false; 138 activate_insertion_automatically_ = false;
139 activate_selection_automatically_ = false; 139 activate_selection_automatically_ = false;
140 } 140 }
141 141
142 void TouchSelectionController::SetTemporarilyHidden(bool hidden) { 142 void TouchSelectionController::SetTemporarilyHidden(bool hidden) {
143 if (temporarily_hidden_ == hidden) 143 if (temporarily_hidden_ == hidden)
144 return; 144 return;
145 temporarily_hidden_ = hidden; 145 temporarily_hidden_ = hidden;
146 146
147 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); 147 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true);
148 if (is_selection_active_) { 148 if (is_selection_active_) {
149 start_selection_handle_->SetVisible(GetStartVisible(), animation_style); 149 start_selection_handle_->SetVisible(GetStartVisible(), animation_style);
150 end_selection_handle_->SetVisible(GetEndVisible(), animation_style); 150 end_selection_handle_->SetVisible(GetEndVisible(), animation_style);
151 } 151 }
152 if (is_insertion_active_) 152 if (is_insertion_active_)
153 insertion_handle_->SetVisible(GetStartVisible(), animation_style); 153 insertion_handle_->SetVisible(GetStartVisible(), animation_style);
154 } 154 }
155 155
156 void TouchSelectionController::OnSelectionEditable(bool editable) { 156 void TouchSelectionController::OnSelectionEditable(bool editable) {
157 if (selection_editable_ == editable) 157 if (selection_editable_ == editable)
158 return; 158 return;
159 selection_editable_ = editable; 159 selection_editable_ = editable;
160 ResetCachedValues(); 160 ResetCachedValuesIfInactive();
161 if (!selection_editable_) 161 if (!selection_editable_)
162 DeactivateInsertion(); 162 DeactivateInsertion();
163 } 163 }
164 164
165 void TouchSelectionController::OnSelectionEmpty(bool empty) { 165 void TouchSelectionController::OnSelectionEmpty(bool empty) {
166 if (selection_empty_ == empty) 166 if (selection_empty_ == empty)
167 return; 167 return;
168 selection_empty_ = empty; 168 selection_empty_ = empty;
169 ResetCachedValues(); 169 ResetCachedValuesIfInactive();
170 } 170 }
171 171
172 bool TouchSelectionController::Animate(base::TimeTicks frame_time) { 172 bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
173 if (is_insertion_active_) 173 if (is_insertion_active_)
174 return insertion_handle_->Animate(frame_time); 174 return insertion_handle_->Animate(frame_time);
175 175
176 if (is_selection_active_) { 176 if (is_selection_active_) {
177 bool needs_animate = start_selection_handle_->Animate(frame_time); 177 bool needs_animate = start_selection_handle_->Animate(frame_time);
178 needs_animate |= end_selection_handle_->Animate(frame_time); 178 needs_animate |= end_selection_handle_->Animate(frame_time);
179 return needs_animate; 179 return needs_animate;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 223 }
224 224
225 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() { 225 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() {
226 return client_->CreateDrawable(); 226 return client_->CreateDrawable();
227 } 227 }
228 228
229 void TouchSelectionController::ShowInsertionHandleAutomatically() { 229 void TouchSelectionController::ShowInsertionHandleAutomatically() {
230 if (activate_insertion_automatically_) 230 if (activate_insertion_automatically_)
231 return; 231 return;
232 activate_insertion_automatically_ = true; 232 activate_insertion_automatically_ = true;
233 if (!is_insertion_active_ && !is_selection_active_) 233 ResetCachedValuesIfInactive();
234 ResetCachedValues();
235 } 234 }
236 235
237 void TouchSelectionController::ShowSelectionHandlesAutomatically() { 236 void TouchSelectionController::ShowSelectionHandlesAutomatically() {
238 if (activate_selection_automatically_) 237 if (activate_selection_automatically_)
239 return; 238 return;
240 activate_selection_automatically_ = true; 239 activate_selection_automatically_ = true;
241 if (!is_insertion_active_ && !is_selection_active_) 240 ResetCachedValuesIfInactive();
242 ResetCachedValues();
243 } 241 }
244 242
245 void TouchSelectionController::OnInsertionChanged() { 243 void TouchSelectionController::OnInsertionChanged() {
246 DeactivateSelection(); 244 DeactivateSelection();
247 245
248 if (last_input_event_type_ == TAP && selection_empty_) { 246 if (last_input_event_type_ == TAP && selection_empty_) {
249 HideAndDisallowShowingAutomatically(); 247 HideAndDisallowShowingAutomatically();
250 return; 248 return;
251 } 249 }
252 250
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 if (!is_selection_active_) 329 if (!is_selection_active_)
332 return; 330 return;
333 DCHECK(start_selection_handle_); 331 DCHECK(start_selection_handle_);
334 DCHECK(end_selection_handle_); 332 DCHECK(end_selection_handle_);
335 start_selection_handle_->SetEnabled(false); 333 start_selection_handle_->SetEnabled(false);
336 end_selection_handle_->SetEnabled(false); 334 end_selection_handle_->SetEnabled(false);
337 is_selection_active_ = false; 335 is_selection_active_ = false;
338 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF()); 336 client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF());
339 } 337 }
340 338
341 void TouchSelectionController::ResetCachedValues() { 339 void TouchSelectionController::ResetCachedValuesIfInactive() {
340 if (is_selection_active_ || is_insertion_active_)
341 return;
342 start_rect_ = gfx::RectF(); 342 start_rect_ = gfx::RectF();
343 end_rect_ = gfx::RectF(); 343 end_rect_ = gfx::RectF();
344 start_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; 344 start_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED;
345 end_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; 345 end_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED;
346 start_visible_ = false; 346 start_visible_ = false;
347 end_visible_ = false; 347 end_visible_ = false;
348 } 348 }
349 349
350 gfx::PointF TouchSelectionController::GetStartPosition() const { 350 gfx::PointF TouchSelectionController::GetStartPosition() const {
351 return start_rect_.bottom_left(); 351 return start_rect_.bottom_left();
(...skipping 20 matching lines...) Expand all
372 } 372 }
373 373
374 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( 374 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle(
375 bool was_active) const { 375 bool was_active) const {
376 return was_active && client_->SupportsAnimation() 376 return was_active && client_->SupportsAnimation()
377 ? TouchHandle::ANIMATION_SMOOTH 377 ? TouchHandle::ANIMATION_SMOOTH
378 : TouchHandle::ANIMATION_NONE; 378 : TouchHandle::ANIMATION_NONE;
379 } 379 }
380 380
381 } // namespace content 381 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698