webengine/webkitutils/stmgesturefw/src/updowngesturerecogniser.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 "updowngesturerecogniser.h"
       
    19 #include "GenericSimpleGesture.h"
       
    20 #include "rt_uievent.h"
       
    21 
       
    22 #include "filelogger.h"
       
    23 
       
    24 using namespace stmGesture ;
       
    25 
       
    26 _LIT8(KUpdownName, "Updown") ;
       
    27 
       
    28 CUpdownGestureRecogniser::CUpdownGestureRecogniser(MGestureListener* aListener) : 
       
    29         CGestureRecogniser(aListener)
       
    30 {
       
    31 }
       
    32 
       
    33 CUpdownGestureRecogniser* CUpdownGestureRecogniser::NewL(MGestureListener* aListener)
       
    34 {
       
    35     CUpdownGestureRecogniser* self = new (ELeave) CUpdownGestureRecogniser(aListener) ;
       
    36     return self;
       
    37 }
       
    38 
       
    39 CUpdownGestureRecogniser::~CUpdownGestureRecogniser()
       
    40 {
       
    41 }
       
    42 
       
    43 TGestureRecognitionState CUpdownGestureRecogniser::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("CUpdownGestureRecogniser: UpDown: 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                 // check that the Y movement is bigger
       
    75                 if (Abs(dp.iX) < Abs(dp.iY))
       
    76                 {
       
    77                     state = EGestureActive;
       
    78                     stmGesture::TGenericSimpleGesture pgest(KUid, p, dp.iY, puie) ;
       
    79                     // Give the gesture a name
       
    80                     pgest.setName(KUpdownName) ;
       
    81                     // Call the listener to inform that a UpDown has occurred...
       
    82                     m_listener->gestureEnter(pgest) ;
       
    83                 }
       
    84             }
       
    85         }
       
    86     }
       
    87     return state;
       
    88 }
       
    89 
       
    90 void CUpdownGestureRecogniser::release(MGestureEngineIf* /*ge*/)
       
    91 {
       
    92     m_listener->gestureExit(KUid) ;
       
    93 }
       
    94