Exemple #1
0
void BrowserControl::handleButtonPressEvent(const XButtonPressedEvent& event)
{
    if (event.button == 4 || event.button == 5) {
        const float pixelsPerStep = 40.0f;

        NIXWheelEvent ev;
        ev.type = kNIXInputEventTypeWheel;
        ev.modifiers = convertXEventModifiersToNativeModifiers(event.state);
        ev.timestamp = convertXEventTimeToNixTimestamp(event.time);
        ev.x = event.x;
        ev.y = event.y;
        ev.globalX = event.x_root;
        ev.globalY = event.y_root;
        ev.delta = pixelsPerStep * (event.button == 4 ? 1 : -1);
        ev.orientation = event.state & Mod1Mask ? kNIXWheelEventOrientationHorizontal : kNIXWheelEventOrientationVertical;
        m_client->handleMouseWheel(&ev);
        return;
    }
    updateClickCount(event);

    NIXMouseEvent ev;
    ev.type = kNIXInputEventTypeMouseDown;
    ev.button = convertXEventButtonToNativeMouseButton(event.button);
    ev.x = event.x;
    ev.y = event.y;
    ev.globalX = event.x_root;
    ev.globalY = event.y_root;
    ev.clickCount = m_clickCount;
    ev.modifiers = convertXEventModifiersToNativeModifiers(event.state);
    ev.timestamp = convertXEventTimeToNixTimestamp(event.time);
    m_client->handleMousePress(&ev);

    passFocusToWebView();
}
Exemple #2
0
static JSValueRef mouseDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    int button = 1;
    if (argumentCount == 1) {
        button = static_cast<int>(JSValueToNumber(context, arguments[0], exception)) + 1;
        g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
    }

    GdkEvent event;
    if (!prepareMouseButtonEvent(&event, button))
        return JSValueMakeUndefined(context);

    buttonCurrentlyDown = event.button.button;

    // Normally GDK will send both GDK_BUTTON_PRESS and GDK_2BUTTON_PRESS for
    // the second button press during double-clicks. WebKit GTK+ selectively
    // ignores the first GDK_BUTTON_PRESS of that pair using gdk_event_peek.
    // Since our events aren't ever going onto the GDK event queue, WebKit won't
    // be able to filter out the first GDK_BUTTON_PRESS, so we just don't send
    // it here. Eventually this code should probably figure out a way to get all
    // appropriate events onto the event queue and this work-around should be
    // removed.
    updateClickCount(event.button.button);
    if (clickCount == 2)
        event.type = GDK_2BUTTON_PRESS;
    else if (clickCount == 3)
        event.type = GDK_3BUTTON_PRESS;
    else
        event.type = GDK_BUTTON_PRESS;

    sendOrQueueEvent(event);
    return JSValueMakeUndefined(context);
}
void EventSendingController::mouseUp(int button, JSValueRef modifierArray)
{
    WKBundlePageRef page = InjectedBundle::shared().page()->page();
    WKBundleFrameRef frame = WKBundlePageGetMainFrame(page);
    JSContextRef context = WKBundleFrameGetJavaScriptContext(frame);
    WKEventModifiers modifiers = parseModifierArray(context, modifierArray);

#ifdef USE_WEBPROCESS_EVENT_SIMULATION
    updateClickCount(button);
    WKBundlePageSimulateMouseUp(page, button, m_position, m_clickCount, modifiers, m_time);
#else
    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());

    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseUp"));
    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());

    WKRetainPtr<WKStringRef> buttonKey(AdoptWK, WKStringCreateWithUTF8CString("Button"));
    WKRetainPtr<WKUInt64Ref> buttonRef(AdoptWK, WKUInt64Create(button));
    WKDictionaryAddItem(EventSenderMessageBody.get(), buttonKey.get(), buttonRef.get());

    WKRetainPtr<WKStringRef> modifiersKey(AdoptWK, WKStringCreateWithUTF8CString("Modifiers"));
    WKRetainPtr<WKUInt64Ref> modifiersRef(AdoptWK, WKUInt64Create(modifiers));
    WKDictionaryAddItem(EventSenderMessageBody.get(), modifiersKey.get(), modifiersRef.get());

    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
