svgtopt/SVG/SVGImpl/src/SVGDiscardElementImpl.cpp
changeset 46 88edb906c587
equal deleted inserted replaced
-1:000000000000 46:88edb906c587
       
     1 /*
       
     2 * Copyright (c) 2005 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 FILES
       
    20 #include "SVGDiscardElementImpl.h"
       
    21 #include "SVGDocumentImpl.h"
       
    22 #include "SVGSchemaData.h"
       
    23 #include "SVGAnimTimingParser.h"
       
    24 #include "SVGEngineImpl.h"
       
    25 #include "SVGAnimationBase.h"
       
    26 #include "SVGRectElementImpl.h"
       
    27 #include "SVGEvent.h"
       
    28 
       
    29 #if !defined(__E32BASE_H__)
       
    30 #include <e32base.h>
       
    31 #endif
       
    32 
       
    33 
       
    34 // ============================= LOCAL FUNCTIONS ===============================
       
    35 
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // RemoveTargetElement: A utility function that renmoves target element.
       
    39 // Remove target element and all its child from its parent level.
       
    40 // Allocated Style properties of the target elements have to be deleted here.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 void CSvgDiscardElementImpl::RemoveTargetElement()
       
    44 	{
       
    45 	
       
    46     if (iTargetElement!= NULL)
       
    47         {
       
    48 		CSvgElementImpl* lParent = (CSvgElementImpl*)iTargetElement->ParentNode();
       
    49 		if ( lParent != NULL )
       
    50 		    {
       
    51 		    lParent->RemoveChild(iTargetElement);
       
    52 		    }
       
    53 		else if ( iTargetElement->ElemID() == KSvgSvgElement )
       
    54 			{
       
    55 			// remove all children
       
    56 		    CSvgElementImpl* child = (CSvgElementImpl*)iTargetElement->FirstChild();
       
    57 		    CSvgElementImpl* sib = (CSvgElementImpl*) NULL;
       
    58 		    while ( (child != NULL ) || sib != (CSvgElementImpl*) NULL )
       
    59 		    	{
       
    60 		        sib = (CSvgElementImpl*)child->NextSibling();
       
    61 		        // remove myself later
       
    62 				if (child != this)
       
    63 					{					
       
    64 					iTargetElement->RemoveChild(child);
       
    65 					delete child;
       
    66 					}
       
    67 				child = sib;
       
    68 		    	}
       
    69 			}
       
    70         
       
    71         // make sure that the target element is not root
       
    72         if ( iTargetElement->ElemID() != KSvgSvgElement )
       
    73         	{
       
    74 			delete iTargetElement;        	
       
    75 			iTargetElement = NULL;
       
    76         	}
       
    77         iRemoveMyself = ETrue;
       
    78         }
       
    79 	}
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // FindTargetElementL: A utility function that finds target element
       
    83 // and adjust the begin time.
       
    84 //
       
    85 // Returns: TBool ETrue if target is set.
       
    86 //                EFalse if target is not found.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 TBool CSvgDiscardElementImpl::FindTargetElementL()
       
    90 	{
       
    91 	if (iTargetElement)
       
    92 		return ETrue;
       
    93 
       
    94 	// Target could be set from one of the following ways:
       
    95 	// 1) Defined as SyncBased value.  ==> get element
       
    96 	// 2) xlink-href defined.          ==> get element
       
    97 	// 3) Invalid element id           ==> Ignore
       
    98 	// 4) No specified xlink-href nor other element id. ==> Use parent
       
    99 
       
   100 	if ( iHrefValueDefined )
       
   101     	{
       
   102     	// Case 2 & 3
       
   103     	TPtrC lPtr = iTargetId->Des();
       
   104 		iTargetElement = ( CSvgElementImpl * )
       
   105 	    	((CSvgDocumentImpl*)iOwnerDocument)->GetElementById(lPtr);
       
   106     	if (iTargetElement == NULL)
       
   107         	{
       
   108         	// Case 3
       
   109         	// Ignore and remove myself later.
       
   110         	iRemoveMyself = ETrue;
       
   111         	return EFalse;
       
   112         	}
       
   113     	}
       
   114     else // Case 4
       
   115         {
       
   116         // Set parent to target only when the parent is an animation element
       
   117 		iTargetElement = ( CSvgElementImpl * ) ParentNode();
       
   118         }
       
   119 
       
   120 	// Target element should be determined by now.
       
   121 
       
   122 
       
   123 	// Check to see if the target element is animatable.
       
   124 	// If not, remove myself.
       
   125 	// Calculate begin time.
       
   126 
       
   127 	if ( iSyncValueDefined )
       
   128 		{
       
   129 		// Get reference target element
       
   130 		iRefTargetElement = ( CSvgElementImpl * )
       
   131 	    ((CSvgDocumentImpl*)iOwnerDocument)->GetElementById(iBeginSyncElementId);
       
   132 
       
   133 	    // Only Syncbased begin time
       
   134 	    if (!iEventValueDefined)
       
   135 	    	{
       
   136 	    	// If specified element doesn't exist or the element is not animated,
       
   137 	    	// remove myself.
       
   138 	    	if ((iRefTargetElement == NULL) /*|| !IsAnimationElement(iRefTargetElement)*/)
       
   139 	        	{
       
   140 	        	// No referenced element or not animatable element (no begin/end attr)
       
   141 	        	// ==> Ignore and remove myself later.
       
   142 	        	iRemoveMyself = ETrue;
       
   143 	        	return EFalse;
       
   144 	        	}
       
   145 
       
   146 	        // re-calculate begin time. e.g. id1.start+5s
       
   147 	        if (iBeginReferenceEvent == ESvgEventBeginEvent)
       
   148 	        	{
       
   149 				iAbsoluteBeginTime +=
       
   150 					((CSvgAnimationBase*)iRefTargetElement)->GetAbsoluteBeginTime();
       
   151 	        	}
       
   152 	        else if (iBeginReferenceEvent == ESvgEventEndEvent)
       
   153 	        	{
       
   154 				iAbsoluteBeginTime +=
       
   155 					((CSvgAnimationBase*)iRefTargetElement)->GetEndTime();
       
   156 	        	}
       
   157 	    	}
       
   158 	    else // iEventValueDefined is TRUE
       
   159 	    	{
       
   160 	    	// Listen external events
       
   161 	        ((CSvgDocumentImpl*)
       
   162 	        	iOwnerDocument)->AddToEventReceiverListL(iRefTargetElement,
       
   163                                                 KSvgEventMaskExternalUI);
       
   164 	    	}
       
   165 		}
       
   166 	else if (iEventValueDefined)
       
   167     	{
       
   168        	// Listen external events
       
   169         ((CSvgDocumentImpl*)
       
   170         	iOwnerDocument)->AddToEventReceiverListL(iTargetElement,
       
   171                                             KSvgEventMaskExternalUI);
       
   172     	}
       
   173 
       
   174     return ETrue; // Set Target element
       
   175 	}
       
   176 
       
   177 
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // HasAnimationElements: A utility function that check if the element
       
   181 // contains animation element(s).
       
   182 //
       
   183 // Returns: TBool ETrue if the element contains animation element(s)
       
   184 //                EFalse if the element doesn't animated.
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 /*
       
   188 TBool CSvgDiscardElementImpl::HasAnimationElements(CSvgElementImpl* aElement)
       
   189     {
       
   190 	TBool lFound = EFalse;
       
   191 
       
   192 	// Return immediately if the target element is already an animation element.
       
   193 	if (IsAnimationElement(aElement))
       
   194 		return ETrue;
       
   195 
       
   196 	// Look through childs
       
   197     CSvgElementImpl* child = (CSvgElementImpl*)aElement->FirstChild();
       
   198     while ( child != NULL )
       
   199     	{
       
   200         if ( IsAnimationElement(child) )
       
   201         	{
       
   202         	lFound = ETrue;
       
   203         	break;
       
   204         	}
       
   205         child = (CSvgElementImpl*)child->NextSibling();
       
   206     	}
       
   207     if (lFound)
       
   208     	return ETrue;
       
   209 
       
   210     return EFalse;
       
   211     }
       
   212 */
       
   213 
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // IsAnimationElement: A utility function that check if the element
       
   217 // is an animation element.
       
   218 //
       
   219 // Returns: TBool ETrue if the element is a animation element.
       
   220 //                EFalse if the element is not an animation element.
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 
       
   224 /*
       
   225 TBool CSvgDiscardElementImpl::IsAnimationElement(CSvgElementImpl* aElement)
       
   226     {
       
   227 
       
   228 	TInt id = aElement->ElemID();
       
   229 
       
   230     return (( id == KSvgAnimateElement ) ||
       
   231 	        ( id == KSvgAnimateMotionElement ) ||
       
   232 	        ( id == KSvgAnimateTransformElement ) ||
       
   233 	        ( id == KSvgSetElement ) ||
       
   234 	        ( id == KSvgAnimateColorElement ));
       
   235     }
       
   236 */
       
   237 
       
   238 // ============================ MEMBER FUNCTIONS ===============================
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // SetAttributeL: The implemented function will be called from CSvgContentHandler.
       
   242 //
       
   243 // From CSvgElementImpl
       
   244 //
       
   245 // There will be two attributes been set: begin and xlink:href.
       
   246 // If xlink:href is not specified, the target element will be parent element
       
   247 // If begin time is not specifid, the target element will be remove immdeiately.
       
   248 //
       
   249 // Returns: ETrue always in this case.
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 TInt CSvgDiscardElementImpl::SetAttributeL( const TDesC& aName,
       
   253                                             const TDesC& aValue )
       
   254     {
       
   255     _LIT( KTmpXlinkHref, "xlink:href" );
       
   256     _LIT( KTmpBegin, "begin" );
       
   257 
       
   258     // If not xlink:href, it must be attribute "begin"
       
   259      if ( aName == KTmpXlinkHref )
       
   260         {
       
   261 		// STEP 1 - Get the reference element
       
   262 		// If the first char is '#' then remove it
       
   263 		// This is possible if coming from cXML parser and not the Decoder
       
   264 		iHrefValueDefined = ETrue;
       
   265 		TInt pos = aValue.Locate( '#' );
       
   266 		if ( pos == 0 )
       
   267 			{
       
   268 			if (iTargetId)
       
   269 				{
       
   270 				delete iTargetId;
       
   271 				iTargetId = NULL;
       
   272 				}
       
   273 			iTargetId = aValue.AllocL();
       
   274 	    	TPtr tPtr = iTargetId->Des();
       
   275 			tPtr.Delete(pos, 1);
       
   276 			}
       
   277         }
       
   278     else if ( aName == KTmpBegin )
       
   279         {
       
   280         CSvgAnimTimingParser* atParser = CSvgAnimTimingParser::NewLC( aValue, this );
       
   281         TInt32     clockValue;
       
   282         TReal32    lRepeatBeginValue;
       
   283         atParser->Parse( iBeginSyncElementId,
       
   284                          iBeginReferenceEvent,
       
   285                          clockValue,
       
   286                          lRepeatBeginValue,
       
   287                          ETrue);
       
   288 
       
   289    		iAbsoluteBeginTime = clockValue;
       
   290 
       
   291         if ( iBeginSyncElementId.Size() != 0 )
       
   292         	{
       
   293         	iSyncValueDefined = ETrue;
       
   294         	}
       
   295 
       
   296         if ( iBeginReferenceEvent != ESvgEventNone )
       
   297         	{
       
   298         	iEventValueDefined = ETrue;
       
   299         	iRefBeginTime = clockValue;
       
   300 	   		iAbsoluteBeginTime = KTimeIndefinite;
       
   301         	if (iBeginReferenceEvent == ESvgEventKey)
       
   302         		{
       
   303         		iKeyValue = atParser->AccekeyValue();
       
   304         		}
       
   305         	}
       
   306 
       
   307 
       
   308         CleanupStack::PopAndDestroy( 1 );     // atParser
       
   309         }
       
   310 	
       
   311 	CSvgElementImpl::SetAttributeL(aName,aValue);
       
   312 	
       
   313     return KErrNone;
       
   314     }
       
   315 
       
   316 
       
   317 
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // ReceiveEventL: The implemented function will be called whenever subscribed
       
   321 // events are received.
       
   322 //
       
   323 // From MSvgEventReceiver
       
   324 //
       
   325 // Return: TBool ETrue if redraw is needed
       
   326 //               EFalse if redraw is not needed
       
   327 // -----------------------------------------------------------------------------
       
   328 //
       
   329 TBool CSvgDiscardElementImpl::ReceiveEventL( MSvgEvent* aEvent )
       
   330     {
       
   331 
       
   332 	if (iRemoveMyself)
       
   333 		{
       
   334 		// Two reasons to remove myself.
       
   335 		// 1) when discard element is not sepcified inside of the target
       
   336 	    //    element so the object is not removed automatically along with
       
   337 	    //    target element.
       
   338 	    // 2) Invalid begin time
       
   339 		iTargetElement = ( CSvgElementImpl * ) ParentNode();
       
   340 		iTargetElement->RemoveChild(this);
       
   341 		delete this;
       
   342 		return EFalse;
       
   343     	}
       
   344 
       
   345 	// Looking for target as soon as first event received. Also adject time
       
   346 	// according to timeing attribute.
       
   347 	if (!FindTargetElementL())
       
   348 		{
       
   349 		// Target not found, exit and remove myself next time
       
   350 		return EFalse;
       
   351 		}
       
   352 
       
   353 	// Target element should be identified by now.
       
   354 
       
   355 	CSvgEngineImpl* engine = ((CSvgDocumentImpl*)iOwnerDocument)->Engine();
       
   356 	if (engine == NULL)
       
   357 		{
       
   358 		return EFalse;
       
   359 		}
       
   360 
       
   361     TInt32 lEngineCurrentTime = engine->CurrentTIme();
       
   362 
       
   363 	// User input event
       
   364 	if (aEvent->EventType() == ESvgEngineEventKeyPress)
       
   365 		{
       
   366         MSvgUiKeyEvent* evt   = ( MSvgUiKeyEvent* ) aEvent;
       
   367     	if (evt->KeyCode() == iKeyValue)
       
   368     	    {
       
   369     		// Remove target immediately
       
   370         	RemoveTargetElement();
       
   371         	engine->RedrawL();
       
   372         	return ETrue;
       
   373     	    }
       
   374         return EFalse;
       
   375 		}
       
   376 	// Timer event
       
   377     if (aEvent->EventMask() == KSvgEventMaskTimer)
       
   378         {
       
   379 
       
   380         if (lEngineCurrentTime >= iAbsoluteBeginTime)
       
   381             {
       
   382             // Time to remove target
       
   383         	RemoveTargetElement();
       
   384             }
       
   385         }
       
   386     // Internal event
       
   387     else if ((aEvent->EventMask() == KSvgEventMaskInternal )
       
   388     		 && (!iRefBeginTimeSet))
       
   389     	{
       
   390         MSvgInternalEvent*  evt = ( MSvgInternalEvent* ) aEvent;
       
   391         TSvgEvent s_evt = evt->SvgEvent();
       
   392         if (s_evt == iBeginReferenceEvent)
       
   393         	{
       
   394 
       
   395 	    	// Event other than AccessKey
       
   396 	    	// Check to see if there is a clock associated with the event.
       
   397 	    	 if (s_evt == iBeginReferenceEvent)
       
   398 	    		{
       
   399 	    		// This is some form of event+(-)clock so delay removing
       
   400 	    		// Note that once the reference time is set, the absolutetime
       
   401 	    		// can't be changed with other events.
       
   402 	    		if (iRefTargetElement != NULL)
       
   403 	    			{
       
   404 					// This is a syncbased event
       
   405 		    		if (evt->ObjectAddress() == iRefTargetElement)
       
   406 		    			{
       
   407 			    		iAbsoluteBeginTime = lEngineCurrentTime + iRefBeginTime;
       
   408 			    		iRefBeginTimeSet = ETrue;
       
   409 			    		return EFalse;
       
   410 		    			}
       
   411 	    			}
       
   412 	    		else
       
   413 	    			{
       
   414 					// Not syncbased event
       
   415 		    		if (evt->ObjectAddress() == iTargetElement)
       
   416 		    			{
       
   417 			    		iAbsoluteBeginTime = lEngineCurrentTime + iRefBeginTime;
       
   418 			    		iRefBeginTimeSet = ETrue;
       
   419 			    		return EFalse;
       
   420 		    			}
       
   421 	    			}
       
   422 	    		} //  if (s_evt == iBeginReferenceEvent)...
       
   423 	    	else
       
   424 	    		{
       
   425 	    		// No clock assoicated with the event.
       
   426 	    		if (iRefTargetElement != NULL)
       
   427 	    			{
       
   428 	    			// This is a syncbased event
       
   429 		    		if (evt->ObjectAddress() == iRefTargetElement)
       
   430 		    			{
       
   431 			    		// Remove target immediately
       
   432 			        	RemoveTargetElement();
       
   433 		    			}
       
   434 	    			}
       
   435 				// Not syncbased event
       
   436 	    		else if (evt->ObjectAddress() == iTargetElement)
       
   437 	    			{
       
   438 		    		// Remove target immediately
       
   439 		        	RemoveTargetElement();
       
   440 	    			}
       
   441 	    		}
       
   442         	} // if (s_evt == iBeginReferenceEvent)...
       
   443     	} //if ((aEvent->EventMask() == KSvgEventMaskInte...
       
   444     else
       
   445    		{
       
   446    		// Not interested event
       
   447     	return EFalse;
       
   448    		}
       
   449 
       
   450     // return true to be redrawn
       
   451     return ETrue;
       
   452     }
       
   453 
       
   454 
       
   455 // Setter functions
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // SetTargetId: Set iTargetId to the object. Mainly used by decoder.
       
   459 //
       
   460 // Returns: void
       
   461 // -----------------------------------------------------------------------------
       
   462 //
       
   463 void CSvgDiscardElementImpl::SetTargetId(const TDesC& aTargetId)
       
   464     {
       
   465     delete iTargetId;
       
   466     iTargetId = NULL;
       
   467     TRAPD(err, iTargetId = aTargetId.AllocL());
       
   468     if (err != KErrNone)
       
   469         {
       
   470         // Only display error message. If this failed, iTargetId can safely to be null.
       
   471         #ifdef _DEBUG
       
   472             RDebug::Printf("CSvgDiscardElementImpl::SetTargetId Error: memory allocation failed.");
       
   473         #endif
       
   474         }
       
   475     }
       
   476 
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // SetSyncValueDefined: Set iSyncValueDefined to the object. Mainly used by decoder.
       
   480 //
       
   481 // Returns: void
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 void CSvgDiscardElementImpl::SetSyncValueDefined(TBool aSyncValueDefined)
       
   485     {
       
   486     iSyncValueDefined = aSyncValueDefined;
       
   487     }
       
   488 
       
   489 
       
   490 
       
   491 // -----------------------------------------------------------------------------
       
   492 // SetEventValueDefined: Set iEventValueDefined to the object. Mainly used by decoder.
       
   493 //
       
   494 // Returns: void
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 void CSvgDiscardElementImpl::SetEventValueDefined(TBool aEventValueDefined)
       
   498     {
       
   499     iEventValueDefined = aEventValueDefined;
       
   500     }
       
   501 
       
   502 
       
   503 // -----------------------------------------------------------------------------
       
   504 // SetHrefValueDefined: Set iHrefValueDefined to the object. Mainly used by decoder.
       
   505 //
       
   506 // Returns: void
       
   507 // -----------------------------------------------------------------------------
       
   508 //
       
   509 void CSvgDiscardElementImpl::SetHrefValueDefined(TBool aHrefValueDefined)
       
   510     {
       
   511     iHrefValueDefined = aHrefValueDefined;
       
   512     }
       
   513 
       
   514 
       
   515 // -----------------------------------------------------------------------------
       
   516 // SetBeginSyncElementId: Set aBeginSyncElementId to the object. Mainly used by decoder.
       
   517 //
       
   518 // Returns: void
       
   519 // -----------------------------------------------------------------------------
       
   520 //
       
   521 void CSvgDiscardElementImpl::SetBeginSyncElementId(const TDesC& aBeginSyncElementId)
       
   522     {
       
   523     iBeginSyncElementId.SetLength(0);
       
   524     iBeginSyncElementId.Append(aBeginSyncElementId);
       
   525     }
       
   526 
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // SetAbsoluteBeginTime: Set iAbsoluteBeginTime to the object. Mainly used by decoder.
       
   530 //
       
   531 // Returns: void
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 void CSvgDiscardElementImpl::SetAbsoluteBeginTime(TInt aAbsoluteBeginTime)
       
   535     {
       
   536     if (aAbsoluteBeginTime == -1)
       
   537     	{
       
   538 	    iAbsoluteBeginTime = KTimeIndefinite;
       
   539     	}
       
   540     else
       
   541     	{
       
   542 	    iAbsoluteBeginTime = aAbsoluteBeginTime;
       
   543     	}
       
   544     }
       
   545 
       
   546 
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // SetRefBeginTime: Set aRefBeginTime to the object. Mainly used by decoder.
       
   550 //
       
   551 // Returns: void
       
   552 // -----------------------------------------------------------------------------
       
   553 //
       
   554 void CSvgDiscardElementImpl::SetRefBeginTime(TInt aRefBeginTime)
       
   555     {
       
   556     iRefBeginTime = aRefBeginTime;
       
   557     }
       
   558 
       
   559 
       
   560 
       
   561 // -----------------------------------------------------------------------------
       
   562 // SetKeyValue: Set aKeyValue to the object. Mainly used by decoder.
       
   563 //
       
   564 // Returns: void
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 void CSvgDiscardElementImpl::SetKeyValue(TInt aKeyValue)
       
   568     {
       
   569     iKeyValue = aKeyValue;
       
   570     }
       
   571 
       
   572 
       
   573 
       
   574 // -----------------------------------------------------------------------------
       
   575 // TargetId: Returns iBeginReferenceEvent that is specified in begin attribute.
       
   576 // Mainly used by encoder.
       
   577 //
       
   578 // Returns: void
       
   579 // -----------------------------------------------------------------------------
       
   580 //
       
   581 void CSvgDiscardElementImpl::SetBeginReferenceEvent(TSvgEvent aBeginReferenceEvent)
       
   582     {
       
   583     iBeginReferenceEvent = aBeginReferenceEvent;
       
   584     }
       
   585 
       
   586 
       
   587 // Getter functions
       
   588 
       
   589 // -----------------------------------------------------------------------------
       
   590 // TargetId: Returns the target element's id. Mainly used by encoder.
       
   591 //
       
   592 // Returns: Descriptor of target element's id
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 const TDesC& CSvgDiscardElementImpl::TargetId()
       
   596     {
       
   597     return (TDesC&) *iTargetId;
       
   598     }
       
   599 
       
   600 
       
   601 
       
   602 // -----------------------------------------------------------------------------
       
   603 // BeginSyncElementId: Returns element's id that is specified in begin attribute.
       
   604 // Mainly used by encoder.
       
   605 //
       
   606 // Returns: Descriptor of the element's id
       
   607 // -----------------------------------------------------------------------------
       
   608 //
       
   609 const TDesC& CSvgDiscardElementImpl::BeginSyncElementId()
       
   610     {
       
   611     return iBeginSyncElementId;
       
   612     }
       
   613 
       
   614 
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // AbsoluteBeginTime: Returns the absolute begin time that is identified in
       
   618 // SetAttribute. The begin time may be changed when using with SyncBase or
       
   619 // EventBased attribute.
       
   620 //
       
   621 // Mainly used by encoder.
       
   622 //
       
   623 // Returns: TInt AbsoluteBeginTime
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 TInt CSvgDiscardElementImpl::AbsoluteBeginTime()
       
   627     {
       
   628     if (iAbsoluteBeginTime == KTimeIndefinite)
       
   629     	{
       
   630     	// write -1 in case both encorder and decoder understand.
       
   631     	return -1;
       
   632     	}
       
   633     else
       
   634 		{
       
   635 	    return iAbsoluteBeginTime;
       
   636 		}
       
   637     }
       
   638 
       
   639 
       
   640 // -----------------------------------------------------------------------------
       
   641 // IsSyncValueDefined: Returns the flag iSyncValueDefined that was set in
       
   642 // SetAttribute.
       
   643 //
       
   644 // Mainly used by encoder.
       
   645 //
       
   646 // Returns: TBool iSyncValueDefined
       
   647 // -----------------------------------------------------------------------------
       
   648 //
       
   649 TBool CSvgDiscardElementImpl::IsSyncValueDefined()
       
   650     {
       
   651     return iSyncValueDefined;
       
   652     }
       
   653 
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // IsEventValueDefined: Returns the flag iEventValueDefined that was set in
       
   657 // SetAttribute.
       
   658 //
       
   659 // Mainly used by encoder.
       
   660 //
       
   661 // Returns: TBool iEventValueDefined
       
   662 // -----------------------------------------------------------------------------
       
   663 //
       
   664 TBool CSvgDiscardElementImpl::IsEventValueDefined()
       
   665     {
       
   666     return iEventValueDefined;
       
   667     }
       
   668 
       
   669 
       
   670 // -----------------------------------------------------------------------------
       
   671 // IsHrefValueDefined: Returns the flag iHrefValueDefined that was set in
       
   672 // SetAttribute.
       
   673 //
       
   674 // Mainly used by encoder.
       
   675 //
       
   676 // Returns: TBool iHrefValueDefined
       
   677 // -----------------------------------------------------------------------------
       
   678 //
       
   679 TBool CSvgDiscardElementImpl::IsHrefValueDefined()
       
   680     {
       
   681     return iHrefValueDefined;
       
   682     }
       
   683 
       
   684 
       
   685 // -----------------------------------------------------------------------------
       
   686 // RefBeginTime: Returns the reference begin time that was set in
       
   687 // SetAttribute.
       
   688 //
       
   689 // Mainly used by encoder.
       
   690 //
       
   691 // Returns: TInt iRefBeginTime
       
   692 // -----------------------------------------------------------------------------
       
   693 //
       
   694 TInt CSvgDiscardElementImpl::RefBeginTime()
       
   695     {
       
   696     return iRefBeginTime;
       
   697     }
       
   698 
       
   699 
       
   700 // -----------------------------------------------------------------------------
       
   701 // KeyValue: Returns the key value (scan code) that was set in
       
   702 // SetAttribute.
       
   703 //
       
   704 // Mainly used by encoder.
       
   705 //
       
   706 // Returns: TInt iKeyValue
       
   707 // -----------------------------------------------------------------------------
       
   708 //
       
   709 TInt CSvgDiscardElementImpl::KeyValue()
       
   710     {
       
   711     return iKeyValue;
       
   712     }
       
   713 
       
   714 
       
   715 // -----------------------------------------------------------------------------
       
   716 // KeyValue: Returns the iBeginReferenceEvent that was set in
       
   717 // SetAttribute.
       
   718 //
       
   719 // Mainly used by encoder.
       
   720 //
       
   721 // Returns: TSvgEvent iBeginReferenceEvent
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 TSvgEvent CSvgDiscardElementImpl::BeginReferenceEvent()
       
   725     {
       
   726     return iBeginReferenceEvent;
       
   727     }
       
   728 
       
   729 
       
   730 
       
   731 // -----------------------------------------------------------------------------
       
   732 // CloneL: Perform a deep clone of this object
       
   733 //
       
   734 // Returns: MXmlElement pointer to the newly created element.
       
   735 // -----------------------------------------------------------------------------
       
   736 //
       
   737 MXmlElement* CSvgDiscardElementImpl::CloneL(MXmlElement* aParentElement)
       
   738     {
       
   739 	CSvgDiscardElementImpl* newElement = CSvgDiscardElementImpl::NewL( this->ElemID(),
       
   740 	        ((CSvgDocumentImpl*)iOwnerDocument) );
       
   741 	CleanupStack::PushL(newElement);
       
   742 	newElement->iParentNode = aParentElement;
       
   743 
       
   744     // copy everything over
       
   745     this->CopyL(newElement);
       
   746     CleanupStack::Pop();
       
   747 
       
   748     return newElement;
       
   749     }
       
   750 
       
   751 
       
   752 // -----------------------------------------------------------------------------
       
   753 // CopyL: Perform a deep copy of this object
       
   754 //
       
   755 // Returns: none
       
   756 // -----------------------------------------------------------------------------
       
   757 //
       
   758 void CSvgDiscardElementImpl::CopyL( CSvgDiscardElementImpl* aDestElement )
       
   759     {
       
   760     if(aDestElement)
       
   761 	   	{
       
   762 	    aDestElement->iOwnerDocument = this->iOwnerDocument;
       
   763 		// copy stuff from superclass
       
   764 	    this->CSvgElementImpl::CopyL(aDestElement);
       
   765 	    }
       
   766     }
       
   767 
       
   768 // -----------------------------------------------------------------------------
       
   769 // Two-phased constructor.
       
   770 // -----------------------------------------------------------------------------
       
   771 //
       
   772 CSvgDiscardElementImpl* CSvgDiscardElementImpl::NewL( const TUint8 aElemID,
       
   773                                                       CSvgDocumentImpl* aDoc)
       
   774     {
       
   775     CSvgDiscardElementImpl* self = new (ELeave)CSvgDiscardElementImpl(aDoc);
       
   776     CleanupStack::PushL( self );
       
   777     self->ConstructL( aElemID );
       
   778     CleanupStack::Pop();
       
   779 
       
   780     return self;
       
   781     }
       
   782 
       
   783 // -----------------------------------------------------------------------------
       
   784 // Two-phased constructor.
       
   785 // -----------------------------------------------------------------------------
       
   786 //
       
   787 CSvgDiscardElementImpl* CSvgDiscardElementImpl::NewLC( const TUint8 aElemID,
       
   788                                                        CSvgDocumentImpl* aDoc)
       
   789     {
       
   790     CSvgDiscardElementImpl* self = new (ELeave) CSvgDiscardElementImpl(aDoc);
       
   791     CleanupStack::PushL( self );
       
   792     self->ConstructL( aElemID );
       
   793 
       
   794     return self;
       
   795     }
       
   796 
       
   797 // -----------------------------------------------------------------------------
       
   798 // C++ default constructor
       
   799 // -----------------------------------------------------------------------------
       
   800 //
       
   801 CSvgDiscardElementImpl::CSvgDiscardElementImpl( CSvgDocumentImpl* aDoc )
       
   802 	{
       
   803     SetOwnerDocument(aDoc);
       
   804     }
       
   805 
       
   806 
       
   807 // -----------------------------------------------------------------------------
       
   808 // Symbian default constructor that can leave.
       
   809 // -----------------------------------------------------------------------------
       
   810 //
       
   811 void CSvgDiscardElementImpl::ConstructL(  const TUint8 aElemID )
       
   812     {
       
   813     CXmlElementImpl::InitializeL( aElemID );
       
   814 
       
   815  	iTargetElement = NULL;
       
   816  	iTargetId = HBufC::NewL(0);
       
   817  	iAbsoluteBeginTime = 0;
       
   818  	iRemoveMyself = EFalse;
       
   819  	iHrefValueDefined = EFalse;
       
   820  	iBeginReferenceEvent = (TSvgEvent)NULL;
       
   821  	iSyncValueDefined = EFalse;
       
   822  	iEventValueDefined = EFalse;
       
   823  	iRefBeginTime = 0;
       
   824 	iRefTargetElement = NULL;
       
   825 	iRefBeginTimeSet = EFalse;
       
   826 	iKeyValue = 0;
       
   827 	iBeginSyncElementId.SetLength(0);
       
   828 
       
   829     ((CSvgDocumentImpl*)
       
   830     	iOwnerDocument)->AddToEventReceiverListL(this, KSvgEventMaskTimer |
       
   831     	    KSvgEventMaskInternal | KSvgEventMaskExternalUI);
       
   832     }
       
   833 
       
   834 
       
   835 // -----------------------------------------------------------------------------
       
   836 // Destructor
       
   837 // -----------------------------------------------------------------------------
       
   838 //
       
   839 CSvgDiscardElementImpl::~CSvgDiscardElementImpl()
       
   840     {
       
   841     delete iTargetId;
       
   842     }
       
   843 
       
   844 // -----------------------------------------------------------------------------
       
   845 // Print
       
   846 // -----------------------------------------------------------------------------
       
   847 //
       
   848 void CSvgDiscardElementImpl::Print( TBool aIsEncodeOn )
       
   849 {
       
   850 	if (!aIsEncodeOn)
       
   851 	{
       
   852 		#ifdef _DEBUG
       
   853 		RDebug::Printf("<discard xlink:href =\"hmm\" begin=\"%d\" />", /*Href(),*/ (int)iAbsoluteBeginTime);
       
   854 		#endif
       
   855 	}
       
   856 }
       
   857 
       
   858 //  End of File