idlehomescreen/xmluirendering/uiengine/src/xneffectmanager.cpp
branchRCL_3
changeset 23 7be2816dbabd
parent 12 9674c1a575e9
child 26 1b758917cafc
equal deleted inserted replaced
19:79311d856354 23:7be2816dbabd
    18 
    18 
    19 // System includes
    19 // System includes
    20 #include <eikapp.h>
    20 #include <eikapp.h>
    21 #include <aknappui.h>
    21 #include <aknappui.h>
    22 #include <gfxtranseffect/gfxtranseffect.h>  
    22 #include <gfxtranseffect/gfxtranseffect.h>  
    23 #include <akntranseffect.h>                 
    23 #include <akntranseffect.h>
       
    24 #include <alf/alfcompositionutility.h>
       
    25 #include <layoutmetadata.cdl.h>
    24 
    26 
    25 // User includes
    27 // User includes
       
    28 #include "xnappuiadapter.h"
       
    29 #include "xnbackgroundmanager.h"
    26 #include "xneffectmanager.h"
    30 #include "xneffectmanager.h"
    27 #include "xnplugindata.h"
    31 #include "xnplugindata.h"
    28 #include "xnviewdata.h"
    32 #include "xnviewdata.h"
       
    33 #include "xnviewadapter.h"
    29 #include "xnnode.h"
    34 #include "xnnode.h"
    30 #include "xndomnode.h"
    35 #include "xndomnode.h"
    31 #include "xncontroladapter.h"
    36 #include "xncontroladapter.h"
    32 
    37 
    33 // Constants
    38 // Constants
    34 const TInt KWaitForLayout = 1;
    39 const TInt KWaitForLayout( 1 );
    35 const TInt KEffectStarted = 2;
    40 const TInt KEffectStarted( 2 );
       
    41 
       
    42 const TInt KControlEffectWaitInterval( 100000 ); // 100ms
       
    43 const TInt KFullScreenEffectWaitInterval( 300000 ); // 300ms
       
    44 const TInt KWaitInterval( 25000 ); // 25ms
       
    45 const TInt KInterval( 500000 );
       
    46 
       
    47 #define IS_VALID( e ) \
       
    48     ( e == KGfxContextActivateNextView || \
       
    49     e == KGfxContextActivatePrevView )
       
    50 
       
    51 // ============================ LOCAL FUNCTIONS ================================
    36 
    52 
    37 // ============================ MEMBER FUNCTIONS ===============================
    53 // ============================ MEMBER FUNCTIONS ===============================
    38 
       
    39 // -----------------------------------------------------------------------------
    54 // -----------------------------------------------------------------------------
    40 // CXnEffectManager::CXnEffectManager
    55 // CXnEffectManager::CXnEffectManager
    41 //
    56 //
    42 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    43 //
    58 //
    44 CXnEffectManager::CXnEffectManager()
    59 CXnEffectManager::CXnEffectManager( CXnAppUiAdapter& aAppUiAdapter )
    45     {
    60     : CTimer( CActive::EPriorityIdle ), iAppUiAdapter( aAppUiAdapter ), 
       
    61       iGroupId( -1 )
       
    62     {
       
    63     CActiveScheduler::Add( this );
    46     }
    64     }
    47 
    65 
    48 // -----------------------------------------------------------------------------
    66 // -----------------------------------------------------------------------------
    49 // CXnEffectManager::ConstructL
    67 // CXnEffectManager::ConstructL
    50 //
    68 //
    51 // -----------------------------------------------------------------------------
    69 // -----------------------------------------------------------------------------
    52 //
    70 //
    53 void CXnEffectManager::ConstructL()
    71 void CXnEffectManager::ConstructL()
    54     {
    72     {
       
    73     CTimer::ConstructL();
       
    74     
       
    75     OrientationChanged();
       
    76     
       
    77     iObserver = CAlfEffectObserver::NewL();
    55     }
    78     }
    56 
    79 
    57 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
    58 // CXnEffectManager::NewL
    81 // CXnEffectManager::NewL
    59 //
    82 //
    60 // -----------------------------------------------------------------------------
    83 // -----------------------------------------------------------------------------
    61 //
    84 //
    62 CXnEffectManager* CXnEffectManager::NewL()
    85 CXnEffectManager* CXnEffectManager::NewL( CXnAppUiAdapter& aAppUiAdapter )
    63     {
    86     {
    64     CXnEffectManager* self = new ( ELeave ) CXnEffectManager();
    87     CXnEffectManager* self = new ( ELeave ) CXnEffectManager( aAppUiAdapter );
    65     CleanupStack::PushL( self );
    88     CleanupStack::PushL( self );
    66     self->ConstructL();
    89     self->ConstructL();
    67     CleanupStack::Pop( self );
    90     CleanupStack::Pop( self );
    68     return self;
    91     return self;
    69     }
    92     }
    73 //
    96 //
    74 // -----------------------------------------------------------------------------
    97 // -----------------------------------------------------------------------------
    75 //
    98 //
    76 CXnEffectManager::~CXnEffectManager()
    99 CXnEffectManager::~CXnEffectManager()
    77     {
   100     {
    78     GfxTransEffect::AbortFullScreen();
   101     Cancel();
    79     iEffects.ResetAndDestroy();
   102            
       
   103     delete iObserver;
       
   104            
       
   105     iControls.Reset();
       
   106     
       
   107     iEffects.Reset();
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CXnEffectManager::RunL
       
   112 //
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CXnEffectManager::RunL() 
       
   116     {
       
   117     // No implementation required
    80     }
   118     }
    81 
   119 
    82 // -----------------------------------------------------------------------------
   120 // -----------------------------------------------------------------------------
    83 // CXnEffectManager::BeginFullscreenEffectL
   121 // CXnEffectManager::BeginFullscreenEffectL
    84 //
   122 //
    85 // -----------------------------------------------------------------------------
   123 // -----------------------------------------------------------------------------
    86 //
   124 //
    87 void CXnEffectManager::BeginFullscreenEffectL( TInt aId, CXnViewData& aView )
   125 void CXnEffectManager::BeginFullscreenEffectL( TInt aId, CXnViewData& aView )
    88     {
   126     {    
    89     // Only one fullscreen effect at time
   127     TXnEffect effect;
    90     if ( iEffects.Count() != 0 )
   128     
    91         {
   129     effect.iId = aId;    
    92         return;
   130     effect.iNode = aView.ViewNode();
    93         }
       
    94     
       
    95     TXnEffect* effect = new (ELeave) TXnEffect;
       
    96     CleanupStack::PushL( effect );
       
    97     effect->iId = aId;
       
    98     effect->iNode = aView.ViewNode();
       
    99     iEffects.AppendL( effect );
       
   100     CleanupStack::Pop( effect );
       
   101     
   131     
   102     if ( !aView.ViewNode()->IsLaidOut() )
   132     if ( !aView.ViewNode()->IsLaidOut() )
   103         {
   133         {
   104         effect->iState = KWaitForLayout;
   134         effect.iState = KWaitForLayout;
       
   135         
       
   136         iEffects.AppendL( effect );               
   105         }
   137         }
   106     else
   138     else
   107         {
   139         {
   108         DoBeginFullscreenEffect( *effect );
   140         if ( DoBeginFullscreenEffect( effect ) )
   109         }
   141             {
       
   142             iEffects.AppendL( effect );                               
       
   143             }
       
   144         }
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CXnEffectManager::BeginFullscreenEffectL
       
   149 //
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CXnEffectManager::BeginFullscreenEffectL( TInt aId )
       
   153     {
       
   154     TXnEffect effect;
       
   155     
       
   156     effect.iId = aId;
       
   157     effect.iExplicitEnd = ETrue;
       
   158     
       
   159     if ( DoBeginFullscreenEffect( effect ) )
       
   160         {
       
   161         iEffects.AppendL( effect );
       
   162         }
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CXnEffectManager::EndFullscreenEffect
       
   167 //
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 void CXnEffectManager::EndFullscreenEffect( TInt aId )
       
   171     {
       
   172     for ( TInt i = 0; i < iEffects.Count(); i++ )
       
   173         {
       
   174         TXnEffect& effect( iEffects[i] );
       
   175         
       
   176         if ( effect.iId == aId && 
       
   177             effect.iExplicitEnd && 
       
   178             effect.iState == KEffectStarted )
       
   179             {
       
   180             GfxTransEffect::EndFullScreen();
       
   181             
       
   182             iEffects.Remove( i );
       
   183             break;
       
   184             }
       
   185         }        
   110     }
   186     }
   111 
   187 
   112 // -----------------------------------------------------------------------------
   188 // -----------------------------------------------------------------------------
   113 // CXnEffectManager::UiRendered
   189 // CXnEffectManager::UiRendered
   114 //
   190 //
   116 //
   192 //
   117 void CXnEffectManager::UiRendered()
   193 void CXnEffectManager::UiRendered()
   118     {
   194     {
   119     for ( TInt i = 0; i < iEffects.Count(); )
   195     for ( TInt i = 0; i < iEffects.Count(); )
   120         {
   196         {
   121         TXnEffect* effect( iEffects[i] );
   197         TXnEffect& effect( iEffects[i] );
   122         
   198         
   123         if ( effect && effect->iState == KEffectStarted )            
   199         if ( effect.iState == KEffectStarted && !effect.iExplicitEnd )            
   124             {
   200             {
   125             GfxTransEffect::EndFullScreen();
   201             GfxTransEffect::EndFullScreen();
   126             RemoveEffect( effect );
   202                         
       
   203             iEffects.Remove( i );            
   127             }
   204             }
   128         else
   205         else
   129             {
   206             {
   130             i++;
   207             i++;
   131             }
   208             }
   139 //
   216 //
   140 void CXnEffectManager::UiLayouted()
   217 void CXnEffectManager::UiLayouted()
   141     {
   218     {
   142     for ( TInt i = 0; i < iEffects.Count(); )
   219     for ( TInt i = 0; i < iEffects.Count(); )
   143         {
   220         {
   144         TBool effectStarted( ETrue );
   221         TBool started( ETrue );
   145         
   222         
   146         TXnEffect* effect( iEffects[i] );
   223         TXnEffect& effect( iEffects[i] );
   147         
   224         
   148         if ( effect && effect->iNode &&
   225         if ( effect.iNode && effect.iState == KWaitForLayout &&             
   149              effect->iState == KWaitForLayout &&
   226              effect.iNode->IsLaidOut() )
   150              effect->iNode->IsLaidOut() )
   227             {
   151             {
   228             started = DoBeginFullscreenEffect( effect );                       
   152             effectStarted = DoBeginFullscreenEffect( *effect );
   229             }
   153             }
   230         
   154         
   231         if ( !started )
   155         if ( effectStarted )
   232             {
       
   233             iEffects.Remove( i );            
       
   234             }
       
   235         else
   156             {
   236             {
   157             i++;
   237             i++;
   158             }
   238             }
   159         else
       
   160             {
       
   161             // effect cannot be started, remove it
       
   162             RemoveEffect( effect );
       
   163             }
       
   164         }
   239         }
   165     }
   240     }
   166 
   241 
   167 // -----------------------------------------------------------------------------
   242 // -----------------------------------------------------------------------------
   168 // CXnEffectManager::DoBeginFullscreenEffect
   243 // CXnEffectManager::DoBeginFullscreenEffect
   169 //
   244 //
   170 // -----------------------------------------------------------------------------
   245 // -----------------------------------------------------------------------------
   171 //
   246 //
   172 TBool CXnEffectManager::DoBeginFullscreenEffect( TXnEffect& aEffect )
   247 TBool CXnEffectManager::DoBeginFullscreenEffect( TXnEffect& aEffect )
   173     {
   248     {   
   174     CCoeEnv* env( CCoeEnv::Static() );
   249     if ( !iAppUiAdapter.IsForeground() )          
   175            
   250         {
   176     RWsSession& session( env->WsSession() );
   251         // Not in foreground
   177     
   252         return EFalse;
   178     if ( session.GetFocusWindowGroup() != env->RootWin().Identifier() )          
   253         }
   179         {
   254     
   180         // Window group is not focused
   255     if ( !WaitActiveEffect( KFullScreenEffectWaitInterval ) )
       
   256         {
   181         return EFalse;
   257         return EFalse;
   182         }
   258         }
   183 
   259 
   184     const TInt flags( AknTransEffect::TParameter::EActivateExplicitCancel );
   260     const TInt flags( AknTransEffect::TParameter::EActivateExplicitCancel );
   185     const TUid targetAppUid( iAvkonAppUi->Application()->AppDllUid() );
   261     const TUid targetAppUid( iAppUiAdapter.Application()->AppDllUid() );
   186     
   262     
   187     // Must give some time before starting effect, because otherwise
       
   188     // fullscreen effect may contain unwanted parts (dialog, note, etc.)
       
   189     // which was shown when fullscreen effect is about to be started
       
   190     session.Finish();
       
   191     User::After( 1000 );
       
   192         
       
   193     // Set effect begin point
   263     // Set effect begin point
   194     GfxTransEffect::BeginFullScreen( aEffect.iId , iAvkonAppUi->ClientRect(),
   264     GfxTransEffect::BeginFullScreen( aEffect.iId , iAppUiAdapter.ClientRect(),
   195         AknTransEffect::EParameterType, AknTransEffect::GfxTransParam(
   265         AknTransEffect::EParameterType, AknTransEffect::GfxTransParam(
   196         targetAppUid, flags ) );
   266         targetAppUid, flags ) );
   197     
   267     
   198     aEffect.iState = KEffectStarted;
   268     aEffect.iState = KEffectStarted;
   199     
   269     
   200     return ETrue;
   270     return ETrue;
   201     }
   271     }
   202 
   272 
   203 // -----------------------------------------------------------------------------
   273 // -----------------------------------------------------------------------------
   204 // CXnEffectManager::RemoveEffect
   274 // CXnEffectManager::WaitActiveEffect
   205 //
   275 //
   206 // -----------------------------------------------------------------------------
   276 // -----------------------------------------------------------------------------
   207 //
   277 //
   208 void CXnEffectManager::RemoveEffect( TXnEffect* aEffect )
   278 TBool CXnEffectManager::WaitActiveEffect( TInt aInterval )     
   209     {
   279     {
   210     TInt index( iEffects.Find( aEffect ) );
   280     TBool retval( EFalse );
   211     
   281     
   212     if ( index != KErrNotFound )
   282     TInt loop( aInterval / KWaitInterval );
   213         {
   283     
   214         TXnEffect* temp( iEffects[index] ); 
   284     while ( loop >= 0 )
   215         delete temp;
   285         {               
   216         temp = NULL;
   286         TInt count( iObserver->ActiveEffectsCount() );
   217         
   287         
   218         iEffects.Remove( index );        
   288         if ( count == 0 )
   219         }
   289             {
       
   290             retval = ETrue;
       
   291             break;                        
       
   292             }
       
   293         
       
   294         User::After( KWaitInterval );
       
   295         loop--;
       
   296         }
       
   297 
       
   298     return retval;    
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CXnEffectManager::BeginActivateViewEffect
       
   303 //
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 TBool CXnEffectManager::BeginActivateViewEffect( const CXnViewData& aThis, 
       
   307     const CXnViewData& aOther, TUid aEffect )
       
   308     {
       
   309     CleanupControlEffect();
       
   310     
       
   311     if ( !IS_VALID( aEffect ) )
       
   312         {
       
   313         // Not a valid view switch effect uid
       
   314         return EFalse;
       
   315         }
       
   316             
       
   317     CXnControlAdapter* thisView( aThis.ViewNode()->Control() );                             
       
   318     CXnControlAdapter* otherView( aOther.ViewNode()->Control() ); 
       
   319     
       
   320     if ( thisView == otherView )
       
   321         {
       
   322         // Same controls
       
   323         return EFalse;
       
   324         }
       
   325     
       
   326     if ( IsActive() )
       
   327         {
       
   328         Cancel();
       
   329         After( KInterval );
       
   330         
       
   331         return EFalse;
       
   332         }
       
   333     
       
   334     if ( !WaitActiveEffect( KControlEffectWaitInterval ) )
       
   335         {               
       
   336         After( KInterval );
       
   337         
       
   338         return EFalse;
       
   339         }
       
   340     
       
   341     iControls.Append( thisView );
       
   342     iControls.Append( otherView );
       
   343                
       
   344     GfxTransEffect::Register( thisView, aEffect );    
       
   345     GfxTransEffect::Register( otherView, aEffect );
       
   346 
       
   347     iGroupId = GfxTransEffect::BeginGroup();
       
   348     
       
   349     CFbsBitmap* currentBg( aThis.WallpaperImage() );
       
   350     CFbsBitmap* nextBg( aOther.WallpaperImage() );
       
   351            
       
   352     if ( currentBg || nextBg )
       
   353         {
       
   354         CCoeControl* bg( &iAppUiAdapter.ViewAdapter().BgManager() );
       
   355              
       
   356         iControls.Append( bg );
       
   357         
       
   358         if ( !currentBg && nextBg )
       
   359             {           
       
   360             GfxTransEffect::Begin( bg, KGfxControlActionBgAnimToImgAppear );
       
   361             }
       
   362         else
       
   363             {
       
   364             GfxTransEffect::Begin( bg, KGfxControlActionBgImgToImgAppear );
       
   365             }
       
   366         
       
   367         iBgEffect = ETrue;
       
   368         }
       
   369                   
       
   370     if ( iLandscape )
       
   371         {
       
   372         GfxTransEffect::Begin( thisView, KGfxControlActionDisappearLsc );
       
   373         GfxTransEffect::Begin( otherView, KGfxControlActionAppearLsc );
       
   374         }
       
   375     else
       
   376         {
       
   377         GfxTransEffect::Begin( thisView, KGfxControlActionDisappearPrt );
       
   378         GfxTransEffect::Begin( otherView, KGfxControlActionAppearPrt );
       
   379         }    
       
   380     
       
   381     return ETrue;
       
   382     }
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // CXnEffectManager::EndActivateViewEffect
       
   386 //
       
   387 // -----------------------------------------------------------------------------
       
   388 //
       
   389 void CXnEffectManager::EndActivateViewEffect( const CXnViewData& aThis, 
       
   390     const CXnViewData& aOther, TUid aEffect )
       
   391     {
       
   392     if ( !IS_VALID( aEffect ) || iGroupId == -1 )
       
   393         {
       
   394         // Not a valid view switch effect uid or group effect is not started
       
   395         return;
       
   396         }
       
   397     
       
   398     CXnControlAdapter* thisView( aThis.ViewNode()->Control() );                             
       
   399     CXnControlAdapter* otherView( aOther.ViewNode()->Control() ); 
       
   400     
       
   401     if ( iBgEffect )
       
   402         {    
       
   403         CCoeControl* bg( &iAppUiAdapter.ViewAdapter().BgManager() );
       
   404         
       
   405         GfxTransEffect::SetDemarcation( bg, bg->Position() );
       
   406         GfxTransEffect::End( bg );        
       
   407         }
       
   408         
       
   409     GfxTransEffect::SetDemarcation( thisView, thisView->Position() );
       
   410     GfxTransEffect::End( thisView );
       
   411     
       
   412     GfxTransEffect::SetDemarcation( otherView, otherView->Position() );
       
   413     GfxTransEffect::End( otherView );                     
       
   414                             
       
   415     GfxTransEffect::EndGroup( iGroupId );
       
   416     
       
   417     GfxTransEffect::Deregister( thisView );
       
   418     GfxTransEffect::Deregister( otherView );    
       
   419     }
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 // CXnEffectManager::BgAppearEffect
       
   423 //
       
   424 // -----------------------------------------------------------------------------
       
   425 //
       
   426 void CXnEffectManager::BgAppearEffect( CCoeControl* aBg, TBool aWaitActiveEffect )
       
   427     {
       
   428     if ( aWaitActiveEffect )
       
   429         {
       
   430         WaitActiveEffect( KFullScreenEffectWaitInterval );               
       
   431         }
       
   432     
       
   433     GfxTransEffect::Begin( aBg, KGfxControlActionBgImgToImgAppear );
       
   434     
       
   435     GfxTransEffect::SetDemarcation( aBg, aBg->Position() );
       
   436     GfxTransEffect::End( aBg );                         
       
   437     }
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CXnEffectManager::Cleanup
       
   441 //
       
   442 // -----------------------------------------------------------------------------
       
   443 //
       
   444 void CXnEffectManager::CleanupControlEffect()
       
   445     {
       
   446     iBgEffect = EFalse;
       
   447     iGroupId = -1;       
       
   448     
       
   449     iControls.Reset();        
       
   450     }
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // CXnEffectManager::ControlEffectActive
       
   454 //
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 TBool CXnEffectManager::ControlEffectActive( const CCoeControl* aControl ) const
       
   458     {
       
   459     TInt index( iControls.Find( aControl ) );
       
   460     
       
   461     return index != KErrNotFound;
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CXnEffectManager::OrientationChanged
       
   466 //
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 void CXnEffectManager::OrientationChanged()
       
   470     {
       
   471     iLandscape = Layout_Meta_Data::IsLandscapeOrientation();
   220     }
   472     }
   221 
   473 
   222 //  End of File
   474 //  End of File