webengine/webkitutils/stmgesturefw/src/UiEvent.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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32math.h>
       
    19 #include "UiEvent.h"
       
    20 #include "filelogger.h"
       
    21 #include "statemachine.h" // for stmUiEventEngine::Distance(dx,dy)
       
    22 //#include "flogger.h"
       
    23 
       
    24 using namespace stmUiEventEngine ;
       
    25 
       
    26 static const char* const eventNames[] = {  // for debugging purposes define the names of the UI events
       
    27         "noEvent",
       
    28         "ETouch",
       
    29         "EHold",
       
    30         "EDrag",
       
    31         "ERelease",
       
    32         "ENull"
       
    33 } ;
       
    34 
       
    35 const char* stmUiEventEngine::EventName(stmUiEventEngine::TUiEventCode aCode)
       
    36 {
       
    37     return eventNames[aCode];
       
    38 }
       
    39 
       
    40 CUiEvent* CUiEvent::NewL(
       
    41     TUiEventCode aCode,
       
    42     const TPoint& aStart, const TPoint& aXY, const TPoint& aPreviousXY,
       
    43     bool aTimerExpired, void* aTarget, TTimeIntervalMicroSeconds aInterval,
       
    44     int aIndex, TInt64 aTimestamp)
       
    45 {
       
    46     CUiEvent* self = new (ELeave) CUiEvent(aCode, aStart, aXY, aPreviousXY,
       
    47         aTimerExpired, aTarget, aInterval, aIndex, aTimestamp) ;
       
    48     return self;
       
    49 }
       
    50 
       
    51 CUiEvent::CUiEvent(
       
    52     TUiEventCode aCode,
       
    53     const TPoint& aStart, const TPoint& aXY, const TPoint& aPreviousXY,
       
    54     bool aTimerExpired, void* aTarget, TTimeIntervalMicroSeconds aInterval,
       
    55     int aIndex, TInt64 aTimestamp) :
       
    56     m_code(aCode), m_start(aStart), m_XY(aXY), m_previousXY(aPreviousXY),
       
    57     m_statetransition(aInterval), m_target(aTarget), m_timerExpired(aTimerExpired),
       
    58     m_index(aIndex), m_previousEvent(NULL), m_timestamp(aTimestamp)
       
    59 {
       
    60 }
       
    61 
       
    62 CUiEvent::~CUiEvent()
       
    63 {
       
    64     delete m_previousEvent ;
       
    65     m_previousEvent = NULL ;
       
    66 }
       
    67 const TPoint& CUiEvent::StartPos() const
       
    68 {
       
    69     return m_start ;
       
    70 }
       
    71 const TPoint& CUiEvent::CurrentXY() const
       
    72 {
       
    73     return m_XY ;
       
    74 }
       
    75 TUiEventCode CUiEvent::Code()const
       
    76 {
       
    77     return m_code ;
       
    78 }
       
    79 const TPoint& CUiEvent::PreviousXY() const
       
    80 {
       
    81     return m_previousXY ;
       
    82 }
       
    83 TTimeIntervalMicroSeconds CUiEvent::StateTransition() const
       
    84 {
       
    85     return m_statetransition ;
       
    86 }
       
    87 bool CUiEvent::TimerExpired() const
       
    88 {
       
    89     return m_timerExpired ;
       
    90 }
       
    91 void * CUiEvent::Target() const
       
    92 {
       
    93     return m_target ;
       
    94 }
       
    95 int CUiEvent::Index() const
       
    96 {
       
    97     return m_index ;
       
    98 }
       
    99 void CUiEvent::setPrevious(CUiEvent* aEvent)
       
   100 {
       
   101     m_previousEvent = aEvent ;
       
   102 }
       
   103 MUiEvent* CUiEvent::previousEvent() const
       
   104 {
       
   105     return m_previousEvent ;
       
   106 }
       
   107 int CUiEvent::countOfEvents() const
       
   108 {
       
   109     int count = 1 ;
       
   110     for(CUiEvent* prev = m_previousEvent; prev; prev = prev->m_previousEvent)
       
   111         {
       
   112         ++count;
       
   113         }
       
   114     return count ;
       
   115 }
       
   116 TInt64 CUiEvent::timestamp() const
       
   117 {
       
   118     return m_timestamp ;
       
   119 }
       
   120 
       
   121 float CUiEvent::speedX() const __SOFTFP
       
   122 {
       
   123     int distX = m_XY.iX - m_previousXY.iX;
       
   124     // now calculate speed
       
   125     float elapsed = float (m_statetransition.Int64()/1000) ; // use ms as time unit
       
   126 
       
   127     float speed = 0;
       
   128     if (elapsed == 0) {
       
   129         elapsed = 5.0;    // if time is 0, take 5ms
       
   130     }
       
   131     speed = float(distX)/elapsed ;
       
   132     return speed ;
       
   133 }
       
   134 
       
   135 float CUiEvent::speedY() const __SOFTFP
       
   136 {
       
   137     int distY = m_XY.iY - m_previousXY.iY;
       
   138     // now calculate speed
       
   139     float elapsed = float (m_statetransition.Int64()/1000) ; // use ms as time unit
       
   140     float speed = 0;
       
   141     if (elapsed == 0) {
       
   142         elapsed = 5.0;    // if time is 0, take 5ms
       
   143     }
       
   144     speed = float(distY)/elapsed ;
       
   145     return speed ;
       
   146 }
       
   147