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 <QGraphicsSceneMouseEvent>
32 #include <QMouseEvent>
33 #include <wtf/CurrentTime.h>
34
35 namespace WebCore {
36
37 #if !defined(QT_NO_GRAPHICSVIEW)
PlatformMouseEvent(QGraphicsSceneMouseEvent * event,int clickCount)38 PlatformMouseEvent::PlatformMouseEvent(QGraphicsSceneMouseEvent* event, int clickCount)
39 {
40 m_timestamp = WTF::currentTime();
41
42 switch (event->type()) {
43 case QEvent::GraphicsSceneMouseDoubleClick:
44 case QEvent::GraphicsSceneMousePress:
45 m_eventType = MouseEventPressed;
46 break;
47 case QEvent::GraphicsSceneMouseRelease:
48 m_eventType = MouseEventReleased;
49 break;
50 case QEvent::GraphicsSceneMouseMove:
51 default:
52 m_eventType = MouseEventMoved;
53 }
54
55 m_position = IntPoint(event->pos().toPoint());
56 m_globalPosition = IntPoint(event->screenPos());
57
58 if (event->button() == Qt::LeftButton || (event->buttons() & Qt::LeftButton))
59 m_button = LeftButton;
60 else if (event->button() == Qt::RightButton || (event->buttons() & Qt::RightButton))
61 m_button = RightButton;
62 else if (event->button() == Qt::MidButton || (event->buttons() & Qt::MidButton))
63 m_button = MiddleButton;
64 else
65 m_button = NoButton;
66
67 m_clickCount = clickCount;
68 m_shiftKey = (event->modifiers() & Qt::ShiftModifier);
69 m_ctrlKey = (event->modifiers() & Qt::ControlModifier);
70 m_altKey = (event->modifiers() & Qt::AltModifier);
71 m_metaKey = (event->modifiers() & Qt::MetaModifier);
72 }
73 #endif // QT_NO_GRAPHICSVIEW
74
PlatformMouseEvent(QInputEvent * event,int clickCount)75 PlatformMouseEvent::PlatformMouseEvent(QInputEvent* event, int clickCount)
76 {
77 m_timestamp = WTF::currentTime();
78
79 QMouseEvent* me = 0;
80
81 switch (event->type()) {
82 case QEvent::MouseMove:
83 m_eventType = MouseEventMoved;
84 me = static_cast<QMouseEvent *>(event);
85 break;
86 case QEvent::MouseButtonDblClick:
87 case QEvent::MouseButtonPress:
88 m_eventType = MouseEventPressed;
89 me = static_cast<QMouseEvent *>(event);
90 break;
91 case QEvent::MouseButtonRelease:
92 m_eventType = MouseEventReleased;
93 me = static_cast<QMouseEvent *>(event);
94 break;
95 #ifndef QT_NO_CONTEXTMENU
96 case QEvent::ContextMenu: {
97 m_eventType = MouseEventPressed;
98 QContextMenuEvent* ce = static_cast<QContextMenuEvent*>(event);
99 m_position = IntPoint(ce->pos());
100 m_globalPosition = IntPoint(ce->globalPos());
101 m_button = RightButton;
102 break;
103 }
104 #endif // QT_NO_CONTEXTMENU
105 default:
106 m_eventType = MouseEventMoved;
107 }
108
109 if (me) {
110 m_position = IntPoint(me->pos());
111 m_globalPosition = IntPoint(me->globalPos());
112
113 if (me->button() == Qt::LeftButton || (me->buttons() & Qt::LeftButton))
114 m_button = LeftButton;
115 else if (me->button() == Qt::RightButton || (me->buttons() & Qt::RightButton))
116 m_button = RightButton;
117 else if (me->button() == Qt::MidButton || (me->buttons() & Qt::MidButton))
118 m_button = MiddleButton;
119 else
120 m_button = NoButton;
121 }
122
123 m_clickCount = clickCount;
124 m_shiftKey = (event->modifiers() & Qt::ShiftModifier);
125 m_ctrlKey = (event->modifiers() & Qt::ControlModifier);
126 m_altKey = (event->modifiers() & Qt::AltModifier);
127 m_metaKey = (event->modifiers() & Qt::MetaModifier);
128 }
129
130 }
131
132 // vim: ts=4 sw=4 et
133