idlehomescreen/xmluirendering/uiengine/src/xncontroladapterimpl.cpp
branchRCL_3
changeset 18 d05a55b217df
parent 17 b8fae6b8a148
child 23 7be2816dbabd
--- a/idlehomescreen/xmluirendering/uiengine/src/xncontroladapterimpl.cpp	Wed Mar 31 21:17:19 2010 +0300
+++ b/idlehomescreen/xmluirendering/uiengine/src/xncontroladapterimpl.cpp	Wed Apr 14 15:47:59 2010 +0300
@@ -53,7 +53,6 @@
 #include "xndomlist.h"
 #include "xnodt.h"
 #include "xnresource.h"
-#include "xnhittest.h"
 #include "xnplugindata.h"
 #include "xnnode.h"
 #include "xnpanic.h"
@@ -63,9 +62,6 @@
 #include "xneditmode.h"
 
 _LIT8(KScrollableBoxNodeName, "scrollablebox");
-        
-using namespace XnGestureHelper;
-#include "xngesture.h"
 
 // Constants
 const TInt KSkinGfxInnerRectShrink = 5;
@@ -74,7 +70,9 @@
 const TInt KLongTapStartShortDelay( 150000 ); // 0.15s for Sk
 const TInt KLongTapStartLongDelay( 500000 ); // 0.5s
 const TInt KLongTapTimeShortDelay( 600000 ); // 0.6s for SK
-const TInt KLongTapTimeLongDelay( 1500000 ); // 1.5s 
+const TInt KLongTapTimeLongDelay( 1500000 ); // 1.5s
+
+const TInt KDragThreshold = 20; // pixels
 
 // LOCAL FUNCTION PROTOTYPES
 static TRgb ConvertHslToRgb( TInt aHue, TInt aSaturation, TInt aLightness );
@@ -3356,44 +3354,6 @@
 
 // -----------------------------------------------------------------------------
 // SoftkeyNode
-// Gets the node of softkey according to index
-// -----------------------------------------------------------------------------
-//
-static CXnNode* SoftkeyNodeL( CXnNode* aMenuBarNode, const TDesC8& aSoftkey )
-    {
-    if ( aMenuBarNode )
-        {
-        XnMenuInterface::MXnMenuInterface* menuIf( NULL );
-        XnComponentInterface::MakeInterfaceL( menuIf, aMenuBarNode->AppIfL() );
-        CXnNodePluginIf* skNode( NULL );
-        if ( menuIf )
-            {
-            if ( aSoftkey == XnPropertyNames::softkey::type::KLeft )
-                {
-                skNode = menuIf->SoftKeyL(
-                    XnMenuInterface::MXnMenuInterface::ELeft );
-                }
-            else if ( aSoftkey == XnPropertyNames::softkey::type::KMiddle )
-                {
-                skNode = menuIf->SoftKeyL(
-                    XnMenuInterface::MXnMenuInterface::ECenter );
-                }
-            else if ( aSoftkey == XnPropertyNames::softkey::type::KRight )
-                {
-                skNode = menuIf->SoftKeyL(
-                    XnMenuInterface::MXnMenuInterface::ERight );
-                }
-            }
-        if ( skNode )
-            {
-            return &skNode->Node();
-            }
-        }
-    return NULL;
-    }
-
-// -----------------------------------------------------------------------------
-// SoftkeyNode
 // Gets the node of softkey according to pointer location
 // -----------------------------------------------------------------------------
 //
@@ -3654,11 +3614,8 @@
         iAnimation->Stop();
         delete iAnimation;
         }
-
-    if ( iGestureHelper )
-        {
-        delete iGestureHelper;
-        }
+    
+    delete iGestureFw;
     }
 
 // -----------------------------------------------------------------------------
