1 /* 2 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 4 This library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this library; see the file COPYING.LIB. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 Boston, MA 02110-1301, USA. 18 */ 19 20 #include "config.h" 21 #include "WheelEvent.h" 22 23 #include "PlatformMouseEvent.h" 24 #include "PlatformWheelEvent.h" 25 #include "Scrollbar.h" 26 27 #include <QGraphicsSceneWheelEvent> 28 #include <QWheelEvent> 29 #include <qapplication.h> 30 31 namespace WebCore { 32 33 void PlatformWheelEvent::applyDelta(int delta, Qt::Orientation orientation) 34 { 35 // A delta that is not mod 120 indicates a device that is sending 36 // fine-resolution scroll events, so use the delta as number of wheel ticks 37 // and number of pixels to scroll.See also webkit.org/b/29601 38 bool fullTick = !(delta % 120); 39 40 if (orientation == Qt::Horizontal) { 41 m_deltaX = (fullTick) ? delta / 120.0f : delta; 42 m_deltaY = 0; 43 } else { 44 m_deltaX = 0; 45 m_deltaY = (fullTick) ? delta / 120.0f : delta; 46 } 47 48 m_wheelTicksX = m_deltaX; 49 m_wheelTicksY = m_deltaY; 50 51 #ifndef QT_NO_WHEELEVENT 52 // Use the same single scroll step as QTextEdit 53 // (in QTextEditPrivate::init [h,v]bar->setSingleStep) 54 static const float cDefaultQtScrollStep = 20.f; 55 m_deltaX *= (fullTick) ? QApplication::wheelScrollLines() * cDefaultQtScrollStep : 1; 56 m_deltaY *= (fullTick) ? QApplication::wheelScrollLines() * cDefaultQtScrollStep : 1; 57 #endif 58 } 59 60 PlatformWheelEvent::PlatformWheelEvent(QGraphicsSceneWheelEvent* e) 61 #ifndef QT_NO_WHEELEVENT 62 : m_position(e->pos().toPoint()) 63 , m_globalPosition(e->screenPos()) 64 , m_granularity(ScrollByPixelWheelEvent) 65 , m_isAccepted(false) 66 , m_shiftKey(e->modifiers() & Qt::ShiftModifier) 67 , m_ctrlKey(e->modifiers() & Qt::ControlModifier) 68 , m_altKey(e->modifiers() & Qt::AltModifier) 69 , m_metaKey(e->modifiers() & Qt::MetaModifier) 70 #endif 71 { 72 #ifndef QT_NO_WHEELEVENT 73 applyDelta(e->delta(), e->orientation()); 74 #else 75 Q_UNUSED(e); 76 #endif 77 } 78 79 PlatformWheelEvent::PlatformWheelEvent(QWheelEvent* e) 80 #ifndef QT_NO_WHEELEVENT 81 : m_position(e->pos()) 82 , m_globalPosition(e->globalPos()) 83 , m_granularity(ScrollByPixelWheelEvent) 84 , m_isAccepted(false) 85 , m_shiftKey(e->modifiers() & Qt::ShiftModifier) 86 , m_ctrlKey(e->modifiers() & Qt::ControlModifier) 87 , m_altKey(e->modifiers() & Qt::AltModifier) 88 , m_metaKey(e->modifiers() & Qt::MetaModifier) 89 #endif 90 { 91 #ifndef QT_NO_WHEELEVENT 92 applyDelta(e->delta(), e->orientation()); 93 #else 94 Q_UNUSED(e); 95 #endif 96 } 97 98 } // namespace WebCore 99