1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * |
5 * under the terms of "Eclipse Public License v1.0" |
5 * This program is free software: you can redistribute it and/or modify |
6 * which accompanies this distribution, and is available |
6 * it under the terms of the GNU Lesser General Public License as published by |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * the Free Software Foundation, version 2.1 of the License. |
8 * |
8 * |
9 * Initial Contributors: |
9 * This program is distributed in the hope that it will be useful, |
10 * Nokia Corporation - initial contribution. |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * Contributors: |
12 * GNU Lesser General Public License for more details. |
13 * |
13 * |
14 * Description: |
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
15 * |
19 * |
16 */ |
20 */ |
17 |
21 |
18 |
|
19 /* Temporary implementation of WebTouchNavigation until gestures are ready. */ |
22 /* Temporary implementation of WebTouchNavigation until gestures are ready. */ |
20 |
23 |
21 #ifndef WEBTOUCHNAVIGATION_H |
24 #ifndef GWEBTOUCHNAVIGATION_H |
22 #define WEBTOUCHNAVIGATION_H |
25 #define GWEBTOUCHNAVIGATION_H |
23 |
26 |
24 #include <QTime> |
27 #include <QTime> |
25 #include <qobject.h> |
28 #include <QObject> |
26 #include <qpoint.h> |
29 #include <QPoint> |
27 #include <qevent.h> |
30 #include <QEvent> |
28 #include <qobject.h> |
31 #include <QTimeLine> |
29 #include <qtimeline.h> |
32 #include <QWebFrame> |
30 #include <qwebframe.h> |
33 #include <QWebElement> |
31 #include <qwebelement.h> |
|
32 #include <QWebPage> |
34 #include <QWebPage> |
|
35 #include <QGraphicsWebView> |
33 #include "wrtBrowserDefs.h" |
36 #include "wrtBrowserDefs.h" |
34 |
37 |
35 |
38 |
36 class QWebFrame; |
39 class QWebFrame; |
37 class QWebPage; |
40 class QWebPage; |
38 class QTimer; |
41 class QTimer; |
|
42 class QWebElement; |
|
43 class WebViewEventContext; |
39 |
44 |
40 namespace GVA |
45 namespace GVA |
41 { |
46 { |
42 class GWebContentViewWidget; |
47 class GWebContentViewWidget; |
43 class ChromeWidget; |
48 class ChromeWidget; |
44 |
49 |
45 enum Direction |
|
46 { |
|
47 DOWN, // SOUTH |
|
48 UP, // NORTH |
|
49 RIGHT, // EAST |
|
50 LEFT, // WEST |
|
51 BOTTOMRIGHT, // SOUTHEAST |
|
52 BOTTOMLEFT, // SOUTHWEST |
|
53 TOPLEFT, // NORTHWEST |
|
54 TOPRIGHT // NORTHEAST |
|
55 }; |
|
56 |
|
57 enum PanDirection { |
|
58 HorizontalPan, |
|
59 VerticalPan, |
|
60 RandomPan |
|
61 }; |
|
62 |
|
63 class DragPoint |
|
64 { |
|
65 public: |
|
66 QPoint iPoint; |
|
67 QTime iTime; |
|
68 }; |
|
69 |
|
70 class GWebTouchNavigation : public QObject |
50 class GWebTouchNavigation : public QObject |
71 { |
51 { |
72 Q_OBJECT |
52 Q_OBJECT |
73 public: |
53 public: |
74 GWebTouchNavigation(QWebPage* webPage, GWebContentViewWidget* view); |
54 enum Direction |
|
55 { |
|
56 DOWN, // SOUTH |
|
57 UP, // NORTH |
|
58 RIGHT, // EAST |
|
59 LEFT, // WEST |
|
60 BOTTOMRIGHT, // SOUTHEAST |
|
61 BOTTOMLEFT, // SOUTHWEST |
|
62 TOPLEFT, // NORTHWEST |
|
63 TOPRIGHT, // NORTHEAST |
|
64 NONE, |
|
65 }; |
|
66 |
|
67 enum PanDirection { |
|
68 HorizontalPan, |
|
69 VerticalPan, |
|
70 RandomPan |
|
71 }; |
|
72 |
|
73 class DragPoint |
|
74 { |
|
75 public: |
|
76 QPoint iPoint; |
|
77 QTime iTime; |
|
78 }; |
|
79 |
|
80 GWebTouchNavigation(QWebPage* webPage, QGraphicsWebView* view); |
75 virtual ~GWebTouchNavigation(); |
81 virtual ~GWebTouchNavigation(); |
76 void install(); |
82 void install(); |
77 void uninstall(); |
83 void uninstall(); |
78 void setPage( QWebPage * page); |
84 void setPage( QWebPage * page); |
79 bool enabled() const { return m_enabled; } |
85 bool enabled() const { return m_enabled; } |
80 void setEnabled(bool value) { m_enabled = value; } |
86 void setEnabled(bool value) { m_enabled = value; } |
81 void setChromeWidget(ChromeWidget* chrome) { m_chrome = chrome;} |
87 void setWantSlideViewCalls(bool value) { m_wantSlideViewCalls = value; } |
82 |
88 |
83 signals: |
89 signals: |
84 void longPressEvent();// mouse long press signal |
90 void longPressEvent(QPoint pos);// mouse long press signal |
85 void focusElementChanged(wrtBrowserDefs::BrowserElementType &);// mouse long press signal |
91 void focusElementChanged(wrtBrowserDefs::BrowserElementType &); |
86 void pageScrollPositionZero(); |
92 void pageScrollPositionZero(); |
87 |
93 |
88 /// Sent when this object starts panning/scrolling the page. Can be useful for |
94 /// Sent when this object starts panning/scrolling the page. Can be useful for |
89 /// cancelling things like long-press timers which otherwise wouldn't get |
95 /// cancelling things like long-press timers which otherwise wouldn't get |
90 /// mouse-move events. |
96 /// mouse-move events. |
91 void startingPanGesture(int directionHint); |
97 void startingPanGesture(int directionHint); |
92 void mouseEvent(QEvent::Type type); |
98 void mouseEvent(QEvent::Type type); |
93 |
99 |
|
100 |
94 protected slots: |
101 protected slots: |
95 void scrollToEdge(); |
102 void scrollToEdge(); |
96 void doubleClickTimerExpired(); |
103 void doubleClickTimerExpired(); |
97 void timerControl();// local slot for controlling timer |
104 void onLongPressTimer(); |
98 void pan(); |
105 void pan(); |
99 void kineticScroll(); |
106 void kineticScroll(); |
100 void BlockFocusChanged(QPoint pt); |
107 void BlockFocusChanged(QPoint pt); |
101 void onLoadStarted(); |
108 void onLoadStarted(); |
102 void onLoadFinished(bool ok); |
109 void onLoadFinished(bool ok); |
|
110 void onContentsSizeChanged(const QSize &); |
|
111 void enableDClick(bool aValue); |
|
112 |
103 protected: |
113 protected: |
104 bool eventFilter(QObject *object, QEvent *event); |
114 bool eventFilter(QObject *object, QEvent *event); |
105 void mousePressEvent(const QPoint& pos); |
115 void mousePressEvent(const QPoint& pos); |
106 void mouseMoveEvent(const QPoint& pos, const QPoint& diff); |
116 void mouseMoveEvent(const QPoint& pos, const QPoint& diff); |
107 void mouseReleaseEvent(const QPoint& pos); |
117 void mouseReleaseEvent(const QPoint& pos); |
108 void mouseDoubleClickEvent(const QPoint& pos); |
118 void mouseDoubleClickEvent(const QPoint& pos); |
|
119 void contextMenuEvent(); |
109 QWebFrame* getNextScrollableFrame(const QPoint& pos); |
120 QWebFrame* getNextScrollableFrame(const QPoint& pos); |
110 void scrollFrame(const QPoint& diff); |
121 void scrollFrame(const QPoint& diff); |
111 |
122 |
112 void startScrollTimer(); |
123 void startScrollTimer(); |
113 void updateFlickScrollDistance(); |
124 void updateFlickScrollDistance(); |
114 bool isFlick() ; |
125 bool isFlick() ; |
115 QPoint speed() ; |
126 QPoint speed() ; |
116 QPoint currentPos(); |
127 QPoint currentPos(); |
122 int roundOff(qreal num); |
133 int roundOff(qreal num); |
123 QRect findEnclosingBlock(QMouseEvent* ev); |
134 QRect findEnclosingBlock(QMouseEvent* ev); |
124 QWebHitTestResult getHitTestResult(QMouseEvent* ev); |
135 QWebHitTestResult getHitTestResult(QMouseEvent* ev); |
125 void calculateActualScrollDistance(); |
136 void calculateActualScrollDistance(); |
126 void setNewScrollDistance(QPoint blockCanvasPoint, int thresholdCheckVal); |
137 void setNewScrollDistance(QPoint blockCanvasPoint, int thresholdCheckVal); |
127 void handleMousePressEvent(QMouseEvent* ev); |
138 void handleMousePressEvent(QMouseEvent* ev); |
128 void handleMouseReleaseEvent(QMouseEvent* ev); |
139 void handleMouseReleaseEvent(QMouseEvent* ev); |
129 void handleDoubleClickEvent(QMouseEvent* ev); |
140 void handleDoubleClickEvent(QMouseEvent* ev); |
130 |
141 void cancelPressEvent(); |
131 |
142 void cancelReleaseEvent(); |
132 private: |
143 |
133 void highlightableElement(QMouseEvent* ev); |
144 // Methods that can be overridden in subclasses. Mainly here so that |
134 QWebElement getClosestAnchorElement(QMouseEvent* ev); |
145 // we can create a subclass that can interact with GWebContentViewWidget |
135 bool traverseNextNode(QWebElement parentNode,QWebElement& nextNode); |
146 // and ChromeWidget, and still handle generic QWebViews. |
136 |
147 virtual qreal slideView(qreal delta) { Q_UNUSED(delta) return 0; } |
137 void handleHighlightChange(QMouseEvent* ev); |
148 virtual qreal shrinkView(qreal delta) { Q_UNUSED(delta) return 0; } |
138 bool canDehighlight(QMouseEvent* ev); |
149 virtual void setViewBlockElement(const QWebElement &el) { Q_UNUSED(el) } |
139 void dehighlight(QMouseEvent* ev); |
150 virtual qreal viewInitialScale() { return 1; } |
140 void getFocusedElement(); |
151 virtual void setViewZoomFactor(qreal zoom) { Q_UNUSED(zoom) } |
141 void startTimer(); |
152 |
142 void stopTimer(); |
153 private: |
143 |
154 void highlightableElement(QMouseEvent* ev); |
144 |
155 QWebElement getClosestAnchorElement(QMouseEvent* ev); |
145 void stopScrolling(); |
156 bool traverseNextNode(QWebElement parentNode,QWebElement& nextNode); |
|
157 |
|
158 void handleHighlightChange(QMouseEvent* ev); |
|
159 bool canDehighlight(QMouseEvent* ev); |
|
160 void dehighlight(QMouseEvent* ev); |
|
161 void emitFocusedElementChanged(); |
|
162 void startLongPressTimer(); |
|
163 void stopLongPressTimer(); |
|
164 |
|
165 void stopScrolling(); |
146 void startPanGesture(PanDirection); |
166 void startPanGesture(PanDirection); |
147 void panBy(const QPointF& delta); |
167 void panBy(const QPointF& delta); |
148 void scrollCurrentFrame (int dx, int dy); |
168 void scrollCurrentFrame (int dx, int dy); |
149 void setCurrentFrameScrollPosition (QPoint& pos); |
169 void setCurrentFrameScrollPosition (QPoint& pos); |
150 |
170 |
151 Qt::KeyboardModifier getEventModifier(const QPoint& pos); |
171 Qt::KeyboardModifier getEventModifier(const QPoint& pos); |
152 |
172 |
153 private: |
173 protected: |
154 QWebPage* m_webPage; |
174 QWebPage* m_webPage; |
155 GWebContentViewWidget* m_view; |
175 QGraphicsWebView* m_view; |
156 QWebFrame* m_frame; |
176 QWebFrame* m_frame; |
157 ChromeWidget* m_chrome; |
|
158 bool m_scrolled; |
177 bool m_scrolled; |
159 QPoint m_touchPosition; |
178 QPoint m_touchPosition; |
160 QPointF m_scrollDistance; |
179 QPointF m_scrollDistance; |
161 QPointF m_actualScrollDistance; |
180 QPointF m_actualScrollDistance; |
162 QPointF m_prevPoint; |
181 QPointF m_prevPoint; |
163 QList<DragPoint> m_dragPoints; |
182 QList<DragPoint> m_dragPoints; |
164 Direction m_flickDirection; |
183 Direction m_flickDirection; |
165 QTime m_lastMoveEventTime; |
184 QTime m_lastMoveEventTime; |
166 QTimer* m_doubleClickTimer; |
185 QTimer* m_doubleClickTimer; |
167 QMouseEvent *m_pressEvent; |
186 QMouseEvent *m_pressEvent; |
168 QMouseEvent *m_releaseEvent; |
187 QMouseEvent *m_releaseEvent; |
169 QPoint m_focusedBlockPt; |
188 QPoint m_focusedBlockPt; |
170 QWebElement m_anchorElement; |
189 QWebElement m_anchorElement; |
171 QPoint m_higlightedPos; |
190 QPoint m_higlightedPos; |
172 bool m_ishighlighted; |
191 bool m_ishighlighted; |
173 int m_offset; |
192 int m_offset; |
174 QTimer* m_longPressTimer;// long press timer |
193 QTimer* m_longPressTimer;// long press timer |
175 QPoint m_initialSpeed; |
194 QPoint m_longPressPosition; |
176 qreal m_finalzoomfactor; |
195 QPoint m_initialSpeed; |
177 QTimer* m_scrollTimer; |
196 qreal m_finalzoomfactor; |
178 QPoint m_scrollDelta; |
197 QTimer* m_scrollTimer; |
179 QTimer* m_kineticTimer; |
198 QPoint m_scrollDelta; |
180 QPointF m_kineticSpeed; |
199 QTimer* m_kineticTimer; |
181 QTime m_actualTime; |
200 QPointF m_kineticSpeed; |
182 int m_kineticScrollTime; |
201 QTime m_actualTime; |
183 QPoint m_initialScrollPos; |
202 int m_kineticScrollTime; |
184 bool m_isPanning; |
203 QPoint m_initialScrollPos; |
|
204 bool m_isPanning; |
185 QTime m_delayedPressMoment; |
205 QTime m_delayedPressMoment; |
186 QPointF m_dragStartPos; |
206 QPointF m_dragStartPos; |
187 PanDirection m_panDirection; |
207 PanDirection m_panDirection; |
188 QPointF m_panModeResidue; |
208 QPointF m_panModeResidue; |
189 bool m_enabled; |
209 bool m_enabled; |
|
210 bool m_textSelected; // whether the text of an input field is selected manually |
|
211 |
|
212 bool m_isLoading; |
|
213 int m_contentHeight; |
|
214 // m_isContextEvent is set to true when a context menu event is received |
|
215 // and then cleared when on mouse release events. Mouse release events |
|
216 // are ignored when this flags is true to avoid activating links when |
|
217 // the context menu is activated over them. |
|
218 bool m_isContextEvent; |
|
219 // Flag that governs whether calls to slideView should be made or not. |
|
220 bool m_wantSlideViewCalls; |
190 |
221 |
191 bool m_isLoading; |
222 bool m_doubleClickEnabled; |
192 }; |
223 }; |
193 |
224 |
194 } |
225 } |
195 |
226 |
196 #endif |
227 #endif |