webengine/webkitutils/stmgesturefw/src/longpressgesturerecogniser.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 "GenericSimpleGesture.h"
       
    19 #include "longpressgesturerecogniser.h"
       
    20 #include "rt_uievent.h"
       
    21 #include "filelogger.h"
       
    22 
       
    23 using namespace stmGesture ;
       
    24 
       
    25 CLongPressGestureRecogniser::CLongPressGestureRecogniser(MGestureListener* aListener) :
       
    26     CGestureRecogniser(aListener)
       
    27 {
       
    28 }
       
    29 
       
    30 CLongPressGestureRecogniser* CLongPressGestureRecogniser::NewL(MGestureListener* aListener)
       
    31 {
       
    32     CLongPressGestureRecogniser* self = new (ELeave) CLongPressGestureRecogniser(aListener) ;
       
    33     return self;
       
    34 }
       
    35 
       
    36 CLongPressGestureRecogniser::~CLongPressGestureRecogniser()
       
    37 {
       
    38 }
       
    39 
       
    40 /*!
       
    41  * recognise the long press; basically it is just the EHold UI event
       
    42  */
       
    43 TGestureRecognitionState CLongPressGestureRecogniser::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 
       
    51     // Look at the events to see if it looks like long press with one pointer
       
    52     if (numOfActiveStreams == 1)
       
    53     {
       
    54         // Then look at the event stream, it has to be EHold
       
    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 
       
    60         if (m_loggingenabled)
       
    61         {
       
    62             LOGARG("CLongPressGestureRecogniser: %d num %d code %d", eventCode, countOfEvents, eventCode);
       
    63         }
       
    64         if (puie->Target() == m_powner && eventCode == stmUiEventEngine::EHold) // The last one is EHold, look if it is near our borders
       
    65         {
       
    66             const TPoint& p = puie->CurrentXY() ;
       
    67             if (m_loggingenabled)
       
    68             {
       
    69                 LOGARG("CLongPressGestureRecogniser: (%d, %d) in (%d,%d)(%d,%d)", p.iX, p.iY,
       
    70                         m_area.iTl.iX, m_area.iTl.iY, m_area.iBr.iX, m_area.iBr.iY);
       
    71             }
       
    72              state = EGestureActive ;
       
    73              // issue the long press gesture
       
    74              stmGesture::TGenericSimpleGesture pgest(KUid, p, 0, puie) ; // TODO: speed is 0?
       
    75              // Call the listener to inform that the gesture has occurred...
       
    76              m_listener->gestureEnter(pgest) ;
       
    77         }
       
    78     }
       
    79     return state;
       
    80 }
       
    81 
       
    82 void CLongPressGestureRecogniser::release(MGestureEngineIf* /*ge*/)
       
    83 {
       
    84     if (m_loggingenabled)
       
    85     {
       
    86         LOGARG("CLongPressGestureRecogniser: 0x%x release", this);
       
    87     }
       
    88 }
       
    89 
       
    90 void CLongPressGestureRecogniser::setArea(const TRect& theArea)
       
    91 {
       
    92     m_area = theArea ;
       
    93 }