• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include "config.h"
29 #include "PlatformMouseEvent.h"
30 
31 #include <wtf/CurrentTime.h>
32 
33 #include <QMouseEvent>
34 
35 namespace WebCore {
36 
PlatformMouseEvent(QInputEvent * event,int clickCount)37 PlatformMouseEvent::PlatformMouseEvent(QInputEvent* event, int clickCount)
38 {
39     m_timestamp = WTF::currentTime();
40 
41     QMouseEvent* me = 0;
42 
43     switch (event->type()) {
44     case QEvent::MouseMove:
45         m_eventType = MouseEventMoved;
46         me = static_cast<QMouseEvent *>(event);
47         break;
48     case QEvent::MouseButtonDblClick:
49     case QEvent::MouseButtonPress:
50         m_eventType = MouseEventPressed;
51         me = static_cast<QMouseEvent *>(event);
52         break;
53     case QEvent::MouseButtonRelease:
54         m_eventType = MouseEventReleased;
55         me = static_cast<QMouseEvent *>(event);
56         break;
57 #ifndef QT_NO_CONTEXTMENU
58     case QEvent::ContextMenu: {
59         m_eventType = MouseEventPressed;
60         QContextMenuEvent *ce = static_cast<QContextMenuEvent *>(event);
61         m_position = IntPoint(ce->pos());
62         m_globalPosition = IntPoint(ce->globalPos());
63         m_button = RightButton;
64         break;
65     }
66 #endif // QT_NO_CONTEXTMENU
67     default:
68         m_eventType = MouseEventMoved;
69     }
70 
71     if (me) {
72         m_position = IntPoint(me->pos());
73         m_globalPosition = IntPoint(me->globalPos());
74 
75         if (me->button() == Qt::LeftButton || (me->buttons() & Qt::LeftButton))
76             m_button = LeftButton;
77         else if (me->button() == Qt::RightButton || (me->buttons() & Qt::RightButton))
78             m_button = RightButton;
79         else if (me->button() == Qt::MidButton || (me->buttons() & Qt::MidButton))
80             m_button = MiddleButton;
81         else
82             m_button = NoButton;
83     }
84 
85     m_clickCount = clickCount;
86     m_shiftKey =  (event->modifiers() & Qt::ShiftModifier) != 0;
87     m_ctrlKey = (event->modifiers() & Qt::ControlModifier) != 0;
88     m_altKey =  (event->modifiers() & Qt::AltModifier) != 0;
89     m_metaKey = (event->modifiers() & Qt::MetaModifier) != 0;
90 }
91 
92 }
93 
94 // vim: ts=4 sw=4 et
95