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

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

Issue 1404163004: Swap touch selection handles when they are interchanged (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 // Notify if selection bounds have just been established or dissolved. 83 // Notify if selection bounds have just been established or dissolved.
84 if (start.type() != SelectionBound::EMPTY && 84 if (start.type() != SelectionBound::EMPTY &&
85 start_.type() == SelectionBound::EMPTY) { 85 start_.type() == SelectionBound::EMPTY) {
86 client_->OnSelectionEvent(SELECTION_ESTABLISHED); 86 client_->OnSelectionEvent(SELECTION_ESTABLISHED);
87 } else if (start.type() == SelectionBound::EMPTY && 87 } else if (start.type() == SelectionBound::EMPTY &&
88 start_.type() != SelectionBound::EMPTY) { 88 start_.type() != SelectionBound::EMPTY) {
89 client_->OnSelectionEvent(SELECTION_DISSOLVED); 89 client_->OnSelectionEvent(SELECTION_DISSOLVED);
90 } 90 }
91 91
92 // Swap the Handles when the start and end selection points cross each other.
93 if (active_status_ == SELECTION_ACTIVE &&
AKV 2015/10/21 06:19:29 We can break this condition to 2 ifs to add more r
AviD 2015/10/21 06:40:02 Done.
94 ((start_selection_handle_->IsActive() &&
95 end_.edge_bottom() == start.edge_bottom()) ||
96 (end_selection_handle_->IsActive() &&
97 end.edge_bottom() == start_.edge_bottom()))) {
98 start_selection_handle_.swap(end_selection_handle_);
99 }
100
92 start_ = start; 101 start_ = start;
93 end_ = end; 102 end_ = end;
94 start_orientation_ = ToTouchHandleOrientation(start_.type()); 103 start_orientation_ = ToTouchHandleOrientation(start_.type());
95 end_orientation_ = ToTouchHandleOrientation(end_.type()); 104 end_orientation_ = ToTouchHandleOrientation(end_.type());
96 force_next_update_ = false; 105 force_next_update_ = false;
97 106
98 if (!activate_selection_automatically_ && 107 if (!activate_selection_automatically_ &&
99 !activate_insertion_automatically_) { 108 !activate_insertion_automatically_) {
100 DCHECK_EQ(INACTIVE, active_status_); 109 DCHECK_EQ(INACTIVE, active_status_);
101 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); 110 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_);
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 return !temporarily_hidden_ && !longpress_drag_selector_.IsActive(); 651 return !temporarily_hidden_ && !longpress_drag_selector_.IsActive();
643 } 652 }
644 653
645 bool TouchSelectionController::GetEndVisible() const { 654 bool TouchSelectionController::GetEndVisible() const {
646 if (!end_.visible()) 655 if (!end_.visible())
647 return false; 656 return false;
648 657
649 return !temporarily_hidden_ && !longpress_drag_selector_.IsActive(); 658 return !temporarily_hidden_ && !longpress_drag_selector_.IsActive();
650 } 659 }
651 660
661 TouchHandleOrientation TouchSelectionController::GetStartHandleOrientation()
662 const {
663 if (active_status_ != SELECTION_ACTIVE)
AKV 2015/10/21 06:19:29 May be we can return actual orientation and do thi
AviD 2015/10/21 06:40:02 I think this is better as it will also check for N
664 return TouchHandleOrientation::UNDEFINED;
665 return start_selection_handle_->orientation();
666 }
667
668 TouchHandleOrientation TouchSelectionController::GetEndHandleOrientation()
669 const {
670 if (active_status_ != SELECTION_ACTIVE)
AKV 2015/10/21 06:19:29 ditto
671 return TouchHandleOrientation::UNDEFINED;
672 return end_selection_handle_->orientation();
673 }
674
652 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( 675 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle(
653 bool was_active) const { 676 bool was_active) const {
654 return was_active && client_->SupportsAnimation() 677 return was_active && client_->SupportsAnimation()
655 ? TouchHandle::ANIMATION_SMOOTH 678 ? TouchHandle::ANIMATION_SMOOTH
656 : TouchHandle::ANIMATION_NONE; 679 : TouchHandle::ANIMATION_NONE;
657 } 680 }
658 681
659 void TouchSelectionController::LogSelectionEnd() { 682 void TouchSelectionController::LogSelectionEnd() {
660 // TODO(mfomitchev): Once we are able to tell the difference between 683 // TODO(mfomitchev): Once we are able to tell the difference between
661 // 'successful' and 'unsuccessful' selections - log 684 // 'successful' and 'unsuccessful' selections - log
662 // Event.TouchSelection.Duration instead and get rid of 685 // Event.TouchSelection.Duration instead and get rid of
663 // Event.TouchSelectionD.WasDraggeduration. 686 // Event.TouchSelectionD.WasDraggeduration.
664 if (selection_handle_dragged_) { 687 if (selection_handle_dragged_) {
665 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; 688 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
666 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", 689 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
667 duration, 690 duration,
668 base::TimeDelta::FromMilliseconds(500), 691 base::TimeDelta::FromMilliseconds(500),
669 base::TimeDelta::FromSeconds(60), 692 base::TimeDelta::FromSeconds(60),
670 60); 693 60);
671 } 694 }
672 } 695 }
673 696
674 } // namespace ui 697 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698