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

Side by Side Diff: ui/touch_selection/touch_selection_controller.cc

Issue 1358263002: [Android] Support double-tap selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix contextual search Created 5 years, 2 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 "ui/touch_selection/touch_selection_controller.h" 5 #include "ui/touch_selection/touch_selection_controller.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 10
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 if ((event_pos - GetStartPosition()).LengthSquared() <= 167 if ((event_pos - GetStartPosition()).LengthSquared() <=
168 (event_pos - GetEndPosition()).LengthSquared()) { 168 (event_pos - GetEndPosition()).LengthSquared()) {
169 return start_selection_handle_->WillHandleTouchEvent(event); 169 return start_selection_handle_->WillHandleTouchEvent(event);
170 } 170 }
171 return end_selection_handle_->WillHandleTouchEvent(event); 171 return end_selection_handle_->WillHandleTouchEvent(event);
172 } 172 }
173 173
174 return false; 174 return false;
175 } 175 }
176 176
177 bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location) { 177 bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location,
178 int tap_count) {
178 if (WillHandleTapOrLongPress(location)) 179 if (WillHandleTapOrLongPress(location))
179 return true; 180 return true;
180 181
181 response_pending_input_event_ = TAP; 182 if (tap_count > 1) {
182 if (active_status_ != SELECTION_ACTIVE) 183 response_pending_input_event_ = REPEATED_TAP;
183 activate_selection_automatically_ = false; 184 ShowSelectionHandlesAutomatically();
185 } else {
186 response_pending_input_event_ = TAP;
187 if (active_status_ != SELECTION_ACTIVE)
188 activate_selection_automatically_ = false;
189 }
184 ShowInsertionHandleAutomatically(); 190 ShowInsertionHandleAutomatically();
185 if (selection_empty_ && !config_.show_on_tap_for_empty_editable) 191 if (selection_empty_ && !config_.show_on_tap_for_empty_editable)
186 DeactivateInsertion(); 192 DeactivateInsertion();
187 ForceNextUpdateIfInactive(); 193 ForceNextUpdateIfInactive();
188 return false; 194 return false;
189 } 195 }
190 196
191 bool TouchSelectionController::WillHandleLongPressEvent( 197 bool TouchSelectionController::WillHandleLongPressEvent(
192 base::TimeTicks event_time, 198 base::TimeTicks event_time,
193 const gfx::PointF& location) { 199 const gfx::PointF& location) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 RectFBetweenSelectionBounds(start_, end_).Contains(location)) { 427 RectFBetweenSelectionBounds(start_, end_).Contains(location)) {
422 AllowShowingFromCurrentSelection(); 428 AllowShowingFromCurrentSelection();
423 return true; 429 return true;
424 } 430 }
425 return false; 431 return false;
426 } 432 }
427 433
428 void TouchSelectionController::OnInsertionChanged() { 434 void TouchSelectionController::OnInsertionChanged() {
429 DeactivateSelection(); 435 DeactivateSelection();
430 436
431 if (response_pending_input_event_ == TAP && selection_empty_ && 437 if ((response_pending_input_event_ == TAP ||
432 !config_.show_on_tap_for_empty_editable) { 438 response_pending_input_event_ == REPEATED_TAP) &&
439 selection_empty_ && !config_.show_on_tap_for_empty_editable) {
433 HideAndDisallowShowingAutomatically(); 440 HideAndDisallowShowingAutomatically();
434 return; 441 return;
435 } 442 }
436 443
437 if (!activate_insertion_automatically_) 444 if (!activate_insertion_automatically_)
438 return; 445 return;
439 446
440 const bool activated = ActivateInsertionIfNecessary(); 447 const bool activated = ActivateInsertionIfNecessary();
441 448
442 const TouchHandle::AnimationStyle animation = GetAnimationStyle(!activated); 449 const TouchHandle::AnimationStyle animation = GetAnimationStyle(!activated);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 } else { 512 } else {
506 end_selection_handle_->SetEnabled(true); 513 end_selection_handle_->SetEnabled(true);
507 end_selection_handle_->SetOrientation(end_orientation_); 514 end_selection_handle_->SetOrientation(end_orientation_);
508 } 515 }
509 516
510 // As a long press received while a selection is already active may trigger 517 // As a long press received while a selection is already active may trigger
511 // an entirely new selection, notify the client but avoid sending an 518 // an entirely new selection, notify the client but avoid sending an
512 // intervening SELECTION_HANDLES_CLEARED update to avoid unnecessary state 519 // intervening SELECTION_HANDLES_CLEARED update to avoid unnecessary state
513 // changes. 520 // changes.
514 if (active_status_ == INACTIVE || 521 if (active_status_ == INACTIVE ||
515 response_pending_input_event_ == LONG_PRESS) { 522 response_pending_input_event_ == LONG_PRESS ||
523 response_pending_input_event_ == REPEATED_TAP) {
516 if (active_status_ == SELECTION_ACTIVE) { 524 if (active_status_ == SELECTION_ACTIVE) {
517 // The active selection session finishes with the start of the new one. 525 // The active selection session finishes with the start of the new one.
518 LogSelectionEnd(); 526 LogSelectionEnd();
519 } 527 }
520 active_status_ = SELECTION_ACTIVE; 528 active_status_ = SELECTION_ACTIVE;
521 selection_handle_dragged_ = false; 529 selection_handle_dragged_ = false;
522 selection_start_time_ = base::TimeTicks::Now(); 530 selection_start_time_ = base::TimeTicks::Now();
523 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE; 531 response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
524 longpress_drag_selector_.OnSelectionActivated(); 532 longpress_drag_selector_.OnSelectionActivated();
525 return true; 533 return true;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; 607 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
600 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", 608 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
601 duration, 609 duration,
602 base::TimeDelta::FromMilliseconds(500), 610 base::TimeDelta::FromMilliseconds(500),
603 base::TimeDelta::FromSeconds(60), 611 base::TimeDelta::FromSeconds(60),
604 60); 612 60);
605 } 613 }
606 } 614 }
607 615
608 } // namespace ui 616 } // namespace ui
OLDNEW
« no previous file with comments | « ui/touch_selection/touch_selection_controller.h ('k') | ui/touch_selection/touch_selection_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698