textinput/peninputarc/src/peninputanim/penpointereventsuppressor.cpp
changeset 0 eb1f2e154e89
child 22 bd83ceabce89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2009 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 "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 <penpointereventsuppressor.h>
       
    19 
       
    20 const TInt KPenPointerEventSuppressorDefaultMaxTapDuration = 400000;	// 0.4 seconds
       
    21 const TInt KPenPointerEventSuppressorDefaultMinInterDragInterval = 0;
       
    22 const TInt KPenPointerEventSuppressorDefaultMovement = 6;
       
    23 
       
    24 CPenPointerEventSuppressor* CPenPointerEventSuppressor::NewL()
       
    25 	{
       
    26 	return new (ELeave) CPenPointerEventSuppressor;
       
    27 	}
       
    28 
       
    29 CPenPointerEventSuppressor::~CPenPointerEventSuppressor()
       
    30 	{
       
    31 	
       
    32 	}
       
    33 
       
    34 CPenPointerEventSuppressor::CPenPointerEventSuppressor()
       
    35 : iMaxTapDuration(KPenPointerEventSuppressorDefaultMaxTapDuration),
       
    36   iMinInterDragInterval(KPenPointerEventSuppressorDefaultMinInterDragInterval),
       
    37   iTap(EFalse)
       
    38   	{
       
    39   	// default move limit is 6 units, which seems to be a forgiving value for finger touch
       
    40   	iMaxTapMove.iWidth = KPenPointerEventSuppressorDefaultMovement;
       
    41 	iMaxTapMove.iHeight = KPenPointerEventSuppressorDefaultMovement;
       
    42   	}
       
    43 
       
    44 TBool CPenPointerEventSuppressor::SuppressPointerEvent(
       
    45         const TPointerEvent& aPointerEvent)
       
    46 	{
       
    47 	switch ( aPointerEvent.iType )
       
    48 		{
       
    49 		case TPointerEvent::EButton1Down:
       
    50 		    {
       
    51 			iDownTime.HomeTime();
       
    52 			iTap = ETrue;
       
    53 			iDownPos = aPointerEvent.iPosition;
       
    54 			iLastEventTime = iDownTime;
       
    55 			break;
       
    56 		    }		
       
    57 		case TPointerEvent::EDrag:
       
    58 			{
       
    59 			TTime now;
       
    60 			now.HomeTime();
       
    61 			if (iTap)
       
    62 				{
       
    63 				TPoint delta = aPointerEvent.iPosition - iDownPos;
       
    64 				if (Abs(delta.iX) > iMaxTapMove.iWidth ||
       
    65 					Abs(delta.iY) > iMaxTapMove.iHeight ||
       
    66 					now.MicroSecondsFrom(iDownTime) >= iMaxTapDuration)
       
    67 					{
       
    68 					// This touch action has gone outside the parameters of a tap
       
    69 					// the drag event should be handled
       
    70 					iTap = EFalse;
       
    71 					iLastEventTime = now;
       
    72 					return EFalse;
       
    73 					}
       
    74 				else
       
    75 					{
       
    76 					// still a tap, so suppress the drag event
       
    77 					return ETrue;
       
    78 					}
       
    79 				}
       
    80 			else if (now.MicroSecondsFrom(iLastEventTime) < iMinInterDragInterval)
       
    81 				{
       
    82 				// too soon since the last drag, suppress it
       
    83 				return ETrue;
       
    84 				}
       
    85 
       
    86 			// this drag event should be handled
       
    87 			iLastEventTime = now;
       
    88 			break;
       
    89 			}
       
    90 		case TPointerEvent::EButton1Up:
       
    91 		    {
       
    92 			iTap = EFalse;
       
    93 			break;
       
    94 		    }
       
    95 		case TPointerEvent::ENullType:
       
    96 		    break;
       
    97 		default:
       
    98 			break;
       
    99 		}
       
   100 	
       
   101 	// all non-drag events should be handled
       
   102 	return EFalse;
       
   103 	}
       
   104 
       
   105 void CPenPointerEventSuppressor::SetMaxTapDuration(
       
   106         TTimeIntervalMicroSeconds aDuration)
       
   107 	{
       
   108 	iMaxTapDuration = aDuration;
       
   109 	}
       
   110 
       
   111 void CPenPointerEventSuppressor::SetMaxTapMove(TSize aMoveLimits)
       
   112 	{
       
   113 	iMaxTapMove = aMoveLimits;
       
   114 	}
       
   115 	
       
   116 void CPenPointerEventSuppressor::SetMinInterDragInterval(
       
   117         TTimeIntervalMicroSeconds aInterval)
       
   118 	{
       
   119 	iMinInterDragInterval = aInterval;
       
   120 	}