svgtopt/SVG/SVGImpl/src/SVGMediaAnimationElementImpl.cpp
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  SVG Implementation source file
       
    15  *
       
    16 */
       
    17 
       
    18 #if !defined(__E32BASE_H__)
       
    19 #include <e32base.h>
       
    20 #endif
       
    21 
       
    22 #include "Gfx2dGcOpenVG.h"
       
    23 #include "GfxRoundRectangle2D.h"
       
    24 #include "SVGMediaAnimationElementImpl.h"
       
    25 #include "SVGDocumentImpl.h"
       
    26 #include "SVGEngineImpl.h"
       
    27 #include "SVGSchemaData.h"
       
    28 #include "SVGEventHandler.h"
       
    29 
       
    30 _LIT( KXlink, "xlink:href" );
       
    31 _LIT( KFocusable, "focusable" );
       
    32 _LIT(KInitialVisibility, "initialVisibility");
       
    33 _LIT( KSvgFile, ".svg");
       
    34 _LIT( KSvgbFile, ".svgb");
       
    35 _LIT( KSvgzFile, ".svgz");
       
    36 _LIT(msg, "Fail to open file for reading: ");
       
    37 _LIT( KErrorMsg, "Failed to Load Svg Content: Read File Size Error." );
       
    38 _LIT( KMemoryErrorMsg, "Failed to Load Svg Content: Out of memory");
       
    39 _LIT( KReadErrorMsg, "Failed to Load Svg Content: Read File Data Error");
       
    40 _LIT(KEngineFailed, "Failed to Create Svg Document: Out of Memory");
       
    41 _LIT( KTmpDur, "dur" );
       
    42 _LIT( KTmpDurMedia, "media" );
       
    43 
       
    44 CSvgMediaAnimationElementImpl* CSvgMediaAnimationElementImpl::NewL(const TUint8
       
    45                                                aElemID,CSvgDocumentImpl* aDoc )
       
    46     {
       
    47     CSvgMediaAnimationElementImpl* self = CSvgMediaAnimationElementImpl::NewLC
       
    48                                                                 (aElemID,aDoc);
       
    49     CleanupStack::Pop();
       
    50     return self;
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 // ---------------------------------------------------------------------------
       
    56 CSvgMediaAnimationElementImpl* CSvgMediaAnimationElementImpl::NewLC(const TUint8
       
    57                                               aElemID, CSvgDocumentImpl* aDoc )
       
    58     {
       
    59     CSvgMediaAnimationElementImpl* self = new ( ELeave ) CSvgMediaAnimationElementImpl( aDoc );
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL(  aElemID,aDoc );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CSvgMediaAnimationElementImpl::SetSyncBehavior
       
    67 // Set the Synchronised behaviour for the animation element
       
    68 // -----------------------------------------------------------------------------
       
    69 //        
       
    70 void CSvgMediaAnimationElementImpl::SetSyncBehavior( const TDesC& aValue )
       
    71     {
       
    72     CSvgMediaElementBase::SetSyncBehavior( aValue );
       
    73     // If document is created then set the sync value to the time container
       
    74     if ( iNewDocument )
       
    75         {
       
    76         iNewDocument->SetTCSyncBehavior( iSyncBehavior );
       
    77         }
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CSvgMediaAnimationElementImpl::SetSyncTolerance
       
    82 // Set the Synchronised Tolerance for the animation element
       
    83 // -----------------------------------------------------------------------------
       
    84 //        
       
    85 void CSvgMediaAnimationElementImpl::SetSyncTolerance( const TDesC& aValue )
       
    86     {
       
    87     CSvgMediaElementBase::SetSyncTolerance( aValue );
       
    88     
       
    89     // If document is created then set the sync value to the time container
       
    90     if ( iNewDocument )
       
    91         {
       
    92         iNewDocument->SetTCSyncTolerance( iSyncTolerance );
       
    93         }
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CSvgMediaAnimationElementImpl::SetSyncMaster
       
    98 // Set the animation element as Synchronised Master
       
    99 // -----------------------------------------------------------------------------
       
   100 //        
       
   101 void CSvgMediaAnimationElementImpl::SetSyncMaster( const TDesC& aValue )
       
   102     {
       
   103     CSvgMediaElementBase::SetSyncMaster( aValue );
       
   104 
       
   105     // If document is created then set the sync value to the time container
       
   106     if ( iNewDocument )
       
   107         {
       
   108         iNewDocument->SetTCSyncMaster( iSyncMasterConfig );
       
   109         }
       
   110     }
       
   111     
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 // ---------------------------------------------------------------------------
       
   115 void CSvgMediaAnimationElementImpl::ConstructL(  const TUint8 aElemID,
       
   116                                        CSvgDocumentImpl*  /* aDoc */ )
       
   117     {
       
   118 	CSvgMediaElementBase::ConstructL( aElemID );
       
   119 	iViewBoxImpl = CSvgFitToViewBoxImpl::NewL();
       
   120 	iIsFocusable = ETrue;
       
   121 	iDurMediaTime = ETrue;
       
   122     iSvgError = CSvgErrorImpl::NewL();
       
   123     if(!iSvgTransformable)
       
   124         iSvgTransformable = CSvgTransformableImpl::NewL();
       
   125     iChildSvgName = HBufC::NewL( 100 );
       
   126 	#ifdef SVG_FLOAT_BUILD
       
   127     iX = ( 0 );
       
   128     iY = ( 0 );
       
   129 	#else
       
   130     iX.operator = ( 0 );
       
   131     iY.operator = ( 0 );
       
   132 	#endif
       
   133 	
       
   134 	#ifdef SVG_FLOAT_BUILD
       
   135    
       
   136     iScale = ( 0 );
       
   137 	#else
       
   138     iScale.operator = ( 0 );
       
   139 	#endif
       
   140 	iIsOriginalRootTrSet = EFalse;
       
   141 	if (OwnerDocument())
       
   142 	{
       
   143 	((CSvgDocumentImpl*)OwnerDocument())->AddInternalMouseListener( this );
       
   144 	     ((CSvgDocumentImpl*)iOwnerDocument)->AddToEventReceiverListL(
       
   145                                                this, KSvgEventMaskExternalUI );
       
   146 	}
       
   147 	
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 //  Constructor
       
   152 // ---------------------------------------------------------------------------
       
   153 
       
   154 CSvgMediaAnimationElementImpl::CSvgMediaAnimationElementImpl
       
   155                                ( CSvgDocumentImpl* aDoc ):CSvgMediaElementBase
       
   156                                ( aDoc ),iAnimationStatus(EPlayerStateIdle),iInitialVisibility(EAnimationNotVisible)
       
   157                           
       
   158 
       
   159     {
       
   160     iAttrId = KAtrMediaAnimationId;
       
   161 	}
       
   162 	
       
   163 // ---------------------------------------------------------------------------
       
   164 // perform a deep clone of this object
       
   165 // ---------------------------------------------------------------------------
       
   166 MXmlElement* CSvgMediaAnimationElementImpl::CloneL(MXmlElement* aParentElement)
       
   167     {
       
   168     CSvgMediaAnimationElementImpl* newElement = CSvgMediaAnimationElementImpl::
       
   169     NewL( this->ElemID(), ((CSvgDocumentImpl*)iOwnerDocument) );
       
   170 
       
   171     CleanupStack::PushL(newElement);
       
   172     newElement->iParentNode = aParentElement;
       
   173     // copy everything over
       
   174     this->CopyL(newElement);
       
   175     CleanupStack::Pop();
       
   176     return newElement;
       
   177     }
       
   178 	
       
   179 // ==========================================================================
       
   180 // perform a deep copy of this object
       
   181 // ==========================================================================
       
   182 void CSvgMediaAnimationElementImpl::CopyL( CSvgMediaAnimationElementImpl* aDestElement )
       
   183     {
       
   184     if(aDestElement)
       
   185 		{
       
   186 	    // copy stuff from superclass
       
   187 	    this->CSvgElementImpl::CopyL(aDestElement);
       
   188 	    this->CSvgMediaElementBase::CopyL(aDestElement);
       
   189 	    aDestElement->iWidth = iWidth;
       
   190         aDestElement->iHeight = iHeight;
       
   191         aDestElement->iInitialVisibility = iInitialVisibility;
       
   192         aDestElement->iDurMediaTime = iDurMediaTime;
       
   193         aDestElement->iX = iX;
       
   194         aDestElement->iY = iY;
       
   195         aDestElement->iScale = iScale;
       
   196         aDestElement->iOriginalRootTr = iOriginalRootTr;
       
   197         aDestElement->iIsOriginalRootTrSet = iIsOriginalRootTrSet;
       
   198         aDestElement->iAnimationStatus = iAnimationStatus;
       
   199         aDestElement->iTargetElement = ( CSvgElementImpl * ) ParentNode();
       
   200 		aDestElement->iTargetSet = ETrue;
       
   201 		TInt handle = 0;
       
   202         TInt engine = 0;
       
   203         TPtr    tPtr    = this->iChildSvgName->Des();
       
   204         aDestElement->PrepareDomChildSvg(tPtr,handle,engine);
       
   205 		
       
   206 	    }
       
   207 
       
   208     }
       
   209 	
       
   210 // ---------------------------------------------------------------------------
       
   211 //  Destructor
       
   212 // ---------------------------------------------------------------------------
       
   213 CSvgMediaAnimationElementImpl::~CSvgMediaAnimationElementImpl()
       
   214     {
       
   215         
       
   216     delete iViewBoxImpl;
       
   217     delete iSvgError;
       
   218     delete iNewDocument;
       
   219     iSvgMouseEnteredElements.Close(); 
       
   220     delete iChildSvgName;        
       
   221     }
       
   222 
       
   223   
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 // ---------------------------------------------------------------------------
       
   227 TInt CSvgMediaAnimationElementImpl::SetAttributeL( const TDesC& aName,
       
   228                                           const TDesC& aValue )
       
   229     {
       
   230      CSvgElementImpl::SetAttributeL(aName,aValue);
       
   231             //added for the bug if no begin is given
       
   232     if ( !iTargetSet )
       
   233 			{
       
   234 			// default is parent element
       
   235 			iTargetElement = ( CSvgElementImpl * ) ParentNode();
       
   236 			iTargetSet = ETrue;
       
   237 			}
       
   238 
       
   239     // Encapsulates both viewBox and preserveAspectRatio attributes.
       
   240     if ( iViewBoxImpl->SetViewBoxL( aName, aValue ) )
       
   241         {
       
   242                 if ( iNewDocument && iNewDocument->RootElement() )
       
   243                     {
       
   244                         MSvgPreserveAspectRatio* lAspectRatio;
       
   245                         iViewBoxImpl->GetPreserveAspectRatio(lAspectRatio);
       
   246                         
       
   247                         if ( lAspectRatio )
       
   248                             {
       
   249                             ((CSvgSvgElementImpl *)
       
   250                              (iNewDocument->RootElement()))->SetPreserveAspectRatioL
       
   251                              (lAspectRatio->GetAlign(), lAspectRatio->GetMeetOrSlice());                
       
   252                             }    
       
   253                     }
       
   254                 
       
   255                 return KErrNone;
       
   256         }
       
   257     
       
   258     if ( aName == KXlink )
       
   259         {
       
   260             if ( aValue.Length() != 0 )
       
   261             {
       
   262             iChildSvgName = iChildSvgName->ReAlloc(aValue.Length());
       
   263             TPtr    tPtr    = iChildSvgName->Des();
       
   264             tPtr.Copy( aValue );
       
   265             TInt length = tPtr.Length();
       
   266             TPtrC tPtrCSvg = tPtr.Right(4);
       
   267             TPtrC tPtrCSvgX = tPtr.Right(5);
       
   268             
       
   269             if ( tPtrCSvg.Find(KSvgFile) == KErrNotFound && 
       
   270                             tPtrCSvgX.Find(KSvgbFile) == KErrNotFound  
       
   271                             && tPtrCSvgX.Find(KSvgzFile) == KErrNotFound  )
       
   272                 {
       
   273                 return KErrGeneral;
       
   274                 }
       
   275             else
       
   276                 {
       
   277                 TInt handle = 0;
       
   278                 TInt engine = 0;
       
   279                 TPtrC fileName;
       
   280                 PrepareDomChildSvg(tPtr,handle,engine);
       
   281                
       
   282                 // Check if error occured
       
   283                 if ( !iSvgError->HasError() )
       
   284                     {
       
   285                     // If document is valid then set parameters of child svg
       
   286                     // element from animation element 
       
   287                     
       
   288                     if ( iNewDocument && iNewDocument->RootElement() )
       
   289                         {
       
   290                         ((CSvgSvgElementImpl *)
       
   291                          (iNewDocument->RootElement()))->iWidthInPercentage = EFalse;
       
   292                         ((CSvgSvgElementImpl *)
       
   293                          (iNewDocument->RootElement()))->iHeightInPercentage = EFalse;
       
   294                         ((CSvgSvgElementImpl *)
       
   295                          (iNewDocument->RootElement()))->SetWidth((TFloatFixPt)iWidth);
       
   296                         ((CSvgSvgElementImpl *)
       
   297                          (iNewDocument->RootElement()))->SetHeight((TFloatFixPt)iHeight);
       
   298                        
       
   299                   // Set the Sync Values from animation element to time container
       
   300                         // Sync Behaviour
       
   301                         iNewDocument->SetTCSyncBehavior( iSyncBehavior );
       
   302                         // Sync Tolerance
       
   303                         iNewDocument->SetTCSyncTolerance( iSyncTolerance );
       
   304                         // Sync Mastership
       
   305                         iNewDocument->SetTCSyncMaster( iSyncMasterConfig );
       
   306                         
       
   307                         MSvgPreserveAspectRatio* lAspectRatio;
       
   308                         iViewBoxImpl->GetPreserveAspectRatio(lAspectRatio);
       
   309                         
       
   310                         if ( lAspectRatio )
       
   311                             {
       
   312                             ((CSvgSvgElementImpl *)
       
   313                              (iNewDocument->RootElement()))->
       
   314                              SetPreserveAspectRatioL(lAspectRatio->GetAlign(), 
       
   315                              lAspectRatio->GetMeetOrSlice());                
       
   316                             }
       
   317                    
       
   318                         }
       
   319                     }
       
   320                  else  
       
   321                     {
       
   322                       return KErrGeneral;
       
   323                     }
       
   324                 }
       
   325               }
       
   326 		}
       
   327 	
       
   328     else if ( aName == KFocusable )
       
   329         {
       
   330             if ( aValue == _L("true") )
       
   331                 iIsFocusable = ETrue;
       
   332             if ( aValue == _L("false") )
       
   333                  iIsFocusable = EFalse;
       
   334         }
       
   335     else if ( aName == KInitialVisibility )    
       
   336         {
       
   337                 if ( aValue == _L("always") )
       
   338                 {
       
   339                     iInitialVisibility =  EAnimationVisible;
       
   340                 }
       
   341         }
       
   342     else if ( aName == KTmpDur && aValue != KTmpDurMedia )
       
   343            {
       
   344            iDurMediaTime = EFalse;
       
   345            return CSvgMediaElementBase::SetAttributeL(aName, aValue);
       
   346            }
       
   347     else 
       
   348 	    {
       
   349    	    return CSvgMediaElementBase::SetAttributeL(aName, aValue);
       
   350 	    }
       
   351 
       
   352 	return KErrNone;
       
   353     }
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 //
       
   357 // ---------------------------------------------------------------------------
       
   358 TInt  CSvgMediaAnimationElementImpl::SetAttributeDesL( const TInt aNameId,
       
   359 											   const TDesC& aValue )
       
   360 	{
       
   361 	return CSvgMediaElementBase::SetAttributeDesL( aNameId, aValue );
       
   362     }
       
   363 
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 // ---------------------------------------------------------------------------
       
   367 TInt CSvgMediaAnimationElementImpl::GetAttributeFloat(const TInt aNameId,
       
   368                                                 TFloatFixPt& aValue )
       
   369     {
       
   370      switch ( aNameId )
       
   371      {
       
   372      case KAtrX:
       
   373 	   aValue = iX ;
       
   374 	   break;
       
   375 
       
   376      case KAtrY:
       
   377 	   aValue = iY ;
       
   378 	   break;
       
   379 
       
   380      case KAtrWidth:
       
   381 	   aValue = iWidth ;
       
   382 	   break;
       
   383 
       
   384      case KAtrHeight:
       
   385 	   aValue = iHeight ;
       
   386 	   break;
       
   387      default:
       
   388        return CSvgMediaElementBase::GetAttributeFloat( aNameId, aValue );
       
   389      }
       
   390         
       
   391      return KErrNone;
       
   392     }
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 // ---------------------------------------------------------------------------
       
   397 TInt CSvgMediaAnimationElementImpl::SetAttributeFloatL( const TInt aNameId,
       
   398                                                TFloatFixPt aValue )
       
   399     {
       
   400       switch ( aNameId )
       
   401       {
       
   402       case KAtrX:
       
   403           iX = aValue;
       
   404           SetInitialCTM();
       
   405           break;
       
   406 
       
   407       case KAtrY:
       
   408           iY = aValue;
       
   409           SetInitialCTM();
       
   410           break;
       
   411           
       
   412       case KAtrWidth:
       
   413           iWidth = aValue;
       
   414           break;
       
   415 
       
   416       case KAtrHeight:
       
   417           iHeight= aValue;
       
   418           break;
       
   419       
       
   420       default:
       
   421          return CSvgMediaElementBase::SetAttributeFloatL( aNameId, aValue );
       
   422         }
       
   423       return KErrNone;
       
   424     }
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // From MSvgEventReceiver
       
   428 // ---------------------------------------------------------------------------
       
   429 
       
   430 TBool CSvgMediaAnimationElementImpl::ReceiveEventL( MSvgEvent* aEvent )
       
   431     {
       
   432     if( CSvgElementImpl::IsSVGEnginePaused())
       
   433     {
       
   434     	return EFalse;
       
   435     }
       
   436     
       
   437     if ( !iNewDocument )
       
   438         {
       
   439         return EFalse;
       
   440         }
       
   441     // Process animation element's events first    
       
   442     TBool lSelfRedrawReqd = CSvgMediaElementBase::ReceiveEventProcL( aEvent, 
       
   443         this );
       
   444     
       
   445     CSvgElementImpl::ReceiveEventL(aEvent);    
       
   446     // Only External UI events are sent to the child document
       
   447     if ( ( aEvent->EventMask() & KSvgEventMaskExternalUI ) )
       
   448         {
       
   449         TInt lEvtTime = 0;
       
   450         // Save the time as the ProcessEvent modifies the time of the event
       
   451         // to the document's current time for keypress events
       
   452         if ( aEvent->EventType() == ESvgEngineEventKeyPress )
       
   453             {
       
   454             lEvtTime = ( ( MSvgUiKeyEvent * ) aEvent )->Time();
       
   455             }
       
   456         
       
   457         // Send the events to the child document
       
   458         ( ( ( CSvgDocumentImpl* )
       
   459             iOwnerDocument )->Engine() )->ProcessEventL( iNewDocument, 
       
   460             aEvent, EFalse );
       
   461   
       
   462         // Restore the time, so that when the event is propogated to 
       
   463         // further elements in the DOM tree, the time is in sync with
       
   464         // respect to current document time. 
       
   465         if ( aEvent->EventType() == ESvgEngineEventKeyPress )
       
   466             {
       
   467             ( ( MSvgUiKeyEvent * ) aEvent )->SetTime( lEvtTime );
       
   468             }
       
   469             
       
   470         }
       
   471     return lSelfRedrawReqd;
       
   472      
       
   473   
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------------------------
       
   477 // 
       
   478 // ---------------------------------------------------------------------------
       
   479 
       
   480 void CSvgMediaAnimationElementImpl::ResetAnimationL()
       
   481     {
       
   482   	// Check if document is valid
       
   483 	if ( !iNewDocument || !iNewDocument->RootElement() )
       
   484 	    {
       
   485 	    return;
       
   486 	    }
       
   487 
       
   488         if (( iAnimStatus == KAnimActive ) ||
       
   489 		( iAnimStatus == KAnimFinished) ||
       
   490 		( iAnimStatus == KAnimEnd))
       
   491 		{
       
   492 		if (( iAnimationStatus == EPlayerStatePlaying ) ||
       
   493 			( iAnimationStatus == EPlayerStateStop ))
       
   494 			{
       
   495 			// if previously audio is still playing, and asked to play again...
       
   496 	            iNewDocument->SetCurrentTime( 0 );
       
   497                 
       
   498                    iNewDocument->iAnimationResetNeeded = ETrue;
       
   499                 
       
   500                 if(this->iNewDocument && this->iNewDocument->iEventHandler)
       
   501                     {
       
   502                     this->iNewDocument->iEventHandler->SetCurrentTime(0);
       
   503                     }
       
   504             	
       
   505             	 TSvgTimerEvent timeEvent(0);
       
   506             	
       
   507             	
       
   508             	 iNewDocument->Reset( &timeEvent );
       
   509         	// Save the animation start tick so that
       
   510         	// child document's tick can be correctly offset
       
   511 	    	iBeginTick = ( ( CSvgDocumentImpl* )
       
   512 	    	    iOwnerDocument )->TimeContainer()->GetCurTick(); 
       
   513 	    	iAnimationStatus = EPlayerStatePlaying;
       
   514 			}
       
   515 		}
       
   516     }
       
   517 
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 // ---------------------------------------------------------------------------
       
   521 void CSvgMediaAnimationElementImpl::Reset( MSvgEvent* aEvent )
       
   522 	{
       
   523 
       
   524 	iIsUserSeek = ETrue;
       
   525 
       
   526 	// call the animation base function.
       
   527 	TSvgTimerEvent* timerEvent  = ( TSvgTimerEvent* ) aEvent;
       
   528 
       
   529 
       
   530 	if ( (TInt32)timerEvent->Time() < iAbsoluteBeginTime )
       
   531 		{
       
   532 		// let it come to initial position.
       
   533 		((CSvgDocumentImpl*)iOwnerDocument)->iInitialDrawFlag = ETrue;
       
   534 		ReInitializeAnimation();
       
   535 		// Seek to the initial position means that 
       
   536 		// animation should also be drawn in initial position
       
   537     	if ( iNewDocument && iNewDocument->RootElement() )
       
   538     	    {
       
   539             iNewDocument->SetCurrentTime( 0 );
       
   540             iNewDocument->iAnimationResetNeeded = ETrue;
       
   541 
       
   542             if ( this->iNewDocument && this->iNewDocument->iEventHandler )
       
   543                 {
       
   544                 this->iNewDocument->iEventHandler->SetCurrentTime(0);
       
   545                 }
       
   546 
       
   547             TSvgTimerEvent timeEvent(0);
       
   548             iNewDocument->Reset( &timeEvent );    	    
       
   549     	    }
       
   550 		return;
       
   551 		}
       
   552 	TRAPD(error,CSvgMediaElementBase::ResetL( aEvent, this));
       
   553 
       
   554 		if ( error != KErrNone )
       
   555 		{
       
   556 			// error processing not processed
       
   557 			return;
       
   558 		}
       
   559 	}  
       
   560 
       
   561 // ---------------------------------------------------------------------------
       
   562 //
       
   563 // ---------------------------------------------------------------------------
       
   564 
       
   565 TBool CSvgMediaAnimationElementImpl::DoAnimProcL(MSvgEvent* aEvent)
       
   566     {
       
   567         if ( !iNewDocument )
       
   568         {
       
   569             return EFalse;
       
   570         }
       
   571     return this->AnimProcL((MSvgTimerEvent*)aEvent);
       
   572     }
       
   573 
       
   574 // ---------------------------------------------------------------------------
       
   575 //
       
   576 // ---------------------------------------------------------------------------
       
   577 
       
   578 TBool CSvgMediaAnimationElementImpl::IsViewable()
       
   579     {
       
   580      if ( iInitialVisibility == EAnimationVisible )
       
   581         {
       
   582         return ETrue;
       
   583         }
       
   584         return EFalse;
       
   585     }
       
   586 
       
   587 // ---------------------------------------------------------------------------
       
   588 //
       
   589 // ---------------------------------------------------------------------------
       
   590 void CSvgMediaAnimationElementImpl::Print( TBool /*aIsEncodeOn */)
       
   591     {
       
   592 	    // No implementation.
       
   593     }  
       
   594        
       
   595 // ---------------------------------------------------------------------------
       
   596 //
       
   597 // ---------------------------------------------------------------------------
       
   598 TBool CSvgMediaAnimationElementImpl::DrawL( CGfx2dGc* aGc, 
       
   599                                            CSvgElementImpl* /* aElement */)
       
   600     {
       
   601     // Check if document is valid
       
   602 	if ( !iNewDocument || !iNewDocument->RootElement() || (TInt)iWidth==0 || 
       
   603 	                                                      (TInt)iHeight==0 )
       
   604 	    {
       
   605 	    return EFalse;
       
   606 	    }
       
   607 
       
   608     // if iInitialVisibility status is EAnimationInitialised then draw won't happen
       
   609     if ( iInitialVisibility == EAnimationNotVisible || 
       
   610                             iInitialVisibility == EAnimationVisible )
       
   611         {
       
   612         
       
   613             // visibility is set to initialised state to get font before actual draw
       
   614             if ( iInitialVisibility == EAnimationNotVisible )
       
   615                 {
       
   616                     iInitialVisibility = EAnimationInitialised;    
       
   617                 }
       
   618             
       
   619             TReal32 opacity = 1;
       
   620             TGfxRoundRectangle2D        Rectangle;
       
   621             TGfxAffineTransform aTr = GetCTM();
       
   622             ((CSvgSvgElementImpl *)(iNewDocument->RootElement()))->SetTransformList
       
   623                                                                    (iOriginalRootTr);
       
   624             ((CSvgElementImpl*)iNewDocument->RootElement())->UpdateCTM();   
       
   625             
       
   626             iNewDocument->iIsRendering = ETrue; 
       
   627             ((CGfx2dGcOpenVG*)aGc)->BindToMediaImageL(iScale * iWidth,iScale * iHeight);
       
   628             (iNewDocument->Engine())->DrawElementsL((CSvgElementImpl*)
       
   629                                       (iNewDocument->RootElement()));
       
   630             iNewDocument->iIsRendering = EFalse; 
       
   631             TGfxAffineTransform tMatrix;
       
   632             tMatrix = aTr;
       
   633             
       
   634             #ifdef SVG_FLOAT_BUILD
       
   635             tMatrix.Scale( ( TFloatFixPt( 1 ) / ( iScale ) ), 
       
   636                              ( TFloatFixPt( 1 ) / ( iScale ) ) );
       
   637             #else
       
   638             tMatrix.Scale( ( TFloatFixPt( 0x10000,ETrue ) / ( iScale ) ), 
       
   639                              ( TFloatFixPt( 0x10000,ETrue ) / ( iScale ) ) );
       
   640             #endif
       
   641             
       
   642             // draw happens only if iInitialVisibility status is EAnimationVisible
       
   643             // i.e. animation element has started its animation
       
   644             
       
   645             ((CGfx2dGcOpenVG*)aGc)->UnbindFromMediaImageL(tMatrix,opacity,150,150,iInitialVisibility);
       
   646             
       
   647             tMatrix.Concatenate(iOriginalRootTr);
       
   648             ((CSvgSvgElementImpl *)(iNewDocument->RootElement()))->SetTransformList
       
   649                                                                    (tMatrix);
       
   650             ((CSvgElementImpl*)iNewDocument->RootElement())->UpdateCTM();   
       
   651              return ETrue;
       
   652         }
       
   653         
       
   654       return EFalse;  
       
   655     }
       
   656 
       
   657 //---------------------------------------------------------------------------
       
   658 //
       
   659 //---------------------------------------------------------------------------    
       
   660 void CSvgMediaAnimationElementImpl::SetInitialCTM()
       
   661     {
       
   662  
       
   663        TGfxAffineTransform aTr(1,0,0,1,iX,iY);
       
   664        SetTransformList(aTr);
       
   665     }
       
   666 
       
   667 // ---------------------------------------------------------------------------
       
   668 // CSvgMediaAnimationElementImpl::GetChildDocument()
       
   669 // Accessor function for obtaining the child SVG document
       
   670 // ---------------------------------------------------------------------------
       
   671 CSvgDocumentImpl* CSvgMediaAnimationElementImpl::GetChildDocument()
       
   672     {
       
   673         if ( iNewDocument )
       
   674          return iNewDocument;
       
   675         else 
       
   676           return NULL;
       
   677     }
       
   678     
       
   679 // -----------------------------------------------------------------------------
       
   680 // CSvgMediaAnimationElementImpl::SetPreserveAspectRatioL
       
   681 // From CSvgElementImpl
       
   682 // -----------------------------------------------------------------------------
       
   683 //        
       
   684 void CSvgMediaAnimationElementImpl::SetPreserveAspectRatioL( 
       
   685     TSvgPreserveAspectAlignType aAlign,
       
   686     TSvgMeetOrSliceType aMeetSlice )
       
   687     {
       
   688     iViewBoxImpl->SetPreserveAspectRatioL( aAlign, aMeetSlice);
       
   689     }
       
   690     
       
   691 // ---------------------------------------------------------------------------
       
   692 //
       
   693 // ---------------------------------------------------------------------------
       
   694 void CSvgMediaAnimationElementImpl::SetWidth(TReal32 aValue)
       
   695     {
       
   696       iWidth = aValue;
       
   697     }
       
   698 
       
   699 // ---------------------------------------------------------------------------
       
   700 //
       
   701 // ---------------------------------------------------------------------------
       
   702 void CSvgMediaAnimationElementImpl::SetHeight(TReal32 aValue)
       
   703     {
       
   704      iHeight = aValue;
       
   705     }
       
   706 
       
   707 // ---------------------------------------------------------------------------
       
   708 //
       
   709 // ---------------------------------------------------------------------------    
       
   710 MSvgError* CSvgMediaAnimationElementImpl::PrepareDomChildSvg
       
   711                            (const TDesC& aFileName,TInt& aHandle, TInt aEngine)
       
   712     {
       
   713          // Create session to open file
       
   714     RFs session;
       
   715     CSvgDocumentImpl::OpenSession( session, *iSvgError );
       
   716     if ( iSvgError->HasError() )
       
   717     {
       
   718         return iSvgError;
       
   719     }
       
   720 
       
   721     // Open file handle
       
   722     RFile fileHandle;
       
   723     TInt openError = 0;
       
   724     
       
   725     if ( ((CSvgDocumentImpl*)iOwnerDocument)->Engine() == NULL  )
       
   726        {
       
   727        return iSvgError;
       
   728        }
       
   729     if ( (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->iRequestObserver == NULL) 
       
   730        {
       
   731        return iSvgError;	
       
   732        }
       
   733     
       
   734     openError = (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->iRequestObserver
       
   735    									->FetchImage( aFileName, session,fileHandle  );
       
   736    
       
   737     if ( openError != KErrNone )
       
   738        {
       
   739        CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, openError,
       
   740                                         msg, aFileName );
       
   741        fileHandle.Close();
       
   742        session.Close();
       
   743        return iSvgError;                                 
       
   744        }
       
   745      else
       
   746        {
       
   747        PrepareDomChildSvg( fileHandle, aHandle, aEngine );
       
   748        }
       
   749         
       
   750      // If iDurMediaTime is ETrue then it means dur has been set as sometime
       
   751      // else dur was not there and defauly media duration is set.
       
   752      // iDurMediaTime is set to ETrue by default.
       
   753         if ( iDurMediaTime  )
       
   754            {
       
   755            TUint32 dur =  iNewDocument->AnimationDuration();
       
   756            if ( dur == 0xFFFFFFFF )
       
   757               {
       
   758               fileHandle.Close();
       
   759     		  session.Close();
       
   760     		  return iSvgError;
       
   761               }
       
   762            dur /=  1000; 
       
   763            TBuf<10> number;
       
   764            number.Num(dur); 
       
   765            CSvgMediaElementBase::SetAttributeL(KTmpDur, number);    	
       
   766            }
       
   767         
       
   768         
       
   769      
       
   770     fileHandle.Close();
       
   771     session.Close();
       
   772     return iSvgError;
       
   773     }
       
   774 // ---------------------------------------------------------------------------
       
   775 //
       
   776 // ---------------------------------------------------------------------------    
       
   777  MSvgError* CSvgMediaAnimationElementImpl::PrepareDomChildSvg
       
   778                           ( RFile& aFileHandle, TInt& aHandle, TInt aEngine)
       
   779     {
       
   780         // reset to start of file
       
   781     TInt zero = 0;
       
   782     aFileHandle.Seek( ESeekStart, zero );
       
   783 
       
   784     TInt fileSize = 0;
       
   785     TInt sizeError = aFileHandle.Size( fileSize );
       
   786     if ( sizeError != KErrNone )
       
   787     {
       
   788         
       
   789         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgUnknown, sizeError,
       
   790                                         KErrorMsg, KNullDesC );
       
   791         return iSvgError;
       
   792     }
       
   793 
       
   794     HBufC8* byteArray = NULL;
       
   795     TRAPD( error, byteArray = HBufC8::NewL( fileSize ) );
       
   796     if ( error != KErrNone )
       
   797     {
       
   798         
       
   799         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, error,
       
   800                                         KMemoryErrorMsg, KNullDesC );
       
   801         return iSvgError;
       
   802     }
       
   803 
       
   804     TPtr8 des = byteArray->Des();
       
   805     TInt readError = aFileHandle.Read( des );
       
   806     if ( readError != KErrNone )
       
   807     {
       
   808         
       
   809         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, error,
       
   810                                         KReadErrorMsg, KNullDesC );
       
   811         delete byteArray;
       
   812         return iSvgError;
       
   813     }
       
   814 
       
   815     PrepareDomChildSvg( *byteArray, aHandle, aEngine );
       
   816     delete byteArray;
       
   817     return iSvgError;
       
   818     
       
   819     }
       
   820     
       
   821 // ---------------------------------------------------------------------------
       
   822 //
       
   823 // ---------------------------------------------------------------------------  
       
   824     
       
   825 MSvgError* CSvgMediaAnimationElementImpl::PrepareDomChildSvg(const TDesC8& aByteData, 
       
   826     TInt& aHandle, TInt /* aEngine */)  
       
   827     {
       
   828     aHandle = 0;
       
   829 
       
   830     // Clear Error
       
   831     iSvgError->SetErrorCode( ESvgNoError );
       
   832 
       
   833 
       
   834     // CSvgDocumentImpl* newDocument = NULL;
       
   835     CSvgSvgElementImpl* lRoot = (CSvgSvgElementImpl* )((CSvgDocumentImpl* )
       
   836                                             iOwnerDocument)->RootElement();
       
   837     
       
   838     // Get the default sync behaviour from SVG element
       
   839     TSvgSyncBehaviour lRootSB = lRoot->SyncBehaviorDefault();
       
   840     
       
   841     // Get the default tolerance from SVG element
       
   842     TInt32 lRootST = lRoot->SyncToleranceDefault();
       
   843     
       
   844     // Indicate ETrue while creating document to indicate that
       
   845     // document has a parent
       
   846     CSvgBitmapFontProvider *tempBitmapFontProvider = 
       
   847             ((CSvgDocumentImpl*)iOwnerDocument)->GetBitmapFontProvider();
       
   848             
       
   849     TRAPD( error, iNewDocument = CSvgDocumentImpl::NewL( tempBitmapFontProvider,
       
   850             ETrue, lRootSB, lRootST ) );
       
   851     
       
   852     // Check for error
       
   853     if ( error != KErrNone )
       
   854         {
       
   855         #ifdef _DEBUG
       
   856         RDebug::Print(KEngineFailed);
       
   857         #endif //_DEBUG
       
   858         CSvgDocumentImpl::PrepareError( *iSvgError, ESvgNoMemory, error,
       
   859                                         KEngineFailed, KNullDesC );
       
   860         return iSvgError;
       
   861         }
       
   862 
       
   863     // Set appropriate flags to documents
       
   864     iNewDocument->SetWasPrepared( !iIsLoadingRequest );
       
   865     iNewDocument->SetDRMMode( iDrmEnabled );
       
   866     iNewDocument->SetThumbNailMode( iIsThumbNailMode );
       
   867   
       
   868 
       
   869     iNewDocument->SetEngine(((CSvgDocumentImpl*)iOwnerDocument)->Engine());
       
   870     iNewDocument->SetLoadingListeners(((CSvgDocumentImpl*)iOwnerDocument)
       
   871                                                  ->GetLoadingListeners());
       
   872 
       
   873     // Parse document
       
   874     iNewDocument->Load( aByteData, *iSvgError );
       
   875 
       
   876     #ifdef _DEBUG
       
   877     if ( iNewDocument->GetError() && iNewDocument->GetError()->HasError() )
       
   878         {
       
   879         RDebug::Printf("Load warning: ");
       
   880         RDebug::RawPrint( iNewDocument->GetError()->Description() );
       
   881         }
       
   882     #endif
       
   883 
       
   884     iFileIsLoaded = !iSvgError->HasError() || iSvgError->IsWarning();
       
   885 
       
   886     // Parsing error or out of memory
       
   887     if ( !iFileIsLoaded )
       
   888         {
       
   889         return iSvgError;
       
   890         }
       
   891 
       
   892     aHandle = (TInt)iNewDocument;
       
   893 
       
   894     // Add the animation element as an observer on the child time 
       
   895     // container
       
   896     iNewDocument->TimeContainer()->SetTcObserver( this );
       
   897 
       
   898     return iSvgError;
       
   899     }
       
   900     
       
   901 // -----------------------------------------------------------------------------
       
   902 // CSvgMediaAnimationElementImpl::ParentTimeContainerTick
       
   903 // From CSvgMediaElementBase
       
   904 // -----------------------------------------------------------------------------
       
   905 //
       
   906 void CSvgMediaAnimationElementImpl::ParentTimeContainerTick( 
       
   907     TSvgTick /* aTick */) // Current tick information 
       
   908     {
       
   909         //empty implementation
       
   910     }
       
   911        
       
   912 
       
   913 // -----------------------------------------------------------------------------
       
   914 // CSvgMediaAnimationElementImpl::GetEntityCurrentTime
       
   915 // From CSvgMediaElementBase
       
   916 // -----------------------------------------------------------------------------
       
   917 //        
       
   918 void CSvgMediaAnimationElementImpl::GetEntityCurrentTime( TUint32& 
       
   919             aEntityCurTime ) // Current Entity Time in msecs. 
       
   920     {
       
   921     if ( iNewDocument )
       
   922         {
       
   923         // Access time container from child document
       
   924         CSvgTimeContainer* lChildTC = iNewDocument->TimeContainer();
       
   925             
       
   926         if ( lChildTC )
       
   927             {
       
   928             lChildTC->GetEntityCurrentTime( aEntityCurTime );        
       
   929             // Adjust the time from the timed entity to compensate
       
   930             // the BeginTick's parent time container tick
       
   931             aEntityCurTime += iBeginTick.iParentTcTick;
       
   932             }
       
   933         }
       
   934     }
       
   935 
       
   936 // -----------------------------------------------------------------------------
       
   937 // CSvgMediaAnimationElementImpl::SetCurSyncMasterStatus
       
   938 // From CSvgMediaElementBase
       
   939 // -----------------------------------------------------------------------------
       
   940 void CSvgMediaAnimationElementImpl::SetCurSyncMasterStatus( 
       
   941     TBool aSyncMasterStatus ) //  Indicates whether the element is currrently 
       
   942                               // Sync Master.
       
   943     {
       
   944     // Set the current sync master status
       
   945     CSvgMediaElementBase::SetCurSyncMasterStatus( aSyncMasterStatus );
       
   946     if ( iNewDocument )
       
   947         {
       
   948         // Access time container from child document
       
   949         CSvgTimeContainer* lChildTC = iNewDocument->TimeContainer();
       
   950             
       
   951         if ( lChildTC )
       
   952             {
       
   953             lChildTC->SetCurSyncMasterStatus( aSyncMasterStatus );        
       
   954             }    
       
   955         }
       
   956     }
       
   957 
       
   958 // -----------------------------------------------------------------------------
       
   959 // CSvgMediaAnimationElementImpl::CanGenerateTick
       
   960 // From CSvgMediaElementBase
       
   961 // -----------------------------------------------------------------------------
       
   962 TBool CSvgMediaAnimationElementImpl::CanGenerateTick()
       
   963     {
       
   964     if ( iNewDocument )
       
   965         {
       
   966         // Access time container from child document
       
   967         CSvgTimeContainer* lChildTC = iNewDocument->TimeContainer();
       
   968             
       
   969         if ( lChildTC )
       
   970             {
       
   971             return ( lChildTC->CanGenerateTick() );
       
   972             }
       
   973         }
       
   974     return EFalse; 
       
   975     }
       
   976 
       
   977 // -----------------------------------------------------------------------------
       
   978 // CSvgMediaAnimationElementImpl::ResyncTimedEntity
       
   979 // From CSvgMediaElementBase
       
   980 // -----------------------------------------------------------------------------
       
   981 void CSvgMediaAnimationElementImpl::ResyncTimedEntity( 
       
   982             TUint32 /* aSynctime */ ) // Time for resync in msecs.
       
   983     {
       
   984     // Empty Implementation
       
   985     }    
       
   986 // -----------------------------------------------------------------------------
       
   987 // CSvgMediaAnimationElementImpl::PauseTimedEntity
       
   988 // From CSvgMediaElementBase
       
   989 // -----------------------------------------------------------------------------
       
   990 void CSvgMediaAnimationElementImpl::PauseTimedEntity()
       
   991     {
       
   992     iIsSyncPauseIssued = ETrue;
       
   993     if ( iNewDocument && iAnimationStatus == EPlayerStatePlaying )
       
   994         {
       
   995         iAnimationStatus = EPlayerStatePaused;
       
   996         }
       
   997     }
       
   998 
       
   999 // -----------------------------------------------------------------------------
       
  1000 // CSvgMediaAnimationElementImpl::ResumeTimedEntity
       
  1001 // From CSvgMediaElementBase
       
  1002 // -----------------------------------------------------------------------------
       
  1003 void CSvgMediaAnimationElementImpl::ResumeTimedEntity()
       
  1004     {
       
  1005     iIsSyncPauseIssued =  EFalse;
       
  1006     if ( iNewDocument && iAnimationStatus == EPlayerStatePaused )
       
  1007     	{
       
  1008     	// The child time container recieves the event from the parent time
       
  1009     	// container directly.
       
  1010 	    iAnimationStatus = EPlayerStatePlaying;
       
  1011     	}    
       
  1012     }
       
  1013 
       
  1014 // -----------------------------------------------------------------------------
       
  1015 // CSvgMediaAnimationElementImpl::StopTimedEntity
       
  1016 // From CSvgMediaElementBase
       
  1017 // -----------------------------------------------------------------------------
       
  1018 void CSvgMediaAnimationElementImpl::StopTimedEntity()
       
  1019     {
       
  1020     if ( iNewDocument )
       
  1021     	{
       
  1022     	iAnimationStatus = EPlayerStateStop;
       
  1023     	}    
       
  1024     }
       
  1025     
       
  1026 
       
  1027 //From MSvgTimedEntityInterface
       
  1028 TSvgObjectType CSvgMediaAnimationElementImpl::ObjectType()
       
  1029     {
       
  1030 	return ESvgMediaAnimationElement;	
       
  1031     }
       
  1032 
       
  1033 
       
  1034 //returns the child time container of the element 
       
  1035 //used in timecontainer
       
  1036 CSvgTimeContainer* CSvgMediaAnimationElementImpl::GetChildTimeContainer()
       
  1037     {
       
  1038     //Check for valid document and get time container from documentimpl
       
  1039     if ( iNewDocument )
       
  1040         {
       
  1041         return iNewDocument->TimeContainer();
       
  1042         }
       
  1043     else
       
  1044         {
       
  1045         return NULL;    
       
  1046         }
       
  1047     }
       
  1048 // -----------------------------------------------------------------------------
       
  1049 // CSvgMediaAnimationElementImpl::TimeContainerReady
       
  1050 // From MSvgTimeContainerObserver
       
  1051 // -----------------------------------------------------------------------------
       
  1052 void CSvgMediaAnimationElementImpl::TimeContainerReady()
       
  1053     {
       
  1054     // Access time container from owner document
       
  1055     CSvgTimeContainer* lOwnerTC = ((CSvgDocumentImpl* )
       
  1056         iOwnerDocument)->TimeContainer();
       
  1057         
       
  1058     if ( lOwnerTC )
       
  1059         {
       
  1060         lOwnerTC->TimedEntityReady( this );        
       
  1061         }
       
  1062     }
       
  1063 
       
  1064 // -----------------------------------------------------------------------------
       
  1065 // CSvgMediaAnimationElementImpl::TimeContainerNotReady
       
  1066 // From MSvgTimeContainerObserver
       
  1067 // -----------------------------------------------------------------------------
       
  1068 void CSvgMediaAnimationElementImpl::TimeContainerNotReady()
       
  1069     {
       
  1070     // Access time container from owner document
       
  1071     CSvgTimeContainer* lOwnerTC = ((CSvgDocumentImpl* )
       
  1072         iOwnerDocument)->TimeContainer();
       
  1073         
       
  1074     if ( lOwnerTC )
       
  1075         {
       
  1076         lOwnerTC->TimedEntityNotReady( this );        
       
  1077         }    
       
  1078     }
       
  1079     
       
  1080 // ---------------------------------------------------------------------------
       
  1081 //
       
  1082 // ---------------------------------------------------------------------------
       
  1083 
       
  1084 TBool CSvgMediaAnimationElementImpl::AnimProcL( MSvgTimerEvent* /* aEvent */ )
       
  1085     {
       
  1086 #ifdef _DEBUG    
       
  1087 	RDebug::Print(_L("%d %d"), iAnimStatus, IsAnimating());
       
  1088 #endif
       
  1089 	// Check if document is valid
       
  1090 	if ( !iNewDocument || !iNewDocument->RootElement() )
       
  1091 	    {
       
  1092 	    return EFalse;
       
  1093 	    }
       
  1094     if ( iAnimationStatus == EPlayerProhibit )
       
  1095         return EFalse;
       
  1096     if ( iAnimTime->DurationTime() == KTimeIndefinite || iAnimTime->DurationTime() == 0 )
       
  1097         {
       
  1098          return EFalse;
       
  1099         }
       
  1100 	
       
  1101     if ( iAnimStatus != KAnimActive )
       
  1102         {
       
  1103         if ( iAnimationStatus == EPlayerStatePlaying )
       
  1104     		{
       
  1105              //stop child svg animation based on freeze/remove value.
       
  1106             if( iFill == KAnimFillRemove )
       
  1107                 {
       
  1108                     iNewDocument->SetCurrentTime( 0 );
       
  1109                 
       
  1110                    iNewDocument->iAnimationResetNeeded = ETrue;
       
  1111                  
       
  1112                     if  (iNewDocument && iNewDocument->iEventHandler )
       
  1113                     {
       
  1114                     iNewDocument->iEventHandler->SetCurrentTime(0);
       
  1115                     }
       
  1116             	
       
  1117             	    TSvgTimerEvent timeEvent(0);
       
  1118             	
       
  1119             	
       
  1120             	    iNewDocument->Reset( &timeEvent );
       
  1121                 }
       
  1122             
       
  1123         	iAnimationStatus = EPlayerStateStop;
       
  1124         	return EFalse;
       
  1125     		}
       
  1126         }
       
  1127     else //iAnimStatus == KAnimActive
       
  1128         {
       
  1129         if ( !iHadBegun )
       
  1130             {
       
  1131             iHadBegun = ETrue;
       
  1132             // animation element can be drawn now
       
  1133             iInitialVisibility = EAnimationVisible;
       
  1134             // this is a restart from begin list.
       
  1135             if ( (iAnimationStatus != EPlayerStateIdle) )
       
  1136 //            	(iAnimationStatus != EPlayerStatePlayInit))
       
  1137             	{
       
  1138             	
       
  1139             	//child svg animataion should begin from 0 again, seek it to zero.
       
  1140             	
       
  1141             	// Remember the current time as beginning of the animation.
       
  1142             	
       
  1143                    iNewDocument->SetCurrentTime(0);
       
  1144                 
       
  1145                    iNewDocument->iAnimationResetNeeded = ETrue;
       
  1146                 
       
  1147                 if ( this->iNewDocument && this->iNewDocument->iEventHandler )
       
  1148                     {
       
  1149                     this->iNewDocument->iEventHandler->SetCurrentTime(0);
       
  1150                     }
       
  1151             	
       
  1152             	 TSvgTimerEvent timeEvent(0);
       
  1153             	
       
  1154             	
       
  1155             	 iNewDocument->Reset( &timeEvent );
       
  1156             	
       
  1157             	// Save the animation start tick so that
       
  1158             	// child document's tick can be correctly offset
       
  1159 		    	iBeginTick = ( ( CSvgDocumentImpl* )
       
  1160 		    	    iOwnerDocument )->TimeContainer()->GetCurTick(); 
       
  1161 		    	iAnimationStatus = EPlayerStatePlaying;
       
  1162 		    	
       
  1163             	}
       
  1164             return ETrue;
       
  1165             }
       
  1166             
       
  1167             
       
  1168         if ( iAnimationStatus == EPlayerStateIdle ) // stopped
       
  1169             {
       
  1170             //child svg animataion should begin from 0 i.e for the first time
       
  1171             // Remember the current time as beginning of the animation.
       
  1172              iNewDocument->SetCurrentTime( 0 );
       
  1173                 
       
  1174                    iNewDocument->iAnimationResetNeeded = ETrue;
       
  1175                 
       
  1176                 if ( this->iNewDocument && this->iNewDocument->iEventHandler )
       
  1177                     {
       
  1178                     this->iNewDocument->iEventHandler->SetCurrentTime(0);
       
  1179                     }
       
  1180             	
       
  1181             	 TSvgTimerEvent timeEvent(0);
       
  1182             	
       
  1183             	
       
  1184             	 iNewDocument->Reset( &timeEvent );
       
  1185             	            
       
  1186             	// Save the animation start tick so that
       
  1187             	// child document's tick can be correctly offset
       
  1188 		    	iBeginTick = ( ( CSvgDocumentImpl* )
       
  1189 		    	    iOwnerDocument )->TimeContainer()->GetCurTick(); 
       
  1190        		    iAnimationStatus = EPlayerStatePlaying;
       
  1191            	    return ETrue;
       
  1192             }
       
  1193             
       
  1194             if ( iAnimationStatus == EPlayerStatePlaying )
       
  1195                 {
       
  1196 
       
  1197                 // child svg active and in running state so pass the tick
       
  1198                 // to the child svg's time container
       
  1199                 // Subtract the reference begin tick from the current tick 
       
  1200                 // before giving the tick.
       
  1201                 TSvgTick lChildTick = ( ( CSvgDocumentImpl* )
       
  1202 		    	    iOwnerDocument )->TimeContainer()->GetCurTick(); 
       
  1203                 
       
  1204                 lChildTick.iParentTcTick -= iBeginTick.iParentTcTick;
       
  1205                 lChildTick.iRealTimeTick -= iBeginTick.iRealTimeTick;
       
  1206                 lChildTick.iParentTcTick -= iNegativeBeginTime;
       
  1207                 lChildTick.iRealTimeTick -= iNegativeBeginTime;
       
  1208                 iNewDocument->TimeContainer()->ParentTimeContainerTick
       
  1209                                                ( lChildTick );
       
  1210                 }
       
  1211              if ( iAnimationStatus == EPlayerStateStop )
       
  1212         	{
       
  1213             	
       
  1214         	       iNewDocument->SetCurrentTime( 0 );
       
  1215                    iNewDocument->iAnimationResetNeeded = ETrue;
       
  1216                 
       
  1217                 if ( this->iNewDocument && this->iNewDocument->iEventHandler )
       
  1218                     {
       
  1219                     this->iNewDocument->iEventHandler->SetCurrentTime(0);
       
  1220                     }
       
  1221             	
       
  1222             	 TSvgTimerEvent timeEvent(0);
       
  1223             	
       
  1224             	
       
  1225             	 iNewDocument->Reset( &timeEvent );
       
  1226             	            
       
  1227             	// Save the animation start tick so that
       
  1228             	// child document's tick can be correctly offset
       
  1229 		    	iBeginTick = ( ( CSvgDocumentImpl* )
       
  1230 		    	    iOwnerDocument )->TimeContainer()->GetCurTick(); 
       
  1231        		    iAnimationStatus = EPlayerStatePlaying;
       
  1232            	    return ETrue;   
       
  1233         	}    
       
  1234         }
       
  1235 
       
  1236 
       
  1237     return ETrue;
       
  1238     }
       
  1239 
       
  1240 // ---------------------------------------------------------------------------
       
  1241 //
       
  1242 // ---------------------------------------------------------------------------
       
  1243 
       
  1244 void CSvgMediaAnimationElementImpl::InitAnimationL()
       
  1245     {
       
  1246         if ( !iNewDocument )
       
  1247         {
       
  1248             return;
       
  1249         }
       
  1250     CSvgMediaElementBase::InitAnimationL();
       
  1251     }
       
  1252 
       
  1253 // ---------------------------------------------------------------------------
       
  1254 //
       
  1255 // ---------------------------------------------------------------------------
       
  1256 void CSvgMediaAnimationElementImpl::GetPreserveAspectRatio(
       
  1257                                     MSvgPreserveAspectRatio*& aAspectRatio )
       
  1258     {
       
  1259     iViewBoxImpl->GetPreserveAspectRatio( aAspectRatio );
       
  1260     }
       
  1261 
       
  1262 // ---------------------------------------------------------------------------
       
  1263 //
       
  1264 // ---------------------------------------------------------------------------
       
  1265 TFloatFixPt CSvgMediaAnimationElementImpl::X()
       
  1266     {
       
  1267     return iX;
       
  1268     }
       
  1269 
       
  1270 // ---------------------------------------------------------------------------
       
  1271 //
       
  1272 // ---------------------------------------------------------------------------
       
  1273 TFloatFixPt CSvgMediaAnimationElementImpl::Y()
       
  1274     {
       
  1275     return iY;
       
  1276     }
       
  1277 
       
  1278 // ---------------------------------------------------------------------------
       
  1279 //
       
  1280 // ---------------------------------------------------------------------------
       
  1281 TFloatFixPt CSvgMediaAnimationElementImpl::Width()
       
  1282     {
       
  1283     return iWidth;
       
  1284     }
       
  1285 
       
  1286 // ---------------------------------------------------------------------------
       
  1287 //
       
  1288 // ---------------------------------------------------------------------------
       
  1289 TFloatFixPt CSvgMediaAnimationElementImpl::Height()
       
  1290     {
       
  1291     return iHeight;
       
  1292     }
       
  1293 
       
  1294 
       
  1295 // ---------------------------------------------------------------------------
       
  1296 //
       
  1297 // ---------------------------------------------------------------------------    
       
  1298  void CSvgMediaAnimationElementImpl::GetBBox( TGfxRectangle2D& aBbox )
       
  1299     {
       
  1300         TGfxRoundRectangle2D        aRectangle;   
       
  1301          
       
  1302         aRectangle.iX = 0;
       
  1303         aRectangle.iY = 0;
       
  1304         aRectangle.iHeight = iHeight;
       
  1305         aRectangle.iWidth =  iWidth;
       
  1306         if ( !(TInt32)iHeight || !(TInt32)iWidth || iInitialVisibility != EAnimationVisible  )
       
  1307             {
       
  1308                aRectangle.iHeight = aRectangle.iWidth = 0;
       
  1309             }
       
  1310         aRectangle.GetBounds( GetCTM(), aBbox );
       
  1311     }
       
  1312     
       
  1313 // ---------------------------------------------------------------------------
       
  1314 //
       
  1315 // ---------------------------------------------------------------------------    
       
  1316 void CSvgMediaAnimationElementImpl::GetFourPointBBox
       
  1317                                     (TSvgFourPointRect& aFourPointBbox)
       
  1318 {
       
  1319 	const TGfxAffineTransform& ctm = GetCTM();
       
  1320     TGfxRoundRectangle2D        aRectangle;   
       
  1321     aRectangle.iX = 0;
       
  1322     aRectangle.iY = 0;
       
  1323     aRectangle.iHeight = iHeight;
       
  1324     aRectangle.iWidth =  iWidth;
       
  1325         
       
  1326     if ( !(TInt32)iHeight || !(TInt32)iWidth )
       
  1327     {
       
  1328      aRectangle.iHeight = aRectangle.iWidth = 0;
       
  1329     }
       
  1330 	TSvgFourPointRect lFourPointBox(aRectangle.iX, aRectangle.iY, aRectangle.iWidth, aRectangle.iHeight);
       
  1331 
       
  1332     TGfxPoint2D lPoint1, lPoint2, lPoint3, lPoint4;
       
  1333 
       
  1334     lFourPointBox.GetPoints(lPoint1, lPoint2, lPoint3, lPoint4);
       
  1335 
       
  1336     ctm.Transform(&lPoint1, &lPoint1, 1);
       
  1337     ctm.Transform(&lPoint2, &lPoint2, 1);
       
  1338     ctm.Transform(&lPoint3, &lPoint3, 1);
       
  1339     ctm.Transform(&lPoint4, &lPoint4, 1);
       
  1340 
       
  1341     aFourPointBbox.SetRectPoints(lPoint1, lPoint2, lPoint3, lPoint4);
       
  1342 }
       
  1343 
       
  1344 // ---------------------------------------------------------------------------
       
  1345 //
       
  1346 // ---------------------------------------------------------------------------
       
  1347 void CSvgMediaAnimationElementImpl::GetUnscaledBBox( TGfxRectangle2D& aBbox )
       
  1348     {
       
  1349     TGfxAffineTransform identityTx;
       
  1350     TGfxRoundRectangle2D        aRectangle;   
       
  1351     aRectangle.iX = iX;
       
  1352     aRectangle.iY = iY;
       
  1353     aRectangle.iHeight = iHeight;
       
  1354     aRectangle.iWidth =  iWidth;
       
  1355     aRectangle.GetBounds( identityTx, aBbox );
       
  1356     }
       
  1357 
       
  1358 // ---------------------------------------------------------------------------
       
  1359 //
       
  1360 // ---------------------------------------------------------------------------    
       
  1361 TBool CSvgMediaAnimationElementImpl::MouseEntered( 
       
  1362                             RPointerArray<CSvgElementImpl>& /* aElements */,
       
  1363                             TInt aX, TInt aY )
       
  1364     
       
  1365     {
       
  1366     if ( !iNewDocument )
       
  1367         {
       
  1368         return EFalse;
       
  1369         }
       
  1370         
       
  1371     TInt listenerCount = (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->
       
  1372                                                      MouseListenerCount();
       
  1373 
       
  1374     if ( iNewDocument )
       
  1375         {
       
  1376         listenerCount += iNewDocument->MouseInternalListenerCount();
       
  1377         }
       
  1378     if ( listenerCount == 0 )
       
  1379         {
       
  1380         return EFalse;
       
  1381         }
       
  1382     // Get list of elements containing pointer (bounding-box)
       
  1383     RPointerArray<CSvgElementImpl> viewableElements;
       
  1384     RPointerArray<CSvgElementImpl> enteringElements;
       
  1385     RPointerArray<CSvgElementImpl> stillInsideElements;
       
  1386     (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->GetViewableElementsAtPoint
       
  1387                                     (iNewDocument, viewableElements, aX, aY );
       
  1388 
       
  1389     // check for mouse entering of elements
       
  1390     TInt viewableEleCnt = viewableElements.Count();
       
  1391     for ( TInt i = 0; i < viewableEleCnt; i++ )
       
  1392         {
       
  1393         // If an element is in the view-list but NOT in the entered-list
       
  1394         // then, it's copied to the entered-list
       
  1395         // otherwise, ignore (still inside)
       
  1396         if ( iSvgMouseEnteredElements.Find( viewableElements[i] ) 
       
  1397              == KErrNotFound )
       
  1398             {
       
  1399             enteringElements.Append( viewableElements[i] );
       
  1400             }
       
  1401         else
       
  1402             {
       
  1403             stillInsideElements.Append( viewableElements[i] );
       
  1404             }
       
  1405         }
       
  1406 
       
  1407     // check for mouse exiting of elements
       
  1408     RPointerArray<CSvgElementImpl> exitingElements;
       
  1409     TInt svgMouseEnteredEleCnt = iSvgMouseEnteredElements.Count();
       
  1410     for ( TInt i = 0; i < svgMouseEnteredEleCnt; i++ )
       
  1411         {
       
  1412         // If an element is in the entered-list but not the view-list
       
  1413         // then, it's copied to the exiting list
       
  1414         // otherwise, ignore (
       
  1415         if ( viewableElements.Find( iSvgMouseEnteredElements[i] ) 
       
  1416              == KErrNotFound )
       
  1417             {
       
  1418             exitingElements.Append( iSvgMouseEnteredElements[i] );
       
  1419             }
       
  1420         }
       
  1421 
       
  1422     // Remove exiting elements from entered list
       
  1423     TInt exitingEleCnt = exitingElements.Count();
       
  1424     for ( TInt i = 0; i < exitingEleCnt; i++ )
       
  1425         {
       
  1426         TInt index = iSvgMouseEnteredElements.Find( exitingElements[i] );
       
  1427         if ( index != KErrNotFound )
       
  1428             {
       
  1429             iSvgMouseEnteredElements.Remove( index );
       
  1430             }
       
  1431         }
       
  1432 
       
  1433     // Add entering elements to entered-list
       
  1434     TInt enteringEleCnt = enteringElements.Count();
       
  1435     for ( TInt i = 0; i < enteringEleCnt; i++ )
       
  1436         {
       
  1437         iSvgMouseEnteredElements.Append( enteringElements[i] );
       
  1438         }
       
  1439 
       
  1440     // Notify exiting
       
  1441     if ( exitingElements.Count() > 0 )
       
  1442         {
       
  1443         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMouseExited
       
  1444                                                 ( exitingElements, aX, aY );
       
  1445         if ( iNewDocument )
       
  1446             {
       
  1447             iNewDocument->NotifyInternalMouseExited( exitingElements, aX, aY );
       
  1448             }
       
  1449         }
       
  1450 
       
  1451     // Notify entering
       
  1452     if ( enteringElements.Count() > 0 )
       
  1453         {
       
  1454         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMouseEntered
       
  1455                                                 ( enteringElements, aX, aY );
       
  1456         if ( iNewDocument )
       
  1457             {
       
  1458             iNewDocument->NotifyInternalMouseEntered( enteringElements, aX, aY );
       
  1459             }
       
  1460         }
       
  1461 
       
  1462     // Notify moved
       
  1463     if ( stillInsideElements.Count() > 0 )
       
  1464         {
       
  1465         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMouseMoved
       
  1466                                             ( stillInsideElements, aX, aY );
       
  1467         if ( iNewDocument )
       
  1468             {
       
  1469             iNewDocument->NotifyInternalMouseMoved( stillInsideElements, aX, aY );
       
  1470             }
       
  1471         }
       
  1472 
       
  1473     exitingElements.Close();
       
  1474     enteringElements.Close();
       
  1475     stillInsideElements.Close();
       
  1476     viewableElements.Close();
       
  1477     
       
  1478     
       
  1479     return ETrue;
       
  1480     }
       
  1481 
       
  1482 // ---------------------------------------------------------------------------
       
  1483 //
       
  1484 // ---------------------------------------------------------------------------    
       
  1485 TBool CSvgMediaAnimationElementImpl::MouseExited( 
       
  1486     RPointerArray<CSvgElementImpl>& /* aElements */,
       
  1487     TInt aX, TInt aY )
       
  1488     {
       
  1489      if ( !iNewDocument )
       
  1490         {
       
  1491         return EFalse;
       
  1492         }
       
  1493         
       
  1494     TInt listenerCount = (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->
       
  1495                                                     MouseListenerCount();
       
  1496 
       
  1497     if ( iNewDocument )
       
  1498     {
       
  1499         listenerCount += iNewDocument->MouseInternalListenerCount();
       
  1500     }
       
  1501     if ( listenerCount == 0 )
       
  1502         {
       
  1503         return EFalse;
       
  1504         }
       
  1505     // Get list of elements containing pointer (bounding-box)
       
  1506     RPointerArray<CSvgElementImpl> viewableElements;
       
  1507     RPointerArray<CSvgElementImpl> enteringElements;
       
  1508     RPointerArray<CSvgElementImpl> stillInsideElements;
       
  1509     (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->GetViewableElementsAtPoint
       
  1510                                     (iNewDocument, viewableElements, aX, aY );
       
  1511 
       
  1512     // check for mouse entering of elements
       
  1513     TInt viewableEleCnt = viewableElements.Count();
       
  1514     for ( TInt i = 0; i < viewableEleCnt; i++ )
       
  1515         {
       
  1516         // If an element is in the view-list but NOT in the entered-list
       
  1517         // then, it's copied to the entered-list
       
  1518         // otherwise, ignore (still inside)
       
  1519         if ( iSvgMouseEnteredElements.Find( viewableElements[i] ) 
       
  1520              == KErrNotFound )
       
  1521             {
       
  1522             enteringElements.Append( viewableElements[i] );
       
  1523             }
       
  1524         else
       
  1525             {
       
  1526             stillInsideElements.Append( viewableElements[i] );
       
  1527             }
       
  1528         }
       
  1529 
       
  1530     // check for mouse exiting of elements
       
  1531     RPointerArray<CSvgElementImpl> exitingElements;
       
  1532     TInt svgMouseEnteredEleCnt = iSvgMouseEnteredElements.Count();
       
  1533     for ( TInt i = 0; i < svgMouseEnteredEleCnt; i++ )
       
  1534         {
       
  1535         // If an element is in the entered-list but not the view-list
       
  1536         // then, it's copied to the exiting list
       
  1537         // otherwise, ignore (
       
  1538         if ( viewableElements.Find( iSvgMouseEnteredElements[i] ) 
       
  1539              == KErrNotFound )
       
  1540             {
       
  1541             exitingElements.Append( iSvgMouseEnteredElements[i] );
       
  1542             }
       
  1543         }
       
  1544 
       
  1545     // Remove exiting elements from entered list
       
  1546     TInt exitingEleCnt = exitingElements.Count();
       
  1547     for ( TInt i = 0; i < exitingEleCnt; i++ )
       
  1548         {
       
  1549         TInt index = iSvgMouseEnteredElements.Find( exitingElements[i] );
       
  1550         if ( index != KErrNotFound )
       
  1551             {
       
  1552             iSvgMouseEnteredElements.Remove( index );
       
  1553             }
       
  1554         }
       
  1555 
       
  1556     // Add entering elements to entered-list
       
  1557     TInt enteringEleCnt = enteringElements.Count();
       
  1558     for ( TInt i = 0; i < enteringEleCnt; i++ )
       
  1559         {
       
  1560         iSvgMouseEnteredElements.Append( enteringElements[i] );
       
  1561         }
       
  1562 
       
  1563     // Notify exiting
       
  1564     if ( exitingElements.Count() > 0 )
       
  1565         {
       
  1566         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMouseExited
       
  1567                                                 ( exitingElements, aX, aY );
       
  1568         if ( iNewDocument )
       
  1569             {
       
  1570             iNewDocument->NotifyInternalMouseExited( exitingElements, aX, aY );
       
  1571             }
       
  1572         }
       
  1573 
       
  1574     // Notify entering
       
  1575     if ( enteringElements.Count() > 0 )
       
  1576         {
       
  1577         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMouseEntered
       
  1578                                                 ( enteringElements, aX, aY );
       
  1579         if ( iNewDocument )
       
  1580             {
       
  1581             iNewDocument->NotifyInternalMouseEntered( enteringElements, aX, aY );
       
  1582             }
       
  1583         }
       
  1584 
       
  1585     // Notify moved
       
  1586     if ( stillInsideElements.Count() > 0 )
       
  1587         {
       
  1588         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMouseMoved
       
  1589                                             ( stillInsideElements, aX, aY );
       
  1590         if ( iNewDocument )
       
  1591             {
       
  1592             iNewDocument->NotifyInternalMouseMoved( stillInsideElements, aX, aY );
       
  1593             }
       
  1594         }
       
  1595 
       
  1596     exitingElements.Close();
       
  1597     enteringElements.Close();
       
  1598     stillInsideElements.Close();
       
  1599     viewableElements.Close();
       
  1600     
       
  1601     
       
  1602     return ETrue;
       
  1603     }
       
  1604 
       
  1605 // ---------------------------------------------------------------------------
       
  1606 //
       
  1607 // ---------------------------------------------------------------------------    
       
  1608 TBool CSvgMediaAnimationElementImpl::MouseMoved( 
       
  1609     RPointerArray<CSvgElementImpl>& /*aElements */,
       
  1610                                 TInt aX, TInt aY )
       
  1611     {
       
  1612     if( !iNewDocument ) 
       
  1613         {
       
  1614         return EFalse;
       
  1615         }
       
  1616         
       
  1617     // Process for Mouse enter/exit
       
  1618     TInt listenerCount = (((CSvgDocumentImpl*)iOwnerDocument)->Engine())
       
  1619                                                    ->MouseListenerCount();
       
  1620 
       
  1621     if ( iNewDocument )
       
  1622     {
       
  1623         listenerCount += iNewDocument->MouseInternalListenerCount();
       
  1624     }
       
  1625     if ( listenerCount == 0 )
       
  1626         {
       
  1627         return EFalse;
       
  1628         }
       
  1629     // Get list of elements containing pointer (bounding-box)
       
  1630     RPointerArray<CSvgElementImpl> viewableElements;
       
  1631     RPointerArray<CSvgElementImpl> enteringElements;
       
  1632     RPointerArray<CSvgElementImpl> stillInsideElements;
       
  1633     (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->GetViewableElementsAtPoint
       
  1634                                     (iNewDocument, viewableElements, aX, aY );
       
  1635 
       
  1636     // check for mouse entering of elements
       
  1637     TInt viewableEleCnt = viewableElements.Count();
       
  1638     for ( TInt i = 0; i < viewableEleCnt; i++ )
       
  1639         {
       
  1640         // If an element is in the view-list but NOT in the entered-list
       
  1641         // then, it's copied to the entered-list
       
  1642         // otherwise, ignore (still inside)
       
  1643         if ( iSvgMouseEnteredElements.Find( viewableElements[i] ) 
       
  1644              == KErrNotFound )
       
  1645             {
       
  1646             enteringElements.Append( viewableElements[i] );
       
  1647             }
       
  1648         else
       
  1649             {
       
  1650             stillInsideElements.Append( viewableElements[i] );
       
  1651             }
       
  1652         }
       
  1653 
       
  1654     // check for mouse exiting of elements
       
  1655     RPointerArray<CSvgElementImpl> exitingElements;
       
  1656     TInt svgMouseEnteredEleCnt = iSvgMouseEnteredElements.Count();
       
  1657     for ( TInt i = 0; i < svgMouseEnteredEleCnt; i++ )
       
  1658         {
       
  1659         // If an element is in the entered-list but not the view-list
       
  1660         // then, it's copied to the exiting list
       
  1661         // otherwise, ignore (
       
  1662         if ( viewableElements.Find( iSvgMouseEnteredElements[i] ) 
       
  1663              == KErrNotFound )
       
  1664             {
       
  1665             exitingElements.Append( iSvgMouseEnteredElements[i] );
       
  1666             }
       
  1667         }
       
  1668 
       
  1669     // Remove exiting elements from entered list
       
  1670     TInt exitingEleCnt = exitingElements.Count();
       
  1671     for ( TInt i = 0; i < exitingEleCnt; i++ )
       
  1672         {
       
  1673         TInt index = iSvgMouseEnteredElements.Find( exitingElements[i] );
       
  1674         if ( index != KErrNotFound )
       
  1675             {
       
  1676             iSvgMouseEnteredElements.Remove( index );
       
  1677             }
       
  1678         }
       
  1679 
       
  1680     // Add entering elements to entered-list
       
  1681     TInt enteringEleCnt = enteringElements.Count();
       
  1682     for ( TInt i = 0; i < enteringEleCnt; i++ )
       
  1683         {
       
  1684         iSvgMouseEnteredElements.Append( enteringElements[i] );
       
  1685         }
       
  1686 
       
  1687     // Notify exiting
       
  1688     if ( exitingElements.Count() > 0 )
       
  1689         {
       
  1690         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMouseExited
       
  1691                                                 ( exitingElements, aX, aY );
       
  1692         if ( iNewDocument )
       
  1693             {
       
  1694             iNewDocument->NotifyInternalMouseExited( exitingElements, aX, aY );
       
  1695             }
       
  1696         }
       
  1697 
       
  1698     // Notify entering
       
  1699     if ( enteringElements.Count() > 0 )
       
  1700         {
       
  1701         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMouseEntered
       
  1702                                                 ( enteringElements, aX, aY );
       
  1703         if ( iNewDocument )
       
  1704             {
       
  1705             iNewDocument->NotifyInternalMouseEntered( enteringElements, aX, aY );
       
  1706             }
       
  1707         }
       
  1708 
       
  1709     // Notify moved
       
  1710     if ( stillInsideElements.Count() > 0 )
       
  1711         {
       
  1712         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMouseMoved
       
  1713                                             ( stillInsideElements, aX, aY );
       
  1714         if ( iNewDocument )
       
  1715             {
       
  1716             iNewDocument->NotifyInternalMouseMoved( stillInsideElements, aX, aY );
       
  1717             }
       
  1718         }
       
  1719 
       
  1720     exitingElements.Close();
       
  1721     enteringElements.Close();
       
  1722     stillInsideElements.Close();
       
  1723     viewableElements.Close();
       
  1724     
       
  1725 
       
  1726     return ETrue;
       
  1727     }
       
  1728 
       
  1729 // ---------------------------------------------------------------------------
       
  1730 //
       
  1731 // ---------------------------------------------------------------------------
       
  1732 TBool CSvgMediaAnimationElementImpl::MousePressed( 
       
  1733     RPointerArray<CSvgElementImpl>& /* aElements */,
       
  1734     TInt aX, TInt aY )
       
  1735     {
       
  1736     
       
  1737     if( !iNewDocument )
       
  1738         {
       
  1739         return EFalse;            
       
  1740         }
       
  1741 
       
  1742         
       
  1743      TInt listenerCount = (((CSvgDocumentImpl*)iOwnerDocument)->Engine())
       
  1744                                                     ->MouseListenerCount();
       
  1745         
       
  1746       
       
  1747     if (iNewDocument)
       
  1748     {
       
  1749         listenerCount += iNewDocument->MouseInternalListenerCount();
       
  1750     }
       
  1751     if ( listenerCount == 0 )
       
  1752         {
       
  1753            // return 0;
       
  1754            return EFalse;
       
  1755         }
       
  1756     RPointerArray<CSvgElementImpl> viewableElements;
       
  1757     // TInt topClickedElement = 0;
       
  1758 
       
  1759     (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->GetViewableElementsAtPoint
       
  1760                                     (iNewDocument,viewableElements, aX, aY );
       
  1761     if ( viewableElements.Count() > 0 )
       
  1762         {
       
  1763         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMousePressed
       
  1764                                                 ( viewableElements, aX, aY );
       
  1765         if ( iNewDocument)
       
  1766             {
       
  1767             iNewDocument->NotifyInternalMousePressed( viewableElements, aX, aY );
       
  1768             }
       
  1769         }
       
  1770     viewableElements.Close();
       
  1771 
       
  1772     //return topClickedElement;
       
  1773    
       
  1774    
       
  1775     return ETrue;
       
  1776     }
       
  1777     
       
  1778 TBool CSvgMediaAnimationElementImpl::MouseReleased( 
       
  1779     RPointerArray<CSvgElementImpl>& /* aElements */,
       
  1780     TInt aX, TInt aY )
       
  1781     {
       
  1782     // Process for MouseRelease
       
  1783     if ( !iNewDocument )
       
  1784         {
       
  1785         return EFalse;    
       
  1786         }
       
  1787     
       
  1788     TInt listenerCount = (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->
       
  1789                                                         MouseListenerCount();
       
  1790 
       
  1791     if ( iNewDocument )
       
  1792     {
       
  1793         listenerCount += iNewDocument->MouseInternalListenerCount();
       
  1794     }
       
  1795     if ( listenerCount == 0 )
       
  1796         {
       
  1797         return ETrue;
       
  1798         }
       
  1799     RPointerArray<CSvgElementImpl> viewableElements;
       
  1800     (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->GetViewableElementsAtPoint
       
  1801                                     (iNewDocument, viewableElements, aX, aY );
       
  1802     if ( viewableElements.Count() > 0 )
       
  1803         {
       
  1804         (((CSvgDocumentImpl*)iOwnerDocument)->Engine())->NotifyMouseReleased
       
  1805                                                 ( viewableElements, aX, aY );
       
  1806         if ( iNewDocument )
       
  1807             {
       
  1808             iNewDocument->NotifyInternalMouseReleased( viewableElements, aX, aY );
       
  1809             }
       
  1810         }
       
  1811     viewableElements.Close();
       
  1812     return ETrue;
       
  1813     }                
       
  1814  
       
  1815 // ---------------------------------------------------------------------------
       
  1816 //
       
  1817 // ---------------------------------------------------------------------------
       
  1818 void CSvgMediaAnimationElementImpl::UpdateCTM()
       
  1819     {
       
  1820     if ( !iNewDocument )
       
  1821     {
       
  1822     return;
       
  1823     }
       
  1824         
       
  1825     CSvgElementImpl::UpdateCTM();
       
  1826     TGfxAffineTransform aTr = GetCTM();
       
  1827           
       
  1828     TGfxPoint2D ep( 1, 0 ), org( 2, 0 );
       
  1829     aTr.Transform( &ep, & ep, 1 );
       
  1830     aTr.Transform( &org, & org, 1 );
       
  1831     ep.iX -= org.iX;
       
  1832     ep.iY -= org.iY;
       
  1833     iScale = TFloatFixPt::Sqrt( ep.iX * ep.iX + ep.iY * ep.iY );
       
  1834    
       
  1835     TGfxAffineTransform tMatrix;
       
  1836     tMatrix = aTr;
       
  1837 
       
  1838     #ifdef SVG_FLOAT_BUILD
       
  1839     tMatrix.Scale( ( TFloatFixPt( 1 ) / ( iScale ) ), ( TFloatFixPt( 1 ) / ( iScale ) ) );
       
  1840     #else
       
  1841     tMatrix.Scale( ( TFloatFixPt( 0x10000,ETrue ) / ( iScale ) ), ( TFloatFixPt( 0x10000,ETrue ) / ( iScale ) ) );
       
  1842     #endif
       
  1843     
       
  1844     if ( !iIsOriginalRootTrSet )
       
  1845     {
       
  1846        MSvgTransformList* aTransformList;
       
  1847        ((CSvgSvgElementImpl *)(iNewDocument->RootElement()))->GetTransform
       
  1848                                                           (aTransformList);
       
  1849         iOriginalRootTr = aTransformList->GetItem(0);
       
  1850         iIsOriginalRootTrSet = ETrue;
       
  1851     }
       
  1852    
       
  1853     iNewDocument->DocumentTransform(tMatrix);
       
  1854     tMatrix.Concatenate(iOriginalRootTr);
       
  1855    
       
  1856     ((CSvgSvgElementImpl *)(iNewDocument->RootElement()))->SetTransformList
       
  1857                                                             (tMatrix);
       
  1858    
       
  1859     TFloatFixPt  newWidth =        iScale * iWidth; 
       
  1860     TFloatFixPt  newHeight =     iScale * iHeight; 
       
  1861    
       
  1862 
       
  1863     ((CSvgSvgElementImpl *)(iNewDocument->RootElement()))->SetWidth(newWidth);
       
  1864     ((CSvgSvgElementImpl *)(iNewDocument->RootElement()))->SetHeight(newHeight);
       
  1865    
       
  1866     ((CSvgElementImpl*)iNewDocument->RootElement())->UpdateCTM();
       
  1867         
       
  1868          
       
  1869     }
       
  1870     
       
  1871 // ---------------------------------------------------------------------------
       
  1872 //
       
  1873 // ---------------------------------------------------------------------------    
       
  1874 void CSvgMediaAnimationElementImpl::DeactivateAnimation()
       
  1875     {
       
  1876         CSvgMediaElementBase::DeactivateAnimation(this);
       
  1877     }
       
  1878         
       
  1879 // End of file
       
  1880