webengine/webkitutils/stmgesturefw/src/hoveringgesturerecogniser.cpp
branchRCL_3
changeset 49 919f36ff910f
parent 28 d39add9822e2
equal deleted inserted replaced
48:79859ed3eea9 49:919f36ff910f
       
     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:   
       
    15 *
       
    16 */
       
    17 
       
    18 #include "hoveringgesturerecogniser.h"
       
    19 #include "GenericSimpleGesture.h"
       
    20 #include "rt_uievent.h"
       
    21 
       
    22 #include "filelogger.h"
       
    23 
       
    24 using namespace stmGesture ;
       
    25 
       
    26 extern long Mm2Pixels(long mm) ;
       
    27 
       
    28 
       
    29 CHoveringGestureRecogniser::CHoveringGestureRecogniser(MGestureListener* aListener) :
       
    30     CGestureRecogniser(aListener)
       
    31 {
       
    32     m_hovering = false ;
       
    33     m_hoveringspeed = 0.9f ;
       
    34 }
       
    35 
       
    36 CHoveringGestureRecogniser* CHoveringGestureRecogniser::NewL(MGestureListener* aListener)
       
    37 {
       
    38     CHoveringGestureRecogniser* self = new (ELeave) CHoveringGestureRecogniser(aListener) ;
       
    39     return self;
       
    40 }
       
    41 
       
    42 CHoveringGestureRecogniser::~CHoveringGestureRecogniser()
       
    43 {
       
    44 }
       
    45 
       
    46 TGestureRecognitionState CHoveringGestureRecogniser::recognise(int numOfActiveStreams,
       
    47         MGestureEngineIf* pge)
       
    48 {
       
    49     TGestureRecognitionState state = ENotMyGesture;
       
    50     // Check if we are enabled or not
       
    51     if (!m_gestureEnabled) return state ;
       
    52 
       
    53     // Look at the events to see if it looks like hovering
       
    54     if (numOfActiveStreams == 1)
       
    55     {
       
    56         // Then look at the event stream, it has to be tap and release
       
    57         const stmUiEventEngine::MUiEvent* puie = pge->getUiEvents(0);
       
    58         int countOfEvents = puie->countOfEvents() ;
       
    59         stmUiEventEngine::TUiEventCode eventCode = puie->Code() ;
       
    60         if (countOfEvents > 1) // do we have more than one event in the stream?
       
    61         {
       
    62             // Then look at the events to see if they are suitable for us
       
    63             // should we check that all of the events are targeted to our window?
       
    64             // currently we only check if the last one is for us and is EMove, then we pan...
       
    65             if (puie->Target() == m_powner &&
       
    66                     eventCode == stmUiEventEngine::EMove) // The last one is move in our window
       
    67             {
       
    68                 float speedX = puie->speedX() ;
       
    69                 float speedY = puie->speedY() ;
       
    70                 if (m_loggingenabled)
       
    71                 {
       
    72                     LOGARG("CHoveringGestureRecogniser: %d: num %d code %d, speed %f, limit %f",
       
    73                         m_hovering, countOfEvents, eventCode, 
       
    74                         double(speedX), double(m_hoveringspeed));
       
    75                 }
       
    76                 // It might be hovering gesture in our window, handle it
       
    77                 if (!m_hovering)
       
    78                 {
       
    79                     // we are not yet hovering, so lets see if it is slow movement
       
    80                     // but it must be movement; if it is 0.0 do not hover
       
    81                     if ( ((speedX > 0.01f) ||(speedY > 0.01f)) && 
       
    82                             ((speedX < m_hoveringspeed) || (speedY < m_hoveringspeed))
       
    83                         )
       
    84                     {
       
    85                         state = EGestureActive;
       
    86                         m_hovering = true;
       
    87                     }
       
    88                 }
       
    89                 if (m_hovering)
       
    90                 {
       
    91                     // after we've started hovering, the speed could be increased a little before we loose hovering
       
    92                     // but this adjustment is not implemented now...
       
    93                     if (speedX < m_hoveringspeed || speedY < m_hoveringspeed)
       
    94 
       
    95                     {
       
    96                         using stmUiEventEngine::TUiEventSpeed;
       
    97 
       
    98                         state = EGestureActive;
       
    99                         TUiEventSpeed speedIf(speedX, speedY);
       
   100                         stmGesture::TDirectionalGesture pgest(
       
   101                                         KUid,
       
   102                                         puie->CurrentXY(),
       
   103                                         puie->PreviousXY(),
       
   104                                         &speedIf,
       
   105                                         m_loggingenabled);
       
   106 
       
   107                         // Call the listener to inform that a Hover has occurred...
       
   108                         m_listener->gestureEnter(pgest);
       
   109                     }
       
   110                 }
       
   111             }
       
   112             else if (m_hovering)
       
   113             {
       
   114                 if (eventCode == stmUiEventEngine::ERelease) // The last one is release in any window
       
   115                 {
       
   116                     m_hovering = false ;
       
   117                     // release will handle informing of the listener
       
   118                 }
       
   119             }
       
   120         }
       
   121         else
       
   122         {
       
   123             // count of events == 1, lets see if it is EMove, then we take it and start hovering
       
   124             if (puie->Target() == m_powner &&
       
   125                     eventCode == stmUiEventEngine::EMove) // The only one is move in our window
       
   126             {
       
   127                 if (m_loggingenabled)
       
   128                 {
       
   129                     LOGARG("CHoveringGestureRecogniser: move: num %d code %d", countOfEvents, eventCode);
       
   130                 }
       
   131                 state = EGestureActive;
       
   132                 stmGesture::TDirectionalGesture pgest(
       
   133                                         KUid,
       
   134                                         puie->CurrentXY(),
       
   135                                         puie->PreviousXY(),
       
   136                                         puie,
       
   137                                         m_loggingenabled);
       
   138 
       
   139                 // Call the listener to inform that a Hover has occurred...
       
   140                 m_listener->gestureEnter(pgest);
       
   141             }
       
   142         }
       
   143     }
       
   144     if (state == ENotMyGesture)
       
   145     {
       
   146         // if it was not our gesture, then the state can not be hovering...
       
   147         m_hovering = false ;
       
   148     }
       
   149     return state;
       
   150 }
       
   151 
       
   152 void CHoveringGestureRecogniser::release(MGestureEngineIf* /*ge*/)
       
   153 {
       
   154     m_hovering = false ;
       
   155     m_listener->gestureExit(KUid) ;
       
   156 }
       
   157 
       
   158 void CHoveringGestureRecogniser::setHoveringSpeed(float aSpeed) __SOFTFP
       
   159 {
       
   160     m_hoveringspeed = aSpeed ;
       
   161 }
       
   162