WebGestureEventBuilder::WebGestureEventBuilder(const LayoutObject* layoutObject, const GestureEvent& event) { if (event.type() == EventTypeNames::gestureshowpress) type = GestureShowPress; else if (event.type() == EventTypeNames::gesturelongpress) type = GestureLongPress; else if (event.type() == EventTypeNames::gesturetapdown) type = GestureTapDown; else if (event.type() == EventTypeNames::gesturescrollstart) type = GestureScrollBegin; else if (event.type() == EventTypeNames::gesturescrollend) type = GestureScrollEnd; else if (event.type() == EventTypeNames::gesturescrollupdate) { type = GestureScrollUpdate; data.scrollUpdate.deltaX = event.deltaX(); data.scrollUpdate.deltaY = event.deltaY(); } else if (event.type() == EventTypeNames::gesturetap) { type = GestureTap; data.tap.tapCount = 1; } timeStampSeconds = event.timeStamp() / millisPerSecond; modifiers = getWebInputModifiers(event); globalX = event.screenX(); globalY = event.screenY(); IntPoint localPoint = convertAbsoluteLocationForLayoutObject(event.absoluteLocation(), *layoutObject); x = localPoint.x(); y = localPoint.y(); }
WebGestureEventBuilder::WebGestureEventBuilder(const LayoutObject* layoutObject, const GestureEvent& event) { if (event.type() == EventTypeNames::gestureshowpress) { type = GestureShowPress; } else if (event.type() == EventTypeNames::gesturelongpress) { type = GestureLongPress; } else if (event.type() == EventTypeNames::gesturetapdown) { type = GestureTapDown; } else if (event.type() == EventTypeNames::gesturescrollstart) { type = GestureScrollBegin; resendingPluginId = event.resendingPluginId(); data.scrollBegin.deltaXHint = event.deltaX(); data.scrollBegin.deltaYHint = event.deltaY(); data.scrollBegin.deltaHintUnits = toWebGestureScrollUnits(event.deltaUnits()); data.scrollBegin.inertial = event.inertial(); data.scrollBegin.synthetic = event.synthetic(); } else if (event.type() == EventTypeNames::gesturescrollend) { type = GestureScrollEnd; resendingPluginId = event.resendingPluginId(); data.scrollEnd.deltaUnits = toWebGestureScrollUnits(event.deltaUnits()); data.scrollEnd.inertial = event.inertial(); data.scrollEnd.synthetic = event.synthetic(); } else if (event.type() == EventTypeNames::gesturescrollupdate) { type = GestureScrollUpdate; data.scrollUpdate.deltaUnits = toWebGestureScrollUnits(event.deltaUnits()); data.scrollUpdate.deltaX = event.deltaX(); data.scrollUpdate.deltaY = event.deltaY(); data.scrollUpdate.inertial = event.inertial(); resendingPluginId = event.resendingPluginId(); } else if (event.type() == EventTypeNames::gestureflingstart) { type = GestureFlingStart; data.flingStart.velocityX = event.velocityX(); data.flingStart.velocityY = event.velocityY(); } else if (event.type() == EventTypeNames::gesturetap) { type = GestureTap; data.tap.tapCount = 1; } timeStampSeconds = event.platformTimeStamp(); modifiers = event.modifiers(); globalX = event.screenX(); globalY = event.screenY(); IntPoint localPoint = convertAbsoluteLocationForLayoutObject(event.absoluteLocation(), *layoutObject); x = localPoint.x(); y = localPoint.y(); switch (event.source()) { case GestureSourceTouchpad: sourceDevice = WebGestureDeviceTouchpad; break; case GestureSourceTouchscreen: sourceDevice = WebGestureDeviceTouchscreen; break; case GestureSourceUninitialized: ASSERT_NOT_REACHED(); } }
// Generate a synthetic WebMouseEvent given a TouchEvent (eg. for emulating a mouse // with touch input for plugins that don't support touch input). WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, const LayoutObject* layoutObject, const TouchEvent& event) { if (!event.touches()) return; if (event.touches()->length() != 1) { if (event.touches()->length() || event.type() != EventTypeNames::touchend || !event.changedTouches() || event.changedTouches()->length() != 1) return; } const Touch* touch = event.touches()->length() == 1 ? event.touches()->item(0) : event.changedTouches()->item(0); if (touch->identifier()) return; if (event.type() == EventTypeNames::touchstart) type = MouseDown; else if (event.type() == EventTypeNames::touchmove) type = MouseMove; else if (event.type() == EventTypeNames::touchend) type = MouseUp; else return; // TODO(majidvp): Instead of using |Event::createTime| which is epoch time // we should instead use |Event::platformTimeStamp| which is the actual // platform monotonic time. See: crbug.com/538199 timeStampSeconds = convertDOMTimeStampToSeconds(event.createTime()); modifiers = event.modifiers(); // The mouse event co-ordinates should be generated from the co-ordinates of the touch point. FrameView* view = toFrameView(widget->parent()); // FIXME: if view == nullptr, pointInRootFrame will really be pointInRootContent. IntPoint pointInRootFrame = roundedIntPoint(touch->absoluteLocation()); if (view) pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); IntPoint screenPoint = roundedIntPoint(touch->screenLocation()); globalX = screenPoint.x(); globalY = screenPoint.y(); windowX = pointInRootFrame.x(); windowY = pointInRootFrame.y(); button = WebMouseEvent::ButtonLeft; modifiers |= WebInputEvent::LeftButtonDown; clickCount = (type == MouseDown || type == MouseUp); IntPoint localPoint = convertAbsoluteLocationForLayoutObject(touch->absoluteLocation(), *layoutObject); x = localPoint.x(); y = localPoint.y(); }
// Generate a synthetic WebMouseEvent given a TouchEvent (eg. for emulating a mouse // with touch input for plugins that don't support touch input). WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, const LayoutObject* layoutObject, const TouchEvent& event) { if (!event.touches()) return; if (event.touches()->length() != 1) { if (event.touches()->length() || event.type() != EventTypeNames::touchend || !event.changedTouches() || event.changedTouches()->length() != 1) return; } const Touch* touch = event.touches()->length() == 1 ? event.touches()->item(0) : event.changedTouches()->item(0); if (touch->identifier()) return; if (event.type() == EventTypeNames::touchstart) type = MouseDown; else if (event.type() == EventTypeNames::touchmove) type = MouseMove; else if (event.type() == EventTypeNames::touchend) type = MouseUp; else return; timeStampSeconds = event.platformTimeStamp(); modifiers = event.modifiers(); // The mouse event co-ordinates should be generated from the co-ordinates of the touch point. FrameView* view = toFrameView(widget->parent()); // FIXME: if view == nullptr, pointInRootFrame will really be pointInRootContent. IntPoint pointInRootFrame = roundedIntPoint(touch->absoluteLocation()); if (view) pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); IntPoint screenPoint = roundedIntPoint(touch->screenLocation()); globalX = screenPoint.x(); globalY = screenPoint.y(); windowX = pointInRootFrame.x(); windowY = pointInRootFrame.y(); button = WebMouseEvent::ButtonLeft; modifiers |= WebInputEvent::LeftButtonDown; clickCount = (type == MouseDown || type == MouseUp); IntPoint localPoint = convertAbsoluteLocationForLayoutObject(touch->absoluteLocation(), *layoutObject); x = localPoint.x(); y = localPoint.y(); pointerType = WebPointerProperties::PointerType::Touch; }
// FIXME: Change |widget| to const Widget& after RemoteFrames get // RemoteFrameViews. static void updateWebMouseEventFromCoreMouseEvent(const MouseRelatedEvent& event, const Widget* widget, const LayoutObject& layoutObject, WebMouseEvent& webEvent) { webEvent.timeStampSeconds = event.platformTimeStamp(); webEvent.modifiers = event.modifiers(); FrameView* view = widget ? toFrameView(widget->parent()) : 0; // TODO(bokan): If view == nullptr, pointInRootFrame will really be pointInRootContent. IntPoint pointInRootFrame = IntPoint(event.absoluteLocation().x(), event.absoluteLocation().y()); if (view) pointInRootFrame = view->contentsToRootFrame(pointInRootFrame); webEvent.globalX = event.screenX(); webEvent.globalY = event.screenY(); webEvent.windowX = pointInRootFrame.x(); webEvent.windowY = pointInRootFrame.y(); IntPoint localPoint = convertAbsoluteLocationForLayoutObject(event.absoluteLocation(), layoutObject); webEvent.x = localPoint.x(); webEvent.y = localPoint.y(); }