svgtopt/SVG/SVGImpl/src/SVGAElementImpl.cpp
changeset 0 d46562c3d99d
equal deleted inserted replaced
-1:000000000000 0:d46562c3d99d
       
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  SVG Implementation source file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #if !defined(__E32BASE_H__)
       
    22 #include <e32base.h>
       
    23 #endif
       
    24 #include "SVGAElementImpl.h"
       
    25 #include "SVGElementImpl.h"
       
    26 #include "SVGDocumentImpl.h"
       
    27 #include "SVGEngineImpl.h"
       
    28 
       
    29 #include "GfxAffineTransform.h"
       
    30 #include "SVGGElementImpl.h"
       
    31 
       
    32 _LIT(TARGET, "target");
       
    33 _LIT(NEW, "new");
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // Two phase construction
       
    37 // ---------------------------------------------------------------------------
       
    38 CSvgAElementImpl* CSvgAElementImpl::NewL(  const TUint8 aElemID,
       
    39 										  CSvgDocumentImpl* aDoc )
       
    40 	{
       
    41 	CSvgAElementImpl*   self    = new ( ELeave ) CSvgAElementImpl( aDoc );
       
    42 	CleanupStack::PushL( self );
       
    43 	self->ConstructL(aElemID);
       
    44 	CleanupStack::Pop();
       
    45 
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 // ---------------------------------------------------------------------------
       
    52 CSvgAElementImpl* CSvgAElementImpl::NewLC(  const TUint8 aElemID,
       
    53 										   CSvgDocumentImpl* aDoc )
       
    54 	{
       
    55 	CSvgAElementImpl*   self    = new ( ELeave ) CSvgAElementImpl( aDoc );
       
    56 	CleanupStack::PushL( self );
       
    57 	self->ConstructL(aElemID);
       
    58 
       
    59 	return self;
       
    60 	}
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 // ---------------------------------------------------------------------------
       
    66 void CSvgAElementImpl::ConstructL( const TUint8 aElemID)
       
    67 	{
       
    68 	CSvgElementImpl::InitializeL( aElemID);
       
    69 
       
    70 	iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR);
       
    71 	User::LeaveIfError( iSvgStyleProperties->Append( NULL ) );
       
    72 	iSvgStyleProperties->Remove( 0 );
       
    73 
       
    74     iSvgTransformable = CSvgTransformableImpl::NewL();
       
    75 
       
    76     iSvgUriReferenceImpl = CSvgUriReferenceImpl::NewL();
       
    77 		iTarget = HBufC::NewL( 0 );
       
    78 
       
    79 	if (OwnerDocument())
       
    80 	{
       
    81 		((CSvgDocumentImpl*)OwnerDocument())->AddInternalMouseListener( this );
       
    82 	}
       
    83 
       
    84 
       
    85 	}
       
    86 
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 // ---------------------------------------------------------------------------
       
    92 CSvgAElementImpl::~CSvgAElementImpl()
       
    93 {
       
    94     if(iSvgUriReferenceImpl)
       
    95     	{
       
    96     	delete iSvgUriReferenceImpl;
       
    97     	iSvgUriReferenceImpl = NULL;
       
    98     	}
       
    99 
       
   100     if(iSvgStyleProperties)
       
   101 		{
       
   102 		iSvgStyleProperties->Close();
       
   103 		delete iSvgStyleProperties;
       
   104 		iSvgStyleProperties = NULL;
       
   105 		}
       
   106 		if (iTarget)
       
   107 		{
       
   108 			delete iTarget;
       
   109 			iTarget = NULL;
       
   110 		}
       
   111 
       
   112 	if (OwnerDocument())
       
   113 		{
       
   114 			((CSvgDocumentImpl*)OwnerDocument())->RemoveInternalMouseListener( this );
       
   115 		}
       
   116 }
       
   117 
       
   118 // Private
       
   119 
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 // ---------------------------------------------------------------------------
       
   124 
       
   125 CSvgAElementImpl::CSvgAElementImpl( CSvgDocumentImpl* aDoc ) : iInitDone( EFalse )
       
   126     {
       
   127 	SetOwnerDocument(aDoc);
       
   128     }
       
   129 
       
   130 
       
   131 // *******************************************************
       
   132 // From MXmlElement
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 // ---------------------------------------------------------------------------
       
   137 TInt CSvgAElementImpl::SetAttributeL( const TDesC& aName, const TDesC& aValue )
       
   138     {
       
   139     if ( this->SetXlinkAttributeL( aName, aValue ) )
       
   140         {
       
   141         return KErrNone;
       
   142         }
       
   143    if ( SetTargetL( aName, aValue ))
       
   144    		{
       
   145    		return KErrNone;
       
   146    		}
       
   147 
       
   148 	CSvgElementImpl::SetAttributeL(aName,aValue);
       
   149 
       
   150     return KErrNone;
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 // ---------------------------------------------------------------------------
       
   156 
       
   157 TBool CSvgAElementImpl::SetTargetL( const TDesC& aName, const TDesC& aValue )
       
   158     {
       
   159 	if ( aName == TARGET )
       
   160         {
       
   161         if(iTarget)
       
   162 	        {
       
   163 	        delete iTarget;
       
   164 	        iTarget = NULL;
       
   165 	        }
       
   166 	       iTarget = aValue.AllocL();
       
   167         }
       
   168     else
       
   169         {
       
   170   		return EFalse;
       
   171         }
       
   172 
       
   173     return ETrue;
       
   174 
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 // ---------------------------------------------------------------------------
       
   180 const TDesC& CSvgAElementImpl::Target( )
       
   181 {
       
   182 	 if (iTarget)
       
   183 	 {
       
   184 	 		return *iTarget;
       
   185 	 }
       
   186 	 else
       
   187 	 {
       
   188     	return KNullDesC;
       
   189    }
       
   190 }
       
   191 
       
   192 // *******************************************************
       
   193 // From CSvgElementImpl
       
   194 
       
   195 // perform a deep clone of this object
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 // ---------------------------------------------------------------------------
       
   199 MXmlElement* CSvgAElementImpl::CloneL(MXmlElement*)
       
   200     {
       
   201     return NULL;
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 // ---------------------------------------------------------------------------
       
   207 TBool CSvgAElementImpl::DrawL( CGfx2dGc* /* aGc */,
       
   208                                CSvgElementImpl* /* aElement */ )
       
   209     {
       
   210     if ( !iInitDone )
       
   211         {
       
   212         // Add child elemenets as mouse event receiver to engine
       
   213         // so that child elements can fire ui internal event
       
   214         AddEventReceiverSubtreeL( this );
       
   215 
       
   216         // Add this as internal event receiver
       
   217         ((CSvgDocumentImpl*)iOwnerDocument)->AddToEventReceiverListL( this, KSvgEventMaskInternal);
       
   218 
       
   219 
       
   220         iInitDone = ETrue;
       
   221         }
       
   222 
       
   223     return ETrue;
       
   224     }
       
   225 
       
   226 
       
   227 // *******************************************************
       
   228 // From MSvgEventReceiver
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 // ---------------------------------------------------------------------------
       
   232 TBool CSvgAElementImpl::ReceiveEventL( MSvgEvent* aEvent )
       
   233     {
       
   234 
       
   235 	if( CSvgElementImpl::IsSVGEnginePaused())
       
   236     {
       
   237     	return EFalse;
       
   238     }
       
   239     // Receive internal UI click event on child elements only
       
   240     if ( aEvent->EventType() != ESvgEngineInternalEvent )
       
   241 		{
       
   242         return EFalse;
       
   243 		}
       
   244 
       
   245 	// Link activation process
       
   246     MSvgInternalEvent*  evt = ( MSvgInternalEvent* ) aEvent;
       
   247 
       
   248      if ( !IsChild( this, evt->ObjectAddress() ) )
       
   249 		{
       
   250         return EFalse;
       
   251 		}
       
   252 
       
   253 //////
       
   254 
       
   255 	CSvgEngineImpl* engine  = ( ( CSvgDocumentImpl* ) OwnerDocument() )->Engine();
       
   256  // Process the UI event on its child elements and propagate that event to its dependents
       
   257     switch ( evt->SvgEvent() )
       
   258         {
       
   259 
       
   260         case ESvgEventMousedown:
       
   261         case ESvgEventMouseup:
       
   262         case ESvgEventClick:
       
   263 		case ESvgEventActivate:
       
   264 		case ESvgEventMouseover:
       
   265 		case ESvgEventMousemove:
       
   266 		case ESvgEventFocusin:
       
   267 		case ESvgEventMouseout:
       
   268 		case ESvgEventFocusout:
       
   269             {
       
   270             TSvgInternalEvent   lEvt ( evt->SvgEvent(),
       
   271                                         ( CSvgElementImpl* )
       
   272                                              this );
       
   273             engine->ProcessEventL( 
       
   274                 ( CSvgDocumentImpl* ) OwnerDocument(), &lEvt );
       
   275 			}
       
   276         break;
       
   277 
       
   278         default:
       
   279         break;
       
   280         }
       
   281 
       
   282 ///////
       
   283 
       
   284 
       
   285 	// To activate only on mouse click event
       
   286     if ( evt->SvgEvent() != ESvgEventClick )
       
   287 		{
       
   288         return EFalse;
       
   289 		}
       
   290 
       
   291     // Linking behavior
       
   292 
       
   293 	TPtrC n(XlinkShow());
       
   294 
       
   295 	if (n == NEW)
       
   296 		{
       
   297 		engine->LinkRequestWithShow( Href(),XlinkShow() ); // ssb iHrefUri->Des());
       
   298 		}
       
   299 	else
       
   300 		{
       
   301 		engine->LinkRequest( Href() ); // ssb iHrefUri->Des());
       
   302 		}
       
   303 
       
   304 
       
   305 
       
   306     return EFalse;
       
   307     }
       
   308 
       
   309 
       
   310 // *******************************************************
       
   311 // Private methods
       
   312 //
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 // ---------------------------------------------------------------------------
       
   316 void CSvgAElementImpl::AddEventReceiverSubtreeL( CSvgElementImpl* aElement )
       
   317     {
       
   318     CSvgElementImpl*element = ( CSvgElementImpl* ) aElement->FirstChild();
       
   319     while ( element != NULL )
       
   320         {
       
   321 
       
   322         ((CSvgDocumentImpl*)iOwnerDocument)->AddToEventReceiverListL( element,
       
   323                                                 KSvgEventMaskExternalUI);
       
   324 
       
   325         AddEventReceiverSubtreeL( element );
       
   326         element = ( CSvgElementImpl * ) element->NextSibling();
       
   327         }
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 // ---------------------------------------------------------------------------
       
   333 TBool CSvgAElementImpl::IsChild( CSvgElementImpl* aSubtree,
       
   334                                  CSvgElementImpl* aElement )
       
   335     {
       
   336     CSvgElementImpl*element = ( CSvgElementImpl* ) aSubtree->FirstChild();
       
   337     if ( element != NULL )
       
   338         {
       
   339         do
       
   340             {
       
   341             if ( element == aElement || IsChild( element, aElement ) )
       
   342 				{
       
   343                 return ETrue;
       
   344 				}
       
   345             element = ( CSvgElementImpl * ) element->NextSibling();
       
   346             }
       
   347         while ( element != NULL );
       
   348         }
       
   349     return EFalse;
       
   350     }
       
   351 void CSvgAElementImpl::Reset(MSvgEvent* /*aEvent*/)
       
   352 {
       
   353 }
       
   354 
       
   355 TInt CSvgAElementImpl::SetAttributeDesL( const TInt aNameId,
       
   356                                              const TDesC& aValue )
       
   357     {
       
   358 	_LIT( KXlinkHref, "xlink:href" );
       
   359 	_LIT( KTarget, "target");
       
   360 
       
   361     switch ( aNameId )
       
   362         {
       
   363         case KAtrXlinkhref:
       
   364         SetAttributeL(KXlinkHref, aValue );
       
   365         break;
       
   366         case KAtrTarget:
       
   367         SetAttributeL(KTarget, aValue );
       
   368         break;
       
   369         default:
       
   370         return CSvgElementImpl::SetAttributeDesL( aNameId, aValue );
       
   371         }
       
   372     return KErrNone;
       
   373     }
       
   374 TInt CSvgAElementImpl::GetAttributeDes( const TInt aNameId,
       
   375                                                      TPtrC16& aValue )
       
   376 {
       
   377  if(aNameId == KAtrXlinkhref)
       
   378 	{
       
   379 	 aValue.Set( Href() );
       
   380 	 return KErrNone;
       
   381 	}
       
   382 	if (aNameId == KAtrTarget)
       
   383 	{
       
   384 		aValue.Set( Target() );
       
   385 		return KErrNone;
       
   386 	}
       
   387  return CSvgElementImpl::GetAttributeDes( aNameId, aValue );
       
   388 }
       
   389 
       
   390 /*** FROM MSvgMouseListener ***/
       
   391 // ---------------------------------------------------------------------------
       
   392 // mouse entered
       
   393 // ---------------------------------------------------------------------------
       
   394 TBool CSvgAElementImpl::MouseEntered( RPointerArray<CSvgElementImpl>& aElements,
       
   395                                     TInt /*aX*/, TInt /*aY*/ )
       
   396 {
       
   397 	CSvgEngineImpl* lEngine  = ( ( CSvgDocumentImpl* ) OwnerDocument() )->Engine();
       
   398 	
       
   399 	TInt lEleCnt = aElements.Count();
       
   400 	for (TInt i = 0; i < lEleCnt; i++ )
       
   401 	{
       
   402 		if ( aElements[i] == this )
       
   403 		{
       
   404 			lEngine->NotifyHyperlinkEntered(this);
       
   405 			return ETrue;
       
   406 		}
       
   407     }
       
   408 
       
   409 	return EFalse;
       
   410 }
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // Notified when the mouse pointer exits a visible svg element.
       
   414 // ---------------------------------------------------------------------------
       
   415 TBool CSvgAElementImpl::MouseExited( RPointerArray<CSvgElementImpl>& aElements,
       
   416                                    TInt /*aX*/, TInt /*aY*/ )
       
   417 {
       
   418 	CSvgEngineImpl* lEngine  = ( ( CSvgDocumentImpl* ) OwnerDocument() )->Engine();
       
   419 	
       
   420 	TInt lEleCnt = aElements.Count();
       
   421 	for (TInt i = 0; i < lEleCnt; i++ )
       
   422 	{
       
   423 		if ( aElements[i] == this )
       
   424 		{
       
   425 			lEngine->NotifyHyperlinkExited(this);
       
   426 			return ETrue;
       
   427 		}
       
   428     }
       
   429 
       
   430 	return EFalse;
       
   431 }
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // Notified when the mouse pointer is pressed down on visible svg element.
       
   435 // ---------------------------------------------------------------------------
       
   436 TBool CSvgAElementImpl::MouseMoved( RPointerArray<CSvgElementImpl>& /*aElements*/,
       
   437                                     TInt /*aX*/, TInt /*aY*/ )
       
   438 {
       
   439     return EFalse;
       
   440 }
       
   441 
       
   442 // ---------------------------------------------------------------------------
       
   443 // Notified when the mouse pointer is pressed down on visible svg element.
       
   444 // ---------------------------------------------------------------------------
       
   445 TBool CSvgAElementImpl::MousePressed( RPointerArray<CSvgElementImpl>& /*aElements*/,
       
   446                                     TInt /*aX*/, TInt /*aY*/ )
       
   447 {
       
   448 	return EFalse;
       
   449 }
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // Notified when the mouse pointer is released on on visible svg element.
       
   453 // ---------------------------------------------------------------------------
       
   454 TBool CSvgAElementImpl::MouseReleased( RPointerArray<CSvgElementImpl>& aElements,
       
   455                                     TInt /*aX*/, TInt /*aY*/ )
       
   456 {
       
   457 	CSvgEngineImpl* lEngine  = ( ( CSvgDocumentImpl* ) OwnerDocument() )->Engine();
       
   458 	
       
   459 	TInt lEleCnt = aElements.Count();
       
   460 	for (TInt i = 0; i < lEleCnt; i++ )
       
   461 	{
       
   462 		if ( aElements[i] == this )
       
   463 		{
       
   464 			lEngine->NotifyHyperlinkActivated(this);
       
   465 			return ETrue;
       
   466 		}
       
   467     }
       
   468 
       
   469     return EFalse;
       
   470 }
       
   471 
       
   472 void CSvgAElementImpl::GetUnscaledBBox( TGfxRectangle2D& aBbox )
       
   473 {
       
   474 	CSvgGElementImpl::GetGroupBoundingUnscaled( aBbox, this );
       
   475 }
       
   476 
       
   477 void CSvgAElementImpl::GetBBox( TGfxRectangle2D& aBbox )
       
   478 {
       
   479 	CSvgGElementImpl::GetGroupBounding( aBbox, this );
       
   480 }
       
   481 
       
   482 void CSvgAElementImpl::Print( TBool aIsEncodeOn )
       
   483 {
       
   484 	if (!aIsEncodeOn)
       
   485 	{
       
   486 		#ifdef _DEBUG
       
   487 		RDebug::Printf("<a xlink:href=\"hmm\">"/*, Href()*/);
       
   488 		#endif
       
   489 	}
       
   490 }