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 |
|
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 * |
4 * |
9 * Initial Contributors: |
5 * This program is free software: you can redistribute it and/or modify |
10 * Nokia Corporation - initial contribution. |
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
11 * |
8 * |
12 * Contributors: |
9 * This program 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 |
|
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/". |
15 * |
17 * |
16 */ |
18 * Description: |
17 |
19 * |
|
20 */ |
18 |
21 |
19 #include "GWebTouchNavigation.h" |
22 #include "GWebTouchNavigation.h" |
20 #include "qwebpage.h" |
23 #include "wrtBrowserUtils.h" |
21 #include "qwebframe.h" |
24 |
22 #include "qapplication.h" |
25 #include <QWebPage> |
23 #include "qwebelement.h" |
26 #include <QWebFrame> |
24 #include "GWebContentViewWidget.h" |
27 #include <QApplication> |
25 #include "GWebContentView.h" |
28 #include <QWebElement> |
26 #include <QGraphicsSceneMouseEvent> |
29 #include <QGraphicsSceneMouseEvent> |
27 #include <QTimer> |
30 #include <QTimer> |
28 #include <qmath.h> |
31 #include <qmath.h> |
29 #include <QDebug> |
32 #include <QDebug> |
30 #include <QGraphicsView> |
33 #include <QGraphicsView> |
31 |
34 |
32 #include "webcontentview.h" |
35 |
33 #include "wrtBrowserUtils.h" |
36 namespace GVA { |
34 #include "ChromeWidget.h" |
|
35 #include <qdebug.h> |
|
36 |
|
37 |
|
38 #define LONG_PRESS_DURATION 500 |
|
39 |
37 |
40 const int KFlickSpeed = 400; |
38 const int KFlickSpeed = 400; |
41 const qreal PI = 3.1415926535897932; |
39 const qreal PI = 3.1415926535897932; |
42 const qreal KAngleTolerance = 30; |
40 const qreal KAngleTolerance = 30; |
43 const int KAnimationTimeout = 40; |
41 const int KAnimationTimeout = 40; |
53 const int KTouchThresholdX = 20; |
51 const int KTouchThresholdX = 20; |
54 const int KTouchThresholdY = 20; |
52 const int KTouchThresholdY = 20; |
55 const int KPanThreshold = 2; |
53 const int KPanThreshold = 2; |
56 const int KThreshHoldValForLink = 10; |
54 const int KThreshHoldValForLink = 10; |
57 const qreal KDeccelaration = 1000.00; |
55 const qreal KDeccelaration = 1000.00; |
58 const int KDefaultViewportWidth = 980; |
|
59 const int KDefaultPortraitScaleWidth = 540; |
|
60 |
|
61 const int KKineticTimeout = 60; |
|
62 |
56 |
63 static const int KStartPanDistance = 50; |
57 static const int KStartPanDistance = 50; |
64 static const int KWaitForClickTimeoutMS = 200; |
58 static const int KWaitForClickTimeoutMS = 200; |
|
59 static const int KLongPressDuration = 1000; |
|
60 static const int KLongPressThreshold = 30; |
65 //The amount of pixels to try to pan before pan mode unlocks |
61 //The amount of pixels to try to pan before pan mode unlocks |
66 static const int KPanModeChangeDelta = 100; |
62 static const int KPanModeChangeDelta = 100; |
67 |
|
68 |
|
69 namespace GVA { |
|
70 |
63 |
71 /*! |
64 /*! |
72 \class WebTouchNavigation |
65 \class WebTouchNavigation |
73 \since cwrt 1.0 |
66 \since cwrt 1.0 |
74 \brief cwrt navigation. |
67 \brief cwrt navigation. |
75 |
68 |
76 \sa WebNavigation, WebHtmlTabIndexedNavigation, WebCursorNavigation, WebDirectionalNavigation |
69 \sa WebNavigation, WebHtmlTabIndexedNavigation, WebCursorNavigation, WebDirectionalNavigation |
77 */ |
70 */ |
78 GWebTouchNavigation::GWebTouchNavigation(QWebPage* webPage,GWebContentViewWidget* view) |
71 GWebTouchNavigation::GWebTouchNavigation(QWebPage* webPage, QGraphicsWebView* view) |
79 : m_webPage(webPage) |
72 : m_webPage(webPage) |
80 , m_view(view) |
73 , m_view(view) |
81 , m_frame(0) |
74 , m_frame(0) |
82 , m_doubleClickTimer(0) |
75 , m_doubleClickTimer(0) |
83 , m_pressEvent(0) |
76 , m_pressEvent(0) |
84 , m_scrollTimer(0) |
|
85 , m_releaseEvent(0) |
77 , m_releaseEvent(0) |
86 , m_focusedBlockPt(-1, -1) |
78 , m_focusedBlockPt(-1, -1) |
87 , m_ishighlighted(false) |
79 , m_ishighlighted(false) |
88 , m_offset(0) |
80 , m_offset(0) |
89 , m_longPressTimer(0) |
81 , m_longPressTimer(0) |
90 , m_finalzoomfactor(0) |
82 , m_finalzoomfactor(0) |
|
83 , m_scrollTimer(0) |
91 , m_kineticTimer(0) |
84 , m_kineticTimer(0) |
92 , m_isPanning(false) |
85 , m_isPanning(false) |
93 , m_enabled(true) |
86 , m_enabled(true) |
|
87 , m_textSelected(false) |
94 , m_isLoading(false) |
88 , m_isLoading(false) |
|
89 , m_contentHeight(0) |
|
90 , m_isContextEvent(false) |
|
91 , m_wantSlideViewCalls(true) |
|
92 , m_doubleClickEnabled(true) |
95 { |
93 { |
96 install(); |
94 install(); |
97 connect(m_view, SIGNAL(BlockFocusChanged(QPoint)), this, SLOT(BlockFocusChanged(QPoint))); |
|
98 connect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
95 connect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
99 connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
96 connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
100 } |
97 } |
101 |
98 |
|
99 inline void GWebTouchNavigation::cancelPressEvent() { |
|
100 if (m_pressEvent) { |
|
101 delete m_pressEvent; |
|
102 m_pressEvent = 0; |
|
103 } |
|
104 } |
|
105 |
|
106 inline void GWebTouchNavigation::cancelReleaseEvent() { |
|
107 if (m_releaseEvent) { |
|
108 delete m_releaseEvent; |
|
109 m_releaseEvent = 0; |
|
110 } |
|
111 } |
|
112 |
102 /*! |
113 /*! |
103 */ |
114 */ |
104 GWebTouchNavigation::~GWebTouchNavigation() |
115 GWebTouchNavigation::~GWebTouchNavigation() |
105 { |
116 { |
106 disconnect(m_doubleClickTimer, SIGNAL(timeout()), this, SLOT(doubleClickTimerExpired())); |
117 delete m_doubleClickTimer; |
107 if (m_doubleClickTimer) { |
|
108 m_doubleClickTimer->stop(); |
|
109 delete m_doubleClickTimer; |
|
110 } |
|
111 disconnect(m_scrollTimer, SIGNAL(timeout()),this,SLOT(pan())); |
|
112 delete m_scrollTimer; |
118 delete m_scrollTimer; |
113 |
|
114 disconnect(m_kineticTimer, SIGNAL(timeout()),this,SLOT(kineticScroll())); |
|
115 delete m_kineticTimer; |
119 delete m_kineticTimer; |
|
120 delete m_longPressTimer; |
116 uninstall(); |
121 uninstall(); |
|
122 |
|
123 cancelPressEvent(); |
|
124 cancelReleaseEvent(); |
117 } |
125 } |
118 |
126 |
119 void GWebTouchNavigation::install() |
127 void GWebTouchNavigation::install() |
120 { |
128 { |
121 m_view->installEventFilter(this); |
129 m_view->installEventFilter(this); |
122 } |
130 } |
123 |
131 |
124 void GWebTouchNavigation::BlockFocusChanged(QPoint pt) |
132 void GWebTouchNavigation::BlockFocusChanged(QPoint pt) |
125 { |
133 { |
126 m_focusedBlockPt = pt; |
134 m_focusedBlockPt = pt; |
127 } |
135 } |
128 |
136 |
129 void GWebTouchNavigation::uninstall() |
137 void GWebTouchNavigation::uninstall() |
130 { |
138 { |
131 if (m_view) |
139 if (m_view) |
169 QPoint diff = static_cast<QGraphicsSceneMouseEvent*>(event)->lastScenePos().toPoint() - static_cast<QGraphicsSceneMouseEvent*>(event)->scenePos().toPoint(); |
177 QPoint diff = static_cast<QGraphicsSceneMouseEvent*>(event)->lastScenePos().toPoint() - static_cast<QGraphicsSceneMouseEvent*>(event)->scenePos().toPoint(); |
170 mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent*>(event)->pos().toPoint(), diff); |
178 mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent*>(event)->pos().toPoint(), diff); |
171 return true; |
179 return true; |
172 } |
180 } |
173 break; |
181 break; |
174 case QEvent::GraphicsSceneMouseRelease: |
182 case QEvent::GraphicsSceneMouseRelease: |
175 mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent*>(event)->pos().toPoint()); |
183 mouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent*>(event)->pos().toPoint()); |
176 emit mouseEvent(QEvent::GraphicsSceneMouseRelease); |
184 emit mouseEvent(QEvent::GraphicsSceneMouseRelease); |
177 return true; |
185 return true; |
178 break; |
|
179 case QEvent::GraphicsSceneMouseDoubleClick: |
186 case QEvent::GraphicsSceneMouseDoubleClick: |
180 mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent*>(event)->pos().toPoint()); |
187 mouseDoubleClickEvent(static_cast<QGraphicsSceneMouseEvent*>(event)->pos().toPoint()); |
181 emit mouseEvent(QEvent::GraphicsSceneMouseDoubleClick); |
188 emit mouseEvent(QEvent::GraphicsSceneMouseDoubleClick); |
182 return true; |
189 return true; |
|
190 case QEvent::GraphicsSceneContextMenu: |
|
191 contextMenuEvent(); |
183 break; |
192 break; |
184 default: |
193 default: |
185 break; |
194 break; |
186 } |
195 } |
187 return false; |
196 return false; |
188 } |
197 } |
189 |
198 |
190 void GWebTouchNavigation::stopScrolling() |
199 void GWebTouchNavigation::stopScrolling() |
191 { |
200 { |
192 if (m_scrollTimer && m_scrollTimer->isActive()) { |
201 if (m_scrollTimer && m_scrollTimer->isActive()) { |
193 m_scrollTimer->stop(); |
202 m_scrollTimer->stop(); |
194 m_scrollDelta = QPoint(0,0); |
203 m_scrollDelta = QPoint(0,0); |
195 } |
204 } |
196 |
205 |
197 if (m_kineticTimer && m_kineticTimer->isActive()) { |
206 if (m_kineticTimer && m_kineticTimer->isActive()) { |
198 m_kineticTimer->stop(); |
207 m_kineticTimer->stop(); |
199 m_kineticSpeed.setX(0.0); |
208 m_kineticSpeed.setX(0.0); |
200 m_kineticSpeed.setY(0.0); |
209 m_kineticSpeed.setY(0.0); |
201 } |
210 } |
202 } |
211 } |
203 |
212 |
204 |
213 |
205 void GWebTouchNavigation::pan() |
214 void GWebTouchNavigation::pan() |
206 { |
215 { |
207 if (m_scrollDelta.x() != 0 || m_scrollDelta.y() != 0) { |
216 if (m_scrollDelta.x() != 0 || m_scrollDelta.y() != 0) { |
208 scrollCurrentFrame(-m_scrollDelta.x(), m_scrollDelta.y()); |
217 scrollCurrentFrame(-m_scrollDelta.x(), m_scrollDelta.y()); |
209 m_scrollDelta = QPoint(0,0); |
218 m_scrollDelta = QPoint(0,0); |
210 } |
219 } |
211 } |
220 } |
212 |
221 |
213 #define DECELERATION 0.0002 |
222 #define DECELERATION 0.0002 |
214 |
223 |
215 void GWebTouchNavigation::kineticScroll() |
224 void GWebTouchNavigation::kineticScroll() |
216 { |
225 { |
217 qreal decelX = m_kineticSpeed.x() > 0 ? -DECELERATION : DECELERATION; |
226 qreal decelX = m_kineticSpeed.x() > 0 ? -DECELERATION : DECELERATION; |
218 qreal decelY = m_kineticSpeed.y() > 0 ? -DECELERATION : DECELERATION; |
227 qreal decelY = m_kineticSpeed.y() > 0 ? -DECELERATION : DECELERATION; |
219 qreal dx = 0; |
228 qreal dx = 0; |
220 qreal dy = 0; |
229 qreal dy = 0; |
221 qreal vx = 0; |
230 qreal vx = 0; |
222 qreal vy = 0; |
231 qreal vy = 0; |
223 |
232 |
224 m_kineticScrollTime += m_actualTime.elapsed(); |
233 m_kineticScrollTime += m_actualTime.elapsed(); |
225 |
234 |
226 if (m_kineticSpeed.x()) { |
235 if (m_kineticSpeed.x()) { |
227 vx = m_kineticSpeed.x() + decelX * m_kineticScrollTime; |
236 vx = m_kineticSpeed.x() + decelX * m_kineticScrollTime; |
228 if (vx * m_kineticSpeed.x() < 0) { |
237 if (vx * m_kineticSpeed.x() < 0) { |
229 dx = 0; |
238 dx = 0; |
230 vx = 0; |
239 vx = 0; |
231 } |
240 } |
232 else { |
241 else { |
233 dx = m_kineticScrollTime * m_kineticSpeed.x() + |
242 dx = m_kineticScrollTime * m_kineticSpeed.x() + |
234 0.5 * decelX * m_kineticScrollTime * m_kineticScrollTime; |
243 0.5 * decelX * m_kineticScrollTime * m_kineticScrollTime; |
235 } |
244 } |
236 } |
245 } |
237 |
246 |
238 if (m_kineticSpeed.y()) { |
247 if (m_kineticSpeed.y()) { |
239 vy = m_kineticSpeed.y() + decelY * m_kineticScrollTime; |
248 vy = m_kineticSpeed.y() + decelY * m_kineticScrollTime; |
240 if (vy * m_kineticSpeed.y() < 0) { |
249 if (vy * m_kineticSpeed.y() < 0) { |
241 dy = 0; |
250 dy = 0; |
242 vy = 0; |
251 vy = 0; |
243 } |
252 } |
244 else { |
253 else { |
245 dy = m_kineticScrollTime * m_kineticSpeed.y() + |
254 dy = m_kineticScrollTime * m_kineticSpeed.y() + |
246 0.5 * decelY * m_kineticScrollTime * m_kineticScrollTime; |
255 0.5 * decelY * m_kineticScrollTime * m_kineticScrollTime; |
247 } |
256 } |
248 } |
257 } |
249 |
258 |
250 QPoint scrollPos = m_frame->scrollPosition(); |
259 QPoint scrollPos = m_frame->scrollPosition(); |
251 QPoint distPos = m_initialScrollPos + QPointF(dx, dy).toPoint(); |
260 QPoint distPos = m_initialScrollPos + QPointF(dx, dy).toPoint(); |
252 |
261 |
253 if (vx != 0 || vy != 0) { |
262 if (vx != 0 || vy != 0) { |
254 setCurrentFrameScrollPosition(distPos); |
263 setCurrentFrameScrollPosition(distPos); |
255 } |
264 } |
256 |
265 |
257 if ((vx == 0 && vy == 0) || scrollPos == m_frame->scrollPosition()) { |
266 if ((vx == 0 && vy == 0) || scrollPos == m_frame->scrollPosition()) { |
258 stopScrolling(); |
267 stopScrolling(); |
259 } |
268 } |
260 |
269 |
261 } |
270 } |
262 |
271 |
263 |
272 |
268 */ |
277 */ |
269 void GWebTouchNavigation::scrollFrame(const QPoint& diff) |
278 void GWebTouchNavigation::scrollFrame(const QPoint& diff) |
270 { |
279 { |
271 if (qAbs(diff.x()) < KPanThreshold && qAbs(diff.y()) < KPanThreshold) |
280 if (qAbs(diff.x()) < KPanThreshold && qAbs(diff.y()) < KPanThreshold) |
272 return; |
281 return; |
273 else if(m_dragPoints.size() == 1) { |
282 else if (m_dragPoints.size() == 1) { |
274 //WebContentWidget* view = qobject_cast<WebContentWidget*>(m_view); |
283 setViewBlockElement(QWebElement()); |
275 m_view->setBlockElement(QWebElement()); |
284 } |
276 } |
285 |
277 |
286 if (!m_isPanning) { |
278 if(!m_isPanning) { |
|
279 qreal dy = qAbs(diff.y()); |
287 qreal dy = qAbs(diff.y()); |
280 qreal dx = qAbs(diff.x()); |
288 qreal dx = qAbs(diff.x()); |
281 if (dy > KStartPanDistance || dx > KStartPanDistance |
289 if (dy > KStartPanDistance || dx > KStartPanDistance |
282 || m_delayedPressMoment.elapsed() > KWaitForClickTimeoutMS) { |
290 || m_delayedPressMoment.elapsed() > KWaitForClickTimeoutMS) { |
283 //get the scroll direction |
291 //get the scroll direction |
284 Direction scrollDir = findDirectionWithAngle(diff); |
292 Direction scrollDir = findDirectionWithAngle(diff); |
285 if(scrollDir == UP || scrollDir == DOWN) |
293 if (scrollDir == UP || scrollDir == DOWN) |
286 startPanGesture(VerticalPan); |
294 startPanGesture(VerticalPan); |
287 else if(scrollDir == LEFT || scrollDir == RIGHT) |
295 else if (scrollDir == LEFT || scrollDir == RIGHT) |
288 startPanGesture(HorizontalPan); |
296 startPanGesture(HorizontalPan); |
289 else |
297 else |
290 startPanGesture(RandomPan); |
298 startPanGesture(RandomPan); |
291 m_isPanning = true; |
299 m_isPanning = true; |
292 } |
300 } |
293 } |
301 } |
294 |
302 |
295 if (m_isPanning) { |
303 if (m_isPanning) { |
296 m_scrolled= false; |
304 m_scrolled= false; |
297 m_frame = getNextScrollableFrame(diff); |
305 m_frame = getNextScrollableFrame(diff); |
298 QPoint scrollPosition = m_frame->scrollPosition(); |
306 QPoint scrollPosition = m_frame->scrollPosition(); |
299 if (diff.manhattanLength()) |
307 if (diff.manhattanLength()) |
300 panBy(diff); |
308 panBy(diff); |
301 |
309 |
302 m_scrolled = (scrollPosition != m_frame->scrollPosition()); |
310 m_scrolled = (scrollPosition != m_frame->scrollPosition()); |
303 } |
311 } |
304 } |
312 } |
305 |
313 |
306 void GWebTouchNavigation::startPanGesture(PanDirection directionHint) { |
314 void GWebTouchNavigation::startPanGesture(PanDirection directionHint) { |
307 emit startingPanGesture((int)directionHint); |
315 emit startingPanGesture((int)directionHint); |
308 m_panDirection = directionHint; |
316 m_panDirection = directionHint; |
309 m_panModeResidue = QPointF(0., 0.); |
317 m_panModeResidue = QPointF(0., 0.); |
310 } |
318 } |
311 |
319 |
312 void GWebTouchNavigation::panBy(const QPointF& delta) { |
320 void GWebTouchNavigation::panBy(const QPointF& delta) { |
313 |
321 |
314 m_panModeResidue += delta; |
322 m_panModeResidue += delta; |
315 |
323 |
316 if (qAbs(m_panModeResidue.x()) > KPanModeChangeDelta) |
324 if (qAbs(m_panModeResidue.x()) > KPanModeChangeDelta) |
317 m_panDirection = HorizontalPan; |
325 m_panDirection = HorizontalPan; |
318 |
326 |
319 if (qAbs(m_panModeResidue.y()) > KPanModeChangeDelta) |
327 if (qAbs(m_panModeResidue.y()) > KPanModeChangeDelta) |
320 m_panDirection = VerticalPan; |
328 m_panDirection = VerticalPan; |
321 |
329 |
322 if(qAbs(m_panModeResidue.x()) > KPanModeChangeDelta |
330 if (qAbs(m_panModeResidue.x()) > KPanModeChangeDelta |
323 && qAbs(m_panModeResidue.y()) > KPanModeChangeDelta) |
331 && qAbs(m_panModeResidue.y()) > KPanModeChangeDelta) |
324 m_panDirection = RandomPan; |
332 m_panDirection = RandomPan; |
325 |
333 |
326 QPointF p; |
334 QPointF p; |
327 if(m_panDirection == HorizontalPan) |
335 if (m_panDirection == HorizontalPan) |
328 p.setX(delta.x()); |
336 p.setX(delta.x()); |
329 if(m_panDirection == VerticalPan) |
337 if (m_panDirection == VerticalPan) |
330 p.setY(delta.y()); |
338 p.setY(delta.y()); |
331 if(m_panDirection == RandomPan) { |
339 if (m_panDirection == RandomPan) { |
332 p.setX(delta.x()); |
340 p.setX(delta.x()); |
333 p.setY(delta.y()); |
341 p.setY(delta.y()); |
334 } |
342 } |
335 |
343 |
336 scrollCurrentFrame(p.x(),p.y()); |
344 scrollCurrentFrame(p.x(),p.y()); |
337 } |
345 } |
338 |
346 |
339 void GWebTouchNavigation::highlightableElement(QMouseEvent* ev) { |
347 void GWebTouchNavigation::highlightableElement(QMouseEvent* ev) { |
340 m_anchorElement = getClosestAnchorElement(ev); |
348 m_anchorElement = getClosestAnchorElement(ev); |
348 inline int yInRect(const QRect& r, int y) |
356 inline int yInRect(const QRect& r, int y) |
349 { |
357 { |
350 return std::min(std::max(y, r.y()), r.y() + r.height()); |
358 return std::min(std::max(y, r.y()), r.y() + r.height()); |
351 } |
359 } |
352 |
360 |
353 bool GWebTouchNavigation::traverseNextNode(QWebElement parentNode,QWebElement& nextNode) |
361 bool GWebTouchNavigation::traverseNextNode(QWebElement parentNode,QWebElement& nextNode) |
354 { |
362 { |
355 if (!parentNode.firstChild().isNull()) { |
363 if (!parentNode.firstChild().isNull()) { |
356 nextNode = parentNode.firstChild(); |
364 nextNode = parentNode.firstChild(); |
357 return true; |
365 return true; |
358 } |
366 } |
359 |
367 |
360 if (!parentNode.nextSibling().isNull()) { |
368 if (!parentNode.nextSibling().isNull()) { |
361 nextNode = parentNode.nextSibling(); |
369 nextNode = parentNode.nextSibling(); |
362 return true; |
370 return true; |
363 } |
371 } |
364 |
372 |
365 QWebElement n = parentNode; |
373 QWebElement n = parentNode; |
366 while (!n.isNull() && n.nextSibling().isNull()) |
374 while (!n.isNull() && n.nextSibling().isNull()) |
367 n = n.parent (); |
375 n = n.parent (); |
368 |
376 |
369 if (!n.isNull()) { |
377 if (!n.isNull()) { |
370 nextNode = n.nextSibling(); |
378 nextNode = n.nextSibling(); |
371 return true; |
379 return true; |
372 } |
380 } |
373 |
381 |
374 return false; |
382 return false; |
375 } |
383 } |
376 |
384 |
377 |
385 |
378 QWebElement GWebTouchNavigation::getClosestAnchorElement(QMouseEvent* ev) |
386 QWebElement GWebTouchNavigation::getClosestAnchorElement(QMouseEvent* ev) |
379 { |
387 { |
380 QWebElement webElement; |
388 QWebElement webElement; |
381 QWebHitTestResult htRes = getHitTestResult(ev); |
389 QWebHitTestResult htRes = getHitTestResult(ev); |
382 QWebElement hitElement = htRes.element(); |
390 QWebElement hitElement = htRes.element(); |
383 //check whether hit test returns a link element |
391 //check whether hit test returns a link element |
384 if(!htRes.linkElement().isNull()) { |
392 if (!htRes.linkElement().isNull()) { |
385 webElement = htRes.linkElement(); |
393 webElement = htRes.linkElement(); |
386 m_higlightedPos = ev->pos(); |
394 m_higlightedPos = ev->pos(); |
387 m_ishighlighted = true; |
395 m_ishighlighted = true; |
388 } |
396 } |
389 //get the closet anchor element |
397 //get the closet anchor element |
390 else { |
398 else { |
391 QPoint docPoint = (m_touchPosition + m_frame->scrollPosition()); |
399 QPoint docPoint = (m_touchPosition + m_frame->scrollPosition()); |
392 int dist = 99999999; |
400 int dist = 99999999; |
393 QWebElement result; |
401 QWebElement result; |
394 QWebElement ele = m_webPage->currentFrame()->documentElement(); |
402 QWebElement ele = m_webPage->currentFrame()->documentElement(); |
395 do { |
403 do { |
396 if(ele.tagName().compare("a",Qt::CaseInsensitive) == 0 ) { |
404 if (ele.tagName().compare("a",Qt::CaseInsensitive) == 0 ) { |
397 QRect r = ele.geometry(); |
405 QRect r = ele.geometry(); |
398 if(r.contains(docPoint)) { |
406 if (r.contains(docPoint)) { |
399 dist = 0; |
407 dist = 0; |
400 result = ele; |
408 result = ele; |
401 break; |
409 break; |
402 } |
410 } |
403 |
411 |
434 */ |
441 */ |
435 void GWebTouchNavigation::mousePressEvent(const QPoint& pos) |
442 void GWebTouchNavigation::mousePressEvent(const QPoint& pos) |
436 { |
443 { |
437 m_delayedPressMoment.start(); |
444 m_delayedPressMoment.start(); |
438 // stop deceleration and don't send further events to engine if scroll timer is active |
445 // stop deceleration and don't send further events to engine if scroll timer is active |
439 if(m_scrollTimer && m_scrollTimer->isActive()) { |
446 if (m_scrollTimer && m_scrollTimer->isActive()) { |
440 m_prevPoint.setX(0); |
447 m_prevPoint.setX(0); |
441 m_prevPoint.setY(0); |
448 m_prevPoint.setY(0); |
442 m_scrollDistance.setX(0); |
449 m_scrollDistance.setX(0); |
443 m_scrollDistance.setY(0); |
450 m_scrollDistance.setY(0); |
444 |
451 |
445 m_lastMoveEventTime.setHMS(0,0,0,0); //H, M, S, mS |
452 m_lastMoveEventTime.setHMS(0,0,0,0); //H, M, S, mS |
446 m_scrolled = false; |
453 m_scrolled = false; |
447 m_ishighlighted = false; |
454 m_ishighlighted = false; |
448 m_higlightedPos = m_touchPosition = pos; |
455 m_higlightedPos = m_touchPosition = pos; |
449 m_frame = m_webPage->frameAt(pos); |
456 m_frame = m_webPage->frameAt(pos); |
450 if (!m_frame) |
457 if (!m_frame) |
451 m_frame = m_webPage->currentFrame(); |
458 m_frame = m_webPage->currentFrame(); |
452 |
459 |
453 m_dragPoints.clear(); |
460 m_dragPoints.clear(); |
454 |
461 |
455 DragPoint dragPoint; |
462 DragPoint dragPoint; |
456 dragPoint.iPoint = m_touchPosition; |
463 dragPoint.iPoint = m_touchPosition; |
457 dragPoint.iTime = QTime::currentTime(); |
464 dragPoint.iTime = QTime::currentTime(); |
458 m_dragPoints.append(dragPoint); |
465 m_dragPoints.append(dragPoint); |
459 m_offset = 0; |
466 m_offset = 0; |
460 |
467 |
461 m_pressEvent = new QMouseEvent(QEvent::MouseButtonPress, m_touchPosition, Qt::LeftButton, Qt::LeftButton, getEventModifier(m_touchPosition)); |
468 m_pressEvent = new QMouseEvent(QEvent::MouseButtonPress, m_touchPosition, Qt::LeftButton, Qt::LeftButton, getEventModifier(m_touchPosition)); |
462 m_scrollTimer->stop(); |
469 m_scrollTimer->stop(); |
463 return; |
470 return; |
464 } |
471 } |
465 |
472 |
466 if (m_doubleClickTimer) { |
473 if (m_doubleClickTimer) { |
467 // If there is another click event almost on the same region |
474 // If there is another click event almost on the same region |
468 // as the previous click before doubleClick timeout |
475 // as the previous click before doubleClick timeout |
469 // Consider it as double click. |
476 // Consider it as double click. |
470 if (m_doubleClickTimer->isActive() && m_pressEvent) { |
477 if (m_doubleClickTimer->isActive() && m_pressEvent) { |
471 QPoint diff = m_pressEvent->pos() - pos; |
478 QPoint diff = m_pressEvent->pos() - pos; |
472 if (qAbs(diff.x()) < KTouchThresholdX && qAbs(diff.y()) < KTouchThresholdY) { |
479 if (qAbs(diff.x()) < KTouchThresholdX && qAbs(diff.y()) < KTouchThresholdY) { |
473 mouseDoubleClickEvent(pos); |
480 mouseDoubleClickEvent(pos); |
474 return; |
481 return; |
475 } |
482 } |
476 } |
483 } |
477 m_doubleClickTimer->stop(); |
484 m_doubleClickTimer->stop(); |
478 } else { |
485 } else { |
479 m_doubleClickTimer = new QTimer(this); |
486 m_doubleClickTimer = new QTimer(this); |
480 connect(m_doubleClickTimer, SIGNAL(timeout()), this, SLOT(doubleClickTimerExpired())); |
487 connect(m_doubleClickTimer, SIGNAL(timeout()), this, SLOT(doubleClickTimerExpired())); |
481 } |
488 } |
482 |
489 |
483 //Clear the previous press and release events. |
490 //Clear the previous press and release events. |
484 if (m_pressEvent) { |
491 cancelPressEvent(); |
485 delete m_pressEvent; |
492 cancelReleaseEvent(); |
486 m_pressEvent = NULL; |
|
487 } |
|
488 |
|
489 if (m_releaseEvent) { |
|
490 delete m_releaseEvent; |
|
491 m_releaseEvent = NULL; |
|
492 } |
|
493 |
493 |
494 m_doubleClickTimer->start(KDoubleClickTimeOut); |
494 m_doubleClickTimer->start(KDoubleClickTimeOut); |
495 m_pressEvent = new QMouseEvent(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, getEventModifier(pos)); |
495 m_pressEvent = new QMouseEvent(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, getEventModifier(pos)); |
|
496 m_longPressPosition = pos; |
|
497 startLongPressTimer(); |
496 } |
498 } |
497 |
499 |
498 void GWebTouchNavigation::handleMousePressEvent(QMouseEvent* ev) |
500 void GWebTouchNavigation::handleMousePressEvent(QMouseEvent* ev) |
499 { |
501 { |
|
502 if (!ev) return; |
500 m_lastMoveEventTime.setHMS(0,0,0,0); //H, M, S, mS |
503 m_lastMoveEventTime.setHMS(0,0,0,0); //H, M, S, mS |
501 if(!m_longPressTimer){ |
|
502 delete m_longPressTimer; |
|
503 m_longPressTimer = 0; |
|
504 } |
|
505 startTimer(); |
|
506 m_scrolled = false; |
504 m_scrolled = false; |
507 m_ishighlighted = false; |
505 m_ishighlighted = false; |
508 m_higlightedPos = m_touchPosition = ev->pos(); |
506 m_higlightedPos = m_touchPosition = ev->pos(); |
509 m_frame = m_webPage->frameAt(ev->pos()); |
507 m_frame = m_webPage->frameAt(ev->pos()); |
510 if (!m_frame) |
508 if (!m_frame) |
511 m_frame = m_webPage->currentFrame(); |
509 m_frame = m_webPage->currentFrame(); |
512 |
510 |
513 m_dragPoints.clear(); |
511 m_dragPoints.clear(); |
514 |
512 |
515 DragPoint dragPoint; |
513 DragPoint dragPoint; |
516 dragPoint.iPoint = m_touchPosition; |
514 dragPoint.iPoint = m_touchPosition; |
517 dragPoint.iTime = QTime::currentTime(); |
515 dragPoint.iTime = QTime::currentTime(); |
518 m_dragPoints.append(dragPoint); |
516 m_dragPoints.append(dragPoint); |
519 |
517 |
520 m_offset = 0; |
518 m_offset = 0; |
521 |
519 |
522 highlightableElement(ev); |
520 highlightableElement(ev); |
523 getFocusedElement(); |
521 emitFocusedElementChanged(); |
524 |
522 |
525 //send a mouse press |
523 //send a mouse press |
526 QMouseEvent iev(ev->type(), m_touchPosition, ev->button(), ev->buttons(), getEventModifier(m_higlightedPos)); |
524 QMouseEvent iev(ev->type(), m_touchPosition, ev->button(), ev->buttons(), getEventModifier(m_higlightedPos)); |
527 m_webPage->event(&iev); |
525 m_webPage->event(&iev); |
|
526 m_textSelected = false; |
528 } |
527 } |
529 |
528 |
530 void GWebTouchNavigation::doubleClickTimerExpired() |
529 void GWebTouchNavigation::doubleClickTimerExpired() |
531 { |
530 { |
532 handleMousePressEvent(m_pressEvent); |
531 handleMousePressEvent(m_pressEvent); |
533 |
532 |
534 delete m_pressEvent; |
533 cancelPressEvent(); |
535 m_pressEvent = NULL; |
534 |
536 |
|
537 if (m_releaseEvent) { |
535 if (m_releaseEvent) { |
538 handleMouseReleaseEvent(m_releaseEvent); |
536 handleMouseReleaseEvent(m_releaseEvent); |
539 |
537 |
540 //clear release event |
538 //clear release event |
541 delete m_releaseEvent; |
539 cancelReleaseEvent(); |
542 m_releaseEvent = NULL; |
540 } |
543 } |
541 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) |
544 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) |
|
545 m_doubleClickTimer->stop(); |
542 m_doubleClickTimer->stop(); |
546 } |
543 } |
547 |
544 |
548 bool GWebTouchNavigation::canDehighlight(QMouseEvent* ev) |
545 bool GWebTouchNavigation::canDehighlight(QMouseEvent* ev) |
549 { |
546 { |
550 bool checkDehighlight = false; |
547 bool checkDehighlight = false; |
551 QPoint pt = ev->pos() + m_frame->scrollPosition(); |
548 QPoint pt = ev->pos() + m_frame->scrollPosition(); |
552 |
549 |
553 if(m_scrolled && m_ishighlighted) { |
550 if (m_scrolled && m_ishighlighted) { |
554 checkDehighlight = true; |
551 checkDehighlight = true; |
555 } |
552 } |
556 else if(!m_scrolled && m_ishighlighted) { |
553 else if (!m_scrolled && m_ishighlighted) { |
557 QRect rect = m_anchorElement.geometry(); |
554 QRect rect = m_anchorElement.geometry(); |
558 |
555 |
559 if(m_anchorElement.geometry().contains(pt)) { |
556 if (m_anchorElement.geometry().contains(pt)) { |
560 checkDehighlight = false; |
557 checkDehighlight = false; |
561 } |
558 } |
562 else if(m_offset){ |
559 else if (m_offset){ |
563 QPoint centerpt = m_anchorElement.geometry().center(); |
560 QPoint centerpt = m_anchorElement.geometry().center(); |
564 int newoffset = (pt.x()- centerpt.x())*(pt.x()- centerpt.x()) + (pt.y()- centerpt.y())*(pt.y()- centerpt.y()); |
561 int newoffset = (pt.x()- centerpt.x())*(pt.x()- centerpt.x()) + (pt.y()- centerpt.y())*(pt.y()- centerpt.y()); |
565 |
562 |
566 if(newoffset <= m_offset ) { |
563 if (newoffset <= m_offset ) { |
567 m_offset = newoffset; |
564 m_offset = newoffset; |
568 checkDehighlight = false; |
565 checkDehighlight = false; |
569 } |
566 } |
570 else { |
567 else { |
571 m_offset =0; |
568 m_offset =0; |
572 checkDehighlight = true; |
569 checkDehighlight = true; |
573 } |
570 } |
597 Scrolls the frame |
594 Scrolls the frame |
598 \sa scrollFrame() |
595 \sa scrollFrame() |
599 */ |
596 */ |
600 void GWebTouchNavigation::mouseMoveEvent(const QPoint& pos, const QPoint& diff) |
597 void GWebTouchNavigation::mouseMoveEvent(const QPoint& pos, const QPoint& diff) |
601 { |
598 { |
602 |
599 if (m_longPressTimer && m_longPressTimer->isActive()){ |
|
600 QPoint diff2 = m_longPressPosition - pos; |
|
601 if (qAbs(diff2.x()) > KLongPressThreshold || qAbs(diff2.y()) > KLongPressThreshold) { |
|
602 stopLongPressTimer(); |
|
603 } |
|
604 } |
|
605 |
603 if (m_pressEvent){ |
606 if (m_pressEvent){ |
604 QPoint diff2 = m_pressEvent->pos() - pos; |
607 QPoint diff2 = m_pressEvent->pos() - pos; |
605 if (qAbs(diff2.x()) < KTouchThresholdX && qAbs(diff2.y()) < KTouchThresholdY) |
608 if (qAbs(diff2.x()) < KTouchThresholdX && qAbs(diff2.y()) < KTouchThresholdY) { |
606 return; |
609 return; |
607 } |
610 } |
608 |
611 } |
|
612 |
609 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) { |
613 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) { |
610 //send mousePressEvent |
614 //send mousePressEvent |
611 m_doubleClickTimer->stop(); |
615 m_doubleClickTimer->stop(); |
612 handleMousePressEvent(m_pressEvent); |
616 handleMousePressEvent(m_pressEvent); |
613 delete m_pressEvent; |
617 cancelPressEvent(); |
614 m_pressEvent = NULL; |
618 } |
615 } |
619 |
616 |
|
617 stopTimer(); |
|
618 QMouseEvent tmpEv(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
620 QMouseEvent tmpEv(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
619 handleHighlightChange(&tmpEv); |
621 handleHighlightChange(&tmpEv); |
620 |
622 |
621 scrollFrame(diff); |
623 //the viewport hasn't been scrolled |
622 |
624 if (!m_scrolled) { |
623 //m_touchPosition = pos; |
625 QWebHitTestResult hitTestResult = m_frame->hitTestContent(m_touchPosition); |
624 DragPoint dragPoint; |
626 QWebElement oriElement = hitTestResult.element(); |
625 dragPoint.iPoint = pos; |
627 QWebElement curElement = m_frame->hitTestContent(pos).element(); |
626 dragPoint.iTime = QTime::currentTime(); |
628 // the mousepress event and the mousemove event have the same target |
627 m_dragPoints.append(dragPoint); |
629 if (oriElement == curElement) { |
628 |
630 // the mousemove event's position is in an input field |
629 QTime now(QTime::currentTime()); |
631 if (hitTestResult.isContentEditable()) { |
630 m_lastMoveEventTime.setHMS(now.hour(),now.minute(), now.second(), now.msec()); |
632 QMouseEvent moveEvt(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
631 |
633 m_webPage->event(&moveEvt); |
632 while (m_dragPoints.size() > 4) |
634 m_textSelected = true; |
633 m_dragPoints.removeFirst(); |
635 } |
634 |
636 } |
|
637 } |
|
638 if (!m_textSelected) |
|
639 scrollFrame(diff); |
|
640 |
|
641 //m_touchPosition = pos; |
|
642 DragPoint dragPoint; |
|
643 dragPoint.iPoint = pos; |
|
644 dragPoint.iTime = QTime::currentTime(); |
|
645 m_dragPoints.append(dragPoint); |
|
646 |
|
647 QTime now(QTime::currentTime()); |
|
648 m_lastMoveEventTime.setHMS(now.hour(),now.minute(), now.second(), now.msec()); |
|
649 |
|
650 while (m_dragPoints.size() > 4) |
|
651 m_dragPoints.removeFirst(); |
|
652 |
635 } |
653 } |
636 |
654 |
637 /*! |
655 /*! |
638 If WebCanvas or QWebFrame were scrolled starts the deceleration alogrithm |
656 If WebCanvas or QWebFrame were scrolled starts the deceleration alogrithm |
639 Otherwise sends the mouse release event to QWebPage |
657 Otherwise sends the mouse release event to QWebPage |
640 \sa startDeceleration() |
658 \sa startDeceleration() |
641 */ |
659 */ |
642 void GWebTouchNavigation::mouseReleaseEvent(const QPoint& pos) |
660 void GWebTouchNavigation::mouseReleaseEvent(const QPoint& pos) |
643 { |
661 { |
644 if(m_isPanning) |
662 stopLongPressTimer(); |
|
663 |
|
664 if (m_isPanning) |
645 m_isPanning = false; |
665 m_isPanning = false; |
646 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) { |
666 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) { |
647 m_releaseEvent = new QMouseEvent(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
667 m_releaseEvent = new QMouseEvent(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
|
668 return; |
|
669 } |
|
670 |
|
671 if (m_isContextEvent) { |
|
672 // A context event just occurred, ignore the release event so that links are not activated. |
|
673 m_isContextEvent = false; |
648 return; |
674 return; |
649 } |
675 } |
650 //mouseReleaseEvent is called in two cases. 1. Double click, 2. Mouse Drag |
676 //mouseReleaseEvent is called in two cases. 1. Double click, 2. Mouse Drag |
651 //m_releaseEvent is not null only in Mouse double click |
677 //m_releaseEvent is not null only in Mouse double click |
652 //So delete m_releaseEvent only in double click case. |
678 //So delete m_releaseEvent only in double click case. |
653 //Send release event in mouse move case |
679 //Send release event in mouse move case |
654 if (m_releaseEvent) { |
680 if (m_releaseEvent) { |
655 delete m_releaseEvent ; |
681 cancelReleaseEvent(); |
656 m_releaseEvent = NULL; |
|
657 } else { |
682 } else { |
658 QMouseEvent tmpEv(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
683 QMouseEvent tmpEv(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
659 handleMouseReleaseEvent(&tmpEv); |
684 handleMouseReleaseEvent(&tmpEv); |
660 } |
685 } |
661 } |
686 } |
662 Qt::KeyboardModifier GWebTouchNavigation::getEventModifier(const QPoint& pos) |
687 Qt::KeyboardModifier GWebTouchNavigation::getEventModifier(const QPoint& pos) |
663 { |
688 { |
664 QWebFrame *frame = m_webPage->frameAt(pos); |
689 QWebFrame *frame = m_webPage->frameAt(pos); |
665 if (!frame) |
690 if (!frame) |
666 frame = m_webPage->currentFrame(); |
691 frame = m_webPage->currentFrame(); |
667 QWebHitTestResult htr = frame->hitTestContent(pos); |
692 QWebHitTestResult htr = frame->hitTestContent(pos); |
668 if (htr.element().tagName().toLower().compare("select")==0 && htr.element().hasAttribute("multiple")) |
693 if (htr.element().tagName().toLower().compare("select")==0 && htr.element().hasAttribute("multiple")) |
669 return Qt::ControlModifier; |
694 return Qt::ControlModifier; |
670 return Qt::NoModifier; |
695 return Qt::NoModifier; |
671 } |
696 } |
672 |
697 |
673 void GWebTouchNavigation::handleMouseReleaseEvent(QMouseEvent* ev) |
698 void GWebTouchNavigation::handleMouseReleaseEvent(QMouseEvent* ev) |
674 { |
699 { |
675 m_frame = m_webPage->frameAt(ev->pos()); |
700 m_frame = m_webPage->frameAt(ev->pos()); |
676 if (!m_frame) |
701 if (!m_frame) |
677 m_frame = m_webPage->currentFrame(); |
702 m_frame = m_webPage->currentFrame(); |
678 assert(m_frame); |
703 Q_ASSERT(m_frame); |
679 |
704 |
680 stopTimer(); |
705 stopLongPressTimer(); |
681 if (m_scrolled) { |
706 if (m_scrolled) { |
682 int msecs = 0; |
707 int msecs = 0; |
683 if (!m_lastMoveEventTime.isNull()) { |
708 if (!m_lastMoveEventTime.isNull()) { |
684 //Start deceleration only if the delta since last drag event is less than threshold |
709 //Start deceleration only if the delta since last drag event is less than threshold |
685 QTime now(QTime::currentTime()); |
710 QTime now(QTime::currentTime()); |
686 msecs = m_lastMoveEventTime.msecsTo(now); |
711 msecs = m_lastMoveEventTime.msecsTo(now); |
687 m_lastMoveEventTime.setHMS(0,0,0,0); |
712 m_lastMoveEventTime.setHMS(0,0,0,0); |
688 } |
713 } |
689 if (msecs < KDecelerationTimer) { |
714 if (msecs < KDecelerationTimer) { |
690 if( isFlick()) { |
715 if ( isFlick()) { |
691 updateFlickScrollDistance(); |
716 updateFlickScrollDistance(); |
692 } |
717 } |
693 else { |
718 else { |
694 QRect enclosingRect = findEnclosingBlock(ev); |
719 QRect enclosingRect = findEnclosingBlock(ev); |
695 QPoint blockDocPt(enclosingRect.x(), enclosingRect.y()); |
720 QPoint blockDocPt(enclosingRect.x(), enclosingRect.y()); |
738 handleDoubleClickEvent(&tmpEv); |
767 handleDoubleClickEvent(&tmpEv); |
739 } |
768 } |
740 |
769 |
741 void GWebTouchNavigation::handleDoubleClickEvent(QMouseEvent* ev) |
770 void GWebTouchNavigation::handleDoubleClickEvent(QMouseEvent* ev) |
742 { |
771 { |
|
772 if (!m_doubleClickEnabled) |
|
773 return; |
|
774 |
743 QPoint imageFocusPoint; |
775 QPoint imageFocusPoint; |
744 QWebHitTestResult hitTest = getHitTestResult(ev); |
776 QWebHitTestResult hitTest = getHitTestResult(ev); |
745 |
777 |
746 QWebElement block = hitTest.element(); |
778 QWebElement block = hitTest.element(); |
747 |
779 |
748 if (block.tagName() != "IMG" && (block.styleProperty(QString("background-image"),QWebElement::InlineStyle) == "")) |
780 if (block.tagName() != "IMG" && (block.styleProperty(QString("background-image"),QWebElement::InlineStyle) == "")) |
749 block = hitTest.enclosingBlockElement(); |
781 block = hitTest.enclosingBlockElement(); |
750 |
782 |
751 QWebFrame* frame = m_webPage->frameAt(ev->pos()); |
783 QWebFrame* frame = m_webPage->frameAt(ev->pos()); |
752 m_frame = (frame) ? frame : m_webPage->mainFrame(); |
784 m_frame = (frame) ? frame : m_webPage->mainFrame(); |
753 |
785 |
754 QRect enclosingRect = block.geometry(); |
786 QRect enclosingRect = block.geometry(); |
755 |
787 |
756 QPoint blockCanvasPt = QPoint(enclosingRect.topLeft()) - m_frame->scrollPosition(); |
788 QPoint blockCanvasPt = QPoint(enclosingRect.topLeft()) - m_frame->scrollPosition(); |
757 //WebContentWidget* view = qobject_cast<WebContentWidget*>(m_view); |
789 setViewBlockElement(QWebElement()); |
758 m_view->setBlockElement(QWebElement()); |
790 if (m_focusedBlockPt == blockCanvasPt) { |
759 if(m_focusedBlockPt == blockCanvasPt) { |
791 m_focusedBlockPt.setX(-1); |
760 m_focusedBlockPt.setX(-1); |
792 m_focusedBlockPt.setY(-1); |
761 m_focusedBlockPt.setY(-1); |
793 qreal m_Ratiox = (qreal) blockCanvasPt.x() / block.geometry().width(); |
762 qreal m_Ratiox = (qreal) blockCanvasPt.x() / block.geometry().width(); |
794 qreal m_Ratioy = (qreal) blockCanvasPt.y() / block.geometry().height(); |
763 qreal m_Ratioy = (qreal) blockCanvasPt.y() / block.geometry().height(); |
795 setViewZoomFactor(viewInitialScale()); |
764 m_view->setZoomFactor(m_view->initialScale()); |
796 QPoint m_InfocusBlockPt = QPoint(block.geometry().topLeft()) - m_webPage->mainFrame()->scrollPosition(); |
765 QPoint m_InfocusBlockPt = QPoint(block.geometry().topLeft()) - m_webPage->mainFrame()->scrollPosition(); |
797 m_webPage->currentFrame()->scroll(m_InfocusBlockPt.x() - (m_Ratiox * block.geometry().width()), |
766 m_webPage->currentFrame()->scroll(m_InfocusBlockPt.x() - (m_Ratiox * block.geometry().width()), |
798 m_InfocusBlockPt.y() - (m_Ratioy * block.geometry().height())); |
767 m_InfocusBlockPt.y() - (m_Ratioy * block.geometry().height())); |
|
768 m_finalzoomfactor = 0; |
799 m_finalzoomfactor = 0; |
769 }else { |
800 }else { |
770 if(block.tagName() != "IMG" && (block.styleProperty(QString("background-image"),QWebElement::InlineStyle) == "")) { |
801 if (block.tagName() != "IMG" && (block.styleProperty(QString("background-image"),QWebElement::InlineStyle) == "")) { |
771 m_finalzoomfactor = (qreal) (m_webPage->viewportSize().width() - 10) * m_view->zoomFactor(); |
802 m_finalzoomfactor = (qreal) (m_webPage->viewportSize().width() - 10) * m_view->zoomFactor(); |
772 m_finalzoomfactor = (qreal) m_finalzoomfactor / (enclosingRect.width()); |
803 m_finalzoomfactor = (qreal) m_finalzoomfactor / (enclosingRect.width()); |
773 QString str; |
804 QString str; |
774 str.setNum(m_finalzoomfactor,'f',2); |
805 str.setNum(m_finalzoomfactor,'f',2); |
775 m_finalzoomfactor = str.toDouble(); |
806 m_finalzoomfactor = str.toDouble(); |
776 }else { |
807 }else { |
777 qreal factor; |
808 qreal factor; |
778 factor = 1/m_view->initialScale(); |
809 factor = 1/viewInitialScale(); |
779 int boundW = block.geometry().width() * factor/m_view->zoomFactor(); |
810 int boundW = block.geometry().width() * factor/m_view->zoomFactor(); |
780 int boundH = block.geometry().height() * factor/m_view->zoomFactor(); |
811 int boundH = block.geometry().height() * factor/m_view->zoomFactor(); |
781 qreal factorw = 0.0,factorh = 0.0 ; |
812 qreal factorw = 0.0,factorh = 0.0 ; |
782 |
813 |
783 if( boundW > m_webPage->viewportSize().width()) |
814 if ( boundW > m_webPage->viewportSize().width()) |
784 factorw = (qreal)(m_webPage->viewportSize().width()-5)/ block.geometry().width(); |
815 factorw = (qreal)(m_webPage->viewportSize().width()-5)/ block.geometry().width(); |
785 |
816 |
786 if(boundH > m_webPage->viewportSize().height()) |
817 if (boundH > m_webPage->viewportSize().height()) |
787 factorh = (qreal)(m_webPage->viewportSize().height()-5)/ block.geometry().height(); |
818 factorh = (qreal)(m_webPage->viewportSize().height()-5)/ block.geometry().height(); |
788 |
819 |
789 if( (factorw == 0.0) && (factorh == 0.0)) |
820 if ( (factorw == 0.0) && (factorh == 0.0)) |
790 ; |
821 ; |
791 else if(factorw == 0.0) |
822 else if (factorw == 0.0) |
792 factor = factorh * m_view->zoomFactor(); |
823 factor = factorh * m_view->zoomFactor(); |
793 else if(factorh == 0.0) |
824 else if (factorh == 0.0) |
794 factor = factorw * m_view->zoomFactor(); |
825 factor = factorw * m_view->zoomFactor(); |
795 else { |
826 else { |
796 factor = ((factorh < factorw) ? factorh : factorw) * m_view->zoomFactor(); |
827 factor = ((factorh < factorw) ? factorh : factorw) * m_view->zoomFactor(); |
797 } |
828 } |
798 |
829 |
799 QString str; |
830 QString str; |
800 str.setNum(factor,'f',2); |
831 str.setNum(factor,'f',2); |
801 factor = str.toDouble(); |
832 factor = str.toDouble(); |
802 |
833 |
803 if(m_finalzoomfactor != factor) |
834 if (m_finalzoomfactor != factor) |
804 m_finalzoomfactor = factor; |
835 m_finalzoomfactor = factor; |
805 } |
836 } |
806 |
837 |
807 |
838 |
808 if (m_finalzoomfactor != m_view->zoomFactor()) { |
839 if (m_finalzoomfactor != m_view->zoomFactor()) { |
809 m_view->setZoomFactor(m_finalzoomfactor); |
840 setViewZoomFactor(m_finalzoomfactor); |
810 m_focusedBlockPt = QPoint(block.geometry().topLeft()) - m_frame->scrollPosition(); |
841 m_focusedBlockPt = QPoint(block.geometry().topLeft()) - m_frame->scrollPosition(); |
811 |
842 |
812 if(block.tagName() != "IMG" && (block.styleProperty(QString("background-image"),QWebElement::InlineStyle) == "")) |
843 if (block.tagName() != "IMG" && (block.styleProperty(QString("background-image"),QWebElement::InlineStyle) == "")) |
813 scrollCurrentFrame(m_focusedBlockPt.x() - KFocussPoint.x() , m_focusedBlockPt.y() - KFocussPoint.y()); |
844 scrollCurrentFrame(m_focusedBlockPt.x() - KFocussPoint.x() , m_focusedBlockPt.y() - KFocussPoint.y()); |
814 else { |
845 else { |
815 if((m_webPage->viewportSize().width() - block.geometry().width()) > 0) |
846 if ((m_webPage->viewportSize().width() - block.geometry().width()) > 0) |
816 imageFocusPoint.setX((m_webPage->viewportSize().width() - block.geometry().width())/2); |
847 imageFocusPoint.setX((m_webPage->viewportSize().width() - block.geometry().width())/2); |
817 else |
848 else |
818 imageFocusPoint.setX(0); |
849 imageFocusPoint.setX(0); |
819 |
850 |
820 if((m_webPage->viewportSize().height() - block.geometry().height()) > 0) |
851 if ((m_webPage->viewportSize().height() - block.geometry().height()) > 0) |
821 imageFocusPoint.setY((m_webPage->viewportSize().height() - block.geometry().height())/2); |
852 imageFocusPoint.setY((m_webPage->viewportSize().height() - block.geometry().height())/2); |
822 else |
853 else |
823 imageFocusPoint.setY(0); |
854 imageFocusPoint.setY(0); |
824 |
855 |
825 scrollCurrentFrame(m_focusedBlockPt.x() - imageFocusPoint.x() , m_focusedBlockPt.y() - imageFocusPoint.y()); |
856 scrollCurrentFrame(m_focusedBlockPt.x() - imageFocusPoint.x() , m_focusedBlockPt.y() - imageFocusPoint.y()); |
826 } |
857 } |
827 |
858 |
828 m_focusedBlockPt = QPoint(block.geometry().topLeft()) - m_frame->scrollPosition(); |
859 m_focusedBlockPt = QPoint(block.geometry().topLeft()) - m_frame->scrollPosition(); |
829 } else { |
860 } else { |
830 //Get doc size and current bottom right view corner point in document |
861 //Get doc size and current bottom right view corner point in document |
831 QSize viewSize = m_webPage->viewportSize(); |
862 QSize viewSize = m_webPage->viewportSize(); |
832 QSize contentSize = m_frame->contentsSize(); |
863 QSize contentSize = m_frame->contentsSize(); |
833 QPoint documentViewPoint = QPoint(viewSize.width(),viewSize.height()) + m_frame->scrollPosition(); |
864 QPoint documentViewPoint = QPoint(viewSize.width(),viewSize.height()) + m_frame->scrollPosition(); |
834 QPoint docFocusPoint; |
865 QPoint docFocusPoint; |
835 |
866 |
836 if(block.tagName() != "IMG" && (block.styleProperty(QString("background-image"),QWebElement::InlineStyle) == "")) |
867 if (block.tagName() != "IMG" && (block.styleProperty(QString("background-image"),QWebElement::InlineStyle) == "")) |
837 docFocusPoint = KFocussPoint + m_frame->scrollPosition(); |
868 docFocusPoint = KFocussPoint + m_frame->scrollPosition(); |
838 else { |
869 else { |
839 if((m_webPage->viewportSize().width() - block.geometry().width()) > 0) |
870 if ((m_webPage->viewportSize().width() - block.geometry().width()) > 0) |
840 imageFocusPoint.setX((m_webPage->viewportSize().width() - block.geometry().width())/2); |
871 imageFocusPoint.setX((m_webPage->viewportSize().width() - block.geometry().width())/2); |
841 else |
872 else |
842 imageFocusPoint.setX(0); |
873 imageFocusPoint.setX(0); |
843 |
874 |
844 if((m_webPage->viewportSize().height() - block.geometry().height()) > 0) |
875 if ((m_webPage->viewportSize().height() - block.geometry().height()) > 0) |
845 imageFocusPoint.setY((m_webPage->viewportSize().height()- block.geometry().height())/2); |
876 imageFocusPoint.setY((m_webPage->viewportSize().height()- block.geometry().height())/2); |
846 else |
877 else |
847 imageFocusPoint.setY(0); |
878 imageFocusPoint.setY(0); |
848 |
879 |
849 docFocusPoint = imageFocusPoint + m_frame->scrollPosition(); |
880 docFocusPoint = imageFocusPoint + m_frame->scrollPosition(); |
850 } |
881 } |
851 |
882 |
852 m_focusedBlockPt = QPoint(block.geometry().x(), block.geometry().y()); |
883 m_focusedBlockPt = QPoint(block.geometry().x(), block.geometry().y()); |
853 m_scrollDistance.setX(m_focusedBlockPt.x() - docFocusPoint.x()); |
884 m_scrollDistance.setX(m_focusedBlockPt.x() - docFocusPoint.x()); |
854 m_scrollDistance.setY(m_focusedBlockPt.y() - docFocusPoint.y()); |
885 m_scrollDistance.setY(m_focusedBlockPt.y() - docFocusPoint.y()); |
855 |
886 |
856 QPoint scrollableDistance(0, 0); |
887 QPoint scrollableDistance(0, 0); |
857 QPoint viewStartPoint = QPoint(0,0) + m_frame->scrollPosition(); |
888 QPoint viewStartPoint = QPoint(0,0) + m_frame->scrollPosition(); |
858 |
889 |
859 if(m_scrollDistance.x() < 0) |
890 if (m_scrollDistance.x() < 0) |
860 scrollableDistance.setX(viewStartPoint.x()); |
891 scrollableDistance.setX(viewStartPoint.x()); |
861 else |
892 else |
862 scrollableDistance.setX(contentSize.width() - documentViewPoint.x()); |
893 scrollableDistance.setX(contentSize.width() - documentViewPoint.x()); |
863 |
894 |
864 |
895 |
865 if(m_scrollDistance.y() < 0) |
896 if (m_scrollDistance.y() < 0) |
866 scrollableDistance.setY(viewStartPoint.y()); |
897 scrollableDistance.setY(viewStartPoint.y()); |
867 else |
898 else |
868 scrollableDistance.setY(contentSize.height() - documentViewPoint.y()); |
899 scrollableDistance.setY(contentSize.height() - documentViewPoint.y()); |
869 |
900 |
870 if(abs(m_scrollDistance.x()) > abs(scrollableDistance.x())){ |
901 if (abs(m_scrollDistance.x()) > abs(scrollableDistance.x())){ |
871 //m_scrollDistance.x() >= 0 means scroll from right to left |
902 //m_scrollDistance.x() >= 0 means scroll from right to left |
872 if(m_scrollDistance.x() >= 0) |
903 if (m_scrollDistance.x() >= 0) |
873 m_focusedBlockPt.setX(m_focusedBlockPt.x() - abs(scrollableDistance.x())); |
904 m_focusedBlockPt.setX(m_focusedBlockPt.x() - abs(scrollableDistance.x())); |
874 //m_scrollDistance.x() < 0 means scroll from left to right |
905 //m_scrollDistance.x() < 0 means scroll from left to right |
875 else |
906 else |
876 m_focusedBlockPt.setX(m_focusedBlockPt.x() + abs(scrollableDistance.x())); |
907 m_focusedBlockPt.setX(m_focusedBlockPt.x() + abs(scrollableDistance.x())); |
877 } else |
908 } else |
878 m_focusedBlockPt.setX(docFocusPoint.x()); |
909 m_focusedBlockPt.setX(docFocusPoint.x()); |
879 |
910 |
880 if (abs(m_scrollDistance.y()) > abs(scrollableDistance.y())){ |
911 if (abs(m_scrollDistance.y()) > abs(scrollableDistance.y())){ |
881 if(m_scrollDistance.y() >= 0) |
912 if (m_scrollDistance.y() >= 0) |
882 m_focusedBlockPt.setY(m_focusedBlockPt.y() - abs(scrollableDistance.y())); |
913 m_focusedBlockPt.setY(m_focusedBlockPt.y() - abs(scrollableDistance.y())); |
883 else |
914 else |
884 m_focusedBlockPt.setY(m_focusedBlockPt.y() + abs(scrollableDistance.y())); |
915 m_focusedBlockPt.setY(m_focusedBlockPt.y() + abs(scrollableDistance.y())); |
885 } |
916 } |
886 else |
917 else |
887 m_focusedBlockPt.setY(docFocusPoint.y()); |
918 m_focusedBlockPt.setY(docFocusPoint.y()); |
888 |
919 |
889 m_focusedBlockPt = m_focusedBlockPt - m_frame->scrollPosition(); |
920 m_focusedBlockPt = m_focusedBlockPt - m_frame->scrollPosition(); |
890 startScrollTimer(); |
921 startScrollTimer(); |
891 } |
922 } |
892 m_view->setBlockElement(block); |
923 setViewBlockElement(block); |
893 } |
924 } |
894 } |
925 } |
|
926 |
|
927 void GWebTouchNavigation::contextMenuEvent() { |
|
928 m_isContextEvent = true; |
|
929 cancelPressEvent(); |
|
930 } |
|
931 |
895 |
932 |
896 /*! |
933 /*! |
897 Returns the next scrollable frame in the frame tree give the x,y position |
934 Returns the next scrollable frame in the frame tree give the x,y position |
898 */ |
935 */ |
899 QWebFrame* GWebTouchNavigation::getNextScrollableFrame(const QPoint& pos) |
936 QWebFrame* GWebTouchNavigation::getNextScrollableFrame(const QPoint& pos) |
939 /* |
976 /* |
940 Update the scroll distance for flick gesture. Update the scroll distance upto the edge of the page |
977 Update the scroll distance for flick gesture. Update the scroll distance upto the edge of the page |
941 */ |
978 */ |
942 void GWebTouchNavigation::updateFlickScrollDistance() |
979 void GWebTouchNavigation::updateFlickScrollDistance() |
943 { |
980 { |
944 m_initialSpeed = speed(); |
981 m_initialSpeed = speed(); |
945 m_initialSpeed.setX(qAbs(m_initialSpeed.x())); |
982 m_initialSpeed.setX(qAbs(m_initialSpeed.x())); |
946 m_initialSpeed.setY(qAbs(m_initialSpeed.y())); |
983 m_initialSpeed.setY(qAbs(m_initialSpeed.y())); |
947 m_flickDirection = findDirectionWithAngle(m_dragPoints.first().iPoint - m_dragPoints.last().iPoint); |
984 m_flickDirection = findDirectionWithAngle(m_dragPoints.first().iPoint - m_dragPoints.last().iPoint); |
948 m_scrollDistance.setX((m_initialSpeed.x() * m_initialSpeed.x())/( 2 * KDeccelaration)); |
985 m_scrollDistance.setX((m_initialSpeed.x() * m_initialSpeed.x())/( 2 * KDeccelaration)); |
949 m_scrollDistance.setY((m_initialSpeed.y() * m_initialSpeed.y())/( 2 * KDeccelaration)); |
986 m_scrollDistance.setY((m_initialSpeed.y() * m_initialSpeed.y())/( 2 * KDeccelaration)); |
950 |
987 |
951 m_scrollDistance.setX(m_view->zoomFactor() * m_scrollDistance.x() / m_view->initialScale()); |
988 m_scrollDistance.setX(m_view->zoomFactor() * m_scrollDistance.x() / viewInitialScale()); |
952 m_scrollDistance.setY(m_view->zoomFactor() * m_scrollDistance.y() / m_view->initialScale()); |
989 m_scrollDistance.setY(m_view->zoomFactor() * m_scrollDistance.y() / viewInitialScale()); |
953 |
990 |
954 QSize viewSize = m_webPage->viewportSize(); |
991 QSize viewSize = m_webPage->viewportSize(); |
955 QSize contentSize = m_frame->contentsSize(); |
992 QSize contentSize = m_frame->contentsSize(); |
956 QPoint documentViewPoint = QPoint(viewSize.width(),viewSize.height()) + m_frame->scrollPosition(); |
993 QPoint documentViewPoint = QPoint(viewSize.width(),viewSize.height()) + m_frame->scrollPosition(); |
957 QPoint documentTouchPoint = m_touchPosition + m_frame->scrollPosition();; |
994 QPoint documentTouchPoint = m_touchPosition + m_frame->scrollPosition();; |
958 |
995 |
959 switch(m_flickDirection) |
996 switch (m_flickDirection) |
960 { |
997 { |
961 case DOWN : |
998 case DOWN : |
962 m_scrollDistance.setX(0); |
999 m_scrollDistance.setX(0); |
963 m_scrollDistance.setY(-(m_scrollDistance.y())); |
1000 m_scrollDistance.setY(-(m_scrollDistance.y())); |
964 |
1001 |
965 if(m_scrollDistance.y() < -(documentTouchPoint.y() - m_touchPosition.y())) |
1002 if (m_scrollDistance.y() < -(documentTouchPoint.y() - m_touchPosition.y())) |
966 m_scrollDistance.setY(-(documentTouchPoint.y() - m_touchPosition.y())); |
1003 m_scrollDistance.setY(-(documentTouchPoint.y() - m_touchPosition.y())); |
967 break; |
1004 break; |
968 case UP : |
1005 case UP : |
969 m_scrollDistance.setX(0); |
1006 m_scrollDistance.setX(0); |
970 if(m_scrollDistance.y() > (contentSize.height() - documentViewPoint.y())) |
1007 if (m_scrollDistance.y() > (contentSize.height() - documentViewPoint.y())) |
971 m_scrollDistance.setY(contentSize.height() - documentViewPoint.y()); |
1008 m_scrollDistance.setY(contentSize.height() - documentViewPoint.y()); |
972 break; |
1009 break; |
973 case RIGHT: |
1010 case RIGHT: |
974 m_scrollDistance.setX(-(m_scrollDistance.x())); |
1011 m_scrollDistance.setX(-(m_scrollDistance.x())); |
975 if(m_scrollDistance.x() < -(documentTouchPoint.x() - m_touchPosition.x())) |
1012 if (m_scrollDistance.x() < -(documentTouchPoint.x() - m_touchPosition.x())) |
976 m_scrollDistance.setX(-(documentTouchPoint.x() - m_touchPosition.x())); |
1013 m_scrollDistance.setX(-(documentTouchPoint.x() - m_touchPosition.x())); |
977 m_scrollDistance.setY(0); |
1014 m_scrollDistance.setY(0); |
978 break; |
1015 break; |
979 case LEFT: |
1016 case LEFT: |
980 m_scrollDistance.setY(0); |
1017 m_scrollDistance.setY(0); |
981 if(m_scrollDistance.x() > (contentSize.width() - documentViewPoint.x())) |
1018 if (m_scrollDistance.x() > (contentSize.width() - documentViewPoint.x())) |
982 m_scrollDistance.setX(contentSize.width() - documentViewPoint.x()); |
1019 m_scrollDistance.setX(contentSize.width() - documentViewPoint.x()); |
983 break; |
1020 break; |
984 case BOTTOMRIGHT: |
1021 case BOTTOMRIGHT: |
985 m_scrollDistance.setX(-(m_scrollDistance.x())); |
1022 m_scrollDistance.setX(-(m_scrollDistance.x())); |
986 m_scrollDistance.setY(-(m_scrollDistance.y())); |
1023 m_scrollDistance.setY(-(m_scrollDistance.y())); |
987 if(m_scrollDistance.x() < -(documentTouchPoint.x()-m_touchPosition.x())) |
1024 if (m_scrollDistance.x() < -(documentTouchPoint.x()-m_touchPosition.x())) |
988 m_scrollDistance.setX(-(documentTouchPoint.x()-m_touchPosition.x())); |
1025 m_scrollDistance.setX(-(documentTouchPoint.x()-m_touchPosition.x())); |
989 if(m_scrollDistance.y() < -((documentTouchPoint.y()-m_touchPosition.y())/2)) |
1026 if (m_scrollDistance.y() < -((documentTouchPoint.y()-m_touchPosition.y())/2)) |
990 m_scrollDistance.setY(-((documentTouchPoint.y()-m_touchPosition.y())/2)); |
1027 m_scrollDistance.setY(-((documentTouchPoint.y()-m_touchPosition.y())/2)); |
991 break; |
1028 break; |
992 case BOTTOMLEFT: |
1029 case BOTTOMLEFT: |
993 m_scrollDistance.setY(-(m_scrollDistance.y())); |
1030 m_scrollDistance.setY(-(m_scrollDistance.y())); |
994 if(m_scrollDistance.x() > contentSize.width()-documentViewPoint.x()) |
1031 if (m_scrollDistance.x() > contentSize.width()-documentViewPoint.x()) |
995 m_scrollDistance.setX(contentSize.width()-documentViewPoint.x()); |
1032 m_scrollDistance.setX(contentSize.width()-documentViewPoint.x()); |
996 if(m_scrollDistance.y() < (-((documentTouchPoint.y()-m_touchPosition.y())/2))) |
1033 if (m_scrollDistance.y() < (-((documentTouchPoint.y()-m_touchPosition.y())/2))) |
997 m_scrollDistance.setY(-((documentTouchPoint.y()-m_touchPosition.y())/2)); |
1034 m_scrollDistance.setY(-((documentTouchPoint.y()-m_touchPosition.y())/2)); |
998 break; |
1035 break; |
999 case TOPLEFT: |
1036 case TOPLEFT: |
1000 if(m_scrollDistance.x() > (contentSize.width()-documentViewPoint.x())) |
1037 if (m_scrollDistance.x() > (contentSize.width()-documentViewPoint.x())) |
1001 m_scrollDistance.setX(contentSize.width()-documentViewPoint.x()); |
1038 m_scrollDistance.setX(contentSize.width()-documentViewPoint.x()); |
1002 if(m_scrollDistance.y() > ((contentSize.height()-documentViewPoint.y())/2)) |
1039 if (m_scrollDistance.y() > ((contentSize.height()-documentViewPoint.y())/2)) |
1003 m_scrollDistance.setY((contentSize.height()-documentViewPoint.y())/2); |
1040 m_scrollDistance.setY((contentSize.height()-documentViewPoint.y())/2); |
1004 break; |
1041 break; |
1005 case TOPRIGHT: |
1042 case TOPRIGHT: |
1006 m_scrollDistance.setX(-(m_scrollDistance.x())); |
1043 m_scrollDistance.setX(-(m_scrollDistance.x())); |
1007 if(m_scrollDistance.x() < (-(documentTouchPoint.x()-m_touchPosition.x()))) |
1044 if (m_scrollDistance.x() < (-(documentTouchPoint.x()-m_touchPosition.x()))) |
1008 m_scrollDistance.setX(-(documentTouchPoint.x()-m_touchPosition.x())); |
1045 m_scrollDistance.setX(-(documentTouchPoint.x()-m_touchPosition.x())); |
1009 if(m_scrollDistance.y() > ((contentSize.height()-documentViewPoint.y())/2)) |
1046 if (m_scrollDistance.y() > ((contentSize.height()-documentViewPoint.y())/2)) |
1010 m_scrollDistance.setY((contentSize.height()-documentViewPoint.y())/2); |
1047 m_scrollDistance.setY((contentSize.height()-documentViewPoint.y())/2); |
1011 break; |
1048 break; |
|
1049 default: break; |
1012 } |
1050 } |
1013 } |
1051 } |
1014 |
1052 |
1015 /* |
1053 /* |
1016 Distinguishes b/w swipe and flick |
1054 Distinguishes b/w swipe and flick |
1017 */ |
1055 */ |
1018 bool GWebTouchNavigation::isFlick() |
1056 bool GWebTouchNavigation::isFlick() |
1019 { |
1057 { |
1020 bool flick = false; |
1058 bool flick = false; |
1021 QPoint moveSpeed = speed(); |
1059 QPoint moveSpeed = speed(); |
1022 int xSpeed = moveSpeed.x(); |
1060 int xSpeed = moveSpeed.x(); |
1023 int ySpeed = moveSpeed.y(); |
1061 int ySpeed = moveSpeed.y(); |
1024 |
1062 |
1025 flick = (qAbs(xSpeed) > KFlickSpeed || |
1063 flick = (qAbs(xSpeed) > KFlickSpeed || |
1026 qAbs(ySpeed) > KFlickSpeed); |
1064 qAbs(ySpeed) > KFlickSpeed); |
1027 |
1065 |
1028 return flick; |
1066 return flick; |
1029 } |
1067 } |
1030 |
1068 |
1031 /* |
1069 /* |
1032 Calculates the speed of te scroll along x-axis and y-axis |
1070 Calculates the speed of te scroll along x-axis and y-axis |
1033 */ |
1071 */ |
1034 QPoint GWebTouchNavigation::speed() |
1072 QPoint GWebTouchNavigation::speed() |
1035 { |
1073 { |
1036 // Speed is only evaluated at the end of the swipe |
1074 // Speed is only evaluated at the end of the swipe |
1037 QPoint dragSpeed(0,0); |
1075 QPoint dragSpeed(0,0); |
1038 qreal time = dragTime() / KMilliSecond; |
1076 qreal time = dragTime() / KMilliSecond; |
1039 if (time > 0) { |
1077 if (time > 0) { |
1063 /* |
1101 /* |
1064 Finds the time difference b/w the first and last dragpoint |
1102 Finds the time difference b/w the first and last dragpoint |
1065 */ |
1103 */ |
1066 qreal GWebTouchNavigation::dragTime() const |
1104 qreal GWebTouchNavigation::dragTime() const |
1067 { |
1105 { |
1068 if(m_dragPoints.isEmpty()) |
1106 if (m_dragPoints.isEmpty()) |
1069 return 0.0; |
1107 return 0.0; |
1070 else |
1108 else |
1071 return m_dragPoints[0].iTime.msecsTo(m_dragPoints[m_dragPoints.size()-1].iTime); |
1109 return m_dragPoints[0].iTime.msecsTo(m_dragPoints[m_dragPoints.size()-1].iTime); |
1072 } |
1110 } |
1073 |
1111 |
1074 /*! |
1112 /*! |
1075 Find the flick direction with respect to angle of flick |
1113 Find the flick direction with respect to angle of flick |
1076 */ |
1114 */ |
1077 Direction GWebTouchNavigation::findDirectionWithAngle(const QPoint& diff) |
1115 GWebTouchNavigation::Direction GWebTouchNavigation::findDirectionWithAngle(const QPoint& diff) |
1078 { |
1116 { |
1079 Direction direction; |
1117 Direction direction = NONE; |
1080 int xDelta = -diff.x(); |
1118 int xDelta = -diff.x(); |
1081 int yDelta = -diff.y(); |
1119 int yDelta = -diff.y(); |
1082 |
1120 |
1083 qreal angle = findAngle(xDelta, yDelta); |
1121 qreal angle = findAngle(xDelta, yDelta); |
1084 if(isNear(angle, 60.0, 120.0)) { |
1122 if (isNear(angle, 60.0, 120.0)) { |
1085 direction = DOWN; |
1123 direction = DOWN; |
1086 } |
1124 } |
1087 else if(isNear(angle, 150.0, 210.0)) { |
1125 else if (isNear(angle, 150.0, 210.0)) { |
1088 direction = LEFT; |
1126 direction = LEFT; |
1089 } |
1127 } |
1090 else if(isNear(angle, 240.0, 300.0)) { |
1128 else if (isNear(angle, 240.0, 300.0)) { |
1091 direction = UP; |
1129 direction = UP; |
1092 } |
1130 } |
1093 else if(360.0 - KAngleTolerance <= angle || angle <= KAngleTolerance) { |
1131 else if (360.0 - KAngleTolerance <= angle || angle <= KAngleTolerance) { |
1094 direction = RIGHT; |
1132 direction = RIGHT; |
1095 } |
1133 } |
1096 else if(isNear(angle, 30.0, 60.0)) { |
1134 else if (isNear(angle, 30.0, 60.0)) { |
1097 direction = BOTTOMRIGHT; |
1135 direction = BOTTOMRIGHT; |
1098 } |
1136 } |
1099 else if(isNear(angle, 120.0, 150.0)) { |
1137 else if (isNear(angle, 120.0, 150.0)) { |
1100 direction = BOTTOMLEFT; |
1138 direction = BOTTOMLEFT; |
1101 } |
1139 } |
1102 else if(isNear(angle, 210.0, 240.0)) { |
1140 else if (isNear(angle, 210.0, 240.0)) { |
1103 direction = TOPLEFT; |
1141 direction = TOPLEFT; |
1104 } |
1142 } |
1105 else if(isNear(angle, 300.0, 330.0)) { |
1143 else if (isNear(angle, 300.0, 330.0)) { |
1106 direction = TOPRIGHT; |
1144 direction = TOPRIGHT; |
1107 } |
1145 } |
|
1146 Q_ASSERT(direction != NONE); |
1108 |
1147 |
1109 return direction; |
1148 return direction; |
1110 } |
1149 } |
1111 |
1150 |
1112 /* |
1151 /* |
1178 } |
1217 } |
1179 } |
1218 } |
1180 |
1219 |
1181 /* |
1220 /* |
1182 In the case of slow swipe, if the destination location lies within the threshold area, then |
1221 In the case of slow swipe, if the destination location lies within the threshold area, then |
1183 we need to align the block to te left edge of the mobile screen. This method finds out the |
1222 we need to align the block to te left edge of the mobile screen. This method finds out the |
1184 new scroll distance |
1223 new scroll distance |
1185 */ |
1224 */ |
1186 void GWebTouchNavigation::setNewScrollDistance(QPoint blockCanvasPoint, int thresholdCheckVal) |
1225 void GWebTouchNavigation::setNewScrollDistance(QPoint blockCanvasPoint, int thresholdCheckVal) |
1187 { |
1226 { |
1188 m_scrollDistance.setX(m_actualScrollDistance.x()); |
1227 m_scrollDistance.setX(m_actualScrollDistance.x()); |
1189 m_scrollDistance.setY(m_actualScrollDistance.y()); |
1228 m_scrollDistance.setY(m_actualScrollDistance.y()); |
1190 if(blockCanvasPoint.x() > 0) { |
1229 if (blockCanvasPoint.x() > 0) { |
1191 //Checks whether the block falls within the threshold after right to left swipe |
1230 //Checks whether the block falls within the threshold after right to left swipe |
1192 if( (thresholdCheckVal < KThresholdForRightToLeftMotion) && (thresholdCheckVal > 0)) { |
1231 if ( (thresholdCheckVal < KThresholdForRightToLeftMotion) && (thresholdCheckVal > 0)) { |
1193 //if the block is within the threshold range already and the user tries |
1232 //if the block is within the threshold range already and the user tries |
1194 //to swipe from left to right , then let it move to right. Dont try to |
1233 //to swipe from left to right , then let it move to right. Dont try to |
1195 //snap to the left edge . |
1234 //snap to the left edge . |
1196 if(m_actualScrollDistance.x() > 0) { |
1235 if (m_actualScrollDistance.x() > 0) { |
1197 m_scrollDistance.setX(blockCanvasPoint.x() - XAlignVal); |
1236 m_scrollDistance.setX(blockCanvasPoint.x() - XAlignVal); |
1198 } |
1237 } |
1199 } |
1238 } |
1200 } |
1239 } |
1201 else { |
1240 else { |
1202 //Checks whether the block falls within the threshold after left to right swipe |
1241 //Checks whether the block falls within the threshold after left to right swipe |
1203 if( (thresholdCheckVal > KThresholdForLeftToRightMotion) && (thresholdCheckVal < 0)) { |
1242 if ( (thresholdCheckVal > KThresholdForLeftToRightMotion) && (thresholdCheckVal < 0)) { |
1204 //if the block is within the threshold range already and the user tries |
1243 //if the block is within the threshold range already and the user tries |
1205 //to swipe from right to left , then let it move to left. Dont try to |
1244 //to swipe from right to left , then let it move to left. Dont try to |
1206 //snap to the left edge . |
1245 //snap to the left edge . |
1207 if (m_actualScrollDistance.x() < 0) { |
1246 if (m_actualScrollDistance.x() < 0) { |
1208 m_scrollDistance.setX(blockCanvasPoint.x() - XAlignVal); |
1247 m_scrollDistance.setX(blockCanvasPoint.x() - XAlignVal); |
1209 } |
1248 } |
1210 } |
1249 } |
1211 |
1250 |
1212 } |
1251 } |
1213 } |
1252 } |
1214 |
1253 |
1215 |
1254 |
1216 /* |
1255 /* |
1221 m_prevPoint.setX(m_scrollDistance.x()); |
1260 m_prevPoint.setX(m_scrollDistance.x()); |
1222 m_prevPoint.setY(m_scrollDistance.y()); |
1261 m_prevPoint.setY(m_scrollDistance.y()); |
1223 |
1262 |
1224 m_scrollDistance.setX(m_scrollDistance.x() * KDecelerationFactor); |
1263 m_scrollDistance.setX(m_scrollDistance.x() * KDecelerationFactor); |
1225 m_scrollDistance.setY(m_scrollDistance.y() * KDecelerationFactor); |
1264 m_scrollDistance.setY(m_scrollDistance.y() * KDecelerationFactor); |
1226 |
1265 |
1227 //round off the values |
1266 //round off the values |
1228 m_scrollDistance.setX(roundOff(m_scrollDistance.x())); |
1267 m_scrollDistance.setX(roundOff(m_scrollDistance.x())); |
1229 m_scrollDistance.setY(roundOff(m_scrollDistance.y())); |
1268 m_scrollDistance.setY(roundOff(m_scrollDistance.y())); |
1230 |
1269 |
1231 int diffX = m_prevPoint.x() - m_scrollDistance.x(); |
1270 int diffX = m_prevPoint.x() - m_scrollDistance.x(); |
1232 int diffY = m_prevPoint.y() - m_scrollDistance.y(); |
1271 int diffY = m_prevPoint.y() - m_scrollDistance.y(); |
1233 |
1272 |
1234 if (((m_scrollDistance.x() == 0) && (m_scrollDistance.y() == 0)) |
1273 if (((m_scrollDistance.x() == 0) && (m_scrollDistance.y() == 0)) |
1235 || ((diffX == 0) && (diffY == 0))) { |
1274 || ((diffX == 0) && (diffY == 0))) { |
1236 scrollCurrentFrame(m_prevPoint.x(), m_prevPoint.y()); |
1275 scrollCurrentFrame(m_prevPoint.x(), m_prevPoint.y()); |
1237 m_scrollTimer->stop(); |
1276 m_scrollTimer->stop(); |
1238 return; |
1277 return; |
1239 } |
1278 } |
1240 scrollCurrentFrame(diffX, diffY); |
1279 scrollCurrentFrame(diffX, diffY); |
1241 } |
1280 } |
1242 void GWebTouchNavigation::timerControl() |
1281 |
1243 { |
1282 void GWebTouchNavigation::onLongPressTimer() |
1244 stopTimer();// stop timer as soon as timeout |
1283 { |
1245 emit longPressEvent(); |
1284 stopLongPressTimer();// stop timer as soon as timeout |
1246 } |
1285 emit longPressEvent(m_touchPosition); |
1247 void GWebTouchNavigation::startTimer() |
1286 } |
1248 { |
1287 |
1249 m_longPressTimer = new QTimer(this); |
1288 void GWebTouchNavigation::startLongPressTimer() |
1250 connect(m_longPressTimer,SIGNAL(timeout()),this,SLOT(timerControl())); |
1289 { |
1251 m_longPressTimer->start(LONG_PRESS_DURATION); |
1290 if(!m_longPressTimer) { |
1252 } |
1291 m_longPressTimer = new QTimer(this); |
1253 void GWebTouchNavigation::stopTimer() |
1292 connect(m_longPressTimer, SIGNAL(timeout()), this, SLOT(onLongPressTimer())); |
1254 { |
1293 } |
1255 if(m_longPressTimer){ |
1294 else { |
1256 m_longPressTimer->stop(); |
1295 m_longPressTimer->stop(); |
1257 delete m_longPressTimer; |
1296 } |
1258 m_longPressTimer = 0; |
1297 m_longPressTimer->start(KLongPressDuration); |
1259 } |
1298 } |
1260 } |
1299 |
1261 void GWebTouchNavigation::getFocusedElement() |
1300 void GWebTouchNavigation::stopLongPressTimer() |
1262 { |
1301 { |
1263 QWebHitTestResult htRes = m_frame->hitTestContent(m_touchPosition); |
1302 if (m_longPressTimer){ |
1264 wrtBrowserDefs::BrowserElementType elType = wrtBrowserUtils::getTypeFromElement(htRes); |
1303 m_longPressTimer->stop(); |
1265 emit focusElementChanged(elType); |
1304 delete m_longPressTimer; |
|
1305 m_longPressTimer = 0; |
|
1306 } |
|
1307 } |
|
1308 |
|
1309 void GWebTouchNavigation::emitFocusedElementChanged() |
|
1310 { |
|
1311 QWebHitTestResult htRes = m_frame->hitTestContent(m_touchPosition); |
|
1312 wrtBrowserDefs::BrowserElementType elType = wrtBrowserUtils::getTypeFromElement(htRes); |
|
1313 emit focusElementChanged(elType); |
1266 } |
1314 } |
1267 |
1315 |
1268 void GWebTouchNavigation::scrollCurrentFrame (int dx, int dy) |
1316 void GWebTouchNavigation::scrollCurrentFrame (int dx, int dy) |
1269 { |
1317 { |
1270 QPoint scrollPosition = m_frame->scrollPosition(); |
1318 QPoint scrollPosition = m_frame->scrollPosition(); |
1271 if (m_frame == m_webPage->mainFrame() && |
1319 /* slide the url bar up if content is scrolled to top */ |
1272 //scrollPosition.y() < m_chrome->getSnippetRect("UrlSearchChromeId").height()) { |
1320 if (m_frame == m_webPage->mainFrame() && |
1273 scrollPosition.y() <=0 && |
1321 scrollPosition.y() <=0 && !m_isLoading && m_wantSlideViewCalls) { |
1274 !m_isLoading && |
1322 qreal slide = slideView(-dy); |
1275 !m_view->view()->currentPageIsSuperPage()) { |
1323 dy+=slide; |
1276 qreal slide = m_chrome->slideView(-dy); |
1324 } |
1277 dy+=slide; |
1325 |
1278 } |
1326 /* shrink the viewport size at bottom if content is scrolled to bottom, |
1279 |
1327 so that use can click the link under the toolbar */ |
1280 m_frame->scroll(dx, dy); |
1328 /* |
|
1329 if (m_frame == m_webPage->mainFrame()) { |
|
1330 if (scrollPosition.y() + m_webPage->viewportSize().height() >= m_frame->contentsSize().height()) { |
|
1331 qreal slide = shrinkView(-dy); |
|
1332 dy+=slide; |
|
1333 } |
|
1334 } |
|
1335 */ |
|
1336 m_frame->scroll(dx, dy); |
|
1337 |
1281 } |
1338 } |
1282 |
1339 |
1283 void GWebTouchNavigation::setCurrentFrameScrollPosition (QPoint& pos) |
1340 void GWebTouchNavigation::setCurrentFrameScrollPosition (QPoint& pos) |
1284 { |
1341 { |
1285 QPoint scrollPosition = m_frame->scrollPosition(); |
1342 QPoint scrollPosition = m_frame->scrollPosition(); |
1286 QPoint finalPos = pos; |
1343 QPoint finalPos = pos; |
1287 |
1344 int dy = scrollPosition.y() - pos.y(); |
1288 |
1345 |
1289 /* emit pageScrollPositionZero singal if it's mainFrame scrolling or scroll to top*/ |
1346 if (m_frame == m_webPage->mainFrame() && |
1290 if (m_frame == m_webPage->mainFrame() && |
|
1291 //scrollPosition.y() < m_chrome->getSnippetRect("UrlSearchChromeId").height()) { |
|
1292 scrollPosition.y() <=0 && |
1347 scrollPosition.y() <=0 && |
1293 !m_isLoading && |
1348 !m_isLoading && |
1294 !m_view->view()->currentPageIsSuperPage()) { |
1349 m_wantSlideViewCalls) { |
1295 |
1350 |
1296 int dy = scrollPosition.y() - pos.y(); |
1351 qreal slide = slideView(-dy); |
1297 qreal slide = m_chrome->slideView(-dy); |
1352 dy+=slide; |
1298 dy+=slide; |
1353 finalPos.setY(scrollPosition.y() - dy); |
1299 finalPos.setY(scrollPosition.y() - dy); |
1354 } |
1300 } |
1355 /* |
1301 |
1356 if (m_frame == m_webPage->mainFrame()) { |
|
1357 if (scrollPosition.y() + m_webPage->viewportSize().height() == m_frame->contentsSize().height()) { |
|
1358 qreal slide = shrinkView(-dy); |
|
1359 dy-=slide; |
|
1360 } |
|
1361 finalPos.setY(scrollPosition.y() - dy); |
|
1362 } |
|
1363 */ |
1302 m_frame->setScrollPosition(finalPos); |
1364 m_frame->setScrollPosition(finalPos); |
1303 } |
1365 } |
1304 |
1366 |
1305 void GWebTouchNavigation::onLoadStarted() |
1367 void GWebTouchNavigation::onLoadStarted() |
1306 { |
1368 { |
1307 m_isLoading = true; |
1369 m_isLoading = true; |
1308 } |
1370 } |
|
1371 |
1309 void GWebTouchNavigation::onLoadFinished(bool ok) |
1372 void GWebTouchNavigation::onLoadFinished(bool ok) |
1310 { |
1373 { |
1311 m_isLoading = false; |
1374 Q_UNUSED(ok) |
|
1375 m_isLoading = false; |
1312 } |
1376 } |
1313 void GWebTouchNavigation::setPage( QWebPage * page) |
1377 void GWebTouchNavigation::setPage( QWebPage * page) |
1314 { |
1378 { |
1315 disconnect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
1379 if (m_webPage) { |
1316 disconnect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
1380 disconnect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
1317 m_webPage = page ; |
1381 disconnect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
1318 connect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
1382 //disconnect(m_webPage->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &))); |
1319 connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
1383 } |
1320 } |
1384 m_webPage = page; |
1321 } |
1385 if (m_webPage) { |
|
1386 connect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
|
1387 connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
|
1388 //connect(m_webPage->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &))); |
|
1389 } |
|
1390 } |
|
1391 |
|
1392 void GWebTouchNavigation::onContentsSizeChanged(const QSize & size) |
|
1393 { |
|
1394 Q_UNUSED(size) |
|
1395 /* get the new content height, and resize the viewport size */ |
|
1396 if (m_webPage->mainFrame()->contentsSize().height() != m_contentHeight) { |
|
1397 m_contentHeight = m_webPage->mainFrame()->contentsSize().height(); |
|
1398 shrinkView(100); |
|
1399 } |
|
1400 } |
|
1401 |
|
1402 void GWebTouchNavigation::enableDClick(bool aValue) |
|
1403 { |
|
1404 m_doubleClickEnabled = aValue; |
|
1405 } |
|
1406 } |