messagingappbase/smilengine/engine/parser/smilparser.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     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: smilparser implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "smilparser.h"
       
    21 
       
    22 #include "smilsequence.h"
       
    23 #include "smilparallel.h"
       
    24 #include "smilexclusive.h"
       
    25 #include "smilmedia.h"
       
    26 #include "smilregion.h"
       
    27 #include "smilrootregion.h"
       
    28 #include "smilpresentation.h"
       
    29 #include "smilanchor.h"
       
    30 #include "smilarea.h"
       
    31 #include "smila.h"
       
    32 #include "smiltransition.h"
       
    33 #include "smilprefetch.h"
       
    34 
       
    35 #include "smilmediafactoryinterface.h"
       
    36 
       
    37 #include "smilliterals.h"
       
    38 #include "smillinkedlist.h"
       
    39 
       
    40 // maximum number of elements allowed in the timegraph
       
    41 #define MAX_TIMEGRAPH_SIZE 80
       
    42 
       
    43 // what it says. only used for resolving the content control attribute
       
    44 #define SYSTEM_SCREEN_DEPTH 16
       
    45 
       
    46 //#define PARSER_DEBUG
       
    47 
       
    48 // defined elsewhere
       
    49 void ParseXmlL( CSmilParser* parser, const TDesC& aSource );
       
    50 void ParseDomL( CSmilParser* parser, CMDXMLDocument* aSource );
       
    51 
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // CSmilParser::CSmilParser
       
    55 // ----------------------------------------------------------------------------
       
    56 //
       
    57 CSmilParser::CSmilParser()
       
    58     {    
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CSmilParser::~CSmilParser
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 CSmilParser::~CSmilParser()
       
    66     {
       
    67     delete iSwitchStack;
       
    68     delete iCurrent; // not yet part of a presentation!
       
    69     delete iCurrentRegion;
       
    70     
       
    71     if ( iNamespaces )
       
    72         {
       
    73         CLinkedList<Namespace>::Iter nsi( *iNamespaces );
       
    74         while( nsi.HasMore() )
       
    75             {
       
    76             Namespace& ns = nsi.Next();
       
    77             delete ns.name;
       
    78             delete ns.uri;
       
    79             }
       
    80         }
       
    81         
       
    82     delete iNamespaces;
       
    83     }
       
    84 
       
    85 // ----------------------------------------------------------------------------
       
    86 // CSmilParser::NewL
       
    87 // ----------------------------------------------------------------------------
       
    88 //
       
    89 EXPORT_C CSmilParser* CSmilParser::NewL( MSmilPlayer* aPlayer )
       
    90     {
       
    91     CSmilParser* self = new( ELeave ) CSmilParser();
       
    92     
       
    93     CleanupStack::PushL( self );
       
    94     self->ConstructL( aPlayer );
       
    95     CleanupStack::Pop( self );
       
    96      
       
    97     return self;    
       
    98     }
       
    99 
       
   100 // ----------------------------------------------------------------------------
       
   101 // CSmilParser::ConstructL
       
   102 // ----------------------------------------------------------------------------
       
   103 //
       
   104 void CSmilParser::ConstructL( MSmilPlayer* aPlayer )
       
   105     {
       
   106     iPlayer = aPlayer;
       
   107 
       
   108     iCurrent = 0;
       
   109     iCurrentRegion = 0;
       
   110     iSwitchStack = new( ELeave ) CLinkedList<Switch>();
       
   111     iNamespaces = new( ELeave ) CLinkedList<Namespace>();
       
   112     }
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CSmilParser::Init
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 void CSmilParser::Init()
       
   119     {
       
   120     iState = EInitial;
       
   121     
       
   122     delete iCurrent;  //might be some leftovers from a failed parsi
       
   123     iCurrent = 0;
       
   124     
       
   125     iTimeContainer = 0;
       
   126     
       
   127     delete iCurrentRegion;
       
   128     iCurrentRegion = 0;
       
   129     
       
   130     iCurrentTransition = 0;
       
   131     
       
   132     if ( iAnchor )
       
   133         {
       
   134         iAnchor->Close();
       
   135         iAnchor = 0;
       
   136         }
       
   137 
       
   138     CLinkedList<Namespace>::Iter nsi( *iNamespaces );
       
   139     while ( nsi.HasMore() )
       
   140         {
       
   141         Namespace& ns = nsi.Next();
       
   142         delete ns.name;
       
   143         delete ns.uri;
       
   144         }
       
   145     iNamespaces->Empty();
       
   146 
       
   147     iArea = 0;
       
   148 
       
   149     iIgnoreDepth = 0;
       
   150     iDepth = 0;
       
   151     iSwitchStack->Empty();
       
   152     iSkipContent = ETrue;
       
   153     iUnknownElement = EFalse;
       
   154     iTag.Set( TPtrC() );
       
   155     iParamName.Set( TPtrC() );
       
   156     iParamValue.Set( TPtrC() );
       
   157     iTimegraphSize = 0;
       
   158     }
       
   159 
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // CSmilParser::ParseL
       
   163 // 
       
   164 // ---------------------------------------------------------
       
   165 //
       
   166 EXPORT_C CSmilPresentation* CSmilParser::ParseL( const TDesC& /*aSmil*/, 
       
   167                                                  const TDesC& /*aBaseUrl*/ )
       
   168     {
       
   169 #if 0
       
   170     // can't parse descriptor with current Symbian DOM parser!!!
       
   171 #ifdef PARSER_DEBUG
       
   172     RDebug::Print(_L("ParseL(): %S"), &aSmil);
       
   173 #endif    
       
   174     
       
   175     Init();
       
   176     
       
   177     CSmilPresentation* tempPresentationPointer = CSmilPresentation::NewL( iPlayer );
       
   178 
       
   179     // Everything constructed during parsing is owned by the presentation
       
   180     // (directly or indirectly) and added there immediatly after construction.
       
   181     // Thus it is enough to take care that the presentation gets deleted if 
       
   182     // a leave occurs.
       
   183 
       
   184     CleanupStack::PushL( tempPresentationPointer );    
       
   185 
       
   186     tempPresentationPointer->SetBaseUrlL( aBaseUrl );    
       
   187     tempPresentationPointer->SetMaxDownUpScaling( iDown, iUp );    
       
   188     iPlayer->GetMediaFactory(tempPresentationPointer)->SetBaseUrlL( aBaseUrl );    
       
   189     
       
   190     iPresentation = tempPresentationPointer;    
       
   191     TBool ok = ParseXml( this, aSmil ); //parse! (see smilparser_cxml.cpp etc.)
       
   192     
       
   193     if ( ok && iState == ESmilFinished )
       
   194         {
       
   195 #ifdef PARSER_DEBUG
       
   196         RDebug::Print(_L("Parsed succesfully"));
       
   197 #endif
       
   198         tempPresentationPointer->Ready();    
       
   199         
       
   200 #ifdef PARSER_DEBUG
       
   201         tempPresentationPointer->PrintDebug();    
       
   202         
       
   203 #endif
       
   204         CleanupStack::Pop(); // tempPresentationPointer
       
   205         }
       
   206     else
       
   207         {
       
   208 #ifdef PARSER_DEBUG
       
   209         RDebug::Print(_L("Parsing failed, leaving"));
       
   210 #endif        
       
   211         User::Leave( KErrUnknown );
       
   212         }
       
   213     return tempPresentationPointer;    
       
   214     
       
   215 #endif
       
   216     return 0;
       
   217     }
       
   218 
       
   219 // ----------------------------------------------------------------------------
       
   220 // CSmilParser::ParseL
       
   221 // ----------------------------------------------------------------------------
       
   222 //
       
   223 EXPORT_C CSmilPresentation* CSmilParser::ParseL( const CMDXMLDocument* aSmilDoc, 
       
   224                                                  const TDesC& aBaseUrl )
       
   225     {
       
   226 #ifdef PARSER_DEBUG
       
   227     RDebug::Print(_L("ParseL(): parsing DOM"));
       
   228 #endif
       
   229 
       
   230     Init();
       
   231     
       
   232     CSmilPresentation* tempPresentationPointer = CSmilPresentation::NewL( iPlayer );
       
   233 
       
   234     // Everything constructed during parsing is owned by the presentation
       
   235     // (directly or indirectly) and added there immediatly after construction.
       
   236     // Thus it is enough to take care that the presentation gets deleted if 
       
   237     // a leave occurs.
       
   238 
       
   239     CleanupStack::PushL( tempPresentationPointer );    
       
   240     
       
   241     tempPresentationPointer->SetBaseUrlL( aBaseUrl );    
       
   242     tempPresentationPointer->SetMaxDownUpScaling( iDown, iUp );    
       
   243     iPlayer->GetMediaFactory(tempPresentationPointer)->SetBaseUrlL( aBaseUrl );    
       
   244     
       
   245     iPresentation = tempPresentationPointer;    
       
   246     
       
   247     ParseDomL( this, const_cast<CMDXMLDocument*>( aSmilDoc ) ); //parse! (see smilparser_dom.cpp)
       
   248     
       
   249     if ( iState == ESmilFinished )
       
   250         {
       
   251 #ifdef PARSER_DEBUG
       
   252         RDebug::Print(_L("Parsed succesfully"));
       
   253 #endif
       
   254         tempPresentationPointer->ReadyL();    
       
   255 
       
   256 #ifdef PARSER_DEBUG
       
   257         tempPresentationPointer->PrintDebug();    
       
   258 #endif
       
   259         CleanupStack::Pop(); // tempPresentationPointer
       
   260         }
       
   261     else
       
   262         {
       
   263 #ifdef PARSER_DEBUG
       
   264         RDebug::Print(_L("Parsing failed, leaving"));
       
   265 #endif    
       
   266         User::Leave( KErrUnknown );
       
   267         }
       
   268 
       
   269     return tempPresentationPointer;
       
   270     }
       
   271     
       
   272 // ----------------------------------------------------------------------------
       
   273 // CSmilParser::BeginElementL
       
   274 // ----------------------------------------------------------------------------
       
   275 //
       
   276 void CSmilParser::BeginElementL( const TDesC& aName )
       
   277     {
       
   278 #ifdef PARSER_DEBUG
       
   279     RDebug::Print(_L("BeginElement: %S"), &aName);
       
   280 #endif
       
   281 
       
   282     iDepth++;
       
   283 
       
   284     if ( iIgnoreDepth > 0 )
       
   285         {
       
   286         iIgnoreDepth++;
       
   287         return;
       
   288         }
       
   289 
       
   290     if ( !iSwitchStack->IsEmpty() && 
       
   291          iSwitchStack->Peek().depth == iDepth - 1 && 
       
   292          iSwitchStack->Peek().done )
       
   293         {
       
   294         iIgnoreDepth = 1;
       
   295         return;
       
   296         }
       
   297 
       
   298     if ( aName.CompareF( KSmilTag ) == 0 )
       
   299         {        
       
   300         if ( iState != EInitial )
       
   301             {
       
   302             User::Leave( KErrGeneral );
       
   303             }
       
   304     
       
   305         iState = ESmil;
       
   306         iTag.Set( KSmilTag );
       
   307 
       
   308         // we need root layout even if there is no <layout> element
       
   309         CSmilRootRegion* root = CSmilRootRegion::NewL( iPresentation );
       
   310         iPresentation->SetLayout( root );        
       
   311         }
       
   312     else if ( aName.CompareF( KRegionTag ) == 0 )
       
   313         {
       
   314         if ( iState != ELayout )
       
   315             {
       
   316             User::Leave( KErrGeneral );
       
   317             }
       
   318 
       
   319         iTag.Set( KRegionTag );
       
   320         CSmilRegion* r = CSmilRegion::NewL( iPresentation );
       
   321         iCurrentRegion = r;
       
   322         }
       
   323     else if ( aName.CompareF( KHeadTag ) == 0 )
       
   324         {
       
   325         if (iState != ESmil)
       
   326             {
       
   327             User::Leave( KErrGeneral );
       
   328             }
       
   329 
       
   330         iState = EHead;
       
   331         iTag.Set( KHeadTag );
       
   332         }
       
   333     else if ( aName.CompareF( KLayoutTag ) == 0 )
       
   334         {
       
   335         if ( iState != EHead )
       
   336             {
       
   337             User::Leave( KErrGeneral );
       
   338             }
       
   339 
       
   340         iState = ELayout;
       
   341         iTag.Set( KLayoutTag );
       
   342         iPresentation->GetLayout()->SetDefaultLayout( EFalse );
       
   343         }
       
   344     else if ( aName.CompareF( KRootLayoutTag ) == 0 && 
       
   345               iState == ELayout )
       
   346         {
       
   347         if ( iState != ELayout )
       
   348             {
       
   349             User::Leave( KErrGeneral );
       
   350             }
       
   351 
       
   352         iTag.Set( KRootLayoutTag );
       
   353         iCurrentRegion = iPresentation->GetLayout();
       
   354         }    
       
   355     else if ( aName.CompareF( KBodyTag ) == 0 )
       
   356         {        
       
   357         if ( iState != ESmil && 
       
   358              iState != EHeadFinished )
       
   359             {
       
   360             User::Leave( KErrGeneral );
       
   361             }
       
   362 
       
   363         iTag.Set( KBodyTag );
       
   364         CSmilSequence* body = CSmilSequence::NewL( iPresentation );
       
   365         iPresentation->SetTimegraph( body );
       
   366         iCurrent = body;
       
   367 
       
   368         iState = EBody;
       
   369         }
       
   370     else if ( aName.CompareF( KSeqTag ) == 0 )
       
   371         {
       
   372         if ( iState != EBody )
       
   373             {
       
   374             User::Leave(KErrGeneral);
       
   375             }
       
   376 
       
   377         iTag.Set( KSeqTag );
       
   378         iCurrent = CSmilSequence::NewL( iPresentation );
       
   379         }    
       
   380     else if ( aName.CompareF( KParTag ) == 0 )
       
   381         {
       
   382         if ( iState != EBody )
       
   383             {
       
   384             User::Leave(KErrGeneral);
       
   385             }
       
   386 
       
   387         iTag.Set( KParTag );
       
   388         iCurrent = CSmilParallel::NewL( iPresentation );        
       
   389         }
       
   390     else if ( aName.CompareF( KExclTag ) == 0 )
       
   391         {
       
   392         if ( iState != EBody )
       
   393             {
       
   394             User::Leave( KErrGeneral );
       
   395             } 
       
   396 
       
   397         iTag.Set( KExclTag );
       
   398         iCurrent = CSmilExclusive::NewL( iPresentation );
       
   399         }
       
   400     else if ( aName.CompareF( KTransitionTag ) == 0 )
       
   401         {
       
   402         if ( iState != EHead && 
       
   403              iState != ELayoutFinished )
       
   404             {
       
   405             User::Leave( KErrGeneral );
       
   406             }
       
   407 
       
   408         iTag.Set( KTransitionTag );
       
   409         
       
   410         iCurrentTransition = new (ELeave) CSmilTransition();
       
   411         iPresentation->AddTransitionL( iCurrentTransition );
       
   412         }
       
   413     else if ( aName.CompareF( KImageTag ) == 0 ||
       
   414               aName.CompareF( KTextTag ) == 0 ||
       
   415               aName.CompareF( KAudioTag ) == 0 ||
       
   416               aName.CompareF( KRefTag ) == 0 ||
       
   417               aName.CompareF( KTextStreamTag ) == 0 ||
       
   418               aName.CompareF( KAnimationTag ) == 0 ||
       
   419               aName.CompareF( KVideoTag ) == 0 )
       
   420         {
       
   421         if ( iState != EBody )
       
   422             {
       
   423             User::Leave(KErrGeneral);
       
   424             }
       
   425 
       
   426         iTag.Set( KRefTag );
       
   427         iCurrent = CSmilMedia::NewL( iPresentation );    
       
   428 
       
   429         if ( iAnchor )
       
   430             {
       
   431             iCurrent->SetAnchor( iAnchor );
       
   432             }
       
   433         }
       
   434     else if ( aName.CompareF( KParamTag ) == 0 )
       
   435         {
       
   436         iTag.Set( KParamTag );
       
   437         }
       
   438     else if ( aName.CompareF( KSwitchTag ) == 0 )
       
   439         {
       
   440         iTag.Set( KSwitchTag );
       
   441         
       
   442         Switch sw;
       
   443         sw.depth = iDepth;
       
   444         sw.done = EFalse;
       
   445         iSwitchStack->PushL( sw );
       
   446         }
       
   447     else if ( aName.CompareF( KATag ) == 0 )
       
   448         {
       
   449         iTag.Set( KATag );
       
   450 
       
   451         if ( iAnchor )
       
   452             {
       
   453             iAnchor->Close();
       
   454             iAnchor = 0;
       
   455             }
       
   456 
       
   457         iAnchor = new( ELeave ) CSmilAnchor();
       
   458         }
       
   459     else if ( aName.CompareF( KAreaTag ) == 0 || 
       
   460               aName.CompareF( KAnchorTag ) == 0)
       
   461         {
       
   462         iTag.Set( KAreaTag );
       
   463                 
       
   464         iArea = CSmilArea::NewL( iPresentation );    
       
   465         iArea->SetTimeContainer( iTimeContainer );
       
   466         iCurrent = iArea;
       
   467         }
       
   468     else if ( aName.CompareF( KPrefetchTag ) == 0 )
       
   469         {
       
   470         if ( iState != EBody )
       
   471             {
       
   472             User::Leave(KErrGeneral);
       
   473             }
       
   474 
       
   475         iTag.Set( KPrefetchTag );
       
   476         iCurrent = CSmilPrefetch::NewL( iPresentation );
       
   477         }    
       
   478     else
       
   479         {
       
   480         if ( iState != EInitial )
       
   481             {
       
   482             iUnknownElement = ETrue;
       
   483             }
       
   484         }
       
   485 
       
   486     return;
       
   487     }
       
   488 
       
   489 // ----------------------------------------------------------------------------
       
   490 // CSmilParser::EndElementL
       
   491 // ----------------------------------------------------------------------------
       
   492 //
       
   493 void CSmilParser::EndElementL( const TDesC& aName )
       
   494     {
       
   495 #ifdef PARSER_DEBUG
       
   496     RDebug::Print( _L( "EndElement: %S" ), &aName );
       
   497 #endif
       
   498 
       
   499     iDepth--;
       
   500 
       
   501     if ( iIgnoreDepth > 0 )
       
   502         {
       
   503         iIgnoreDepth--;
       
   504         return;
       
   505         }
       
   506 
       
   507     if ( aName.CompareF( KSmilTag ) == 0 )
       
   508         {
       
   509         if ( iPresentation && 
       
   510              iPresentation->GetTimegraph() && 
       
   511              iPresentation->GetLayout() )
       
   512             {
       
   513             iState = ESmilFinished;
       
   514             }
       
   515         } 
       
   516     else if ( aName.CompareF( KHeadTag ) == 0 )
       
   517         {
       
   518         iState = EHeadFinished;
       
   519         } 
       
   520     else if ( aName.CompareF( KTransitionTag ) == 0 )
       
   521         {
       
   522         iCurrentTransition = 0;
       
   523         }
       
   524     else if ( aName.CompareF( KLayoutTag ) == 0 )
       
   525         {
       
   526         iState = ELayoutFinished;
       
   527         iCurrentRegion = 0;
       
   528         }
       
   529     else if ( aName.CompareF( KSwitchTag ) == 0 )
       
   530         {           
       
   531         if ( !iSwitchStack->IsEmpty() )
       
   532             {            
       
   533             iSwitchStack->Pop();
       
   534             }
       
   535         }
       
   536     else if ( aName.CompareF( KBodyTag ) == 0 )
       
   537         {
       
   538         iState = EBodyFinished;
       
   539 
       
   540         iCurrent = 0;
       
   541         iTimeContainer = 0;
       
   542         } 
       
   543 
       
   544     else if ( aName.CompareF( KATag ) == 0 )
       
   545         {
       
   546         if ( iAnchor )
       
   547             {
       
   548             if (iAnchor->AccessCount()==1 && iTimeContainer)
       
   549                 {
       
   550                 // empty <a> element, we'll create a place holder SmilObject
       
   551                 CSmilA* a = CSmilA::NewL( iPresentation ); 
       
   552                 a->SetAnchor( iAnchor );
       
   553                 iTimeContainer->AddChild( a );
       
   554                 a->AttachedL();
       
   555                 }
       
   556             iAnchor->Close();        
       
   557             iAnchor = 0;
       
   558             }
       
   559         } 
       
   560 
       
   561     else if ( aName.CompareF( KParamTag ) == 0 )
       
   562         {
       
   563         iParamName.Set( TPtrC() );
       
   564         iParamValue.Set( TPtrC() );
       
   565         }
       
   566 
       
   567     else if ( ( aName.CompareF( KParTag ) == 0 || 
       
   568                 aName.CompareF( KSeqTag ) == 0 || 
       
   569                 aName.CompareF( KExclTag ) == 0 ) && 
       
   570               iTimeContainer )
       
   571         {        
       
   572         iTimeContainer = iTimeContainer->ParentObject();
       
   573         }
       
   574 
       
   575     else if ( ( aName.CompareF( KImageTag ) == 0 ||
       
   576                 aName.CompareF( KTextTag ) == 0 || 
       
   577                 aName.CompareF( KAudioTag ) == 0 ||
       
   578                 aName.CompareF( KRefTag ) == 0 ||
       
   579                 aName.CompareF( KTextStreamTag ) == 0 ||
       
   580                 aName.CompareF( KAnimationTag ) == 0 || 
       
   581                 aName.CompareF( KVideoTag ) == 0 ) && 
       
   582               iTimeContainer )
       
   583         {
       
   584         iTimeContainer = iTimeContainer->ParentObject();
       
   585         }
       
   586 
       
   587     return;
       
   588     }
       
   589 
       
   590 // ----------------------------------------------------------------------------
       
   591 // StripWhitespace
       
   592 // ----------------------------------------------------------------------------
       
   593 //
       
   594 TPtrC StripWhitespace( const TDesC& aStr )
       
   595     {
       
   596     // strip leading and trailing spaces from a string
       
   597     TInt b = 0;
       
   598     TInt e = aStr.Length() - 1;
       
   599     while ( b < aStr.Length() && aStr[b] == ' ' )
       
   600         {
       
   601         b++;
       
   602         }
       
   603     while ( e >= 0 && aStr[e] == ' ' )
       
   604         {
       
   605         e--;
       
   606         }
       
   607         
       
   608     if ( e >= b )
       
   609         {
       
   610         return aStr.Mid( b, e - b + 1 );
       
   611         }
       
   612     else
       
   613         {
       
   614         return TPtrC();
       
   615         }
       
   616     }
       
   617 
       
   618 // ----------------------------------------------------------------------------
       
   619 // CSmilParser::AttributeValueL
       
   620 // ----------------------------------------------------------------------------
       
   621 //
       
   622 void CSmilParser::AttributeValueL( const TDesC& aName, const TDesC& aAttrValue )    
       
   623     {
       
   624 #ifdef PARSER_DEBUG
       
   625     RDebug::Print( _L( "attrib: %S=%S" ), &aName, &aValue );
       
   626 #endif
       
   627 
       
   628     if ( iIgnoreDepth > 0 )
       
   629         {
       
   630         return;
       
   631         }
       
   632 
       
   633     const TPtrC aValue = StripWhitespace( aAttrValue );
       
   634 
       
   635     if ( aName.Length() == 0 )
       
   636         {
       
   637         return;
       
   638         }
       
   639 
       
   640     if ( CheckSystemAttribute( aName, aValue ) )
       
   641         {
       
   642         return;
       
   643         }
       
   644 
       
   645     if ( aName.CompareF( KSkipContentAttr ) == 0 )
       
   646         {
       
   647         if ( aValue.CompareF( KTrueVal ) == 0 )
       
   648             {
       
   649             iSkipContent = ETrue;
       
   650             }
       
   651         else if ( aValue.CompareF( KFalseVal ) == 0 )
       
   652             {
       
   653             iSkipContent = EFalse;
       
   654             }
       
   655         }
       
   656 
       
   657     switch ( iState )
       
   658         {
       
   659         case EBody:
       
   660             {
       
   661             if ( ( iAnchor && iTag == KATag ) || 
       
   662                  ( iArea && iTag == KAreaTag ) )
       
   663                 {
       
   664                 CSmilAnchor* a = iArea ? iArea->Anchor() : iAnchor;
       
   665                 
       
   666                 if ( aName.CompareF( KHrefAttr ) == 0 )
       
   667                     {
       
   668                     a->SetHrefL( aValue );
       
   669                     }
       
   670                 else if ( aName.CompareF( KAltAttr ) == 0 )
       
   671                     {
       
   672                     a->SetAltL( aValue );
       
   673                     }
       
   674                 else if ( aName.CompareF( KTargetAttr ) == 0 )
       
   675                     {
       
   676                     a->SetTargetL( aValue );
       
   677                     }
       
   678                 else if ( aName.CompareF( KTabindexAttr ) == 0 )
       
   679                     {
       
   680                     a->iTabIndex = StringToIntValue( aValue,0 );
       
   681                     }
       
   682                 else if (aName.CompareF( KActuateAttr ) == 0 )
       
   683                     {
       
   684                     if ( aValue.CompareF( KOnLoadVal ) == 0 )
       
   685                         {
       
   686                         a->iActuate = CSmilAnchor::EOnLoad;
       
   687                         }
       
   688                     }
       
   689                 else if ( aName.CompareF( KAccesskeyAttr ) == 0 )
       
   690                     {
       
   691                     if ( aValue.Length() > 0 )
       
   692                         {
       
   693                         a->iAccessKey = aValue[0];
       
   694                         }
       
   695                     }
       
   696                 else if ( iArea )
       
   697                     {
       
   698                     if ( aName.CompareF( KShapeAttr ) == 0 )
       
   699                         {                    
       
   700                         if ( aValue.CompareF( KCircleVal ) == 0 )
       
   701                             {
       
   702                             iArea->iShape = CSmilArea::ECircle;
       
   703                             }
       
   704                         else if ( aValue.CompareF( KPolyVal ) == 0 )
       
   705                             {
       
   706                             iArea->iShape = CSmilArea::EPoly;
       
   707                             }
       
   708                         else if ( aValue.CompareF( KRectVal ) == 0 )
       
   709                             {
       
   710                             iArea->iShape = CSmilArea::ERect;
       
   711                             }
       
   712                         }
       
   713                     else if ( aName.CompareF( KCoordsAttr ) == 0 )
       
   714                         {
       
   715                         TInt b = 0;
       
   716                         TInt e = 0;
       
   717                         
       
   718                         while ( e < aValue.Length() )
       
   719                             {
       
   720                             while ( e < aValue.Length() && aValue[e] != ',' )
       
   721                                 {
       
   722                                 e++;
       
   723                                 }
       
   724                                 
       
   725                             while ( aValue[b] == ' ' )
       
   726                                 {
       
   727                                 b++;
       
   728                                 }
       
   729                                 
       
   730                             TPtrC val = aValue.Mid( b, e - b );
       
   731                             
       
   732                             iArea->iCoords->AddL( TSmilLength( val ) );
       
   733                             
       
   734                             e++;
       
   735                             b = e;        
       
   736                             }
       
   737                         }
       
   738                     }
       
   739 
       
   740                 if ( !iArea )
       
   741                     {
       
   742                     return;
       
   743                     }
       
   744                 }
       
   745 
       
   746             else if (iTag == KParamTag )
       
   747                 {
       
   748                 if ( aName.CompareF( KNameAttr ) == 0 )
       
   749                     {
       
   750                     iParamName.Set( aValue );
       
   751                     }
       
   752                 else if ( aName.CompareF( KValueAttr ) == 0 )
       
   753                     {
       
   754                     iParamValue.Set( aValue );
       
   755                     }
       
   756                     
       
   757                 return;
       
   758                 }        
       
   759 
       
   760             if ( !iCurrent )
       
   761                 {
       
   762                 return;
       
   763                 }
       
   764 
       
   765             if ( aName.CompareF( KDurAttr ) == 0 )
       
   766                 {
       
   767                 iCurrent->SetDuration( TSmilTime( aValue ) );
       
   768                 }
       
   769             else if ( aName.CompareF( KBeginAttr ) == 0 )
       
   770                 {
       
   771                 ParseTimeListL( aValue, ETrue );
       
   772                 }
       
   773             else if ( aName.CompareF( KEndAttr ) == 0 )
       
   774                 {
       
   775                 ParseTimeListL( aValue, EFalse );
       
   776                 }
       
   777             else if ( aName.CompareF( KRepeatDurAttr ) == 0 )
       
   778                 {
       
   779                 iCurrent->SetRepeatDur( TSmilTime( aValue ) );
       
   780                 }
       
   781             else if ( aName.CompareF( KMinAttr ) == 0 )
       
   782                 {
       
   783                 iCurrent->SetMin( TSmilTime( aValue ) );
       
   784                 }
       
   785             else if ( aName.CompareF( KMaxAttr ) == 0 )
       
   786                 {
       
   787                 iCurrent->SetMax( TSmilTime( aValue ) );
       
   788                 }
       
   789             else if ( aName.CompareF( KFillAttr ) == 0 )
       
   790                 {
       
   791                 if ( aValue.CompareF( KRemoveVal ) == 0 )
       
   792                     {
       
   793                     iCurrent->SetFill( EFillRemove );
       
   794                     }
       
   795                 else if ( aValue.CompareF( KFreezeVal ) == 0 )
       
   796                     {
       
   797                     iCurrent->SetFill( EFillFreeze );
       
   798                     }
       
   799                 else if (aValue.CompareF( KHoldVal ) == 0 )
       
   800                     {
       
   801                     iCurrent->SetFill( EFillHold );
       
   802                     }
       
   803                 else if ( aValue.CompareF( KTransitionVal ) == 0 )
       
   804                     {
       
   805                     iCurrent->SetFill( EFillTransition );
       
   806                     }
       
   807                 }
       
   808             else if ( aName.CompareF( KEndsyncAttr ) == 0 )
       
   809                 {
       
   810                 if ( aValue.CompareF( KFirstVal ) == 0 )
       
   811                     {
       
   812                     iCurrent->SetEndsyncL( EEndsyncFirst );
       
   813                     }
       
   814                 else if (aValue.CompareF( KLastVal ) == 0 )
       
   815                     {
       
   816                     iCurrent->SetEndsyncL( EEndsyncLast );
       
   817                     }
       
   818                 else if (aValue.CompareF( KAllVal ) == 0 )
       
   819                     {
       
   820                     iCurrent->SetEndsyncL( EEndsyncAll );
       
   821                     }
       
   822                 else
       
   823                     {
       
   824                     iCurrent->SetEndsyncL( EEndsyncId, aValue );
       
   825                     }
       
   826                 }
       
   827             else if ( aName.CompareF( KRestartAttr ) == 0 )
       
   828                 {
       
   829                 if ( aValue.CompareF( KNeverVal ) == 0 )
       
   830                     {
       
   831                     iCurrent->SetRestart( ERestartNever );
       
   832                     }
       
   833                 else if (aValue.CompareF( KWhenNotActiveVal ) == 0 )
       
   834                     {
       
   835                     iCurrent->SetRestart( ERestartWhenNotActive );
       
   836                     }
       
   837                 else 
       
   838                     {
       
   839                     iCurrent->SetRestart(ERestartAlways);
       
   840                     }
       
   841                 }
       
   842             else if ( aName.CompareF( KRepeatCountAttr ) == 0 || 
       
   843                       aName.CompareF( KRepeatAttr ) == 0 )
       
   844                 {
       
   845                 TReal32 rc = StringToRealValue( aValue, 1 );
       
   846                 
       
   847                 if ( aValue.CompareF( KIndefiniteVal ) == 0 )
       
   848                     {
       
   849                     iCurrent->SetRepeatCount( KFloatIndefinite );
       
   850                     }
       
   851                 else if ( rc > 0 )
       
   852                     {
       
   853                     iCurrent->SetRepeatCount( rc );
       
   854                     }
       
   855                 }
       
   856             else if ( aName.CompareF( KIdAttr ) == 0 )
       
   857                 {
       
   858                 iCurrent->SetIdL( aValue );
       
   859                 }
       
   860             else if ( iCurrent->IsMedia() )
       
   861                 {
       
   862                 CSmilMedia* m = static_cast<CSmilMedia*>( iCurrent );
       
   863                 if ( aName.CompareF( KRegionAttr ) == 0 )
       
   864                     {
       
   865                     if ( iPresentation->GetLayout() )
       
   866                         {
       
   867                         CSmilRegion* r = iPresentation->GetLayout()->FindRegion( aValue );
       
   868                         if ( r )
       
   869                             {
       
   870                             m->SetRegion( r );
       
   871                             }
       
   872                         }
       
   873                     }
       
   874                 else if ( aName.CompareF( KSrcAttr ) == 0 )
       
   875                     {
       
   876                     m->SetSrcL( aValue );
       
   877                     }
       
   878                 else if ( aName.CompareF( KAltAttr ) == 0 )
       
   879                     {
       
   880                     m->SetAltL( aValue );
       
   881                     }
       
   882                 else if ( aName.CompareF( KTransInAttr ) == 0 )
       
   883                     {
       
   884                     m->iTransitionIn = iPresentation->FindTransition( aValue );            
       
   885                     }
       
   886                 else if ( aName.CompareF( KTransOutAttr ) == 0 )
       
   887                     {
       
   888                     m->iTransitionOut = iPresentation->FindTransition( aValue );            
       
   889                     }
       
   890                 else if ( aName.CompareF( KClipBeginAttr ) == 0 || 
       
   891                           aName.CompareF( KClipBegin2Attr ) == 0 )
       
   892                     {
       
   893                     TSmilTime tmp( aValue );
       
   894                     if ( tmp.IsFinite() )
       
   895                         {
       
   896                         m->iClipBegin = tmp;
       
   897                         }
       
   898                         
       
   899                     // SMTP values
       
   900                     }
       
   901                 else if ( aName.CompareF( KClipEndAttr ) == 0 || 
       
   902                           aName.CompareF( KClipEnd2Attr ) == 0 )
       
   903                     {
       
   904                     TSmilTime tmp( aValue );
       
   905                     if ( tmp.IsFinite() )
       
   906                         {
       
   907                         m->iClipEnd = tmp;
       
   908                         }
       
   909                     //### SMTP values
       
   910                     }
       
   911                 else if ( aName.CompareF( KTypeAttr ) == 0 )
       
   912                     {
       
   913                     m->SetTypeL(aValue);
       
   914                     }
       
   915                 }
       
   916 
       
   917             break;
       
   918             }
       
   919         case ELayout:
       
   920             {
       
   921             if ( !iCurrentRegion )
       
   922                 {
       
   923                 return;
       
   924                 }
       
   925 
       
   926             if ( aName.CompareF( KWidthAttr ) == 0 )
       
   927                 {
       
   928                 iCurrentRegion->iWidth = TSmilLength( aValue );
       
   929                 }
       
   930             else if ( aName.CompareF( KHeightAttr ) == 0 )
       
   931                 {
       
   932                 iCurrentRegion->iHeight = TSmilLength( aValue );
       
   933                 }
       
   934             else if ( aName.CompareF( KTopAttr ) == 0 )
       
   935                 {
       
   936                 iCurrentRegion->iTop = TSmilLength( aValue );
       
   937                 }
       
   938             else if ( aName.CompareF( KBottomAttr ) == 0 )
       
   939                 {
       
   940                 iCurrentRegion->iBottom = TSmilLength( aValue );
       
   941                 }
       
   942             else if ( aName.CompareF( KLeftAttr ) == 0 )
       
   943                 {
       
   944                 iCurrentRegion->iLeft = TSmilLength( aValue );
       
   945                 }
       
   946             else if ( aName.CompareF( KRightAttr ) == 0 )
       
   947                 {
       
   948                 iCurrentRegion->iRight = TSmilLength( aValue );
       
   949                 }
       
   950             else if ( aName.CompareF( KIdAttr ) == 0 )
       
   951                 {
       
   952                 iCurrentRegion->SetId( aValue );
       
   953                 }
       
   954             else if ( aName.CompareF( KRegionNameAttr ) == 0 )
       
   955                 {
       
   956                 iCurrentRegion->SetName( aValue );
       
   957                 }
       
   958             else if ( aName.CompareF( KZIndexAttr ) == 0 )
       
   959                 {
       
   960                 iCurrentRegion->iZIndex = StringToIntValue( aValue, 0 );
       
   961                 }
       
   962             else if ( aName.CompareF( KShowBackgroundAttr ) == 0 )
       
   963                 {
       
   964                 if ( aValue.CompareF( KAlwaysVal ) == 0 )
       
   965                     {
       
   966                     iCurrentRegion->iBackgroundMode = MSmilRegion::EAlways;
       
   967                     }
       
   968                 else if ( aValue.CompareF( KWhenActiveVal ) == 0 )
       
   969                     {
       
   970                     iCurrentRegion->iBackgroundMode = MSmilRegion::EWhenActive;
       
   971                     }
       
   972                 }
       
   973             else if ( aName.CompareF( KBackgroundColorAttr ) == 0 || 
       
   974                       aName.CompareF( KBackgroundColor2Attr ) == 0 )
       
   975                 {
       
   976                 TBool transparent;
       
   977                 iCurrentRegion->iBackground = ParseColor( aValue, transparent );
       
   978                 iCurrentRegion->iTransparent = transparent;
       
   979                 }        
       
   980             else if ( aName.CompareF( KFitAttr ) == 0 )
       
   981                 {
       
   982                 if ( aValue.CompareF( KMeetVal ) == 0 )
       
   983                     {
       
   984                     iCurrentRegion->iFit = MSmilRegion::EMeet;
       
   985                     }
       
   986                 else if ( aValue.CompareF( KSliceVal ) == 0 )
       
   987                     {
       
   988                     iCurrentRegion->iFit = MSmilRegion::ESlice;
       
   989                     }
       
   990                 else if ( aValue.CompareF( KFillVal ) == 0 )
       
   991                     {
       
   992                     iCurrentRegion->iFit = MSmilRegion::EFill;
       
   993                     }
       
   994                 else if ( aValue.CompareF( KHiddenVal ) == 0 )
       
   995                     {
       
   996                     iCurrentRegion->iFit = MSmilRegion::EHidden;
       
   997                     }
       
   998                 else if ( aValue.CompareF( KScrollVal ) == 0 )
       
   999                     {
       
  1000                     iCurrentRegion->iFit = MSmilRegion::EScroll;
       
  1001                     }
       
  1002                 }
       
  1003             break;
       
  1004             }
       
  1005         case EHead:
       
  1006         case ELayoutFinished:
       
  1007             {
       
  1008             if ( !iCurrentTransition )
       
  1009                 {
       
  1010                 return;
       
  1011                 }
       
  1012 
       
  1013             if ( aName.CompareF( KIdAttr ) == 0 )
       
  1014                 {
       
  1015                 iCurrentTransition->SetId( aValue );
       
  1016                 }
       
  1017             else if ( aName.CompareF( KTypeAttr ) == 0 )
       
  1018                 {
       
  1019                 iCurrentTransition->SetType( aValue );
       
  1020                 }
       
  1021             else if ( aName.CompareF( KSubtypeAttr ) == 0 )
       
  1022                 {
       
  1023                 iCurrentTransition->SetSubtype( aValue );
       
  1024                 }
       
  1025             else if ( aName.CompareF( KDurAttr ) == 0 )
       
  1026                 {
       
  1027                 iCurrentTransition->iDur = TSmilTime( aValue );
       
  1028                 }
       
  1029             else if ( aName.CompareF( KFadeColorAttr ) == 0 )
       
  1030                 {
       
  1031                 TBool b;
       
  1032                 iCurrentTransition->iFadeColor = ParseColor( aValue, b );
       
  1033                 }
       
  1034             else if ( aName.CompareF( KDirectionAttr ) == 0 )
       
  1035                 {
       
  1036                 iCurrentTransition->iReverse = ( aValue.CompareF( KReverseVal ) == 0 );
       
  1037                 }
       
  1038             else if ( aName.CompareF( KStartProgressAttr ) == 0 )
       
  1039                 {
       
  1040                 iCurrentTransition->iStartProgress = (TInt8)( 100 * StringToRealValue( aValue, 0 ) );
       
  1041                 }
       
  1042             else if ( aName.CompareF( KEndProgressAttr ) == 0 )
       
  1043                 {
       
  1044                 iCurrentTransition->iEndProgress = (TInt8)( 100 * StringToRealValue( aValue, 1 ) );
       
  1045                 }
       
  1046             break;
       
  1047             }
       
  1048         case ESmil:
       
  1049             {
       
  1050             if ( aName.Left(6).CompareF( KXmlnsAttr2 ) == 0 && 
       
  1051                  aName.Length() > 6 && 
       
  1052                  aValue.Length() > 0 )
       
  1053                 {
       
  1054                 Namespace ns;
       
  1055                 ns.name = aName.Mid(6).AllocL();
       
  1056                 ns.uri = aValue.AllocL();
       
  1057                 iNamespaces->AddL(ns);
       
  1058                 }
       
  1059             break;
       
  1060             }
       
  1061         default: 
       
  1062             {
       
  1063             break;
       
  1064             }
       
  1065         }
       
  1066     
       
  1067     return;
       
  1068     }
       
  1069 
       
  1070 // ----------------------------------------------------------------------------
       
  1071 // CSmilParser::AttributesEndL
       
  1072 // ----------------------------------------------------------------------------
       
  1073 //
       
  1074 void CSmilParser::AttributesEndL( TInt /*aCount*/ )
       
  1075     {
       
  1076 #ifdef PARSER_DEBUG
       
  1077     RDebug::Print(_L("AttributesEnd"));
       
  1078 #endif
       
  1079 
       
  1080     if ( !iSwitchStack->IsEmpty() && 
       
  1081          iSwitchStack->Peek().depth == iDepth - 1 && 
       
  1082          iIgnoreDepth == 0 )
       
  1083         {
       
  1084         iSwitchStack->Peek().done = ETrue;
       
  1085         }
       
  1086 
       
  1087     //unknown element, start ignoring if skip-content="true" (default)
       
  1088     if ( iUnknownElement )
       
  1089         {
       
  1090         if ( iSkipContent && !iIgnoreDepth )
       
  1091             {
       
  1092             iIgnoreDepth = 1;
       
  1093             }
       
  1094         iUnknownElement = EFalse;
       
  1095         }
       
  1096     // timing element
       
  1097     else if ( iState == EBody && iCurrent )
       
  1098         {
       
  1099         if ( iIgnoreDepth == 0 && iTimegraphSize < MAX_TIMEGRAPH_SIZE )
       
  1100             {
       
  1101             if ( iTimeContainer )
       
  1102                 {
       
  1103                 iTimeContainer->AddChild( iCurrent );
       
  1104                 }
       
  1105                 
       
  1106             if ( iCurrent->IsTimeContainer() )
       
  1107                 {
       
  1108                 iTimeContainer = static_cast<CSmilTimeContainer*>( iCurrent );
       
  1109                 }
       
  1110                 
       
  1111             iCurrent->AttachedL();
       
  1112             iCurrent = 0;
       
  1113             iTimegraphSize++;
       
  1114             }    
       
  1115         else
       
  1116             {
       
  1117             delete iCurrent;
       
  1118             iCurrent = 0;
       
  1119             }
       
  1120         }
       
  1121     // other
       
  1122     else 
       
  1123         {
       
  1124         if ( iTag == KParamTag && iTimeContainer && iTimeContainer->IsMedia() )
       
  1125             {
       
  1126             if ( iParamName.Length() > 0 && iParamValue.Length() > 0 )
       
  1127                 {                
       
  1128                 static_cast<CSmilMedia*>(iTimeContainer)->AddParamL( iParamName, iParamValue );
       
  1129                 }
       
  1130             }
       
  1131         else if ( iCurrentRegion && iCurrentRegion != iPresentation->GetLayout() )
       
  1132             {
       
  1133             if ( iIgnoreDepth == 0 )
       
  1134                 {    
       
  1135                 iPresentation->GetLayout()->AddChild( iCurrentRegion );                
       
  1136         
       
  1137                 iCurrentRegion = 0;
       
  1138                 }
       
  1139             else
       
  1140                 {
       
  1141                 delete iCurrentRegion;
       
  1142                 iCurrentRegion = 0;
       
  1143                 }
       
  1144             }
       
  1145         else
       
  1146             {
       
  1147             iCurrentRegion = 0;
       
  1148             }
       
  1149         }
       
  1150 
       
  1151     iArea = 0;    
       
  1152 
       
  1153     iTag.Set( TPtrC() );
       
  1154     }
       
  1155 
       
  1156 // ----------------------------------------------------------------------------
       
  1157 // CSmilParser::CheckSystemAttribute
       
  1158 // ----------------------------------------------------------------------------
       
  1159 //
       
  1160 TBool CSmilParser::CheckSystemAttribute(const TDesC& aName, const TDesC& aValue)
       
  1161     {
       
  1162     if ( !( aName.Left( 6 ) == KSystemAttr ) )
       
  1163         {
       
  1164         return EFalse;
       
  1165         }
       
  1166 
       
  1167     if ( iIgnoreDepth > 0 )
       
  1168         {
       
  1169         return ETrue;
       
  1170         }
       
  1171 
       
  1172     if ( aName == KSystemRequiredAttr )
       
  1173         {
       
  1174         TInt b = 0;
       
  1175         TInt e = 0;
       
  1176         while ( e < aValue.Length() )
       
  1177             {
       
  1178             while ( e < aValue.Length() && aValue[e] != '+' )
       
  1179                 {
       
  1180                 e++;
       
  1181                 }
       
  1182                 
       
  1183             TPtrC item = aValue.Mid( b, e - b );
       
  1184             TBool found = EFalse;
       
  1185             CLinkedList<Namespace>::Iter nsi(*iNamespaces);
       
  1186             
       
  1187             while( nsi.HasMore() )
       
  1188                 {
       
  1189                 Namespace ns = nsi.Next();
       
  1190                 if ( *(ns.name) == item )
       
  1191                     {
       
  1192                     found = EFalse;
       
  1193                     for ( TInt n = 0; KSystemReqValue[n]; n++ )
       
  1194                         {
       
  1195                         if ( *(ns.uri) == TPtrC( KSystemReqValue[n] ) )
       
  1196                             {
       
  1197                             found = ETrue;
       
  1198                             break;
       
  1199                             }
       
  1200                         }        
       
  1201                         
       
  1202                     if ( !found )
       
  1203                         {
       
  1204                         iIgnoreDepth = 1;
       
  1205                         }
       
  1206                     break;
       
  1207                     }
       
  1208                 }
       
  1209                 
       
  1210             if ( !found ) 
       
  1211                 {
       
  1212                 break;
       
  1213                 }
       
  1214                 
       
  1215             e++;
       
  1216             b = e;
       
  1217             }
       
  1218         }
       
  1219     else if ( aName == KSystemScreenSizeAttr )
       
  1220         {
       
  1221         TInt n = 0;
       
  1222         for ( ; n < aValue.Length(); n++ )
       
  1223             {
       
  1224             if ( aValue[n] == 'x' || aValue[n] == 'X' )
       
  1225                 {
       
  1226                 break;
       
  1227                 }
       
  1228             }
       
  1229         
       
  1230         if ( n > 0 && n < aValue.Length() - 1 )
       
  1231             {
       
  1232             TInt w, h;
       
  1233             TLex lex( aValue.Left( n ) );
       
  1234             lex.Val( h );            
       
  1235             lex = TLex( aValue.Mid( n + 1, aValue.Length() - n - 1 ) );
       
  1236             lex.Val( w );
       
  1237 
       
  1238             TRect s = iPlayer->GetDimensions( iPresentation );
       
  1239             if ( w > s.Width() || h > s.Height() )
       
  1240                 {
       
  1241                 iIgnoreDepth = 1;
       
  1242                 }
       
  1243             }
       
  1244         }
       
  1245     else if ( aName == KSystemScreenDepthAttr )
       
  1246         {
       
  1247         TInt d;
       
  1248         TLex lex( aValue );
       
  1249         TBool r =lex.Val( d );
       
  1250         
       
  1251         // Hardcoded bitdepth. This should be a callback.
       
  1252         // Querying system would be bad idea though, as it would
       
  1253         // introduce new lib depedencies.
       
  1254         if (r && d > SYSTEM_SCREEN_DEPTH )
       
  1255             {
       
  1256             iIgnoreDepth = 1;
       
  1257             }
       
  1258         }
       
  1259     else if ( aName == KSystemCPUAttr )
       
  1260         {
       
  1261         if ( aValue != KCPUVal )
       
  1262             {
       
  1263             iIgnoreDepth = 1;
       
  1264             }
       
  1265         }
       
  1266 
       
  1267     else if ( aName == KSystemOperatingSystemAttr )
       
  1268         {
       
  1269         if ( aValue != KOSVal )
       
  1270             {
       
  1271             iIgnoreDepth = 1;
       
  1272             }
       
  1273         }
       
  1274     else if ( aName == KSystemComponentAttr &&
       
  1275               aValue.Left( 12 ) == KContentTypeVal )
       
  1276         {
       
  1277         MSmilMediaFactory* f = iPlayer->GetMediaFactory( iPresentation );
       
  1278         if ( aValue.Length() >= 13 )
       
  1279             {
       
  1280             // strip off the scheme part from "ContentType:image/gif"
       
  1281             // call with "image/gif" only
       
  1282             if ( f->QueryContentType( aValue.Mid( 12 ) ) == EFalse )
       
  1283                 {
       
  1284                 iIgnoreDepth = 1;
       
  1285                 }
       
  1286             }
       
  1287         }
       
  1288 /*    else if (aName==KSystemContentTypeAttr)
       
  1289         {
       
  1290         MSmilMediaFactory* f = iPlayer->GetMediaFactory(iPresentation);
       
  1291         if (f->QueryContentType(aValue)==EFalse)
       
  1292             iIgnoreDepth = 1;
       
  1293         }*/
       
  1294     else
       
  1295         {
       
  1296         if ( iPlayer->EvaluateContentControlAttribute( aName, aValue ) == EFalse )
       
  1297             {
       
  1298             iIgnoreDepth = 1;
       
  1299             }
       
  1300         }
       
  1301 
       
  1302     return ETrue;
       
  1303     }
       
  1304     
       
  1305 // ----------------------------------------------------------------------------
       
  1306 // CSmilParser::ParseTimeListL
       
  1307 // ----------------------------------------------------------------------------
       
  1308 //
       
  1309 void CSmilParser::ParseTimeListL( const TDesC& aString, TBool aBegin )
       
  1310     {
       
  1311     TInt itemindex = 0;
       
  1312 
       
  1313     HBufC* list = HBufC::NewL( aString.Length() );
       
  1314     CleanupStack::PushL( list );
       
  1315     TPtrC listitem;
       
  1316     TPtr buf( list->Des() );
       
  1317     buf.Copy( aString );
       
  1318     TBool last = EFalse;
       
  1319     while( buf.Length() > 0 && !last )
       
  1320         {
       
  1321         TSmilCondition condition;
       
  1322 
       
  1323         buf.TrimLeft();
       
  1324 
       
  1325         itemindex = buf.Locate(';');
       
  1326         if( itemindex > 0 )
       
  1327             listitem.Set( buf.Left( itemindex ) );
       
  1328         else
       
  1329             {
       
  1330             listitem.Set( buf.Right( buf.Length() - itemindex ) );
       
  1331             last = ETrue;
       
  1332             }
       
  1333 
       
  1334 #ifdef PARSER_DEBUG
       
  1335         RDebug::Print(_L("timelist: %S"),&listitem);
       
  1336 #endif
       
  1337         
       
  1338         condition.iOffset =  TSmilTime( listitem ) ;
       
  1339             
       
  1340         if (condition.iOffset.IsUnresolved())
       
  1341             {
       
  1342             condition.iOffset = 0;
       
  1343             // ### FIXME!
       
  1344             TInt colindex = listitem.Locate( '.' );
       
  1345 
       
  1346             TInt offindex = listitem.Locate( ' ' );
       
  1347             if (offindex==KErrNotFound)
       
  1348                 offindex = listitem.Locate( '+' );
       
  1349             if (offindex==KErrNotFound)
       
  1350                 offindex = listitem.Locate( '-' );
       
  1351 
       
  1352             if (colindex!=KErrNotFound)
       
  1353                 {
       
  1354                 condition.SetEventSourceL(listitem.Left(colindex));
       
  1355                 if (offindex==KErrNotFound)
       
  1356                     condition.SetEventClassL(listitem.Mid(colindex+1));
       
  1357                 else
       
  1358                     condition.SetEventClassL(listitem.Mid(colindex+1, offindex-colindex-1));
       
  1359 
       
  1360                 }
       
  1361             else
       
  1362                 {    
       
  1363                 if (offindex==KErrNotFound)
       
  1364                     condition.SetEventClassL(listitem);
       
  1365                 else
       
  1366                     condition.SetEventClassL(listitem.Left(offindex));                
       
  1367                 }
       
  1368 
       
  1369             if (offindex!=KErrNotFound)
       
  1370                 {
       
  1371                 condition.iOffset = TSmilTime(listitem.Mid(offindex));
       
  1372                 if (!condition.iOffset.IsFinite())
       
  1373                     condition.iOffset = 0;
       
  1374                 }
       
  1375             
       
  1376             
       
  1377             }
       
  1378 
       
  1379             iCurrent->AddConditionL( condition, aBegin );
       
  1380 
       
  1381         buf.Delete( 0, itemindex + 1 );
       
  1382         }
       
  1383     CleanupStack::PopAndDestroy();  //list
       
  1384     }
       
  1385 
       
  1386 
       
  1387 // ---------------------------------------------------------
       
  1388 // CMediaObject::StringToRealValue
       
  1389 // Convert a descriptor to TReal32
       
  1390 // ---------------------------------------------------------
       
  1391 //
       
  1392 TReal32 CSmilParser::StringToRealValue( const TDesC& aString, TReal32 aDefault )
       
  1393     {
       
  1394     TReal32 value = aDefault;
       
  1395     if( aString.Length() != 0 )
       
  1396         {
       
  1397         TLex lex( aString );
       
  1398         if (lex.Val( value ) != KErrNone)
       
  1399             {
       
  1400             value = aDefault;
       
  1401             }
       
  1402         }
       
  1403     return value;
       
  1404     }
       
  1405 
       
  1406 // ---------------------------------------------------------
       
  1407 // CMediaObject::SetBeginString
       
  1408 // Convert a descriptor to TInt
       
  1409 // ---------------------------------------------------------
       
  1410 //
       
  1411 TInt CSmilParser::StringToIntValue( const TDesC& aString, TInt aDefault )
       
  1412     {
       
  1413     TInt value = aDefault;
       
  1414     if( aString.Length() != 0 )
       
  1415         {
       
  1416         TLex lex( aString );
       
  1417         if (lex.Val( value ) != KErrNone)
       
  1418             {
       
  1419             value = aDefault;
       
  1420             }
       
  1421         }
       
  1422     return value;
       
  1423     }
       
  1424 
       
  1425 
       
  1426 // ----------------------------------------------------------------------------
       
  1427 // CSmilParser::ParseTimeListL
       
  1428 // Parser for css2 color values. Should be somewhere else
       
  1429 // ----------------------------------------------------------------------------
       
  1430 //
       
  1431 EXPORT_C TRgb CSmilParser::ParseColor( const TDesC& aStr, TBool& aTransparent )
       
  1432     {
       
  1433     aTransparent = ETrue;        
       
  1434     TRgb res;
       
  1435     if (aStr.Length()>256)
       
  1436         return res;
       
  1437     TBuf<256> aString = aStr;
       
  1438     aString.LowerCase();
       
  1439     if (aString.Length()>1 )
       
  1440         {
       
  1441         _LIT(KRgbO,"rgb(");
       
  1442         TUint32 val;
       
  1443         if (aString[0]=='#')
       
  1444             {
       
  1445             TLex lexer (aString.Mid(1));
       
  1446             if (aString.Length()==4)
       
  1447                 {
       
  1448                 // #a3b notation (==#aa33bb)
       
  1449                 if (lexer.Val( val, EHex, TUint(0x00000fff) )==KErrNone )
       
  1450                     {
       
  1451 #ifdef PARSER_DEBUG
       
  1452                     RDebug::Print(_L("color=%x"), val);
       
  1453 #endif
       
  1454                     res = TRgb (((val&0xf00)>>8)|((val&0xf00)>>4), 
       
  1455                         ((val&0x0f0)>>4)|(val&0x0f0), 
       
  1456                         (val&0xf)|((val&0xf)<<4));
       
  1457                     aTransparent = EFalse;
       
  1458                     }
       
  1459                 }
       
  1460             else
       
  1461                 {
       
  1462                 // #aa33bb notation
       
  1463                 if (lexer.Val( val, EHex, TUint(0x00ffffff) )==KErrNone )
       
  1464                     {
       
  1465 #ifdef PARSER_DEBUG
       
  1466                     RDebug::Print(_L("color=%x"), val);
       
  1467 #endif
       
  1468 
       
  1469                     res = TRgb ((val&0x00ff0000)>>16, (val&0x0000ff00)>>8, (val&0x000000ff));
       
  1470                     aTransparent = EFalse;
       
  1471                     }
       
  1472                 }            
       
  1473             }
       
  1474         else if (aString.Left(4)==KRgbO)
       
  1475             {
       
  1476             // rgb(123,33,167) notation and rgb(40%,10%,70%) notation            
       
  1477             TInt rgb[3];
       
  1478             TInt count=0;
       
  1479             TInt b = 4;
       
  1480             TInt e = 4;
       
  1481             TBool percent = EFalse;
       
  1482             while (e<aString.Length())
       
  1483                 {
       
  1484                 while (e<aString.Length() && aString[e]==' ')
       
  1485                     e++;
       
  1486                 b=e;
       
  1487                 while (e<aString.Length() && aString[e]!=',' && aString[e]!=')')
       
  1488                     e++;
       
  1489                 TInt te = e-1;
       
  1490                 while (te>b && aString[te]==' ')
       
  1491                     te--;
       
  1492                 if (te>=b)
       
  1493                     {
       
  1494                     if (aString[te]=='%')
       
  1495                         {
       
  1496                         percent = ETrue;
       
  1497                         te--;
       
  1498                         }
       
  1499                     TPtrC num = aString.Mid(b,te-b+1);
       
  1500 #ifdef PARSER_DEBUG
       
  1501                     RDebug::Print(_L("rgb num=%S"),&num);
       
  1502 #endif
       
  1503                     rgb[count] = StringToIntValue(num,0);
       
  1504                     TInt max = 255;
       
  1505                     if (percent) max=100;
       
  1506                     if (rgb[count]<0) rgb[count]=0;
       
  1507                     if (rgb[count]>max) rgb[count]=max;
       
  1508     
       
  1509                     count++;
       
  1510                     if (count==3)
       
  1511                         break;
       
  1512                     }
       
  1513                 e++;        
       
  1514                 }
       
  1515             if (count==3)
       
  1516                 {
       
  1517                 if (percent)
       
  1518                     res = TRgb(rgb[0]*255/100, rgb[1]*255/100, rgb[2]*255/100);
       
  1519                 else
       
  1520                     res = TRgb(rgb[0], rgb[1], rgb[2]);
       
  1521                 aTransparent = EFalse;
       
  1522                 }
       
  1523             }
       
  1524         else if (aString==KTransparentVal)
       
  1525             {
       
  1526             aTransparent = ETrue;
       
  1527             }
       
  1528         else
       
  1529             {
       
  1530             for (int n=0; KColorNames[n]; n++)
       
  1531                 {
       
  1532                 if (aString == TPtrC(KColorNames[n]))
       
  1533                     {                    
       
  1534                     res = KColorValues[n];
       
  1535 #ifdef PARSER_DEBUG
       
  1536                     RDebug::Print(_L("color=%x (%S)"), res.Value(), &aString);
       
  1537 #endif
       
  1538 
       
  1539                     aTransparent = EFalse;
       
  1540                     break;
       
  1541                     }
       
  1542 
       
  1543                 }            
       
  1544             }
       
  1545         // ### FIXME add system colors!
       
  1546         
       
  1547         }
       
  1548 
       
  1549     return res;
       
  1550 
       
  1551     }
       
  1552 
       
  1553 // ----------------------------------------------------------------------------
       
  1554 // CSmilParser::SetMaxDownUpScaling
       
  1555 // ----------------------------------------------------------------------------
       
  1556 //    
       
  1557 EXPORT_C void CSmilParser::SetMaxDownUpScaling( TReal32 aDown, TReal32 aUp )
       
  1558     {
       
  1559     iDown = aDown;
       
  1560     iUp = aUp;
       
  1561     }