| 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_scroll_gesture.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/common/input/input_event.h" | |
| 9 #include "ui/events/latency_info.h" | |
| 10 #include "ui/gfx/point_f.h" | 8 #include "ui/gfx/point_f.h" |
| 11 | 9 |
| 12 namespace content { | 10 namespace content { |
| 13 namespace { | 11 namespace { |
| 14 | 12 |
| 15 gfx::Vector2d FloorTowardZero(const gfx::Vector2dF& vector) { | 13 gfx::Vector2d FloorTowardZero(const gfx::Vector2dF& vector) { |
| 16 int x = vector.x() > 0 ? floor(vector.x()) : ceil(vector.x()); | 14 int x = vector.x() > 0 ? floor(vector.x()) : ceil(vector.x()); |
| 17 int y = vector.y() > 0 ? floor(vector.y()) : ceil(vector.y()); | 15 int y = vector.y() > 0 ? floor(vector.y()) : ceil(vector.y()); |
| 18 return gfx::Vector2d(x, y); | 16 return gfx::Vector2d(x, y); |
| 19 } | 17 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 case DONE: | 145 case DONE: |
| 148 NOTREACHED() | 146 NOTREACHED() |
| 149 << "State DONE invalid for synthetic scroll using touch input."; | 147 << "State DONE invalid for synthetic scroll using touch input."; |
| 150 } | 148 } |
| 151 } | 149 } |
| 152 | 150 |
| 153 void SyntheticSmoothScrollGesture::ForwardTouchEvent( | 151 void SyntheticSmoothScrollGesture::ForwardTouchEvent( |
| 154 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { | 152 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { |
| 155 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 153 touch_event_.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 156 | 154 |
| 157 target->DispatchInputEventToPlatform( | 155 target->DispatchInputEventToPlatform(touch_event_); |
| 158 InputEvent(touch_event_, ui::LatencyInfo(), false)); | |
| 159 } | 156 } |
| 160 | 157 |
| 161 void SyntheticSmoothScrollGesture::ForwardMouseWheelEvent( | 158 void SyntheticSmoothScrollGesture::ForwardMouseWheelEvent( |
| 162 SyntheticGestureTarget* target, | 159 SyntheticGestureTarget* target, |
| 163 const gfx::Vector2dF& delta, | 160 const gfx::Vector2dF& delta, |
| 164 const base::TimeTicks& timestamp) const { | 161 const base::TimeTicks& timestamp) const { |
| 165 blink::WebMouseWheelEvent mouse_wheel_event = | 162 blink::WebMouseWheelEvent mouse_wheel_event = |
| 166 SyntheticWebMouseWheelEventBuilder::Build(delta.x(), delta.y(), 0, false); | 163 SyntheticWebMouseWheelEventBuilder::Build(delta.x(), delta.y(), 0, false); |
| 167 | 164 |
| 168 mouse_wheel_event.x = params_.anchor.x(); | 165 mouse_wheel_event.x = params_.anchor.x(); |
| 169 mouse_wheel_event.y = params_.anchor.y(); | 166 mouse_wheel_event.y = params_.anchor.y(); |
| 170 | 167 |
| 171 mouse_wheel_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); | 168 mouse_wheel_event.timeStampSeconds = ConvertTimestampToSeconds(timestamp); |
| 172 | 169 |
| 173 target->DispatchInputEventToPlatform( | 170 target->DispatchInputEventToPlatform(mouse_wheel_event); |
| 174 InputEvent(mouse_wheel_event, ui::LatencyInfo(), false)); | |
| 175 } | 171 } |
| 176 | 172 |
| 177 void SyntheticSmoothScrollGesture::PressTouchPoint( | 173 void SyntheticSmoothScrollGesture::PressTouchPoint( |
| 178 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { | 174 SyntheticGestureTarget* target, const base::TimeTicks& timestamp) { |
| 179 touch_event_.PressPoint(params_.anchor.x(), params_.anchor.y()); | 175 touch_event_.PressPoint(params_.anchor.x(), params_.anchor.y()); |
| 180 ForwardTouchEvent(target, timestamp); | 176 ForwardTouchEvent(target, timestamp); |
| 181 } | 177 } |
| 182 | 178 |
| 183 void SyntheticSmoothScrollGesture::MoveTouchPoint( | 179 void SyntheticSmoothScrollGesture::MoveTouchPoint( |
| 184 SyntheticGestureTarget* target, | 180 SyntheticGestureTarget* target, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 const base::TimeTicks& timestamp) const { | 233 const base::TimeTicks& timestamp) const { |
| 238 return std::min(timestamp, stop_scrolling_time_); | 234 return std::min(timestamp, stop_scrolling_time_); |
| 239 } | 235 } |
| 240 | 236 |
| 241 bool SyntheticSmoothScrollGesture::HasScrolledEntireDistance( | 237 bool SyntheticSmoothScrollGesture::HasScrolledEntireDistance( |
| 242 const base::TimeTicks& timestamp) const { | 238 const base::TimeTicks& timestamp) const { |
| 243 return timestamp >= stop_scrolling_time_; | 239 return timestamp >= stop_scrolling_time_; |
| 244 } | 240 } |
| 245 | 241 |
| 246 } // namespace content | 242 } // namespace content |
| OLD | NEW |