webengine/webkitutils/stmgesturefw/src/edgescrollgesturerecogniser.cpp
changeset 42 d39add9822e2
equal deleted inserted replaced
38:6297cdf66332 42:d39add9822e2
       
     1 /*
       
     2 * Copyright (c) 2008 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 the License "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:  Gesture helper implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "GenericSimpleGesture.h"
       
    19 #include "edgescrollgesturerecogniser.h"
       
    20 #include "rt_uievent.h"
       
    21 #include "filelogger.h"
       
    22 
       
    23 using namespace stmGesture ;
       
    24 
       
    25 CEdgeScrollGestureRecogniser::CEdgeScrollGestureRecogniser(MGestureListener* aListener) :
       
    26     CPeriodic(0), m_listener(aListener) , m_area()
       
    27 {
       
    28     m_powner = aListener->getOwner() ;
       
    29     m_gestureEnabled = true ;
       
    30     m_rangesizeInPixels = 10 ;  // by default 10 pixels from the edges is the area
       
    31 }
       
    32 
       
    33 CEdgeScrollGestureRecogniser* CEdgeScrollGestureRecogniser::NewL(MGestureListener* aListener)
       
    34 {
       
    35     CEdgeScrollGestureRecogniser* self = new (ELeave) CEdgeScrollGestureRecogniser(aListener) ;
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL(); // construct base class
       
    38     CActiveScheduler::Add(self);
       
    39     CleanupStack::Pop(self);
       
    40     return self;
       
    41 }
       
    42 
       
    43 CEdgeScrollGestureRecogniser::~CEdgeScrollGestureRecogniser()
       
    44 {
       
    45     Cancel();
       
    46 }
       
    47 
       
    48 TGestureRecognitionState CEdgeScrollGestureRecogniser::recognise(int numOfActiveStreams,
       
    49         MGestureEngineIf* pge)
       
    50 {
       
    51     TGestureRecognitionState state = ENotMyGesture;
       
    52     // Check if we are enabled or not
       
    53     if (!m_gestureEnabled) return state ;
       
    54 
       
    55     // Look at the events to see if it looks like edge scroll with one pointer
       
    56     if (numOfActiveStreams == 1)
       
    57     {
       
    58         // Then look at the event stream, it has to be EHold
       
    59         const stmUiEventEngine::MUiEvent* puie = pge->getUiEvents(0);
       
    60         int countOfEvents = puie->countOfEvents();
       
    61         stmUiEventEngine::TUiEventCode eventCode = puie->Code();
       
    62 
       
    63         if (m_loggingenabled)
       
    64         {
       
    65             LOGARG("CEdgeScrollGestureRecogniser: %d num %d code %d", 
       
    66                     eventCode, countOfEvents, eventCode);
       
    67         }
       
    68 
       
    69         if (eventCode == stmUiEventEngine::EHold) // The last one is EHold, look if it is near the area defined
       
    70         {
       
    71             const TPoint& p = puie->CurrentXY();
       
    72             if (m_loggingenabled)
       
    73             {
       
    74                 LOGARG("CEdgeScrollGestureRecogniser: 0x%x EHold: num %d code %d, %d", 
       
    75                         this, countOfEvents, p.iX, p.iY);
       
    76                 LOGARG("CEdgeScrollGestureRecogniser: area, %d,%d %d,%d, range: %d", 
       
    77                         m_area.iTl.iX, 
       
    78                         m_area.iTl.iY, 
       
    79                         m_area.iBr.iX, 
       
    80                         m_area.iBr.iY, 
       
    81                         m_rangesizeInPixels);
       
    82             }
       
    83             // check where the point is inside the area defined but outside of the area shrinked by m_rangesizeInPixels.
       
    84             TRect rcInner = m_area ;
       
    85             rcInner.Shrink(m_rangesizeInPixels, m_rangesizeInPixels) ;
       
    86             if (m_area.Contains(p) && !rcInner.Contains(p))
       
    87             {
       
    88                 if (m_loggingenabled)
       
    89                 {
       
    90                     LOGARG("CEdgeScrollGestureRecogniser: HIT, (%d,%d) in %d,%d %d,%d, range: %d", 
       
    91                             p.iX, p.iY, m_area.iTl.iX, m_area.iTl.iY, 
       
    92                             m_area.iBr.iX, m_area.iBr.iY, 
       
    93                             m_rangesizeInPixels);
       
    94                 }
       
    95 
       
    96                 state = EGestureActive ;
       
    97                 // this is edge scroll, check where it is about...
       
    98                 TEdgeScroll scrolltype = EEdgeScrollUnknown ;
       
    99                 if (p.iY < m_area.iTl.iY + m_rangesizeInPixels)
       
   100                     scrolltype = EEdgeScrollUp ;   // if Y is small enough, it is always up
       
   101                 else if (p.iY > m_area.iBr.iY - m_rangesizeInPixels)
       
   102                     scrolltype = EEdgeScrollDown ; // if Y is big enough, it is always down
       
   103                 else if (p.iX < m_area.iTl.iX + m_rangesizeInPixels)
       
   104                     scrolltype = EEdgeScrollLeft ; // if X is small enough, it is always left
       
   105                 else  if (p.iX > m_area.iBr.iX - m_rangesizeInPixels)
       
   106                     scrolltype = EEdgeScrollRight ;   // if X is big enough, it is always right
       
   107                 // issue the edge scroll gesture
       
   108                 stmGesture::TGenericSimpleGesture pgest(KUid, p, scrolltype, puie) ;
       
   109                 // Call the listener to inform that a Tap has occurred...
       
   110                 m_listener->gestureEnter(pgest) ;
       
   111             }
       
   112         }
       
   113     }
       
   114     return state;
       
   115 }
       
   116 
       
   117 void CEdgeScrollGestureRecogniser::release(MGestureEngineIf* /*ge*/)
       
   118 {
       
   119     Cancel() ;  // some other gesture took hold of the thing, do not send gesture
       
   120     if (m_loggingenabled)
       
   121     {
       
   122         LOGARG("CEdgeScrollGestureRecogniser: 0x%x release", this);
       
   123     }
       
   124 }
       
   125 
       
   126 void CEdgeScrollGestureRecogniser::RunL()
       
   127 {
       
   128     if (m_loggingenabled)
       
   129     {
       
   130         LOGARG("CEdgeScrollGestureRecogniser: 0x%x timer", this);
       
   131     }
       
   132 }
       
   133 
       
   134 void CEdgeScrollGestureRecogniser::enableLogging(bool loggingOn)
       
   135 {
       
   136     m_loggingenabled = loggingOn;
       
   137 }
       
   138 
       
   139 void CEdgeScrollGestureRecogniser::enable(bool enabled)
       
   140 {
       
   141     m_gestureEnabled = enabled ;
       
   142 }
       
   143 
       
   144 bool CEdgeScrollGestureRecogniser::isEnabled()
       
   145 {
       
   146     return m_gestureEnabled ;
       
   147 }
       
   148 
       
   149 void CEdgeScrollGestureRecogniser::setOwner(CCoeControl* owner)
       
   150 {
       
   151     m_powner = owner;
       
   152 }
       
   153 
       
   154 void CEdgeScrollGestureRecogniser::setScrollRange(int rangeInPixels)
       
   155 {
       
   156     m_rangesizeInPixels = rangeInPixels ;
       
   157 }
       
   158 
       
   159 void CEdgeScrollGestureRecogniser::setArea(const TRect& theArea)
       
   160 {
       
   161     m_area = theArea ;
       
   162     if (m_loggingenabled)
       
   163     {
       
   164         LOGARG("CEdgeScrollGestureRecogniser: set area, %d,%d %d,%d", m_area.iTl.iX, m_area.iTl.iY, m_area.iBr.iX, m_area.iBr.iY);
       
   165     }
       
   166 }