WebWheelEvent WebEventFactory::createWebWheelEvent(QWheelEvent* e, const QTransform& fromItemTransform) { float deltaX = 0; float deltaY = 0; float wheelTicksX = 0; float wheelTicksY = 0; WebWheelEvent::Granularity granularity = WebWheelEvent::ScrollByPixelWheelEvent; WebEvent::Modifiers modifiers = modifiersForEvent(e->modifiers()); double timestamp = currentTimeForEvent(e); if (e->orientation() == Qt::Horizontal) { deltaX = e->delta(); wheelTicksX = deltaX / 120.0f; } else { deltaY = e->delta(); wheelTicksY = deltaY / 120.0f; } // Since we report the scroll by the pixel, convert the delta to pixel distance using standard scroll step. // Use the same single scroll step as QTextEdit (in QTextEditPrivate::init [h,v]bar->setSingleStep) static const float cDefaultQtScrollStep = 20.f; // ### FIXME: Default from QtGui. Should use Qt platform theme API once configurable. const int wheelScrollLines = 3; deltaX = wheelTicksX * wheelScrollLines * cDefaultQtScrollStep; deltaY = wheelTicksY * wheelScrollLines * cDefaultQtScrollStep; // Transform the position and the pixel scrolling distance. QLineF transformedScroll = fromItemTransform.map(QLineF(e->posF(), e->posF() + QPointF(deltaX, deltaY))); IntPoint transformedPoint = transformedScroll.p1().toPoint(); IntPoint globalPoint = e->globalPosF().toPoint(); FloatSize transformedDelta(transformedScroll.dx(), transformedScroll.dy()); FloatSize wheelTicks(wheelTicksX, wheelTicksY); return WebWheelEvent(WebEvent::Wheel, transformedPoint, globalPoint, transformedDelta, wheelTicks, granularity, modifiers, timestamp); }
WebWheelEvent WebEventFactory::createWebWheelEvent(QWheelEvent* e) { float deltaX = 0; float deltaY = 0; float wheelTicksX = 0; float wheelTicksY = 0; WebWheelEvent::Granularity granularity = WebWheelEvent::ScrollByPixelWheelEvent; WebEvent::Modifiers modifiers = modifiersForEvent(e->modifiers()); double timestamp = currentTimeForEvent(e); // A delta that is not mod 120 indicates a device that is sending // fine-resolution scroll events, so use the delta as number of wheel ticks // and number of pixels to scroll.See also webkit.org/b/29601 bool fullTick = !(e->delta() % 120); if (e->orientation() == Qt::Horizontal) { deltaX = (fullTick) ? e->delta() / 120.0f : e->delta(); wheelTicksX = deltaX; } else { deltaY = (fullTick) ? e->delta() / 120.0f : e->delta(); wheelTicksY = deltaY; } // Use the same single scroll step as QTextEdit // (in QTextEditPrivate::init [h,v]bar->setSingleStep) static const float cDefaultQtScrollStep = 20.f; deltaX *= (fullTick) ? QApplication::wheelScrollLines() * cDefaultQtScrollStep : 1; deltaY *= (fullTick) ? QApplication::wheelScrollLines() * cDefaultQtScrollStep : 1; return WebWheelEvent(WebEvent::Wheel, e->posF().toPoint(), e->globalPosF().toPoint(), FloatSize(deltaX, deltaY), FloatSize(wheelTicksX, wheelTicksY), granularity, modifiers, timestamp); }
WebMouseEvent WebEventFactory::createWebMouseEvent(QMouseEvent* event, const QTransform& fromItemTransform, int eventClickCount) { static FloatPoint lastPos = FloatPoint(0, 0); WebEvent::Type type = webEventTypeForEvent(event); WebMouseEvent::Button button = mouseButtonForEvent(event); float deltaX = event->pos().x() - lastPos.x(); float deltaY = event->pos().y() - lastPos.y(); int clickCount = eventClickCount; WebEvent::Modifiers modifiers = modifiersForEvent(event->modifiers()); double timestamp = currentTimeForEvent(event); lastPos.set(event->localPos().x(), event->localPos().y()); return WebMouseEvent(type, button, fromItemTransform.map(event->localPos()).toPoint(), event->screenPos().toPoint(), deltaX, deltaY, 0.0f, clickCount, modifiers, timestamp); }
WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(QKeyEvent* event) { const int state = event->modifiers(); WebEvent::Type type = webEventTypeForEvent(event); const String text = event->text(); const String unmodifiedText = event->text(); bool isAutoRepeat = event->isAutoRepeat(); bool isSystemKey = false; // FIXME: No idea what that is. bool isKeypad = (state & Qt::KeypadModifier); const String keyIdentifier = keyIdentifierForQtKeyCode(event->key()); int windowsVirtualKeyCode = windowsKeyCodeForKeyEvent(event->key(), isKeypad); int nativeVirtualKeyCode = event->nativeVirtualKey(); int macCharCode = 0; WebEvent::Modifiers modifiers = modifiersForEvent(event->modifiers()); double timestamp = currentTimeForEvent(event); return WebKeyboardEvent(type, text, unmodifiedText, keyIdentifier, windowsVirtualKeyCode, nativeVirtualKeyCode, macCharCode, isAutoRepeat, isKeypad, isSystemKey, modifiers, timestamp); }
WebTouchEvent WebEventFactory::createWebTouchEvent(const QTouchEvent* event, const QTransform& fromItemTransform) { WebEvent::Type type = webEventTypeForEvent(event); WebPlatformTouchPoint::TouchPointState state = static_cast<WebPlatformTouchPoint::TouchPointState>(0); unsigned int id; WebEvent::Modifiers modifiers = modifiersForEvent(event->modifiers()); double timestamp = currentTimeForEvent(event); const QList<QTouchEvent::TouchPoint>& points = event->touchPoints(); Vector<WebPlatformTouchPoint, 6> m_touchPoints; for (int i = 0; i < points.count(); ++i) { const QTouchEvent::TouchPoint& touchPoint = points.at(i); id = static_cast<unsigned>(touchPoint.id()); switch (touchPoint.state()) { case Qt::TouchPointReleased: state = WebPlatformTouchPoint::TouchReleased; break; case Qt::TouchPointMoved: state = WebPlatformTouchPoint::TouchMoved; break; case Qt::TouchPointPressed: state = WebPlatformTouchPoint::TouchPressed; break; case Qt::TouchPointStationary: state = WebPlatformTouchPoint::TouchStationary; break; default: ASSERT_NOT_REACHED(); break; } // Qt does not have a Qt::TouchPointCancelled point state, so if we receive a touch cancel event, // simply cancel all touch points here. if (type == WebEvent::TouchCancel) state = WebPlatformTouchPoint::TouchCancelled; IntSize radius(touchPoint.rect().width()/ 2, touchPoint.rect().height() / 2); m_touchPoints.append(WebPlatformTouchPoint(id, state, touchPoint.screenPos().toPoint(), fromItemTransform.map(touchPoint.pos()).toPoint(), radius, 0.0, touchPoint.pressure())); } return WebTouchEvent(type, m_touchPoints, modifiers, timestamp); }
WebTouchEvent WebEventFactory::createWebTouchEvent(const QTouchEvent* event) { WebEvent::Type type = webEventTypeForEvent(event); WebPlatformTouchPoint::TouchPointState state = static_cast<WebPlatformTouchPoint::TouchPointState>(0); unsigned int id; WebEvent::Modifiers modifiers = modifiersForEvent(event->modifiers()); double timestamp = currentTimeForEvent(event); const QList<QTouchEvent::TouchPoint>& points = event->touchPoints(); Vector<WebPlatformTouchPoint> m_touchPoints; for (int i = 0; i < points.count(); ++i) { id = static_cast<unsigned>(points.at(i).id()); switch (points.at(i).state()) { case Qt::TouchPointReleased: state = WebPlatformTouchPoint::TouchReleased; break; case Qt::TouchPointMoved: state = WebPlatformTouchPoint::TouchMoved; break; case Qt::TouchPointPressed: state = WebPlatformTouchPoint::TouchPressed; break; case Qt::TouchPointStationary: state = WebPlatformTouchPoint::TouchStationary; break; default: ASSERT_NOT_REACHED(); break; } m_touchPoints.append(WebPlatformTouchPoint(id, state, points.at(i).screenPos().toPoint(), points.at(i).pos().toPoint())); } return WebTouchEvent(type, m_touchPoints, modifiers, timestamp); }