1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef WEBTOUCHNAVIGATION_H |
|
20 #define WEBTOUCHNAVIGATION_H |
|
21 |
|
22 #include <QTime> |
|
23 #include <qobject.h> |
|
24 #include <qpoint.h> |
|
25 #include <qevent.h> |
|
26 #include <qobject.h> |
|
27 #include <qtimeline.h> |
|
28 #include <qwebframe.h> |
|
29 #include <qwebelement.h> |
|
30 #include "wrtBrowserDefs.h" |
|
31 #include <QTime> |
|
32 |
|
33 class QWebFrame; |
|
34 class QWebPage; |
|
35 class QTimer; |
|
36 |
|
37 namespace WRT |
|
38 { |
|
39 |
|
40 enum Direction |
|
41 { |
|
42 DOWN, // SOUTH |
|
43 UP, // NORTH |
|
44 RIGHT, // EAST |
|
45 LEFT, // WEST |
|
46 BOTTOMRIGHT, // SOUTHEAST |
|
47 BOTTOMLEFT, // SOUTHWEST |
|
48 TOPLEFT, // NORTHWEST |
|
49 TOPRIGHT // NORTHEAST |
|
50 }; |
|
51 |
|
52 enum PanDirection { |
|
53 HorizontalPan, |
|
54 VerticalPan, |
|
55 RandomPan |
|
56 }; |
|
57 |
|
58 class DragPoint |
|
59 { |
|
60 public: |
|
61 QPoint iPoint; |
|
62 QTime iTime; |
|
63 }; |
|
64 |
|
65 class WebTouchNavigation : public QObject |
|
66 { |
|
67 Q_OBJECT |
|
68 public: |
|
69 WebTouchNavigation(QWebPage* webPage,QObject* view); |
|
70 virtual ~WebTouchNavigation(); |
|
71 void install(); |
|
72 void uninstall(); |
|
73 void setPage( QWebPage * page){ m_webPage = page ;} |
|
74 signals: |
|
75 void longPressEvent();// mouse long press signal |
|
76 void focusElementChanged(wrtBrowserDefs::BrowserElementType &);// mouse long press signal |
|
77 void pageScrollPositionZero(); |
|
78 |
|
79 protected slots: |
|
80 void scrollToEdge(); |
|
81 void doubleClickTimerExpired(); |
|
82 void timerControl();// local slot for controlling timer |
|
83 void pan(); |
|
84 void kineticScroll(); |
|
85 void BlockFocusChanged(QPoint pt); |
|
86 protected: |
|
87 bool eventFilter(QObject *object, QEvent *event); |
|
88 void mousePressEvent(const QPoint& pos); |
|
89 void mouseMoveEvent(const QPoint& pos); |
|
90 void mouseReleaseEvent(const QPoint& pos); |
|
91 void mouseDoubleClickEvent(const QPoint& pos); |
|
92 QWebFrame* getNextScrollableFrame(const QPoint& pos); |
|
93 void scrollFrame(const QPoint& pos); |
|
94 |
|
95 void startScrollTimer(); |
|
96 void updateFlickScrollDistance(); |
|
97 bool isFlick() ; |
|
98 QPoint speed() ; |
|
99 QPoint currentPos(); |
|
100 QPoint previousPos(); |
|
101 qreal dragTime() const; |
|
102 Direction findDirectionWithAngle(const QPoint& stPoint,const QPoint& endPoint); |
|
103 bool isNear(qreal aAngleUnderTest, qreal aMinAngle, qreal aMaxAngle); |
|
104 qreal findAngle(const int& xDelta,const int& yDelta); |
|
105 int roundOff(qreal num); |
|
106 QRect findEnclosingBlock(QMouseEvent* ev); |
|
107 QWebHitTestResult getHitTestResult(QMouseEvent* ev); |
|
108 void calculateActualScrollDistance(); |
|
109 void setNewScrollDistance(QPoint blockCanvasPoint, int thresholdCheckVal); |
|
110 void handleMousePressEvent(QMouseEvent* ev); |
|
111 void handleMouseReleaseEvent(QMouseEvent* ev); |
|
112 void handleDoubleClickEvent(QMouseEvent* ev); |
|
113 |
|
114 |
|
115 private: |
|
116 void highlightableElement(QMouseEvent* ev); |
|
117 QWebElement getClosestAnchorElement(QMouseEvent* ev); |
|
118 bool traverseNextNode(QWebElement parentNode,QWebElement& nextNode); |
|
119 |
|
120 void handleHighlightChange(QMouseEvent* ev); |
|
121 bool canDehighlight(QMouseEvent* ev); |
|
122 void dehighlight(QMouseEvent* ev); |
|
123 void getFocusedElement(); |
|
124 void startTimer(); |
|
125 void stopTimer(); |
|
126 |
|
127 |
|
128 void stopScrolling(); |
|
129 |
|
130 void startPanGesture(PanDirection); |
|
131 void panBy(const QPointF& delta); |
|
132 void scrollCurrentFrame (int dx, int dy); |
|
133 void setCurrentFrameScrollPosition (QPoint& pos); |
|
134 |
|
135 private: |
|
136 QWebPage* m_webPage; |
|
137 QObject* m_view; |
|
138 QWebFrame* m_frame; |
|
139 bool m_scrolled; |
|
140 QPoint m_touchPosition; |
|
141 QPointF m_scrollDistance; |
|
142 QPointF m_actualScrollDistance; |
|
143 QPointF m_prevPoint; |
|
144 QList<DragPoint> m_dragPoints; |
|
145 Direction m_flickDirection; |
|
146 QTime m_lastMoveEventTime; |
|
147 QTimer* m_doubleClickTimer; |
|
148 QMouseEvent *m_pressEvent; |
|
149 QMouseEvent *m_releaseEvent; |
|
150 QPoint m_focusedBlockPt; |
|
151 QWebElement m_anchorElement; |
|
152 QPoint m_higlightedPos; |
|
153 bool m_ishighlighted; |
|
154 int m_offset; |
|
155 QTimer* m_longPressTimer;// long press timer |
|
156 QPoint m_initialSpeed; |
|
157 qreal m_finalzoomfactor; |
|
158 QTimer* m_scrollTimer; |
|
159 QPoint m_scrollDelta; |
|
160 QTimer* m_kineticTimer; |
|
161 QPointF m_kineticSpeed; |
|
162 QTime m_actualTime; |
|
163 int m_kineticScrollTime; |
|
164 QPoint m_initialScrollPos; |
|
165 bool m_isPanning; |
|
166 QTime m_delayedPressMoment; |
|
167 QPointF m_dragStartPos; |
|
168 PanDirection m_panDirection; |
|
169 QPointF m_panModeResidue; |
|
170 |
|
171 }; |
|
172 |
|
173 } |
|
174 |
|
175 #endif |
|