Changed to PlatformMouseEvent constructor to allow construction from a QContextMenuEvent.
[WebKit-https.git] / WebCore / platform / qt / PlatformMouseEventQt.cpp
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;