18 * Description: |
18 * Description: |
19 * |
19 * |
20 */ |
20 */ |
21 |
21 |
22 #include "GWebTouchNavigation.h" |
22 #include "GWebTouchNavigation.h" |
|
23 #include "wrtBrowserUtils.h" |
|
24 |
23 #include <QWebPage> |
25 #include <QWebPage> |
24 #include <QWebFrame> |
26 #include <QWebFrame> |
25 #include <QApplication> |
27 #include <QApplication> |
26 #include <QWebElement> |
28 #include <QWebElement> |
27 #include "GWebContentViewWidget.h" |
|
28 #include "GWebContentView.h" |
|
29 #include <QGraphicsSceneMouseEvent> |
29 #include <QGraphicsSceneMouseEvent> |
30 #include <QTimer> |
30 #include <QTimer> |
31 #include <qmath.h> |
31 #include <qmath.h> |
32 #include <QDebug> |
32 #include <QDebug> |
33 #include <QGraphicsView> |
33 #include <QGraphicsView> |
34 #include <QGraphicsSceneContextMenuEvent> |
34 |
35 |
35 |
36 #include "wrtBrowserUtils.h" |
36 namespace GVA { |
37 #include "ChromeWidget.h" |
|
38 #include <QDebug> |
|
39 |
|
40 |
|
41 #define LONG_PRESS_DURATION 500 |
|
42 |
37 |
43 const int KFlickSpeed = 400; |
38 const int KFlickSpeed = 400; |
44 const qreal PI = 3.1415926535897932; |
39 const qreal PI = 3.1415926535897932; |
45 const qreal KAngleTolerance = 30; |
40 const qreal KAngleTolerance = 30; |
46 const int KAnimationTimeout = 40; |
41 const int KAnimationTimeout = 40; |
56 const int KTouchThresholdX = 20; |
51 const int KTouchThresholdX = 20; |
57 const int KTouchThresholdY = 20; |
52 const int KTouchThresholdY = 20; |
58 const int KPanThreshold = 2; |
53 const int KPanThreshold = 2; |
59 const int KThreshHoldValForLink = 10; |
54 const int KThreshHoldValForLink = 10; |
60 const qreal KDeccelaration = 1000.00; |
55 const qreal KDeccelaration = 1000.00; |
61 //const int KDefaultViewportWidth = 980; |
|
62 //const int KDefaultPortraitScaleWidth = 540; |
|
63 |
|
64 //const int KKineticTimeout = 60; |
|
65 |
56 |
66 static const int KStartPanDistance = 50; |
57 static const int KStartPanDistance = 50; |
67 static const int KWaitForClickTimeoutMS = 200; |
58 static const int KWaitForClickTimeoutMS = 200; |
|
59 static const int KLongPressDuration = 1000; |
|
60 static const int KLongPressThreshold = 30; |
68 //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 |
69 static const int KPanModeChangeDelta = 100; |
62 static const int KPanModeChangeDelta = 100; |
70 |
|
71 |
|
72 namespace GVA { |
|
73 |
63 |
74 /*! |
64 /*! |
75 \class WebTouchNavigation |
65 \class WebTouchNavigation |
76 \since cwrt 1.0 |
66 \since cwrt 1.0 |
77 \brief cwrt navigation. |
67 \brief cwrt navigation. |
97 , m_textSelected(false) |
87 , m_textSelected(false) |
98 , m_isLoading(false) |
88 , m_isLoading(false) |
99 , m_contentHeight(0) |
89 , m_contentHeight(0) |
100 , m_isContextEvent(false) |
90 , m_isContextEvent(false) |
101 , m_wantSlideViewCalls(true) |
91 , m_wantSlideViewCalls(true) |
|
92 , m_doubleClickEnabled(true) |
102 { |
93 { |
103 install(); |
94 install(); |
104 connect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
95 connect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
105 connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
96 connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
106 } |
97 } |
|
98 |
107 inline void GWebTouchNavigation::cancelPressEvent() { |
99 inline void GWebTouchNavigation::cancelPressEvent() { |
108 if (m_pressEvent) { |
100 if (m_pressEvent) { |
109 delete m_pressEvent; |
101 delete m_pressEvent; |
110 m_pressEvent = 0; |
102 m_pressEvent = 0; |
111 } |
103 } |
120 |
112 |
121 /*! |
113 /*! |
122 */ |
114 */ |
123 GWebTouchNavigation::~GWebTouchNavigation() |
115 GWebTouchNavigation::~GWebTouchNavigation() |
124 { |
116 { |
125 disconnect(m_doubleClickTimer, SIGNAL(timeout()), this, SLOT(doubleClickTimerExpired())); |
117 delete m_doubleClickTimer; |
126 if (m_doubleClickTimer) { |
|
127 m_doubleClickTimer->stop(); |
|
128 delete m_doubleClickTimer; |
|
129 } |
|
130 disconnect(m_scrollTimer, SIGNAL(timeout()),this,SLOT(pan())); |
|
131 delete m_scrollTimer; |
118 delete m_scrollTimer; |
132 |
|
133 disconnect(m_kineticTimer, SIGNAL(timeout()),this,SLOT(kineticScroll())); |
|
134 delete m_kineticTimer; |
119 delete m_kineticTimer; |
|
120 delete m_longPressTimer; |
135 uninstall(); |
121 uninstall(); |
136 |
122 |
137 cancelPressEvent(); |
123 cancelPressEvent(); |
138 cancelReleaseEvent(); |
124 cancelReleaseEvent(); |
139 } |
125 } |
291 */ |
277 */ |
292 void GWebTouchNavigation::scrollFrame(const QPoint& diff) |
278 void GWebTouchNavigation::scrollFrame(const QPoint& diff) |
293 { |
279 { |
294 if (qAbs(diff.x()) < KPanThreshold && qAbs(diff.y()) < KPanThreshold) |
280 if (qAbs(diff.x()) < KPanThreshold && qAbs(diff.y()) < KPanThreshold) |
295 return; |
281 return; |
296 else if (m_dragPoints.size() == 1) { |
282 else if (m_dragPoints.size() == 1) { |
297 setViewBlockElement(QWebElement()); |
283 setViewBlockElement(QWebElement()); |
298 } |
284 } |
299 |
285 |
300 if (!m_isPanning) { |
286 if (!m_isPanning) { |
301 qreal dy = qAbs(diff.y()); |
287 qreal dy = qAbs(diff.y()); |
302 qreal dx = qAbs(diff.x()); |
288 qreal dx = qAbs(diff.x()); |
303 if (dy > KStartPanDistance || dx > KStartPanDistance |
289 if (dy > KStartPanDistance || dx > KStartPanDistance |
304 || m_delayedPressMoment.elapsed() > KWaitForClickTimeoutMS) { |
290 || m_delayedPressMoment.elapsed() > KWaitForClickTimeoutMS) { |
305 //get the scroll direction |
291 //get the scroll direction |
306 Direction scrollDir = findDirectionWithAngle(diff); |
292 Direction scrollDir = findDirectionWithAngle(diff); |
307 if (scrollDir == UP || scrollDir == DOWN) |
293 if (scrollDir == UP || scrollDir == DOWN) |
308 startPanGesture(VerticalPan); |
294 startPanGesture(VerticalPan); |
309 else if (scrollDir == LEFT || scrollDir == RIGHT) |
295 else if (scrollDir == LEFT || scrollDir == RIGHT) |
312 startPanGesture(RandomPan); |
298 startPanGesture(RandomPan); |
313 m_isPanning = true; |
299 m_isPanning = true; |
314 } |
300 } |
315 } |
301 } |
316 |
302 |
317 if (m_isPanning) { |
303 if (m_isPanning) { |
318 m_scrolled= false; |
304 m_scrolled= false; |
319 m_frame = getNextScrollableFrame(diff); |
305 m_frame = getNextScrollableFrame(diff); |
320 QPoint scrollPosition = m_frame->scrollPosition(); |
306 QPoint scrollPosition = m_frame->scrollPosition(); |
321 if (diff.manhattanLength()) |
307 if (diff.manhattanLength()) |
322 panBy(diff); |
308 panBy(diff); |
323 |
309 |
324 m_scrolled = (scrollPosition != m_frame->scrollPosition()); |
310 m_scrolled = (scrollPosition != m_frame->scrollPosition()); |
325 } |
311 } |
326 } |
312 } |
327 |
313 |
328 void GWebTouchNavigation::startPanGesture(PanDirection directionHint) { |
314 void GWebTouchNavigation::startPanGesture(PanDirection directionHint) { |
329 emit startingPanGesture((int)directionHint); |
315 emit startingPanGesture((int)directionHint); |
330 m_panDirection = directionHint; |
316 m_panDirection = directionHint; |
467 m_scrolled = false; |
453 m_scrolled = false; |
468 m_ishighlighted = false; |
454 m_ishighlighted = false; |
469 m_higlightedPos = m_touchPosition = pos; |
455 m_higlightedPos = m_touchPosition = pos; |
470 m_frame = m_webPage->frameAt(pos); |
456 m_frame = m_webPage->frameAt(pos); |
471 if (!m_frame) |
457 if (!m_frame) |
472 m_frame = m_webPage->currentFrame(); |
458 m_frame = m_webPage->currentFrame(); |
473 |
459 |
474 m_dragPoints.clear(); |
460 m_dragPoints.clear(); |
475 |
461 |
476 DragPoint dragPoint; |
462 DragPoint dragPoint; |
477 dragPoint.iPoint = m_touchPosition; |
463 dragPoint.iPoint = m_touchPosition; |
505 cancelPressEvent(); |
491 cancelPressEvent(); |
506 cancelReleaseEvent(); |
492 cancelReleaseEvent(); |
507 |
493 |
508 m_doubleClickTimer->start(KDoubleClickTimeOut); |
494 m_doubleClickTimer->start(KDoubleClickTimeOut); |
509 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(); |
510 } |
498 } |
511 |
499 |
512 void GWebTouchNavigation::handleMousePressEvent(QMouseEvent* ev) |
500 void GWebTouchNavigation::handleMousePressEvent(QMouseEvent* ev) |
513 { |
501 { |
514 if (!ev) return; |
502 if (!ev) return; |
515 m_lastMoveEventTime.setHMS(0,0,0,0); //H, M, S, mS |
503 m_lastMoveEventTime.setHMS(0,0,0,0); //H, M, S, mS |
516 if (!m_longPressTimer){ |
|
517 delete m_longPressTimer; |
|
518 m_longPressTimer = 0; |
|
519 } |
|
520 startTimer(); |
|
521 m_scrolled = false; |
504 m_scrolled = false; |
522 m_ishighlighted = false; |
505 m_ishighlighted = false; |
523 m_higlightedPos = m_touchPosition = ev->pos(); |
506 m_higlightedPos = m_touchPosition = ev->pos(); |
524 m_frame = m_webPage->frameAt(ev->pos()); |
507 m_frame = m_webPage->frameAt(ev->pos()); |
525 if (!m_frame) |
508 if (!m_frame) |
533 m_dragPoints.append(dragPoint); |
516 m_dragPoints.append(dragPoint); |
534 |
517 |
535 m_offset = 0; |
518 m_offset = 0; |
536 |
519 |
537 highlightableElement(ev); |
520 highlightableElement(ev); |
538 getFocusedElement(); |
521 emitFocusedElementChanged(); |
539 |
522 |
540 //send a mouse press |
523 //send a mouse press |
541 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)); |
542 m_webPage->event(&iev); |
525 m_webPage->event(&iev); |
543 m_textSelected = false; |
526 m_textSelected = false; |
558 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) |
541 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) |
559 m_doubleClickTimer->stop(); |
542 m_doubleClickTimer->stop(); |
560 } |
543 } |
561 |
544 |
562 bool GWebTouchNavigation::canDehighlight(QMouseEvent* ev) |
545 bool GWebTouchNavigation::canDehighlight(QMouseEvent* ev) |
563 { |
546 { |
564 bool checkDehighlight = false; |
547 bool checkDehighlight = false; |
565 QPoint pt = ev->pos() + m_frame->scrollPosition(); |
548 QPoint pt = ev->pos() + m_frame->scrollPosition(); |
566 |
549 |
567 if (m_scrolled && m_ishighlighted) { |
550 if (m_scrolled && m_ishighlighted) { |
568 checkDehighlight = true; |
551 checkDehighlight = true; |
576 else if (m_offset){ |
559 else if (m_offset){ |
577 QPoint centerpt = m_anchorElement.geometry().center(); |
560 QPoint centerpt = m_anchorElement.geometry().center(); |
578 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()); |
579 |
562 |
580 if (newoffset <= m_offset ) { |
563 if (newoffset <= m_offset ) { |
581 m_offset = newoffset; |
564 m_offset = newoffset; |
582 checkDehighlight = false; |
565 checkDehighlight = false; |
583 } |
566 } |
584 else { |
567 else { |
585 m_offset =0; |
568 m_offset =0; |
586 checkDehighlight = true; |
569 checkDehighlight = true; |
587 } |
570 } |
590 checkDehighlight = true; |
573 checkDehighlight = true; |
591 } |
574 } |
592 } |
575 } |
593 return checkDehighlight; |
576 return checkDehighlight; |
594 } |
577 } |
595 void GWebTouchNavigation::dehighlight(QMouseEvent* ev) |
578 void GWebTouchNavigation::dehighlight(QMouseEvent* ev) |
596 { |
579 { |
597 m_higlightedPos = QPoint(0,0); |
580 m_higlightedPos = QPoint(0,0); |
598 m_ishighlighted = false; |
581 m_ishighlighted = false; |
599 QMouseEvent iev(QEvent::MouseButtonPress,m_higlightedPos,ev->button(), ev->buttons(), ev->modifiers()); |
582 QMouseEvent iev(QEvent::MouseButtonPress,m_higlightedPos,ev->button(), ev->buttons(), ev->modifiers()); |
600 m_webPage->event(&iev); |
583 m_webPage->event(&iev); |
611 Scrolls the frame |
594 Scrolls the frame |
612 \sa scrollFrame() |
595 \sa scrollFrame() |
613 */ |
596 */ |
614 void GWebTouchNavigation::mouseMoveEvent(const QPoint& pos, const QPoint& diff) |
597 void GWebTouchNavigation::mouseMoveEvent(const QPoint& pos, const QPoint& diff) |
615 { |
598 { |
|
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 } |
616 |
605 |
617 if (m_pressEvent){ |
606 if (m_pressEvent){ |
618 QPoint diff2 = m_pressEvent->pos() - pos; |
607 QPoint diff2 = m_pressEvent->pos() - pos; |
619 if (qAbs(diff2.x()) < KTouchThresholdX && qAbs(diff2.y()) < KTouchThresholdY) |
608 if (qAbs(diff2.x()) < KTouchThresholdX && qAbs(diff2.y()) < KTouchThresholdY) { |
620 return; |
609 return; |
|
610 } |
621 } |
611 } |
622 |
612 |
623 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) { |
613 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) { |
624 //send mousePressEvent |
614 //send mousePressEvent |
625 m_doubleClickTimer->stop(); |
615 m_doubleClickTimer->stop(); |
626 handleMousePressEvent(m_pressEvent); |
616 handleMousePressEvent(m_pressEvent); |
627 cancelPressEvent(); |
617 cancelPressEvent(); |
628 } |
618 } |
629 |
619 |
630 stopTimer(); |
|
631 QMouseEvent tmpEv(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
620 QMouseEvent tmpEv(QEvent::MouseMove, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); |
632 handleHighlightChange(&tmpEv); |
621 handleHighlightChange(&tmpEv); |
633 |
622 |
634 //the viewport hasn't been scrolled |
623 //the viewport hasn't been scrolled |
635 if (!m_scrolled) { |
624 if (!m_scrolled) { |
647 } |
636 } |
648 } |
637 } |
649 if (!m_textSelected) |
638 if (!m_textSelected) |
650 scrollFrame(diff); |
639 scrollFrame(diff); |
651 |
640 |
652 //m_touchPosition = pos; |
641 //m_touchPosition = pos; |
653 DragPoint dragPoint; |
642 DragPoint dragPoint; |
654 dragPoint.iPoint = pos; |
643 dragPoint.iPoint = pos; |
655 dragPoint.iTime = QTime::currentTime(); |
644 dragPoint.iTime = QTime::currentTime(); |
656 m_dragPoints.append(dragPoint); |
645 m_dragPoints.append(dragPoint); |
657 |
646 |
658 QTime now(QTime::currentTime()); |
647 QTime now(QTime::currentTime()); |
659 m_lastMoveEventTime.setHMS(now.hour(),now.minute(), now.second(), now.msec()); |
648 m_lastMoveEventTime.setHMS(now.hour(),now.minute(), now.second(), now.msec()); |
660 |
649 |
661 while (m_dragPoints.size() > 4) |
650 while (m_dragPoints.size() > 4) |
662 m_dragPoints.removeFirst(); |
651 m_dragPoints.removeFirst(); |
663 |
652 |
664 } |
653 } |
665 |
654 |
666 /*! |
655 /*! |
667 If WebCanvas or QWebFrame were scrolled starts the deceleration alogrithm |
656 If WebCanvas or QWebFrame were scrolled starts the deceleration alogrithm |
668 Otherwise sends the mouse release event to QWebPage |
657 Otherwise sends the mouse release event to QWebPage |
669 \sa startDeceleration() |
658 \sa startDeceleration() |
670 */ |
659 */ |
671 void GWebTouchNavigation::mouseReleaseEvent(const QPoint& pos) |
660 void GWebTouchNavigation::mouseReleaseEvent(const QPoint& pos) |
672 { |
661 { |
|
662 stopLongPressTimer(); |
|
663 |
673 if (m_isPanning) |
664 if (m_isPanning) |
674 m_isPanning = false; |
665 m_isPanning = false; |
675 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) { |
666 if (m_doubleClickTimer && m_doubleClickTimer->isActive()) { |
676 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); |
677 return; |
668 return; |
707 void GWebTouchNavigation::handleMouseReleaseEvent(QMouseEvent* ev) |
698 void GWebTouchNavigation::handleMouseReleaseEvent(QMouseEvent* ev) |
708 { |
699 { |
709 m_frame = m_webPage->frameAt(ev->pos()); |
700 m_frame = m_webPage->frameAt(ev->pos()); |
710 if (!m_frame) |
701 if (!m_frame) |
711 m_frame = m_webPage->currentFrame(); |
702 m_frame = m_webPage->currentFrame(); |
712 assert(m_frame); |
703 Q_ASSERT(m_frame); |
713 |
704 |
714 stopTimer(); |
705 stopLongPressTimer(); |
715 if (m_scrolled) { |
706 if (m_scrolled) { |
716 int msecs = 0; |
707 int msecs = 0; |
717 if (!m_lastMoveEventTime.isNull()) { |
708 if (!m_lastMoveEventTime.isNull()) { |
718 //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 |
719 QTime now(QTime::currentTime()); |
710 QTime now(QTime::currentTime()); |
720 msecs = m_lastMoveEventTime.msecsTo(now); |
711 msecs = m_lastMoveEventTime.msecsTo(now); |
733 setNewScrollDistance(blockCanvasPoint, thresholdCheckVal); |
724 setNewScrollDistance(blockCanvasPoint, thresholdCheckVal); |
734 } |
725 } |
735 startScrollTimer(); |
726 startScrollTimer(); |
736 } |
727 } |
737 } else { |
728 } else { |
|
729 // we don't want to automatically display the SIP (Software input panel) by qtwebkit |
|
730 bool sipEnabled = qApp->autoSipEnabled(); |
|
731 qApp->setAutoSipEnabled(false); |
738 QMouseEvent iev = m_ishighlighted ? |
732 QMouseEvent iev = m_ishighlighted ? |
739 QMouseEvent(ev->type(), m_higlightedPos, ev->button(), ev->buttons(), getEventModifier(m_higlightedPos)) : |
733 QMouseEvent(ev->type(), m_higlightedPos, ev->button(), ev->buttons(), getEventModifier(m_higlightedPos)) : |
740 QMouseEvent(QEvent::MouseButtonRelease, m_touchPosition, ev->button(), ev->buttons(), getEventModifier(m_touchPosition)); |
734 QMouseEvent(QEvent::MouseButtonRelease, m_touchPosition, ev->button(), ev->buttons(), getEventModifier(m_touchPosition)); |
741 m_webPage->event(&iev); |
735 m_webPage->event(&iev); |
|
736 qApp->setAutoSipEnabled(sipEnabled); |
742 #if defined __SYMBIAN32__ |
737 #if defined __SYMBIAN32__ |
743 // FIXME Remove this, it will be fixed Qt 4.6.3 ? |
738 // FIXME Remove this, it will be fixed Qt 4.6.3 ? |
744 if (ev->button() == Qt::LeftButton) { |
739 if (ev->button() == Qt::LeftButton) { |
745 QWebHitTestResult htr = m_frame->hitTestContent(ev->pos()); |
740 QWebHitTestResult htr = m_frame->hitTestContent(ev->pos()); |
746 if (htr.isContentEditable()) { |
741 if (htr.isContentEditable()) { |
772 handleDoubleClickEvent(&tmpEv); |
767 handleDoubleClickEvent(&tmpEv); |
773 } |
768 } |
774 |
769 |
775 void GWebTouchNavigation::handleDoubleClickEvent(QMouseEvent* ev) |
770 void GWebTouchNavigation::handleDoubleClickEvent(QMouseEvent* ev) |
776 { |
771 { |
|
772 if (!m_doubleClickEnabled) |
|
773 return; |
|
774 |
777 QPoint imageFocusPoint; |
775 QPoint imageFocusPoint; |
778 QWebHitTestResult hitTest = getHitTestResult(ev); |
776 QWebHitTestResult hitTest = getHitTestResult(ev); |
779 |
777 |
780 QWebElement block = hitTest.element(); |
778 QWebElement block = hitTest.element(); |
781 |
779 |
1046 if (m_scrollDistance.x() < (-(documentTouchPoint.x()-m_touchPosition.x()))) |
1044 if (m_scrollDistance.x() < (-(documentTouchPoint.x()-m_touchPosition.x()))) |
1047 m_scrollDistance.setX(-(documentTouchPoint.x()-m_touchPosition.x())); |
1045 m_scrollDistance.setX(-(documentTouchPoint.x()-m_touchPosition.x())); |
1048 if (m_scrollDistance.y() > ((contentSize.height()-documentViewPoint.y())/2)) |
1046 if (m_scrollDistance.y() > ((contentSize.height()-documentViewPoint.y())/2)) |
1049 m_scrollDistance.setY((contentSize.height()-documentViewPoint.y())/2); |
1047 m_scrollDistance.setY((contentSize.height()-documentViewPoint.y())/2); |
1050 break; |
1048 break; |
|
1049 default: break; |
1051 } |
1050 } |
1052 } |
1051 } |
1053 |
1052 |
1054 /* |
1053 /* |
1055 Distinguishes b/w swipe and flick |
1054 Distinguishes b/w swipe and flick |
1277 m_scrollTimer->stop(); |
1276 m_scrollTimer->stop(); |
1278 return; |
1277 return; |
1279 } |
1278 } |
1280 scrollCurrentFrame(diffX, diffY); |
1279 scrollCurrentFrame(diffX, diffY); |
1281 } |
1280 } |
1282 void GWebTouchNavigation::timerControl() |
1281 |
1283 { |
1282 void GWebTouchNavigation::onLongPressTimer() |
1284 stopTimer();// stop timer as soon as timeout |
1283 { |
1285 emit longPressEvent(); |
1284 stopLongPressTimer();// stop timer as soon as timeout |
1286 } |
1285 emit longPressEvent(m_touchPosition); |
1287 void GWebTouchNavigation::startTimer() |
1286 } |
1288 { |
1287 |
1289 m_longPressTimer = new QTimer(this); |
1288 void GWebTouchNavigation::startLongPressTimer() |
1290 connect(m_longPressTimer,SIGNAL(timeout()),this,SLOT(timerControl())); |
1289 { |
1291 m_longPressTimer->start(LONG_PRESS_DURATION); |
1290 if(!m_longPressTimer) { |
1292 } |
1291 m_longPressTimer = new QTimer(this); |
1293 void GWebTouchNavigation::stopTimer() |
1292 connect(m_longPressTimer, SIGNAL(timeout()), this, SLOT(onLongPressTimer())); |
|
1293 } |
|
1294 else { |
|
1295 m_longPressTimer->stop(); |
|
1296 } |
|
1297 m_longPressTimer->start(KLongPressDuration); |
|
1298 } |
|
1299 |
|
1300 void GWebTouchNavigation::stopLongPressTimer() |
1294 { |
1301 { |
1295 if (m_longPressTimer){ |
1302 if (m_longPressTimer){ |
1296 m_longPressTimer->stop(); |
1303 m_longPressTimer->stop(); |
1297 delete m_longPressTimer; |
1304 delete m_longPressTimer; |
1298 m_longPressTimer = 0; |
1305 m_longPressTimer = 0; |
1299 } |
1306 } |
1300 } |
1307 } |
1301 void GWebTouchNavigation::getFocusedElement() |
1308 |
|
1309 void GWebTouchNavigation::emitFocusedElementChanged() |
1302 { |
1310 { |
1303 QWebHitTestResult htRes = m_frame->hitTestContent(m_touchPosition); |
1311 QWebHitTestResult htRes = m_frame->hitTestContent(m_touchPosition); |
1304 wrtBrowserDefs::BrowserElementType elType = wrtBrowserUtils::getTypeFromElement(htRes); |
1312 wrtBrowserDefs::BrowserElementType elType = wrtBrowserUtils::getTypeFromElement(htRes); |
1305 emit focusElementChanged(elType); |
1313 emit focusElementChanged(elType); |
1306 } |
1314 } |
1315 dy+=slide; |
1323 dy+=slide; |
1316 } |
1324 } |
1317 |
1325 |
1318 /* shrink the viewport size at bottom if content is scrolled to bottom, |
1326 /* shrink the viewport size at bottom if content is scrolled to bottom, |
1319 so that use can click the link under the toolbar */ |
1327 so that use can click the link under the toolbar */ |
|
1328 /* |
1320 if (m_frame == m_webPage->mainFrame()) { |
1329 if (m_frame == m_webPage->mainFrame()) { |
1321 if (scrollPosition.y() + m_webPage->viewportSize().height() >= m_frame->contentsSize().height()) { |
1330 if (scrollPosition.y() + m_webPage->viewportSize().height() >= m_frame->contentsSize().height()) { |
1322 qreal slide = shrinkView(-dy); |
1331 qreal slide = shrinkView(-dy); |
1323 dy+=slide; |
1332 dy+=slide; |
1324 } |
1333 } |
1325 /* |
|
1326 else { |
|
1327 qDebug()<<"scrollPosition.y() = "<<scrollPosition.y()<<" m_webPage->viewportSize().height() = "<<m_webPage->viewportSize().height()<<" m_frame->contentsSize().height() = "<<m_frame->contentsSize().height(); |
|
1328 }*/ |
|
1329 } |
1334 } |
|
1335 */ |
1330 m_frame->scroll(dx, dy); |
1336 m_frame->scroll(dx, dy); |
1331 |
1337 |
1332 } |
1338 } |
1333 |
1339 |
1334 void GWebTouchNavigation::setCurrentFrameScrollPosition (QPoint& pos) |
1340 void GWebTouchNavigation::setCurrentFrameScrollPosition (QPoint& pos) |
1344 |
1350 |
1345 qreal slide = slideView(-dy); |
1351 qreal slide = slideView(-dy); |
1346 dy+=slide; |
1352 dy+=slide; |
1347 finalPos.setY(scrollPosition.y() - dy); |
1353 finalPos.setY(scrollPosition.y() - dy); |
1348 } |
1354 } |
|
1355 /* |
1349 if (m_frame == m_webPage->mainFrame()) { |
1356 if (m_frame == m_webPage->mainFrame()) { |
1350 if (scrollPosition.y() + m_webPage->viewportSize().height() == m_frame->contentsSize().height()) { |
1357 if (scrollPosition.y() + m_webPage->viewportSize().height() == m_frame->contentsSize().height()) { |
1351 qreal slide = shrinkView(-dy); |
1358 qreal slide = shrinkView(-dy); |
1352 dy-=slide; |
1359 dy-=slide; |
1353 } |
1360 } |
1354 finalPos.setY(scrollPosition.y() - dy); |
1361 finalPos.setY(scrollPosition.y() - dy); |
1355 } |
1362 } |
1356 |
1363 */ |
1357 m_frame->setScrollPosition(finalPos); |
1364 m_frame->setScrollPosition(finalPos); |
1358 } |
1365 } |
1359 |
1366 |
1360 void GWebTouchNavigation::onLoadStarted() |
1367 void GWebTouchNavigation::onLoadStarted() |
1361 { |
1368 { |
1370 void GWebTouchNavigation::setPage( QWebPage * page) |
1377 void GWebTouchNavigation::setPage( QWebPage * page) |
1371 { |
1378 { |
1372 if (m_webPage) { |
1379 if (m_webPage) { |
1373 disconnect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
1380 disconnect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
1374 disconnect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
1381 disconnect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
1375 disconnect(m_webPage->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &))); |
1382 //disconnect(m_webPage->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &))); |
1376 } |
1383 } |
1377 m_webPage = page; |
1384 m_webPage = page; |
1378 if (m_webPage) { |
1385 if (m_webPage) { |
1379 connect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
1386 connect(m_webPage, SIGNAL(loadStarted()), this, SLOT(onLoadStarted())); |
1380 connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
1387 connect(m_webPage, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); |
1381 connect(m_webPage->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &))); |
1388 //connect(m_webPage->mainFrame(), SIGNAL(contentsSizeChanged(const QSize &)), this, SLOT(onContentsSizeChanged(const QSize &))); |
1382 } |
1389 } |
1383 } |
1390 } |
1384 |
1391 |
1385 void GWebTouchNavigation::onContentsSizeChanged(const QSize & size) |
1392 void GWebTouchNavigation::onContentsSizeChanged(const QSize & size) |
1386 { |
1393 { |