OLD | NEW |
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/events/gesture_detection/snap_scroll_controller.h" | 5 #include "ui/events/gesture_detection/snap_scroll_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "ui/events/gesture_detection/motion_event.h" | 9 #include "ui/events/gesture_detection/motion_event.h" |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 down_position_ = gfx::PointF(); | 84 down_position_ = gfx::PointF(); |
85 accumulated_distance_ = gfx::Vector2dF(); | 85 accumulated_distance_ = gfx::Vector2dF(); |
86 break; | 86 break; |
87 default: | 87 default: |
88 break; | 88 break; |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 void SnapScrollController::UpdateSnapScrollMode(float distance_x, | 92 void SnapScrollController::UpdateSnapScrollMode(float distance_x, |
93 float distance_y) { | 93 float distance_y) { |
94 if (!IsSnappingScrolls()) | 94 if (mode_ != SNAP_VERT && mode_ != SNAP_HORIZ) |
95 return; | 95 return; |
96 | 96 |
97 accumulated_distance_ += | 97 accumulated_distance_ += |
98 gfx::Vector2dF(std::abs(distance_x), std::abs(distance_y)); | 98 gfx::Vector2dF(std::abs(distance_x), std::abs(distance_y)); |
99 if (mode_ == SNAP_HORIZ) { | 99 if (mode_ == SNAP_HORIZ) { |
100 if (accumulated_distance_.y() > channel_distance_) | 100 if (accumulated_distance_.y() > channel_distance_) |
101 mode_ = SNAP_NONE; | 101 mode_ = SNAP_NONE; |
102 else if (accumulated_distance_.x() > channel_distance_) | 102 else if (accumulated_distance_.x() > channel_distance_) |
103 accumulated_distance_ = gfx::Vector2dF(); | 103 accumulated_distance_ = gfx::Vector2dF(); |
104 } else if (mode_ == SNAP_VERT) { | 104 } else if (mode_ == SNAP_VERT) { |
105 if (accumulated_distance_.x() > channel_distance_) | 105 if (accumulated_distance_.x() > channel_distance_) |
106 mode_ = SNAP_NONE; | 106 mode_ = SNAP_NONE; |
107 else if (accumulated_distance_.y() > channel_distance_) | 107 else if (accumulated_distance_.y() > channel_distance_) |
108 accumulated_distance_ = gfx::Vector2dF(); | 108 accumulated_distance_ = gfx::Vector2dF(); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 bool SnapScrollController::IsSnapVertical() const { | 112 bool SnapScrollController::IsSnapVertical() const { |
113 return mode_ == SNAP_VERT; | 113 return ScrollRailState() == GestureEventDetails::ScrollRailState::Vertical; |
114 } | 114 } |
115 | 115 |
116 bool SnapScrollController::IsSnapHorizontal() const { | 116 bool SnapScrollController::IsSnapHorizontal() const { |
117 return mode_ == SNAP_HORIZ; | 117 return ScrollRailState() == GestureEventDetails::ScrollRailState::Horizontal; |
118 } | 118 } |
119 | 119 |
120 bool SnapScrollController::IsSnappingScrolls() const { | 120 bool SnapScrollController::IsSnappingScrolls() const { |
121 return IsSnapHorizontal() || IsSnapVertical(); | 121 return ScrollRailState() != GestureEventDetails::ScrollRailState::Free; |
| 122 } |
| 123 |
| 124 |
| 125 GestureEventDetails::ScrollRailState SnapScrollController::ScrollRailState() |
| 126 const { |
| 127 if (mode_ == SNAP_VERT) |
| 128 return GestureEventDetails::ScrollRailState::Vertical; |
| 129 if (mode_ == SNAP_HORIZ) |
| 130 return GestureEventDetails::ScrollRailState::Horizontal; |
| 131 return GestureEventDetails::ScrollRailState::Free; |
122 } | 132 } |
123 | 133 |
124 } // namespace ui | 134 } // namespace ui |
OLD | NEW |