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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 default: | 46 default: |
47 return false; | 47 return false; |
48 } | 48 } |
49 | 49 |
50 if (state_ != DRAG_PENDING && state_ != DRAGGING) | 50 if (state_ != DRAG_PENDING && state_ != DRAGGING) |
51 return false; | 51 return false; |
52 | 52 |
53 gfx::PointF position(event.GetX(), event.GetY()); | 53 gfx::PointF position(event.GetX(), event.GetY()); |
54 if (state_ == DRAGGING) { | 54 if (state_ == DRAGGING) { |
55 gfx::PointF drag_position = position + longpress_drag_selection_offset_; | 55 gfx::PointF drag_position = position + longpress_drag_selection_offset_; |
56 client_->OnDragUpdate(*this, drag_position); | 56 client_->OnDragEvent(HANDLE_DRAG_UPDATE, *this, drag_position); |
57 return true; | 57 return true; |
58 } | 58 } |
59 | 59 |
60 // We can't use |touch_down_position_| as the offset anchor, as | 60 // We can't use |touch_down_position_| as the offset anchor, as |
61 // showing the selection UI may have shifted the motion coordinates. | 61 // showing the selection UI may have shifted the motion coordinates. |
62 if (!has_longpress_drag_start_anchor_) { | 62 if (!has_longpress_drag_start_anchor_) { |
63 has_longpress_drag_start_anchor_ = true; | 63 has_longpress_drag_start_anchor_ = true; |
64 longpress_drag_start_anchor_ = position; | 64 longpress_drag_start_anchor_ = position; |
65 return true; | 65 return true; |
66 } | 66 } |
(...skipping 28 matching lines...) Expand all Loading... |
95 extend_selection_start = start_dot_product > end_dot_product; | 95 extend_selection_start = start_dot_product > end_dot_product; |
96 } else { | 96 } else { |
97 // If we're already moving away from both endpoints, pick the closest. | 97 // If we're already moving away from both endpoints, pick the closest. |
98 extend_selection_start = | 98 extend_selection_start = |
99 start_delta.LengthSquared() < end_delta.LengthSquared(); | 99 start_delta.LengthSquared() < end_delta.LengthSquared(); |
100 } | 100 } |
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_->OnDragEvent(HANDLE_DRAG_BEGIN, *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_ != INACTIVE && state_ != LONGPRESS_PENDING; |
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) { |
(...skipping 22 matching lines...) Expand all Loading... |
138 void LongPressDragSelector::SetState(SelectionState state) { | 138 void LongPressDragSelector::SetState(SelectionState state) { |
139 if (state_ == state) | 139 if (state_ == state) |
140 return; | 140 return; |
141 | 141 |
142 const bool was_dragging = state_ == DRAGGING; | 142 const bool was_dragging = state_ == DRAGGING; |
143 const bool was_active = IsActive(); | 143 const bool was_active = IsActive(); |
144 state_ = state; | 144 state_ = state; |
145 | 145 |
146 // TODO(jdduke): Add UMA for tracking relative longpress drag frequency. | 146 // TODO(jdduke): Add UMA for tracking relative longpress drag frequency. |
147 if (was_dragging) | 147 if (was_dragging) |
148 client_->OnDragEnd(*this); | 148 client_->OnDragEvent(HANDLE_DRAG_END, *this, gfx::PointF()); |
149 | 149 |
150 if (was_active != IsActive()) | 150 if (was_active != IsActive()) |
151 client_->OnLongPressDragActiveStateChanged(); | 151 client_->OnLongPressDragActiveStateChanged(); |
152 } | 152 } |
153 | 153 |
154 } // namespace ui | 154 } // namespace ui |
OLD | NEW |