#endif
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    m_clicks(0)
{
    ui->setupUi(this);
    connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close()));

    connect(ui->lineEdit, SIGNAL(textChanged(QString)), ui->textEditDisplay, SLOT(setText(QString)));
    connect(ui->textEdit, SIGNAL(textChanged()), this, SLOT(updateTextEditDisplay()));

    connect(ui->pushButton, SIGNAL(pressed()), this, SLOT(updatePushButtonDisplay()));
    connect(ui->pushButton, SIGNAL(released()), this, SLOT(updatePushButtonDisplay()));
    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(updateClickCount()));
    connect(ui->radioButton1, SIGNAL(toggled(bool)), this, SLOT(updateRadioButtonDisplay()));
    connect(ui->radioButton2, SIGNAL(toggled(bool)), this, SLOT(updateRadioButtonDisplay()));
    connect(ui->checkBox, SIGNAL(stateChanged(int)), this, SLOT(updateCheckBoxDisplay()));
    connect(ui->comboBox, SIGNAL(activated(int)), this, SLOT(updateComboBoxDisplay()));
    connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(updateHorizontalSliderDisplay()));

    QWidget *contents = new QWidget;
    contents->setObjectName("contents");
    contents->setFixedSize(QSize(500, 500));
    QPushButton *topLeft = new QPushButton(contents);
    topLeft->setObjectName("topLeft");
    topLeft->setFixedSize(QSize(20,20));
    topLeft->move(10, 10);
    QPushButton *topRight = new QPushButton(contents);
    topRight->setObjectName("topRight");
    topRight->setFixedSize(QSize(20,20));
    topRight->move(470, 10);
    QPushButton *bottomLeft = new QPushButton(contents);
    bottomLeft->setObjectName("bottomLeft");
    bottomLeft->setFixedSize(QSize(20,20));
    bottomLeft->move(10, 470);
    QPushButton *bottomRight = new QPushButton(contents);
    bottomRight->setObjectName("bottomRight");
    bottomRight->setFixedSize(QSize(20,20));
    bottomRight->move(470, 470);

    ui->scrollArea->setWidget(contents);

    QStandardItemModel *model = new QStandardItemModel(this);
    model->setHorizontalHeaderLabels(QStringList() << tr("items"));
    QStandardItem *parentItem;
    for (int j = 0; j < 3; ++j) {
        parentItem = model->invisibleRootItem();
        for (int i = 0; i < 4; ++i) {
            QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
            parentItem->appendRow(item);
            parentItem = item;
        }
    }

    ui->treeView->setModel(model);
}
static JSValueRef mouseDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
    if (!view)
        return JSValueMakeUndefined(context);

    down = true;

    GdkEvent event;
    memset(&event, 0, sizeof(event));
    event.type = GDK_BUTTON_PRESS;
    event.button.button = 1;

    if (argumentCount == 1) {
        event.button.button = (int)JSValueToNumber(context, arguments[0], exception) + 1;
        g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));
    }

    currentEventButton = event.button.button;

    event.button.x = lastMousePositionX;
    event.button.y = lastMousePositionY;
    event.button.window = GTK_WIDGET(view)->window;
    event.button.time = GDK_CURRENT_TIME;
    event.button.device = gdk_device_get_core_pointer();

    int x_root, y_root;
#if GTK_CHECK_VERSION(2,17,3)
    gdk_window_get_root_coords(GTK_WIDGET(view)->window, lastMousePositionX, lastMousePositionY, &x_root, &y_root);
#else
    getRootCoords(GTK_WIDGET(view), &x_root, &y_root);
