WebMouseEvent WebEventFactory::createWebMouseEvent(const Evas_Event_Mouse_Down* event, const AffineTransform& toWebContent, const AffineTransform& toDeviceScreen) { IntPoint pos(event->canvas.x, event->canvas.y); return WebMouseEvent(WebEvent::MouseDown, buttonForEvent(event->button), toWebContent.mapPoint(pos), toDeviceScreen.mapPoint(pos), 0 /* deltaX */, 0 /* deltaY */, 0 /* deltaZ */, clickCountForEvent(event->flags), modifiersForEvent(event->modifiers), convertMillisecondToSecond(event->timestamp)); }
WebMouseEvent WebEventFactory::createWebMouseEvent(const Evas_Event_Mouse_Move* event, const AffineTransform& toWebContent, const AffineTransform& toDeviceScreen) { IntPoint pos(event->cur.canvas.x, event->cur.canvas.y); return WebMouseEvent(WebEvent::MouseMove, buttonForEvent(event->buttons), toWebContent.mapPoint(pos), toDeviceScreen.mapPoint(pos), (event->cur.canvas.x - event->prev.canvas.x) /* deltaX */, (event->cur.canvas.y - event->prev.canvas.y) /* deltaY */, 0 /* deltaZ */, 0 /* clickCount */, modifiersForEvent(event->modifiers), convertMillisecondToSecond(event->timestamp)); }
WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(const GdkEvent* event, const WebCore::CompositionResults& compositionResults, Vector<String>&& commands) { return WebKeyboardEvent( event->type == GDK_KEY_RELEASE ? WebEvent::KeyUp : WebEvent::KeyDown, compositionResults.simpleString.length() ? compositionResults.simpleString : PlatformKeyboardEvent::singleCharacterString(event->key.keyval), PlatformKeyboardEvent::keyIdentifierForGdkKeyCode(event->key.keyval), PlatformKeyboardEvent::windowsKeyCodeForGdkKeyCode(event->key.keyval), static_cast<int>(event->key.keyval), compositionResults.compositionUpdated(), WTF::move(commands), isGdkKeyCodeFromKeyPad(event->key.keyval), modifiersForEvent(event), gdk_event_get_time(event)); }
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(const Evas_Event_Key_Up* event) { const String keyName(event->key); return WebKeyboardEvent(WebEvent::KeyUp, String::fromUTF8(event->string), String::fromUTF8(event->string), keyIdentifierForEvasKeyName(keyName), windowsKeyCodeForEvasKeyName(keyName), 0 /* FIXME: nativeVirtualKeyCode */, 0 /* macCharCode */, false /* FIXME: isAutoRepeat */, keyName.startsWith(keyPadPrefix), false /* isSystemKey */, modifiersForEvent(event->modifiers), convertMillisecondToSecond(event->timestamp)); }
WebWheelEvent WebEventFactory::createWebWheelEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { // Taken from WebCore static const float cScrollbarPixelsPerLine = 100.0f / 3.0f; POINT globalPosition = point(lParam); POINT position = globalPosition; ::ScreenToClient(hWnd, &position); WebWheelEvent::Granularity granularity = WebWheelEvent::ScrollByPixelWheelEvent; WebEvent::Modifiers modifiers = modifiersForEvent(wParam); double timestamp = ::GetTickCount() * 0.001; // ::GetTickCount returns milliseconds (Chrome uses GetMessageTime() / 1000.0) int deltaX = 0; int deltaY = 0; int wheelTicksX = 0; int wheelTicksY = 0; float delta = GET_WHEEL_DELTA_WPARAM(wParam) / static_cast<float>(WHEEL_DELTA); bool isMouseHWheel = (message == WM_VISTA_MOUSEHWHEEL); if (isMouseHWheel) { wheelTicksX = delta; wheelTicksY = 0; delta = -delta; } else { wheelTicksX = 0; wheelTicksY = delta; } if (isMouseHWheel || (modifiers & WebEvent::ShiftKey)) { deltaX = delta * static_cast<float>(horizontalScrollChars()) * cScrollbarPixelsPerLine; deltaY = 0; granularity = WebWheelEvent::ScrollByPixelWheelEvent; } else { deltaX = 0; deltaY = delta; int verticalMultiplier = verticalScrollLines(); if (verticalMultiplier == WHEEL_PAGESCROLL) granularity = WebWheelEvent::ScrollByPageWheelEvent; else { granularity = WebWheelEvent::ScrollByPixelWheelEvent; deltaY *= static_cast<float>(verticalMultiplier) * cScrollbarPixelsPerLine; } } return WebWheelEvent(WebEvent::Wheel, position, globalPosition, FloatSize(deltaX, deltaY), FloatSize(wheelTicksX, wheelTicksY), granularity, modifiers, timestamp); }
WebWheelEvent WebEventFactory::createWebWheelEvent(const GdkEvent* event) { double x, y, xRoot, yRoot; gdk_event_get_coords(event, &x, &y); gdk_event_get_root_coords(event, &xRoot, &yRoot); FloatSize wheelTicks; switch (event->scroll.direction) { case GDK_SCROLL_UP: wheelTicks = FloatSize(0, 1); break; case GDK_SCROLL_DOWN: wheelTicks = FloatSize(0, -1); break; case GDK_SCROLL_LEFT: wheelTicks = FloatSize(1, 0); break; case GDK_SCROLL_RIGHT: wheelTicks = FloatSize(-1, 0); break; #if GTK_CHECK_VERSION(3, 3, 18) case GDK_SCROLL_SMOOTH: { double deltaX, deltaY; gdk_event_get_scroll_deltas(event, &deltaX, &deltaY); wheelTicks = FloatSize(-deltaX, -deltaY); } break; #endif default: ASSERT_NOT_REACHED(); } // FIXME: [GTK] Add a setting to change the pixels per line used for scrolling // https://bugs.webkit.org/show_bug.cgi?id=54826 float step = static_cast<float>(Scrollbar::pixelsPerLineStep()); FloatSize delta(wheelTicks.width() * step, wheelTicks.height() * step); return WebWheelEvent(WebEvent::Wheel, IntPoint(x, y), IntPoint(xRoot, yRoot), delta, wheelTicks, WebWheelEvent::ScrollByPixelWheelEvent, modifiersForEvent(event), gdk_event_get_time(event)); }
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); }
WebKeyboardEvent WebEventFactory::createWebKeyboardEvent(const GdkEvent* event, const WebCore::CompositionResults& compositionResults) { unsigned int keyValue = event->key.keyval; String text = compositionResults.simpleString.length() ? compositionResults.simpleString : PlatformKeyboardEvent::singleCharacterString(keyValue); int windowsVirtualKeyCode = compositionResults.compositionUpdated() ? VK_PROCESSKEY : PlatformKeyboardEvent::windowsKeyCodeForGdkKeyCode(event->key.keyval); return WebKeyboardEvent((event->type == GDK_KEY_RELEASE) ? WebEvent::KeyUp : WebEvent::KeyDown, text, text, PlatformKeyboardEvent::keyIdentifierForGdkKeyCode(keyValue), windowsVirtualKeyCode, static_cast<int>(keyValue), 0 /* macCharCode */, false /* isAutoRepeat */, isGdkKeyCodeFromKeyPad(keyValue), false /* isSystemKey */, modifiersForEvent(event), gdk_event_get_time(event)); }
WebTouchEvent WebEventFactory::createWebTouchEvent(const GdkEvent* event, Vector<WebPlatformTouchPoint>&& touchPoints) { #ifndef GTK_API_VERSION_2 WebEvent::Type type = WebEvent::NoType; switch (event->type) { case GDK_TOUCH_BEGIN: type = WebEvent::TouchStart; break; case GDK_TOUCH_UPDATE: type = WebEvent::TouchMove; break; case GDK_TOUCH_END: type = WebEvent::TouchEnd; break; default: ASSERT_NOT_REACHED(); } return WebTouchEvent(type, WTFMove(touchPoints), modifiersForEvent(event), gdk_event_get_time(event)); #else return WebTouchEvent(); #endif // GTK_API_VERSION_2 }
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); }
WebMouseEvent WebEventFactory::createWebMouseEvent(const GdkEvent* event, int currentClickCount) { double x, y, xRoot, yRoot; gdk_event_get_coords(event, &x, &y); gdk_event_get_root_coords(event, &xRoot, &yRoot); WebEvent::Type type = static_cast<WebEvent::Type>(0); switch (event->type) { case GDK_MOTION_NOTIFY: case GDK_ENTER_NOTIFY: case GDK_LEAVE_NOTIFY: type = WebEvent::MouseMove; break; case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: type = WebEvent::MouseDown; break; case GDK_BUTTON_RELEASE: type = WebEvent::MouseUp; break; default : ASSERT_NOT_REACHED(); } return WebMouseEvent(type, buttonForEvent(event), IntPoint(x, y), IntPoint(xRoot, yRoot), 0 /* deltaX */, 0 /* deltaY */, 0 /* deltaZ */, currentClickCount, modifiersForEvent(event), gdk_event_get_time(event)); }
WebMouseEvent WebEventFactory::createWebMouseEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { WebEvent::Type type; WebMouseEvent::Button button = WebMouseEvent::NoButton; switch (message) { case WM_MOUSEMOVE: type = WebEvent::MouseMove; if (wParam & MK_LBUTTON) button = WebMouseEvent::LeftButton; else if (wParam & MK_MBUTTON) button = WebMouseEvent::MiddleButton; else if (wParam & MK_RBUTTON) button = WebMouseEvent::RightButton; break; case WM_MOUSELEAVE: type = WebEvent::MouseMove; if (wParam & MK_LBUTTON) button = WebMouseEvent::LeftButton; else if (wParam & MK_MBUTTON) button = WebMouseEvent::MiddleButton; else if (wParam & MK_RBUTTON) button = WebMouseEvent::RightButton; // Set the current mouse position (relative to the client area of the // current window) since none is specified for this event. lParam = relativeCursorPosition(hWnd); break; case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: type = WebEvent::MouseDown; button = WebMouseEvent::LeftButton; break; case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: type = WebEvent::MouseDown; button = WebMouseEvent::MiddleButton; break; case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: type = WebEvent::MouseDown; button = WebMouseEvent::RightButton; break; case WM_LBUTTONUP: type = WebEvent::MouseUp; button = WebMouseEvent::LeftButton; break; case WM_MBUTTONUP: type = WebEvent::MouseUp; button = WebMouseEvent::MiddleButton; break; case WM_RBUTTONUP: type = WebEvent::MouseUp; button = WebMouseEvent::RightButton; break; default: ASSERT_NOT_REACHED(); type = WebEvent::KeyDown; } POINT position = point(lParam); POINT globalPosition = position; ::ClientToScreen(hWnd, &globalPosition); double timestamp = ::GetTickCount() * 0.001; // ::GetTickCount returns milliseconds (Chrome uses GetMessageTime() / 1000.0) int clickCount = WebKit::clickCount(type, button, position, timestamp); WebEvent::Modifiers modifiers = modifiersForEvent(wParam); return WebMouseEvent(type, button, position, globalPosition, 0, 0, 0, clickCount, modifiers, timestamp); }