webengine/webkitutils/stmgesturefw/src/leftrightgesturerecogniser.cpp
changeset 65 5bfc169077b2
parent 42 d39add9822e2
child 66 cacf6ee57968
equal deleted inserted replaced
42:d39add9822e2 65:5bfc169077b2
     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 "leftrightgesturerecogniser.h"
       
    19 #include "GenericSimpleGesture.h"
       
    20 #include "rt_uievent.h"
       
    21 
       
    22 #include "filelogger.h"
       
    23 
       
    24 using namespace stmGesture ;
       
    25 
       
    26 _LIT8(KLeftrightName, "Leftlight");
       
    27 
       
    28 CLeftrightGestureRecogniser::CLeftrightGestureRecogniser(MGestureListener* aListener) : 
       
    29         CGestureRecogniser(aListener)
       
    30 {
       
    31 }
       
    32 
       
    33 CLeftrightGestureRecogniser* CLeftrightGestureRecogniser::NewL(MGestureListener* aListener)
       
    34 {
       
    35     CLeftrightGestureRecogniser* self = new (ELeave) CLeftrightGestureRecogniser(aListener) ;
       
    36     return self;
       
    37 }
       
    38 
       
    39 CLeftrightGestureRecogniser::~CLeftrightGestureRecogniser()
       
    40 {
       
    41 }
       
    42 
       
    43 TGestureRecognitionState CLeftrightGestureRecogniser::recognise(int numOfActiveStreams,
       
    44         MGestureEngineIf* pge)
       
    45 {
       
    46     TGestureRecognitionState state = ENotMyGesture;
       
    47     // Check if we are enabled or not
       
    48     if (!m_gestureEnabled) return state ;
       
    49 
       
    50     // Look at the events to see if it looks like a tap or double tap
       
    51     if (numOfActiveStreams == 1)
       
    52     {
       
    53         // Then look at the event stream, it has to be tap and release
       
    54         const stmUiEventEngine::MUiEvent* puie = pge->getUiEvents(0);
       
    55         int countOfEvents = puie->countOfEvents() ;
       
    56         stmUiEventEngine::TUiEventCode eventCode = puie->Code() ;
       
    57         if (countOfEvents > 1) // do we have more than one event in the stream?
       
    58         {
       
    59             // Then look at the events to see if they are suitable for us
       
    60             // should we check that all of the events are targeted to our window?
       
    61             // currently we only check if the last one is for us and is EMove, then check if |x| > |y|
       
    62             if (puie->Target() == m_powner &&
       
    63                     eventCode == stmUiEventEngine::EMove) // The last one is move in our window
       
    64 
       
    65             {
       
    66                 if (m_loggingenabled)
       
    67                 {
       
    68                     LOGARG("CLeftrightGestureRecogniser: Leftright: num %d code %d", 
       
    69                             countOfEvents, eventCode);
       
    70                 }
       
    71                 // Is it leftright gesture in our window?
       
    72                 const TPoint& p = puie->CurrentXY();
       
    73                 TPoint dp = p - puie->PreviousXY();
       
    74                 if (Abs(dp.iX) > Abs(dp.iY))
       
    75                 {
       
    76                     state = EGestureActive;
       
    77                     stmGesture::TGenericSimpleGesture pgest(KUid, p, dp.iX, puie) ;
       
    78                     pgest.setName(KLeftrightName) ;
       
    79                     // Call the listener to inform that a Leftright has occurred...
       
    80                     m_listener->gestureEnter(pgest) ;
       
    81                 }
       
    82             }
       
    83         }
       
    84     }
       
    85     return state;
       
    86 }
       
    87 
       
    88 void CLeftrightGestureRecogniser::release(MGestureEngineIf* /*ge*/)
       
    89 {
       
    90     m_listener->gestureExit(KUid) ;
       
    91 }
       
    92