Changed to PlatformMouseEvent constructor to allow construction from a QContextMenuEvent.
authorhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2007 14:29:03 +0000 (14:29 +0000)
committerhausmann <hausmann@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Nov 2007 14:29:03 +0000 (14:29 +0000)
Call sendContextMenuEvent on the event handler from a QWidget::contextMenuEvent re-implementation instead of in mousePressEvent.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27531 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/PlatformMouseEvent.h
WebCore/platform/qt/PlatformMouseEventQt.cpp
WebKit/qt/Api/qwebpage.cpp
WebKit/qt/Api/qwebpage.h
WebKit/qt/ChangeLog

index da0a1e9f7d0e8cf93e467428d8c63486f3063417..024cc9f50a818ee644b007050e577c62b05e175e 100644 (file)
@@ -1,3 +1,16 @@
+2007-11-07  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Lars.
+
+        Changed to PlatformMouseEvent constructor to allow construction from a QContextMenuEvent.
+        Call sendContextMenuEvent on the event handler from a QWidget::contextMenuEvent re-implementation instead of in mousePressEvent.
+
+        WARNING: NO TEST CASES ADDED OR CHANGED
+
+        * platform/PlatformMouseEvent.h:
+        * platform/qt/PlatformMouseEventQt.cpp:
+        (WebCore::PlatformMouseEvent::PlatformMouseEvent):
+
 2007-11-07  Lars Knoll  <lars@trolltech.com>
 
         Reviewed by Simon.
index f0be5f4d3242e77ec956963b0e3a074d309a59a7..983a5d11683fd716a98051dbdcf930318be295a5 100644 (file)
@@ -54,7 +54,7 @@ typedef struct _GdkEventMotion GdkEventMotion;
 #endif
 
 #if PLATFORM(QT)
-class QMouseEvent;
+class QInputEvent;
 #endif
 
 #if PLATFORM(WX)
@@ -127,7 +127,7 @@ namespace WebCore {
         PlatformMouseEvent(GdkEventMotion*);
 #endif
 #if PLATFORM(QT)
-        PlatformMouseEvent(QMouseEvent*, int clickCount);
+        PlatformMouseEvent(QInputEvent*, int clickCount);
 #endif
 
 #if PLATFORM(WX)
index 55bf9fbe749036de4f4e98afc3792ec404100239..ce7375b17acd0af2e9f2644ef3357c14532827a9 100644 (file)
 
 namespace WebCore {
 
-PlatformMouseEvent::PlatformMouseEvent(QMouseEvent* event, int clickCount)
+PlatformMouseEvent::PlatformMouseEvent(QInputEvent* event, int clickCount)
 {
-    m_position = IntPoint(event->pos());
-    m_globalPosition = IntPoint(event->globalPos());
-    
     m_timestamp = WebCore::currentTime();
+
+    QMouseEvent *me = 0;
+
     switch(event->type()) {
     case QEvent::MouseMove:
         m_eventType = MouseEventMoved;
+        me = static_cast<QMouseEvent *>(event);
         break;
     case QEvent::MouseButtonPress:
         m_eventType = MouseEventPressed;
+        me = static_cast<QMouseEvent *>(event);
         break;
     case QEvent::MouseButtonRelease:
         m_eventType = MouseEventReleased;
+        me = static_cast<QMouseEvent *>(event);
+        break;
+    case QEvent::ContextMenu: {
+        m_eventType = MouseEventPressed;
+        QContextMenuEvent *ce = static_cast<QContextMenuEvent *>(event);
+        m_position = IntPoint(ce->pos());
+        m_globalPosition = IntPoint(ce->globalPos());
+        m_button = RightButton;
         break;
+    }
     default:
         m_eventType = MouseEventMoved;
     }
 
-    if (event->button() == Qt::LeftButton || (event->buttons() & Qt::LeftButton))
-        m_button = LeftButton;
-    else if (event->button() == Qt::RightButton || (event->buttons() & Qt::RightButton))
-        m_button = RightButton;
-    else if (event->button() == Qt::MidButton || (event->buttons() & Qt::MidButton))
-        m_button = MiddleButton;
-    else
-        m_button = NoButton;
+    if (me) {
+        m_position = IntPoint(me->pos());
+        m_globalPosition = IntPoint(me->globalPos());
+
+        if (me->button() == Qt::LeftButton || (me->buttons() & Qt::LeftButton))
+            m_button = LeftButton;
+        else if (me->button() == Qt::RightButton || (me->buttons() & Qt::RightButton))
+            m_button = RightButton;
+        else if (me->button() == Qt::MidButton || (me->buttons() & Qt::MidButton))
+            m_button = MiddleButton;
+        else
+            m_button = NoButton;
+    }
 
     m_clickCount = clickCount;
     m_shiftKey =  (event->modifiers() & Qt::ShiftModifier) != 0;
index b303a16159abc012f2b238a9aa02f1ad4bbc0400..8ed3e1dbb7e9499d5e74b4091db97ca5db7c8319 100644 (file)
@@ -435,10 +435,7 @@ void QWebPage::mousePressEvent(QMouseEvent *ev)
     if (!frame->eventHandler)
         return;
 
-    if (ev->button() == Qt::RightButton)
-        frame->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
-    else
-        frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
+    frame->eventHandler->handleMousePressEvent(PlatformMouseEvent(ev, 1));
 
     //FIXME need to keep track of subframe focus for key events!
     frame->page->setFocus();
@@ -468,6 +465,13 @@ void QWebPage::mouseReleaseEvent(QMouseEvent *ev)
     d->frameUnderMouse = 0;
 }
 
+void QWebPage::contextMenuEvent(QContextMenuEvent *ev)
+{
+    QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
+    if (frame->eventHandler)
+        frame->eventHandler->sendContextMenuEvent(PlatformMouseEvent(ev, 1));
+}
+
 void QWebPage::wheelEvent(QWheelEvent *ev)
 {
     QWebFramePrivate *frame = d->currentFrame(ev->pos())->d;
index 47a9acb060da8cbc0523ae4e8cc03d9b4be36fa7..7f9b60d1ed9adcaa2d41c61fcacb857982a42679 100644 (file)
@@ -201,6 +201,7 @@ protected:
     virtual void mousePressEvent(QMouseEvent*);
     virtual void mouseDoubleClickEvent(QMouseEvent*);
     virtual void mouseReleaseEvent(QMouseEvent*);
+    virtual void contextMenuEvent(QContextMenuEvent*);
     virtual void wheelEvent(QWheelEvent*);
     virtual void keyPressEvent(QKeyEvent*);
     virtual void keyReleaseEvent(QKeyEvent*);
index 9aeb0afcccd22d2edd0e0cd8b5288a92ef31b0a8..45e2cd97092d2cebf0685d826c9ce0afc1eee839 100644 (file)
@@ -1,3 +1,15 @@
+2007-11-07  Simon Hausmann  <hausmann@kde.org>
+
+        Reviewed by Lars.
+
+        Changed to PlatformMouseEvent constructor to allow construction from a QContextMenuEvent.
+        Call sendContextMenuEvent on the event handler from a QWidget::contextMenuEvent re-implementation instead of in mousePressEvent.
+
+        * Api/qwebpage.cpp:
+        (QWebPage::mousePressEvent):
+        (QWebPage::contextMenuEvent):
+        * Api/qwebpage.h:
+
 2007-11-07  Simon Hausmann  <hausmann@kde.org>
 
         Reviewed by Lars.