diff -r 79311d856354 -r 7be2816dbabd idlehomescreen/xmluirendering/uiengine/src/xneffectmanager.cpp --- a/idlehomescreen/xmluirendering/uiengine/src/xneffectmanager.cpp Tue Apr 27 16:26:12 2010 +0300 +++ b/idlehomescreen/xmluirendering/uiengine/src/xneffectmanager.cpp Tue May 11 16:02:39 2010 +0300 @@ -20,29 +20,47 @@ #include #include #include -#include +#include +#include +#include // User includes +#include "xnappuiadapter.h" +#include "xnbackgroundmanager.h" #include "xneffectmanager.h" #include "xnplugindata.h" #include "xnviewdata.h" +#include "xnviewadapter.h" #include "xnnode.h" #include "xndomnode.h" #include "xncontroladapter.h" // Constants -const TInt KWaitForLayout = 1; -const TInt KEffectStarted = 2; +const TInt KWaitForLayout( 1 ); +const TInt KEffectStarted( 2 ); + +const TInt KControlEffectWaitInterval( 100000 ); // 100ms +const TInt KFullScreenEffectWaitInterval( 300000 ); // 300ms +const TInt KWaitInterval( 25000 ); // 25ms +const TInt KInterval( 500000 ); + +#define IS_VALID( e ) \ + ( e == KGfxContextActivateNextView || \ + e == KGfxContextActivatePrevView ) + +// ============================ LOCAL FUNCTIONS ================================ // ============================ MEMBER FUNCTIONS =============================== - // ----------------------------------------------------------------------------- // CXnEffectManager::CXnEffectManager // // ----------------------------------------------------------------------------- // -CXnEffectManager::CXnEffectManager() +CXnEffectManager::CXnEffectManager( CXnAppUiAdapter& aAppUiAdapter ) + : CTimer( CActive::EPriorityIdle ), iAppUiAdapter( aAppUiAdapter ), + iGroupId( -1 ) { + CActiveScheduler::Add( this ); } // ----------------------------------------------------------------------------- @@ -52,6 +70,11 @@ // void CXnEffectManager::ConstructL() { + CTimer::ConstructL(); + + OrientationChanged(); + + iObserver = CAlfEffectObserver::NewL(); } // ----------------------------------------------------------------------------- @@ -59,9 +82,9 @@ // // ----------------------------------------------------------------------------- // -CXnEffectManager* CXnEffectManager::NewL() +CXnEffectManager* CXnEffectManager::NewL( CXnAppUiAdapter& aAppUiAdapter ) { - CXnEffectManager* self = new ( ELeave ) CXnEffectManager(); + CXnEffectManager* self = new ( ELeave ) CXnEffectManager( aAppUiAdapter ); CleanupStack::PushL( self ); self->ConstructL(); CleanupStack::Pop( self ); @@ -75,8 +98,23 @@ // CXnEffectManager::~CXnEffectManager() { - GfxTransEffect::AbortFullScreen(); - iEffects.ResetAndDestroy(); + Cancel(); + + delete iObserver; + + iControls.Reset(); + + iEffects.Reset(); + } + +// ----------------------------------------------------------------------------- +// CXnEffectManager::RunL +// +// ----------------------------------------------------------------------------- +// +void CXnEffectManager::RunL() + { + // No implementation required } // ----------------------------------------------------------------------------- @@ -85,31 +123,69 @@ // ----------------------------------------------------------------------------- // void CXnEffectManager::BeginFullscreenEffectL( TInt aId, CXnViewData& aView ) - { - // Only one fullscreen effect at time - if ( iEffects.Count() != 0 ) - { - return; - } + { + TXnEffect effect; - TXnEffect* effect = new (ELeave) TXnEffect; - CleanupStack::PushL( effect ); - effect->iId = aId; - effect->iNode = aView.ViewNode(); - iEffects.AppendL( effect ); - CleanupStack::Pop( effect ); + effect.iId = aId; + effect.iNode = aView.ViewNode(); if ( !aView.ViewNode()->IsLaidOut() ) { - effect->iState = KWaitForLayout; + effect.iState = KWaitForLayout; + + iEffects.AppendL( effect ); } else { - DoBeginFullscreenEffect( *effect ); + if ( DoBeginFullscreenEffect( effect ) ) + { + iEffects.AppendL( effect ); + } + } + } + +// ----------------------------------------------------------------------------- +// CXnEffectManager::BeginFullscreenEffectL +// +// ----------------------------------------------------------------------------- +// +void CXnEffectManager::BeginFullscreenEffectL( TInt aId ) + { + TXnEffect effect; + + effect.iId = aId; + effect.iExplicitEnd = ETrue; + + if ( DoBeginFullscreenEffect( effect ) ) + { + iEffects.AppendL( effect ); } } // ----------------------------------------------------------------------------- +// CXnEffectManager::EndFullscreenEffect +// +// ----------------------------------------------------------------------------- +// +void CXnEffectManager::EndFullscreenEffect( TInt aId ) + { + for ( TInt i = 0; i < iEffects.Count(); i++ ) + { + TXnEffect& effect( iEffects[i] ); + + if ( effect.iId == aId && + effect.iExplicitEnd && + effect.iState == KEffectStarted ) + { + GfxTransEffect::EndFullScreen(); + + iEffects.Remove( i ); + break; + } + } + } + +// ----------------------------------------------------------------------------- // CXnEffectManager::UiRendered // // ----------------------------------------------------------------------------- @@ -118,12 +194,13 @@ { for ( TInt i = 0; i < iEffects.Count(); ) { - TXnEffect* effect( iEffects[i] ); + TXnEffect& effect( iEffects[i] ); - if ( effect && effect->iState == KEffectStarted ) + if ( effect.iState == KEffectStarted && !effect.iExplicitEnd ) { GfxTransEffect::EndFullScreen(); - RemoveEffect( effect ); + + iEffects.Remove( i ); } else { @@ -141,25 +218,23 @@ { for ( TInt i = 0; i < iEffects.Count(); ) { - TBool effectStarted( ETrue ); + TBool started( ETrue ); - TXnEffect* effect( iEffects[i] ); + TXnEffect& effect( iEffects[i] ); - if ( effect && effect->iNode && - effect->iState == KWaitForLayout && - effect->iNode->IsLaidOut() ) + if ( effect.iNode && effect.iState == KWaitForLayout && + effect.iNode->IsLaidOut() ) { - effectStarted = DoBeginFullscreenEffect( *effect ); + started = DoBeginFullscreenEffect( effect ); } - if ( effectStarted ) + if ( !started ) { - i++; + iEffects.Remove( i ); } else { - // effect cannot be started, remove it - RemoveEffect( effect ); + i++; } } } @@ -170,28 +245,23 @@ // ----------------------------------------------------------------------------- // TBool CXnEffectManager::DoBeginFullscreenEffect( TXnEffect& aEffect ) - { - CCoeEnv* env( CCoeEnv::Static() ); - - RWsSession& session( env->WsSession() ); + { + if ( !iAppUiAdapter.IsForeground() ) + { + // Not in foreground + return EFalse; + } - if ( session.GetFocusWindowGroup() != env->RootWin().Identifier() ) + if ( !WaitActiveEffect( KFullScreenEffectWaitInterval ) ) { - // Window group is not focused return EFalse; } const TInt flags( AknTransEffect::TParameter::EActivateExplicitCancel ); - const TUid targetAppUid( iAvkonAppUi->Application()->AppDllUid() ); + const TUid targetAppUid( iAppUiAdapter.Application()->AppDllUid() ); - // Must give some time before starting effect, because otherwise - // fullscreen effect may contain unwanted parts (dialog, note, etc.) - // which was shown when fullscreen effect is about to be started - session.Finish(); - User::After( 1000 ); - // Set effect begin point - GfxTransEffect::BeginFullScreen( aEffect.iId , iAvkonAppUi->ClientRect(), + GfxTransEffect::BeginFullScreen( aEffect.iId , iAppUiAdapter.ClientRect(), AknTransEffect::EParameterType, AknTransEffect::GfxTransParam( targetAppUid, flags ) ); @@ -201,22 +271,204 @@ } // ----------------------------------------------------------------------------- -// CXnEffectManager::RemoveEffect +// CXnEffectManager::WaitActiveEffect +// +// ----------------------------------------------------------------------------- +// +TBool CXnEffectManager::WaitActiveEffect( TInt aInterval ) + { + TBool retval( EFalse ); + + TInt loop( aInterval / KWaitInterval ); + + while ( loop >= 0 ) + { + TInt count( iObserver->ActiveEffectsCount() ); + + if ( count == 0 ) + { + retval = ETrue; + break; + } + + User::After( KWaitInterval ); + loop--; + } + + return retval; + } + +// ----------------------------------------------------------------------------- +// CXnEffectManager::BeginActivateViewEffect // // ----------------------------------------------------------------------------- // -void CXnEffectManager::RemoveEffect( TXnEffect* aEffect ) +TBool CXnEffectManager::BeginActivateViewEffect( const CXnViewData& aThis, + const CXnViewData& aOther, TUid aEffect ) { - TInt index( iEffects.Find( aEffect ) ); + CleanupControlEffect(); + + if ( !IS_VALID( aEffect ) ) + { + // Not a valid view switch effect uid + return EFalse; + } + + CXnControlAdapter* thisView( aThis.ViewNode()->Control() ); + CXnControlAdapter* otherView( aOther.ViewNode()->Control() ); + + if ( thisView == otherView ) + { + // Same controls + return EFalse; + } + + if ( IsActive() ) + { + Cancel(); + After( KInterval ); + + return EFalse; + } + + if ( !WaitActiveEffect( KControlEffectWaitInterval ) ) + { + After( KInterval ); + + return EFalse; + } - if ( index != KErrNotFound ) + iControls.Append( thisView ); + iControls.Append( otherView ); + + GfxTransEffect::Register( thisView, aEffect ); + GfxTransEffect::Register( otherView, aEffect ); + + iGroupId = GfxTransEffect::BeginGroup(); + + CFbsBitmap* currentBg( aThis.WallpaperImage() ); + CFbsBitmap* nextBg( aOther.WallpaperImage() ); + + if ( currentBg || nextBg ) + { + CCoeControl* bg( &iAppUiAdapter.ViewAdapter().BgManager() ); + + iControls.Append( bg ); + + if ( !currentBg && nextBg ) + { + GfxTransEffect::Begin( bg, KGfxControlActionBgAnimToImgAppear ); + } + else + { + GfxTransEffect::Begin( bg, KGfxControlActionBgImgToImgAppear ); + } + + iBgEffect = ETrue; + } + + if ( iLandscape ) + { + GfxTransEffect::Begin( thisView, KGfxControlActionDisappearLsc ); + GfxTransEffect::Begin( otherView, KGfxControlActionAppearLsc ); + } + else { - TXnEffect* temp( iEffects[index] ); - delete temp; - temp = NULL; + GfxTransEffect::Begin( thisView, KGfxControlActionDisappearPrt ); + GfxTransEffect::Begin( otherView, KGfxControlActionAppearPrt ); + } + + return ETrue; + } + +// ----------------------------------------------------------------------------- +// CXnEffectManager::EndActivateViewEffect +// +// ----------------------------------------------------------------------------- +// +void CXnEffectManager::EndActivateViewEffect( const CXnViewData& aThis, + const CXnViewData& aOther, TUid aEffect ) + { + if ( !IS_VALID( aEffect ) || iGroupId == -1 ) + { + // Not a valid view switch effect uid or group effect is not started + return; + } + + CXnControlAdapter* thisView( aThis.ViewNode()->Control() ); + CXnControlAdapter* otherView( aOther.ViewNode()->Control() ); + + if ( iBgEffect ) + { + CCoeControl* bg( &iAppUiAdapter.ViewAdapter().BgManager() ); + + GfxTransEffect::SetDemarcation( bg, bg->Position() ); + GfxTransEffect::End( bg ); + } - iEffects.Remove( index ); + GfxTransEffect::SetDemarcation( thisView, thisView->Position() ); + GfxTransEffect::End( thisView ); + + GfxTransEffect::SetDemarcation( otherView, otherView->Position() ); + GfxTransEffect::End( otherView ); + + GfxTransEffect::EndGroup( iGroupId ); + + GfxTransEffect::Deregister( thisView ); + GfxTransEffect::Deregister( otherView ); + } + +// ----------------------------------------------------------------------------- +// CXnEffectManager::BgAppearEffect +// +// ----------------------------------------------------------------------------- +// +void CXnEffectManager::BgAppearEffect( CCoeControl* aBg, TBool aWaitActiveEffect ) + { + if ( aWaitActiveEffect ) + { + WaitActiveEffect( KFullScreenEffectWaitInterval ); } + + GfxTransEffect::Begin( aBg, KGfxControlActionBgImgToImgAppear ); + + GfxTransEffect::SetDemarcation( aBg, aBg->Position() ); + GfxTransEffect::End( aBg ); + } + +// ----------------------------------------------------------------------------- +// CXnEffectManager::Cleanup +// +// ----------------------------------------------------------------------------- +// +void CXnEffectManager::CleanupControlEffect() + { + iBgEffect = EFalse; + iGroupId = -1; + + iControls.Reset(); + } + +// ----------------------------------------------------------------------------- +// CXnEffectManager::ControlEffectActive +// +// ----------------------------------------------------------------------------- +// +TBool CXnEffectManager::ControlEffectActive( const CCoeControl* aControl ) const + { + TInt index( iControls.Find( aControl ) ); + + return index != KErrNotFound; + } + +// ----------------------------------------------------------------------------- +// CXnEffectManager::OrientationChanged +// +// ----------------------------------------------------------------------------- +// +void CXnEffectManager::OrientationChanged() + { + iLandscape = Layout_Meta_Data::IsLandscapeOrientation(); } // End of File