• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "PlatformWheelEvent.h"
22 
23 #include "PlatformMouseEvent.h"
24 #include "Scrollbar.h"
25 
26 #include <qapplication.h>
27 #include <QWheelEvent>
28 #include <QGraphicsSceneWheelEvent>
29 
30 namespace WebCore {
31 
applyDelta(int delta,Qt::Orientation orientation)32 void PlatformWheelEvent::applyDelta(int delta, Qt::Orientation orientation)
33 {
34     if (orientation == Qt::Horizontal) {
35         m_deltaX = (delta / 120.0f);
36         m_deltaY = 0;
37     } else {
38         m_deltaX = 0;
39         m_deltaY = (delta / 120.0f);
40     }
41 
42     m_wheelTicksX = m_deltaX;
43     m_wheelTicksY = m_deltaY;
44 
45     // Use the same single scroll step as QTextEdit
46     // (in QTextEditPrivate::init [h,v]bar->setSingleStep)
47     static const float cDefaultQtScrollStep = 20.f;
48 #ifndef QT_NO_WHEELEVENT
49     m_deltaX *= QApplication::wheelScrollLines() * cDefaultQtScrollStep;
50     m_deltaY *= QApplication::wheelScrollLines() * cDefaultQtScrollStep;
51 #endif
52 }
53 
PlatformWheelEvent(QGraphicsSceneWheelEvent * e)54 PlatformWheelEvent::PlatformWheelEvent(QGraphicsSceneWheelEvent* e)
55 #ifdef QT_NO_WHEELEVENT
56 {
57     Q_UNUSED(e);
58 }
59 #else
60     : m_position(e->pos().toPoint())
61     , m_globalPosition(e->screenPos())
62     , m_granularity(ScrollByPixelWheelEvent)
63     , m_isAccepted(false)
64     , m_shiftKey(e->modifiers() & Qt::ShiftModifier)
65     , m_ctrlKey(e->modifiers() & Qt::ControlModifier)
66     , m_altKey(e->modifiers() & Qt::AltModifier)
67     , m_metaKey(e->modifiers() & Qt::MetaModifier)
68 {
69     applyDelta(e->delta(), e->orientation());
70 }
71 #endif // QT_NO_WHEELEVENT
72 
PlatformWheelEvent(QWheelEvent * e)73 PlatformWheelEvent::PlatformWheelEvent(QWheelEvent* e)
74 #ifdef QT_NO_WHEELEVENT
75 {
76     Q_UNUSED(e);
77 }
78 #else
79     : m_position(e->pos())
80     , m_globalPosition(e->globalPos())
81     , m_granularity(ScrollByPixelWheelEvent)
82     , m_isAccepted(false)
83     , m_shiftKey(e->modifiers() & Qt::ShiftModifier)
84     , m_ctrlKey(e->modifiers() & Qt::ControlModifier)
85     , m_altKey(e->modifiers() & Qt::AltModifier)
86     , m_metaKey(e->modifiers() & Qt::MetaModifier)
87 {
88     applyDelta(e->delta(), e->orientation());
89 }
90 #endif // QT_NO_WHEELEVENT
91 
92 } // namespace WebCore
93