Chromium Code Reviews| 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. |
| 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? |
|
bokan
2017/01/27 16:57:17
Please file bugs for these and put the bug # in th
dtapuska
2017/01/27 21:00:00
Done.
| |
| 192 m_clickCount = e.clickCount; | 153 if (event.type() == WebInputEvent::MouseUp) { |
| 193 | 154 result.setModifiers(event.modifiers() & |
| 194 m_pointerProperties = static_cast<WebPointerProperties>(e); | 155 ~toWebInputEventModifierFrom(event.button)); |
| 195 | |
| 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 } | 156 } |
| 157 result.setFrameScale(frameScale(widget)); | |
| 158 result.setFrameTranslate(frameTranslation(widget)); | |
| 159 return result; | |
| 220 } | 160 } |
| 221 | 161 |
| 222 WebMouseWheelEvent TransformWebMouseWheelEvent( | 162 WebMouseWheelEvent TransformWebMouseWheelEvent( |
| 223 Widget* widget, | 163 Widget* widget, |
| 224 const WebMouseWheelEvent& event) { | 164 const WebMouseWheelEvent& event) { |
| 225 WebMouseWheelEvent result = event; | 165 WebMouseWheelEvent result = event; |
| 226 result.setFrameScale(frameScale(widget)); | 166 result.setFrameScale(frameScale(widget)); |
| 227 result.setFrameTranslate(frameTranslation(widget)); | 167 result.setFrameTranslate(frameTranslation(widget)); |
| 228 return result; | 168 return result; |
| 229 } | 169 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 251 | 191 |
| 252 WebTouchEvent TransformWebTouchEvent(Widget* widget, | 192 WebTouchEvent TransformWebTouchEvent(Widget* widget, |
| 253 const WebTouchEvent& event) { | 193 const WebTouchEvent& event) { |
| 254 return TransformWebTouchEvent(frameScale(widget), frameTranslation(widget), | 194 return TransformWebTouchEvent(frameScale(widget), frameTranslation(widget), |
| 255 event); | 195 event); |
| 256 } | 196 } |
| 257 | 197 |
| 258 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, | 198 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, |
| 259 const LayoutItem layoutItem, | 199 const LayoutItem layoutItem, |
| 260 const MouseEvent& event) { | 200 const MouseEvent& event) { |
| 201 if (event.nativeEvent()) { | |
| 202 // This is the slimplified code path once we OOPIF ships | |
|
bokan
2017/01/27 16:57:17
nit: "we OOPIF" -> "OOPIF"
I think this comment s
dtapuska
2017/01/27 21:00:00
Done.
| |
| 203 // as that will break sending synthetic events to OOPIFs and | |
| 204 // all events should have a native event attached. | |
| 205 *static_cast<WebMouseEvent*>(this) = | |
| 206 event.nativeEvent()->flattenTransform(); | |
| 207 WebFloatPoint absoluteRootFrameLocation = | |
| 208 event.nativeEvent()->positionInRootFrame(); | |
| 209 IntPoint localPoint = roundedIntPoint( | |
| 210 layoutItem.absoluteToLocal(absoluteRootFrameLocation, UseTransforms)); | |
| 211 x = localPoint.x(); | |
| 212 y = localPoint.y(); | |
| 213 return; | |
| 214 } | |
| 215 | |
| 261 if (event.type() == EventTypeNames::mousemove) | 216 if (event.type() == EventTypeNames::mousemove) |
| 262 m_type = WebInputEvent::MouseMove; | 217 m_type = WebInputEvent::MouseMove; |
| 263 else if (event.type() == EventTypeNames::mouseout) | 218 else if (event.type() == EventTypeNames::mouseout) |
| 264 m_type = WebInputEvent::MouseLeave; | 219 m_type = WebInputEvent::MouseLeave; |
| 265 else if (event.type() == EventTypeNames::mouseover) | 220 else if (event.type() == EventTypeNames::mouseover) |
| 266 m_type = WebInputEvent::MouseEnter; | 221 m_type = WebInputEvent::MouseEnter; |
| 267 else if (event.type() == EventTypeNames::mousedown) | 222 else if (event.type() == EventTypeNames::mousedown) |
| 268 m_type = WebInputEvent::MouseDown; | 223 m_type = WebInputEvent::MouseDown; |
| 269 else if (event.type() == EventTypeNames::mouseup) | 224 else if (event.type() == EventTypeNames::mouseup) |
| 270 m_type = WebInputEvent::MouseUp; | 225 m_type = WebInputEvent::MouseUp; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 301 break; | 256 break; |
| 302 } | 257 } |
| 303 } else { | 258 } else { |
| 304 button = WebMouseEvent::Button::NoButton; | 259 button = WebMouseEvent::Button::NoButton; |
| 305 } | 260 } |
| 306 movementX = event.movementX(); | 261 movementX = event.movementX(); |
| 307 movementY = event.movementY(); | 262 movementY = event.movementY(); |
| 308 clickCount = event.detail(); | 263 clickCount = event.detail(); |
| 309 | 264 |
| 310 pointerType = WebPointerProperties::PointerType::Mouse; | 265 pointerType = WebPointerProperties::PointerType::Mouse; |
| 311 if (event.mouseEvent()) | |
| 312 pointerType = event.mouseEvent()->pointerProperties().pointerType; | |
| 313 } | 266 } |
| 314 | 267 |
| 315 // Generate a synthetic WebMouseEvent given a TouchEvent (eg. for emulating a | 268 // Generate a synthetic WebMouseEvent given a TouchEvent (eg. for emulating a |
| 316 // mouse with touch input for plugins that don't support touch input). | 269 // mouse with touch input for plugins that don't support touch input). |
| 317 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, | 270 WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, |
| 318 const LayoutItem layoutItem, | 271 const LayoutItem layoutItem, |
| 319 const TouchEvent& event) { | 272 const TouchEvent& event) { |
| 320 if (!event.touches()) | 273 if (!event.touches()) |
| 321 return; | 274 return; |
| 322 if (event.touches()->length() != 1) { | 275 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) | 342 else if (event.type() == EventTypeNames::keypress) |
| 390 m_type = WebInputEvent::Char; | 343 m_type = WebInputEvent::Char; |
| 391 else | 344 else |
| 392 return; // Skip all other keyboard events. | 345 return; // Skip all other keyboard events. |
| 393 | 346 |
| 394 m_modifiers = event.modifiers(); | 347 m_modifiers = event.modifiers(); |
| 395 m_timeStampSeconds = event.platformTimeStamp().InSeconds(); | 348 m_timeStampSeconds = event.platformTimeStamp().InSeconds(); |
| 396 windowsKeyCode = event.keyCode(); | 349 windowsKeyCode = event.keyCode(); |
| 397 } | 350 } |
| 398 | 351 |
| 399 Vector<PlatformMouseEvent> createPlatformMouseEventVector( | 352 Vector<WebMouseEvent> TransformWebMouseEventVector( |
| 400 Widget* widget, | 353 Widget* widget, |
| 401 const std::vector<const WebInputEvent*>& coalescedEvents) { | 354 const std::vector<const WebInputEvent*>& coalescedEvents) { |
| 402 Vector<PlatformMouseEvent> result; | 355 Vector<WebMouseEvent> result; |
| 403 for (const auto& event : coalescedEvents) { | 356 for (const auto& event : coalescedEvents) { |
| 404 DCHECK(WebInputEvent::isMouseEventType(event->type())); | 357 DCHECK(WebInputEvent::isMouseEventType(event->type())); |
| 405 result.push_back(PlatformMouseEventBuilder( | 358 result.push_back(TransformWebMouseEvent( |
| 406 widget, static_cast<const WebMouseEvent&>(*event))); | 359 widget, static_cast<const WebMouseEvent&>(*event))); |
| 407 } | 360 } |
| 408 return result; | 361 return result; |
| 409 } | 362 } |
| 410 | 363 |
| 411 Vector<WebTouchEvent> TransformWebTouchEventVector( | 364 Vector<WebTouchEvent> TransformWebTouchEventVector( |
| 412 Widget* widget, | 365 Widget* widget, |
| 413 const std::vector<const WebInputEvent*>& coalescedEvents) { | 366 const std::vector<const WebInputEvent*>& coalescedEvents) { |
| 414 float scale = frameScale(widget); | 367 float scale = frameScale(widget); |
| 415 FloatPoint translation = frameTranslation(widget); | 368 FloatPoint translation = frameTranslation(widget); |
| 416 Vector<WebTouchEvent> result; | 369 Vector<WebTouchEvent> result; |
| 417 for (const auto& event : coalescedEvents) { | 370 for (const auto& event : coalescedEvents) { |
| 418 DCHECK(WebInputEvent::isTouchEventType(event->type())); | 371 DCHECK(WebInputEvent::isTouchEventType(event->type())); |
| 419 result.push_back(TransformWebTouchEvent( | 372 result.push_back(TransformWebTouchEvent( |
| 420 scale, translation, static_cast<const WebTouchEvent&>(*event))); | 373 scale, translation, static_cast<const WebTouchEvent&>(*event))); |
| 421 } | 374 } |
| 422 return result; | 375 return result; |
| 423 } | 376 } |
| 424 | 377 |
| 425 } // namespace blink | 378 } // namespace blink |
| OLD | NEW |