webengine/webkitutils/stmgesturefw/src/flickgesturerecogniser.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 "flickgesturerecogniser.h"
       
    20 #include "rt_uievent.h"
       
    21 #include "filelogger.h"
       
    22 //#include "flogger.h"
       
    23 
       
    24 using namespace stmGesture ;
       
    25 
       
    26 CFlickGestureRecogniser::CFlickGestureRecogniser(MGestureListener* aListener) :
       
    27     CGestureRecogniser(aListener)
       
    28 {
       
    29 }
       
    30 
       
    31 CFlickGestureRecogniser* CFlickGestureRecogniser::NewL(MGestureListener* aListener)
       
    32 {
       
    33     CFlickGestureRecogniser* self = new (ELeave) CFlickGestureRecogniser(aListener) ;
       
    34     return self;
       
    35 }
       
    36 
       
    37 CFlickGestureRecogniser::~CFlickGestureRecogniser()
       
    38 {
       
    39 }
       
    40 /*!
       
    41  * Release gesture recogniser.  Note that this one never owns the gesture, it just calls
       
    42  * the callback if it detects ERelease inside the area being watched.
       
    43  * There could be also check for the target window?
       
    44  */
       
    45 TGestureRecognitionState CFlickGestureRecogniser::recognise(int numOfActiveStreams,
       
    46         MGestureEngineIf* pge)
       
    47 {
       
    48     TGestureRecognitionState state = ENotMyGesture;
       
    49     // Check if we are enabled or not
       
    50     if (!m_gestureEnabled) return state ;
       
    51 
       
    52     // Look at the events to see if it looks like flick with one pointer
       
    53     if (numOfActiveStreams == 1)
       
    54     {
       
    55         const stmUiEventEngine::MUiEvent* puie = pge->getUiEvents(0);
       
    56         if (!puie) return state;
       
    57         int countOfEvents = puie->countOfEvents();
       
    58         stmUiEventEngine::TUiEventCode eventCode = puie->Code();
       
    59         if (m_loggingenabled)
       
    60         {
       
    61             LOGARG("CFlickGestureRecogniser: %d num %d code %d", eventCode, countOfEvents, eventCode);
       
    62 
       
    63         }
       
    64         if (m_powner == puie->Target() && eventCode == stmUiEventEngine::ERelease)
       
    65         {
       
    66             if (m_loggingenabled)
       
    67             {
       
    68                 LOGARG("CFlickGestureRecogniser: 0x%x ERelease: num %d code %d, %d", this, countOfEvents, puie->CurrentXY().iX, puie->CurrentXY().iY);
       
    69             }
       
    70             // Check if the speed before release was fast enough for flick
       
    71             const stmUiEventEngine::MUiEvent* puieprev = puie->previousEvent() ;
       
    72             if (puieprev && puieprev->Code() == stmUiEventEngine::EMove)
       
    73             {
       
    74                 using stmUiEventEngine::TUiEventSpeed;
       
    75 
       
    76                 float thespeedX = puieprev->speedX() ;
       
    77                 float thespeedY = puieprev->speedY() ;
       
    78                 if (m_loggingenabled)
       
    79                 {
       
    80                     LOGARG("CFlickGestureRecogniser: prev speed: %f (limit: %f)", double(thespeedX), double(m_speed)) ;
       
    81                 }
       
    82                 if (Abs( thespeedX) >= m_speed || Abs( thespeedY) >= m_speed )
       
    83                 {
       
    84                     state = EGestureActive ;
       
    85 
       
    86                     TUiEventSpeed speedIf(thespeedX, thespeedY);
       
    87 
       
    88                     // issue the flick gesture using the TDirectionalGesture (it has the speed and direction)
       
    89                     stmGesture::TDirectionalGesture pgest(
       
    90                             KUid,
       
    91                             puieprev->CurrentXY(),
       
    92                             puieprev->PreviousXY(),
       
    93                             &speedIf,
       
    94                             m_loggingenabled);
       
    95 
       
    96                     // Call the listener to inform that a flick has occurred...
       
    97                     m_listener->gestureEnter(pgest);
       
    98                 }
       
    99             }
       
   100         }
       
   101     }
       
   102     return state;
       
   103 }
       
   104 void CFlickGestureRecogniser::release(MGestureEngineIf* /*ge*/)
       
   105 {
       
   106     if (m_loggingenabled)
       
   107     {
       
   108         LOGARG("CFlickGestureRecogniser: 0x%x flick", this);
       
   109     }
       
   110 }
       
   111 void CFlickGestureRecogniser::setFlickingSpeed(float aSpeed) __SOFTFP
       
   112 {
       
   113     m_speed = aSpeed ;
       
   114 }