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