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