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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 overscrollOffset = | 78 overscrollOffset = |
79 rootView->page()->frameHost().chromeClient().elasticOverscroll(); | 79 rootView->page()->frameHost().chromeClient().elasticOverscroll(); |
80 } | 80 } |
81 } | 81 } |
82 return FloatPoint( | 82 return FloatPoint( |
83 -offset.width() / scale + visualViewport.x() + overscrollOffset.width(), | 83 -offset.width() / scale + visualViewport.x() + overscrollOffset.width(), |
84 -offset.height() / scale + visualViewport.y() + | 84 -offset.height() / scale + visualViewport.y() + |
85 overscrollOffset.height()); | 85 overscrollOffset.height()); |
86 } | 86 } |
87 | 87 |
88 float scaleDeltaToWindow(const Widget* widget, float delta) { | |
89 return delta / frameScale(widget); | |
90 } | |
91 | |
92 // This method converts from the renderer's coordinate space into Blink's root | |
93 // frame coordinate space. It's somewhat unique in that it takes into account | |
94 // DevTools emulation, which applies a scale and offset in the root layer (see | |
95 // updateRootLayerTransform in WebViewImpl) as well as the overscroll effect on | |
96 // OSX. This is in addition to the visual viewport "pinch-zoom" transformation | |
97 // and is one of the few cases where the visual viewport is not equal to the | |
98 // renderer's coordinate-space. | |
99 FloatPoint convertHitPointToRootFrame(const Widget* widget, | |
100 FloatPoint pointInRendererViewport) { | |
101 float scale = 1; | |
102 IntSize offset; | |
103 IntPoint visualViewport; | |
104 FloatSize overscrollOffset; | |
105 if (widget) { | |
106 FrameView* rootView = toFrameView(widget->root()); | |
107 if (rootView) { | |
108 scale = rootView->inputEventsScaleFactor(); | |
109 offset = rootView->inputEventsOffsetForEmulation(); | |
110 visualViewport = flooredIntPoint(rootView->page() | |
111 ->frameHost() | |
112 .visualViewport() | |
113 .visibleRect() | |
114 .location()); | |
115 overscrollOffset = | |
116 rootView->page()->frameHost().chromeClient().elasticOverscroll(); | |
117 } | |
118 } | |
119 return FloatPoint((pointInRendererViewport.x() - offset.width()) / scale + | |
120 visualViewport.x() + overscrollOffset.width(), | |
121 (pointInRendererViewport.y() - offset.height()) / scale + | |
122 visualViewport.y() + overscrollOffset.height()); | |
123 } | |
124 | |
125 unsigned toPlatformModifierFrom(WebMouseEvent::Button button) { | |
126 if (button == WebMouseEvent::Button::NoButton) | |
127 return 0; | |
128 | |
129 unsigned webMouseButtonToPlatformModifier[] = { | |
130 PlatformEvent::LeftButtonDown, PlatformEvent::MiddleButtonDown, | |
131 PlatformEvent::RightButtonDown}; | |
132 | |
133 return webMouseButtonToPlatformModifier[static_cast<int>(button)]; | |
134 } | |
135 | |
136 FloatPoint convertAbsoluteLocationForLayoutObjectFloat( | 88 FloatPoint convertAbsoluteLocationForLayoutObjectFloat( |
137 const DoublePoint& location, | 89 const DoublePoint& location, |
138 const LayoutItem layoutItem) { | 90 const LayoutItem layoutItem) { |
139 return layoutItem.absoluteToLocal(FloatPoint(location), UseTransforms); | 91 return layoutItem.absoluteToLocal(FloatPoint(location), UseTransforms); |
140 } | 92 } |
141 | 93 |
142 IntPoint convertAbsoluteLocationForLayoutObjectInt( | 94 IntPoint convertAbsoluteLocationForLayoutObjectInt( |
143 const DoublePoint& location, | 95 const DoublePoint& location, |
144 const LayoutItem layoutItem) { | 96 const LayoutItem layoutItem) { |
145 return roundedIntPoint( | 97 return roundedIntPoint( |
(...skipping 19 matching lines...) Expand all Loading... |
165 webEvent.globalX = event.screenX(); | 117 webEvent.globalX = event.screenX(); |
166 webEvent.globalY = event.screenY(); | 118 webEvent.globalY = event.screenY(); |
167 webEvent.windowX = pointInRootFrame.x(); | 119 webEvent.windowX = pointInRootFrame.x(); |
168 webEvent.windowY = pointInRootFrame.y(); | 120 webEvent.windowY = pointInRootFrame.y(); |
169 IntPoint localPoint = convertAbsoluteLocationForLayoutObjectInt( | 121 IntPoint localPoint = convertAbsoluteLocationForLayoutObjectInt( |
170 event.absoluteLocation(), layoutItem); | 122 event.absoluteLocation(), layoutItem); |
171 webEvent.x = localPoint.x(); | 123 webEvent.x = localPoint.x(); |
172 webEvent.y = localPoint.y(); | 124 webEvent.y = localPoint.y(); |
173 } | 125 } |
174 | 126 |
| 127 unsigned toWebInputEventModifierFrom(WebMouseEvent::Button button) { |
| 128 if (button == WebMouseEvent::Button::NoButton) |
| 129 return 0; |
| 130 |
| 131 unsigned webMouseButtonToPlatformModifier[] = { |
| 132 WebInputEvent::LeftButtonDown, WebInputEvent::MiddleButtonDown, |
| 133 WebInputEvent::RightButtonDown}; |
| 134 |
| 135 return webMouseButtonToPlatformModifier[static_cast<int>(button)]; |
| 136 } |
| 137 |
175 } // namespace | 138 } // namespace |
176 | 139 |
177 // MakePlatformMouseEvent ----------------------------------------------------- | 140 WebMouseEvent TransformWebMouseEvent(Widget* widget, |
| 141 const WebMouseEvent& event) { |
| 142 WebMouseEvent result = event; |
178 | 143 |
179 // TODO(mustaq): Add tests for this. | 144 // TODO(dtapuska): Remove this translation. In the past blink has |
180 PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, | 145 // converted leaves into moves and not known about leaves. It should |
181 const WebMouseEvent& e) { | 146 // be educated about them. crbug.com/686196 |
182 // FIXME: Widget is always toplevel, unless it's a popup. We may be able | 147 if (event.type() == WebInputEvent::MouseEnter || |
183 // to get rid of this once we abstract popups into a WebKit API. | 148 event.type() == WebInputEvent::MouseLeave) { |
184 m_position = widget->convertFromRootFrame( | 149 result.setType(WebInputEvent::MouseMove); |
185 flooredIntPoint(convertHitPointToRootFrame(widget, IntPoint(e.x, e.y)))); | 150 } |
186 m_globalPosition = IntPoint(e.globalX, e.globalY); | |
187 m_movementDelta = IntPoint(scaleDeltaToWindow(widget, e.movementX), | |
188 scaleDeltaToWindow(widget, e.movementY)); | |
189 m_modifiers = e.modifiers(); | |
190 | 151 |
191 m_timestamp = TimeTicks::FromSeconds(e.timeStampSeconds()); | 152 // TODO(dtapuska): Perhaps the event should be constructed correctly? |
192 m_clickCount = e.clickCount; | 153 // crbug.com/686200 |
193 | 154 if (event.type() == WebInputEvent::MouseUp) { |
194 m_pointerProperties = static_cast<WebPointerProperties>(e); | 155 result.setModifiers(event.modifiers() & |
195 | 156 ~toWebInputEventModifierFrom(event.button)); |
196 switch (e.type()) { | |
197 case WebInputEvent::MouseMove: | |
198 case WebInputEvent::MouseEnter: // synthesize a move event | |
199 case WebInputEvent::MouseLeave: // synthesize a move event | |
200 m_type = PlatformEvent::MouseMoved; | |
201 break; | |
202 | |
203 case WebInputEvent::MouseDown: | |
204 m_type = PlatformEvent::MousePressed; | |
205 break; | |
206 | |
207 case WebInputEvent::MouseUp: | |
208 m_type = PlatformEvent::MouseReleased; | |
209 | |
210 // The MouseEvent spec requires that buttons indicates the state | |
211 // immediately after the event takes place. To ensure consistency | |
212 // between platforms here, we explicitly clear the button that is | |
213 // in the process of being released. | |
214 m_modifiers &= ~toPlatformModifierFrom(e.button); | |
215 break; | |
216 | |
217 default: | |
218 NOTREACHED(); | |
219 } | 157 } |
| 158 result.setFrameScale(frameScale(widget)); |
| 159 result.setFrameTranslate(frameTranslation(widget)); |
| 160 return result; |
220 } | 161 } |
221 | 162 |
222 WebMouseWheelEvent TransformWebMouseWheelEvent( | 163 WebMouseWheelEvent TransformWebMouseWheelEvent( |
223 Widget* widget, | 164 Widget* widget, |
224 const WebMouseWheelEvent& event) { | 165 const WebMouseWheelEvent& event) { |
225 WebMouseWheelEvent result = event; | 166 WebMouseWheelEvent result = event; |
226 result.setFrameScale(frameScale(widget)); | 167 result.setFrameScale(frameScale(widget)); |
227 result.setFrameTranslate(frameTranslation(widget)); | 168 result.setFrameTranslate(frameTranslation(widget)); |
228 return result; | 169 return result; |
229 } | 170 } |
(...skipping 21 matching lines...) Expand all Loading... |
251 | 192 |
252 WebTouchEvent TransformWebTouchEvent(Widget* widget, | 193 WebTouchEvent TransformWebTouchEvent(Widget* widget, |
253 const WebTouchEvent& event) { | 194 const WebTouchEvent& event) { |
254 return TransformWebTouchEvent(frameScale(widget), frameTranslation(widget), | 195 return TransformWebTouchEvent(frameScale(widget), frameTranslation(widget), |
255 event); | 196 event); |
256 } | 197 } |
257 | 198 |
258 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, | 199 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, |
259 const LayoutItem layoutItem, | 200 const LayoutItem layoutItem, |
260 const MouseEvent& event) { | 201 const MouseEvent& event) { |
| 202 if (event.nativeEvent()) { |
| 203 *static_cast<WebMouseEvent*>(this) = |
| 204 event.nativeEvent()->flattenTransform(); |
| 205 WebFloatPoint absoluteRootFrameLocation = positionInRootFrame(); |
| 206 IntPoint localPoint = roundedIntPoint( |
| 207 layoutItem.absoluteToLocal(absoluteRootFrameLocation, UseTransforms)); |
| 208 x = localPoint.x(); |
| 209 y = localPoint.y(); |
| 210 return; |
| 211 } |
| 212 |
| 213 // Code below here can be removed once OOPIF ships. |
| 214 // OOPIF will prevent synthetic events being dispatched into |
| 215 // other frames; but for now we allow the fallback to generate |
| 216 // WebMouseEvents from synthetic events. |
261 if (event.type() == EventTypeNames::mousemove) | 217 if (event.type() == EventTypeNames::mousemove) |
262 m_type = WebInputEvent::MouseMove; | 218 m_type = WebInputEvent::MouseMove; |
263 else if (event.type() == EventTypeNames::mouseout) | 219 else if (event.type() == EventTypeNames::mouseout) |
264 m_type = WebInputEvent::MouseLeave; | 220 m_type = WebInputEvent::MouseLeave; |
265 else if (event.type() == EventTypeNames::mouseover) | 221 else if (event.type() == EventTypeNames::mouseover) |
266 m_type = WebInputEvent::MouseEnter; | 222 m_type = WebInputEvent::MouseEnter; |
267 else if (event.type() == EventTypeNames::mousedown) | 223 else if (event.type() == EventTypeNames::mousedown) |
268 m_type = WebInputEvent::MouseDown; | 224 m_type = WebInputEvent::MouseDown; |
269 else if (event.type() == EventTypeNames::mouseup) | 225 else if (event.type() == EventTypeNames::mouseup) |
270 m_type = WebInputEvent::MouseUp; | 226 m_type = WebInputEvent::MouseUp; |
(...skipping 30 matching lines...) Expand all Loading... |
301 break; | 257 break; |
302 } | 258 } |
303 } else { | 259 } else { |
304 button = WebMouseEvent::Button::NoButton; | 260 button = WebMouseEvent::Button::NoButton; |
305 } | 261 } |
306 movementX = event.movementX(); | 262 movementX = event.movementX(); |
307 movementY = event.movementY(); | 263 movementY = event.movementY(); |
308 clickCount = event.detail(); | 264 clickCount = event.detail(); |
309 | 265 |
310 pointerType = WebPointerProperties::PointerType::Mouse; | 266 pointerType = WebPointerProperties::PointerType::Mouse; |
311 if (event.mouseEvent()) | |
312 pointerType = event.mouseEvent()->pointerProperties().pointerType; | |
313 } | 267 } |
314 | 268 |
315 // Generate a synthetic WebMouseEvent given a TouchEvent (eg. for emulating a | 269 // Generate a synthetic WebMouseEvent given a TouchEvent (eg. for emulating a |
316 // mouse with touch input for plugins that don't support touch input). | 270 // mouse with touch input for plugins that don't support touch input). |
317 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, | 271 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, |
318 const LayoutItem layoutItem, | 272 const LayoutItem layoutItem, |
319 const TouchEvent& event) { | 273 const TouchEvent& event) { |
320 if (!event.touches()) | 274 if (!event.touches()) |
321 return; | 275 return; |
322 if (event.touches()->length() != 1) { | 276 if (event.touches()->length() != 1) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 else if (event.type() == EventTypeNames::keypress) | 343 else if (event.type() == EventTypeNames::keypress) |
390 m_type = WebInputEvent::Char; | 344 m_type = WebInputEvent::Char; |
391 else | 345 else |
392 return; // Skip all other keyboard events. | 346 return; // Skip all other keyboard events. |
393 | 347 |
394 m_modifiers = event.modifiers(); | 348 m_modifiers = event.modifiers(); |
395 m_timeStampSeconds = event.platformTimeStamp().InSeconds(); | 349 m_timeStampSeconds = event.platformTimeStamp().InSeconds(); |
396 windowsKeyCode = event.keyCode(); | 350 windowsKeyCode = event.keyCode(); |
397 } | 351 } |
398 | 352 |
399 Vector<PlatformMouseEvent> createPlatformMouseEventVector( | 353 Vector<WebMouseEvent> TransformWebMouseEventVector( |
400 Widget* widget, | 354 Widget* widget, |
401 const std::vector<const WebInputEvent*>& coalescedEvents) { | 355 const std::vector<const WebInputEvent*>& coalescedEvents) { |
402 Vector<PlatformMouseEvent> result; | 356 Vector<WebMouseEvent> result; |
403 for (const auto& event : coalescedEvents) { | 357 for (const auto& event : coalescedEvents) { |
404 DCHECK(WebInputEvent::isMouseEventType(event->type())); | 358 DCHECK(WebInputEvent::isMouseEventType(event->type())); |
405 result.push_back(PlatformMouseEventBuilder( | 359 result.push_back(TransformWebMouseEvent( |
406 widget, static_cast<const WebMouseEvent&>(*event))); | 360 widget, static_cast<const WebMouseEvent&>(*event))); |
407 } | 361 } |
408 return result; | 362 return result; |
409 } | 363 } |
410 | 364 |
411 Vector<WebTouchEvent> TransformWebTouchEventVector( | 365 Vector<WebTouchEvent> TransformWebTouchEventVector( |
412 Widget* widget, | 366 Widget* widget, |
413 const std::vector<const WebInputEvent*>& coalescedEvents) { | 367 const std::vector<const WebInputEvent*>& coalescedEvents) { |
414 float scale = frameScale(widget); | 368 float scale = frameScale(widget); |
415 FloatPoint translation = frameTranslation(widget); | 369 FloatPoint translation = frameTranslation(widget); |
416 Vector<WebTouchEvent> result; | 370 Vector<WebTouchEvent> result; |
417 for (const auto& event : coalescedEvents) { | 371 for (const auto& event : coalescedEvents) { |
418 DCHECK(WebInputEvent::isTouchEventType(event->type())); | 372 DCHECK(WebInputEvent::isTouchEventType(event->type())); |
419 result.push_back(TransformWebTouchEvent( | 373 result.push_back(TransformWebTouchEvent( |
420 scale, translation, static_cast<const WebTouchEvent&>(*event))); | 374 scale, translation, static_cast<const WebTouchEvent&>(*event))); |
421 } | 375 } |
422 return result; | 376 return result; |
423 } | 377 } |
424 | 378 |
425 } // namespace blink | 379 } // namespace blink |
OLD | NEW |