webengine/webkitutils/rt_gesturehelper/src/utils.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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 recognition utilities
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "utils.h"
       
    20 
       
    21 #include <coemain.h> // for CCoeEnv
       
    22 #include <eikappui.h>  // for CEikAppUi
       
    23 
       
    24 #include "gesturedefs.h"
       
    25 
       
    26 namespace RT_GestureHelper
       
    27     {
       
    28     /** @return the longer edge of the size */
       
    29     inline TInt LongerEdge( const TSize& aSize ) 
       
    30         {
       
    31         return Max( aSize.iHeight, aSize.iWidth );
       
    32         }
       
    33     
       
    34     // for documentation, see header file
       
    35     TRect ToleranceRect( const TPoint& aCenterPoint ) 
       
    36         {
       
    37         /*
       
    38         TSize screenSize = static_cast<CEikAppUi*>( CCoeEnv::Static()->AppUi() )
       
    39             ->ApplicationRect().Size(); 
       
    40         // multiplication has to be done first, to avoid rounding integer to 0 with division
       
    41         int toleranceLength = ( KGestureTolerancePercent * LongerEdge( screenSize ) ) / 100; 
       
    42         */
       
    43         long toleranceLength = Mm2Pixels(KFingerSize_mm) / 2;
       
    44         TRect toleranceRect( aCenterPoint, TSize() );
       
    45         // grow by the tolerance length, while keeping the center point
       
    46         toleranceRect.Shrink( -toleranceLength, -toleranceLength );
       
    47         return toleranceRect;
       
    48         }
       
    49     
       
    50     long Twips2Pixels(long twips) 
       
    51         {
       
    52         CWsScreenDevice* screen = CCoeEnv::Static()->ScreenDevice();
       
    53         TZoomFactor deviceMap(screen);
       
    54         deviceMap.SetZoomFactor(TZoomFactor::EZoomOneToOne);
       
    55         long px = deviceMap.VerticalTwipsToPixels(twips); //assuming that vertical
       
    56         return px;                                        //the same as horizontal
       
    57         
       
    58         }
       
    59     
       
    60     long Mm2Pixels(long mm) 
       
    61         {
       
    62         return Twips2Pixels(mm * KTwipsInMm); 
       
    63         }
       
    64     
       
    65     long Inches2Pixels(double inches) 
       
    66         {
       
    67         return Twips2Pixels(inches * KTwipsInInch); 
       
    68         }
       
    69 
       
    70         
       
    71     } // namespace GestureHelper