webengine/webkitutils/stmgesturefw/src/releasegesturerecogniser.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 "releasegesturerecogniser.h"
       
    20 #include "rt_uievent.h"
       
    21 #include "filelogger.h"
       
    22 
       
    23 using namespace stmGesture ;
       
    24 
       
    25 _LIT8(KReleaseName, "Release");
       
    26 
       
    27 CReleaseGestureRecogniser::CReleaseGestureRecogniser(MGestureListener* aListener) :
       
    28     CGestureRecogniser(aListener)
       
    29 {
       
    30 }
       
    31 
       
    32 CReleaseGestureRecogniser* CReleaseGestureRecogniser::NewL(MGestureListener* aListener)
       
    33 {
       
    34     CReleaseGestureRecogniser* self = new (ELeave) CReleaseGestureRecogniser(aListener) ;
       
    35     return self;
       
    36 }
       
    37 
       
    38 CReleaseGestureRecogniser::~CReleaseGestureRecogniser()
       
    39 {
       
    40 }
       
    41 
       
    42 /*!
       
    43  * Release gesture recogniser.  Note that this one never owns the gesture, it just calls
       
    44  * the callback if it detects ERelease inside the area being watched.
       
    45  * There could be also check for the target window?
       
    46  */
       
    47 TGestureRecognitionState CReleaseGestureRecogniser::recognise(int numOfActiveStreams,
       
    48         MGestureEngineIf* pge)
       
    49 {
       
    50     TGestureRecognitionState state = ENotMyGesture;
       
    51     // Check if we are enabled or not
       
    52     if (!m_gestureEnabled) return state ;
       
    53 
       
    54     // Look at the events to see if it looks like edge scroll with one pointer
       
    55     if (numOfActiveStreams == 1)
       
    56     {
       
    57         // Then look at the event stream, it has to be EHold
       
    58         const stmUiEventEngine::MUiEvent* puie = pge->getUiEvents(0);
       
    59         if (!puie) return state;
       
    60         
       
    61         int countOfEvents = puie->countOfEvents();
       
    62         stmUiEventEngine::TUiEventCode eventCode = puie->Code();
       
    63 
       
    64         if (m_loggingenabled)
       
    65         {
       
    66             LOGARG("CReleaseGestureRecogniser: %d num %d code %d", eventCode, countOfEvents, eventCode);
       
    67         }
       
    68         if (eventCode == stmUiEventEngine::ERelease)
       
    69         {
       
    70             if (m_loggingenabled)
       
    71             {
       
    72                 LOGARG("CReleaseGestureRecogniser: 0x%x ERelease: num %d code %d, %d", 
       
    73                         this, countOfEvents, puie->CurrentXY().iX, puie->CurrentXY().iY);
       
    74                 LOGARG("CReleaseGestureRecogniser: area, %d,%d %d,%d", 
       
    75                         m_area.iTl.iX, m_area.iTl.iY, m_area.iBr.iX, m_area.iBr.iY);
       
    76             }
       
    77             bool produceGesture ;
       
    78             if(!m_area.IsEmpty())
       
    79             {
       
    80                 produceGesture = m_area.Contains(puie->CurrentXY()) ;
       
    81                 if(produceGesture && m_loggingenabled)
       
    82                 {
       
    83                     LOGARG("CReleaseGestureRecogniser: HIT area (%d,%d) in %d,%d %d,%d", 
       
    84                             puie->CurrentXY().iX, puie->CurrentXY().iY, 
       
    85                             m_area.iTl.iX, m_area.iTl.iY, 
       
    86                             m_area.iBr.iX, m_area.iBr.iY);
       
    87                 }
       
    88             }
       
    89             else
       
    90             {
       
    91                 produceGesture = (m_powner == puie->Target()) ;  // no area defined, touch detected in the window
       
    92             }
       
    93             if (produceGesture)
       
    94             {
       
    95                 state = EGestureActive ;
       
    96                 // issue the release gesture using the GenericSimpleGesture
       
    97                 stmGesture::TGenericSimpleGesture pgest(KUid, puie->CurrentXY());
       
    98                 // Give the gesture a name
       
    99                 pgest.setName(KReleaseName) ;
       
   100                 // Call the listener to inform that a release has occurred...
       
   101                 m_listener->gestureEnter(pgest);
       
   102             }
       
   103         }
       
   104     }
       
   105     return state;
       
   106 }
       
   107 
       
   108 void CReleaseGestureRecogniser::release(MGestureEngineIf* /*ge*/)
       
   109 {
       
   110     if (m_loggingenabled)
       
   111     {
       
   112         LOGARG("CReleaseGestureRecogniser: 0x%x release", this);
       
   113     }
       
   114 }
       
   115 
       
   116 void CReleaseGestureRecogniser::setArea(const TRect& theArea)
       
   117 {
       
   118     m_area = theArea ;
       
   119     if (m_loggingenabled)
       
   120     {
       
   121         LOGARG("CReleaseGestureRecogniser: area, %d,%d %d,%d", 
       
   122                 m_area.iTl.iX, m_area.iTl.iY, 
       
   123                 m_area.iBr.iX, m_area.iBr.iY);
       
   124     }
       
   125 }
       
   126