OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/longpress_drag_selector.h" | 5 #include "ui/touch_selection/longpress_drag_selector.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "ui/events/gesture_detection/motion_event.h" | 8 #include "ui/events/gesture_detection/motion_event.h" |
9 | 9 |
10 namespace ui { | 10 namespace ui { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 101 } |
102 | 102 |
103 gfx::PointF extent = extend_selection_start ? selection_start : selection_end; | 103 gfx::PointF extent = extend_selection_start ? selection_start : selection_end; |
104 longpress_drag_selection_offset_ = extent - position; | 104 longpress_drag_selection_offset_ = extent - position; |
105 client_->OnDragBegin(*this, extent); | 105 client_->OnDragBegin(*this, extent); |
106 SetState(DRAGGING); | 106 SetState(DRAGGING); |
107 return true; | 107 return true; |
108 } | 108 } |
109 | 109 |
110 bool LongPressDragSelector::IsActive() const { | 110 bool LongPressDragSelector::IsActive() const { |
111 return state_ != INACTIVE && state_ != LONGPRESS_PENDING; | 111 return state_ == DRAG_PENDING || state_ == DRAGGING; |
112 } | 112 } |
113 | 113 |
114 void LongPressDragSelector::OnLongPressEvent(base::TimeTicks event_time, | 114 void LongPressDragSelector::OnLongPressEvent(base::TimeTicks event_time, |
115 const gfx::PointF& position) { | 115 const gfx::PointF& position) { |
116 // We have no guarantees that the current gesture stream is aligned with the | 116 // We have no guarantees that the current gesture stream is aligned with the |
117 // observed touch stream. We only know that the gesture sequence is downstream | 117 // observed touch stream. We only know that the gesture sequence is downstream |
118 // from the touch sequence. Using a time/distance heuristic helps ensure that | 118 // from the touch sequence. Using a time/distance heuristic helps ensure that |
119 // the observed longpress corresponds to the active touch sequence. | 119 // the observed longpress corresponds to the active touch sequence. |
120 if (state_ == LONGPRESS_PENDING && | 120 if (state_ == LONGPRESS_PENDING && |
121 // Ensure the down event occurs *before* the longpress event. Use a | 121 // Ensure the down event occurs *before* the longpress event. Use a |
122 // small time epsilon to account for floating point time conversion. | 122 // small time epsilon to account for floating point time conversion. |
123 (touch_down_time_ < event_time + base::TimeDelta::FromMicroseconds(10)) && | 123 (touch_down_time_ < event_time + base::TimeDelta::FromMicroseconds(10)) && |
124 client_->IsWithinTapSlop(touch_down_position_ - position)) { | 124 client_->IsWithinTapSlop(touch_down_position_ - position)) { |
125 SetState(SELECTION_PENDING); | 125 SetState(SELECTION_PENDING); |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
| 129 void LongPressDragSelector::OnScrollBeginEvent() { |
| 130 SetState(INACTIVE); |
| 131 } |
| 132 |
129 void LongPressDragSelector::OnSelectionActivated() { | 133 void LongPressDragSelector::OnSelectionActivated() { |
130 if (state_ == SELECTION_PENDING) | 134 if (state_ == SELECTION_PENDING) |
131 SetState(DRAG_PENDING); | 135 SetState(DRAG_PENDING); |
132 } | 136 } |
133 | 137 |
134 void LongPressDragSelector::OnSelectionDeactivated() { | 138 void LongPressDragSelector::OnSelectionDeactivated() { |
135 SetState(INACTIVE); | 139 SetState(INACTIVE); |
136 } | 140 } |
137 | 141 |
138 void LongPressDragSelector::SetState(SelectionState state) { | 142 void LongPressDragSelector::SetState(SelectionState state) { |
139 if (state_ == state) | 143 if (state_ == state) |
140 return; | 144 return; |
141 | 145 |
142 const bool was_dragging = state_ == DRAGGING; | 146 const bool was_dragging = state_ == DRAGGING; |
143 const bool was_active = IsActive(); | 147 const bool was_active = IsActive(); |
144 state_ = state; | 148 state_ = state; |
145 | 149 |
146 // TODO(jdduke): Add UMA for tracking relative longpress drag frequency. | 150 // TODO(jdduke): Add UMA for tracking relative longpress drag frequency. |
147 if (was_dragging) | 151 if (was_dragging) |
148 client_->OnDragEnd(*this); | 152 client_->OnDragEnd(*this); |
149 | 153 |
150 if (was_active != IsActive()) | 154 if (was_active != IsActive()) |
151 client_->OnLongPressDragActiveStateChanged(); | 155 client_->OnLongPressDragActiveStateChanged(); |
152 } | 156 } |
153 | 157 |
154 } // namespace ui | 158 } // namespace ui |
OLD | NEW |