svgtopt/SVG/SVGImpl/src/SVGDocumentImpl.cpp
changeset 0 d46562c3d99d
child 8 baacd33d915b
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     1 /*
       
     2 * Copyright (c) 2003 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 
       
    19 #include <utf.h>
       
    20 #include <s32mem.h>
       
    21 
       
    22 #include "SVGContentHandler.h"
       
    23 #include "Svgdecoder.h"
       
    24 
       
    25 #include  "SVGDocumentImpl.h"
       
    26 #include  "SVGEngineImpl.h"
       
    27 #include  "SVGSvgElementImpl.h"
       
    28 #include  "SVGLineElementImpl.h"
       
    29 #include  "SVGRectElementImpl.h"
       
    30 #include  "SVGCircleElementImpl.h"
       
    31 #include  "SVGEllipseElementImpl.h"
       
    32 #include  "SVGPolylineElementImpl.h"
       
    33 #include  "SVGGElementImpl.h"
       
    34 #include  "SVGPathElementImpl.h"
       
    35 #include  "SVGMpathElementImpl.h"
       
    36 #include  "SVGSchemaData.h"
       
    37 #include  "SVGTextElementImpl.h"
       
    38 #include  "SVGImageElementImpl.h"
       
    39 #include  "SVGUseElementImpl.h"
       
    40 #include  "SVGAElementImpl.h"
       
    41 #include  "SVGStyleElementImpl.h"
       
    42 #include  "SVGForeignObjectElementImpl.h"
       
    43 #include  "SVGSetElementImpl.h"
       
    44 #include  "SVGAnimateTransformElementImpl.h"
       
    45 #include  "SVGAnimateElementImpl.h"
       
    46 #include  "SVGAnimateMotionElementImpl.h"
       
    47 #include  "SVGAnimationElementImpl.h"
       
    48 #include  "SVGMetadataElementImpl.h"
       
    49 #include  "SVGDescElementImpl.h"
       
    50 #include  "SVGDefsElementImpl.h"
       
    51 #include  "SVGTitleElementImpl.h"
       
    52 #include  "SVGFontElementImpl.h"
       
    53 #include  "SVGFontFaceElementImpl.h"
       
    54 #include  "SVGGlyphElementImpl.h"
       
    55 #include  "SVGMissingGlyphElementImpl.h"
       
    56 #include  "SvgHkernelementimpl.h"
       
    57 
       
    58 #include "SVGLinearGradientElementImpl.h"
       
    59 #include "SVGRadialGradientElementImpl.h"
       
    60 #include "SvgStopElementImpl.h"
       
    61 #include "SVGDiscardElementImpl.h"
       
    62 #include "SVGScriptElementImpl.h"
       
    63 
       
    64 #include "SVGAudioElementImpl.h"
       
    65 
       
    66 //#ifdef RD_SVGT_MEDIAANIMATION_SUPPORT
       
    67 #include "SVGMediaAnimationElementImpl.h"
       
    68 //#endif
       
    69 #include "SVGTextAreaElementImpl.h"
       
    70 #include "SVGSolidColorElementImpl.h"
       
    71 
       
    72 #include "SVGFloatCssValueImpl.h"
       
    73 
       
    74 #include "SVGEventHandler.h"
       
    75 #include "SVGErrorImpl.h"
       
    76 #include "SVGFontHashMap.h"
       
    77 #include "SVGTimeContainer.h"
       
    78 #include <ezgzip.h>
       
    79 
       
    80 #include <caf/caf.h>
       
    81 #include <bautils.h>
       
    82 
       
    83 // ==========================================================================
       
    84 // Need method description
       
    85 // ==========================================================================
       
    86 CSvgDocumentImpl* CSvgDocumentImpl::NewL( CSvgBitmapFontProvider* aSvgBitmapFontProvider, const TBool aHasParent,
       
    87     const TSvgSyncBehaviour aSyncBehavDefault,
       
    88     const TInt32 aSyncTolDefault )
       
    89     {
       
    90     CSvgDocumentImpl*   self    = new ( ELeave ) CSvgDocumentImpl(aSvgBitmapFontProvider, 
       
    91         aHasParent, aSyncBehavDefault, aSyncTolDefault );
       
    92     CleanupStack::PushL( self );
       
    93     self->ConstructL();
       
    94     CleanupStack::Pop();
       
    95 
       
    96     return self;
       
    97     }
       
    98 
       
    99 // ==========================================================================
       
   100 // Need method description
       
   101 // ==========================================================================
       
   102 CSvgDocumentImpl* CSvgDocumentImpl::NewLC( CSvgBitmapFontProvider* aSvgBitmapFontProvider, const TBool aHasParent,
       
   103     const TSvgSyncBehaviour aSyncBehavDefault,
       
   104     const TInt32 aSyncTolDefault )
       
   105     {
       
   106     CSvgDocumentImpl*   self    = new ( ELeave ) CSvgDocumentImpl(aSvgBitmapFontProvider,
       
   107         aHasParent, aSyncBehavDefault, aSyncTolDefault );
       
   108     CleanupStack::PushL( self );
       
   109     self->ConstructL();
       
   110 
       
   111     return self;
       
   112     }
       
   113 
       
   114 // ==========================================================================
       
   115 // Need method description
       
   116 // ==========================================================================
       
   117 void CSvgDocumentImpl::ConstructL()
       
   118     {
       
   119     iSchemaData = CSvgSchemaData::NewL();
       
   120 
       
   121 
       
   122     iEventHandler = CSvgEventHandler::NewL();
       
   123 
       
   124     // create CSvgErrorImpl object
       
   125 //   iSvgError = CSvgErrorImpl::NewL();
       
   126     iIsInteractive = EFalse;
       
   127     iHasGroupOpacity = EFalse;
       
   128 
       
   129 
       
   130 //	iImageHashMap = CSvgImageHashMap::NewL();
       
   131 	iFontHashMap = CSvgFontHashMap::NewL();
       
   132 
       
   133 	iMemoryManager = CSvgMemoryManager::NewL();
       
   134 
       
   135 		iTimeForJSR226 = 0;
       
   136     // Create the time container used for Runtime Sync
       
   137     iTimeContainer = CSvgTimeContainer::NewL( this, iHasParent );
       
   138     
       
   139     // Add to the time container
       
   140     iTimeContainer->AddTimedEntityL( this );
       
   141     
       
   142     //set media state to ready as default for document
       
   143     iTimeContainer->TimedEntityReady( this );
       
   144     }
       
   145 
       
   146 // ==========================================================================
       
   147 // Need method description
       
   148 // ==========================================================================
       
   149 CSvgDocumentImpl::CSvgDocumentImpl( CSvgBitmapFontProvider* aSvgBitmapFontProvider, const TBool aHasParent,
       
   150     const TSvgSyncBehaviour aSyncBehavDefault,
       
   151     const TInt32 aSyncTolDefault ) : 
       
   152                                        iInitSortList( ETrue ),
       
   153                                        iReqExReqFtrSysLTested( EFalse ),
       
   154                                        iFinishedParsing( EFalse ),
       
   155                                        iFontHashMap( NULL ),
       
   156                                        iEngine(NULL),
       
   157                                        iMultipleRendering( EFalse ),
       
   158                                        iHasGradientElement( EFalse ),
       
   159                                        iIsThumbNailMode( EFalse ),
       
   160                                        iIsDRMProtected( EFalse ),
       
   161                                        iHasParent( aHasParent ),
       
   162                                        iSyncBehaviorDefault( 
       
   163                                         aSyncBehavDefault ),
       
   164                                        iSyncToleranceDefault( 
       
   165                                         aSyncTolDefault),
       
   166                                         iSvgBitmapFontProvider(aSvgBitmapFontProvider)
       
   167                                                                                         
       
   168                                         
       
   169 
       
   170     {
       
   171     SetDRMMode( ETrue );
       
   172     SetDRMRights( ETrue );
       
   173     }
       
   174 
       
   175 // ==========================================================================
       
   176 // Need method description
       
   177 // ==========================================================================
       
   178 CSvgDocumentImpl::~CSvgDocumentImpl()
       
   179     {
       
   180     if ( iTimeContainer )
       
   181        {
       
   182        // Stop timer and reset time
       
   183        iTimeContainer->UserStop();
       
   184        iTimeContainer->UserResetTime();
       
   185        }
       
   186 
       
   187     if (iPerfText)
       
   188     {
       
   189         delete iPerfText;
       
   190         iPerfText = NULL;
       
   191     }
       
   192 
       
   193     if( iSchemaData )
       
   194         {
       
   195         delete iSchemaData;
       
   196         iSchemaData = NULL;
       
   197         }
       
   198 
       
   199     if( iEventHandler )
       
   200         {
       
   201         delete iEventHandler;
       
   202         iEventHandler = NULL ;
       
   203         }
       
   204 
       
   205 //    if( iSvgError )
       
   206 //        {
       
   207 //        delete iSvgError;
       
   208 //        iSvgError = NULL;
       
   209 //        }
       
   210 
       
   211     if( iRootElement )
       
   212         {
       
   213         delete iRootElement;
       
   214         iRootElement = NULL;
       
   215         }
       
   216 
       
   217 /*	if ( iImageHashMap )
       
   218 	{
       
   219 		//probably should check to verify that the image ptrs
       
   220 		//in this have had their images deleted somehow to be safe
       
   221 		delete iImageHashMap;
       
   222 		iImageHashMap = NULL;
       
   223 	} */
       
   224 
       
   225 	if ( iFontHashMap )
       
   226 	{
       
   227 		delete iFontHashMap;
       
   228 		iFontHashMap = NULL;
       
   229 	}
       
   230     iSvgMouseListeners.Close();
       
   231 
       
   232 	iSvgAnimations.Close();
       
   233 
       
   234     if ( iXmlHandler )
       
   235         {
       
   236         delete iXmlHandler;
       
   237         }
       
   238 
       
   239     if ( iError )
       
   240         {
       
   241         delete iError;
       
   242         }
       
   243 
       
   244  	if ( iMemoryManager )
       
   245  		{
       
   246  		delete iMemoryManager;
       
   247     	}
       
   248 
       
   249     delete iTimeContainer;
       
   250     }
       
   251 
       
   252 // ==========================================================================
       
   253 // Need method description
       
   254 // ==========================================================================
       
   255 void CSvgDocumentImpl::SetEngine( CSvgEngineImpl* aEngine )
       
   256     {
       
   257     iEngine = aEngine;
       
   258     // Propogate this to all child documentsas well
       
   259     // Only animation elements currently possess a new document
       
   260     // Locate all the active animation elements
       
   261     RPointerArray<CSvgElementImpl> lAnimationEleList;
       
   262     
       
   263     FindAllElements( 
       
   264             (CSvgElementImpl* )RootElement(),
       
   265             KSvgMediaAnimationElement, lAnimationEleList );
       
   266     // Set the engine on the child documents associated with the animation elements as well
       
   267     TInt lAnimationEleCnt = lAnimationEleList.Count();
       
   268     for ( TInt lCurAnimationEle = 0; lCurAnimationEle < lAnimationEleCnt; lCurAnimationEle++ )
       
   269         {
       
   270         CSvgMediaAnimationElementImpl* lAnimationElement = 
       
   271             (CSvgMediaAnimationElementImpl* )lAnimationEleList[ lCurAnimationEle ];
       
   272         CSvgDocumentImpl* lChildDoc = lAnimationElement->GetChildDocument();
       
   273         if ( lChildDoc )
       
   274             {
       
   275             lChildDoc->SetEngine( aEngine );
       
   276             }
       
   277         }
       
   278     lAnimationEleList.Close();
       
   279     }
       
   280 
       
   281 // ==========================================================================
       
   282 // Need method description
       
   283 // ==========================================================================
       
   284 CSvgEngineImpl* CSvgDocumentImpl::Engine()
       
   285     {
       
   286     return iEngine;
       
   287     }
       
   288 
       
   289 //***********************************************************************
       
   290 // From MXmlDocument
       
   291 //
       
   292 
       
   293 // ==========================================================================
       
   294 // Need method description
       
   295 // ==========================================================================
       
   296 MXmlElement* CSvgDocumentImpl::CreateElementL( const TDesC& aTagName )
       
   297     {
       
   298 
       
   299     TInt position = iSchemaData->GetSVGElementId(aTagName);
       
   300 
       
   301     if ( position == KErrNotFound )
       
   302         {
       
   303         return NULL;
       
   304         }
       
   305 
       
   306     	return CreateElementL( position );
       
   307 
       
   308     }
       
   309 
       
   310     // ==========================================================================
       
   311 // Need method description
       
   312 // ==========================================================================
       
   313 MXmlElement* CSvgDocumentImpl::CreateElementL(const TUint8 aTagName )
       
   314     {
       
   315 
       
   316     TInt position = (TInt) aTagName;
       
   317 
       
   318     //##4 this uses the rearrangement of elements, all these elements are same as g element
       
   319     // same constructor
       
   320     //
       
   321     // =====> creating fake G elements to take the place of others...
       
   322     //
       
   323     //need to remove G elements as place holders that is a bad idea
       
   324 
       
   325     if( position >= KSvgAltglyphElement && position <= KSvgViewElement )
       
   326         {
       
   327         return ( MXmlElement * ) CSvgGElementImpl::NewL( (TUint8) position, this );
       
   328         }
       
   329 
       
   330     switch ( position )
       
   331         {
       
   332 
       
   333         case KSvgPathElement:
       
   334             // path
       
   335             return ( MXmlElement * ) CSvgPathElementImpl::NewL(  (TUint8) position, this );
       
   336 
       
   337         case KSvgStopElement:
       
   338         	// stop
       
   339             return ( MXmlElement * ) CSvgStopElementImpl::NewL((TUint8) position,this);
       
   340 
       
   341         case KSvgLinearGradientElement:
       
   342         	// linearGradient
       
   343             return ( MXmlElement * ) CSvgLinearGradientElementImpl::NewL((TUint8) position,this);
       
   344 
       
   345         case KSvgRectElement:
       
   346             // rect
       
   347             return ( MXmlElement * ) CSvgRectElementImpl::NewL(  (TUint8) position, this );
       
   348 
       
   349         case KSvgPolygonElement:
       
   350         	// polygon
       
   351             return ( MXmlElement * ) CSvgPolylineElementImpl::NewL( (TUint8) position, this );
       
   352 
       
   353         case KSvgSvgElement:
       
   354             // svg
       
   355             return ( MXmlElement * ) CSvgSvgElementImpl::NewL( (TUint8) position, this );
       
   356 
       
   357         case KSvgRadialGradientElement:
       
   358         	// radialGradient
       
   359             return ( MXmlElement * ) CSvgRadialGradientElementImpl::NewL((TUint8) position,this);
       
   360 
       
   361         case KSvgCircleElement:
       
   362             // circle
       
   363             return ( MXmlElement * ) CSvgCircleElementImpl::NewL( (TUint8) position, this );
       
   364 
       
   365         case KSvgLineElement:
       
   366             // line
       
   367             return ( MXmlElement * ) CSvgLineElementImpl::NewL( (TUint8) position,this );
       
   368 
       
   369         case KSvgPolylineElement:
       
   370             // polyline
       
   371             return ( MXmlElement * ) CSvgPolylineElementImpl::NewL( (TUint8) position, this );
       
   372 
       
   373         case KSvgEllipseElement:
       
   374             // ellipse
       
   375             return ( MXmlElement * ) CSvgEllipseElementImpl::NewL( (TUint8) position, this );
       
   376 
       
   377         case KSvgDefsElement:
       
   378 			// defs
       
   379         	return ( MXmlElement * ) CSvgDefsElementImpl::NewL((TUint8) position, this);
       
   380 
       
   381 		case KSvgForeignObjectElement:
       
   382 			// foreignObject
       
   383     		return ( MXmlElement * ) CSvgForeignObjectElementImpl::NewL((TUint8) position, this);
       
   384 
       
   385         case KSvgStyleElement:
       
   386             // style
       
   387             return ( MXmlElement * ) CSvgStyleElementImpl::NewL( (TUint8) position, this );
       
   388 
       
   389         case KSvgUseElement:
       
   390             // use
       
   391             return ( MXmlElement * ) CSvgUseElementImpl::NewL( (TUint8) position, this );
       
   392 
       
   393         case KSvgImageElement:
       
   394             // image
       
   395             return ( MXmlElement * ) CSvgImageElementImpl::NewL( (TUint8) position, this );
       
   396 
       
   397         case KSvgAnimateColorElement:
       
   398             // animateColor
       
   399         case KSvgAnimateElement:
       
   400             {
       
   401             // animate
       
   402             CSvgAnimateElementImpl* lAnimateElement = CSvgAnimateElementImpl::NewL( (TUint8) position, this );
       
   403             iSvgAnimations.Append(lAnimateElement);
       
   404             return ( MXmlElement * ) lAnimateElement;
       
   405             }
       
   406 
       
   407         case KSvgSetElement:
       
   408             // set
       
   409             return ( MXmlElement * ) CSvgSetElementImpl::NewL( (TUint8) position, this );
       
   410 
       
   411         case KSvgMpathElement:
       
   412         	// mPath
       
   413             return ( MXmlElement * ) CSvgMpathElementImpl::NewL( (TUint8) position, this );
       
   414 
       
   415         case KSvgDiscardElement:
       
   416   			// discard
       
   417             return ( MXmlElement * ) CSvgDiscardElementImpl::NewL( (TUint8) position, this );
       
   418 
       
   419  /*       case KSvgAnimationElement:
       
   420             {
       
   421             // animation
       
   422             CSvgAnimationElementImpl* lAnimationElementImpl = CSvgAnimationElementImpl::NewL( (TUint8) position, this );
       
   423             iSvgAnimations.Append( lAnimationElementImpl );
       
   424             return ( MXmlElement * ) lAnimationElementImpl;
       
   425             }
       
   426 */
       
   427         case KSvgScriptElement:
       
   428             {
       
   429             // script
       
   430             return ( MXmlElement * ) CSvgScriptElementImpl::NewL((TUint8) position,this);
       
   431             }
       
   432 
       
   433         case KSvgSolidColorElement:
       
   434             // solidColor
       
   435             return ( MXmlElement * ) CSvgSolidColorElementImpl::NewL((TUint8) position,this);
       
   436 
       
   437         case KSvgMetadataElement:
       
   438         	// metaData
       
   439         	return ( MXmlElement * ) CSvgMetadataElementImpl::NewL((TUint8) position, this);
       
   440 
       
   441         case KSvgDescElement:
       
   442         	// desc
       
   443         	return ( MXmlElement * ) CSvgDescElementImpl::NewL((TUint8) position, this);
       
   444 
       
   445         case KSvgTitleElement:
       
   446         	// title
       
   447         	return ( MXmlElement * ) CSvgTitleElementImpl::NewL((TUint8) position, this);
       
   448 
       
   449         case KSvgTextElement:
       
   450             // text
       
   451             //add in the boolean thing here....
       
   452             return ( MXmlElement * ) CSvgTextElementImpl::NewL(  (TUint8) position, this );
       
   453 
       
   454         case KSvgTextAreaElement:
       
   455             {
       
   456             // textArea
       
   457             return ( MXmlElement * ) CSvgTextAreaElementImpl::NewL((TUint8) position,this);
       
   458             }
       
   459 
       
   460         case KSvgAnimateMotionElement:
       
   461             {
       
   462             // animateMotion
       
   463             CSvgAnimateMotionElementImpl* lAnimateMotionElement = CSvgAnimateMotionElementImpl::NewL( (TUint8) position, this );
       
   464             iSvgAnimations.Append(lAnimateMotionElement);
       
   465             return ( MXmlElement * ) lAnimateMotionElement;
       
   466             }
       
   467 
       
   468         case KSvgAnimateTransformElement:
       
   469             {
       
   470             // animateTransform
       
   471             CSvgAnimateTransformElementImpl* lAnimateTransformElement = CSvgAnimateTransformElementImpl::NewL( (TUint8) position, this );
       
   472             iSvgAnimations.Append(lAnimateTransformElement);
       
   473             return ( MXmlElement * ) lAnimateTransformElement;
       
   474             }
       
   475 
       
   476         case KSvgGlyphElement:
       
   477             // glyph
       
   478 #ifdef SVG_FONTS_INCLUDE
       
   479             return ( MXmlElement * ) CSvgGlyphElementImpl::NewL( (TUint8) position, this );
       
   480 #else
       
   481             return ( MXmlElement * ) CSvgGElementImpl::NewL( _L( "g" ),(TUint8) position, this );
       
   482 #endif
       
   483         case KSvgFontElement:
       
   484             // font
       
   485 #ifdef SVG_FONTS_INCLUDE
       
   486             return ( MXmlElement * ) CSvgFontElementImpl::NewL( (TUint8) position, this );
       
   487 #else
       
   488             return ( MXmlElement * ) CSvgGElementImpl::NewL( _L( "g" ),(TUint8) position, this );
       
   489 #endif
       
   490 
       
   491         case KSvgAElement:
       
   492             // a
       
   493             return ( MXmlElement * ) CSvgAElementImpl::NewL( (TUint8) position, this );
       
   494 
       
   495         case KSvgFontfaceElement:
       
   496             // font-face
       
   497 #ifdef SVG_FONTS_INCLUDE
       
   498             return ( MXmlElement * ) CSvgFontFaceElementImpl::NewL( (TUint8) position, this );
       
   499 #else
       
   500             return ( MXmlElement * ) CSvgGElementImpl::NewL( _L( "g" )(TUint8) position, this );
       
   501 #endif
       
   502 
       
   503         case KSvgMissingglyphElement:
       
   504             // missing-glyph
       
   505 #ifdef SVG_FONTS_INCLUDE
       
   506             return ( MXmlElement * ) CSvgMissingGlyphElementImpl::NewL( (TUint8) position, this );
       
   507 #else
       
   508             return ( MXmlElement * ) CSvgGElementImpl::NewL( _L( "g" )(TUint8) position, this );
       
   509 #endif
       
   510 
       
   511         case KSvgHkernElement:
       
   512             // hkern
       
   513 #ifdef SVG_FONTS_INCLUDE
       
   514             return ( MXmlElement * ) CSvgHkernElementImpl::NewL( (TUint8) position, this );
       
   515 #else
       
   516             return ( MXmlElement * ) CSvgGElementImpl::NewL( _L( "g" )(TUint8) position, this );
       
   517 #endif
       
   518 
       
   519         case KSvgAudioElement:
       
   520             {
       
   521             CSvgAudioElementImpl* lAudioElement = CSvgAudioElementImpl::NewL( (TUint8) position, this );
       
   522             iSvgAnimations.Append(lAudioElement);
       
   523             return ( MXmlElement * ) lAudioElement;
       
   524             }
       
   525 //#ifdef RD_SVGT_MEDIAANIMATION_SUPPORT
       
   526         case KSvgMediaAnimationElement:
       
   527             {
       
   528             CSvgMediaAnimationElementImpl* lMediaAnimationElement = CSvgMediaAnimationElementImpl::NewL( (TUint8) position, this );
       
   529             iSvgAnimations.Append(lMediaAnimationElement);
       
   530             return ( MXmlElement * ) lMediaAnimationElement;
       
   531             }
       
   532 //#endif
       
   533 
       
   534         } // for switch
       
   535 
       
   536         return NULL;
       
   537     }
       
   538 
       
   539 // ==========================================================================
       
   540 // Need method description
       
   541 // ==========================================================================
       
   542 TInt CSvgDocumentImpl::CreateAttribute( const TDesC& /* aName */ )
       
   543     {
       
   544     return KErrNone;
       
   545     }
       
   546 
       
   547 // ==========================================================================
       
   548 // Need method description
       
   549 // ==========================================================================
       
   550 MXmlElement* CSvgDocumentImpl::GetElementById( const TDesC& aElementId )
       
   551     {
       
   552     if(iRootElement)
       
   553         {
       
   554             const TDesC* myId = iRootElement->Id();
       
   555 
       
   556                 if (myId)
       
   557                 {
       
   558                     if (myId->Length() > 0)
       
   559                     {
       
   560                         if ( *myId == aElementId )
       
   561                         {
       
   562                             return iRootElement;
       
   563                         }
       
   564                     }
       
   565                 }
       
   566 
       
   567     MXmlElement* element = SearchElementById( iRootElement, aElementId );
       
   568 
       
   569     return element;
       
   570         }
       
   571     else
       
   572         {
       
   573         return NULL;
       
   574         }
       
   575     }
       
   576 
       
   577 // ==========================================================================
       
   578 // Need method description
       
   579 // ==========================================================================
       
   580 TInt CSvgDocumentImpl::GetNumberOfIds(MXmlElement* aElement)
       
   581 {
       
   582     TInt count = 0;
       
   583 
       
   584     CSvgElementImpl* child = ( CSvgElementImpl* ) aElement->FirstChild();
       
   585     while ( child != NULL )
       
   586         {
       
   587             const TDesC* lPtr = child->Id();
       
   588 
       
   589             if (lPtr)
       
   590             {
       
   591                 count++;
       
   592             }
       
   593                 // search children
       
   594                 TInt inside_count = GetNumberOfIds( child );
       
   595                 if ( inside_count > 0 )
       
   596                 {
       
   597                     count = count + inside_count;
       
   598                 }
       
   599                 // search siblings
       
   600 
       
   601                 child = ( CSvgElementImpl * ) child->NextSibling();
       
   602         }
       
   603 
       
   604    return count;
       
   605 }
       
   606 
       
   607 // ==========================================================================
       
   608 // Need method description
       
   609 // ==========================================================================
       
   610 TDesC* CSvgDocumentImpl::GetId(TInt index)
       
   611 {
       
   612         RPointerArray<TDesC> ids;
       
   613 
       
   614         FindAllIds( (CSvgElementImpl*)RootElement(), ids );
       
   615 
       
   616         if (index < ids.Count())
       
   617         {
       
   618             return (ids[index]);
       
   619         }
       
   620 
       
   621         ids.Close();
       
   622 
       
   623     return NULL;
       
   624 }
       
   625 
       
   626 // ==========================================================================
       
   627 // // Return all elements of the given type
       
   628 // ==========================================================================
       
   629 void CSvgDocumentImpl::FindAllIds( CSvgElementImpl* aStartElement, RPointerArray<TDesC>& aList )
       
   630 {
       
   631     if ( aStartElement == NULL )
       
   632         return;
       
   633 
       
   634     CSvgElementImpl* child = (CSvgElementImpl*)aStartElement->FirstChild();
       
   635     while ( child != NULL )
       
   636     {
       
   637         // add to list if child is found
       
   638         const TDesC* myId = child->Id();
       
   639 
       
   640         if ( myId )
       
   641             aList.Append( myId );
       
   642 
       
   643         // find in grandchildren
       
   644         FindAllIds( child, aList );
       
   645         child = (CSvgElementImpl*)child->NextSibling();
       
   646     }
       
   647 }
       
   648 
       
   649 
       
   650 //***********************************************************************
       
   651 // From MSvgDocument
       
   652 //
       
   653 
       
   654 
       
   655 
       
   656 //
       
   657 // ==========================================================================
       
   658 // Need method description
       
   659 // ==========================================================================
       
   660 TDesC& CSvgDocumentImpl::GetUrl()
       
   661     {
       
   662     return iUri;
       
   663     }
       
   664 
       
   665 // ==========================================================================
       
   666 // // Returns the value of the current focus index. 
       
   667 // ==========================================================================
       
   668 
       
   669 TInt32 CSvgDocumentImpl::GetCurFocusIndex()
       
   670 {
       
   671 	return iCurObjIdx;
       
   672 }
       
   673 
       
   674 
       
   675 // ==========================================================================
       
   676 // // Increment the focus index by one value
       
   677 // ==========================================================================
       
   678 
       
   679 TInt32 CSvgDocumentImpl::IncCurFocusIndex()
       
   680 {
       
   681 	return ++iCurObjIdx;
       
   682 }
       
   683 
       
   684 // ==========================================================================
       
   685 // // Decrement the focus index by one value
       
   686 // ==========================================================================
       
   687 TInt32 CSvgDocumentImpl::DecCurFocusIndex()
       
   688 {
       
   689 	return --iCurObjIdx;
       
   690 }
       
   691 
       
   692 // ==========================================================================
       
   693 // // Sets the focus index to the given value
       
   694 // ==========================================================================
       
   695 void CSvgDocumentImpl::SetCurFocusIndex(TInt32 aVal)
       
   696 {
       
   697 	iCurObjIdx = aVal;
       
   698 }
       
   699 
       
   700 // ==========================================================================
       
   701 // // Returns the current focus object
       
   702 // ==========================================================================
       
   703 CSvgElementImpl* CSvgDocumentImpl::GetCurFocusObject()
       
   704 {
       
   705 	return iCurrentFocusObject;
       
   706 }
       
   707 
       
   708 // ==========================================================================
       
   709 // // Sets the current focus element to the element specified
       
   710 // ==========================================================================
       
   711 void CSvgDocumentImpl::SetCurFocusObject(CSvgElementImpl* aElement)
       
   712 {
       
   713 	iCurrentFocusObject = aElement;
       
   714 }
       
   715 
       
   716 //
       
   717 // ==========================================================================
       
   718 // Need method description
       
   719 // ==========================================================================
       
   720 EXPORT_C MXmlElement* CSvgDocumentImpl::RootElement()
       
   721     {
       
   722     return iRootElement;
       
   723     }
       
   724 
       
   725 //***********************************************************************
       
   726 //
       
   727 //
       
   728 
       
   729 // ==========================================================================
       
   730 // Need method description
       
   731 // ==========================================================================
       
   732 MXmlElement* CSvgDocumentImpl::SearchElementById( MXmlElement* aElement,
       
   733                                                   const TDesC& aElementId )
       
   734     {
       
   735     CSvgElementImpl* child = ( CSvgElementImpl* ) aElement->FirstChild();
       
   736     while ( child != NULL )
       
   737         {
       
   738             const TDesC* lPtr = child->Id();
       
   739 
       
   740             if (lPtr)
       
   741             {
       
   742                 if ( *lPtr == aElementId )
       
   743                 {
       
   744                     return child;
       
   745                 }
       
   746             }
       
   747                 // search children
       
   748                 MXmlElement* childrenMatch = SearchElementById( child, aElementId );
       
   749                 if ( childrenMatch != NULL )
       
   750                 {
       
   751                     return childrenMatch;
       
   752                 }
       
   753                 // search siblings
       
   754 
       
   755                 child = ( CSvgElementImpl * ) child->NextSibling();
       
   756 
       
   757         }
       
   758     return NULL;
       
   759     }
       
   760 
       
   761 
       
   762 
       
   763 
       
   764 // ==========================================================================
       
   765 // Need method description
       
   766 // ==========================================================================
       
   767 MXmlElement* CSvgDocumentImpl::AppendChildL( MXmlElement* aNewChild )
       
   768     {
       
   769 
       
   770     if ( aNewChild && ((CXmlElementImpl*)aNewChild)->ElemID() == KSvgSvgElement )
       
   771 
       
   772         {
       
   773         // Set new node as the root element, if it is
       
   774         if ( iRootElement )
       
   775             {
       
   776             return NULL;
       
   777             }
       
   778         iRootElement = (CSvgElementImpl *) aNewChild;
       
   779 
       
   780         // Set the new node's next sibling
       
   781         aNewChild->SetNextSibling( NULL );
       
   782         }
       
   783     else
       
   784         {
       
   785         return NULL;
       
   786         }
       
   787 
       
   788     return aNewChild;
       
   789     }
       
   790 
       
   791 
       
   792 // ==========================================================================
       
   793 // Need method description
       
   794 // ==========================================================================
       
   795 CSvgSchemaData* CSvgDocumentImpl::SchemaData()
       
   796     {
       
   797     return iSchemaData;
       
   798     }
       
   799 
       
   800 
       
   801 // ==========================================================================
       
   802 // Need method description
       
   803 // ==========================================================================
       
   804 void CSvgDocumentImpl::SetUri( const TDesC& aUri )
       
   805     {
       
   806     iUri.Zero();
       
   807     iUri.Copy(aUri);
       
   808     }
       
   809 
       
   810 // ==========================================================================
       
   811 // Need method description
       
   812 // ==========================================================================
       
   813 void CSvgDocumentImpl::GetUri( TDes& aUri )
       
   814     {
       
   815     aUri.Zero();
       
   816     aUri.Copy(iUri);
       
   817     }
       
   818 
       
   819 // ==========================================================================
       
   820 // Register an element for receiving events using the event mask
       
   821 // ==========================================================================
       
   822 void CSvgDocumentImpl::AddToEventReceiverListL( MSvgEventReceiver* aElement,
       
   823                                              TUint8 aEventMask)
       
   824     {
       
   825     if (iEventHandler != NULL)
       
   826     iEventHandler->AddToEventReceiverListL( aElement, aEventMask );
       
   827     }
       
   828 
       
   829 // ==========================================================================
       
   830 // Register an element for receiving events and events using the event mask
       
   831 // ==========================================================================
       
   832 void CSvgDocumentImpl::AddToEventReceiverListL( MSvgEventReceiver* aElement,
       
   833                                                 TSvgEvent aEvent,
       
   834                                              TUint8 aEventMask)
       
   835     {
       
   836     if (iEventHandler != NULL)
       
   837     iEventHandler->AddToEventReceiverListL( aElement,aEvent,aEventMask );
       
   838     }
       
   839 
       
   840 // ==========================================================================
       
   841 // Unregister an element for receiving events using the event mask
       
   842 // ==========================================================================
       
   843 void CSvgDocumentImpl::RemoveFromEventReceiverList( MSvgEventReceiver* aElement )
       
   844     {
       
   845     if (iEventHandler != NULL)
       
   846     iEventHandler->RemoveFromEventReceiverList( aElement );
       
   847     }
       
   848 
       
   849 // ==========================================================================
       
   850 // Provide event handler the event timing information for the
       
   851 // completion of event.
       
   852 // ==========================================================================
       
   853 void CSvgDocumentImpl::AddEventBeginTime(MSvgEventReceiver* aElement, TUint32 aTime, MSvgEventReceiver* aTargetElement )
       
   854     {
       
   855     if (iEventHandler != NULL)
       
   856     iEventHandler->AddEventBeginTime( aElement, aTime, aTargetElement );
       
   857     }
       
   858 
       
   859 // ==========================================================================
       
   860 // Sort the events in a time scale according to their absolute start
       
   861 // and finish times
       
   862 // ==========================================================================
       
   863 void CSvgDocumentImpl::SortEventList()
       
   864     {
       
   865     if (iEventHandler != NULL)
       
   866     iEventHandler->SortEventList();
       
   867     }
       
   868 
       
   869 //
       
   870 // ==========================================================================
       
   871 // Returns an element that is registered for the given event mask and
       
   872 // is the first one starting from the given index (either up or down the
       
   873 // list based on the aNext parameter)
       
   874 // ==========================================================================
       
   875 CSvgElementImpl* CSvgDocumentImpl::GetEventReceiverElement(TInt32 aIndex, TBool aNext, TUint8 aEventMask, TInt32& aNewIndex)
       
   876     {
       
   877     if (iEventHandler != NULL)
       
   878     {
       
   879             return (CSvgElementImpl*)iEventHandler->GetEventReceiver(aIndex, aNext, aEventMask, aNewIndex);
       
   880     }
       
   881     else
       
   882     return NULL;
       
   883 
       
   884     }
       
   885 
       
   886 // ==========================================================================
       
   887 // Is Animation file
       
   888 // ==========================================================================
       
   889 TBool CSvgDocumentImpl::IsAnimationFile()
       
   890     {
       
   891     if( (iEventHandler != NULL) && iEventHandler->Count() )
       
   892         return ETrue;
       
   893     else
       
   894         return EFalse;
       
   895     }
       
   896     
       
   897 // ==========================================================================
       
   898 // IsValidSubEventMask
       
   899 // ==========================================================================
       
   900 TBool CSvgDocumentImpl::IsValidSubEventMask(TUint16 aSubEventMask)
       
   901     {
       
   902     if(iEventHandler)
       
   903         {
       
   904         return(iEventHandler->IsValidSubEventMask(aSubEventMask));
       
   905         }
       
   906     else
       
   907         {
       
   908         return EFalse;    
       
   909         }
       
   910     }
       
   911 // ==========================================================================
       
   912 // Set DRM Mode
       
   913 // ==========================================================================
       
   914 
       
   915 void CSvgDocumentImpl::SetDRMMode(TBool aEnable)
       
   916     {
       
   917     iDrmEnable = aEnable;
       
   918     }
       
   919 // ==========================================================================
       
   920 // Set DRM Mode
       
   921 // ==========================================================================
       
   922 void CSvgDocumentImpl::Reset(MSvgEvent *aEvent)
       
   923     {
       
   924     if ( iAnimationResetNeeded && iEventHandler != NULL )
       
   925         {
       
   926         iEventHandler->Reset( aEvent );
       
   927         iAnimationResetNeeded = EFalse;
       
   928         }
       
   929     }
       
   930 // ==========================================================================
       
   931 // Set DRM Mode
       
   932 // ==========================================================================
       
   933 TBool CSvgDocumentImpl::SvgElementPresent(CSvgElementImpl* aElement)
       
   934 {
       
   935     if(iRootElement == NULL) return EFalse;
       
   936     if ( ( ( CSvgElementImpl * ) iRootElement ) == aElement )
       
   937         {
       
   938         return ETrue;
       
   939         }
       
   940 
       
   941     return SearchByPointer(iRootElement, aElement);
       
   942 
       
   943 }
       
   944 // ==========================================================================
       
   945 // Set DRM Mode
       
   946 // ==========================================================================
       
   947 TBool CSvgDocumentImpl::SearchByPointer(CSvgElementImpl* aParent, CSvgElementImpl* aElement)
       
   948 {
       
   949     CSvgElementImpl* child = ( CSvgElementImpl* ) aParent->FirstChild();
       
   950     while ( child != NULL )
       
   951         {
       
   952 
       
   953         if ( child  == aElement )
       
   954             {
       
   955             return ETrue;
       
   956             }
       
   957         // search children
       
   958         TBool result = SearchByPointer( child, aElement );
       
   959         if (result)
       
   960             {
       
   961             return ETrue;
       
   962             }
       
   963         // search siblings
       
   964         child = ( CSvgElementImpl * ) child->NextSibling();
       
   965         }
       
   966     return EFalse;
       
   967 }
       
   968 // ==========================================================================
       
   969 // Set DRM Mode
       
   970 // ==========================================================================
       
   971 void CSvgDocumentImpl::SetFocusElement(CXmlElementImpl* aElement )
       
   972 {
       
   973     iCurrentFocusObject = (CSvgElementImpl*)aElement;
       
   974 }
       
   975 // ==========================================================================
       
   976 // Set DRM Mode
       
   977 // ==========================================================================
       
   978 CXmlElementImpl* CSvgDocumentImpl::GetFocusElement()
       
   979 {
       
   980     return (CXmlElementImpl*) iCurrentFocusObject;
       
   981 }
       
   982 
       
   983 // ==========================================================================
       
   984 // Need method description
       
   985 // ==========================================================================
       
   986 void CSvgDocumentImpl::ReInitialize()
       
   987     {
       
   988     if(iMultipleRendering)
       
   989         {
       
   990         if (iEventHandler != NULL)
       
   991         iEventHandler->ReInitialize();
       
   992         }
       
   993     else
       
   994         {
       
   995         iMultipleRendering= ETrue;
       
   996         }
       
   997     }
       
   998 
       
   999 // ==========================================================================
       
  1000 // Need method description
       
  1001 // ==========================================================================
       
  1002 void CSvgDocumentImpl::Load( const TDesC& aFileName, CSvgErrorImpl& aError )
       
  1003 {
       
  1004     aError.SetErrorCode( ESvgNoError );
       
  1005 
       
  1006     RFs session;
       
  1007     OpenSession( session, aError );
       
  1008     if ( aError.HasError() )
       
  1009         return;
       
  1010 
       
  1011     RFile fileHandle;
       
  1012     TInt openError = fileHandle.Open( session, aFileName, EFileRead );
       
  1013     if ( openError != KErrNone )
       
  1014     {
       
  1015         PrepareError( aError, ESvgUnknown, openError,
       
  1016                       _L( "Fail to open file for reading: " ), aFileName );
       
  1017         session.Close();
       
  1018         return;
       
  1019     }
       
  1020     else
       
  1021     {
       
  1022         Load( fileHandle, aError );
       
  1023         session.Close();
       
  1024     }
       
  1025 }
       
  1026 
       
  1027 // ==========================================================================
       
  1028 // Need method description
       
  1029 // ==========================================================================
       
  1030 void CSvgDocumentImpl::Load( const TDesC8& aByteData, CSvgErrorImpl& aError, TBool aRemoveFalseSwitchElements )
       
  1031 {
       
  1032     aError.SetErrorCode( ESvgNoError );
       
  1033 
       
  1034     //-------------------------------------------------------------------
       
  1035     // Byte array is gzipped and/or drm:
       
  1036     // Write buffer to file:
       
  1037     // a) GZip only has filename function to unzip
       
  1038     // b) Drm only has file-handle to decrypt
       
  1039     //-------------------------------------------------------------------
       
  1040     if ( IsGzipContent( aByteData ) ||
       
  1041          ( iDrmEnable && IsDRMContent( aByteData ) ) )
       
  1042     {
       
  1043         RFs session;
       
  1044         OpenSession( session, aError );
       
  1045         if ( aError.HasError() )
       
  1046             return;
       
  1047 
       
  1048         // Write byte-array to temp file
       
  1049         TFileName zippedTempFilename;
       
  1050         if ( WriteToTempFile( session, aByteData, zippedTempFilename, aError ) != KErrNone )
       
  1051         {
       
  1052             session.Close();
       
  1053             return;
       
  1054         }
       
  1055         Load( zippedTempFilename, aError );
       
  1056         session.Delete( zippedTempFilename );
       
  1057         session.Close();
       
  1058     }
       
  1059     //-------------------------------------------------------------------
       
  1060     // byte-array is neither gzipped nor DRM encrypted
       
  1061     //-------------------------------------------------------------------
       
  1062     else
       
  1063     {
       
  1064         iIsDRMProtected = EFalse;
       
  1065         iEventHandler->Reset();
       
  1066         TRAPD(error,ProcessSvgContentL( aByteData, aError, aRemoveFalseSwitchElements ));
       
  1067         if ( error != KErrNone )
       
  1068         {
       
  1069             PrepareError( aError, ESvgNoMemory, error,
       
  1070                           _L( "Out of Memory: " ),
       
  1071                           _L( "Instantiating Parser" ) );
       
  1072         }
       
  1073 
       
  1074         iInitialDrawFlag = ETrue;
       
  1075         iFinishedParsing = ETrue;
       
  1076 
       
  1077     }
       
  1078 }
       
  1079 
       
  1080 // ==========================================================================
       
  1081 // Need method description
       
  1082 // ==========================================================================
       
  1083 void CSvgDocumentImpl::Load( RFile& aFileHandle, CSvgErrorImpl& aError )
       
  1084 {
       
  1085     aError.SetErrorCode( ESvgNoError );
       
  1086 
       
  1087     RFs session;
       
  1088     OpenSession( session, aError );
       
  1089     if ( !aError.HasError() )
       
  1090     {
       
  1091         Load( session, aFileHandle, aError );
       
  1092         session.Close();
       
  1093     }
       
  1094 }
       
  1095 // -----------------------------------------------------------------------------
       
  1096 // CSvgDocumentImpl::ParentTimeContainerTick
       
  1097 // From MSvgTimedEntityInterface
       
  1098 // -----------------------------------------------------------------------------
       
  1099 //
       
  1100 void CSvgDocumentImpl::ParentTimeContainerTick( 
       
  1101     TSvgTick aTick ) // Current tick information 
       
  1102     {
       
  1103     TBool lDoRedraw = ETrue;
       
  1104     if ( iHasParent )
       
  1105         {
       
  1106         // Do not redraw in child document to avoid
       
  1107         // double redraws.
       
  1108         lDoRedraw = EFalse;
       
  1109         }
       
  1110     // Create timer event and propogate to engine
       
  1111     TSvgTimerEvent lTimerEvent( aTick.iParentTcTick );
       
  1112     // Send to engine to process the timer event
       
  1113     TRAPD( lProcEvtErr, Engine()->ProcessEventL( 
       
  1114         this, &lTimerEvent, lDoRedraw ) );
       
  1115     if ( lProcEvtErr != KErrNone )
       
  1116         {
       
  1117         // Error Processing
       
  1118         }
       
  1119     }
       
  1120     
       
  1121 // -----------------------------------------------------------------------------
       
  1122 // CSvgDocumentImpl::GetEntitySyncBehavior
       
  1123 // From MSvgTimedEntityInterface
       
  1124 // -----------------------------------------------------------------------------
       
  1125 //        
       
  1126 TSvgSyncBehaviour CSvgDocumentImpl::GetEntitySyncBehavior()
       
  1127     {
       
  1128     // Document is locked with the parent tc timeline
       
  1129     return ESvgSyncLocked; 
       
  1130     }
       
  1131         
       
  1132 
       
  1133 // -----------------------------------------------------------------------------
       
  1134 // CSvgDocumentImpl::GetEntityCurrentTime
       
  1135 // From MSvgTimedEntityInterface
       
  1136 // -----------------------------------------------------------------------------
       
  1137 //        
       
  1138 void CSvgDocumentImpl::GetEntityCurrentTime( TUint32& 
       
  1139             /* aEntityCurTime */) // Current Entity Time in msecs. 
       
  1140     {
       
  1141     }
       
  1142 
       
  1143 // -----------------------------------------------------------------------------
       
  1144 // CSvgDocumentImpl::GetCnfSyncMasterStatus
       
  1145 // From MSvgTimedEntityInterface
       
  1146 // -----------------------------------------------------------------------------
       
  1147 //        
       
  1148 void CSvgDocumentImpl::GetCnfSyncMasterStatus( 
       
  1149             TBool& aIsSyncMaster ) // Indicates whether the element is configured as 
       
  1150                                    // Sync Master. 
       
  1151     {
       
  1152     // Document can never be a sync master
       
  1153     aIsSyncMaster = EFalse;
       
  1154     }                                   
       
  1155 
       
  1156 // -----------------------------------------------------------------------------
       
  1157 // CSvgDocumentImpl::GetCurSyncMasterStatus
       
  1158 // From MSvgTimedEntityInterface
       
  1159 // -----------------------------------------------------------------------------
       
  1160 void CSvgDocumentImpl::GetCurSyncMasterStatus( 
       
  1161             TBool& aIsSyncMaster ) // Indicates whether the element is currrently 
       
  1162                                   // Sync Master. 
       
  1163     {
       
  1164     // Document can never be a sync master
       
  1165     aIsSyncMaster = EFalse;
       
  1166     }        
       
  1167 
       
  1168 
       
  1169 // -----------------------------------------------------------------------------
       
  1170 // CSvgDocumentImpl::SetCurSyncMasterStatus
       
  1171 // From MSvgTimedEntityInterface
       
  1172 // -----------------------------------------------------------------------------
       
  1173 void CSvgDocumentImpl::SetCurSyncMasterStatus( 
       
  1174     TBool /*aSyncMasterStatus */) // Indicates whether the element is 
       
  1175                                   // currrently Sync Master.
       
  1176     {
       
  1177     // Document sync master status is always false as it can never be 
       
  1178     // a sync master
       
  1179     }
       
  1180 
       
  1181 // -----------------------------------------------------------------------------
       
  1182 // CSvgDocumentImpl::CanGenerateTick
       
  1183 // From MSvgTimedEntityInterface
       
  1184 // -----------------------------------------------------------------------------
       
  1185 TBool CSvgDocumentImpl::CanGenerateTick()
       
  1186     {
       
  1187     // Document cannot generate tick, as it is not a inherently timed element
       
  1188     return EFalse;
       
  1189     }
       
  1190 
       
  1191 // -----------------------------------------------------------------------------
       
  1192 // CSvgDocumentImpl::CanUseParentTick
       
  1193 // From MSvgTimedEntityInterface
       
  1194 // -----------------------------------------------------------------------------
       
  1195 TBool CSvgDocumentImpl::CanUseParentTick()
       
  1196     {
       
  1197     // Return True as document can always use parent tick to 
       
  1198     // advance itself
       
  1199     return ( ETrue );
       
  1200     }
       
  1201     
       
  1202 // -----------------------------------------------------------------------------
       
  1203 // CSvgDocumentImpl::ResyncTimedEntity
       
  1204 // From MSvgTimedEntityInterface
       
  1205 // -----------------------------------------------------------------------------
       
  1206 void CSvgDocumentImpl::ResyncTimedEntity( 
       
  1207             TUint32 /*aSynctime*/ ) // Time for resync in msecs.
       
  1208     {
       
  1209     }
       
  1210     
       
  1211 
       
  1212 
       
  1213 // -----------------------------------------------------------------------------
       
  1214 // CSvgDocumentImpl::PauseTimedEntity
       
  1215 // From MSvgTimedEntityInterface
       
  1216 // -----------------------------------------------------------------------------
       
  1217 void CSvgDocumentImpl::PauseTimedEntity()
       
  1218     {
       
  1219     
       
  1220     }
       
  1221 
       
  1222 // -----------------------------------------------------------------------------
       
  1223 // CSvgDocumentImpl::ResumeTimedEntity
       
  1224 // From MSvgTimedEntityInterface
       
  1225 // -----------------------------------------------------------------------------
       
  1226 void CSvgDocumentImpl::ResumeTimedEntity()
       
  1227     {
       
  1228     
       
  1229     }
       
  1230 
       
  1231 // -----------------------------------------------------------------------------
       
  1232 // CSvgDocumentImpl::StopTimedEntity
       
  1233 // From MSvgTimedEntityInterface
       
  1234 // -----------------------------------------------------------------------------
       
  1235 void CSvgDocumentImpl::StopTimedEntity()
       
  1236     {
       
  1237     iEventHandler->ResetTimes();
       
  1238     }
       
  1239 
       
  1240 
       
  1241 //From MSvgTimedEntityInterface
       
  1242 TSvgObjectType CSvgDocumentImpl::ObjectType()
       
  1243 {
       
  1244 	return ESvgDocumentElement;	
       
  1245 }
       
  1246 
       
  1247 
       
  1248 //returns the child time container of the element 
       
  1249 //used in timecontainer
       
  1250 CSvgTimeContainer* CSvgDocumentImpl::GetChildTimeContainer()
       
  1251 {
       
  1252     return NULL;
       
  1253 }
       
  1254     
       
  1255 
       
  1256 //if node has a child
       
  1257 //		visit the child call postorder on that
       
  1258 //add current node
       
  1259 //if there are siblings 
       
  1260 //		visit all siblings
       
  1261 void CSvgDocumentImpl::ParsePostOrderMediaElements( CSvgElementImpl* aRoot, 
       
  1262     RPointerArray<CSvgElementImpl>& aPostOrderList)
       
  1263     {
       
  1264     if ( !aRoot )
       
  1265         {
       
  1266         return;
       
  1267         }
       
  1268         
       
  1269 	CSvgElementImpl* lNodePtr = ( CSvgElementImpl* )aRoot->FirstChild();
       
  1270 	while ( lNodePtr != NULL )
       
  1271 	    {
       
  1272 	    ParsePostOrderMediaElements( lNodePtr, aPostOrderList );
       
  1273         lNodePtr = (CSvgElementImpl* )(lNodePtr->NextSibling() );
       
  1274 	    }
       
  1275 	
       
  1276 	// Add only media elements, currently animation and audio
       
  1277 	if ( aRoot->ElemID() == KSvgMediaAnimationElement || 
       
  1278 	    aRoot->ElemID() == KSvgAudioElement )	
       
  1279 	    {
       
  1280 	    aPostOrderList.Append( aRoot );	    
       
  1281 	    }
       
  1282     }
       
  1283 
       
  1284 // ==========================================================================
       
  1285 // Need method description
       
  1286 // ==========================================================================
       
  1287 void CSvgDocumentImpl::Load( RFs& aSession, RFile& aFileHandle, CSvgErrorImpl& aError )
       
  1288 {
       
  1289     iEventHandler->Reset();
       
  1290 
       
  1291     RFile ungzippedFile;
       
  1292     RFile* fileHandle = &aFileHandle;
       
  1293     TFileName tempFilename;
       
  1294     TBool needToDeleteTempFile = EFalse;
       
  1295     iIsDRMProtected = EFalse;
       
  1296 
       
  1297     //************************************************
       
  1298     // Check for gzip format: write to temp file
       
  1299     //************************************************
       
  1300     // Ignore Gzip content due to platform security: uncompressed file must be created
       
  1301     if ( IsGzipContent( aFileHandle ) )
       
  1302     {
       
  1303         //************************************************
       
  1304         // Ungzipped content may be DRM or txt-svg or binary-svg
       
  1305         //************************************************
       
  1306         needToDeleteTempFile = ETrue;
       
  1307         if ( !ProcessGZipContent( aSession, aFileHandle, tempFilename, aError ) )
       
  1308             return;
       
  1309 
       
  1310         // Open ungzipped file
       
  1311         TInt openError = ungzippedFile.Open( aSession, tempFilename, EFileRead );
       
  1312         if ( openError != KErrNone )
       
  1313         {
       
  1314             // couldn't open temp file for writing
       
  1315             PrepareError( aError, ESvgUnknown, openError,
       
  1316                           _L( "Loading GZipped SVG File failed: " ),
       
  1317                           _L( "Error Opening Temp File for Reading." ) );
       
  1318 
       
  1319             // Delete uncompress temp file if needed
       
  1320             if ( needToDeleteTempFile )
       
  1321                 aSession.Delete( tempFilename );
       
  1322             return;
       
  1323         }
       
  1324         fileHandle = &ungzippedFile;
       
  1325     }
       
  1326 
       
  1327     HBufC8* svgByteArray = NULL;
       
  1328     //************************************************
       
  1329     // Decrypt DRM
       
  1330     //************************************************
       
  1331     if ( iDrmEnable && IsDRMContent( *fileHandle ) )
       
  1332     {
       
  1333         TRAPD( drmError, svgByteArray = ProcessDRMContentL( *fileHandle, aError ) );
       
  1334         if ( drmError != KErrNone )
       
  1335         {
       
  1336             PrepareError( aError, ESvgNoMemory, drmError,
       
  1337                           _L( "Out of Memory: " ),
       
  1338                           _L( "Instantiating DRM Decoder" ) );
       
  1339             return;
       
  1340         }
       
  1341         // drm failed, error should already be set
       
  1342         else if ( svgByteArray == NULL )
       
  1343         {
       
  1344             return;
       
  1345         }
       
  1346 
       
  1347         if ( needToDeleteTempFile && ( drmError || svgByteArray == NULL ) )
       
  1348         {
       
  1349             aSession.Delete( tempFilename );
       
  1350         }
       
  1351         iIsDRMProtected = ETrue;
       
  1352     }
       
  1353     // Read Non encrypted data
       
  1354     else
       
  1355     {
       
  1356         //************************************************
       
  1357         // Read plain file: txt-svg or binary-svg
       
  1358         //************************************************
       
  1359         TInt fileLength = 0;
       
  1360         fileHandle->Size( fileLength );
       
  1361         TRAPD( error, svgByteArray = HBufC8::NewL( fileLength ) );
       
  1362         if ( error != NULL )
       
  1363         {
       
  1364             PrepareError( aError, ESvgNoMemory, error,
       
  1365                           _L( "Out of Memory" ),
       
  1366                           _L( "Allocating byte-array for data" ) );
       
  1367             if ( needToDeleteTempFile )
       
  1368             {
       
  1369                 aSession.Delete( tempFilename );
       
  1370             }
       
  1371             return;
       
  1372         }
       
  1373         TInt pos = 0;
       
  1374         fileHandle->Seek( ESeekStart, pos );
       
  1375         TPtr8 des = svgByteArray->Des();
       
  1376         TInt readError = fileHandle->Read( des );
       
  1377         if ( readError != KErrNone )
       
  1378         {
       
  1379             PrepareError( aError, ESvgUnknown, readError,
       
  1380                           _L( "Reading SVG File Failed." ), _L( "" ) );
       
  1381             delete svgByteArray;
       
  1382             if ( needToDeleteTempFile )
       
  1383             {
       
  1384                 aSession.Delete( tempFilename );
       
  1385             }
       
  1386             return;
       
  1387         }
       
  1388     }
       
  1389 
       
  1390     //************************************************
       
  1391     // Parser binary or plain svg content
       
  1392     //************************************************
       
  1393     TRAPD( svgError, ProcessSvgContentL( *svgByteArray, aError ) );
       
  1394     if ( svgError != KErrNone || ( aError.HasError() && !aError.IsWarning() ) )
       
  1395     {
       
  1396         delete svgByteArray;
       
  1397         if ( !aError.HasError() )
       
  1398         {
       
  1399             PrepareError( aError, ESvgNoMemory, svgError,
       
  1400                            _L( "Out of Memory: " ),
       
  1401                            _L( "Instantiating SVG ContentHandler/Decoder" ) );
       
  1402         }
       
  1403         if ( needToDeleteTempFile )
       
  1404             aSession.Delete( tempFilename );
       
  1405         return;
       
  1406     }
       
  1407 
       
  1408     iInitialDrawFlag = ETrue;
       
  1409     iFinishedParsing = ETrue;
       
  1410 
       
  1411     delete svgByteArray;
       
  1412 
       
  1413 
       
  1414     // Delete uncompress temp file if needed
       
  1415     if ( needToDeleteTempFile )
       
  1416     {
       
  1417         // Close only when file handle is for temp file
       
  1418         fileHandle->Close();
       
  1419         aSession.Delete( tempFilename );
       
  1420     }
       
  1421 
       
  1422     // Prepare engine to draw document
       
  1423     LoadingCompleted();
       
  1424 }
       
  1425 
       
  1426 // ==========================================================================
       
  1427 // Need method description
       
  1428 // Leaves only when allocating memory fails
       
  1429 // Reports other errors
       
  1430 // ==========================================================================
       
  1431 void CSvgDocumentImpl::ProcessSvgContentL( const TDesC8& aByteArray, CSvgErrorImpl& aError, TBool aRemoveFalseSwitchElements )
       
  1432 {
       
  1433     //************************************************
       
  1434     // Determine binary or xml svg file
       
  1435     //************************************************
       
  1436     if ( IsBinarySvg( aByteArray ) )
       
  1437     {
       
  1438         TInt error = KErrNone;
       
  1439         CSvgDecoder* decoder = CSvgDecoder::NewL( aByteArray );
       
  1440 
       
  1441         TRAP( error, iRootElement = decoder->StartDecodingL( this, aError ) );
       
  1442         if ( error != KErrNone || iRootElement == NULL && !aError.HasError() )
       
  1443         {
       
  1444             if ( error != KErrNone )
       
  1445             {
       
  1446                 PrepareError( aError, ESvgbFileNotValid, error,
       
  1447                               _L( "Invalid binary file." ), _L( "" ) );
       
  1448             }
       
  1449         }
       
  1450         delete decoder;
       
  1451     }
       
  1452     else
       
  1453     {
       
  1454         iXmlHandler = CSvgContentHandler::NewL( aRemoveFalseSwitchElements );
       
  1455         iRootElement = iXmlHandler->ParseByteData( this, aByteArray, aError );
       
  1456         delete iXmlHandler;
       
  1457         iXmlHandler = NULL;
       
  1458     }
       
  1459 }
       
  1460 
       
  1461 // ==========================================================================
       
  1462 // JSR226 only!!
       
  1463 // Allows filling of document from JSR side with 16 bit string instead of 8
       
  1464 //
       
  1465 // ==========================================================================
       
  1466 void CSvgDocumentImpl::Load16BitString( const TDesC16& aSvgString, CSvgErrorImpl& aError, TBool aRemoveFalseSwitchElements )
       
  1467 {
       
  1468     aError.SetErrorCode( ESvgNoError );
       
  1469 
       
  1470     iIsDRMProtected = EFalse;
       
  1471 
       
  1472     if (iEventHandler)
       
  1473     iEventHandler->Reset();
       
  1474     TRAPD(error,Process16BitSvgContentL( aSvgString, aError, aRemoveFalseSwitchElements ));
       
  1475     if ( error != KErrNone )
       
  1476     {
       
  1477     	PrepareError( aError, ESvgNoMemory, error,
       
  1478                           _L( "Out of Memory: " ),
       
  1479                           _L( "Instantiating Parser" ) );
       
  1480     }
       
  1481 
       
  1482     iInitialDrawFlag = ETrue;
       
  1483     iFinishedParsing = ETrue;
       
  1484 }
       
  1485 
       
  1486 void CSvgDocumentImpl::Process16BitSvgContentL( const TDesC16& aSvgString, CSvgErrorImpl& aError, TBool aRemoveFalseSwitchElements )
       
  1487 {
       
  1488     iXmlHandler = CSvgContentHandler::NewL( aRemoveFalseSwitchElements );
       
  1489     iRootElement = iXmlHandler->Parse16BitData( this, aSvgString, aError );
       
  1490     delete iXmlHandler;
       
  1491     iXmlHandler = NULL;
       
  1492 }
       
  1493 // END OF JSR226 ONLY
       
  1494 // ==========================================================================
       
  1495 
       
  1496 // ==========================================================================
       
  1497 void CSvgDocumentImpl::CancelParsing()
       
  1498     {
       
  1499     // Check if there is animation element in the parent svg
       
  1500     RPointerArray<CSvgElementImpl> lAnimationEleList;
       
  1501     FindAllElements((CSvgElementImpl* )RootElement(),
       
  1502                KSvgMediaAnimationElement, lAnimationEleList );
       
  1503     TInt lAnimationEleCnt = lAnimationEleList.Count();    
       
  1504     for ( TInt lCurAnimationEle = 0; 
       
  1505             lCurAnimationEle < lAnimationEleCnt; lCurAnimationEle++ )
       
  1506         {
       
  1507         CSvgMediaAnimationElementImpl* lAnimationElement = 
       
  1508             (CSvgMediaAnimationElementImpl* )lAnimationEleList[ lCurAnimationEle ];
       
  1509         CSvgDocumentImpl* lChildDoc = lAnimationElement->GetChildDocument();
       
  1510         if ( lChildDoc )
       
  1511             {
       
  1512             lChildDoc->CancelParsing(); // Cancel parsing on child svg
       
  1513             }
       
  1514         }
       
  1515     lAnimationEleList.Close();    
       
  1516     if ( iXmlHandler )
       
  1517         {
       
  1518         iXmlHandler->CancelParsing();
       
  1519         }
       
  1520     }
       
  1521 
       
  1522 // ==========================================================================
       
  1523 TBool CSvgDocumentImpl::IsParsing()
       
  1524     {
       
  1525     // xml handler is set to NULL after parsing
       
  1526     return iXmlHandler != NULL;
       
  1527     }
       
  1528 
       
  1529 //***************************************************************************
       
  1530 // The function isGroupOpacity checks to see if there is a valid opacity
       
  1531 // attribute.
       
  1532 //***************************************************************************
       
  1533 
       
  1534 TBool CSvgDocumentImpl::isGroupOpacity( CSvgElementImpl* aElement )
       
  1535 {
       
  1536 	TBool lReturnValue = EFalse;
       
  1537     CCssValue*  lCssValue = NULL;
       
  1538 
       
  1539     aElement->FindProperty( KCSS_ATTR_GROUP_OPACITY, lCssValue, aElement );
       
  1540     if ( lCssValue )
       
  1541        {
       
  1542         if ( ((CFloatCssValueImpl*)lCssValue)->Value() != KFloatFixOne )
       
  1543            {
       
  1544            // valid opacity value
       
  1545             lReturnValue = ETrue;
       
  1546             }
       
  1547         }
       
  1548 
       
  1549     return lReturnValue;
       
  1550 }
       
  1551 
       
  1552 
       
  1553 // ==========================================================================
       
  1554 // Pre-condition: content is DRM
       
  1555 // The content of a DRM may be svg-text or svg-bin
       
  1556 // Leaves only for memory allocation failure
       
  1557 // ==========================================================================
       
  1558 HBufC8* CSvgDocumentImpl::ProcessDRMContentL( RFile& aFileHandle, CSvgErrorImpl& aError )
       
  1559 {
       
  1560     // Open File Content and Data
       
  1561     ContentAccess::CContent* content = ContentAccess::CContent::NewLC( 
       
  1562             aFileHandle );
       
  1563     // Note: very important to use EView and NOT EPlay
       
  1564     ContentAccess::CData* data = content->OpenContentLC( ContentAccess::EView );
       
  1565 
       
  1566     // Read Length of Content
       
  1567     TInt length = 0;
       
  1568     TRAPD( sizeError, data->DataSizeL( length ) );
       
  1569     // Cannot get length of data
       
  1570     if ( sizeError != KErrNone )
       
  1571     {
       
  1572         ProcessDRMError( sizeError, aError );
       
  1573         CleanupStack::PopAndDestroy( 2 );
       
  1574         return NULL;
       
  1575     }
       
  1576 
       
  1577     // Allocate Memory for Content: no leavable command after this
       
  1578     // so, pushing onto cleanup stack not needed
       
  1579     HBufC8* buffer = HBufC8::NewL( length );
       
  1580 
       
  1581     TPtr8 des = buffer->Des();
       
  1582     TInt readError = data->Read( des );
       
  1583 
       
  1584     // Check for read error
       
  1585     if ( readError != KErrNone )
       
  1586     {
       
  1587         ProcessDRMError( readError, aError );
       
  1588         CleanupStack::PopAndDestroy( 2 );
       
  1589         delete buffer;
       
  1590         return NULL;
       
  1591     }
       
  1592     // Only consume rights when not in thumb nail mode
       
  1593     else if ( !iIsThumbNailMode )
       
  1594     {
       
  1595         // Do not consume drm rights if iDrmRightsConsumptionEnabled is EFalse
       
  1596         if(iDrmRightsConsumptionEnabled)
       
  1597         {
       
  1598         TInt intentError = data->ExecuteIntent( ContentAccess::EView );
       
  1599         if ( intentError != KErrNone )
       
  1600         {
       
  1601             ProcessDRMError( readError, aError );
       
  1602             aError.SetIsWarning( ETrue );
       
  1603             }
       
  1604         }
       
  1605     }
       
  1606     CleanupStack::PopAndDestroy( 2 );
       
  1607     return buffer;
       
  1608 }
       
  1609 
       
  1610 // ==========================================================================
       
  1611 // Un-gzip to a temp file and return the name of temp file
       
  1612 // ==========================================================================
       
  1613 TBool CSvgDocumentImpl::ProcessGZipContent( RFs& aSession,
       
  1614                                             RFile& aGZipFileHandle,
       
  1615                                             TFileName& aUnzippedFileName ,
       
  1616                                             CSvgErrorImpl& aError )
       
  1617 {
       
  1618     // Write data to temp file: gzip does not have function to read RFile
       
  1619     TFileName gzipFilename;
       
  1620     if ( WriteToTempFile( aSession, aGZipFileHandle, gzipFilename, aError ) != KErrNone )
       
  1621         return EFalse;
       
  1622 
       
  1623     TBool result = ProcessGZipContent( aSession, gzipFilename, aUnzippedFileName, aError );
       
  1624 
       
  1625     // Delete temp gzipped file
       
  1626     aSession.Delete( gzipFilename );
       
  1627 
       
  1628     return result;
       
  1629 }
       
  1630 
       
  1631 // ==========================================================================
       
  1632 // Uncompress to a temporary file
       
  1633 // ==========================================================================
       
  1634 TBool CSvgDocumentImpl::ProcessGZipContent( RFs& aSession,
       
  1635                                             TFileName& aZippedFileName,
       
  1636                                             TFileName& aUnzippedFileName ,
       
  1637                                             CSvgErrorImpl& aError )
       
  1638 {
       
  1639     // Create ungzipped temp file
       
  1640     TFileName path;
       
  1641     GetProcessPrivatePath( aSession, path );
       
  1642     RFile gzipOutputFile;
       
  1643     TInt replaceError = gzipOutputFile.Temp( aSession, path, aUnzippedFileName, EFileWrite );
       
  1644     if ( replaceError != KErrNone )
       
  1645     {
       
  1646         // couldn't open temp file for writing
       
  1647         PrepareError( aError, ESvgUnknown, replaceError,
       
  1648                       _L( "Failed to create file or unGZip: " ), aUnzippedFileName );
       
  1649         return EFalse;
       
  1650     }
       
  1651 
       
  1652     // okay so far, uncompressing
       
  1653     CEZGZipToFile* uncompressor = NULL;
       
  1654     TRAPD( uncompressorError,
       
  1655            uncompressor = CEZGZipToFile::NewL( aSession, aZippedFileName, gzipOutputFile ) )
       
  1656     if ( uncompressorError != KErrNone )
       
  1657     {
       
  1658         PrepareError( aError, ESvgUnknown, uncompressorError,
       
  1659                       _L( "Out of memory: " ),
       
  1660                       _L( "Instantiating GZip decompressor" ) );
       
  1661         gzipOutputFile.Close();
       
  1662         aSession.Delete( aUnzippedFileName );
       
  1663 
       
  1664         return EFalse;
       
  1665     }
       
  1666 
       
  1667     // Decompress file
       
  1668     TBool done = EFalse;
       
  1669     while ( !done )
       
  1670     {
       
  1671         TRAPD( inflateError, done = !uncompressor->InflateL() );
       
  1672         if ( inflateError != KErrNone )
       
  1673         {
       
  1674             PrepareError( aError, ESvgUnknown, inflateError,
       
  1675                           _L( "Uncompressing GZip file failed." ), _L( "" ) );
       
  1676             delete uncompressor;
       
  1677             gzipOutputFile.Close();
       
  1678             aSession.Delete( aUnzippedFileName );
       
  1679 
       
  1680             return EFalse;
       
  1681         }
       
  1682     }
       
  1683 
       
  1684     gzipOutputFile.Close();
       
  1685     delete uncompressor;
       
  1686 
       
  1687     return ETrue;
       
  1688 }
       
  1689 
       
  1690 // ==========================================================================
       
  1691 // Error codes taken from caf/content.h
       
  1692 // ==========================================================================
       
  1693 void CSvgDocumentImpl::ProcessDRMError( TInt errorCode, CSvgErrorImpl& aError )
       
  1694 {
       
  1695     if ( errorCode == KErrNone )
       
  1696         return;
       
  1697 
       
  1698     if ( errorCode == KErrNotFound )
       
  1699     {
       
  1700         aError.SetDescription( _L( "Content Not Found" ) );
       
  1701     }
       
  1702     else if ( errorCode == KErrCAPendingRights )
       
  1703     {
       
  1704         aError.SetDescription( _L( "Rights Have Not Arrived" ) );
       
  1705     }
       
  1706     else if ( errorCode == KErrCANoPermission )
       
  1707     {
       
  1708         aError.SetDescription( _L( "No Permission to Play Content" ) );
       
  1709     }
       
  1710     else if ( errorCode == KErrCANoRights )
       
  1711     {
       
  1712         aError.SetDescription( _L( "No Rights Exists for Content" ) );
       
  1713     }
       
  1714     else if ( errorCode == KErrCANotSupported )
       
  1715     {
       
  1716         aError.SetDescription( _L( "Unable to Open Content" ) );
       
  1717     }
       
  1718     else if ( errorCode == KErrPermissionDenied )
       
  1719     {
       
  1720         aError.SetDescription( _L( "No Permission to Open Content" ) );
       
  1721     }
       
  1722     else if ( errorCode == KErrAccessDenied )
       
  1723     {
       
  1724         aError.SetDescription( _L( "Content Already in Use or No DRM Capability" ) );
       
  1725     }
       
  1726     else if ( errorCode == KErrCASizeNotDetermined )
       
  1727     {
       
  1728         aError.SetDescription( _L( "Cannot Determine Size of Content" ) );
       
  1729     }
       
  1730     else
       
  1731     {
       
  1732         aError.SetDescription( _L( "Unknown DRM Error" ) );
       
  1733     }
       
  1734     aError.SetIsWarning( EFalse );
       
  1735     aError.SetErrorCode( ESvgDRMFailure );
       
  1736     aError.SetSystemErrorCode( errorCode );
       
  1737 }
       
  1738 
       
  1739 // ==========================================================================
       
  1740 // Returns true if the first two bytes of the given file could be a gzip file.
       
  1741 // This function is modified from the function in EZGZipFile class.
       
  1742 // ==========================================================================
       
  1743 TBool CSvgDocumentImpl::IsGzipContent( RFile& aFileHandle )
       
  1744 {
       
  1745     TUint8 ids[2];
       
  1746     TPtr8 des( ids, 0, sizeof( TUint8 ) * 2 );
       
  1747 
       
  1748     if ( aFileHandle.Read( des ) != KErrNone )
       
  1749         return EFalse;
       
  1750 
       
  1751     // reset to start of file
       
  1752     TInt zero = 0;
       
  1753     aFileHandle.Seek( ESeekStart, zero );
       
  1754     return ( ids[0] == 31 && ids[1] == 139 );
       
  1755 //    return ( ids[0] == EZGZipFile::ID1 && ids[1] == EZGZipFile::ID2 );
       
  1756 }
       
  1757 
       
  1758 // ==========================================================================
       
  1759 // Returns whether the byte-array header matches a GZIP signature
       
  1760 // ==========================================================================
       
  1761 TBool CSvgDocumentImpl::IsGzipContent( const TDesC8& aByteArray )
       
  1762 {
       
  1763     return aByteArray.Length() >= 2 &&
       
  1764            aByteArray[0] == 31 && aByteArray[1] == 139;
       
  1765 //           aByteArray[0] == EZGZipFile::ID1 && aByteArray[1] == EZGZipFile::ID2;
       
  1766 }
       
  1767 
       
  1768 // ==========================================================================
       
  1769 // Returns whether the byte-array header matches a SVG binary signature
       
  1770 // ==========================================================================
       
  1771 TBool CSvgDocumentImpl::IsBinarySvg( const TDesC8& aByteArray )
       
  1772 {
       
  1773 	//const TUint32 KBinaryFile          = 66737868;
       
  1774 	//const TUint32 KBinaryFile2         = 66737869;
       
  1775 
       
  1776 	if ((aByteArray.Length() >= 4 &&
       
  1777            aByteArray[0] == 0xCC && aByteArray[1] == 0x56 &&
       
  1778            aByteArray[2] == 0xFA && aByteArray[3] == 0x03) ||
       
  1779         (aByteArray.Length() >= 4 &&
       
  1780            aByteArray[0] == 0xCD && aByteArray[1] == 0x56 &&
       
  1781            aByteArray[2] == 0xFA && aByteArray[3] == 0x03) ||
       
  1782         (aByteArray.Length() >= 4 &&
       
  1783            aByteArray[0] == 0xCE && aByteArray[1] == 0x56 &&
       
  1784            aByteArray[2] == 0xFA && aByteArray[3] == 0x03) ||
       
  1785         (aByteArray.Length() >= 4 &&
       
  1786            aByteArray[0] == 0xCF && aByteArray[1] == 0x56 &&
       
  1787            aByteArray[2] == 0xFA && aByteArray[3] == 0x03) )
       
  1788 	{
       
  1789 		return ETrue;
       
  1790 	}
       
  1791     else
       
  1792     {
       
  1793     	return EFalse;
       
  1794     }
       
  1795 }
       
  1796 
       
  1797 // ==========================================================================
       
  1798 // Returns whether the file header matches a DRM signature
       
  1799 // ==========================================================================
       
  1800 TBool CSvgDocumentImpl::IsDRMContent( RFile& aFileHandle )
       
  1801 {
       
  1802     TUint8 ids[2];
       
  1803     TPtr8 des( ids, 0, sizeof( TUint8 ) * 2 );
       
  1804 
       
  1805     if ( aFileHandle.Read( des ) != KErrNone )
       
  1806         return EFalse;
       
  1807 
       
  1808     // reset to start of file
       
  1809     TInt zero = 0;
       
  1810     aFileHandle.Seek( ESeekStart, zero );
       
  1811     return ( ids[0] == 0x01 && ids[1] == 0x0D );
       
  1812 }
       
  1813 
       
  1814 // ==========================================================================
       
  1815 // Returns whether the file header matches a DRM signature
       
  1816 // ==========================================================================
       
  1817 TBool CSvgDocumentImpl::IsDRMContent( const TDesC8& aByteArray )
       
  1818 {
       
  1819     return ( aByteArray.Length() > 1 && aByteArray[0] == 0x01 && aByteArray[1] == 0x0D );
       
  1820 }
       
  1821 
       
  1822 // ==========================================================================
       
  1823 // Generate the "c:/private/<sid>" directory name
       
  1824 // ==========================================================================
       
  1825 TInt CSvgDocumentImpl::GetProcessPrivatePath( RFs& aSession, TFileName& aPath )
       
  1826 {
       
  1827     aSession.PrivatePath( aPath );
       
  1828     aPath.Insert( 0, _L( "c:" ) );
       
  1829     return KErrNone;
       
  1830 }
       
  1831 
       
  1832 // ==========================================================================
       
  1833 // Create "c:/private/<sid>" directory if it does not already exist
       
  1834 // ==========================================================================
       
  1835 TInt CSvgDocumentImpl::CreateProcessPrivateDirectory( RFs& aSession, TFileName& aPath )
       
  1836 {
       
  1837     GetProcessPrivatePath( aSession, aPath );
       
  1838     return ( !BaflUtils::FolderExists( aSession, aPath ) ) ? aSession.MkDir( aPath ) : KErrNone;
       
  1839 }
       
  1840 
       
  1841 // ==========================================================================
       
  1842 // Open a file session, error is indicated in aError
       
  1843 // ==========================================================================
       
  1844 void CSvgDocumentImpl::OpenSession( RFs& aSession, CSvgErrorImpl& aError )
       
  1845 {
       
  1846     TInt error = aSession.Connect();
       
  1847     if ( error != KErrNone )
       
  1848     {
       
  1849         // couldn't open temp file for writing
       
  1850         PrepareError( aError, ESvgUnknown, error,
       
  1851                       _L( "Connecting File Session Failed." ), _L( "" ) );
       
  1852     }
       
  1853 }
       
  1854 
       
  1855 // ==========================================================================
       
  1856 // Session must be opened successfully
       
  1857 // File name of temp file is store in aFilename
       
  1858 // ==========================================================================
       
  1859 TInt CSvgDocumentImpl::WriteToTempFile( RFs& aSession, const TDesC8& aByteArray,
       
  1860                                         TFileName& aFilename, CSvgErrorImpl& aError )
       
  1861 {
       
  1862     // Create temporary file for byte-array
       
  1863     TFileName path;
       
  1864     CreateProcessPrivateDirectory( aSession, path );
       
  1865     RFile writeFile;
       
  1866     TInt tempError = writeFile.Temp( aSession, path, aFilename, EFileWrite );
       
  1867     if ( tempError != KErrNone )
       
  1868     {
       
  1869         PrepareError( aError, ESvgUnknown, tempError,
       
  1870                       _L( "Failed open temp file to write data." ), aFilename );
       
  1871         return tempError;
       
  1872     }
       
  1873 
       
  1874     // Write byte-array to file
       
  1875     TInt writeError = writeFile.Write( aByteArray );
       
  1876     if ( writeError != KErrNone )
       
  1877     {
       
  1878         PrepareError( aError, ESvgUnknown, writeError,
       
  1879                       _L( "Failed to write data to temp file." ), aFilename );
       
  1880         writeFile.Close();
       
  1881         aSession.Delete( aFilename );
       
  1882         return writeError;
       
  1883     }
       
  1884     writeFile.Flush();
       
  1885     writeFile.Close();
       
  1886 
       
  1887     return KErrNone;
       
  1888 }
       
  1889 
       
  1890 // ==========================================================================
       
  1891 // Session must be opened successfully
       
  1892 // File name of temp file is store in aFilename
       
  1893 // ==========================================================================
       
  1894 TInt CSvgDocumentImpl::WriteToTempFile( RFs& aSession, RFile& aFileHandle,
       
  1895                                         TFileName& aFilename, CSvgErrorImpl& aError )
       
  1896 {
       
  1897     // Create temporary file for byte-array
       
  1898     TFileName path;
       
  1899     CreateProcessPrivateDirectory( aSession, path );
       
  1900     RFile writeFile;
       
  1901     TInt tempError = writeFile.Temp( aSession, path, aFilename, EFileWrite );
       
  1902     if ( tempError != KErrNone )
       
  1903     {
       
  1904         PrepareError( aError, ESvgUnknown, tempError,
       
  1905                       _L( "Failed open temp file to write data." ), path );
       
  1906         return tempError;
       
  1907     }
       
  1908 
       
  1909     // Write data to temp file
       
  1910     TInt size;
       
  1911     TInt sizeError = aFileHandle.Size( size );
       
  1912     if ( sizeError != KErrNone )
       
  1913     {
       
  1914         PrepareError( aError, ESvgUnknown, sizeError,
       
  1915                       _L( "Failed to get data length of file." ), aFilename );
       
  1916         aSession.Delete( aFilename );
       
  1917         return sizeError;
       
  1918     }
       
  1919 
       
  1920     TBuf8<1024> buffer;
       
  1921     TInt bytesCopied = 0;
       
  1922     while ( bytesCopied < size )
       
  1923     {
       
  1924         buffer.Zero();
       
  1925         TInt bytesToCopy = ( size - bytesCopied < 1024 ) ? size - bytesCopied : 1024;
       
  1926         // read data
       
  1927         TInt readError = aFileHandle.Read( buffer, bytesToCopy );
       
  1928         if ( readError != KErrNone )
       
  1929         {
       
  1930             PrepareError( aError, ESvgUnknown, readError,
       
  1931                           _L( "Failed to read data to copy to temp file: " ), aFilename );
       
  1932             writeFile.Close();
       
  1933             aSession.Delete( aFilename );
       
  1934             return readError;
       
  1935         }
       
  1936         // write data
       
  1937         TInt writeError = writeFile.Write( buffer, bytesToCopy );
       
  1938         if ( writeError != KErrNone )
       
  1939         {
       
  1940             PrepareError( aError, ESvgUnknown, writeError,
       
  1941                           _L( "Failed to write to temp file: " ), aFilename );
       
  1942             writeFile.Close();
       
  1943             aSession.Delete( aFilename );
       
  1944             return writeError;
       
  1945         }
       
  1946         bytesCopied += bytesToCopy;
       
  1947     }
       
  1948 
       
  1949     writeFile.Flush();
       
  1950     writeFile.Close();
       
  1951 
       
  1952     return KErrNone;
       
  1953 }
       
  1954 
       
  1955 // ==========================================================================
       
  1956 // Need method description
       
  1957 // ==========================================================================
       
  1958 void CSvgDocumentImpl::PrepareError( CSvgErrorImpl& aError,
       
  1959                                      TSvgErrorCode aSvgErrorCode,
       
  1960                                      TInt aSystemErrorCode,
       
  1961                                      const TDesC& aMsg1,
       
  1962                                      const TDesC& aMsg2 )
       
  1963 {
       
  1964     aError.SetDescription( aMsg1, aMsg2 );
       
  1965     aError.SetErrorCode( aSvgErrorCode );
       
  1966     aError.SetSystemErrorCode( aSystemErrorCode );
       
  1967     aError.SetIsWarning( EFalse );
       
  1968 }
       
  1969 
       
  1970 // ==========================================================================
       
  1971 // Need method description
       
  1972 // ==========================================================================
       
  1973 void CSvgDocumentImpl::LoadingCompleted()
       
  1974 {
       
  1975     if ( iEngine != NULL && iEngine->GraphicsContext() != NULL )
       
  1976     {
       
  1977         iEngine->GraphicsContext()->SetDoDithering( iHasGradientElement );
       
  1978     }
       
  1979 }
       
  1980 
       
  1981 // ==========================================================================
       
  1982 // Need method description
       
  1983 // ==========================================================================
       
  1984 void CSvgDocumentImpl::SetThumbNailMode( TBool aThumbNailMode )
       
  1985 {
       
  1986     iIsThumbNailMode = aThumbNailMode;
       
  1987 }
       
  1988 
       
  1989 //==========================================================================
       
  1990 // CSvgDocumentImpl::SetDRMRights( TBool aEnable )
       
  1991 //==========================================================================
       
  1992 void CSvgDocumentImpl::SetDRMRights( TBool aEnable)
       
  1993 {
       
  1994 	iDrmRightsConsumptionEnabled = aEnable;
       
  1995 }
       
  1996 // ==========================================================================
       
  1997 // Need method description
       
  1998 // ==========================================================================
       
  1999 TBool CSvgDocumentImpl::IsThumbNailOnly()
       
  2000 {
       
  2001     return iIsThumbNailMode && iIsDRMProtected;
       
  2002 }
       
  2003 
       
  2004 // ==========================================================================
       
  2005 // Need method description
       
  2006 // ==========================================================================
       
  2007 void CSvgDocumentImpl::SetWasPrepared( TBool aBool )
       
  2008 {
       
  2009     iWasPrepared = aBool;
       
  2010 
       
  2011 }
       
  2012 
       
  2013 // ==========================================================================
       
  2014 // Need method description
       
  2015 // ==========================================================================
       
  2016 TBool CSvgDocumentImpl::WasPrepared()
       
  2017 {
       
  2018     return iWasPrepared;
       
  2019 }
       
  2020 
       
  2021 // ==========================================================================
       
  2022 // Need method description
       
  2023 // ==========================================================================
       
  2024 void CSvgDocumentImpl::SetLoadingListeners( const RPointerArray<MSvgLoadingListener>* aList )
       
  2025     {
       
  2026     iLoadingListeners = aList;
       
  2027     }
       
  2028 
       
  2029 // ==========================================================================
       
  2030 // Need method description
       
  2031 // ==========================================================================
       
  2032 const RPointerArray<MSvgLoadingListener>* CSvgDocumentImpl::GetLoadingListeners()
       
  2033     {
       
  2034     return iLoadingListeners;
       
  2035     }
       
  2036 
       
  2037 /*---------------------------MouseListener---------------------------*/
       
  2038 
       
  2039 // ==========================================================================
       
  2040 // Need method description
       
  2041 // ==========================================================================
       
  2042 void CSvgDocumentImpl::AddInternalMouseListener( const MSvgMouseListener* aListener )
       
  2043     {
       
  2044     TInt index = iSvgMouseListeners.Find( aListener );
       
  2045     if ( aListener != NULL && index == KErrNotFound )
       
  2046         {
       
  2047         iSvgMouseListeners.Append( aListener );
       
  2048         }
       
  2049     }
       
  2050 
       
  2051 // ==========================================================================
       
  2052 // Need method description
       
  2053 // ==========================================================================
       
  2054 void CSvgDocumentImpl::RemoveInternalMouseListener( const MSvgMouseListener* aListener )
       
  2055     {
       
  2056     TInt index = iSvgMouseListeners.Find( aListener );
       
  2057     if ( index != KErrNotFound )
       
  2058         {
       
  2059         iSvgMouseListeners.Remove( index );
       
  2060         }
       
  2061     }
       
  2062 
       
  2063 // ==========================================================================
       
  2064 // Need method description
       
  2065 // ==========================================================================
       
  2066 TInt CSvgDocumentImpl::MouseInternalListenerCount()
       
  2067     {
       
  2068     return iSvgMouseListeners.Count();
       
  2069     }
       
  2070 
       
  2071 // ==========================================================================
       
  2072 // Need method description
       
  2073 // ==========================================================================
       
  2074 void CSvgDocumentImpl::NotifyInternalMousePressed( RPointerArray<CSvgElementImpl>& aElements,
       
  2075                                           TInt aX, TInt aY )
       
  2076     {
       
  2077 
       
  2078     for ( TInt i = 0; i < iSvgMouseListeners.Count(); i++ )
       
  2079         {
       
  2080         iSvgMouseListeners[i]->MousePressed( aElements, aX, aY );
       
  2081         }
       
  2082     }
       
  2083 
       
  2084 // ==========================================================================
       
  2085 // Need method description
       
  2086 // ==========================================================================
       
  2087 void CSvgDocumentImpl::NotifyInternalMouseReleased( RPointerArray<CSvgElementImpl>& aElements,
       
  2088                                           TInt aX, TInt aY )
       
  2089     {
       
  2090 
       
  2091     for ( TInt i = 0; i < iSvgMouseListeners.Count(); i++ )
       
  2092         {
       
  2093         iSvgMouseListeners[i]->MouseReleased( aElements, aX, aY );
       
  2094         }
       
  2095     }
       
  2096 
       
  2097 // ==========================================================================
       
  2098 // Need method description
       
  2099 // ==========================================================================
       
  2100 void CSvgDocumentImpl::NotifyInternalMouseEntered( RPointerArray<CSvgElementImpl>& aElements,
       
  2101                                           TInt aX, TInt aY )
       
  2102     {
       
  2103 
       
  2104     for ( TInt i = 0; i < iSvgMouseListeners.Count(); i++ )
       
  2105         {
       
  2106         iSvgMouseListeners[i]->MouseEntered( aElements, aX, aY );
       
  2107         }
       
  2108     }
       
  2109 
       
  2110 // ==========================================================================
       
  2111 // Need method description
       
  2112 // ==========================================================================
       
  2113 void CSvgDocumentImpl::NotifyInternalMouseExited( RPointerArray<CSvgElementImpl>& aElements,
       
  2114                                           TInt aX, TInt aY )
       
  2115     {
       
  2116 
       
  2117     for ( TInt i = 0; i < iSvgMouseListeners.Count(); i++ )
       
  2118         {
       
  2119         iSvgMouseListeners[i]->MouseExited( aElements, aX, aY );
       
  2120         }
       
  2121     }
       
  2122 
       
  2123 // ==========================================================================
       
  2124 // Need method description
       
  2125 // ==========================================================================
       
  2126 void CSvgDocumentImpl::NotifyInternalMouseMoved( RPointerArray<CSvgElementImpl>& aElements,
       
  2127                                           TInt aX, TInt aY )
       
  2128     {
       
  2129 
       
  2130     for ( TInt i = 0; i < iSvgMouseListeners.Count(); i++ )
       
  2131         {
       
  2132         iSvgMouseListeners[i]->MouseMoved( aElements, aX, aY );
       
  2133         }
       
  2134     }
       
  2135 
       
  2136 // ==========================================================================
       
  2137 // Need method description
       
  2138 // ==========================================================================
       
  2139 void CSvgDocumentImpl::NotifyDocumentStart()
       
  2140     {
       
  2141     if ( iLoadingListeners != NULL )
       
  2142         {
       
  2143         TInt loadingListenersCnt = iLoadingListeners->Count();
       
  2144         for ( TInt i = 0; i < loadingListenersCnt; i++ )
       
  2145             {
       
  2146             (*iLoadingListeners)[i]->DocumentStart();
       
  2147             }
       
  2148         }
       
  2149     }
       
  2150 
       
  2151 // ==========================================================================
       
  2152 // Need method description
       
  2153 // ==========================================================================
       
  2154 void CSvgDocumentImpl::NotifyDocumentEnd()
       
  2155     {
       
  2156     if ( iLoadingListeners != NULL )
       
  2157         {
       
  2158         TInt loadingListenersCnt = iLoadingListeners->Count();
       
  2159         for ( TInt i = 0; i < loadingListenersCnt; i++ )
       
  2160             {
       
  2161             (*iLoadingListeners)[i]->DocumentEnd();
       
  2162             }
       
  2163         }
       
  2164     }
       
  2165 
       
  2166 // ==========================================================================
       
  2167 // Need method description
       
  2168 // ==========================================================================
       
  2169 void CSvgDocumentImpl::NotifyElementStart( const TDesC& aTagName,
       
  2170                                            MSvgAttributeList& aAttributeList,
       
  2171                                            TBool aIsSvgChild )
       
  2172     {
       
  2173     // Do not send back attribute list if content was decrypted
       
  2174     // from DRM protected content.
       
  2175     if ( iLoadingListeners != NULL && !iIsDRMProtected )
       
  2176         {
       
  2177         TInt loadingListenersCnt = iLoadingListeners->Count();
       
  2178         for ( TInt i = 0; i < loadingListenersCnt; i++ )
       
  2179             {
       
  2180             if ( aIsSvgChild || (*iLoadingListeners)[i]->ReportAllElements() )
       
  2181                 {
       
  2182                 (*iLoadingListeners)[i]->ElementStart( aTagName, aAttributeList );
       
  2183                 }
       
  2184             }
       
  2185         }
       
  2186     }
       
  2187 
       
  2188 // ==========================================================================
       
  2189 // Need method description
       
  2190 // ==========================================================================
       
  2191 void CSvgDocumentImpl::NotifyElementEnd( const TDesC& aTagName, TBool aIsSvgChild )
       
  2192     {
       
  2193     if ( iLoadingListeners != NULL )
       
  2194         {
       
  2195         TInt loadingListenersCnt = iLoadingListeners->Count();
       
  2196         for ( TInt i = 0; i < loadingListenersCnt; i++ )
       
  2197             {
       
  2198             if ( aIsSvgChild || (*iLoadingListeners)[i]->ReportAllElements() )
       
  2199                 {
       
  2200                 (*iLoadingListeners)[i]->ElementEnd( aTagName );
       
  2201                 }
       
  2202             }
       
  2203         }
       
  2204     }
       
  2205 
       
  2206 // ==========================================================================
       
  2207 // Need method description
       
  2208 // ==========================================================================
       
  2209 void CSvgDocumentImpl::NotifyUnsupportedElement( const TDesC& aTagName,
       
  2210                                                  MSvgAttributeList& aAttributeList )
       
  2211     {
       
  2212     if ( iLoadingListeners != NULL )
       
  2213         {
       
  2214         TInt loadingListenersCnt = iLoadingListeners->Count();
       
  2215         for ( TInt i = 0; i < loadingListenersCnt; i++ )
       
  2216             {
       
  2217             (*iLoadingListeners)[i]->UnsupportedElement( aTagName, aAttributeList );
       
  2218             }
       
  2219         }
       
  2220     }
       
  2221 
       
  2222 // ==========================================================================
       
  2223 // Need method description
       
  2224 // ==========================================================================
       
  2225 void CSvgDocumentImpl::NotifyExternalDataRequested( const TDesC& aUri )
       
  2226     {
       
  2227     if ( iLoadingListeners != NULL )
       
  2228         {
       
  2229         TInt loadingListenersCnt = iLoadingListeners->Count();
       
  2230         for ( TInt i = 0; i < loadingListenersCnt; i++ )
       
  2231             {
       
  2232             (*iLoadingListeners)[i]->ExternalDataRequested( aUri );
       
  2233             }
       
  2234         }
       
  2235     }
       
  2236 
       
  2237 // ==========================================================================
       
  2238 // Need method description
       
  2239 // ==========================================================================
       
  2240 void CSvgDocumentImpl::NotifyExternalDataReceived( const TDesC& aUri )
       
  2241     {
       
  2242     if ( iLoadingListeners != NULL )
       
  2243         {
       
  2244         TInt loadingListenersCnt = iLoadingListeners->Count();
       
  2245         for ( TInt i = 0; i < loadingListenersCnt; i++ )
       
  2246             {
       
  2247             (*iLoadingListeners)[i]->ExternalDataReceived( aUri );
       
  2248             }
       
  2249         }
       
  2250     }
       
  2251 
       
  2252 // ==========================================================================
       
  2253 // Need method description
       
  2254 // ==========================================================================
       
  2255 void CSvgDocumentImpl::NotifyExternalDataRequestFailed( const TDesC& aUri )
       
  2256     {
       
  2257     if ( iLoadingListeners != NULL )
       
  2258         {
       
  2259         TInt loadingListenersCnt = iLoadingListeners->Count();
       
  2260         for ( TInt i = 0; i < loadingListenersCnt; i++ )
       
  2261             {
       
  2262             (*iLoadingListeners)[i]->ExternalDataRequestFailed( aUri );
       
  2263             }
       
  2264         }
       
  2265     }
       
  2266 
       
  2267 // ==========================================================================
       
  2268 // Need method description
       
  2269 // ==========================================================================
       
  2270 TUint32 CSvgDocumentImpl::IsIndefiniteAnimation()
       
  2271     {
       
  2272     if ( !iCheckedAnimationDuration )
       
  2273         {
       
  2274         AnimationDuration();
       
  2275         }
       
  2276     // special value for indefinite animation
       
  2277     return ( iAnimationDuration == KIndefiniteAnimationDuration );
       
  2278     }
       
  2279 
       
  2280 // ==========================================================================
       
  2281 // Need method description
       
  2282 // ==========================================================================
       
  2283 TUint32 CSvgDocumentImpl::AnimationDuration()
       
  2284     {
       
  2285     if ( iCheckedAnimationDuration )
       
  2286         {
       
  2287         return IsIndefiniteAnimation() ? 0xFFFFFFFF : iAnimationDuration;
       
  2288         }
       
  2289     else if ( iRootElement == NULL )
       
  2290         {
       
  2291         return 0;
       
  2292         }
       
  2293 
       
  2294     if ( iIsInteractive )
       
  2295         {
       
  2296         // If there is interactivity in the content, set the animation
       
  2297         // duration to indefinite so that the timer continues to run.
       
  2298         iAnimationDuration = KIndefiniteAnimationDuration;
       
  2299         }
       
  2300     else
       
  2301         {
       
  2302         iAnimationDuration = SubtreeDuration( iRootElement );
       
  2303         }
       
  2304 
       
  2305     iCheckedAnimationDuration = ETrue;
       
  2306     return IsIndefiniteAnimation() ? 0xFFFFFFFF : iAnimationDuration;
       
  2307     }
       
  2308 
       
  2309 // ==========================================================================
       
  2310 // Return the longest animation in subtree
       
  2311 // ==========================================================================
       
  2312 TUint32 CSvgDocumentImpl::SubtreeDuration( CSvgElementImpl* aRootElement )
       
  2313     {
       
  2314     TUint dur = 0;
       
  2315 		
       
  2316     if ( aRootElement->IsAnimatedElement() )
       
  2317         {
       
  2318         dur = ( ( CSvgAnimationBase * ) aRootElement )->CompleteDuration();
       
  2319         }
       
  2320 
       
  2321 	else if ( aRootElement->ElemID() == KSvgDiscardElement )
       
  2322 		{
       
  2323 			dur = ((CSvgDiscardElementImpl*)aRootElement)->AbsoluteBeginTime();
       
  2324 		}
       
  2325 		
       
  2326     // check child duration
       
  2327     TUint childDur;
       
  2328     CSvgElementImpl* child = (CSvgElementImpl*)aRootElement->FirstChild();
       
  2329     while ( child != NULL )
       
  2330         {
       
  2331         childDur = SubtreeDuration( child );
       
  2332         if ( childDur > dur )
       
  2333             {
       
  2334             dur = childDur;
       
  2335             }
       
  2336         child = (CSvgElementImpl*)child->NextSibling();
       
  2337         }
       
  2338     return dur;
       
  2339     }
       
  2340 
       
  2341 // ==========================================================================
       
  2342 // notified from outside (AppendChild/RemoveChild)
       
  2343 // ==========================================================================
       
  2344 void CSvgDocumentImpl::ElementAppendedOrRemoved()
       
  2345     {
       
  2346     // Clear flag to retrieve animation duration on AnimationDuration() call
       
  2347     iCheckedAnimationDuration = EFalse;
       
  2348     }
       
  2349 
       
  2350 // ==========================================================================
       
  2351 // Return all elements of the given type
       
  2352 // or all of the elements if the type = -1
       
  2353 // ==========================================================================
       
  2354 void CSvgDocumentImpl::FindAllElements( CSvgElementImpl* aStartElement, TInt aElementId,
       
  2355                                       RPointerArray<CSvgElementImpl>& aList,
       
  2356                                       TSvgSearchFlags aFlags )
       
  2357     {
       
  2358     if ( aStartElement == NULL )
       
  2359         return;
       
  2360 
       
  2361     CSvgElementImpl* child = (CSvgElementImpl*)aStartElement->FirstChild();
       
  2362     while ( child != NULL )
       
  2363         {
       
  2364         // add to list if child is found
       
  2365         if ( child->ElemID() == aElementId || aElementId == -1 )
       
  2366             aList.Append( child );
       
  2367 
       
  2368         // find in grandchildren
       
  2369         if ( aFlags & ESvgSearchExcludeUseSubtree )
       
  2370             {
       
  2371             // If Exclude Use Subtree, ignore the subtree under use element
       
  2372             if ( child->ElemID() != KSvgUseElement )
       
  2373                 {
       
  2374                 FindAllElements( child, aElementId, aList, aFlags );
       
  2375                 }
       
  2376             }
       
  2377         else
       
  2378             {
       
  2379             FindAllElements( child, aElementId, aList, aFlags );
       
  2380             }
       
  2381         child = (CSvgElementImpl*)child->NextSibling();
       
  2382         }
       
  2383     }
       
  2384 
       
  2385 // ==========================================================================
       
  2386 // ImageLoadingObserver interface method
       
  2387 // ==========================================================================
       
  2388 void CSvgDocumentImpl::ImageLoadingCompleted( TInt aError )
       
  2389     {
       
  2390     iImageElementCnt--;
       
  2391     
       
  2392     if ( iLoadingListeners != NULL && iImageElementCnt == 0)
       
  2393         {
       
  2394         TInt loadingListenersCnt = iLoadingListeners->Count();
       
  2395         for ( TInt i = 0; i < loadingListenersCnt; i++ )
       
  2396             {
       
  2397             (*iLoadingListeners)[i]->ImagesLoaded(aError);
       
  2398             }
       
  2399         }
       
  2400     
       
  2401 
       
  2402     }
       
  2403 
       
  2404 // ==========================================================================
       
  2405 // Loops through the tree and prints out all of the elements
       
  2406 // (almost regenerating the DOM tree)
       
  2407 //
       
  2408 // ==========================================================================
       
  2409 void CSvgDocumentImpl::PrintAllElements( CSvgElementImpl* aStartElement )
       
  2410 {
       
  2411 	if ( aStartElement == NULL )
       
  2412         return;
       
  2413 
       
  2414 	aStartElement->Print( EFalse );
       
  2415 	//===> comment the styles out to generate true SVG content
       
  2416 	//	aStartElement->PrintStyleProperties();
       
  2417 
       
  2418 	CSvgElementImpl* child = (CSvgElementImpl*)aStartElement->FirstChild();
       
  2419 	PrintAllElements( child );
       
  2420 
       
  2421 	child = (CSvgElementImpl*)aStartElement->NextSibling();
       
  2422 	PrintAllElements( child );
       
  2423 }
       
  2424 
       
  2425 TBool CSvgDocumentImpl::HasError()
       
  2426     {
       
  2427     return iError && iError->HasError();
       
  2428     }
       
  2429 
       
  2430 MSvgError* CSvgDocumentImpl::GetError()
       
  2431     {
       
  2432     return iError;
       
  2433     }
       
  2434 
       
  2435 void CSvgDocumentImpl::SetIsWarning( TBool aIsWarning )
       
  2436 {
       
  2437 	if (iError)
       
  2438 	{
       
  2439 		iError->SetIsWarning( aIsWarning );
       
  2440 	}
       
  2441 }
       
  2442 void CSvgDocumentImpl::SetError( TInt aErrorType, const TDesC& aMsg1, const TDesC& aMsg2 )
       
  2443     {
       
  2444     if ( !iError )
       
  2445         {
       
  2446         TRAPD( error, iError = CSvgErrorImpl::NewL() );
       
  2447         if ( error != KErrNone )
       
  2448             {
       
  2449             return;
       
  2450             }
       
  2451         PrepareError( *iError, ESvgUnknown, aErrorType, aMsg1, aMsg2 );
       
  2452         iError->SetIsWarning( ETrue );
       
  2453         }
       
  2454     }
       
  2455 
       
  2456 
       
  2457 // ---------------------------------------------------------------------------
       
  2458 // Accessor funciton for SyncBehaviorDefault value
       
  2459 // ---------------------------------------------------------------------------
       
  2460 TSvgSyncBehaviour CSvgDocumentImpl::SyncBehaviorDefault()
       
  2461     {
       
  2462     return iSyncBehaviorDefault;
       
  2463     }
       
  2464 
       
  2465 // ---------------------------------------------------------------------------
       
  2466 // Accessor funciton for SyncBehaviorDefault value
       
  2467 // ---------------------------------------------------------------------------
       
  2468 TUint32 CSvgDocumentImpl::SyncToleranceDefault()
       
  2469     {
       
  2470     return iSyncToleranceDefault;
       
  2471     }
       
  2472 
       
  2473 // ---------------------------------------------------------------------------
       
  2474 // CSvgDocumentImpl::SetCurrentTime
       
  2475 // Set Function for the document's current time
       
  2476 // ---------------------------------------------------------------------------
       
  2477 void CSvgDocumentImpl::SetCurrentTime( TInt32 aCurTime )
       
  2478     {
       
  2479     if ( iTimeContainer )
       
  2480         {
       
  2481         iTimeContainer->SetCurrentTime( aCurTime );
       
  2482         }
       
  2483     }
       
  2484 
       
  2485 // ---------------------------------------------------------------------------
       
  2486 // CSvgDocumentImpl::CurrentTime
       
  2487 // Accessor for the Document's current time
       
  2488 // ---------------------------------------------------------------------------
       
  2489 TInt32 CSvgDocumentImpl::CurrentTime()
       
  2490     {
       
  2491     if ( iTimeContainer )
       
  2492         {
       
  2493         return iTimeContainer->CurrentTime();
       
  2494         }
       
  2495     return KErrGeneral;
       
  2496     }
       
  2497 
       
  2498 // ---------------------------------------------------------------------------
       
  2499 // CSvgDocumentImpl::SetSyncBehavior
       
  2500 // Set the Synchronised behaviour for the time container
       
  2501 // ---------------------------------------------------------------------------
       
  2502 void CSvgDocumentImpl::SetTCSyncBehavior( const TSvgSyncBehaviour aValue )
       
  2503     {
       
  2504     if ( iTimeContainer )
       
  2505         {
       
  2506         iTimeContainer->SetSyncBehavior( aValue );
       
  2507         }
       
  2508     }
       
  2509 
       
  2510 // ---------------------------------------------------------------------------
       
  2511 // CSvgDocumentImpl::SetSyncTolerance
       
  2512 // Set the Synchronised Tolerance for the time container
       
  2513 // ---------------------------------------------------------------------------
       
  2514 void CSvgDocumentImpl::SetTCSyncTolerance( const TUint32 aValue )
       
  2515     {
       
  2516     if ( iTimeContainer )
       
  2517         {    
       
  2518         iTimeContainer->SetSyncTolerance( aValue );
       
  2519         }
       
  2520     }
       
  2521 
       
  2522 // ---------------------------------------------------------------------------
       
  2523 // CSvgDocumentImpl::SetSyncMaster
       
  2524 // Set the time container as Synchronised Master
       
  2525 // ---------------------------------------------------------------------------
       
  2526 void CSvgDocumentImpl::SetTCSyncMaster( const TBool aValue )
       
  2527     {
       
  2528     if ( iTimeContainer )
       
  2529         {    
       
  2530         iTimeContainer->SetSyncMaster( aValue );
       
  2531         }
       
  2532     }
       
  2533 
       
  2534 // -----------------------------------------------------------------------------
       
  2535 // CSvgDocumentImpl::TimeContainer
       
  2536 // Accessor for time container
       
  2537 // -----------------------------------------------------------------------------
       
  2538 //
       
  2539 CSvgTimeContainer* CSvgDocumentImpl::TimeContainer()    
       
  2540     {
       
  2541     return iTimeContainer;
       
  2542     }
       
  2543 
       
  2544 void CSvgDocumentImpl::DocumentTransform(TGfxAffineTransform& aTr)
       
  2545     {
       
  2546         iTransformMatrix = aTr;
       
  2547     }
       
  2548 
       
  2549 TGfxAffineTransform CSvgDocumentImpl::GetDocumentTransform()
       
  2550     {
       
  2551         return iTransformMatrix;
       
  2552     }
       
  2553     
       
  2554     
       
  2555 CSvgBitmapFontProvider * CSvgDocumentImpl::GetBitmapFontProvider()
       
  2556 {
       
  2557 	return iSvgBitmapFontProvider ;
       
  2558 }
       
  2559 
       
  2560 // -----------------------------------------------------------------------------
       
  2561 // CSvgDocumentImpl::SvgHasAnimationElement
       
  2562 // Checks if Document has Animation Element
       
  2563 // -----------------------------------------------------------------------------
       
  2564 
       
  2565 TBool CSvgDocumentImpl::SvgHasAnimationElement()
       
  2566     {
       
  2567         RPointerArray<CSvgElementImpl> lAnimationEleList;
       
  2568         FindAllElements((CSvgElementImpl* )RootElement(),
       
  2569                    KSvgMediaAnimationElement, lAnimationEleList );
       
  2570         TInt lAnimationEleCnt = lAnimationEleList.Count();    
       
  2571         lAnimationEleList.Close();
       
  2572         if ( lAnimationEleCnt > 0 )
       
  2573             {
       
  2574             return ETrue;
       
  2575             }
       
  2576        
       
  2577         return EFalse;     
       
  2578        
       
  2579     }
       
  2580 
       
  2581 // -----------------------------------------------------------------------------
       
  2582 // CSvgDocumentImpl::IsDocumentContentInteractive
       
  2583 // Checks if Document content is InterActive 
       
  2584 // -----------------------------------------------------------------------------
       
  2585 
       
  2586 TBool CSvgDocumentImpl::IsDocumentContentInteractive()
       
  2587     {
       
  2588         RPointerArray<CSvgElementImpl> elements;
       
  2589         FindAllElements( (CSvgElementImpl* )RootElement(),
       
  2590                                      KSvgAElement, elements );
       
  2591         if ( elements.Count() != 0 )
       
  2592         {
       
  2593             elements.Close();
       
  2594             return ETrue;
       
  2595         }
       
  2596         elements.Close();
       
  2597        
       
  2598         if ( iIsInteractive )
       
  2599             return ETrue;
       
  2600         
       
  2601         // Check if animation element is there 
       
  2602         RPointerArray<CSvgElementImpl> lAnimationEleList;
       
  2603         FindAllElements((CSvgElementImpl* )RootElement(),
       
  2604                    KSvgMediaAnimationElement, lAnimationEleList );
       
  2605                    
       
  2606         // If no animation element is present then return EFalse           
       
  2607         TInt lAnimationEleCnt = lAnimationEleList.Count();  
       
  2608         if ( lAnimationEleCnt == 0 ) 
       
  2609         {
       
  2610            lAnimationEleList.Close();  
       
  2611            return EFalse; 
       
  2612         }
       
  2613         
       
  2614         // Check all animation element and if any child svg has ..
       
  2615         // interactive content then return ETrue   
       
  2616         for ( TInt lCurAnimationEle = 0; 
       
  2617                 lCurAnimationEle < lAnimationEleCnt; lCurAnimationEle++ )
       
  2618         {
       
  2619            CSvgMediaAnimationElementImpl* lAnimationElement = 
       
  2620             (CSvgMediaAnimationElementImpl* )lAnimationEleList[ lCurAnimationEle ];
       
  2621            CSvgDocumentImpl* lChildDoc = lAnimationElement->GetChildDocument();
       
  2622            // if child svg has interavitve content then return
       
  2623            if(lChildDoc && lChildDoc->iIsInteractive)
       
  2624            {
       
  2625            		lAnimationEleList.Close();                
       
  2626            		return ETrue;
       
  2627            }
       
  2628         }  
       
  2629         
       
  2630         lAnimationEleList.Close();                
       
  2631         return EFalse;   
       
  2632 
       
  2633     }
       
  2634 
       
  2635 
       
  2636 void CSvgDocumentImpl::SetImageElementsCount(TInt aCnt)
       
  2637     {
       
  2638     iImageElementCnt = aCnt;
       
  2639     }
       
  2640 
       
  2641 TInt CSvgDocumentImpl::GetImageElementsCount()
       
  2642     {
       
  2643     return iImageElementCnt;
       
  2644     }
       
  2645 // End of file
       
  2646