OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 scale = rootView->inputEventsScaleFactor(); | 59 scale = rootView->inputEventsScaleFactor(); |
60 } | 60 } |
61 return delta / scale; | 61 return delta / scale; |
62 } | 62 } |
63 | 63 |
64 static FloatSize scaleSizeToWindow(const Widget* widget, FloatSize size) | 64 static FloatSize scaleSizeToWindow(const Widget* widget, FloatSize size) |
65 { | 65 { |
66 return FloatSize(scaleDeltaToWindow(widget, size.width()), scaleDeltaToWindo
w(widget, size.height())); | 66 return FloatSize(scaleDeltaToWindow(widget, size.width()), scaleDeltaToWindo
w(widget, size.height())); |
67 } | 67 } |
68 | 68 |
69 static FloatPoint convertHitPointToWindow(const Widget* widget, FloatPoint point
) | 69 // This method converts from the renderer's coordinate space into Blink's root f
rame coordinate space. |
| 70 // It's somewhat unique in that it takes into account DevTools emulation, which
applies a scale and offset |
| 71 // in the root layer (see updateRootLayerTransform in WebViewImpl) as well as th
e overscroll effect on OSX. |
| 72 // This is in addition to the visual viewport "pinch-zoom" transformation and is
one of the few cases where |
| 73 // the visual viewport is not equal to the renderer's coordinate-space. |
| 74 static FloatPoint convertHitPointToRootFrame(const Widget* widget, FloatPoint po
intInRendererViewport) |
70 { | 75 { |
71 float scale = 1; | 76 float scale = 1; |
72 IntSize offset; | 77 IntSize offset; |
73 IntPoint visualViewport; | 78 IntPoint visualViewport; |
74 FloatSize overscrollOffset; | 79 FloatSize overscrollOffset; |
75 if (widget) { | 80 if (widget) { |
76 FrameView* rootView = toFrameView(widget->root()); | 81 FrameView* rootView = toFrameView(widget->root()); |
77 if (rootView) { | 82 if (rootView) { |
78 scale = rootView->inputEventsScaleFactor(); | 83 scale = rootView->inputEventsScaleFactor(); |
79 offset = rootView->inputEventsOffsetForEmulation(); | 84 offset = rootView->inputEventsOffsetForEmulation(); |
80 visualViewport = flooredIntPoint(rootView->page()->frameHost().visua
lViewport().visibleRect().location()); | 85 visualViewport = flooredIntPoint(rootView->page()->frameHost().visua
lViewport().visibleRect().location()); |
81 overscrollOffset = rootView->page()->frameHost().chromeClient().elas
ticOverscroll(); | 86 overscrollOffset = rootView->page()->frameHost().chromeClient().elas
ticOverscroll(); |
82 } | 87 } |
83 } | 88 } |
84 return FloatPoint( | 89 return FloatPoint( |
85 (point.x() - offset.width()) / scale + visualViewport.x() + overscrollOf
fset.width(), | 90 (pointInRendererViewport.x() - offset.width()) / scale + visualViewport.
x() + overscrollOffset.width(), |
86 (point.y() - offset.height()) / scale + visualViewport.y() + overscrollO
ffset.height()); | 91 (pointInRendererViewport.y() - offset.height()) / scale + visualViewport
.y() + overscrollOffset.height()); |
87 } | 92 } |
88 | 93 |
89 static unsigned toPlatformModifierFrom(WebMouseEvent::Button button) | 94 static unsigned toPlatformModifierFrom(WebMouseEvent::Button button) |
90 { | 95 { |
91 if (button == WebMouseEvent::ButtonNone) | 96 if (button == WebMouseEvent::ButtonNone) |
92 return 0; | 97 return 0; |
93 | 98 |
94 unsigned webMouseButtonToPlatformModifier[] = { | 99 unsigned webMouseButtonToPlatformModifier[] = { |
95 PlatformEvent::LeftButtonDown, | 100 PlatformEvent::LeftButtonDown, |
96 PlatformEvent::MiddleButtonDown, | 101 PlatformEvent::MiddleButtonDown, |
97 PlatformEvent::RightButtonDown | 102 PlatformEvent::RightButtonDown |
98 }; | 103 }; |
99 | 104 |
100 return webMouseButtonToPlatformModifier[button]; | 105 return webMouseButtonToPlatformModifier[button]; |
101 } | 106 } |
102 | 107 |
103 // MakePlatformMouseEvent ----------------------------------------------------- | 108 // MakePlatformMouseEvent ----------------------------------------------------- |
104 | 109 |
105 // TODO(mustaq): Add tests for this. | 110 // TODO(mustaq): Add tests for this. |
106 PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMo
useEvent& e) | 111 PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMo
useEvent& e) |
107 { | 112 { |
108 // FIXME: Widget is always toplevel, unless it's a popup. We may be able | 113 // FIXME: Widget is always toplevel, unless it's a popup. We may be able |
109 // to get rid of this once we abstract popups into a WebKit API. | 114 // to get rid of this once we abstract popups into a WebKit API. |
110 m_position = widget->convertFromContainingWindow(flooredIntPoint(convertHitP
ointToWindow(widget, IntPoint(e.x, e.y)))); | 115 m_position = widget->convertFromRootFrame(flooredIntPoint(convertHitPointToR
ootFrame(widget, IntPoint(e.x, e.y)))); |
111 m_globalPosition = IntPoint(e.globalX, e.globalY); | 116 m_globalPosition = IntPoint(e.globalX, e.globalY); |
112 m_movementDelta = IntPoint(scaleDeltaToWindow(widget, e.movementX), scaleDel
taToWindow(widget, e.movementY)); | 117 m_movementDelta = IntPoint(scaleDeltaToWindow(widget, e.movementX), scaleDel
taToWindow(widget, e.movementY)); |
113 m_button = static_cast<MouseButton>(e.button); | 118 m_button = static_cast<MouseButton>(e.button); |
114 m_modifiers = e.modifiers; | 119 m_modifiers = e.modifiers; |
115 | 120 |
116 m_timestamp = e.timeStampSeconds; | 121 m_timestamp = e.timeStampSeconds; |
117 m_clickCount = e.clickCount; | 122 m_clickCount = e.clickCount; |
118 | 123 |
119 m_pointerProperties = static_cast<WebPointerProperties>(e); | 124 m_pointerProperties = static_cast<WebPointerProperties>(e); |
120 | 125 |
(...skipping 19 matching lines...) Expand all Loading... |
140 | 145 |
141 default: | 146 default: |
142 ASSERT_NOT_REACHED(); | 147 ASSERT_NOT_REACHED(); |
143 } | 148 } |
144 } | 149 } |
145 | 150 |
146 // PlatformWheelEventBuilder -------------------------------------------------- | 151 // PlatformWheelEventBuilder -------------------------------------------------- |
147 | 152 |
148 PlatformWheelEventBuilder::PlatformWheelEventBuilder(Widget* widget, const WebMo
useWheelEvent& e) | 153 PlatformWheelEventBuilder::PlatformWheelEventBuilder(Widget* widget, const WebMo
useWheelEvent& e) |
149 { | 154 { |
150 m_position = widget->convertFromContainingWindow(flooredIntPoint(convertHitP
ointToWindow(widget, FloatPoint(e.x, e.y)))); | 155 m_position = widget->convertFromRootFrame(flooredIntPoint(convertHitPointToR
ootFrame(widget, FloatPoint(e.x, e.y)))); |
151 m_globalPosition = IntPoint(e.globalX, e.globalY); | 156 m_globalPosition = IntPoint(e.globalX, e.globalY); |
152 m_deltaX = e.deltaX; | 157 m_deltaX = e.deltaX; |
153 m_deltaY = e.deltaY; | 158 m_deltaY = e.deltaY; |
154 m_wheelTicksX = e.wheelTicksX; | 159 m_wheelTicksX = e.wheelTicksX; |
155 m_wheelTicksY = e.wheelTicksY; | 160 m_wheelTicksY = e.wheelTicksY; |
156 m_granularity = e.scrollByPage ? | 161 m_granularity = e.scrollByPage ? |
157 ScrollByPageWheelEvent : ScrollByPixelWheelEvent; | 162 ScrollByPageWheelEvent : ScrollByPixelWheelEvent; |
158 | 163 |
159 m_type = PlatformEvent::Wheel; | 164 m_type = PlatformEvent::Wheel; |
160 | 165 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 case WebInputEvent::GesturePinchEnd: | 251 case WebInputEvent::GesturePinchEnd: |
247 m_type = PlatformEvent::GesturePinchEnd; | 252 m_type = PlatformEvent::GesturePinchEnd; |
248 break; | 253 break; |
249 case WebInputEvent::GesturePinchUpdate: | 254 case WebInputEvent::GesturePinchUpdate: |
250 m_type = PlatformEvent::GesturePinchUpdate; | 255 m_type = PlatformEvent::GesturePinchUpdate; |
251 m_data.m_pinchUpdate.m_scale = e.data.pinchUpdate.scale; | 256 m_data.m_pinchUpdate.m_scale = e.data.pinchUpdate.scale; |
252 break; | 257 break; |
253 default: | 258 default: |
254 ASSERT_NOT_REACHED(); | 259 ASSERT_NOT_REACHED(); |
255 } | 260 } |
256 m_position = widget->convertFromContainingWindow(flooredIntPoint(convertHitP
ointToWindow(widget, FloatPoint(e.x, e.y)))); | 261 m_position = widget->convertFromRootFrame(flooredIntPoint(convertHitPointToR
ootFrame(widget, FloatPoint(e.x, e.y)))); |
257 m_globalPosition = IntPoint(e.globalX, e.globalY); | 262 m_globalPosition = IntPoint(e.globalX, e.globalY); |
258 m_timestamp = e.timeStampSeconds; | 263 m_timestamp = e.timeStampSeconds; |
259 m_modifiers = e.modifiers; | 264 m_modifiers = e.modifiers; |
260 switch (e.sourceDevice) { | 265 switch (e.sourceDevice) { |
261 case WebGestureDeviceTouchpad: | 266 case WebGestureDeviceTouchpad: |
262 m_source = PlatformGestureSourceTouchpad; | 267 m_source = PlatformGestureSourceTouchpad; |
263 break; | 268 break; |
264 case WebGestureDeviceTouchscreen: | 269 case WebGestureDeviceTouchscreen: |
265 m_source = PlatformGestureSourceTouchscreen; | 270 m_source = PlatformGestureSourceTouchscreen; |
266 break; | 271 break; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 return WebTouchPoint::StateMoved; | 389 return WebTouchPoint::StateMoved; |
385 return WebTouchPoint::StateUndefined; | 390 return WebTouchPoint::StateUndefined; |
386 } | 391 } |
387 | 392 |
388 // TODO(mustaq): Add tests for this. | 393 // TODO(mustaq): Add tests for this. |
389 PlatformTouchPointBuilder::PlatformTouchPointBuilder(Widget* widget, const WebTo
uchPoint& point) | 394 PlatformTouchPointBuilder::PlatformTouchPointBuilder(Widget* widget, const WebTo
uchPoint& point) |
390 { | 395 { |
391 m_pointerProperties = point; | 396 m_pointerProperties = point; |
392 m_state = toPlatformTouchPointState(point.state); | 397 m_state = toPlatformTouchPointState(point.state); |
393 | 398 |
394 // This assumes convertFromContainingWindow does only translations, not scal
es. | 399 // This assumes convertFromRootFrame does only translations, not scales. |
395 FloatPoint floatPos = convertHitPointToWindow(widget, point.position); | 400 FloatPoint floatPos = convertHitPointToRootFrame(widget, point.position); |
396 IntPoint flooredPoint = flooredIntPoint(floatPos); | 401 IntPoint flooredPoint = flooredIntPoint(floatPos); |
397 m_pos = widget->convertFromContainingWindow(flooredPoint) + (floatPos - floo
redPoint); | 402 m_pos = widget->convertFromRootFrame(flooredPoint) + (floatPos - flooredPoin
t); |
398 | 403 |
399 m_screenPos = FloatPoint(point.screenPosition.x, point.screenPosition.y); | 404 m_screenPos = FloatPoint(point.screenPosition.x, point.screenPosition.y); |
400 m_radius = scaleSizeToWindow(widget, FloatSize(point.radiusX, point.radiusY)
); | 405 m_radius = scaleSizeToWindow(widget, FloatSize(point.radiusX, point.radiusY)
); |
401 m_rotationAngle = point.rotationAngle; | 406 m_rotationAngle = point.rotationAngle; |
402 } | 407 } |
403 | 408 |
404 PlatformTouchEventBuilder::PlatformTouchEventBuilder(Widget* widget, const WebTo
uchEvent& event) | 409 PlatformTouchEventBuilder::PlatformTouchEventBuilder(Widget* widget, const WebTo
uchEvent& event) |
405 { | 410 { |
406 m_type = toPlatformTouchEventType(event.type); | 411 m_type = toPlatformTouchEventType(event.type); |
407 m_modifiers = event.modifiers; | 412 m_modifiers = event.modifiers; |
(...skipping 17 matching lines...) Expand all Loading... |
425 } | 430 } |
426 | 431 |
427 // FIXME: Change |widget| to const Widget& after RemoteFrames get | 432 // FIXME: Change |widget| to const Widget& after RemoteFrames get |
428 // RemoteFrameViews. | 433 // RemoteFrameViews. |
429 static void updateWebMouseEventFromCoreMouseEvent(const MouseRelatedEvent& event
, const Widget* widget, const LayoutObject& layoutObject, WebMouseEvent& webEven
t) | 434 static void updateWebMouseEventFromCoreMouseEvent(const MouseRelatedEvent& event
, const Widget* widget, const LayoutObject& layoutObject, WebMouseEvent& webEven
t) |
430 { | 435 { |
431 webEvent.timeStampSeconds = convertDOMTimeStampToSeconds(event.createTime())
; | 436 webEvent.timeStampSeconds = convertDOMTimeStampToSeconds(event.createTime())
; |
432 webEvent.modifiers = event.modifiers(); | 437 webEvent.modifiers = event.modifiers(); |
433 | 438 |
434 FrameView* view = widget ? toFrameView(widget->parent()) : 0; | 439 FrameView* view = widget ? toFrameView(widget->parent()) : 0; |
435 // FIXME: If view == nullptr, pointInRootFrame will really be pointInRootCon
tent. | 440 // TODO(bokan): If view == nullptr, pointInRootFrame will really be pointInR
ootContent. |
436 IntPoint pointInRootFrame = IntPoint(event.absoluteLocation().x(), event.abs
oluteLocation().y()); | 441 IntPoint pointInRootFrame = IntPoint(event.absoluteLocation().x(), event.abs
oluteLocation().y()); |
437 if (view) | 442 if (view) |
438 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); | 443 pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); |
439 webEvent.globalX = event.screenX(); | 444 webEvent.globalX = event.screenX(); |
440 webEvent.globalY = event.screenY(); | 445 webEvent.globalY = event.screenY(); |
441 webEvent.windowX = pointInRootFrame.x(); | 446 webEvent.windowX = pointInRootFrame.x(); |
442 webEvent.windowY = pointInRootFrame.y(); | 447 webEvent.windowY = pointInRootFrame.y(); |
443 IntPoint localPoint = convertAbsoluteLocationForLayoutObject(event.absoluteL
ocation(), layoutObject); | 448 IntPoint localPoint = convertAbsoluteLocationForLayoutObject(event.absoluteL
ocation(), layoutObject); |
444 webEvent.x = localPoint.x(); | 449 webEvent.x = localPoint.x(); |
445 webEvent.y = localPoint.y(); | 450 webEvent.y = localPoint.y(); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 break; | 730 break; |
726 case GestureSourceTouchscreen: | 731 case GestureSourceTouchscreen: |
727 sourceDevice = WebGestureDeviceTouchscreen; | 732 sourceDevice = WebGestureDeviceTouchscreen; |
728 break; | 733 break; |
729 case GestureSourceUninitialized: | 734 case GestureSourceUninitialized: |
730 ASSERT_NOT_REACHED(); | 735 ASSERT_NOT_REACHED(); |
731 } | 736 } |
732 } | 737 } |
733 | 738 |
734 } // namespace blink | 739 } // namespace blink |
OLD | NEW |