| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #include "core/dom/Touch.h" | 34 #include "core/dom/Touch.h" |
| 35 #include "core/dom/TouchList.h" | 35 #include "core/dom/TouchList.h" |
| 36 #include "core/events/GestureEvent.h" | 36 #include "core/events/GestureEvent.h" |
| 37 #include "core/events/KeyboardEvent.h" | 37 #include "core/events/KeyboardEvent.h" |
| 38 #include "core/events/MouseEvent.h" | 38 #include "core/events/MouseEvent.h" |
| 39 #include "core/events/TouchEvent.h" | 39 #include "core/events/TouchEvent.h" |
| 40 #include "core/events/WheelEvent.h" | 40 #include "core/events/WheelEvent.h" |
| 41 #include "core/frame/FrameHost.h" | 41 #include "core/frame/FrameHost.h" |
| 42 #include "core/frame/FrameView.h" | 42 #include "core/frame/FrameView.h" |
| 43 #include "core/frame/PinchViewport.h" | |
| 44 #include "core/page/Page.h" | 43 #include "core/page/Page.h" |
| 45 #include "core/rendering/RenderObject.h" | 44 #include "core/rendering/RenderObject.h" |
| 46 #include "platform/KeyboardCodes.h" | 45 #include "platform/KeyboardCodes.h" |
| 47 #include "platform/Widget.h" | 46 #include "platform/Widget.h" |
| 48 | 47 |
| 49 namespace blink { | 48 namespace blink { |
| 50 | 49 |
| 51 static const double millisPerSecond = 1000.0; | 50 static const double millisPerSecond = 1000.0; |
| 52 | 51 |
| 53 static float widgetInputEventsScaleFactor(const Widget* widget) | 52 static float widgetInputEventsScaleFactor(const Widget* widget) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 66 { | 65 { |
| 67 if (!widget) | 66 if (!widget) |
| 68 return IntSize(); | 67 return IntSize(); |
| 69 FrameView* rootView = toFrameView(widget->root()); | 68 FrameView* rootView = toFrameView(widget->root()); |
| 70 if (!rootView) | 69 if (!rootView) |
| 71 return IntSize(); | 70 return IntSize(); |
| 72 | 71 |
| 73 return rootView->inputEventsOffsetForEmulation(); | 72 return rootView->inputEventsOffsetForEmulation(); |
| 74 } | 73 } |
| 75 | 74 |
| 76 static IntPoint pinchViewportOffset(const Widget* widget) | |
| 77 { | |
| 78 // Event position needs to be adjusted by the pinch viewport's offset within
the | |
| 79 // main frame before being passed into the widget's convertFromContainingWin
dow. | |
| 80 FrameView* rootView = toFrameView(widget->root()); | |
| 81 if (!rootView) | |
| 82 return IntPoint(); | |
| 83 | |
| 84 return flooredIntPoint(rootView->page()->frameHost().pinchViewport().visible
Rect().location()); | |
| 85 } | |
| 86 | |
| 87 // MakePlatformMouseEvent ----------------------------------------------------- | 75 // MakePlatformMouseEvent ----------------------------------------------------- |
| 88 | 76 |
| 89 PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMo
useEvent& e) | 77 PlatformMouseEventBuilder::PlatformMouseEventBuilder(Widget* widget, const WebMo
useEvent& e) |
| 90 { | 78 { |
| 91 float scale = widgetInputEventsScaleFactor(widget); | 79 float scale = widgetInputEventsScaleFactor(widget); |
| 92 IntSize offset = widgetInputEventsOffset(widget); | 80 IntSize offset = widgetInputEventsOffset(widget); |
| 93 IntPoint pinchViewport = pinchViewportOffset(widget); | |
| 94 | 81 |
| 95 // FIXME: Widget is always toplevel, unless it's a popup. We may be able | 82 // FIXME: Widget is always toplevel, unless it's a popup. We may be able |
| 96 // to get rid of this once we abstract popups into a WebKit API. | 83 // to get rid of this once we abstract popups into a WebKit API. |
| 97 m_position = widget->convertFromContainingWindow( | 84 m_position = widget->convertFromContainingWindow( |
| 98 IntPoint((e.x - offset.width()) / scale + pinchViewport.x(), (e.y - offs
et.height()) / scale + pinchViewport.y())); | 85 IntPoint((e.x - offset.width()) / scale, (e.y - offset.height()) / scale
)); |
| 99 m_globalPosition = IntPoint(e.globalX, e.globalY); | 86 m_globalPosition = IntPoint(e.globalX, e.globalY); |
| 100 m_movementDelta = IntPoint(e.movementX / scale, e.movementY / scale); | 87 m_movementDelta = IntPoint(e.movementX / scale, e.movementY / scale); |
| 101 m_button = static_cast<MouseButton>(e.button); | 88 m_button = static_cast<MouseButton>(e.button); |
| 102 | 89 |
| 103 m_modifiers = 0; | 90 m_modifiers = 0; |
| 104 if (e.modifiers & WebInputEvent::ShiftKey) | 91 if (e.modifiers & WebInputEvent::ShiftKey) |
| 105 m_modifiers |= PlatformEvent::ShiftKey; | 92 m_modifiers |= PlatformEvent::ShiftKey; |
| 106 if (e.modifiers & WebInputEvent::ControlKey) | 93 if (e.modifiers & WebInputEvent::ControlKey) |
| 107 m_modifiers |= PlatformEvent::CtrlKey; | 94 m_modifiers |= PlatformEvent::CtrlKey; |
| 108 if (e.modifiers & WebInputEvent::AltKey) | 95 if (e.modifiers & WebInputEvent::AltKey) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 132 ASSERT_NOT_REACHED(); | 119 ASSERT_NOT_REACHED(); |
| 133 } | 120 } |
| 134 } | 121 } |
| 135 | 122 |
| 136 // PlatformWheelEventBuilder -------------------------------------------------- | 123 // PlatformWheelEventBuilder -------------------------------------------------- |
| 137 | 124 |
| 138 PlatformWheelEventBuilder::PlatformWheelEventBuilder(Widget* widget, const WebMo
useWheelEvent& e) | 125 PlatformWheelEventBuilder::PlatformWheelEventBuilder(Widget* widget, const WebMo
useWheelEvent& e) |
| 139 { | 126 { |
| 140 float scale = widgetInputEventsScaleFactor(widget); | 127 float scale = widgetInputEventsScaleFactor(widget); |
| 141 IntSize offset = widgetInputEventsOffset(widget); | 128 IntSize offset = widgetInputEventsOffset(widget); |
| 142 IntPoint pinchViewport = pinchViewportOffset(widget); | |
| 143 | 129 |
| 144 m_position = widget->convertFromContainingWindow( | 130 m_position = widget->convertFromContainingWindow( |
| 145 IntPoint((e.x - offset.width()) / scale + pinchViewport.x(), (e.y - offs
et.height()) / scale + pinchViewport.y())); | 131 IntPoint((e.x - offset.width()) / scale, (e.y - offset.height()) / scale
)); |
| 146 m_globalPosition = IntPoint(e.globalX, e.globalY); | 132 m_globalPosition = IntPoint(e.globalX, e.globalY); |
| 147 m_deltaX = e.deltaX; | 133 m_deltaX = e.deltaX; |
| 148 m_deltaY = e.deltaY; | 134 m_deltaY = e.deltaY; |
| 149 m_wheelTicksX = e.wheelTicksX; | 135 m_wheelTicksX = e.wheelTicksX; |
| 150 m_wheelTicksY = e.wheelTicksY; | 136 m_wheelTicksY = e.wheelTicksY; |
| 151 m_granularity = e.scrollByPage ? | 137 m_granularity = e.scrollByPage ? |
| 152 ScrollByPageWheelEvent : ScrollByPixelWheelEvent; | 138 ScrollByPageWheelEvent : ScrollByPixelWheelEvent; |
| 153 | 139 |
| 154 m_type = PlatformEvent::Wheel; | 140 m_type = PlatformEvent::Wheel; |
| 155 | 141 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 175 m_canRubberbandRight = e.canRubberbandRight; | 161 m_canRubberbandRight = e.canRubberbandRight; |
| 176 #endif | 162 #endif |
| 177 } | 163 } |
| 178 | 164 |
| 179 // PlatformGestureEventBuilder -------------------------------------------------
- | 165 // PlatformGestureEventBuilder -------------------------------------------------
- |
| 180 | 166 |
| 181 PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W
ebGestureEvent& e) | 167 PlatformGestureEventBuilder::PlatformGestureEventBuilder(Widget* widget, const W
ebGestureEvent& e) |
| 182 { | 168 { |
| 183 float scale = widgetInputEventsScaleFactor(widget); | 169 float scale = widgetInputEventsScaleFactor(widget); |
| 184 IntSize offset = widgetInputEventsOffset(widget); | 170 IntSize offset = widgetInputEventsOffset(widget); |
| 185 IntPoint pinchViewport = pinchViewportOffset(widget); | |
| 186 | 171 |
| 187 switch (e.type) { | 172 switch (e.type) { |
| 188 case WebInputEvent::GestureScrollBegin: | 173 case WebInputEvent::GestureScrollBegin: |
| 189 m_type = PlatformEvent::GestureScrollBegin; | 174 m_type = PlatformEvent::GestureScrollBegin; |
| 190 break; | 175 break; |
| 191 case WebInputEvent::GestureScrollEnd: | 176 case WebInputEvent::GestureScrollEnd: |
| 192 m_type = PlatformEvent::GestureScrollEnd; | 177 m_type = PlatformEvent::GestureScrollEnd; |
| 193 break; | 178 break; |
| 194 case WebInputEvent::GestureFlingStart: | 179 case WebInputEvent::GestureFlingStart: |
| 195 m_type = PlatformEvent::GestureFlingStart; | 180 m_type = PlatformEvent::GestureFlingStart; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 m_type = PlatformEvent::GesturePinchEnd; | 239 m_type = PlatformEvent::GesturePinchEnd; |
| 255 break; | 240 break; |
| 256 case WebInputEvent::GesturePinchUpdate: | 241 case WebInputEvent::GesturePinchUpdate: |
| 257 m_type = PlatformEvent::GesturePinchUpdate; | 242 m_type = PlatformEvent::GesturePinchUpdate; |
| 258 m_data.m_pinchUpdate.m_scale = e.data.pinchUpdate.scale; | 243 m_data.m_pinchUpdate.m_scale = e.data.pinchUpdate.scale; |
| 259 break; | 244 break; |
| 260 default: | 245 default: |
| 261 ASSERT_NOT_REACHED(); | 246 ASSERT_NOT_REACHED(); |
| 262 } | 247 } |
| 263 m_position = widget->convertFromContainingWindow( | 248 m_position = widget->convertFromContainingWindow( |
| 264 IntPoint((e.x - offset.width()) / scale + pinchViewport.x(), (e.y - offs
et.height()) / scale + pinchViewport.y())); | 249 IntPoint((e.x - offset.width()) / scale, (e.y - offset.height()) / scale
)); |
| 265 m_globalPosition = IntPoint(e.globalX, e.globalY); | 250 m_globalPosition = IntPoint(e.globalX, e.globalY); |
| 266 m_timestamp = e.timeStampSeconds; | 251 m_timestamp = e.timeStampSeconds; |
| 267 | 252 |
| 268 m_modifiers = 0; | 253 m_modifiers = 0; |
| 269 if (e.modifiers & WebInputEvent::ShiftKey) | 254 if (e.modifiers & WebInputEvent::ShiftKey) |
| 270 m_modifiers |= PlatformEvent::ShiftKey; | 255 m_modifiers |= PlatformEvent::ShiftKey; |
| 271 if (e.modifiers & WebInputEvent::ControlKey) | 256 if (e.modifiers & WebInputEvent::ControlKey) |
| 272 m_modifiers |= PlatformEvent::CtrlKey; | 257 m_modifiers |= PlatformEvent::CtrlKey; |
| 273 if (e.modifiers & WebInputEvent::AltKey) | 258 if (e.modifiers & WebInputEvent::AltKey) |
| 274 m_modifiers |= PlatformEvent::AltKey; | 259 m_modifiers |= PlatformEvent::AltKey; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 return WebTouchPoint::StatePressed; | 401 return WebTouchPoint::StatePressed; |
| 417 if (type == EventTypeNames::touchmove) | 402 if (type == EventTypeNames::touchmove) |
| 418 return WebTouchPoint::StateMoved; | 403 return WebTouchPoint::StateMoved; |
| 419 return WebTouchPoint::StateUndefined; | 404 return WebTouchPoint::StateUndefined; |
| 420 } | 405 } |
| 421 | 406 |
| 422 PlatformTouchPointBuilder::PlatformTouchPointBuilder(Widget* widget, const WebTo
uchPoint& point) | 407 PlatformTouchPointBuilder::PlatformTouchPointBuilder(Widget* widget, const WebTo
uchPoint& point) |
| 423 { | 408 { |
| 424 float scale = 1.0f / widgetInputEventsScaleFactor(widget); | 409 float scale = 1.0f / widgetInputEventsScaleFactor(widget); |
| 425 IntSize offset = widgetInputEventsOffset(widget); | 410 IntSize offset = widgetInputEventsOffset(widget); |
| 426 IntPoint pinchViewport = pinchViewportOffset(widget); | |
| 427 m_id = point.id; | 411 m_id = point.id; |
| 428 m_state = toPlatformTouchPointState(point.state); | 412 m_state = toPlatformTouchPointState(point.state); |
| 429 FloatPoint pos = (point.position - offset).scaledBy(scale); | 413 FloatPoint pos = (point.position - offset).scaledBy(scale); |
| 430 pos.moveBy(pinchViewport); | |
| 431 IntPoint flooredPoint = flooredIntPoint(pos); | 414 IntPoint flooredPoint = flooredIntPoint(pos); |
| 432 // This assumes convertFromContainingWindow does only translations, not scal
es. | 415 // This assumes convertFromContainingWindow does only translations, not scal
es. |
| 433 m_pos = widget->convertFromContainingWindow(flooredPoint) + (pos - flooredPo
int); | 416 m_pos = widget->convertFromContainingWindow(flooredPoint) + (pos - flooredPo
int); |
| 434 m_screenPos = FloatPoint(point.screenPosition.x, point.screenPosition.y); | 417 m_screenPos = FloatPoint(point.screenPosition.x, point.screenPosition.y); |
| 435 m_radius = FloatSize(point.radiusX, point.radiusY).scaledBy(scale); | 418 m_radius = FloatSize(point.radiusX, point.radiusY).scaledBy(scale); |
| 436 m_rotationAngle = point.rotationAngle; | 419 m_rotationAngle = point.rotationAngle; |
| 437 m_force = point.force; | 420 m_force = point.force; |
| 438 } | 421 } |
| 439 | 422 |
| 440 PlatformTouchEventBuilder::PlatformTouchEventBuilder(Widget* widget, const WebTo
uchEvent& event) | 423 PlatformTouchEventBuilder::PlatformTouchEventBuilder(Widget* widget, const WebTo
uchEvent& event) |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 modifiers = getWebInputModifiers(event); | 790 modifiers = getWebInputModifiers(event); |
| 808 | 791 |
| 809 globalX = event.screenX(); | 792 globalX = event.screenX(); |
| 810 globalY = event.screenY(); | 793 globalY = event.screenY(); |
| 811 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL
ocation(), *renderObject); | 794 IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteL
ocation(), *renderObject); |
| 812 x = localPoint.x(); | 795 x = localPoint.x(); |
| 813 y = localPoint.y(); | 796 y = localPoint.y(); |
| 814 } | 797 } |
| 815 | 798 |
| 816 } // namespace blink | 799 } // namespace blink |
| OLD | NEW |