@@ -3722,29 +3679,21 @@
     for ( ; temp; temp = temp->Parent() )
         {
         if ( temp == menuBar )
-            {
-            // This is softkey node
-            const TDesC8* pos( NULL );
-            node = NULL;
-
-            if ( aKeyEvent.iScanCode == EStdKeyDevice0 )
-                {
-                pos = &XnPropertyNames::softkey::type::KLeft;
-                }
-            else if ( aKeyEvent.iScanCode == EStdKeyDevice1 )
+            {            
+            // This is softkey node        
+            XnMenuInterface::MXnMenuInterface* menuIf( NULL );
+            XnComponentInterface::MakeInterfaceL( menuIf, menuBar->AppIfL() );
+        
+            if ( menuIf )
                 {
-                pos = &XnPropertyNames::softkey::type::KRight;
-                }
-            else if ( aKeyEvent.iScanCode == EStdKeyDevice3 )
-                {
-                pos = &XnPropertyNames::softkey::type::KMiddle;
+                CXnNodePluginIf* eventNode( menuIf->KeyEventNode() );
+                
+                if ( eventNode )
+                    {
+                    node = &eventNode->Node();
+                    }
                 }
-
-            if ( pos )
-                {
-                node = SoftkeyNodeL( menuBar, *pos );
-                }
-
+            
             break;
             }
         }
@@ -3759,8 +3708,7 @@
          aKeyEvent.iScanCode == EStdKeyDevice3 )  // MSK
         {
         if ( aType == EEventKeyDown )
-            {
-            iKeyDownNode = node;
+            {            
             iLongtap = EFalse;
             
             if ( aKeyEvent.iScanCode == EStdKeyDevice3 ||
@@ -3789,10 +3737,6 @@
             }
         else if( aType == EEventKey )
             {
-            if( iKeyDownNode != node)
-            	{
-                node = iKeyDownNode;
-            	}
             if ( aKeyEvent.iRepeats == 0 )
                 {
                 if ( !HasHoldTrigger( node->DomNode() ) )
@@ -3821,10 +3765,6 @@
             {
             if ( !iLongtap )
                 {
-              if( iKeyDownNode != node)
-                {
-                node = iKeyDownNode;
-                }   
                 if ( HasHoldTrigger( node->DomNode() ) )
                     {
                     // Hold trigger defined, report activate event here                   
@@ -3934,6 +3874,23 @@
     }
 
 // -----------------------------------------------------------------------------
+// CXnControlAdapterImpl::IsDragThresholdExceeded
+// Checks if drag threshold is exceeded
+// -----------------------------------------------------------------------------
+//
+TBool CXnControlAdapterImpl::IsDragThresholdExceeded( const TPoint& aPoint )
+    {
+    TBool ret = EFalse;
+    TPoint distance = aPoint - iButtonDownStartPoint;
+    if ( Abs( distance.iX ) >= KDragThreshold ||
+         Abs( distance.iY ) >= KDragThreshold )
+        {
+        ret = ETrue;
+        }
+    return ret;
+    }
+
+// -----------------------------------------------------------------------------
 // CXnControlAdapterImpl::HandlePointerEventL
 // Handle pointer events
 // -----------------------------------------------------------------------------
@@ -3945,24 +3902,15 @@
     
     CXnNode* node( &iNode.Node() );
     CXnUiEngine* engine( node->UiEngine() );
- 
-    if(!engine->IsPartialInputActive())
-        {
-        // Forward event to gesture helper
-        if( PassEventToGestureHelperL( aPointerEvent ) )
-            { 
-            CXnAppUiAdapter& appui( engine->AppUiAdapter() );
-            CXnViewData& data( appui.ViewManager().ActiveViewData() );
-            
-            CXnViewControlAdapter* control = 
-                static_cast< CXnViewControlAdapter* >( data.ViewNode()->Control() );
-            
-            control->ResetGrabbing();
-
-            // Swipe took place, consume this event
-            return ETrue;
-            }
-
+    
+    if ( !engine->IsPartialInputActive() )
+        {
+        InitializeGestureL( aPointerEvent );
+        }
+    else
+        {
+        // reset destination
+        iGestureDestination = NULL;
         }
     
     TBool menuBar( node == engine->MenuBarNode() );
@@ -4031,6 +3979,8 @@
                         
         if ( !menuBar && !engine->FocusedNode() )
             {
+            // save starting point
+            iButtonDownStartPoint = event.iPosition;
             // Require focus to be shown
             engine->AppUiAdapter().ShowFocus();                
             
@@ -4045,25 +3995,18 @@
             node->SetStateL( 
                 XnPropertyNames::style::common::KFocus, 
                 XnEventSource::EStylus );
-            node->SetStateL( 
-                XnPropertyNames::style::common::KPressedDown );
             }        
         }
     else if ( event.iType == TPointerEvent::EDrag )
         {        
         if ( node->IsStateSet( XnPropertyNames::style::common::KFocus ) )
             {
-            if ( !node->MarginRect().Contains( event.iPosition ) )
+            if ( IsDragThresholdExceeded( event.iPosition ) ||
+                 !node->MarginRect().Contains( event.iPosition ) )
                 {
-                // Remove pressed down
+                // Remove focus
                 node->UnsetStateL(
-                    XnPropertyNames::style::common::KPressedDown );
-                }
-            if ( node->MarginRect().Contains( event.iPosition ) )
-                {
-                // Add pressed down
-                node->SetStateL(
-                    XnPropertyNames::style::common::KPressedDown );
+                    XnPropertyNames::style::common::KFocus );
                 }
             }
         }
@@ -4076,8 +4019,7 @@
                 node->SetStateL( XnPropertyNames::style::common::KActive );
                 }          
             else if ( ( node->MarginRect().Contains( event.iPosition ) &&
-               node->IsStateSet( XnPropertyNames::style::common::KFocus ) &&
-               node->IsStateSet( XnPropertyNames::style::common::KPressedDown ) ) )
+               node->IsStateSet( XnPropertyNames::style::common::KFocus ) ) )
                 {
 #ifdef RD_TACTILE_FEEDBACK            
                 MTouchFeedback* feedback( MTouchFeedback::Instance() );
@@ -5525,7 +5467,8 @@
 
     if ( CreateGestureHelperL( aNode.Node() ) )
         {
-        iGestureHelper = CXnGestureHelper::NewL( aNode.Node() );
+        iGestureFw = CAknTouchGestureFw::NewL( *this, aAdapter );
+        iGestureFw->SetGestureInterestL( EAknTouchGestureFwGroupFlick );
         }
     }
 
@@ -5865,104 +5808,58 @@
     }
 
 // -----------------------------------------------------------------------------
-// PassEventToGestureHelperL
-// Forwards event to gesturehelper
+// InitializeGestureL
+// Sets up gesture
 // -----------------------------------------------------------------------------
 //
-TBool CXnControlAdapterImpl::PassEventToGestureHelperL(
+void CXnControlAdapterImpl::InitializeGestureL(
     const TPointerEvent& aPointerEvent )
     {
-    TBool ret( EFalse );
+    if ( !iGestureFw || aPointerEvent.iType != TPointerEvent::EButton1Down )
+        {
+        return;
+        }
+    
+    CXnUiEngine* engine( iNode.Node().UiEngine() );                               
+    // Set default destination                     
+    iGestureDestination = &iNode.Node();
+    
+    RPointerArray< CXnPluginData >& plugins( 
+        engine->ViewManager()->ActiveViewData().PluginData() );
     
-    CXnNode* node( &iNode.Node() );
-    CXnUiEngine* engine( node->UiEngine() );
-
-    if ( iGestureHelper && iGestureHelper->Owner() == node )
-        {
-        if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
-            {                               
-            // Set default destination                     
-            iGestureHelper->SetDestination( iGestureHelper->Owner() );
+    for ( TInt i = 0; i < plugins.Count(); i++ )
+        {
+        CXnPluginData* plugin( plugins[i] );
+                                   
+        if ( plugin->Occupied() )
+            {
+            CXnNode* widget( plugin->Node()->LayoutNode() );
             
-            RPointerArray< CXnPluginData >& plugins( 
-                engine->ViewManager()->ActiveViewData().PluginData() );
-            
-            for ( TInt i = 0; i < plugins.Count(); i++ )
+            if ( widget->MarginRect().Contains( aPointerEvent.iPosition ) )
                 {
-                CXnPluginData* plugin( plugins[i] );
-                                           
-                if ( plugin->Occupied() )
+                // Resolve swipe destination
+                CXnProperty* prop( widget->GetPropertyL( 
+                    XnPropertyNames::common::KSwipeDestination ) );
+                
+                if ( prop )
                     {
-                    CXnNode* widget( plugin->Node()->LayoutNode() );
-                    
-                    if ( widget->MarginRect().Contains( aPointerEvent.iPosition ) )
-                        {
-                        // Resolve swipe destination
-                        CXnProperty* prop( widget->GetPropertyL( 
-                            XnPropertyNames::common::KSwipeDestination ) );
+                    const TDesC8& value( prop->StringValue() );
                         
-                        if ( prop )
-                            {
-                            const TDesC8& value( prop->StringValue() );
-                                
-                            if( value == XnPropertyNames::KWidget )
-                                {
-                                // Set widget as destination    
-                                iGestureHelper->SetDestination( widget );
-                                }
-                            else if( value == XnPropertyNames::KNone )
-                                {
-                                // Set no destination    
-                                iGestureHelper->SetDestination( NULL );
-                                }
-                            }
-                        
-                        break;
+                    if( value == XnPropertyNames::KWidget )
+                        {
+                        // Set widget as destination    
+                        iGestureDestination = widget;
+                        }
+                    else if( value == XnPropertyNames::KNone )
+                        {
+                        // Set no destination    
+                        iGestureDestination = NULL;
                         }
                     }
+                break;
                 }
             }
-
-        TXnGestureCode result( iGestureHelper->HandlePointerEventL( aPointerEvent ) );
-        
-        const TDesC8* swipe( NULL );
-    
-        if ( result == EGestureSwipeLeft )
-            {
-            swipe = &XnPropertyNames::action::trigger::name::swipe::direction::KLeft;
-            }
-        else if ( result == EGestureSwipeRight )
-            {
-            swipe = &XnPropertyNames::action::trigger::name::swipe::direction::KRight;
-            }
-
-        if ( swipe )
-            {
-            CXnNode* destination( iGestureHelper->Destination() );
-            
-            if ( destination )
-                {
-                if ( destination == iGestureHelper->Owner() )
-                    {
-                    CancelFocusRefusalL( *engine );
-                    }
-                
-                // Remove focus
-                engine->AppUiAdapter().HideFocus();
-
-                CXnNode* trigger( BuildSwipeTriggerNodeLC( *engine, *swipe ) );
-                destination->ReportXuikonEventL( *trigger );
-                CleanupStack::PopAndDestroy( trigger );
-                       
-                // If needed we can call here for example HandleSwipeL()
-                
-                // Consume this event
-                ret = ETrue;
-                }
-            }
-        }
-
-    return ret;
+        }
     }
 
 // -----------------------------------------------------------------------------
@@ -5989,6 +5886,52 @@
     return iAdapter->ControlEnv()->FsSession();
     }
 
+// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
+//
+void CXnControlAdapterImpl::HandleTouchGestureL( MAknTouchGestureFwEvent& aEvent )
+    {
+    if ( aEvent.Group() == EAknTouchGestureFwGroupFlick )
+        {
+        TAknTouchGestureFwType type = aEvent.Type();
+        
+        const TDesC8* swipe( NULL );
+    
+        if ( type == EAknTouchGestureFwFlickLeft )
+            {
+            swipe = &XnPropertyNames::action::trigger::name::swipe::direction::KLeft;
+            }
+        else if ( type == EAknTouchGestureFwFlickRight )
+            {
+            swipe = &XnPropertyNames::action::trigger::name::swipe::direction::KRight;
+            }
+
+        if ( swipe && iGestureDestination )
+            {
+            CXnUiEngine* engine = iNode.Node().UiEngine();
+            if ( iGestureDestination == &iNode.Node() )
+                {
+                CancelFocusRefusalL( *engine );
+                }
+            
+            // Remove focus
+            engine->AppUiAdapter().HideFocus();
+
+            CXnNode* trigger( BuildSwipeTriggerNodeLC( *engine, *swipe ) );
+            iGestureDestination->ReportXuikonEventL( *trigger );
+            CleanupStack::PopAndDestroy( trigger );
+            
+            CXnAppUiAdapter& appui( engine->AppUiAdapter() );
+            CXnViewData& data( appui.ViewManager().ActiveViewData() );
+            
+            CXnViewControlAdapter* control = 
+                static_cast< CXnViewControlAdapter* >( data.ViewNode()->Control() );
+            
+            control->ResetGrabbing();
+            }
+        }
+    }
+
 
 // ============================= TIconProvider ===============================