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#include <QGraphicsSceneMouseEvent> 35 36namespace WebCore { 37 38PlatformMouseEvent::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) != 0; 69 m_ctrlKey = (event->modifiers() & Qt::ControlModifier) != 0; 70 m_altKey = (event->modifiers() & Qt::AltModifier) != 0; 71 m_metaKey = (event->modifiers() & Qt::MetaModifier) != 0; 72} 73 74PlatformMouseEvent::PlatformMouseEvent(QInputEvent* event, int clickCount) 75{ 76 m_timestamp = WTF::currentTime(); 77 78 QMouseEvent* me = 0; 79 80 switch (event->type()) { 81 case QEvent::MouseMove: 82 m_eventType = MouseEventMoved; 83 me = static_cast<QMouseEvent *>(event); 84 break; 85 case QEvent::MouseButtonDblClick: 86 case QEvent::MouseButtonPress: 87 m_eventType = MouseEventPressed; 88 me = static_cast<QMouseEvent *>(event); 89 break; 90 case QEvent::MouseButtonRelease: 91 m_eventType = MouseEventReleased; 92 me = static_cast<QMouseEvent *>(event); 93 break; 94#ifndef QT_NO_CONTEXTMENU 95 case QEvent::ContextMenu: { 96 m_eventType = MouseEventPressed; 97 QContextMenuEvent *ce = static_cast<QContextMenuEvent *>(event); 98 m_position = IntPoint(ce->pos()); 99 m_globalPosition = IntPoint(ce->globalPos()); 100 m_button = RightButton; 101 break; 102 } 103#endif // QT_NO_CONTEXTMENU 104 default: 105 m_eventType = MouseEventMoved; 106 } 107 108 if (me) { 109 m_position = IntPoint(me->pos()); 110 m_globalPosition = IntPoint(me->globalPos()); 111 112 if (me->button() == Qt::LeftButton || (me->buttons() & Qt::LeftButton)) 113 m_button = LeftButton; 114 else if (me->button() == Qt::RightButton || (me->buttons() & Qt::RightButton)) 115 m_button = RightButton; 116 else if (me->button() == Qt::MidButton || (me->buttons() & Qt::MidButton)) 117 m_button = MiddleButton; 118 else 119 m_button = NoButton; 120 } 121 122 m_clickCount = clickCount; 123 m_shiftKey = (event->modifiers() & Qt::ShiftModifier) != 0; 124 m_ctrlKey = (event->modifiers() & Qt::ControlModifier) != 0; 125 m_altKey = (event->modifiers() & Qt::AltModifier) != 0; 126 m_metaKey = (event->modifiers() & Qt::MetaModifier) != 0; 127} 128 129} 130 131// vim: ts=4 sw=4 et 132