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_move_gesture.h" | 5 #include "content/browser/renderer_host/input/synthetic_smooth_move_gesture.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/gfx/geometry/point_f.h" | 10 #include "ui/gfx/geometry/point_f.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 << "State SETUP invalid for synthetic scroll using touch input."; | 142 << "State SETUP invalid for synthetic scroll using touch input."; |
143 case DONE: | 143 case DONE: |
144 NOTREACHED() | 144 NOTREACHED() |
145 << "State DONE invalid for synthetic scroll using touch input."; | 145 << "State DONE invalid for synthetic scroll using touch input."; |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 void SyntheticSmoothMoveGesture::ForwardMouseWheelInputEvents( | 149 void SyntheticSmoothMoveGesture::ForwardMouseWheelInputEvents( |
150 const base::TimeTicks& timestamp, | 150 const base::TimeTicks& timestamp, |
151 SyntheticGestureTarget* target) { | 151 SyntheticGestureTarget* target) { |
| 152 blink::WebMouseWheelEvent::Phase phase = |
| 153 blink::WebMouseWheelEvent::kPhaseChanged; |
152 switch (state_) { | 154 switch (state_) { |
153 case STARTED: | 155 case STARTED: |
154 if (MoveIsNoOp()) { | 156 if (MoveIsNoOp()) { |
155 state_ = DONE; | 157 state_ = DONE; |
156 break; | 158 break; |
157 } | 159 } |
158 ComputeNextMoveSegment(); | 160 ComputeNextMoveSegment(); |
159 state_ = MOVING; | 161 state_ = MOVING; |
| 162 phase = blink::WebMouseWheelEvent::kPhaseBegan; |
160 // Fall through to forward the first event. | 163 // Fall through to forward the first event. |
161 case MOVING: { | 164 case MOVING: { |
162 // Even though WebMouseWheelEvents take floating point deltas, | 165 // Even though WebMouseWheelEvents take floating point deltas, |
163 // internally the scroll position is stored as an integer. We therefore | 166 // internally the scroll position is stored as an integer. We therefore |
164 // keep track of the discrete delta which is consistent with the | 167 // keep track of the discrete delta which is consistent with the |
165 // internal scrolling state. This ensures that when the gesture has | 168 // internal scrolling state. This ensures that when the gesture has |
166 // finished we've scrolled exactly the specified distance. | 169 // finished we've scrolled exactly the specified distance. |
167 base::TimeTicks event_timestamp = ClampTimestamp(timestamp); | 170 base::TimeTicks event_timestamp = ClampTimestamp(timestamp); |
168 gfx::Vector2dF current_move_segment_total_delta = | 171 gfx::Vector2dF current_move_segment_total_delta = |
169 GetPositionDeltaAtTime(event_timestamp); | 172 GetPositionDeltaAtTime(event_timestamp); |
170 gfx::Vector2d delta_discrete = | 173 gfx::Vector2d delta_discrete = |
171 FloorTowardZero(current_move_segment_total_delta - | 174 FloorTowardZero(current_move_segment_total_delta - |
172 current_move_segment_total_delta_discrete_); | 175 current_move_segment_total_delta_discrete_); |
173 ForwardMouseWheelEvent(target, delta_discrete, event_timestamp); | 176 ForwardMouseWheelEvent(target, delta_discrete, phase, event_timestamp); |
174 current_move_segment_total_delta_discrete_ += delta_discrete; | 177 current_move_segment_total_delta_discrete_ += delta_discrete; |
175 | 178 |
176 if (FinishedCurrentMoveSegment(event_timestamp)) { | 179 if (FinishedCurrentMoveSegment(event_timestamp)) { |
177 if (!IsLastMoveSegment()) { | 180 if (!IsLastMoveSegment()) { |
178 current_move_segment_total_delta_discrete_ = gfx::Vector2d(); | 181 current_move_segment_total_delta_discrete_ = gfx::Vector2d(); |
179 ComputeNextMoveSegment(); | 182 ComputeNextMoveSegment(); |
180 ForwardMouseWheelInputEvents(timestamp, target); | 183 ForwardMouseWheelInputEvents(timestamp, target); |
181 } else { | 184 } else { |
182 state_ = DONE; | 185 state_ = DONE; |
| 186 ForwardMouseWheelEvent(target, gfx::Vector2d(), |
| 187 blink::WebMouseWheelEvent::kPhaseEnded, |
| 188 event_timestamp); |
183 } | 189 } |
184 } | 190 } |
185 } break; | 191 } break; |
186 case SETUP: | 192 case SETUP: |
187 NOTREACHED() << "State SETUP invalid for synthetic scroll using mouse " | 193 NOTREACHED() << "State SETUP invalid for synthetic scroll using mouse " |
188 "wheel input."; | 194 "wheel input."; |
189 case STOPPING: | 195 case STOPPING: |
190 NOTREACHED() << "State STOPPING invalid for synthetic scroll using mouse " | 196 NOTREACHED() << "State STOPPING invalid for synthetic scroll using mouse " |
191 "wheel input."; | 197 "wheel input."; |
192 case DONE: | 198 case DONE: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 << "State SETUP invalid for synthetic drag using mouse input."; | 239 << "State SETUP invalid for synthetic drag using mouse input."; |
234 case DONE: | 240 case DONE: |
235 NOTREACHED() | 241 NOTREACHED() |
236 << "State DONE invalid for synthetic drag using mouse input."; | 242 << "State DONE invalid for synthetic drag using mouse input."; |
237 } | 243 } |
238 } | 244 } |
239 | 245 |
240 void SyntheticSmoothMoveGesture::ForwardMouseWheelEvent( | 246 void SyntheticSmoothMoveGesture::ForwardMouseWheelEvent( |
241 SyntheticGestureTarget* target, | 247 SyntheticGestureTarget* target, |
242 const gfx::Vector2dF& delta, | 248 const gfx::Vector2dF& delta, |
| 249 const blink::WebMouseWheelEvent::Phase phase, |
243 const base::TimeTicks& timestamp) const { | 250 const base::TimeTicks& timestamp) const { |
244 blink::WebMouseWheelEvent mouse_wheel_event = | 251 blink::WebMouseWheelEvent mouse_wheel_event = |
245 SyntheticWebMouseWheelEventBuilder::Build(0, 0, delta.x(), delta.y(), 0, | 252 SyntheticWebMouseWheelEventBuilder::Build(0, 0, delta.x(), delta.y(), 0, |
246 false); | 253 false); |
247 | 254 |
248 mouse_wheel_event.SetPositionInWidget( | 255 mouse_wheel_event.SetPositionInWidget( |
249 current_move_segment_start_position_.x(), | 256 current_move_segment_start_position_.x(), |
250 current_move_segment_start_position_.y()); | 257 current_move_segment_start_position_.y()); |
| 258 mouse_wheel_event.phase = phase; |
251 | 259 |
252 mouse_wheel_event.SetTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); | 260 mouse_wheel_event.SetTimeStampSeconds(ConvertTimestampToSeconds(timestamp)); |
253 | 261 |
254 target->DispatchInputEventToPlatform(mouse_wheel_event); | 262 target->DispatchInputEventToPlatform(mouse_wheel_event); |
255 } | 263 } |
256 | 264 |
257 void SyntheticSmoothMoveGesture::PressPoint(SyntheticGestureTarget* target, | 265 void SyntheticSmoothMoveGesture::PressPoint(SyntheticGestureTarget* target, |
258 const base::TimeTicks& timestamp) { | 266 const base::TimeTicks& timestamp) { |
259 DCHECK_EQ(current_move_segment_, 0); | 267 DCHECK_EQ(current_move_segment_, 0); |
260 synthetic_pointer_driver_->Press(current_move_segment_start_position_.x(), | 268 synthetic_pointer_driver_->Press(current_move_segment_start_position_.x(), |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 DCHECK_LT(current_move_segment_, static_cast<int>(params_.distances.size())); | 345 DCHECK_LT(current_move_segment_, static_cast<int>(params_.distances.size())); |
338 return current_move_segment_ == | 346 return current_move_segment_ == |
339 static_cast<int>(params_.distances.size()) - 1; | 347 static_cast<int>(params_.distances.size()) - 1; |
340 } | 348 } |
341 | 349 |
342 bool SyntheticSmoothMoveGesture::MoveIsNoOp() const { | 350 bool SyntheticSmoothMoveGesture::MoveIsNoOp() const { |
343 return params_.distances.size() == 0 || params_.distances[0].IsZero(); | 351 return params_.distances.size() == 0 || params_.distances[0].IsZero(); |
344 } | 352 } |
345 | 353 |
346 } // namespace content | 354 } // namespace content |
OLD | NEW |