| 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "ui/events/blink/blink_event_util.h" | 8 #include "ui/events/blink/blink_event_util.h" |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <cmath> | 13 #include <cmath> |
| 14 | 14 |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 #include "third_party/WebKit/public/web/WebInputEvent.h" | 17 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 18 #include "ui/events/base_event_utils.h" |
| 18 #include "ui/events/event_constants.h" | 19 #include "ui/events/event_constants.h" |
| 19 #include "ui/events/gesture_detection/gesture_event_data.h" | 20 #include "ui/events/gesture_detection/gesture_event_data.h" |
| 20 #include "ui/events/gesture_detection/motion_event.h" | 21 #include "ui/events/gesture_detection/motion_event.h" |
| 21 #include "ui/events/gesture_event_details.h" | 22 #include "ui/events/gesture_event_details.h" |
| 22 #include "ui/gfx/geometry/safe_integer_conversions.h" | 23 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 23 | 24 |
| 24 using blink::WebGestureEvent; | 25 using blink::WebGestureEvent; |
| 25 using blink::WebInputEvent; | 26 using blink::WebInputEvent; |
| 26 using blink::WebPointerProperties; | 27 using blink::WebPointerProperties; |
| 27 using blink::WebTouchEvent; | 28 using blink::WebTouchEvent; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 static_assert(static_cast<int>(MotionEvent::MAX_TOUCH_POINT_COUNT) == | 166 static_assert(static_cast<int>(MotionEvent::MAX_TOUCH_POINT_COUNT) == |
| 166 static_cast<int>(blink::WebTouchEvent::touchesLengthCap), | 167 static_cast<int>(blink::WebTouchEvent::touchesLengthCap), |
| 167 "inconsistent maximum number of active touch points"); | 168 "inconsistent maximum number of active touch points"); |
| 168 | 169 |
| 169 blink::WebTouchEvent result; | 170 blink::WebTouchEvent result; |
| 170 | 171 |
| 171 result.type = ToWebInputEventType(event.GetAction()); | 172 result.type = ToWebInputEventType(event.GetAction()); |
| 172 result.dispatchType = result.type == WebInputEvent::TouchCancel | 173 result.dispatchType = result.type == WebInputEvent::TouchCancel |
| 173 ? WebInputEvent::EventNonBlocking | 174 ? WebInputEvent::EventNonBlocking |
| 174 : WebInputEvent::Blocking; | 175 : WebInputEvent::Blocking; |
| 175 result.timeStampSeconds = | 176 result.timeStampSeconds = ui::EventTimeStampToSeconds(event.GetEventTime()); |
| 176 (event.GetEventTime() - base::TimeTicks()).InSecondsF(); | |
| 177 result.movedBeyondSlopRegion = moved_beyond_slop_region; | 177 result.movedBeyondSlopRegion = moved_beyond_slop_region; |
| 178 result.modifiers = EventFlagsToWebEventModifiers(event.GetFlags()); | 178 result.modifiers = EventFlagsToWebEventModifiers(event.GetFlags()); |
| 179 DCHECK_NE(event.GetUniqueEventId(), 0U); | 179 DCHECK_NE(event.GetUniqueEventId(), 0U); |
| 180 result.uniqueTouchEventId = event.GetUniqueEventId(); | 180 result.uniqueTouchEventId = event.GetUniqueEventId(); |
| 181 result.touchesLength = | 181 result.touchesLength = |
| 182 std::min(static_cast<unsigned>(event.GetPointerCount()), | 182 std::min(static_cast<unsigned>(event.GetPointerCount()), |
| 183 static_cast<unsigned>(WebTouchEvent::touchesLengthCap)); | 183 static_cast<unsigned>(WebTouchEvent::touchesLengthCap)); |
| 184 DCHECK_GT(result.touchesLength, 0U); | 184 DCHECK_GT(result.touchesLength, 0U); |
| 185 | 185 |
| 186 for (size_t i = 0; i < result.touchesLength; ++i) | 186 for (size_t i = 0; i < result.touchesLength; ++i) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 216 modifiers |= blink::WebInputEvent::RightButtonDown; | 216 modifiers |= blink::WebInputEvent::RightButtonDown; |
| 217 if (flags & EF_IS_REPEAT) | 217 if (flags & EF_IS_REPEAT) |
| 218 modifiers |= blink::WebInputEvent::IsAutoRepeat; | 218 modifiers |= blink::WebInputEvent::IsAutoRepeat; |
| 219 if (flags & EF_TOUCH_ACCESSIBILITY) | 219 if (flags & EF_TOUCH_ACCESSIBILITY) |
| 220 modifiers |= blink::WebInputEvent::IsTouchAccessibility; | 220 modifiers |= blink::WebInputEvent::IsTouchAccessibility; |
| 221 | 221 |
| 222 return modifiers; | 222 return modifiers; |
| 223 } | 223 } |
| 224 | 224 |
| 225 WebGestureEvent CreateWebGestureEvent(const GestureEventDetails& details, | 225 WebGestureEvent CreateWebGestureEvent(const GestureEventDetails& details, |
| 226 base::TimeDelta timestamp, | 226 base::TimeTicks timestamp, |
| 227 const gfx::PointF& location, | 227 const gfx::PointF& location, |
| 228 const gfx::PointF& raw_location, | 228 const gfx::PointF& raw_location, |
| 229 int flags) { | 229 int flags) { |
| 230 WebGestureEvent gesture; | 230 WebGestureEvent gesture; |
| 231 gesture.timeStampSeconds = timestamp.InSecondsF(); | 231 gesture.timeStampSeconds = ui::EventTimeStampToSeconds(timestamp); |
| 232 gesture.x = gfx::ToFlooredInt(location.x()); | 232 gesture.x = gfx::ToFlooredInt(location.x()); |
| 233 gesture.y = gfx::ToFlooredInt(location.y()); | 233 gesture.y = gfx::ToFlooredInt(location.y()); |
| 234 gesture.globalX = gfx::ToFlooredInt(raw_location.x()); | 234 gesture.globalX = gfx::ToFlooredInt(raw_location.x()); |
| 235 gesture.globalY = gfx::ToFlooredInt(raw_location.y()); | 235 gesture.globalY = gfx::ToFlooredInt(raw_location.y()); |
| 236 gesture.modifiers = EventFlagsToWebEventModifiers(flags); | 236 gesture.modifiers = EventFlagsToWebEventModifiers(flags); |
| 237 gesture.sourceDevice = blink::WebGestureDeviceTouchscreen; | 237 gesture.sourceDevice = blink::WebGestureDeviceTouchscreen; |
| 238 | 238 |
| 239 switch (details.type()) { | 239 switch (details.type()) { |
| 240 case ET_GESTURE_SHOW_PRESS: | 240 case ET_GESTURE_SHOW_PRESS: |
| 241 gesture.type = WebInputEvent::GestureShowPress; | 241 gesture.type = WebInputEvent::GestureShowPress; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 default: | 329 default: |
| 330 NOTREACHED() << "EventType provided wasn't a valid gesture event: " | 330 NOTREACHED() << "EventType provided wasn't a valid gesture event: " |
| 331 << details.type(); | 331 << details.type(); |
| 332 } | 332 } |
| 333 | 333 |
| 334 return gesture; | 334 return gesture; |
| 335 } | 335 } |
| 336 | 336 |
| 337 WebGestureEvent CreateWebGestureEventFromGestureEventData( | 337 WebGestureEvent CreateWebGestureEventFromGestureEventData( |
| 338 const GestureEventData& data) { | 338 const GestureEventData& data) { |
| 339 return CreateWebGestureEvent(data.details, data.time - base::TimeTicks(), | 339 return CreateWebGestureEvent(data.details, data.time, |
| 340 gfx::PointF(data.x, data.y), | 340 gfx::PointF(data.x, data.y), |
| 341 gfx::PointF(data.raw_x, data.raw_y), data.flags); | 341 gfx::PointF(data.raw_x, data.raw_y), data.flags); |
| 342 } | 342 } |
| 343 | 343 |
| 344 std::unique_ptr<blink::WebInputEvent> ScaleWebInputEvent( | 344 std::unique_ptr<blink::WebInputEvent> ScaleWebInputEvent( |
| 345 const blink::WebInputEvent& event, | 345 const blink::WebInputEvent& event, |
| 346 float scale) { | 346 float scale) { |
| 347 std::unique_ptr<blink::WebInputEvent> scaled_event; | 347 std::unique_ptr<blink::WebInputEvent> scaled_event; |
| 348 if (scale == 1.f) | 348 if (scale == 1.f) |
| 349 return scaled_event; | 349 return scaled_event; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 case MotionEvent::TOOL_TYPE_MOUSE: | 458 case MotionEvent::TOOL_TYPE_MOUSE: |
| 459 return WebPointerProperties::PointerType::Mouse; | 459 return WebPointerProperties::PointerType::Mouse; |
| 460 case MotionEvent::TOOL_TYPE_ERASER: | 460 case MotionEvent::TOOL_TYPE_ERASER: |
| 461 return WebPointerProperties::PointerType::Unknown; | 461 return WebPointerProperties::PointerType::Unknown; |
| 462 } | 462 } |
| 463 NOTREACHED() << "Invalid MotionEvent::ToolType = " << tool_type; | 463 NOTREACHED() << "Invalid MotionEvent::ToolType = " << tool_type; |
| 464 return WebPointerProperties::PointerType::Unknown; | 464 return WebPointerProperties::PointerType::Unknown; |
| 465 } | 465 } |
| 466 | 466 |
| 467 } // namespace ui | 467 } // namespace ui |
| OLD | NEW |