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

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

Issue 467303002: [Android] Perform haptic feedback after long press when appropriate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback with repeated long press 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
180 } 180 }
181 181
182 return false; 182 return false;
183 } 183 }
184 184
185 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { 185 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) {
186 last_input_event_type_ = INPUT_EVENT_TYPE_NONE;
187
186 if (&handle == insertion_handle_.get()) { 188 if (&handle == insertion_handle_.get()) {
187 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position()); 189 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position());
188 return; 190 return;
189 } 191 }
190 192
191 if (&handle == start_selection_handle_.get()) { 193 if (&handle == start_selection_handle_.get()) {
192 fixed_handle_position_ = end_selection_handle_->position() - 194 fixed_handle_position_ = end_selection_handle_->position() -
193 gfx::Vector2dF(0, GetEndLineHeight() / 2.f); 195 gfx::Vector2dF(0, GetEndLineHeight() / 2.f);
194 } else { 196 } else {
195 fixed_handle_position_ = start_selection_handle_->position() - 197 fixed_handle_position_ = start_selection_handle_->position() -
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 start_selection_handle_->SetOrientation(start_orientation_); 319 start_selection_handle_->SetOrientation(start_orientation_);
318 } 320 }
319 321
320 if (!end_selection_handle_) { 322 if (!end_selection_handle_) {
321 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); 323 end_selection_handle_.reset(new TouchHandle(this, end_orientation_));
322 } else { 324 } else {
323 end_selection_handle_->SetEnabled(true); 325 end_selection_handle_->SetEnabled(true);
324 end_selection_handle_->SetOrientation(end_orientation_); 326 end_selection_handle_->SetOrientation(end_orientation_);
325 } 327 }
326 328
327 if (!is_selection_active_) { 329 // As a long press received while a selection is already active may trigger
330 // an entirely new selection, notify the client but avoid sending an
331 // intervening SELECTION_CLEARED update to avoid unnecessary state changes.
332 if (!is_selection_active_ || last_input_event_type_ == LONG_PRESS) {
cjhopman 2014/08/14 00:12:28 Maybe there's a better name for last_input_event_t
jdduke (slow) 2014/08/14 17:57:19 Yeah, I'll tweak it.
328 is_selection_active_ = true; 333 is_selection_active_ = true;
334 last_input_event_type_ = INPUT_EVENT_TYPE_NONE;
329 client_->OnSelectionEvent(SELECTION_SHOWN, GetStartPosition()); 335 client_->OnSelectionEvent(SELECTION_SHOWN, GetStartPosition());
330 } 336 }
331 } 337 }
332 338
333 void TouchSelectionController::DeactivateSelection() { 339 void TouchSelectionController::DeactivateSelection() {
334 if (!is_selection_active_) 340 if (!is_selection_active_)
335 return; 341 return;
336 DCHECK(start_selection_handle_); 342 DCHECK(start_selection_handle_);
337 DCHECK(end_selection_handle_); 343 DCHECK(end_selection_handle_);
338 start_selection_handle_->SetEnabled(false); 344 start_selection_handle_->SetEnabled(false);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 383 }
378 384
379 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( 385 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle(
380 bool was_active) const { 386 bool was_active) const {
381 return was_active && client_->SupportsAnimation() 387 return was_active && client_->SupportsAnimation()
382 ? TouchHandle::ANIMATION_SMOOTH 388 ? TouchHandle::ANIMATION_SMOOTH
383 : TouchHandle::ANIMATION_NONE; 389 : TouchHandle::ANIMATION_NONE;
384 } 390 }
385 391
386 } // namespace content 392 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698