Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h" | 5 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/gfx/geometry/point_f.h" | 8 #include "ui/gfx/geometry/point_f.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 gfx::Vector2d FloorTowardZero(const gfx::Vector2dF& vector) { | 13 gfx::Vector2d FloorTowardZero(const gfx::Vector2dF& vector) { |
| 14 int x = vector.x() > 0 ? floor(vector.x()) : ceil(vector.x()); | 14 int x = vector.x() > 0 ? floor(vector.x()) : ceil(vector.x()); |
| 15 int y = vector.y() > 0 ? floor(vector.y()) : ceil(vector.y()); | 15 int y = vector.y() > 0 ? floor(vector.y()) : ceil(vector.y()); |
| 16 return gfx::Vector2d(x, y); | 16 return gfx::Vector2d(x, y); |
| 17 } | 17 } |
| 18 | 18 |
| 19 gfx::Vector2d CeilFromZero(const gfx::Vector2dF& vector) { | 19 gfx::Vector2d CeilFromZero(const gfx::Vector2dF& vector) { |
| 20 int x = vector.x() > 0 ? ceil(vector.x()) : floor(vector.x()); | 20 int x = vector.x() > 0 ? ceil(vector.x()) : floor(vector.x()); |
| 21 int y = vector.y() > 0 ? ceil(vector.y()) : floor(vector.y()); | 21 int y = vector.y() > 0 ? ceil(vector.y()) : floor(vector.y()); |
| 22 return gfx::Vector2d(x, y); | 22 return gfx::Vector2d(x, y); |
| 23 } | 23 } |
| 24 | 24 |
| 25 gfx::Vector2dF ProjectScalarOntoVector( | 25 gfx::Vector2dF ProjectScalarOntoVector( |
| 26 float scalar, const gfx::Vector2d& vector) { | 26 float scalar, const gfx::Vector2d& vector) { |
| 27 return gfx::ScaleVector2d(vector, scalar / vector.Length()); | 27 return gfx::ScaleVector2d(vector, scalar / vector.Length()); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 SyntheticSmoothScrollGesture::SyntheticSmoothScrollGesture( | 32 SyntheticSmoothMoveGesture::SyntheticSmoothMoveGesture( |
| 33 const SyntheticSmoothScrollGestureParams& params) | 33 SyntheticGestureParams::GestureSourceType gesture_source_type, |
| 34 : params_(params), | 34 gfx::Point start_point, |
| 35 gesture_source_type_(SyntheticGestureParams::DEFAULT_INPUT), | 35 std::vector<gfx::Vector2d> move_distances, |
| 36 state_(SETUP) {} | 36 int speed_in_pixels_s, |
| 37 | 37 bool prevent_fling) |
| 38 SyntheticSmoothScrollGesture::~SyntheticSmoothScrollGesture() {} | 38 : state_(SETUP), |
| 39 | 39 gesture_source_type_(gesture_source_type), |
| 40 SyntheticGesture::Result SyntheticSmoothScrollGesture::ForwardInputEvents( | 40 current_move_segment_start_position_(start_point), |
| 41 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { | 41 move_distances_(move_distances), |
| 42 if (state_ == SETUP) { | 42 speed_in_pixels_s_(speed_in_pixels_s), |
| 43 gesture_source_type_ = params_.gesture_source_type; | 43 prevent_fling_(prevent_fling) { |
| 44 if (gesture_source_type_ == SyntheticGestureParams::DEFAULT_INPUT) | |
| 45 gesture_source_type_ = target->GetDefaultSyntheticGestureSourceType(); | |
| 46 | |
| 47 state_ = STARTED; | |
| 48 current_scroll_segment_ = -1; | |
| 49 current_scroll_segment_stop_time_ = timestamp; | |
| 50 } | |
| 51 | |
| 52 DCHECK_NE(gesture_source_type_, SyntheticGestureParams::DEFAULT_INPUT); | |
| 53 if (gesture_source_type_ == SyntheticGestureParams::TOUCH_INPUT) | |
| 54 ForwardTouchInputEvents(timestamp, target); | |
| 55 else if (gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT) | |
| 56 ForwardMouseInputEvents(timestamp, target); | |
| 57 else | |
| 58 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; | |
| 59 | |
| 60 return (state_ == DONE) ? SyntheticGesture::GESTURE_FINISHED | |
| 61 : SyntheticGesture::GESTURE_RUNNING; | |
| 62 } | 44 } |
| 63 | 45 |
| 64 void SyntheticSmoothScrollGesture::ForwardTouchInputEvents( | 46 SyntheticSmoothMoveGesture::~SyntheticSmoothMoveGesture() {} |
| 47 | |
| 48 void SyntheticSmoothMoveGesture::ForwardTouchInputEvents( | |
| 65 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { | 49 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { |
| 66 base::TimeTicks event_timestamp = timestamp; | 50 base::TimeTicks event_timestamp = timestamp; |
| 67 switch (state_) { | 51 switch (state_) { |
| 68 case STARTED: | 52 case STARTED: |
| 69 if (ScrollIsNoOp()) { | 53 if (MoveIsNoOp()) { |
| 70 state_ = DONE; | 54 state_ = DONE; |
| 71 break; | 55 break; |
| 72 } | 56 } |
| 73 AddTouchSlopToFirstDistance(target); | 57 AddTouchSlopToFirstDistance(target); |
| 74 ComputeNextScrollSegment(); | 58 ComputeNextMoveSegment(); |
| 75 current_scroll_segment_start_position_ = params_.anchor; | |
| 76 PressTouchPoint(target, event_timestamp); | 59 PressTouchPoint(target, event_timestamp); |
| 77 state_ = MOVING; | 60 state_ = MOVING; |
| 78 break; | 61 break; |
| 79 case MOVING: { | 62 case MOVING: { |
| 80 event_timestamp = ClampTimestamp(timestamp); | 63 event_timestamp = ClampTimestamp(timestamp); |
| 81 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp); | 64 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp); |
| 82 MoveTouchPoint(target, delta, event_timestamp); | 65 MoveTouchPoint(target, delta, event_timestamp); |
| 83 | 66 |
| 84 if (FinishedCurrentScrollSegment(event_timestamp)) { | 67 if (FinishedCurrentMoveSegment(event_timestamp)) { |
| 85 if (!IsLastScrollSegment()) { | 68 if (!IsLastMoveSegment()) { |
| 86 current_scroll_segment_start_position_ += | 69 current_move_segment_start_position_ += |
| 87 params_.distances[current_scroll_segment_]; | 70 move_distances_[current_move_segment_]; |
| 88 ComputeNextScrollSegment(); | 71 ComputeNextMoveSegment(); |
| 89 } else if (params_.prevent_fling) { | 72 } else if (prevent_fling_) { |
| 90 state_ = STOPPING; | 73 state_ = STOPPING; |
| 91 } else { | 74 } else { |
| 92 ReleaseTouchPoint(target, event_timestamp); | 75 ReleaseTouchPoint(target, event_timestamp); |
| 93 state_ = DONE; | 76 state_ = DONE; |
| 94 } | 77 } |
| 95 } | 78 } |
| 96 } break; | 79 } break; |
| 97 case STOPPING: | 80 case STOPPING: |
| 98 if (timestamp - current_scroll_segment_stop_time_ >= | 81 if (timestamp - current_move_segment_stop_time_ >= |
| 99 target->PointerAssumedStoppedTime()) { | 82 target->PointerAssumedStoppedTime()) { |
| 100 event_timestamp = current_scroll_segment_stop_time_ + | 83 event_timestamp = current_move_segment_stop_time_ + |
| 101 target->PointerAssumedStoppedTime(); | 84 target->PointerAssumedStoppedTime(); |
| 102 ReleaseTouchPoint(target, event_timestamp); | 85 ReleaseTouchPoint(target, event_timestamp); |
| 103 state_ = DONE; | 86 state_ = DONE; |
| 104 } | 87 } |
| 105 break; | 88 break; |
| 106 case SETUP: | 89 case SETUP: |
| 107 NOTREACHED() | 90 NOTREACHED() |
| 108 << "State STARTED invalid for synthetic scroll using touch input."; | 91 << "State STARTED invalid for synthetic scroll using touch input."; |
| 109 case DONE: | 92 case DONE: |
| 110 NOTREACHED() | 93 NOTREACHED() |
| 111 << "State DONE invalid for synthetic scroll using touch input."; | 94 << "State DONE invalid for synthetic scroll using touch input."; |
| 112 } | 95 } |
| 113 } | 96 } |
| 114 | 97 |
| 115 void SyntheticSmoothScrollGesture::ForwardMouseInputEvents( | 98 void SyntheticSmoothMoveGesture::ForwardMouseWheelInputEvents( |
| 116 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { | 99 const base::TimeTicks& timestamp, SyntheticGestureTarget* target) { |
| 117 switch (state_) { | 100 switch (state_) { |
| 118 case STARTED: | 101 case STARTED: |
| 119 if (ScrollIsNoOp()) { | 102 if (MoveIsNoOp()) { |
| 120 state_ = DONE; | 103 state_ = DONE; |
| 121 break; | 104 break; |
| 122 } | 105 } |
| 123 ComputeNextScrollSegment(); | 106 ComputeNextMoveSegment(); |
| 124 state_ = MOVING; | 107 state_ = MOVING; |
| 125 // Fall through to forward the first event. | 108 // Fall through to forward the first event. |
| 126 case MOVING: { | 109 case MOVING: { |
| 127 // Even though WebMouseWheelEvents take floating point deltas, | 110 // Even though WebMouseWheelEvents take floating point deltas, |
| 128 // internally the scroll position is stored as an integer. We therefore | 111 // internally the scroll position is stored as an integer. We therefore |
| 129 // keep track of the discrete delta which is consistent with the | 112 // keep track of the discrete delta which is consistent with the |
| 130 // internal scrolling state. This ensures that when the gesture has | 113 // internal scrolling state. This ensures that when the gesture has |
| 131 // finished we've scrolled exactly the specified distance. | 114 // finished we've scrolled exactly the specified distance. |
| 132 base::TimeTicks event_timestamp = ClampTimestamp(timestamp); | 115 base::TimeTicks event_timestamp = ClampTimestamp(timestamp); |
| 133 gfx::Vector2dF current_scroll_segment_total_delta = | 116 gfx::Vector2dF current_move_segment_total_delta = |
| 134 GetPositionDeltaAtTime(event_timestamp); | 117 GetPositionDeltaAtTime(event_timestamp); |
| 135 gfx::Vector2d delta_discrete = | 118 gfx::Vector2d delta_discrete = |
| 136 FloorTowardZero(current_scroll_segment_total_delta - | 119 FloorTowardZero(current_move_segment_total_delta - |
| 137 current_scroll_segment_total_delta_discrete_); | 120 current_move_segment_total_delta_discrete_); |
| 138 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp); | 121 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp); |
| 139 current_scroll_segment_total_delta_discrete_ += delta_discrete; | 122 current_move_segment_total_delta_discrete_ += delta_discrete; |
| 140 | 123 |
| 141 if (FinishedCurrentScrollSegment(event_timestamp)) { | 124 if (FinishedCurrentMoveSegment(event_timestamp)) { |
| 142 if (!IsLastScrollSegment()) { | 125 if (!IsLastMoveSegment()) { |
| 143 current_scroll_segment_total_delta_discrete_ = gfx::Vector2d(); | 126 current_move_segment_total_delta_discrete_ = gfx::Vector2d(); |
| 144 ComputeNextScrollSegment(); | 127 ComputeNextMoveSegment(); |
| 145 ForwardMouseInputEvents(timestamp, target); | 128 ForwardMouseWheelInputEvents(timestamp, target); |
| 146 } else { | 129 } else { |
| 147 state_ = DONE; | 130 state_ = DONE; |
| 148 } | 131 } |
| 149 } | 132 } |
| 150 } break; | 133 } break; |
| 151 case SETUP: | 134 case SETUP: |
| 152 NOTREACHED() | 135 NOTREACHED() |
| 153 << "State STARTED invalid for synthetic scroll using touch input."; | 136 << "State STARTED invalid for synthetic scroll using touch input."; |
|
Sami
2015/02/18 12:01:53
This message looks wrong by the way.
ssid
2015/02/18 17:57:34
Done.
| |
| 154 case STOPPING: | 137 case STOPPING: |
| 155 NOTREACHED() | 138 NOTREACHED() |
| 156 << "State STOPPING invalid for synthetic scroll using touch input."; | 139 << "State STOPPING invalid for synthetic scroll using touch input."; |
| 157 case DONE: | 140 case DONE: |
| 158 NOTREACHED() | 141 NOTREACHED() |
| 159 << "State DONE invalid for synthetic scroll using touch input."; | 142 << "State DONE invalid for synthetic scroll using touch input."; |
| 160 } | 143 } |
| 161 } | 144 } |
| 162 | 145 |
| 163 void SyntheticSmoothScrollGesture::ForwardTouchEvent( | 146 void SyntheticSmoothMoveGesture::ForwardMouseClickInputEvents( |
| 147 const base::TimeTicks& timestamp, | |
| 148 SyntheticGestureTarget* target) { | |
| 149 base::TimeTicks event_timestamp = timestamp; | |
| 150 switch (state_) { | |
| 151 case STARTED: | |
| 152 if (MoveIsNoOp()) { | |
| 153 state_ = DONE; | |
| 154 break; | |
| 155 } | |
| 156 ComputeNextMoveSegment(); | |
| 157 PressMousePoint(target, event_timestamp); | |
| 158 state_ = MOVING; | |
| 159 case MOVING: { | |
| 160 base::TimeTicks event_timestamp = ClampTimestamp(timestamp); | |
| 161 gfx::Vector2dF delta = GetPositionDeltaAtTime(event_timestamp); | |
| 162 MoveMousePoint(target, delta, event_timestamp); | |
| 163 | |
| 164 if (FinishedCurrentMoveSegment(event_timestamp)) { | |
| 165 if (!IsLastMoveSegment()) { | |
| 166 current_move_segment_start_position_ += | |
| 167 move_distances_[current_move_segment_]; | |
| 168 ComputeNextMoveSegment(); | |
| 169 } else { | |
| 170 ReleaseMousePoint(target, event_timestamp); | |
| 171 state_ = DONE; | |
| 172 } | |
| 173 } | |
| 174 } break; | |
| 175 case STOPPING: | |
| 176 NOTREACHED() | |
| 177 << "State STOPPING invalid for synthetic drag using mouse input."; | |
| 178 case SETUP: | |
| 179 NOTREACHED() | |
| 180 << "State SETUP invalid for synthetic drag using mouse input."; | |
| 181 case DONE: | |
| 182 NOTREACHED() | |
| 183 << "State DONE invalid for synthetic drag using mouse input."; | |
| 184 } | |
| 185 } | |
| 186 | |
| 187 void SyntheticSmoothMoveGesture::ForwardTouchEvent( | |
| 164 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { | 188 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { |
| 165 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 189 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 166 | 190 |
| 167 target->DispatchInputEventToPlatform(touch_event_); | 191 target->DispatchInputEventToPlatform(touch_event_); |
| 168 } | 192 } |
| 169 | 193 |
| 170 void SyntheticSmoothScrollGesture::ForwardMouseWheelEvent( | 194 void SyntheticSmoothMoveGesture::ForwardMouseWheelEvent( |
| 171 SyntheticGestureTarget* target, | 195 SyntheticGestureTarget* target, |
| 172 const gfx::Vector2dF& delta, | 196 const gfx::Vector2dF& delta, |
| 173 const base::TimeTicks& timestamp) const { | 197 const base::TimeTicks& timestamp) const { |
| 174 blink::WebMouseWheelEvent mouse_wheel_event = | 198 blink::WebMouseWheelEvent mouse_wheel_event = |
| 175 SyntheticWebMouseWheelEventBuilder::Build(delta.x(), delta.y(), 0, false); | 199 SyntheticWebMouseWheelEventBuilder::Build(delta.x(), delta.y(), 0, false); |
| 176 | 200 |
| 177 mouse_wheel_event.x = params_.anchor.x(); | 201 mouse_wheel_event.x = current_move_segment_start_position_.x(); |
| 178 mouse_wheel_event.y = params_.anchor.y(); | 202 mouse_wheel_event.y = current_move_segment_start_position_.y(); |
| 179 | 203 |
| 180 mouse_wheel_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 204 mouse_wheel_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 181 | 205 |
| 182 target->DispatchInputEventToPlatform(mouse_wheel_event); | 206 target->DispatchInputEventToPlatform(mouse_wheel_event); |
| 183 } | 207 } |
| 184 | 208 |
| 185 void SyntheticSmoothScrollGesture::PressTouchPoint( | 209 void SyntheticSmoothMoveGesture::PressTouchPoint( |
| 186 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { | 210 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { |
| 187 DCHECK_EQ(current_scroll_segment_, 0); | 211 DCHECK_EQ(current_move_segment_, 0); |
| 188 touch_event_.PressPoint(params_.anchor.x(), params_.anchor.y()); | 212 touch_event_.PressPoint(current_move_segment_start_position_.x(), |
| 213 current_move_segment_start_position_.y()); | |
| 189 ForwardTouchEvent(target, timestamp); | 214 ForwardTouchEvent(target, timestamp); |
| 190 } | 215 } |
| 191 | 216 |
| 192 void SyntheticSmoothScrollGesture::MoveTouchPoint( | 217 void SyntheticSmoothMoveGesture::MoveTouchPoint( |
| 193 SyntheticGestureTarget* target, | 218 SyntheticGestureTarget* target, |
| 194 const gfx::Vector2dF& delta, | 219 const gfx::Vector2dF& delta, |
| 195 const base::TimeTicks& timestamp) { | 220 const base::TimeTicks& timestamp) { |
| 196 DCHECK_GE(current_scroll_segment_, 0); | 221 DCHECK_GE(current_move_segment_, 0); |
| 197 DCHECK_LT(current_scroll_segment_, | 222 DCHECK_LT(current_move_segment_, static_cast<int>(move_distances_.size())); |
| 198 static_cast<int>(params_.distances.size())); | 223 gfx::PointF touch_position = current_move_segment_start_position_ + delta; |
| 199 gfx::PointF touch_position = current_scroll_segment_start_position_ + delta; | |
| 200 touch_event_.MovePoint(0, touch_position.x(), touch_position.y()); | 224 touch_event_.MovePoint(0, touch_position.x(), touch_position.y()); |
| 201 ForwardTouchEvent(target, timestamp); | 225 ForwardTouchEvent(target, timestamp); |
| 202 } | 226 } |
| 203 | 227 |
| 204 void SyntheticSmoothScrollGesture::ReleaseTouchPoint( | 228 void SyntheticSmoothMoveGesture::ReleaseTouchPoint( |
| 205 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { | 229 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { |
| 206 DCHECK_EQ(current_scroll_segment_, | 230 DCHECK_EQ(current_move_segment_, |
| 207 static_cast<int>(params_.distances.size()) - 1); | 231 static_cast<int>(move_distances_.size()) - 1); |
| 208 touch_event_.ReleasePoint(0); | 232 touch_event_.ReleasePoint(0); |
| 209 ForwardTouchEvent(target, timestamp); | 233 ForwardTouchEvent(target, timestamp); |
| 210 } | 234 } |
| 211 | 235 |
| 212 void SyntheticSmoothScrollGesture::AddTouchSlopToFirstDistance( | 236 void SyntheticSmoothMoveGesture::PressMousePoint(SyntheticGestureTarget* target, |
| 213 SyntheticGestureTarget* target) { | 237 const base::TimeTicks& timestamp) { |
| 214 DCHECK_GE(params_.distances.size(), 1ul); | 238 DCHECK(gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT); |
| 215 gfx::Vector2d& first_scroll_distance = params_.distances[0]; | 239 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build( |
| 216 DCHECK_GT(first_scroll_distance.Length(), 0); | 240 blink::WebInputEvent::MouseDown, current_move_segment_start_position_.x(), |
| 217 first_scroll_distance += CeilFromZero(ProjectScalarOntoVector( | 241 current_move_segment_start_position_.y(), 0); |
| 218 target->GetTouchSlopInDips(), first_scroll_distance)); | 242 mouse_event.clickCount = 1; |
| 243 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | |
| 244 target->DispatchInputEventToPlatform(mouse_event); | |
| 219 } | 245 } |
| 220 | 246 |
| 221 gfx::Vector2dF SyntheticSmoothScrollGesture::GetPositionDeltaAtTime( | 247 void SyntheticSmoothMoveGesture::ReleaseMousePoint( |
| 248 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { | |
| 249 DCHECK(gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT); | |
| 250 gfx::PointF touch_position = | |
|
Sami
2015/02/18 12:01:53
nit: mouse_position
ssid
2015/02/18 17:57:34
Done.
| |
| 251 current_move_segment_start_position_ + GetPositionDeltaAtTime(timestamp); | |
| 252 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build( | |
| 253 blink::WebInputEvent::MouseUp, touch_position.x(), touch_position.y(), 0); | |
| 254 mouse_event.clickCount = 1; | |
|
Sami
2015/02/18 12:01:53
I think clickCount should only be set for MouseDow
ssid
2015/02/18 17:57:34
Done.
| |
| 255 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | |
| 256 target->DispatchInputEventToPlatform(mouse_event); | |
| 257 } | |
| 258 | |
| 259 void SyntheticSmoothMoveGesture::MoveMousePoint(SyntheticGestureTarget* target, | |
| 260 const gfx::Vector2dF& delta, | |
| 261 const base::TimeTicks& timestamp) { | |
| 262 gfx::PointF touch_position = current_move_segment_start_position_ + delta; | |
|
Sami
2015/02/18 12:01:53
nit: mouse_position
| |
| 263 DCHECK(gesture_source_type_ == SyntheticGestureParams::MOUSE_INPUT); | |
| 264 blink::WebMouseEvent mouse_event = SyntheticWebMouseEventBuilder::Build( | |
| 265 blink::WebInputEvent::MouseMove, touch_position.x(), touch_position.y(), | |
| 266 0); | |
| 267 mouse_event.clickCount = 1; | |
| 268 mouse_event.button = blink::WebMouseEvent::ButtonLeft; | |
| 269 mouse_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | |
| 270 target->DispatchInputEventToPlatform(mouse_event); | |
| 271 } | |
| 272 | |
| 273 void SyntheticSmoothMoveGesture::AddTouchSlopToFirstDistance( | |
| 274 SyntheticGestureTarget* target) { | |
| 275 DCHECK_GE(move_distances_.size(), 1ul); | |
| 276 gfx::Vector2d& first_move_distance = move_distances_[0]; | |
| 277 DCHECK_GT(first_move_distance.Length(), 0); | |
| 278 first_move_distance += CeilFromZero(ProjectScalarOntoVector( | |
| 279 target->GetTouchSlopInDips(), first_move_distance)); | |
| 280 } | |
| 281 | |
| 282 gfx::Vector2dF SyntheticSmoothMoveGesture::GetPositionDeltaAtTime( | |
| 222 const base::TimeTicks& timestamp) const { | 283 const base::TimeTicks& timestamp) const { |
| 223 // Make sure the final delta is correct. Using the computation below can lead | 284 // Make sure the final delta is correct. Using the computation below can lead |
| 224 // to issues with floating point precision. | 285 // to issues with floating point precision. |
| 225 if (FinishedCurrentScrollSegment(timestamp)) | 286 if (FinishedCurrentMoveSegment(timestamp)) |
| 226 return params_.distances[current_scroll_segment_]; | 287 return move_distances_[current_move_segment_]; |
| 227 | 288 |
| 228 float delta_length = | 289 float delta_length = |
| 229 params_.speed_in_pixels_s * | 290 speed_in_pixels_s_ * |
| 230 (timestamp - current_scroll_segment_start_time_).InSecondsF(); | 291 (timestamp - current_move_segment_start_time_).InSecondsF(); |
| 231 return ProjectScalarOntoVector(delta_length, | 292 return ProjectScalarOntoVector(delta_length, |
| 232 params_.distances[current_scroll_segment_]); | 293 move_distances_[current_move_segment_]); |
| 233 } | 294 } |
| 234 | 295 |
| 235 void SyntheticSmoothScrollGesture::ComputeNextScrollSegment() { | 296 void SyntheticSmoothMoveGesture::ComputeNextMoveSegment() { |
| 236 current_scroll_segment_++; | 297 current_move_segment_++; |
| 237 DCHECK_LT(current_scroll_segment_, | 298 DCHECK_LT(current_move_segment_, |
| 238 static_cast<int>(params_.distances.size())); | 299 static_cast<int>(move_distances_.size())); |
| 239 int64 total_duration_in_us = static_cast<int64>( | 300 int64 total_duration_in_us = static_cast<int64>( |
| 240 1e6 * (params_.distances[current_scroll_segment_].Length() / | 301 1e6 * |
| 241 params_.speed_in_pixels_s)); | 302 (move_distances_[current_move_segment_].Length() / speed_in_pixels_s_)); |
| 242 DCHECK_GT(total_duration_in_us, 0); | 303 DCHECK_GT(total_duration_in_us, 0); |
| 243 current_scroll_segment_start_time_ = current_scroll_segment_stop_time_; | 304 current_move_segment_start_time_ = current_move_segment_stop_time_; |
| 244 current_scroll_segment_stop_time_ = | 305 current_move_segment_stop_time_ = |
| 245 current_scroll_segment_start_time_ + | 306 current_move_segment_start_time_ + |
| 246 base::TimeDelta::FromMicroseconds(total_duration_in_us); | 307 base::TimeDelta::FromMicroseconds(total_duration_in_us); |
| 247 } | 308 } |
| 248 | 309 |
| 249 base::TimeTicks SyntheticSmoothScrollGesture::ClampTimestamp( | 310 base::TimeTicks SyntheticSmoothMoveGesture::ClampTimestamp( |
| 250 const base::TimeTicks& timestamp) const { | 311 const base::TimeTicks& timestamp) const { |
| 251 return std::min(timestamp, current_scroll_segment_stop_time_); | 312 return std::min(timestamp, current_move_segment_stop_time_); |
| 252 } | 313 } |
| 253 | 314 |
| 254 bool SyntheticSmoothScrollGesture::FinishedCurrentScrollSegment( | 315 bool SyntheticSmoothMoveGesture::FinishedCurrentMoveSegment( |
| 255 const base::TimeTicks& timestamp) const { | 316 const base::TimeTicks& timestamp) const { |
| 256 return timestamp >= current_scroll_segment_stop_time_; | 317 return timestamp >= current_move_segment_stop_time_; |
| 257 } | 318 } |
| 258 | 319 |
| 259 bool SyntheticSmoothScrollGesture::IsLastScrollSegment() const { | 320 bool SyntheticSmoothMoveGesture::IsLastMoveSegment() const { |
| 260 DCHECK_LT(current_scroll_segment_, | 321 DCHECK_LT(current_move_segment_, static_cast<int>(move_distances_.size())); |
| 261 static_cast<int>(params_.distances.size())); | 322 return current_move_segment_ == static_cast<int>(move_distances_.size()) - 1; |
| 262 return current_scroll_segment_ == | |
| 263 static_cast<int>(params_.distances.size()) - 1; | |
| 264 } | 323 } |
| 265 | 324 |
| 266 bool SyntheticSmoothScrollGesture::ScrollIsNoOp() const { | 325 bool SyntheticSmoothMoveGesture::MoveIsNoOp() const { |
| 267 return params_.distances.size() == 0 || params_.distances[0].IsZero(); | 326 return move_distances_.size() == 0 || move_distances_[0].IsZero(); |
| 268 } | 327 } |
| 269 | 328 |
| 270 } // namespace content | 329 } // namespace content |
| OLD | NEW |