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