#endif

    event.button.x_root = x_root;
    event.button.y_root = y_root;

    updateClickCount(event.button.button);

    if (!msgQueue[endOfQueue].delay) {
        webkit_web_frame_layout(mainFrame);

        gboolean return_val;
        g_signal_emit_by_name(view, "button_press_event", &event, &return_val);
        if (clickCount == 2) {
            event.type = GDK_2BUTTON_PRESS;
            g_signal_emit_by_name(view, "button_press_event", &event, &return_val);
        }
    } else {
        // replaySavedEvents should have the required logic to make leapForward delays work
        msgQueue[endOfQueue++].event = event;
        replaySavedEvents();
    }

    return JSValueMakeUndefined(context);
}
void WindowEventProducer::produceMouseClicked(const MouseEventDetails::MouseButton& Button, const Pnt2f& Location)
{
    //Check if Input is blocked
    if(_BlockInput) { return; }

   Time t(getSystemTime());
   updateClickCount(Button, t, Location);
   Pnt2f ViewportLocation;
   ViewportUnrecPtr ResultViewport;
   ResultViewport = windowToViewport(Location, ViewportLocation);
   if(ResultViewport != NULL)
   {
	   MouseEventDetailsUnrecPtr Details = MouseEventDetails::create(this, t, Button, _ButtonClickCountMap[Button].size(), ViewportLocation, ResultViewport );
	   
       WindowEventProducerBase::produceMouseClicked(Details);
   }
}
Exemple #7
0
void MiniBrowser::handleButtonPressEvent(const XButtonPressedEvent& event)
{
    NIXView view = webViewAtX11Position(WKPointMake(event.x, event.y));
    if (!view)
        return;

    if (event.button == 4 || event.button == 5) {
        handleWheelEvent(event);
        return;
    }

    updateClickCount(event);

    NIXMouseEvent nixEvent = convertXButtonEventToNixButtonEvent(view, event, kNIXInputEventTypeMouseDown, m_clickCount);
    if (m_touchMocker && m_touchMocker->handleMousePress(nixEvent, WKPointMake(event.x, event.y))) {
        scheduleUpdateDisplay();
        return;
    }
    NIXViewSendMouseEvent(view, &nixEvent);
}
void DesktopWindowLinux::handleXEvent(const XEvent& event)
{
    if (event.type == ConfigureNotify) {
        updateSizeIfNeeded(event.xconfigure.width, event.xconfigure.height);
        return;
    }

    if (!m_client)
        return;

    switch (event.type) {
    case Expose:
        m_client->onWindowExpose();
        break;
    case KeyPress:
    case KeyRelease:
        sendKeyboardEventToNix(event);
        break;
    case ButtonPress: {
        const XButtonPressedEvent* xEvent = reinterpret_cast<const XButtonReleasedEvent*>(&event);

        if (xEvent->button == 4 || xEvent->button == 5) {
            // Same constant we use inside WebView to calculate the ticks. See also WebCore::Scrollbar::pixelsPerLineStep().
            const float pixelsPerStep = 40.0f;

            NIXWheelEvent ev;
            ev.type = kNIXInputEventTypeWheel;
            ev.modifiers = convertXEventModifiersToNativeModifiers(xEvent->state);
            ev.timestamp = convertXEventTimeToNixTimestamp(xEvent->time);
            ev.x = xEvent->x;
            ev.y = xEvent->y;
            ev.globalX = xEvent->x_root;
            ev.globalY = xEvent->y_root;
            ev.delta = pixelsPerStep * (xEvent->button == 4 ? 1 : -1);
            ev.orientation = xEvent->state & Mod1Mask ? kNIXWheelEventOrientationHorizontal : kNIXWheelEventOrientationVertical;
            m_client->onMouseWheel(&ev);
            break;
        }
        updateClickCount(xEvent);

        NIXMouseEvent ev;
        ev.type = kNIXInputEventTypeMouseDown;
        ev.button = convertXEventButtonToNativeMouseButton(xEvent->button);
        ev.x = xEvent->x;
        ev.y = xEvent->y;
        ev.globalX = xEvent->x_root;
        ev.globalY = xEvent->y_root;
        ev.clickCount = m_clickCount;
        ev.modifiers = convertXEventModifiersToNativeModifiers(xEvent->state);
        ev.timestamp = convertXEventTimeToNixTimestamp(xEvent->time);
        m_client->onMousePress(&ev);
        break;
    }
    case ButtonRelease: {
        const XButtonReleasedEvent* xEvent = reinterpret_cast<const XButtonReleasedEvent*>(&event);
        if (xEvent->button == 4 || xEvent->button == 5)
            break;

        NIXMouseEvent ev;
        ev.type = kNIXInputEventTypeMouseUp;
        ev.button = convertXEventButtonToNativeMouseButton(xEvent->button);
        ev.x = xEvent->x;
        ev.y = xEvent->y;
        ev.globalX = xEvent->x_root;
        ev.globalY = xEvent->y_root;
        ev.clickCount = 0;
        ev.modifiers = convertXEventModifiersToNativeModifiers(xEvent->state);
        ev.timestamp = convertXEventModifiersToNativeModifiers(xEvent->state);

        m_client->onMouseRelease(&ev);
        break;
    }
    case ClientMessage:
        if ((Atom)event.xclient.data.l[0] == wmDeleteMessageAtom)
            m_client->onWindowClose();
        break;
    case MotionNotify: {
        NIXMouseEvent ev;
        const XPointerMovedEvent* xEvent = reinterpret_cast<const XPointerMovedEvent*>(&event);
        ev.type = kNIXInputEventTypeMouseMove;
        ev.button = kWKEventMouseButtonNoButton;
        ev.x = xEvent->x;
        ev.y = xEvent->y;
        ev.globalX = xEvent->x_root;
        ev.globalY = xEvent->y_root;
        ev.clickCount = 0;
        ev.modifiers = convertXEventModifiersToNativeModifiers(xEvent->state);
        ev.timestamp = convertXEventTimeToNixTimestamp(xEvent->time);
        m_client->onMouseMove(&ev);
        break;
    }
    }
}