Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(712)

Side by Side Diff: ui/events/blink/blink_event_util.cc

Issue 1975533002: Change ui::Event::time_stamp from TimeDelta to TimeTicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/blink/blink_event_util.h ('k') | ui/events/blink/blink_event_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 237
238 switch (details.device_type()) { 238 switch (details.device_type()) {
239 case GestureDeviceType::DEVICE_TOUCHSCREEN: 239 case GestureDeviceType::DEVICE_TOUCHSCREEN:
240 gesture.sourceDevice = blink::WebGestureDeviceTouchscreen; 240 gesture.sourceDevice = blink::WebGestureDeviceTouchscreen;
241 break; 241 break;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 default: 341 default:
342 NOTREACHED() << "EventType provided wasn't a valid gesture event: " 342 NOTREACHED() << "EventType provided wasn't a valid gesture event: "
343 << details.type(); 343 << details.type();
344 } 344 }
345 345
346 return gesture; 346 return gesture;
347 } 347 }
348 348
349 WebGestureEvent CreateWebGestureEventFromGestureEventData( 349 WebGestureEvent CreateWebGestureEventFromGestureEventData(
350 const GestureEventData& data) { 350 const GestureEventData& data) {
351 return CreateWebGestureEvent(data.details, data.time - base::TimeTicks(), 351 return CreateWebGestureEvent(data.details, data.time,
352 gfx::PointF(data.x, data.y), 352 gfx::PointF(data.x, data.y),
353 gfx::PointF(data.raw_x, data.raw_y), data.flags); 353 gfx::PointF(data.raw_x, data.raw_y), data.flags);
354 } 354 }
355 355
356 std::unique_ptr<blink::WebInputEvent> ScaleWebInputEvent( 356 std::unique_ptr<blink::WebInputEvent> ScaleWebInputEvent(
357 const blink::WebInputEvent& event, 357 const blink::WebInputEvent& event,
358 float scale) { 358 float scale) {
359 std::unique_ptr<blink::WebInputEvent> scaled_event; 359 std::unique_ptr<blink::WebInputEvent> scaled_event;
360 if (scale == 1.f) 360 if (scale == 1.f)
361 return scaled_event; 361 return scaled_event;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 case MotionEvent::TOOL_TYPE_MOUSE: 470 case MotionEvent::TOOL_TYPE_MOUSE:
471 return WebPointerProperties::PointerType::Mouse; 471 return WebPointerProperties::PointerType::Mouse;
472 case MotionEvent::TOOL_TYPE_ERASER: 472 case MotionEvent::TOOL_TYPE_ERASER:
473 return WebPointerProperties::PointerType::Unknown; 473 return WebPointerProperties::PointerType::Unknown;
474 } 474 }
475 NOTREACHED() << "Invalid MotionEvent::ToolType = " << tool_type; 475 NOTREACHED() << "Invalid MotionEvent::ToolType = " << tool_type;
476 return WebPointerProperties::PointerType::Unknown; 476 return WebPointerProperties::PointerType::Unknown;
477 } 477 }
478 478
479 } // namespace ui 479 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/blink/blink_event_util.h ('k') | ui/events/blink/blink_event_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698