Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / animations / FUiAnim_VisualElementImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUiAnim_VisualElementImpl.cpp
20  * @brief       This file contains implementation of _VisualElementImpl class
21  *
22  * This file contains implementation _VisualElementImpl class.
23  */
24
25 #include <typeinfo>
26 #include <unique_ptr.h>
27 #include <FBaseString.h>
28 #include <FBaseSysLog.h>
29 #include <FGrpFloatPoint.h>
30 #include <FGrpFloatDimension.h>
31 #include <FGrpFloatRectangle.h>
32 #include <FGrpFloatMatrix4.h>
33 #include <FGrpBufferInfo.h>
34 #include <FBaseByteBuffer.h>
35 #include <FGrp_CanvasImpl.h>
36 #include <FUiAnimIVisualElementAnimationStatusEventListener.h>
37 #include <FUiAnimVisualElementPropertyAnimation.h>
38 #include <FUiAnimVisualElementAnimationGroup.h>
39 #include <FUiAnimVisualElementSurface.h>
40
41 #include <FUiAnimVisualElement.h>
42
43 #include "FUi_Rectanglef.h"
44 #include "FUi_CoordinateSystemUtils.h"
45
46 #include "FUiAnim_VisualElementImpl.h"
47 #include "FUiAnim_VisualElementCanvas.h"
48
49 #include "FUiAnim_VisualElementAnimationImpl.h"
50 #include "FUiAnim_VisualElementAnimationGroupImpl.h"
51 #include "FUiAnim_VisualElementValueAnimationImpl.h"
52 #include "FUiAnim_VisualElementPropertyAnimationImpl.h"
53 #include "FUiAnim_AnimationManager.h"
54 #include "FUiAnim_VisualElementSharedData.h"
55 #include "FUiAnim_RootVisualElement.h"
56 #include "FUiAnim_ControlVisualElement.h"
57 #include "FUiAnim_MatrixUtil.h"
58 #include "FUiAnim_Debug.h"
59 #include "FUiAnim_EflNode.h"
60 #include "FUiAnim_VisualElementSurfaceImpl.h"
61 #include "FUiAnim_EflVisualElementSurfaceImpl.h"
62 #include "FUiAnim_DisplayManager.h"
63
64
65 using namespace std;
66 using namespace Tizen::Base;
67 using namespace Tizen::Base::Collection;
68 using namespace Tizen::Graphics;
69 using namespace Tizen::Ui;
70
71 #define LAZY_EVALUATION // lazy updating and reconfiguring.
72 #define IMPLICIT_ANIMATION_IMPL  //prototyping implicit animation.
73 //#define       MANUAL_PROPERTY_CHANGE_NOTIFICATION
74
75 #define IS_INTERNAL_CLASS(_PUBLIC) (likely(typeid(*(_PUBLIC)) == VeTypeId) || likely(typeid(*(_PUBLIC)) == internalVeTypeId) || likely(typeid(*(_PUBLIC)) == controlVeTypeId) || likely(typeid(*(_PUBLIC)) == rootVeTypeId))
76 #define IS_NEEDED_UPDATE_PRESENTATION(__MODEL)  (((__MODEL)->__isPropertyPropagationEnabled) && ((__MODEL)->__pPresentation))
77 namespace {
78
79 static const char* STR_ERROR_INVALID_VARIANT_ARG_TYPE = "[E_INVALID_ARG] Invalid argument(s) is used. Variant type is invalid.";
80
81 void
82 CalculateBoundingBox(const float x[4], const float y[4], Tizen::Graphics::FloatRectangle& rectangle)
83 {
84         float minX = x[0];
85         float minY = y[0];
86         float maxX = minX;
87         float maxY = minY;
88         for (int i = 1; i < 4; i++)
89         {
90                 if (x[i] < minX)
91                         minX = x[i];
92
93                 if (y[i] < minY)
94                         minY = y[i];
95
96                 if (x[i] > maxX)
97                         maxX = x[i];
98
99                 if (y[i] > maxY)
100                         maxY = y[i];
101         }
102
103         rectangle.x = minX;
104         rectangle.y = minY;
105         rectangle.width = maxX - minX;
106         rectangle.height = maxY - minY;
107 }
108
109
110 }
111
112 namespace Tizen { namespace Ui { namespace Animations
113 {
114 // rules of visual element.
115 //
116 // 1. almost controlling pSharedData occurred in the PRESENTATION layer.
117 // 2. almost Delegate's methods occurred in the MODEL layer.
118 //
119
120 #define SHOWOPACITY_VISIBLE(so) \
121         (so != 0.0f)
122
123 #define VE_VISIBLE(o)                   \
124         SHOWOPACITY_VISIBLE((o)->__showOpacity)
125
126 #define HAVE_SURFACE(o)                 \
127         (likely((o)->GetSharedData().pSurface))
128
129 //TODO: require further examination : __NeedSurface() instead of NEED_SURFACE() macro
130 #define NEED_SURFACE(o)                 \
131         (likely((o)->GetSharedData().needSurface))
132
133 #define IS_ATTACHED(o)                  \
134         ((o)->GetRoot() != null)
135
136 #define IS_PRESENTATION(o)              \
137         ((o)->__pPresentation == (o))
138
139 #define IS_MODEL(o)                             \
140         ((o)->__pModel == (o))
141
142 #define VE_DELEGATE(target, func, ...)  \
143                 (target)->func(__VA_ARGS__)
144
145
146
147 static const std::type_info& VeTypeId = typeid(VisualElement);
148 static const std::type_info& rootVeTypeId = typeid(_RootVisualElement);
149 static const std::type_info& internalVeTypeId = typeid(_VisualElement);
150 static const std::type_info& controlVeTypeId = typeid(_ControlVisualElement);
151
152 // declared AnimationEventListener for implicit animation
153 class _VisualElementImplicitAnimationEventListener
154         : public IVisualElementAnimationStatusEventListener
155         , virtual public Tizen::Base::Runtime::IEventListener
156 {
157 public:
158         _VisualElementImplicitAnimationEventListener(void) {}
159         virtual ~_VisualElementImplicitAnimationEventListener(void) {}
160
161         virtual void OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target) {}
162         virtual void OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount) {}
163         virtual void OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
164         {
165                 target.Destroy();
166                 delete this;
167         }
168 };
169
170 IMPLEMENT_PROPERTY(_VisualElementImpl);
171
172 _VisualElementImpl::_VisualElementImpl(VisualElement& element)
173         : _zOrderGroup(Z_ORDER_GROUP_NORMAL)
174         , __pSharedData(null)
175         , __pParent(null)
176         , __pModel(null)
177         , __pPresentation(null)
178         , __pRoot(null)
179         , __isRoot(false)
180         , __isVisible(false)
181         , __showOpacity(0.0f)
182         , __needRecreateSurface(false)
183         , __bounds(0.0f, 0.0f, 0.0f, 0.0f)
184         , __alignedSize(0.0f, 0.0f)
185         , __contentBounds(0.0f, 0.0f, 1.0f, 1.0f)
186         , __useContentBounds(false)
187         , __zPosition(0.0f)
188         , __contentOpacity(1.0f)
189         , __opacity(1.0f)
190         , __anchor(0.5f, 0.5f)
191         , __anchorZ(0.0f)
192         , __transform()
193         , __decomposedTransform()
194         , __childrenTransform()
195         , __decomposedChildrenTransform()
196         , __childrenNeedsUpdateProps(HIERARCHY_PROPERTY_MASK & ~HIERARCHY_PROPERTY_CONTENT)
197         , __invalidatedProps(HIERARCHY_PROPERTY_MASK& ~HIERARCHY_PROPERTY_CONTENT)
198         , __matrixFromTopValid(false)
199         , __matrixFromTopInvertible(true)
200         , __matrixToSuperValid(false)
201         , __matrixToTopValid(false)
202         , __matrixToClipSourceValid(false)
203         , __boundingBoxValid(false)
204         , __visibleRectValid(false)
205         , __needTransform(false)
206         , __needClipForUntransformed(false)
207         , __isImplicitAnimationEnabled(true)
208         , __isClipChildren(false)
209         , __boundingBox(0.0f, 0.0f, 0.0f, 0.0f)
210         , __pClipSource(null)
211         , __visibleRect(0.0f, 0.0f, 0.0f, 0.0f)
212         , __isPropertyPropagationEnabled(true)
213         , __isDestroying(false)
214         , __isHidingParent(false)
215         , __isInternal(false)
216         , __isAllowedTreeModification(true)
217         , __pPublicInstance(&element)
218         , __imageFilePath()
219         , __renderOperation(VisualElement::RENDER_OPERATION_BLEND)
220         , __pBoundsChangedCallback(null)
221         , __pBoundsChangedCallbackData(null)
222 {
223         ClearLastResult();
224
225         __children.Construct();
226 }
227
228 _VisualElementImpl::_VisualElementImpl(VisualElement& presentation, _VisualElementImpl& modelImpl)
229         : _zOrderGroup(modelImpl._zOrderGroup)
230         , __pSharedData(null)
231         , __pParent(null)
232         , __pModel(null)
233         , __pPresentation(null)
234         , __pRoot(null)
235         , __isRoot(modelImpl.__isRoot)
236         , __isVisible(modelImpl.__isVisible)
237         , __showOpacity(modelImpl.__showOpacity)
238         , __needRecreateSurface(false)
239         , __bounds(modelImpl.__bounds)
240         , __alignedSize(modelImpl.__alignedSize)
241         , __contentBounds(modelImpl.__contentBounds)
242         , __useContentBounds(modelImpl.__useContentBounds)
243         , __zPosition(modelImpl.__zPosition)
244         , __contentOpacity(modelImpl.__contentOpacity)
245         , __opacity(modelImpl.__opacity)
246         , __anchor(modelImpl.__anchor)
247         , __anchorZ(modelImpl.__anchorZ)
248         , __transform(modelImpl.__transform)
249         , __decomposedTransform(modelImpl.__decomposedTransform)
250         , __childrenTransform(modelImpl.__childrenTransform)
251         , __decomposedChildrenTransform(modelImpl.__decomposedChildrenTransform)
252         , __childrenNeedsUpdateProps(HIERARCHY_PROPERTY_MASK & ~HIERARCHY_PROPERTY_CONTENT)
253         , __invalidatedProps(HIERARCHY_PROPERTY_MASK & ~HIERARCHY_PROPERTY_CONTENT)
254         , __matrixFromTopValid(false)
255         , __matrixFromTopInvertible(true)
256         , __matrixToSuperValid(false)
257         , __matrixToTopValid(false)
258         , __matrixToClipSourceValid(false)
259         , __boundingBoxValid(false)
260         , __visibleRectValid(false)
261         , __needTransform(modelImpl.__needTransform)
262         , __needClipForUntransformed(modelImpl.__needClipForUntransformed)
263         , __isImplicitAnimationEnabled(modelImpl.__isImplicitAnimationEnabled)
264         , __isClipChildren(modelImpl.__isClipChildren)
265         , __boundingBox(0.0f, 0.0f, 0.0f, 0.0f)
266         , __pClipSource(null)
267         , __visibleRect(0.0f, 0.0f, 0.0f, 0.0f)
268         , __isPropertyPropagationEnabled(false) // it differs from the property of MODEL object
269         , __isDestroying(false)
270         , __isHidingParent(modelImpl.__isHidingParent)
271         , __isInternal(modelImpl.__isInternal)
272         , __isAllowedTreeModification(true)
273         , __pPublicInstance(&presentation)
274         , __imageFilePath(modelImpl.__imageFilePath)
275         , __renderOperation(modelImpl.__renderOperation)
276         , __pBoundsChangedCallback(modelImpl.__pBoundsChangedCallback)
277         , __pBoundsChangedCallbackData(modelImpl.__pBoundsChangedCallbackData)
278 {
279         ClearLastResult();
280
281         //GetSharedData().AddRef();
282
283         __children.Construct();
284
285         //GetSharedData().invalidatedNativeProps = HIERARCHY_PROPERTY_MASK;
286
287         // for MODEL object
288         //modelImpl.__pPresentation = this;
289 }
290
291 _VisualElementImpl::~_VisualElementImpl(void)
292 {
293         ClearLastResult();
294         // clear data after detaching children
295         if (likely(__pSharedData))
296         {
297                 __pSharedData->Release();
298                 __pSharedData = null;
299         }
300
301         // remove public instance
302         __pPublicInstance = null;
303
304
305         // Remove property observer finally
306 //      if (IsPropertyChangeEventListenerAdded())
307 //      {
308 //              RemovePropertyChangeEventListener(_VisualElementModelObserver::GetInstance());
309 //      }
310 }
311
312 void
313 _VisualElementImpl::Destroy(void)
314 {
315         //SysLog(NID_UI_ANIM, "destruct[%x]-->begin", this);
316
317         if (unlikely(__isDestroying))
318         {
319                 return;
320         }
321
322         __isDestroying = true;
323
324
325         // WARNING:
326         //      Destroy and its callback will be called from the leaf of hiearchy tree first.
327         //      That is, this method first destroys children(Destroy and OnDestructing), and it destroys itself later.
328
329         while (__children.GetCount() > 0)
330         {
331                 _VisualElementImpl* pChild = __children.GetChildAt(0);
332                 if (likely(pChild))
333                 {
334                         //pChild->RemoveFromParent();
335                         //or
336                         if (likely(pChild->__pPublicInstance))
337                         {
338                                 pChild->__pPublicInstance->Destroy();
339                         }
340                         else
341                         {
342                                 SysAssertf(false, "VisualElement does not have public instance.");
343                         }
344
345                 }
346                 else
347                 {
348                         SysAssertf(false, "VisualElement has no child.");
349                 }
350
351         }
352
353
354         // CHECKME:
355         //      Is this right place for invoking 'OnDestructing' ?
356         //      OnConstructed will be called from public instance.
357
358         if (!IS_PRESENTATION(this))
359         {
360                 VE_DELEGATE(this, InvokeOnDestructing);
361         }
362
363
364         RemoveFromParent();
365
366
367         if (IS_MODEL(this))
368         {
369                 if (likely(__pPresentation))
370                 {
371                         __pPresentation->__pPublicInstance->Destroy();
372                 }
373                 __pPresentation = null;
374         }
375         else
376         {
377                 _AnimationManager::GetInstance()->RemoveAllAnimations(*__pPublicInstance);
378
379                 __pModel = null;
380         }
381
382         delete this;
383 }
384
385 result
386 _VisualElementImpl::Construct(void)
387 {
388         result r = E_SUCCESS;
389         __pSharedData = new (std::nothrow) _VisualElementSharedData;
390         SysTryCatch(NID_UI_ANIM, __pSharedData, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
391         SysTryCatch(NID_UI_ANIM, GetSharedData().Construct() == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] failed in shared data constructing.");
392
393         __pModel = this;
394         __pPresentation = null;
395         //SysLog(NID_UI_ANIM, "Created(efl=%p)", GetSharedData().pNativeNode);
396
397 #if 0 // REMOVED : We should invoke property observer method manually.
398         if (__isPropertyPropagationEnabled)
399         {
400                 AddPropertyChangeEventListener(_VisualElementModelObserver::GetInstance());
401         }
402 #endif
403
404         //VE_DELEGATE(this, InvokeOnConstructed);
405
406         return E_SUCCESS;
407
408
409 CATCH:
410         if (likely(__pSharedData))
411         {
412                 GetSharedData().Release();
413                 __pSharedData = null;
414         }
415
416         return r;
417 }
418
419 IVisualElementAnimationProvider*
420 _VisualElementImpl::GetAnimationProvider(void) const
421 {
422         ClearLastResult();
423         SysTryReturn(NID_UI_ANIM, IS_MODEL(this), null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] VisualElement is not Model object.");
424
425         return GetSharedData().pAnimationProvider;
426 }
427
428 result
429 _VisualElementImpl::SetAnimationProvider(IVisualElementAnimationProvider* pProvider)
430 {
431         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
432
433         GetSharedData().pAnimationProvider = pProvider;
434
435         return E_SUCCESS;
436 }
437
438 IVisualElementContentProvider*
439 _VisualElementImpl::GetContentProvider(void) const
440 {
441         ClearLastResult();
442         SysTryReturn(NID_UI_ANIM, IS_MODEL(this), null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] VisualElement is not Model object.");
443
444         return GetSharedData().pContentProvider;
445 }
446
447 result
448 _VisualElementImpl::SetContentProvider(IVisualElementContentProvider* pProvider)
449 {
450         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
451
452         GetSharedData().pContentProvider = pProvider;
453
454         return E_SUCCESS;
455 }
456
457 IVisualElementEventListener*
458 _VisualElementImpl::GetVisualElementEventListener(void) const
459 {
460         ClearLastResult();
461         SysTryReturn(NID_UI_ANIM, IS_MODEL(this), null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] VisualElement is not Model object.");
462
463         return GetSharedData().pEventListener;
464 }
465
466 result
467 _VisualElementImpl::SetVisualElementEventListener(IVisualElementEventListener* pListener)
468 {
469         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
470
471         GetSharedData().pEventListener = pListener;
472
473         return E_SUCCESS;
474 }
475
476 result
477 _VisualElementImpl::FlushI(void)
478 {
479 #ifdef VE_VSYNC_UPDATE
480         _DisplayManager::GetInstance()->RenderAll();
481 #endif
482
483         return _DisplayManager::GetInstance()->Flush();
484 }
485
486 result
487 _VisualElementImpl::SetImageSource(const String& filePath)
488 {
489         RebuildHierarchyProps(0, true, true);
490
491         SysTryReturnResult(NID_UI_ANIM, HAVE_SURFACE(this), E_SYSTEM, "Realizing back-buffer surface failed.");
492
493         result r = GetSharedData().SetImage(filePath);
494         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
495
496         __imageFilePath = filePath;
497
498         return r;
499 }
500
501
502 bool
503 _VisualElementImpl::CreateImplicitAnimationIfNeeded( const String& property,
504                 const Variant& newValue, const Variant& currentPresentationValue, const String** pSubProperties)
505 {
506         bool r = true;
507
508         _AnimationManager* pAnimationManager = _AnimationManager::GetInstance();
509
510         if (likely(GetRoot())
511                 && likely(GetSharedData().needSurface)
512                 && (unlikely(pAnimationManager->IsImplicitAnimationEnabled() && __isImplicitAnimationEnabled))  )
513         {
514                 // WARNING:
515                 //      For performance, following must be done only when oldValue != newValue.
516                 VisualElementAnimation* pAnimation = InvokeCreateAnimationForProperty(property);
517
518                 // user can make other type animation like aAnimationGroup or ValueAnimation
519                 // in this case pPropertyAnimation will have a null value.
520                 VisualElementPropertyAnimation* pPropertyAnimation = dynamic_cast< VisualElementPropertyAnimation* >(pAnimation);
521                 if (likely(pPropertyAnimation))
522                 {
523                         if (pPropertyAnimation->GetEndValue().IsEmpty())
524                         {
525                                 pPropertyAnimation->SetEndValue(newValue);
526                         }
527
528                         if (pPropertyAnimation->GetStartValue().IsEmpty())
529                         {
530                                 pPropertyAnimation->SetStartValue(currentPresentationValue);
531                         }
532                 }
533
534                 if(pSubProperties)
535                 { // remove sub property
536                         for(int i = 0 ; pSubProperties[i] != NULL ; i++)
537                         {
538                                         pAnimationManager->RemoveAnimationForProperty(*__pPublicInstance, *pSubProperties[i]);
539                         }
540                 }
541                 if (unlikely(pAnimation))
542                 {
543                         /// WARNING:
544                         //      Adding property animation causes previous animation for same property to be removed in Animation Manager.
545                         if (unlikely(IsFailed(AddAnimation(null, *pAnimation))))
546                         {
547                                 pAnimationManager->RemoveAnimationForProperty(*__pPresentation->__pPublicInstance, property);
548                                 r = false;
549                         }
550
551                         delete pAnimation;
552                 }
553                 else
554                 {
555                         // WARNING:
556                         //      Remove previous animation even when trying to change the property without animation.
557                         pAnimationManager->RemoveAnimationForProperty(*__pPresentation->__pPublicInstance, property);
558                         r = false;
559                 }
560         }
561         else
562         {
563                 pAnimationManager->RemoveAnimationForProperty(*__pPresentation->__pPublicInstance, property);
564                 r = false;
565         }
566         return r;
567 }
568
569
570 result
571 _VisualElementImpl::SetRenderOperation(VisualElement::RenderOperation renderOperation)
572 {
573         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
574
575         result r = InvokeOnSetPropertyRequested(*pVePropRenderOperation, Variant(static_cast< int >(renderOperation)));
576         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
577
578         return r;
579 }
580
581 VisualElement::RenderOperation
582 _VisualElementImpl::GetRenderOperation(void) const
583 {
584         ClearLastResult();
585
586 #if 0
587         int renderOperation = InvokeOnGetPropertyRequested(*pVePropRenderOperation).ToInt();
588         if (GetLastResult() != E_SUCCESS)
589         {
590                 return VisualElement::RENDER_OPERATION_BLEND;
591         }
592
593         return static_cast< VisualElement::RenderOperation >(renderOperation);
594 #else
595         return __renderOperation;
596 #endif
597 }
598
599 Variant
600 _VisualElementImpl::GetRenderOperationProperty(void) const
601 {
602         ClearLastResult();
603
604         return Variant(static_cast< int >(__renderOperation));
605 }
606
607 result
608 _VisualElementImpl::SetRenderOperationProperty(const Variant& v)
609 {
610         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_INT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
611
612         VisualElement::RenderOperation renderOperation = static_cast< VisualElement::RenderOperation >(v.ToInt());
613         if (likely(__renderOperation != renderOperation))
614         {
615                 SysTryReturnResult(
616                         NID_UI_ANIM,
617                         renderOperation >= VisualElement::RENDER_OPERATION_BLEND && renderOperation <= VisualElement::RENDER_OPERATION_COPY,
618                         E_INVALID_ARG,
619                         "Invalid argument(s) is used. The given render operation is out of range."
620                 );
621
622                 __renderOperation = renderOperation;
623                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_OPACITY, false, false);
624         }
625         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
626         {
627                 __pPresentation->SetRenderOperationProperty(__renderOperation);
628         }
629
630         return E_SUCCESS;
631 }
632
633 bool
634 _VisualElementImpl::GetBackBufferEnabled(void) const
635 {
636         ClearLastResult();
637
638         return GetSharedData().needSurface;
639 }
640
641 result
642 _VisualElementImpl::SetBackBufferEnabled(bool enabled)
643 {
644         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
645
646         if (likely(GetSharedData().needSurface != enabled))
647         {
648                 /// WARNING:
649                 //      Need to check transform matrix if the transform matrix is complex(generic). In this case, disabling Backing-Buffer
650                 //      should not be allowed !
651                 //
652                 if (likely(NEED_SURFACE(this))) // may be redundant checking.... (or using !enabled). Check if this needs surface currently.
653                 {
654 //                      _Matrix3Df;
655 //                      __transform.Optimize();
656 //                      SysTryReturnResult(NID_UI_ANIM, !__transform.IsGeneric(), E_INVALID_STATE, "VisualElement cannot release back-buffer if transform isn't identity or translation.");
657
658                         Matrix4Type matrixType = _GetMatrix4Type(__transform);
659                         SysTryReturnResult(
660                                 NID_UI_ANIM,
661                                 matrixType == MATRIX4_Identity || matrixType == MATRIX4_Translation,
662                                 E_INVALID_STATE,
663                                 "VisualElement cannot release back-buffer if transform isn't identity nor translation."
664                         );
665                 }
666
667                 GetSharedData().needSurface = enabled;
668
669                 if (NEED_SURFACE(this))
670                 {
671                         ExposeRectangle(null, true);
672                 }
673                 else
674                 {
675                         InvalidateVisibleRectToRenderTarget(null);
676                 }
677
678                 SetSurfaceChanged();
679         }
680
681         return E_SUCCESS;
682 }
683
684 bool
685 _VisualElementImpl::GetRedrawOnResizeEnabled(void) const
686 {
687         ClearLastResult();
688
689         return GetSharedData().redrawOnResize;
690 }
691
692 result
693 _VisualElementImpl::SetRedrawOnResizeEnabled(bool enabled)
694 {
695         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
696
697         GetSharedData().redrawOnResize = enabled;
698
699         return E_SUCCESS;
700 }
701
702 bool
703 _VisualElementImpl::GetPropertyPropagationEnabled(void) const
704 {
705         ClearLastResult();
706
707         // TBD: forward using property or direct return ?
708 #if 0
709         bool isPropertyPropagationEnabled = InvokeOnGetPropertyRequested(*pVePropPropertyPropagationEnabled).ToBool();
710         if (GetLastResult() != E_SUCCESS)
711         {
712                 return false;
713         }
714
715         return isPropertyPropagationEnabled;
716 #else
717         return __isPropertyPropagationEnabled;
718 #endif
719 }
720
721 result
722 _VisualElementImpl::SetPropertyPropagationEnabledI(bool enable)
723 {
724         if (unlikely(enable == __isPropertyPropagationEnabled))
725         {
726                 return E_SUCCESS;
727         }
728
729         __isPropertyPropagationEnabled = enable;
730
731 //      if (IS_MODEL(this))
732 //      {
733 //              if (__isPropertyPropagationEnabled)
734 //              {
735 //                      AddPropertyChangeEventListener(_VisualElementModelObserver::GetInstance());
736 //              }
737 //              else
738 //              {
739 //                      RemovePropertyChangeEventListener(_VisualElementModelObserver::GetInstance());
740 //              }
741 //      }
742
743         return E_SUCCESS;
744 }
745
746 result
747 _VisualElementImpl::SetPropertyPropagationEnabled(bool enable)
748 {
749         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
750         if (enable == __isPropertyPropagationEnabled)
751                 return E_SUCCESS;
752
753         result r = InvokeOnSetPropertyRequested(*pVePropPropertyPropagationEnabled, Variant(enable));
754         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
755
756         return r;
757 }
758
759 Variant
760 _VisualElementImpl::GetPropertyPropagationProperty(void) const
761 {
762         ClearLastResult();
763
764         return Variant(__isPropertyPropagationEnabled);
765 }
766
767 result
768 _VisualElementImpl::SetPropertyPropagationProperty(const Variant& v)
769 {
770         // TODO:
771         //      Remove this from property. It is used as a property because of _ControlVisualElement when a control was made up of three VEs.
772         if (IS_PRESENTATION(this))
773                 return E_SUCCESS;
774
775         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
776
777         return SetPropertyPropagationEnabledI(v.ToBool());
778 }
779
780 bool
781 _VisualElementImpl::IsSurfaceNeeded(void) const
782 {
783 //       TBD: root VE must have surface always...
784         if (unlikely(!__pParent))
785         {
786                 return true;
787         }
788
789 #if 0
790         const _VisualElementImpl* pCurrent;
791
792         pCurrent = this;
793         while (pCurrent)
794         {
795                 if (!pCurrent->__pSharedData)
796                 {
797                         return false;
798                 }
799
800                 if (!pCurrent->GetSharedData().needSurface)
801                 {
802                         return true;
803                 }
804
805                 pCurrent = pCurrent->__pParent;
806         }
807
808         return false;
809 #else
810         return GetSharedData().needSurface;
811 #endif
812 }
813
814 void
815 _VisualElementImpl::RebuildSurfaces(void)
816 {
817         if (unlikely(!IS_PRESENTATION(this)) || unlikely(!IS_ATTACHED(this)))
818         {
819                 return;
820         }
821
822         ResetSurfaceIfNeeded();
823
824         int count = __children.GetCount();
825         for (int i = 0; i < count; i++)
826         {
827                 __children.GetChildAt(i)->RebuildSurfaces();
828         }
829 }
830
831 void
832 _VisualElementImpl::ResetSurfaceIfNeeded(void)
833 {
834         if (unlikely(!__needRecreateSurface))
835         {
836                 return;
837         }
838
839         __needRecreateSurface = false;
840
841
842         if (unlikely(HAVE_SURFACE(this)) && unlikely(GetSharedData().fixedSurfaceSize))
843         {
844                 return;
845         }
846
847
848         _VisualElementImpl* pPresentation = null;
849
850         if (likely(__pPresentation))
851         {
852                 pPresentation = __pPresentation;
853         }
854         else
855         {
856                 pPresentation = this;
857         }
858
859
860         if (likely(IsSurfaceNeeded()))
861         {
862                 if (GetRoot())
863                 {
864                         _RootVisualElement* pRoot = dynamic_cast<_RootVisualElement*>(GetRoot()->GetPublic());
865
866                         if (pRoot && pRoot->GetNativeLayer())
867                         {
868                                 GetSharedData().fixedSurfaceSize = false;
869
870                                 float surfaceWidth = __bounds.width;
871                                 float surfaceHeight = __bounds.height;
872
873                                 AdjustSizeForSurface(surfaceWidth, surfaceHeight);
874
875                                 if (likely(GetSharedData().CreateSurface(Dimension(static_cast< int >(surfaceWidth), static_cast< int >(surfaceHeight)), *pRoot->GetNativeLayer()) == E_SUCCESS))
876                                 {
877                                         if (unlikely(!HAVE_SURFACE(this)))
878                                         {
879                                                 pPresentation->InvalidateVisibleRectToRenderTarget(null);
880                                         }
881
882                                         SetSurfaceChanged();
883                                 }
884                         }
885                 }
886         }
887         else // surface not needed, so remove Surface
888         {
889                 if (unlikely(HAVE_SURFACE(this)))
890                 {
891                         GetSharedData().RemoveSurface(*pPresentation);
892                         SetSurfaceChanged();
893                 }
894         }
895 }
896
897 _VisualElementImpl*
898 _VisualElementImpl::GetRenderTarget(void) const
899 {
900         _VisualElementImpl* pRenderTarget = const_cast< _VisualElementImpl* >(this);
901
902         while (likely(pRenderTarget))
903         {
904                 if (likely(NEED_SURFACE(pRenderTarget)))
905                 {
906                         return pRenderTarget;
907                 }
908
909                 pRenderTarget = pRenderTarget->__pParent;
910         }
911
912         return null;
913 }
914
915 VisualElementSurface*
916 _VisualElementImpl::GetSurfaceN(void) const
917 {
918         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
919         pThis->RebuildHierarchyProps(0, true, true);
920
921         SysTryReturn(NID_UI_ANIM, pThis->IsSurfaceNeeded() && HAVE_SURFACE(pThis), null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Realizing back-buffer surface failed.");
922
923         VisualElementSurface* pSurface = new (std::nothrow) VisualElementSurface(*pThis->GetSharedData().pSurface);
924         SysTryReturn(NID_UI_ANIM, pSurface, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
925
926         ClearLastResult();
927
928         return pSurface;
929 }
930
931 result
932 _VisualElementImpl::SetSurface(const VisualElementSurface* pSurface)
933 {
934         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
935         SysTryReturnResult(NID_UI_ANIM, NEED_SURFACE(this), E_INVALID_OPERATION, "A surface cannot be set if VisualElement need no back-buffer.");
936
937         if (unlikely(pSurface == GetSharedData().pSurface))
938         {
939                 return E_SUCCESS;
940         }
941
942         if (likely(pSurface) && likely(GetSharedData().pSurface))
943         {
944                 if (unlikely(pSurface->Equals(*GetSharedData().pSurface)))
945                         return E_SUCCESS;
946         }
947
948         if (likely(pSurface))
949         {
950                 unique_ptr<VisualElementSurface> pTempSurface(new (std::nothrow) VisualElementSurface(*pSurface));
951                 SysTryReturnResult(NID_UI_ANIM, pTempSurface, E_OUT_OF_MEMORY, "Memory allocation failed.");
952
953                 // Delete the old surface
954                 if (GetSharedData().pSurface)
955                 {
956                         delete GetSharedData().pSurface;
957                 }
958
959                 GetSharedData().pSurface = pTempSurface.release();
960                 GetSharedData().fixedSurfaceSize = true;
961
962                 // Clear invalidated region if newly fixed-size surface is attached which do not need(inhibit) redrawing
963                 GetSharedData().invalidatedRegion.SetBounds(0.0f, 0.0f, __bounds.width, __bounds.height);
964         }
965         else
966         {
967                 // Delete the old surface
968                 if (GetSharedData().pSurface)
969                 {
970                         delete GetSharedData().pSurface;
971                 }
972
973                 __needRecreateSurface = true;
974
975                 GetSharedData().pSurface = null;
976                 GetSharedData().fixedSurfaceSize = false;
977
978                 // Fully invalidate because new surface should be allocated and redrawn
979                 GetSharedData().invalidatedRegion.SetBounds(0.0f, 0.0f, __bounds.width, __bounds.height);
980         }
981
982
983         SetSurfaceChanged();
984
985         return E_SUCCESS;
986 }
987
988 void
989 _VisualElementImpl::SetSurfaceChanged(void)
990 {
991         GetSharedData().surfaceChanged = true;
992
993         if (likely(!IS_PRESENTATION(this)))
994         {
995                 if(__pPresentation)
996                 {
997                         __pPresentation->InvalidateHierarchyProps(HIERARCHY_PROPERTY_SURFACE, false, false);
998                 }
999         }
1000         else
1001         {
1002                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_SURFACE, false, false);
1003         }
1004 }
1005
1006 result
1007 _VisualElementImpl::SetContentBoundsI(const FloatRectangle& contentBounds)
1008 {
1009 //      const Dimension& surfaceSize = GetSharedData().pSurface->GetSize();
1010 //      SysTryReturn(NID_UI_ANIM,
1011 //              contentBounds.x >= 0 && contentBounds.y >= 0 && contentBounds.width >= 0 && contentBounds.height >= 0 &&
1012 //                      contentBounds.x + contentBounds.width <= surfaceSize.width && contentBounds.y + contentBounds.height <= surfaceSize.height,
1013 //              E_INVALID_ARG,
1014 //              E_INVALID_ARG,
1015 //              "[E_INVALID_ARG] Invalid content bounds.(%f,%f,%f,%f)", contentBounds.x, contentBounds.y, contentBounds.width, contentBounds.height
1016 //      );
1017
1018         if (unlikely(RectUtilIsEqual(__contentBounds, contentBounds)))
1019                 return E_SUCCESS;
1020
1021         SysTryReturnResult(NID_UI_ANIM, contentBounds.width >= 0.0f && contentBounds.height >= 0.0f, E_INVALID_ARG, "Invalid argument(s) is used. The size of contents bounds must be greater than or equal to 0.0f.");
1022
1023         __contentBounds = contentBounds;
1024         __useContentBounds = (__contentBounds.x != 0.0f || __contentBounds.y != 0.0f || __contentBounds.width != 1.0f || __contentBounds.height != 1.0f);
1025
1026         InvalidateHierarchyProps(HIERARCHY_PROPERTY_CONTENTBOUNDS, false, false);
1027
1028         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1029         {
1030                 FloatRectangle currentValue = __pPresentation->__contentBounds;
1031
1032                 if(CreateImplicitAnimationIfNeeded(*pVePropContentBounds,       __contentBounds, currentValue, NULL) == false)
1033                 {
1034                         __pPresentation->SetContentBoundsProperty(__contentBounds);
1035                 }
1036         }
1037
1038         return E_SUCCESS;
1039 }
1040
1041 result
1042 _VisualElementImpl::SetContentBounds(const FloatRectangle& contentBounds)
1043 {
1044         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1045 #if 0
1046         return SetContentBoundsI(contentBounds);
1047 #else
1048         result r = InvokeOnSetPropertyRequested(*pVePropContentBounds, Variant(contentBounds));
1049         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1050
1051         return r;
1052 #endif
1053 }
1054
1055 FloatRectangle
1056 _VisualElementImpl::GetContentBounds(void) const
1057 {
1058         ClearLastResult();
1059
1060         return __contentBounds;
1061 }
1062
1063 Variant
1064 _VisualElementImpl::GetContentBoundsProperty(void) const
1065 {
1066         ClearLastResult();
1067
1068         return Variant(__contentBounds);
1069 }
1070
1071 result
1072 _VisualElementImpl::SetContentBoundsProperty(const Variant& v)
1073 {
1074         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_RECTANGLE, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1075
1076         return SetContentBoundsI(v.ToFloatRectangle());
1077 }
1078
1079
1080 bool
1081 _VisualElementImpl::GetImplicitAnimationEnabled(void) const
1082 {
1083         ClearLastResult();
1084
1085         // TBD: forward using property or direct return ?
1086 #if 0
1087         bool isImplicitAnimationEnabled = InvokeOnGetPropertyRequested(*pVePropImplicitAnimationEnabled).ToBool();
1088         if (GetLastResult() != E_SUCCESS)
1089                 return false;
1090
1091         return isImplicitAnimationEnabled;
1092 #else
1093         return __isImplicitAnimationEnabled;
1094 #endif
1095 }
1096
1097 result
1098 _VisualElementImpl::SetImplicitAnimationEnabled(bool enable)
1099 {
1100         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1101         result r = InvokeOnSetPropertyRequested(*pVePropImplicitAnimationEnabled, Variant(enable));
1102         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1103
1104         return r;
1105 }
1106
1107 Variant
1108 _VisualElementImpl::GetImplicitAnimationProperty(void) const
1109 {
1110         ClearLastResult();
1111
1112         return Variant(__isImplicitAnimationEnabled);
1113 }
1114
1115 result
1116 _VisualElementImpl::SetImplicitAnimationProperty(const Variant& v)
1117 {
1118         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1119
1120         bool isImplicitAnimationEnabled = v.ToBool();
1121         if (isImplicitAnimationEnabled != __isImplicitAnimationEnabled)
1122         {
1123                 __isImplicitAnimationEnabled = isImplicitAnimationEnabled;
1124         }
1125         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1126         {
1127                 __pPresentation->SetImplicitAnimationProperty(__isImplicitAnimationEnabled);
1128         }
1129
1130         return E_SUCCESS;
1131 }
1132
1133 FloatRectangle
1134 _VisualElementImpl::GetBoundingBox(void) const
1135 {
1136         ClearLastResult();
1137
1138         return GetBoundingBoxI();
1139 }
1140
1141 FloatRectangle
1142 _VisualElementImpl::GetBounds(void) const
1143 {
1144         ClearLastResult();
1145
1146         // TBD: forward using property or direct return ?
1147 #if 0
1148         FloatRectangle bounds = InvokeOnGetPropertyRequested(*pVePropBounds).ToFloatRectangle();
1149         if (GetLastResult() != E_SUCCESS)
1150         {
1151                 return FloatRectangle();
1152         }
1153
1154         return bounds;
1155 #else
1156         return __bounds;
1157 #endif
1158 }
1159
1160 result
1161 _VisualElementImpl::SetBoundsI(const FloatRectangle& bounds)
1162 {
1163         _Rectanglef boundsAdjusted(bounds);
1164         FloatRectangle oldValue(__bounds);
1165
1166         result r =  E_SUCCESS;
1167         bool sizeChanged = false;
1168
1169         if (unlikely(GetSharedData().pEventListener != null))
1170         {
1171                 if (IS_MODEL(this))     // CHECKME: checking need??
1172                 {
1173                         FloatRectangle tmpBounds(bounds);
1174                         r = VE_DELEGATE(this, InvokeOnBoundsChanging, tmpBounds);
1175
1176                         boundsAdjusted = tmpBounds;
1177                 }
1178         }
1179
1180         if (likely(boundsAdjusted != __bounds))
1181         {
1182
1183                 float newWidth = boundsAdjusted.Width();
1184                 if (unlikely(newWidth < 0.0f))
1185                 {
1186                         newWidth = 0.0f;
1187                 }
1188
1189                 float newHeight = boundsAdjusted.Height();
1190                 if (unlikely(newHeight < 0.0f))
1191                 {
1192                         newHeight = 0.0f;
1193                 }
1194
1195
1196                 if (unlikely(newWidth != __bounds.width) || unlikely(newHeight != __bounds.height))
1197                 {
1198                         sizeChanged = true;
1199
1200                         // WARNING:
1201                         //      Adjust logical bounds(size) to sync. with that of surface(physical)
1202
1203                         float alignedWidth = newWidth;
1204                         float alignedHeight = newHeight;
1205
1206                         AdjustSizeForSurface(alignedWidth, alignedHeight);
1207
1208                         __needRecreateSurface = true;
1209                         if (likely(GetSharedData().pSurface))
1210                         {
1211                                 Dimension surfaceSize(GetSharedData().pSurface->GetSize());
1212                                 if (likely(static_cast< int >(alignedWidth) == surfaceSize.width) && likely(static_cast< int >(alignedHeight) == surfaceSize.height))
1213                                         __needRecreateSurface = false;
1214                         }
1215
1216                         _VisualElementCoordinateSystem::ConvertDimensionToPhysicalIntegral(alignedWidth, alignedHeight);
1217                         _VisualElementCoordinateSystem::ConvertDimensionToLogical(alignedWidth, alignedHeight);
1218
1219                         if (newWidth > 0.0f && alignedWidth == 0.0f)
1220                         {
1221                                 alignedWidth = 1.0f / _VisualElementCoordinateSystem::scaleFactorX;
1222                         }
1223
1224                         if (newHeight > 0.0f && alignedHeight == 0.0f)
1225                         {
1226                                 alignedHeight = 1.0f / _VisualElementCoordinateSystem::scaleFactorY;
1227                         }
1228
1229                         __alignedSize.width = alignedWidth;
1230                         __alignedSize.height = alignedHeight;
1231                 }
1232
1233
1234                 // TODO: Need to optimize dirty rectangle.
1235
1236                 // invalidate with previous bounds
1237                 if (unlikely(!NEED_SURFACE(this)))
1238                         InvalidateVisibleRectToRenderTarget(null);
1239
1240         //      if (sizeChanged)
1241         //              SysLog(NID_UI_ANIM, "size changing to " VELOGRECTTAG, VELOGRECT(boundsAdjusted));
1242
1243                 __bounds.x = boundsAdjusted.Left();
1244                 __bounds.y = boundsAdjusted.Top();
1245                 __bounds.width = newWidth;
1246                 __bounds.height = newHeight;
1247
1248                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
1249
1250                 // TBD: Recreating surface may have to be done in presentation layer (thread!)
1251
1252                 // WARNING:
1253                 //      Even when 'no redrawOnResize', it is needed to invalidate for redrawing if surface is not created yet.
1254                 //
1255                 if (unlikely(sizeChanged))
1256                 {
1257                         if (unlikely(!NEED_SURFACE(this)) || unlikely(GetSharedData().redrawOnResize))
1258                                 ExposeRectangle(null, true);
1259
1260                         // WARNING:
1261                         //      Shrink invalidated region to bounds
1262                         RectUtilIntersect(GetSharedData().invalidatedRegion, FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height));
1263                 }
1264                 else
1265                 {
1266                         if (unlikely(!NEED_SURFACE(this)))
1267                                 ExposeRectangle(null, true);
1268                 }
1269         }
1270
1271         // observer
1272         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1273         {
1274                 FloatRectangle currentValue = __pPresentation->__bounds;
1275
1276                 const String* subProperties[] = {       pVeSubPropBoundsSize, pVeSubPropBoundsPosition, NULL };
1277                 if(CreateImplicitAnimationIfNeeded(*pVePropBounds,      __bounds, currentValue, subProperties ) == false)
1278                 {
1279                         __pPresentation->SetBoundsProperty(__bounds);
1280                 }
1281
1282                 VE_DELEGATE(this, InvokeOnBoundsChanged, oldValue);
1283
1284                 if(__pBoundsChangedCallback && sizeChanged == true)
1285                 {
1286                                 (*__pBoundsChangedCallback)(__pBoundsChangedCallbackData);
1287                 }
1288
1289         }
1290
1291         return r;
1292 }
1293
1294
1295 result
1296 _VisualElementImpl::SetBounds(const FloatRectangle& bounds)
1297 {
1298         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1299         result r = E_SUCCESS;
1300
1301         if (IS_INTERNAL_CLASS(__pPublicInstance))
1302         {
1303                 r = SetBoundsI(bounds);
1304         }
1305         else
1306         {
1307                 r = InvokeOnSetPropertyRequested(*pVePropBounds, Variant(bounds));
1308         }
1309         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1310
1311         return r;
1312 }
1313
1314 Variant
1315 _VisualElementImpl::GetBoundsProperty(void) const
1316 {
1317         ClearLastResult();
1318
1319         return Variant(__bounds);
1320 }
1321
1322 result
1323 _VisualElementImpl::SetBoundsProperty(const Variant& v)
1324 {
1325         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_RECTANGLE, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1326
1327         return SetBoundsI(v.ToFloatRectangle());
1328 }
1329
1330 Variant
1331 _VisualElementImpl::GetBoundsPositionSubProperty(void) const
1332 {
1333         ClearLastResult();
1334
1335         return Variant(__bounds.GetTopLeft());
1336 }
1337
1338 result
1339 _VisualElementImpl::SetBoundsPositionSubProperty(const Variant& v)
1340 {
1341         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1342
1343         const FloatPoint& position = v.ToFloatPoint();
1344         return SetBoundsProperty(Variant(FloatRectangle(position.x, position.y, __bounds.width, __bounds.height)));
1345 }
1346
1347 Variant
1348 _VisualElementImpl::GetBoundsSizeSubProperty(void) const
1349 {
1350         ClearLastResult();
1351
1352         return Variant(FloatDimension(__bounds.width, __bounds.height));
1353 }
1354
1355 result
1356 _VisualElementImpl::SetBoundsSizeSubProperty(const Variant& v)
1357 {
1358         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_DIMENSION, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1359
1360         const FloatDimension& size = v.ToFloatDimension();
1361         return SetBoundsProperty(Variant(FloatRectangle(__bounds.x, __bounds.y, size.width, size.height)));
1362 }
1363
1364 float
1365 _VisualElementImpl::GetZPosition(void) const
1366 {
1367         ClearLastResult();
1368
1369         // TBD: forward using property or direct return ?
1370 #if 0
1371         float zPosition = (const_cast< _VisualElementImpl* >(this))->InvokeOnGetPropertyRequested(*pVePropZPosition).ToFloat();
1372         if (GetLastResult() != E_SUCCESS)
1373         {
1374                 return 0.0f;
1375         }
1376
1377         return zPosition;
1378 #else
1379         return __zPosition;
1380 #endif
1381 }
1382
1383 result
1384 _VisualElementImpl::SetZPositionI(float zPosition)
1385 {
1386         if (likely(zPosition != __zPosition))
1387         {
1388                 __zPosition = zPosition;
1389                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false); // lazy evaluation: property changed flag
1390         }
1391
1392         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1393         {
1394                 float currentValue = __pPresentation->__zPosition;
1395
1396                 if(CreateImplicitAnimationIfNeeded(*pVePropZPosition,   __zPosition, currentValue, NULL) == false)
1397                 {
1398                         __pPresentation->SetZPositionProperty(__zPosition);
1399                 }
1400         }
1401
1402         return E_SUCCESS;
1403 }
1404
1405
1406 result
1407 _VisualElementImpl::SetZPosition(float zPosition)
1408 {
1409         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1410         result r = E_SUCCESS;
1411
1412         if (IS_INTERNAL_CLASS(__pPublicInstance))
1413         {
1414                 r = SetZPositionI(zPosition);
1415         }
1416         else
1417         {
1418                 r = InvokeOnSetPropertyRequested(*pVePropZPosition, Variant(zPosition));
1419         }
1420
1421         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1422
1423         return r;
1424 }
1425
1426
1427
1428 Variant
1429 _VisualElementImpl::GetZPositionProperty(void) const
1430 {
1431         ClearLastResult();
1432
1433         return Variant(__zPosition);
1434 }
1435
1436 result
1437 _VisualElementImpl::SetZPositionProperty(const Variant& v)
1438 {
1439         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1440
1441         return SetZPositionI(v.ToFloat());
1442 }
1443
1444 result
1445 _VisualElementImpl::SetZOrderGroupI(int zOrderGroup)
1446 {
1447         result r = E_SUCCESS;
1448
1449         if (likely(__pParent))
1450         {
1451                 r= __pParent->ChangeZOrder(*this, null, true, zOrderGroup);
1452         }
1453         else
1454         {
1455                 _zOrderGroup = zOrderGroup;
1456         }
1457
1458         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1459         {
1460                 __pPresentation->SetZOrderGroupProperty(_zOrderGroup);
1461         }
1462         return r;
1463 }
1464
1465 result
1466 _VisualElementImpl::SetZOrderGroup(int zOrderGroup)
1467 {
1468         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1469         result r = E_SUCCESS;
1470
1471         if (IS_INTERNAL_CLASS(__pPublicInstance))
1472         {
1473                 r = SetZOrderGroupI(zOrderGroup);
1474         }
1475         else
1476         {
1477                 r = InvokeOnSetPropertyRequested(*pVePropZOrderGroup, Variant(zOrderGroup));
1478         }
1479
1480         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1481
1482         return r;
1483 }
1484
1485 int
1486 _VisualElementImpl::GetZOrderGroup(void) const
1487 {
1488         ClearLastResult();
1489
1490         return _zOrderGroup;
1491 }
1492
1493 Variant
1494 _VisualElementImpl::GetZOrderGroupProperty(void) const
1495 {
1496         ClearLastResult();
1497
1498         return Variant(_zOrderGroup);
1499 }
1500
1501 result
1502 _VisualElementImpl::SetZOrderGroupProperty(const Variant& v)
1503 {
1504         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_INT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1505
1506
1507         return SetZOrderGroupI(v.ToInt());
1508
1509         return E_SUCCESS;
1510 }
1511
1512 bool
1513 _VisualElementImpl::IsVisible(void) const
1514 {
1515         ClearLastResult();
1516
1517         return IsVisibleI();
1518 }
1519
1520 #if 0
1521 bool
1522 _VisualElementImpl::IsVisibleI(void) const
1523 {
1524 #if 0
1525         const _VisualElementImpl* pElement = this;
1526         const _VisualElementImpl* pRoot = GetRoot();
1527
1528         if (unlikely(!pRoot))
1529                 return false;
1530
1531         while (pElement)
1532         {
1533                 if (!VE_VISIBLE(pElement))
1534                 {
1535                         return false;
1536                 }
1537
1538 #if 0
1539                 if (!pElement->__pParent)
1540                 {
1541                         if (dynamic_cast< const _RootVisualElement* >(pElement) == null)
1542                         {
1543                                 return false;
1544                         }
1545                 }
1546 #else
1547                 if (!pElement->__pParent && pElement != pRoot)
1548                         return false;
1549 #endif
1550
1551                 pElement = pElement->__pParent;
1552         }
1553
1554         return true;
1555 #else
1556         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
1557         {
1558                 const_cast< _VisualElementImpl* >(this)->RebuildCoordinates();
1559         }
1560
1561         return __isVisible;
1562 #endif
1563 }
1564 #endif
1565
1566 bool
1567 _VisualElementImpl::GetShowState(void) const
1568 {
1569         ClearLastResult();
1570
1571         // TBD: forward using property or direct return ?
1572 #if 0
1573         return InvokeOnGetPropertyRequested(*pVePropShowState).ToBool();
1574 #else
1575         return VE_VISIBLE(this);
1576 #endif
1577 }
1578
1579 result
1580 _VisualElementImpl::SetShowOpacityI(float showOpacity)
1581 {
1582         bool oldShowState = SHOWOPACITY_VISIBLE(__showOpacity);
1583
1584         if (unlikely(showOpacity < 0.0f))
1585         {
1586                 showOpacity = 0.0f;
1587         }
1588         else if (unlikely(showOpacity > 1.0f))
1589         {
1590                 showOpacity = 1.0f;
1591         }
1592
1593         if (likely(__showOpacity != showOpacity))
1594         {
1595
1596                 bool showStateChanged = (oldShowState != SHOWOPACITY_VISIBLE(showOpacity));
1597
1598                 __showOpacity = showOpacity;
1599
1600                 if (likely(showStateChanged))
1601                 {
1602                         if (!oldShowState)
1603                         {
1604                                 // WARNING:
1605                                 //      Coordinates are calculated using visibleRect which is empty when invisible state.
1606                                 //      Show-Recalculation is needed when being visible !
1607                                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES | HIERARCHY_PROPERTY_SHOWSTATE | HIERARCHY_PROPERTY_OPACITY, true, false);
1608
1609                                 if (unlikely(!NEED_SURFACE(this)))
1610                                 {
1611                                         ExposeRectangle(null, true);
1612                                 }
1613                         }
1614                         else
1615                         {
1616                                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_SHOWSTATE | HIERARCHY_PROPERTY_OPACITY, true, false);
1617
1618                                 if (unlikely(!NEED_SURFACE(this)))
1619                                 {
1620                                         InvalidateVisibleRectToRenderTarget(null);
1621                                 }
1622                         }
1623                 }
1624                 else
1625                 {
1626                         // WARNING:
1627                         //      showOpacity is applicable only for surfaces
1628                         if (likely(NEED_SURFACE(this)))
1629                         {
1630                                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_OPACITY, true, false);
1631                         }
1632                 }
1633         }
1634         //Observer
1635         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1636         {
1637                 bool needPresentationUpdate = true;
1638                 const String& property = *pVePropShowState;
1639                 _AnimationManager* pAnimationManager = _AnimationManager::GetInstance();
1640
1641                         if (likely(GetRoot()) && likely(GetSharedData().needSurface)
1642                                 && (unlikely(pAnimationManager->IsImplicitAnimationEnabled() && __isImplicitAnimationEnabled)))
1643                         {
1644                                 // WARNING:
1645                                                 //      For performance, following must be done only when oldValue != newValue.
1646                                 VisualElementAnimation* pAnimation = InvokeCreateAnimationForProperty(property);
1647                                 VisualElementPropertyAnimation* pPropertyAnimation = NULL;
1648                                 if(!pAnimation)
1649                                 {
1650                                         pPropertyAnimation = new (std::nothrow) VisualElementPropertyAnimation();
1651                                         if(pPropertyAnimation)
1652                                         {
1653                                                 pPropertyAnimation->SetPropertyName(*pVePrivPropShowOpacity);
1654                                                 needPresentationUpdate = true;
1655                                         }
1656                                 }
1657                                 else
1658                                 {
1659                                         pPropertyAnimation = dynamic_cast< VisualElementPropertyAnimation* >(pAnimation);
1660                                 }
1661
1662                                 if (likely(pPropertyAnimation))
1663                                 {
1664                                         if (pPropertyAnimation->GetEndValue().IsEmpty())
1665                                         {
1666                                                 pPropertyAnimation->SetEndValue(__showOpacity);
1667                                         }
1668
1669                                         if (pPropertyAnimation->GetStartValue().IsEmpty())
1670                                         {
1671                                                 pPropertyAnimation->SetStartValue(__pPresentation->__showOpacity);
1672                                         }
1673                                 }
1674
1675                                 if (unlikely(pPropertyAnimation))
1676                                 {
1677                                         /// WARNING:
1678                                         //      Adding property animation causes previous animation for same property to be removed in Animation Manager.
1679                                         if (unlikely(IsFailed(AddAnimation(null, *pPropertyAnimation))))
1680                                         {
1681                                                 needPresentationUpdate = true;
1682                                                 //pAnimationManager->RemoveAnimationForProperty(*presentation.GetPublic(), property);
1683                                         }
1684
1685                                         delete pPropertyAnimation;
1686                                 }
1687                                 else
1688                                 {
1689                                         // WARNING:
1690                                         //      Remove previous animation even when trying to change the property without animation.
1691                                         pAnimationManager->RemoveAnimationForProperty(*__pPresentation->__pPublicInstance, property);
1692                                         needPresentationUpdate = true;
1693                                 }
1694                         }
1695                         else
1696                         {
1697                                 pAnimationManager->RemoveAnimationForProperty(*__pPresentation->__pPublicInstance, property);
1698                                 needPresentationUpdate = true;
1699
1700                         }
1701                         if(needPresentationUpdate)
1702                         {
1703                                 __pPresentation->SetShowStateProperty(SHOWOPACITY_VISIBLE(__showOpacity));
1704                         }
1705                         InvokeOnShowStateChanged(oldShowState);
1706
1707         }
1708
1709         return E_SUCCESS;
1710 }
1711
1712 result
1713 _VisualElementImpl::SetShowStateI(bool show)
1714 {
1715         return SetShowOpacityI(show ? 1.0f : 0.0f);
1716 }
1717
1718 result
1719 _VisualElementImpl::SetShowState(bool show)
1720 {
1721         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1722         result r = E_SUCCESS;
1723
1724         if (IS_INTERNAL_CLASS(__pPublicInstance))
1725         {
1726                 r = SetShowOpacityI(show ? 1.0f : 0.0f);
1727         }
1728         else
1729         {
1730                 r = InvokeOnSetPropertyRequested(*pVePropShowState, Variant(show));
1731         }
1732
1733         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1734
1735         return r;
1736 }
1737
1738 Variant
1739 _VisualElementImpl::GetShowStateProperty(void) const
1740 {
1741         ClearLastResult();
1742
1743         return Variant(VE_VISIBLE(this));
1744 }
1745
1746 result
1747 _VisualElementImpl::SetShowStateProperty(const Variant& v)
1748 {
1749         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1750
1751         bool showState = v.ToBool();
1752
1753         return SetShowOpacityI(showState ? 1.0f : 0.0f);
1754 }
1755
1756 Variant
1757 _VisualElementImpl::GetShowOpacityPrivateProperty(void) const
1758 {
1759         ClearLastResult();
1760
1761         return Variant(__showOpacity);
1762 }
1763
1764 result
1765 _VisualElementImpl::SetShowOpacityPrivateProperty(const Variant& v)
1766 {
1767         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1768
1769         return SetShowOpacityI(v.ToFloat());
1770 }
1771
1772 float
1773 _VisualElementImpl::GetContentOpacity(void) const
1774 {
1775         ClearLastResult();
1776
1777         // TBD: forward using property or direct return ?
1778 #if 0
1779         return InvokeOnGetPropertyRequested(*pVePropContentOpacity).ToFloat();
1780 #else
1781         return __contentOpacity;
1782 #endif
1783 }
1784
1785 result
1786 _VisualElementImpl::SetContentOpacityI(float contentOpacity)
1787 {
1788         if (unlikely(contentOpacity == __contentOpacity))       // do not take care of float-error !!
1789         {
1790                 return E_SUCCESS;
1791         }
1792
1793         SysTryReturnResult(NID_UI_ANIM, contentOpacity >= 0.0f && contentOpacity <= 1.0f, E_INVALID_ARG, "Invalid argument(s) is used. Invalid opacity range.");
1794
1795         __contentOpacity = contentOpacity;
1796
1797         InvalidateHierarchyProps(HIERARCHY_PROPERTY_CONTENTOPACITY, false, false); //don't have to apply the changed opacity to children.
1798
1799 #ifndef LAZY_EVALUATION
1800         if (IS_PRESENTATION(this) && likely(__pSharedData) && likely(GetSharedData().pNativeNode))
1801         {
1802                 GetSharedData().NodeReconfigure(*this);
1803         }
1804 #endif
1805
1806         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1807         {
1808                 float currentValue = __pPresentation->__contentOpacity;
1809
1810                 if(CreateImplicitAnimationIfNeeded(*pVePropContentOpacity,      __contentOpacity, currentValue, NULL) == false)
1811                 {
1812                         __pPresentation->SetContentOpacityProperty(__contentOpacity);
1813                 }
1814         }
1815         return E_SUCCESS;
1816 }
1817
1818
1819 result
1820 _VisualElementImpl::SetContentOpacity(float contentOpacity)
1821 {
1822         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1823         result r = E_SUCCESS;
1824
1825 //      PROPERTY_PROCESS(SetContentOpacityI, GetContentOpacityProperty, SetContentOpacityProperty, pVePropContentOpacity, __contentOpacity, contentOpacity);
1826         if (IS_INTERNAL_CLASS(__pPublicInstance))
1827         {
1828                 r = SetContentOpacityI(contentOpacity);
1829         }
1830         else
1831         {
1832                 r = InvokeOnSetPropertyRequested(*pVePropContentOpacity, Variant(contentOpacity));
1833         }
1834
1835         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1836
1837         return r;
1838 }
1839
1840
1841 Variant
1842 _VisualElementImpl::GetContentOpacityProperty(void) const
1843 {
1844         ClearLastResult();
1845
1846         return Variant(__contentOpacity);
1847 }
1848
1849 result
1850 _VisualElementImpl::SetContentOpacityProperty(const Variant& v)
1851 {
1852         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1853
1854         return SetContentOpacityI(v.ToFloat());
1855 }
1856
1857 float
1858 _VisualElementImpl::GetOpacity(void) const
1859 {
1860         ClearLastResult();
1861
1862         // TBD: forward using property or direct return ?
1863 #if 0
1864         return InvokeOnGetPropertyRequested(*pVePropOpacity).ToFloat();
1865 #else
1866         return __opacity;
1867 #endif
1868 }
1869
1870 result
1871 _VisualElementImpl::SetOpacityI(float opacity)
1872 {
1873         if (likely(opacity != __opacity))       // do not take care of float-error !!
1874         {
1875                 if (unlikely(opacity > 1.0f))
1876                 {
1877                         opacity = 1.0f;
1878                 }
1879                 else if (unlikely(opacity < 0.0f))
1880                 {
1881                         opacity = 0.0f;
1882                 }
1883
1884                 __opacity = opacity;
1885
1886                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_OPACITY, true, false);
1887         }
1888
1889         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1890         {
1891                 float currentValue = __pPresentation->__opacity;
1892
1893                 if(CreateImplicitAnimationIfNeeded(*pVePropOpacity,     __opacity, currentValue, NULL) == false)
1894                 {
1895                         __pPresentation->SetOpacityProperty(__opacity);
1896                 }
1897         }
1898         return E_SUCCESS;
1899 }
1900
1901 result
1902 _VisualElementImpl::SetOpacity(float opacity)
1903 {
1904         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1905         result r = E_SUCCESS;
1906
1907 //      PROPERTY_PROCESS(SetOpacityI, GetOpacityProperty, SetOpacityProperty, pVePropOpacity, __opacity, opacity);
1908         if (IS_INTERNAL_CLASS(__pPublicInstance))
1909         {
1910                 r = SetOpacityI(opacity);
1911         }
1912         else
1913         {
1914                 r = InvokeOnSetPropertyRequested(*pVePropOpacity, Variant(opacity));
1915         }
1916
1917         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1918
1919         return r;
1920 }
1921
1922 Variant
1923 _VisualElementImpl::GetOpacityProperty(void) const
1924 {
1925         ClearLastResult();
1926
1927         return Variant(__opacity);
1928 }
1929
1930 result
1931 _VisualElementImpl::SetOpacityProperty(const Variant& v)
1932 {
1933         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
1934
1935         return SetOpacityI(v.ToFloat());
1936 }
1937
1938 FloatPoint
1939 _VisualElementImpl::GetAnchor(void) const
1940 {
1941         ClearLastResult();
1942
1943         // TBD: forward using property or direct return ?
1944 #if 0
1945         return InvokeOnGetPropertyRequested(*pVePropAnchor).ToFloatPoint();
1946 #else
1947         return __anchor;
1948 #endif
1949 }
1950
1951 result
1952 _VisualElementImpl::SetAnchorI(const FloatPoint& anchor)
1953 {
1954         if (likely(anchor != __anchor))
1955         {
1956
1957                 __anchor = anchor;
1958
1959                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
1960
1961                 // VE with surface will be exposed automatically on rebuilding coordinates...
1962                 if (unlikely(!HAVE_SURFACE(this)))
1963                 {
1964                         ExposeRectangle(null, true);    // CHECKME: needed ???
1965                 }
1966         }
1967
1968         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
1969         {
1970                 FloatPoint currentValue = __pPresentation->__anchor;
1971
1972                 if(CreateImplicitAnimationIfNeeded(*pVePropAnchor,      __anchor, currentValue, NULL) == false)
1973                 {
1974                         __pPresentation->SetAnchorProperty(__anchor);
1975                 }
1976         }
1977         return E_SUCCESS;
1978 }
1979
1980
1981 result
1982 _VisualElementImpl::SetAnchor(const FloatPoint& anchor)
1983 {
1984         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
1985         result r = E_SUCCESS;
1986
1987 //      PROPERTY_PROCESS(SetAnchorI, GetAnchorProperty, SetAnchorProperty, pVePropAnchor, __anchor, anchor);
1988         if (IS_INTERNAL_CLASS(__pPublicInstance))
1989         {
1990                 r = SetAnchorI(anchor);
1991         }
1992         else
1993         {
1994                 r = InvokeOnSetPropertyRequested(*pVePropAnchor, Variant(anchor));
1995         }
1996
1997         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
1998
1999         return r;
2000 }
2001
2002
2003 Variant
2004 _VisualElementImpl::GetAnchorProperty(void) const
2005 {
2006         ClearLastResult();
2007
2008         return Variant(__anchor);
2009 }
2010
2011 result
2012 _VisualElementImpl::SetAnchorProperty(const Variant& v)
2013 {
2014         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2015
2016         return SetAnchorI(v.ToFloatPoint());
2017 }
2018
2019 float
2020 _VisualElementImpl::GetAnchorZ(void) const
2021 {
2022         ClearLastResult();
2023
2024         // TBD: forward using property or direct return ?
2025 #if 0
2026         return InvokeOnGetPropertyRequested(*pVePropAnchorZ).ToFloat();
2027 #else
2028         return __anchorZ;
2029 #endif
2030 }
2031
2032 result
2033 _VisualElementImpl::SetAnchorZI(float anchorZ)
2034 {
2035         if (likely(anchorZ != __anchorZ))
2036         {
2037                 __anchorZ = anchorZ;
2038
2039                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
2040
2041                 // VE with surface will be exposed automatically on rebuilding coordinates...
2042                 if (unlikely(!HAVE_SURFACE(this)))
2043                 {
2044                         ExposeRectangle(null, true);    // CHECKME: needed ???
2045                 }
2046         }
2047
2048         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
2049         {
2050                 float currentValue = __pPresentation->__anchorZ;
2051
2052                 if(CreateImplicitAnimationIfNeeded(*pVePropAnchorZ,     __anchorZ, currentValue, NULL) == false)
2053                 {
2054                         __pPresentation->SetAnchorZProperty(__anchorZ);
2055                 }
2056         }
2057         return E_SUCCESS;
2058 }
2059
2060
2061 result
2062 _VisualElementImpl::SetAnchorZ(float anchorZ)
2063 {
2064         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
2065         result r = E_SUCCESS;
2066
2067 //      PROPERTY_PROCESS(SetAnchorZI, GetAnchorZProperty, SetAnchorZProperty, pVePropAnchorZ, __anchorZ, anchorZ);
2068         if (IS_INTERNAL_CLASS(__pPublicInstance))
2069         {
2070                 r = SetAnchorZI(anchorZ);
2071         }
2072         else
2073         {
2074                 r = InvokeOnSetPropertyRequested(*pVePropAnchorZ, Variant(anchorZ));
2075         }
2076
2077         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
2078
2079         return r;
2080 }
2081
2082
2083
2084 Variant
2085 _VisualElementImpl::GetAnchorZProperty(void) const
2086 {
2087         ClearLastResult();
2088
2089         return Variant(__anchorZ);
2090 }
2091
2092 result
2093 _VisualElementImpl::SetAnchorZProperty(const Variant& v)
2094 {
2095         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2096
2097         return SetAnchorZI(v.ToFloat());
2098 }
2099
2100 FloatMatrix4
2101 _VisualElementImpl::GetTransformMatrix(void) const
2102 {
2103         ClearLastResult();
2104
2105         // TBD: forward using property or direct return ?
2106 #if 0
2107         return InvokeOnGetPropertyRequested(*pVePropTransform).ToFloatMatrix4();
2108 #else
2109         return __transform;
2110 #endif
2111 }
2112
2113 result
2114 _VisualElementImpl::SetTransformMatrixI(const FloatMatrix4& xform, bool updateDecomposed)
2115 {
2116
2117         result r = E_SUCCESS;
2118
2119         FloatMatrix4 oldValue(__transform);
2120
2121         FloatMatrix4 matrixAdjusted(xform);
2122
2123         if (unlikely(GetSharedData().pEventListener != null))
2124         {
2125                 if (IS_MODEL(this))     // CHECKME: checking need??
2126                 {
2127                         r = VE_DELEGATE(this, InvokeOnTransformMatrixChanging, matrixAdjusted);
2128                 }
2129         }
2130
2131         if (r == E_SUCCESS && likely(matrixAdjusted != __transform))    // check again because delegate may change the transform matrix
2132         {
2133                 // render target updates for previous bounds
2134                 if (unlikely(!NEED_SURFACE(this)))
2135                 {
2136                         InvalidateVisibleRectToRenderTarget(null);
2137                 }
2138
2139
2140                 MatrixUtilCopy(__transform, matrixAdjusted);
2141
2142                 if (unlikely(updateDecomposed))
2143                 {
2144                         __decomposedTransform.SetTransformMatrix(__transform);
2145                 }
2146
2147                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
2148
2149                 // VE with surface will be exposed automatically on rebuilding coordinates...
2150                 if (unlikely(!NEED_SURFACE(this)))
2151                 {
2152                         ExposeRectangle(null, true);    // CHECKME: needed ???
2153                 }
2154         }
2155
2156         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
2157         {
2158                 FloatMatrix4 currentValue = __pPresentation->__transform;
2159
2160                 const String* subProperties[] = {       pVeSubPropTransformRotationX,
2161                                                                                         pVeSubPropTransformRotationY,
2162                                                                                         pVeSubPropTransformRotationZ,
2163                                                                                         pVeSubPropTransformScaleX,
2164                                                                                         pVeSubPropTransformScaleY,
2165                                                                                         pVeSubPropTransformScaleZ,
2166                                                                                         pVeSubPropTransformTranslationX,
2167                                                                                         pVeSubPropTransformTranslationY,
2168                                                                                         pVeSubPropTransformTranslationZ,
2169                                                                                         pVeSubPropTransformRotationAnchorX,
2170                                                                                         pVeSubPropTransformRotationAnchorY,
2171                                                                                         pVeSubPropTransformRotationAnchorZ,
2172                                                                                         pVeSubPropTransformScaleAnchorX,
2173                                                                                         pVeSubPropTransformScaleAnchorY,
2174                                                                                         pVeSubPropTransformScaleAnchorZ,
2175                                                                                         NULL};
2176
2177                 if(CreateImplicitAnimationIfNeeded(*pVePropTransform,   __transform, currentValue, subProperties ) == false)
2178                 {
2179                         __pPresentation->SetTransformMatrixProperty(__transform);
2180                 }
2181
2182                 VE_DELEGATE(this, InvokeOnTransformMatrixChanged, oldValue);
2183         }
2184         return E_SUCCESS;
2185 }
2186
2187 result
2188 _VisualElementImpl::SetTransformMatrix(const FloatMatrix4& xform)
2189 {
2190         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
2191         result r = E_SUCCESS;
2192
2193 //      PROPERTY_PROCESS(SetTransformMatrixI, GetTransformMatrixProperty, SetTransformMatrixProperty, pVePropTransform, __transform, xform);
2194         if (IS_INTERNAL_CLASS(__pPublicInstance))
2195         {
2196                 r = SetTransformMatrixI(xform);
2197         }
2198         else
2199         {
2200                 r = InvokeOnSetPropertyRequested(*pVePropTransform, Variant(xform));
2201         }
2202
2203         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
2204
2205         return r;
2206 }
2207
2208
2209
2210 Variant
2211 _VisualElementImpl::GetTransformMatrixProperty(void) const
2212 {
2213         ClearLastResult();
2214
2215         return Variant(__transform);
2216 }
2217
2218
2219 result
2220 _VisualElementImpl::SetTransformMatrixProperty(const Variant& v)
2221 {
2222         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_MATRIX4, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2223
2224         return SetTransformMatrixI(v.ToFloatMatrix4(), true);
2225 }
2226
2227 Variant
2228 _VisualElementImpl::GetTransformRotationXSubProperty(void) const
2229 {
2230         ClearLastResult();
2231
2232         float angleX = 0.0f;
2233         float angleY = 0.0f;
2234         float angleZ = 0.0f;
2235         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2236
2237         return Variant(angleX);
2238 }
2239
2240 result
2241 _VisualElementImpl::SetTransformRotationXSubProperty(const Variant& v)
2242 {
2243         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2244
2245         float angleX = 0.0f;
2246         float angleY = 0.0f;
2247         float angleZ = 0.0f;
2248         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2249         __decomposedTransform.UpdateRotationFromEulerAngles(v.ToFloat(), angleY, angleZ);
2250
2251         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2252 }
2253
2254 Variant
2255 _VisualElementImpl::GetTransformRotationYSubProperty(void) const
2256 {
2257         ClearLastResult();
2258
2259         float angleX = 0.0f;
2260         float angleY = 0.0f;
2261         float angleZ = 0.0f;
2262         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2263
2264         return Variant(angleY);
2265 }
2266
2267 result
2268 _VisualElementImpl::SetTransformRotationYSubProperty(const Variant& v)
2269 {
2270         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2271
2272         float angleX = 0.0f;
2273         float angleY = 0.0f;
2274         float angleZ = 0.0f;
2275         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2276         __decomposedTransform.UpdateRotationFromEulerAngles(angleX, v.ToFloat(), angleZ);
2277
2278         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2279 }
2280
2281 Variant
2282 _VisualElementImpl::GetTransformRotationZSubProperty(void) const
2283 {
2284         ClearLastResult();
2285
2286         float angleX = 0.0f;
2287         float angleY = 0.0f;
2288         float angleZ = 0.0f;
2289         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2290
2291         return Variant(angleZ);
2292 }
2293
2294 result
2295 _VisualElementImpl::SetTransformRotationZSubProperty(const Variant& v)
2296 {
2297         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2298
2299         float angleX = 0.0f;
2300         float angleY = 0.0f;
2301         float angleZ = 0.0f;
2302         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2303         __decomposedTransform.UpdateRotationFromEulerAngles(angleX, angleY, v.ToFloat());
2304
2305         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2306 }
2307
2308 Variant
2309 _VisualElementImpl::GetTransformRotationXYSubProperty(void) const
2310 {
2311         ClearLastResult();
2312
2313         float angleX = 0.0f;
2314         float angleY = 0.0f;
2315         float angleZ = 0.0f;
2316         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2317
2318         return Variant(FloatPoint(angleX, angleY));
2319 }
2320
2321 result
2322 _VisualElementImpl::SetTransformRotationXYSubProperty(const Variant& v)
2323 {
2324         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2325
2326         const FloatPoint& point = v.ToFloatPoint();
2327
2328         float angleX = 0.0f;
2329         float angleY = 0.0f;
2330         float angleZ = 0.0f;
2331         __decomposedTransform.GetEulerAngles(angleX, angleY, angleZ);
2332         __decomposedTransform.UpdateRotationFromEulerAngles(point.x, point.y, angleZ);
2333
2334         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2335 }
2336
2337 Variant
2338 _VisualElementImpl::GetTransformRotationAnchorXSubProperty(void) const
2339 {
2340         ClearLastResult();
2341
2342         float anchorX = 0.0f;
2343         float anchorY = 0.0f;
2344         float anchorZ = 0.0f;
2345         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2346
2347         return Variant(anchorX);
2348 }
2349
2350 result
2351 _VisualElementImpl::SetTransformRotationAnchorXSubProperty(const Variant& v)
2352 {
2353         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2354
2355         float anchorX = 0.0f;
2356         float anchorY = 0.0f;
2357         float anchorZ = 0.0f;
2358         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2359         __decomposedTransform.SetRotationAnchor(v.ToFloat(), anchorY, anchorZ);
2360
2361         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2362 }
2363
2364 Variant
2365 _VisualElementImpl::GetTransformRotationAnchorYSubProperty(void) const
2366 {
2367         ClearLastResult();
2368
2369         float anchorX = 0.0f;
2370         float anchorY = 0.0f;
2371         float anchorZ = 0.0f;
2372         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2373
2374         return Variant(anchorY);
2375 }
2376
2377 result
2378 _VisualElementImpl::SetTransformRotationAnchorYSubProperty(const Variant& v)
2379 {
2380         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2381
2382         float anchorX = 0.0f;
2383         float anchorY = 0.0f;
2384         float anchorZ = 0.0f;
2385         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2386         __decomposedTransform.SetRotationAnchor(anchorX, v.ToFloat(), anchorZ);
2387
2388         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2389 }
2390
2391 Variant
2392 _VisualElementImpl::GetTransformRotationAnchorZSubProperty(void) const
2393 {
2394         ClearLastResult();
2395
2396         float anchorX = 0.0f;
2397         float anchorY = 0.0f;
2398         float anchorZ = 0.0f;
2399         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2400
2401         return Variant(anchorZ);
2402 }
2403
2404 result
2405 _VisualElementImpl::SetTransformRotationAnchorZSubProperty(const Variant& v)
2406 {
2407         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2408
2409         float anchorX = 0.0f;
2410         float anchorY = 0.0f;
2411         float anchorZ = 0.0f;
2412         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2413         __decomposedTransform.SetRotationAnchor(anchorX, anchorY, v.ToFloat());
2414
2415         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2416 }
2417
2418 Variant
2419 _VisualElementImpl::GetTransformRotationAnchorXYSubProperty(void) const
2420 {
2421         ClearLastResult();
2422
2423         float anchorX = 0.0f;
2424         float anchorY = 0.0f;
2425         float anchorZ = 0.0f;
2426         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2427
2428         return Variant(FloatPoint(anchorX, anchorY));
2429 }
2430
2431 result
2432 _VisualElementImpl::SetTransformRotationAnchorXYSubProperty(const Variant& v)
2433 {
2434         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2435
2436         const FloatPoint& point = v.ToFloatPoint();
2437
2438         float anchorX = 0.0f;
2439         float anchorY = 0.0f;
2440         float anchorZ = 0.0f;
2441         __decomposedTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
2442         __decomposedTransform.SetRotationAnchor(point.x, point.y, anchorZ);
2443
2444         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2445 }
2446
2447 Variant
2448 _VisualElementImpl::GetTransformScaleXSubProperty(void) const
2449 {
2450         ClearLastResult();
2451
2452         float scaleX = 1.0f;
2453         float scaleY = 1.0f;
2454         float scaleZ = 1.0f;
2455         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2456
2457         return Variant(scaleX);
2458 }
2459
2460 result
2461 _VisualElementImpl::SetTransformScaleXSubProperty(const Variant& v)
2462 {
2463         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2464
2465         float scaleX = 1.0f;
2466         float scaleY = 1.0f;
2467         float scaleZ = 1.0f;
2468         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2469         __decomposedTransform.SetScaleFactors(v.ToFloat(), scaleY, scaleZ);
2470
2471         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2472 }
2473
2474 Variant
2475 _VisualElementImpl::GetTransformScaleYSubProperty(void) const
2476 {
2477         ClearLastResult();
2478
2479         float scaleX = 1.0f;
2480         float scaleY = 1.0f;
2481         float scaleZ = 1.0f;
2482         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2483
2484         return Variant(scaleY);
2485 }
2486
2487 result
2488 _VisualElementImpl::SetTransformScaleYSubProperty(const Variant& v)
2489 {
2490         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2491
2492         float scaleX = 1.0f;
2493         float scaleY = 1.0f;
2494         float scaleZ = 1.0f;
2495         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2496         __decomposedTransform.SetScaleFactors(scaleX, v.ToFloat(), scaleZ);
2497
2498         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2499 }
2500
2501 Variant
2502 _VisualElementImpl::GetTransformScaleZSubProperty(void) const
2503 {
2504         ClearLastResult();
2505
2506         float scaleX = 1.0f;
2507         float scaleY = 1.0f;
2508         float scaleZ = 1.0f;
2509         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2510
2511         return Variant(scaleZ);
2512 }
2513
2514 result
2515 _VisualElementImpl::SetTransformScaleZSubProperty(const Variant& v)
2516 {
2517         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2518
2519         float scaleX = 1.0f;
2520         float scaleY = 1.0f;
2521         float scaleZ = 1.0f;
2522         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2523         __decomposedTransform.SetScaleFactors(scaleX, scaleY, v.ToFloat());
2524
2525         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2526 }
2527
2528 Variant
2529 _VisualElementImpl::GetTransformScaleXYSubProperty(void) const
2530 {
2531         ClearLastResult();
2532
2533         float scaleX = 1.0f;
2534         float scaleY = 1.0f;
2535         float scaleZ = 1.0f;
2536         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2537
2538         return Variant(FloatPoint(scaleX, scaleY));
2539 }
2540
2541 result
2542 _VisualElementImpl::SetTransformScaleXYSubProperty(const Variant& v)
2543 {
2544         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2545
2546         const FloatPoint& point = v.ToFloatPoint();
2547
2548         float scaleX = 1.0f;
2549         float scaleY = 1.0f;
2550         float scaleZ = 1.0f;
2551         __decomposedTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
2552         if (unlikely(scaleX == point.x) && unlikely(scaleY == point.y))
2553         {
2554                 return E_SUCCESS;
2555         }
2556
2557         __decomposedTransform.SetScaleFactors(point.x, point.y, scaleZ);
2558
2559         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2560 }
2561
2562 Variant
2563 _VisualElementImpl::GetTransformScaleAnchorXSubProperty(void) const
2564 {
2565         ClearLastResult();
2566
2567         float anchorX = 0.0f;
2568         float anchorY = 0.0f;
2569         float anchorZ = 0.0f;
2570         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2571
2572         return Variant(anchorX);
2573 }
2574
2575 result
2576 _VisualElementImpl::SetTransformScaleAnchorXSubProperty(const Variant& v)
2577 {
2578         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2579
2580         float anchorX = 0.0f;
2581         float anchorY = 0.0f;
2582         float anchorZ = 0.0f;
2583         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2584         __decomposedTransform.SetScaleAnchor(v.ToFloat(), anchorY, anchorZ);
2585
2586         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2587 }
2588
2589 Variant
2590 _VisualElementImpl::GetTransformScaleAnchorYSubProperty(void) const
2591 {
2592         ClearLastResult();
2593
2594         float anchorX = 0.0f;
2595         float anchorY = 0.0f;
2596         float anchorZ = 0.0f;
2597         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2598
2599         return Variant(anchorY);
2600 }
2601
2602 result
2603 _VisualElementImpl::SetTransformScaleAnchorYSubProperty(const Variant& v)
2604 {
2605         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2606
2607         float anchorX = 0.0f;
2608         float anchorY = 0.0f;
2609         float anchorZ = 0.0f;
2610         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2611         __decomposedTransform.SetScaleAnchor(anchorX, v.ToFloat(), anchorZ);
2612
2613         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2614 }
2615
2616 Variant
2617 _VisualElementImpl::GetTransformScaleAnchorZSubProperty(void) const
2618 {
2619         ClearLastResult();
2620
2621         float anchorX = 0.0f;
2622         float anchorY = 0.0f;
2623         float anchorZ = 0.0f;
2624         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2625
2626         return Variant(anchorZ);
2627 }
2628
2629 result
2630 _VisualElementImpl::SetTransformScaleAnchorZSubProperty(const Variant& v)
2631 {
2632         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2633
2634         float anchorX = 0.0f;
2635         float anchorY = 0.0f;
2636         float anchorZ = 0.0f;
2637         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2638         __decomposedTransform.SetScaleAnchor(anchorX, anchorY, v.ToFloat());
2639
2640         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2641 }
2642
2643 Variant
2644 _VisualElementImpl::GetTransformScaleAnchorXYSubProperty(void) const
2645 {
2646         ClearLastResult();
2647
2648         float anchorX = 0.0f;
2649         float anchorY = 0.0f;
2650         float anchorZ = 0.0f;
2651         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2652
2653         return Variant(FloatPoint(anchorX, anchorY));
2654 }
2655
2656 result
2657 _VisualElementImpl::SetTransformScaleAnchorXYSubProperty(const Variant& v)
2658 {
2659         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2660
2661         const FloatPoint& point = v.ToFloatPoint();
2662
2663         float anchorX = 0.0f;
2664         float anchorY = 0.0f;
2665         float anchorZ = 0.0f;
2666         __decomposedTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
2667         __decomposedTransform.SetScaleAnchor(point.x, point.y, anchorZ);
2668
2669         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2670 }
2671
2672 Variant
2673 _VisualElementImpl::GetTransformTranslationXSubProperty(void) const
2674 {
2675         ClearLastResult();
2676
2677         float translateX = 0.0f;
2678         float translateY = 0.0f;
2679         float translateZ = 0.0f;
2680         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2681
2682         return Variant(translateX);
2683 }
2684
2685 result
2686 _VisualElementImpl::SetTransformTranslationXSubProperty(const Variant& v)
2687 {
2688         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2689
2690         float translateX = 0.0f;
2691         float translateY = 0.0f;
2692         float translateZ = 0.0f;
2693         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2694         __decomposedTransform.SetTranslationFactors(v.ToFloat(), translateY, translateZ);
2695
2696         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2697 }
2698
2699 Variant
2700 _VisualElementImpl::GetTransformTranslationYSubProperty(void) const
2701 {
2702         ClearLastResult();
2703
2704         float translateX = 0.0f;
2705         float translateY = 0.0f;
2706         float translateZ = 0.0f;
2707         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2708
2709         return Variant(translateY);
2710 }
2711
2712 result
2713 _VisualElementImpl::SetTransformTranslationYSubProperty(const Variant& v)
2714 {
2715         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2716
2717         float translateX = 0.0f;
2718         float translateY = 0.0f;
2719         float translateZ = 0.0f;
2720         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2721         __decomposedTransform.SetTranslationFactors(translateX, v.ToFloat(), translateZ);
2722
2723         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2724 }
2725
2726 Variant
2727 _VisualElementImpl::GetTransformTranslationZSubProperty(void) const
2728 {
2729         ClearLastResult();
2730
2731         float translateX = 0.0f;
2732         float translateY = 0.0f;
2733         float translateZ = 0.0f;
2734         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2735
2736         return Variant(translateZ);
2737 }
2738
2739 result
2740 _VisualElementImpl::SetTransformTranslationZSubProperty(const Variant& v)
2741 {
2742         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2743
2744         float translateX = 0.0f;
2745         float translateY = 0.0f;
2746         float translateZ = 0.0f;
2747         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2748         __decomposedTransform.SetTranslationFactors(translateX, translateY, v.ToFloat());
2749
2750         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2751 }
2752
2753 Variant
2754 _VisualElementImpl::GetTransformTranslationXYSubProperty(void) const
2755 {
2756         ClearLastResult();
2757
2758         float translateX = 0.0f;
2759         float translateY = 0.0f;
2760         float translateZ = 0.0f;
2761         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2762
2763         return Variant(FloatPoint(translateX, translateY));
2764 }
2765
2766 result
2767 _VisualElementImpl::SetTransformTranslationXYSubProperty(const Variant& v)
2768 {
2769         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2770
2771         const FloatPoint& point = v.ToFloatPoint();
2772
2773         float translateX = 0.0f;
2774         float translateY = 0.0f;
2775         float translateZ = 0.0f;
2776         __decomposedTransform.GetTranslationFactors(translateX, translateY, translateZ);
2777         __decomposedTransform.SetTranslationFactors(point.x, point.y, translateZ);
2778
2779         return SetTransformMatrixI(__decomposedTransform.GetTransformMatrix(), false);
2780 }
2781
2782 FloatMatrix4
2783 _VisualElementImpl::GetChildrenTransformMatrix(void) const
2784 {
2785         ClearLastResult();
2786
2787         // TBD: forward using property or direct return ?
2788 #if 0
2789         return InvokeOnGetPropertyRequested(*pVePropChildrenTransform).ToFloatMatrix4();
2790 #else
2791         return __childrenTransform;
2792 #endif
2793 }
2794
2795
2796 result
2797 _VisualElementImpl::SetChildrenTransformMatrixI(const FloatMatrix4& xform, bool updateDecomposed)
2798 {
2799         FloatMatrix4 matrixAdjusted(xform);
2800         FloatMatrix4 oldValue(__childrenTransform);
2801         result r = E_SUCCESS;
2802
2803         if (unlikely(GetSharedData().pEventListener != null))
2804         {
2805                 if (IS_MODEL(this))     // CHECKME: checking need??
2806                 {
2807                         r = VE_DELEGATE(this, InvokeOnChildrenTransformMatrixChanging, matrixAdjusted);
2808                 }
2809         }
2810
2811
2812         if (r == E_SUCCESS && likely(matrixAdjusted != __childrenTransform))    // check again because delegate may change the transform matrix
2813         {
2814
2815                 // May be un-needed from now...... (no support for VE without surface or shared-canvas)
2816                 if (!IS_PRESENTATION(this))
2817                 {
2818                         int count = __children.GetCount();
2819                         for (int i = 0; i < count; i++)
2820                         {
2821                                 // VE with surface will be exposed automatically on rebuilding coordinates...
2822                                 _VisualElementImpl* pVe = __children.GetChildAt(i);
2823                                 if (pVe && !NEED_SURFACE(pVe))
2824                                 {
2825                                         pVe->ExposeRectangle(null, true);
2826
2827                                         // render target update for previous bounds
2828                                         pVe->InvalidateVisibleRectToRenderTarget(null);
2829                                 }
2830                         }
2831                 }
2832
2833                 MatrixUtilCopy(__childrenTransform, matrixAdjusted);
2834
2835                 if (unlikely(updateDecomposed))
2836                 {
2837                         __decomposedChildrenTransform.SetTransformMatrix(__childrenTransform);
2838                 }
2839
2840                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
2841         }
2842
2843         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
2844         {
2845                 FloatMatrix4 currentValue = __pPresentation->__childrenTransform;
2846                 const String* subProperties[] = {
2847                                 pVeSubPropChildrenTransformRotationX,
2848                                 pVeSubPropChildrenTransformRotationY,
2849                                 pVeSubPropChildrenTransformRotationZ,
2850                                 pVeSubPropChildrenTransformScaleX,
2851                                 pVeSubPropChildrenTransformScaleY,
2852                                 pVeSubPropChildrenTransformScaleZ,
2853                                 pVeSubPropChildrenTransformTranslationX,
2854                                 pVeSubPropChildrenTransformTranslationY,
2855                                 pVeSubPropChildrenTransformTranslationZ,
2856                                 pVeSubPropChildrenTransformRotationAnchorX,
2857                                 pVeSubPropChildrenTransformRotationAnchorY,
2858                                 pVeSubPropChildrenTransformRotationAnchorZ,
2859                                 pVeSubPropChildrenTransformScaleAnchorX,
2860                                 pVeSubPropChildrenTransformScaleAnchorY,
2861                                 pVeSubPropChildrenTransformScaleAnchorZ,
2862                                 NULL};
2863
2864                 if(CreateImplicitAnimationIfNeeded(*pVePropChildrenTransform,   __childrenTransform, currentValue, subProperties ) == false)
2865                 {
2866                         __pPresentation->SetChildrenTransformMatrixProperty(__childrenTransform);
2867                 }
2868
2869                 VE_DELEGATE(this, InvokeOnChildrenTransformMatrixChanged, oldValue);
2870         }
2871         return E_SUCCESS;
2872 }
2873
2874
2875 result
2876 _VisualElementImpl::SetChildrenTransformMatrix(const FloatMatrix4& xform)
2877 {
2878         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
2879         result r = E_SUCCESS;
2880
2881         //PROPERTY_PROCESS(SetChildrenTransformMatrixI, GetChildrenTransformMatrixProperty, SetChildrenTransformMatrixProperty, pVePropChildrenTransform, __childrenTransform, xform);
2882         if (IS_INTERNAL_CLASS(__pPublicInstance))
2883         {
2884                 r = SetChildrenTransformMatrixI(xform);
2885         }
2886         else
2887         {
2888                 r = InvokeOnSetPropertyRequested(*pVePropChildrenTransform, Variant(xform));
2889         }
2890
2891         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
2892
2893         return r;
2894 }
2895
2896 Variant
2897 _VisualElementImpl::GetChildrenTransformMatrixProperty(void) const
2898 {
2899         ClearLastResult();
2900
2901         return Variant(__childrenTransform);
2902 }
2903
2904
2905 result
2906 _VisualElementImpl::SetChildrenTransformMatrixProperty(const Variant& v)
2907 {
2908         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_MATRIX4, E_INVALID_ARG,     E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2909
2910         return SetChildrenTransformMatrixI(v.ToFloatMatrix4(), true);
2911 }
2912
2913 Variant
2914 _VisualElementImpl::GetChildrenTransformRotationXSubProperty(void) const
2915 {
2916         ClearLastResult();
2917
2918         float angleX = 0.0f;
2919         float angleY = 0.0f;
2920         float angleZ = 0.0f;
2921         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2922
2923         return Variant(angleX);
2924 }
2925
2926 result
2927 _VisualElementImpl::SetChildrenTransformRotationXSubProperty(const Variant& v)
2928 {
2929         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2930
2931         float angleX = 0.0f;
2932         float angleY = 0.0f;
2933         float angleZ = 0.0f;
2934         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2935         __decomposedChildrenTransform.UpdateRotationFromEulerAngles(v.ToFloat(), angleY, angleZ);
2936
2937         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
2938 }
2939
2940 Variant
2941 _VisualElementImpl::GetChildrenTransformRotationYSubProperty(void) const
2942 {
2943         ClearLastResult();
2944
2945         float angleX = 0.0f;
2946         float angleY = 0.0f;
2947         float angleZ = 0.0f;
2948         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2949
2950         return Variant(angleY);
2951 }
2952
2953 result
2954 _VisualElementImpl::SetChildrenTransformRotationYSubProperty(const Variant& v)
2955 {
2956         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2957
2958         float angleX = 0.0f;
2959         float angleY = 0.0f;
2960         float angleZ = 0.0f;
2961         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2962         __decomposedChildrenTransform.UpdateRotationFromEulerAngles(angleX, v.ToFloat(), angleZ);
2963
2964         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
2965 }
2966
2967 Variant
2968 _VisualElementImpl::GetChildrenTransformRotationZSubProperty(void) const
2969 {
2970         ClearLastResult();
2971
2972         float angleX = 0.0f;
2973         float angleY = 0.0f;
2974         float angleZ = 0.0f;
2975         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2976
2977         return Variant(angleZ);
2978 }
2979
2980 result
2981 _VisualElementImpl::SetChildrenTransformRotationZSubProperty(const Variant& v)
2982 {
2983         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
2984
2985         float angleX = 0.0f;
2986         float angleY = 0.0f;
2987         float angleZ = 0.0f;
2988         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
2989         __decomposedChildrenTransform.UpdateRotationFromEulerAngles(angleX, angleY, v.ToFloat());
2990
2991         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
2992 }
2993
2994 Variant
2995 _VisualElementImpl::GetChildrenTransformRotationXYSubProperty(void) const
2996 {
2997         ClearLastResult();
2998
2999         float angleX = 0.0f;
3000         float angleY = 0.0f;
3001         float angleZ = 0.0f;
3002         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
3003
3004         return Variant(FloatPoint(angleX, angleY));
3005 }
3006
3007 result
3008 _VisualElementImpl::SetChildrenTransformRotationXYSubProperty(const Variant& v)
3009 {
3010         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3011
3012         const FloatPoint& point = v.ToFloatPoint();
3013
3014         float angleX = 0.0f;
3015         float angleY = 0.0f;
3016         float angleZ = 0.0f;
3017         __decomposedChildrenTransform.GetEulerAngles(angleX, angleY, angleZ);
3018         __decomposedChildrenTransform.UpdateRotationFromEulerAngles(point.x, point.y, angleZ);
3019
3020         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3021 }
3022
3023 Variant
3024 _VisualElementImpl::GetChildrenTransformRotationAnchorXSubProperty(void) const
3025 {
3026         ClearLastResult();
3027
3028         float anchorX = 0.0f;
3029         float anchorY = 0.0f;
3030         float anchorZ = 0.0f;
3031         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3032
3033         return Variant(anchorX);
3034 }
3035
3036 result
3037 _VisualElementImpl::SetChildrenTransformRotationAnchorXSubProperty(const Variant& v)
3038 {
3039         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3040
3041         float anchorX = 0.0f;
3042         float anchorY = 0.0f;
3043         float anchorZ = 0.0f;
3044         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3045         __decomposedChildrenTransform.SetRotationAnchor(v.ToFloat(), anchorY, anchorZ);
3046
3047         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3048 }
3049
3050 Variant
3051 _VisualElementImpl::GetChildrenTransformRotationAnchorYSubProperty(void) const
3052 {
3053         ClearLastResult();
3054
3055         float anchorX = 0.0f;
3056         float anchorY = 0.0f;
3057         float anchorZ = 0.0f;
3058         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3059
3060         return Variant(anchorY);
3061 }
3062
3063 result
3064 _VisualElementImpl::SetChildrenTransformRotationAnchorYSubProperty(const Variant& v)
3065 {
3066         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3067
3068         float anchorX = 0.0f;
3069         float anchorY = 0.0f;
3070         float anchorZ = 0.0f;
3071         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3072         __decomposedChildrenTransform.SetRotationAnchor(anchorX, v.ToFloat(), anchorZ);
3073
3074         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3075 }
3076
3077 Variant
3078 _VisualElementImpl::GetChildrenTransformRotationAnchorZSubProperty(void) const
3079 {
3080         ClearLastResult();
3081
3082         float anchorX = 0.0f;
3083         float anchorY = 0.0f;
3084         float anchorZ = 0.0f;
3085         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3086
3087         return Variant(anchorZ);
3088 }
3089
3090 result
3091 _VisualElementImpl::SetChildrenTransformRotationAnchorZSubProperty(const Variant& v)
3092 {
3093         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3094
3095         float anchorX = 0.0f;
3096         float anchorY = 0.0f;
3097         float anchorZ = 0.0f;
3098         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3099         __decomposedChildrenTransform.SetRotationAnchor(anchorX, anchorY, v.ToFloat());
3100
3101         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3102 }
3103
3104 Variant
3105 _VisualElementImpl::GetChildrenTransformRotationAnchorXYSubProperty(void) const
3106 {
3107         ClearLastResult();
3108
3109         float anchorX = 0.0f;
3110         float anchorY = 0.0f;
3111         float anchorZ = 0.0f;
3112         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3113
3114         return Variant(FloatPoint(anchorX, anchorY));
3115 }
3116
3117 result
3118 _VisualElementImpl::SetChildrenTransformRotationAnchorXYSubProperty(const Variant& v)
3119 {
3120         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3121
3122         const FloatPoint& point = v.ToFloatPoint();
3123
3124         float anchorX = 0.0f;
3125         float anchorY = 0.0f;
3126         float anchorZ = 0.0f;
3127         __decomposedChildrenTransform.GetRotationAnchor(anchorX, anchorY, anchorZ);
3128         __decomposedChildrenTransform.SetRotationAnchor(point.x, point.y, anchorZ);
3129
3130         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3131 }
3132
3133 Variant
3134 _VisualElementImpl::GetChildrenTransformScaleXSubProperty(void) const
3135 {
3136         ClearLastResult();
3137
3138         float scaleX = 1.0f;
3139         float scaleY = 1.0f;
3140         float scaleZ = 1.0f;
3141         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3142
3143         return Variant(scaleX);
3144 }
3145
3146 result
3147 _VisualElementImpl::SetChildrenTransformScaleXSubProperty(const Variant& v)
3148 {
3149         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3150
3151         float scaleX = 1.0f;
3152         float scaleY = 1.0f;
3153         float scaleZ = 1.0f;
3154         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3155         __decomposedChildrenTransform.SetScaleFactors(v.ToFloat(), scaleY, scaleZ);
3156
3157         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3158 }
3159
3160 Variant
3161 _VisualElementImpl::GetChildrenTransformScaleYSubProperty(void) const
3162 {
3163         ClearLastResult();
3164
3165         float scaleX = 1.0f;
3166         float scaleY = 1.0f;
3167         float scaleZ = 1.0f;
3168         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3169
3170         return Variant(scaleY);
3171 }
3172
3173 result
3174 _VisualElementImpl::SetChildrenTransformScaleYSubProperty(const Variant& v)
3175 {
3176         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3177
3178         float scaleX = 1.0f;
3179         float scaleY = 1.0f;
3180         float scaleZ = 1.0f;
3181         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3182         __decomposedChildrenTransform.SetScaleFactors(scaleX, v.ToFloat(), scaleZ);
3183
3184         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3185 }
3186
3187 Variant
3188 _VisualElementImpl::GetChildrenTransformScaleZSubProperty(void) const
3189 {
3190         ClearLastResult();
3191
3192         float scaleX = 1.0f;
3193         float scaleY = 1.0f;
3194         float scaleZ = 1.0f;
3195         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3196
3197         return Variant(scaleZ);
3198 }
3199
3200 result
3201 _VisualElementImpl::SetChildrenTransformScaleZSubProperty(const Variant& v)
3202 {
3203         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3204
3205         float scaleX = 1.0f;
3206         float scaleY = 1.0f;
3207         float scaleZ = 1.0f;
3208         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3209         __decomposedChildrenTransform.SetScaleFactors(scaleX, scaleY, v.ToFloat());
3210
3211         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3212 }
3213
3214 Variant
3215 _VisualElementImpl::GetChildrenTransformScaleXYSubProperty(void) const
3216 {
3217         ClearLastResult();
3218
3219         float scaleX = 1.0f;
3220         float scaleY = 1.0f;
3221         float scaleZ = 1.0f;
3222         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3223
3224         return Variant(FloatPoint(scaleX, scaleY));
3225 }
3226
3227 result
3228 _VisualElementImpl::SetChildrenTransformScaleXYSubProperty(const Variant& v)
3229 {
3230         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3231
3232         const FloatPoint& point = v.ToFloatPoint();
3233
3234         float scaleX = 1.0f;
3235         float scaleY = 1.0f;
3236         float scaleZ = 1.0f;
3237         __decomposedChildrenTransform.GetScaleFactors(scaleX, scaleY, scaleZ);
3238         __decomposedChildrenTransform.SetScaleFactors(point.x, point.y, scaleZ);
3239
3240         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3241 }
3242
3243 Variant
3244 _VisualElementImpl::GetChildrenTransformScaleAnchorXSubProperty(void) const
3245 {
3246         ClearLastResult();
3247
3248         float anchorX = 0.0f;
3249         float anchorY = 0.0f;
3250         float anchorZ = 0.0f;
3251         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3252
3253         return Variant(anchorX);
3254 }
3255
3256 result
3257 _VisualElementImpl::SetChildrenTransformScaleAnchorXSubProperty(const Variant& v)
3258 {
3259         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3260
3261         float anchorX = 0.0f;
3262         float anchorY = 0.0f;
3263         float anchorZ = 0.0f;
3264         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3265         __decomposedChildrenTransform.SetScaleAnchor(v.ToFloat(), anchorY, anchorZ);
3266
3267         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3268 }
3269
3270 Variant
3271 _VisualElementImpl::GetChildrenTransformScaleAnchorYSubProperty(void) const
3272 {
3273         ClearLastResult();
3274
3275         float anchorX = 0.0f;
3276         float anchorY = 0.0f;
3277         float anchorZ = 0.0f;
3278         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3279
3280         return Variant(anchorY);
3281 }
3282
3283 result
3284 _VisualElementImpl::SetChildrenTransformScaleAnchorYSubProperty(const Variant& v)
3285 {
3286         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3287
3288         float anchorX = 0.0f;
3289         float anchorY = 0.0f;
3290         float anchorZ = 0.0f;
3291         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3292         __decomposedChildrenTransform.SetScaleAnchor(anchorX, v.ToFloat(), anchorZ);
3293
3294         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3295 }
3296
3297 Variant
3298 _VisualElementImpl::GetChildrenTransformScaleAnchorZSubProperty(void) const
3299 {
3300         ClearLastResult();
3301
3302         float anchorX = 0.0f;
3303         float anchorY = 0.0f;
3304         float anchorZ = 0.0f;
3305         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3306
3307         return Variant(anchorZ);
3308 }
3309
3310 result
3311 _VisualElementImpl::SetChildrenTransformScaleAnchorZSubProperty(const Variant& v)
3312 {
3313         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3314
3315         float anchorX = 0.0f;
3316         float anchorY = 0.0f;
3317         float anchorZ = 0.0f;
3318         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3319         __decomposedChildrenTransform.SetScaleAnchor(anchorX, anchorY, v.ToFloat());
3320
3321         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3322 }
3323
3324 Variant
3325 _VisualElementImpl::GetChildrenTransformScaleAnchorXYSubProperty(void) const
3326 {
3327         ClearLastResult();
3328
3329         float anchorX = 0.0f;
3330         float anchorY = 0.0f;
3331         float anchorZ = 0.0f;
3332         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3333
3334         return Variant(FloatPoint(anchorX, anchorY));
3335 }
3336
3337 result
3338 _VisualElementImpl::SetChildrenTransformScaleAnchorXYSubProperty(const Variant& v)
3339 {
3340         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3341
3342         const FloatPoint& point = v.ToFloatPoint();
3343
3344         float anchorX = 0.0f;
3345         float anchorY = 0.0f;
3346         float anchorZ = 0.0f;
3347         __decomposedChildrenTransform.GetScaleAnchor(anchorX, anchorY, anchorZ);
3348         __decomposedChildrenTransform.SetScaleAnchor(point.x, point.y, anchorZ);
3349
3350         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3351 }
3352
3353 Variant
3354 _VisualElementImpl::GetChildrenTransformTranslationXSubProperty(void) const
3355 {
3356         ClearLastResult();
3357
3358         float translateX = 0.0f;
3359         float translateY = 0.0f;
3360         float translateZ = 0.0f;
3361         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3362
3363         return Variant(translateX);
3364 }
3365
3366 result
3367 _VisualElementImpl::SetChildrenTransformTranslationXSubProperty(const Variant& v)
3368 {
3369         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3370
3371         float translateX = 0.0f;
3372         float translateY = 0.0f;
3373         float translateZ = 0.0f;
3374         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3375         __decomposedChildrenTransform.SetTranslationFactors(v.ToFloat(), translateY, translateZ);
3376
3377         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3378 }
3379
3380 Variant
3381 _VisualElementImpl::GetChildrenTransformTranslationYSubProperty(void) const
3382 {
3383         ClearLastResult();
3384
3385         float translateX = 0.0f;
3386         float translateY = 0.0f;
3387         float translateZ = 0.0f;
3388         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3389
3390         return Variant(translateY);
3391 }
3392
3393 result
3394 _VisualElementImpl::SetChildrenTransformTranslationYSubProperty(const Variant& v)
3395 {
3396         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3397
3398         float translateX = 0.0f;
3399         float translateY = 0.0f;
3400         float translateZ = 0.0f;
3401         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3402         __decomposedChildrenTransform.SetTranslationFactors(translateX, v.ToFloat(), translateZ);
3403
3404         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3405 }
3406
3407 Variant
3408 _VisualElementImpl::GetChildrenTransformTranslationZSubProperty(void) const
3409 {
3410         ClearLastResult();
3411
3412         float translateX = 0.0f;
3413         float translateY = 0.0f;
3414         float translateZ = 0.0f;
3415         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3416
3417         return Variant(translateZ);
3418 }
3419
3420 result
3421 _VisualElementImpl::SetChildrenTransformTranslationZSubProperty(const Variant& v)
3422 {
3423         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3424
3425         float translateX = 0.0f;
3426         float translateY = 0.0f;
3427         float translateZ = 0.0f;
3428         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3429         __decomposedChildrenTransform.SetTranslationFactors(translateX, translateY, v.ToFloat());
3430
3431         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3432 }
3433
3434 Variant
3435 _VisualElementImpl::GetChildrenTransformTranslationXYSubProperty(void) const
3436 {
3437         ClearLastResult();
3438
3439         float translateX = 0.0f;
3440         float translateY = 0.0f;
3441         float translateZ = 0.0f;
3442         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3443
3444         return Variant(FloatPoint(translateX, translateY));
3445 }
3446
3447 result
3448 _VisualElementImpl::SetChildrenTransformTranslationXYSubProperty(const Variant& v)
3449 {
3450         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_FLOAT_POINT, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3451
3452         const FloatPoint& point = v.ToFloatPoint();
3453
3454         float translateX = 0.0f;
3455         float translateY = 0.0f;
3456         float translateZ = 0.0f;
3457         __decomposedChildrenTransform.GetTranslationFactors(translateX, translateY, translateZ);
3458         __decomposedChildrenTransform.SetTranslationFactors(point.x, point.y, translateZ);
3459
3460         return SetChildrenTransformMatrixI(__decomposedChildrenTransform.GetTransformMatrix(), false);
3461 }
3462
3463 bool
3464 _VisualElementImpl::IsClipToParent(void) const
3465 {
3466         ClearLastResult();
3467
3468         // TBD: forward using property or direct return ?
3469 #if 0
3470         return InvokeOnGetPropertyRequested(*pVePropClipToParent).ToBool();
3471 #else
3472         return false;
3473 #endif
3474 }
3475
3476 // TBD: clipToParent is not animatable, right??
3477 result
3478 _VisualElementImpl::SetClipToParent(bool clipToParent)
3479 {
3480         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3481
3482         return InvokeOnSetPropertyRequested(*pVePropClipToParent, Variant(clipToParent));
3483 }
3484
3485 Variant
3486 _VisualElementImpl::GetClipToParentProperty(void) const
3487 {
3488         ClearLastResult();
3489         //SysLog(NID_UI_ANIM, "WARNING: ClipToParent is deprecated.");
3490
3491         return Variant(false);
3492 }
3493
3494 result
3495 _VisualElementImpl::SetClipToParentProperty(const Variant& v)
3496 {
3497         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3498
3499         //SysLog(NID_UI_ANIM, "WARNING: ClipToParent is deprecated.");
3500
3501         return E_SUCCESS;
3502 }
3503
3504 bool
3505 _VisualElementImpl::IsClipChildrenEnabled(void) const
3506 {
3507         ClearLastResult();
3508
3509         return __isClipChildren;
3510 }
3511
3512 result
3513 _VisualElementImpl::SetClipChildrenEnabled(bool clipChildren)
3514 {
3515         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3516         result r = E_SUCCESS;
3517
3518         if (IS_INTERNAL_CLASS(__pPublicInstance))
3519         {
3520                 r = SetClipChildrenProperty(Variant(clipChildren));
3521         }
3522         else
3523         {
3524                 r = InvokeOnSetPropertyRequested(*pVePropClipChildren, Variant(clipChildren));
3525         }
3526         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
3527
3528         return r;
3529 }
3530
3531 Variant
3532 _VisualElementImpl::GetClipChildrenProperty(void) const
3533 {
3534         ClearLastResult();
3535
3536         return Variant(__isClipChildren);
3537 }
3538
3539 result
3540 _VisualElementImpl::SetClipChildrenProperty(const Variant& v)
3541 {
3542         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3543
3544         bool clipChildren = v.ToBool();
3545         if (likely(clipChildren != __isClipChildren))
3546         {
3547
3548                 //SysLog(NID_UI_ANIM, "%p ClipChildren = %d", this, clipChildren);
3549
3550                 __isClipChildren = clipChildren;
3551                 InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
3552
3553         }
3554
3555         if(IS_MODEL(this) && IS_NEEDED_UPDATE_PRESENTATION(this))
3556         {
3557                 __pPresentation->SetClipChildrenProperty(__isClipChildren);
3558         }
3559
3560         return E_SUCCESS;
3561 }
3562
3563 bool
3564 _VisualElementImpl::IsSurfaceOpaque(void) const
3565 {
3566         ClearLastResult();
3567
3568         // TBD: forward using property or direct return ?
3569 #if 0
3570         return InvokeOnGetPropertyRequested(*pVePropSurfaceOpaque).ToBool();
3571 #else
3572         return GetSharedData().isSurfaceOpaque;
3573 #endif
3574 }
3575
3576 result
3577 _VisualElementImpl::SetSurfaceOpaque(bool isSurfaceOpaque)
3578 {
3579         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3580         result r = E_SUCCESS;
3581
3582         if (IS_INTERNAL_CLASS(__pPublicInstance))
3583         {
3584                 r = SetSurfaceOpaqueProperty(Variant(isSurfaceOpaque));
3585         }
3586         else
3587         {
3588                 r = InvokeOnSetPropertyRequested(*pVePropSurfaceOpaque, Variant(isSurfaceOpaque));
3589         }
3590         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
3591
3592         return E_SUCCESS;
3593 }
3594
3595 Variant
3596 _VisualElementImpl::GetSurfaceOpaqueProperty(void) const
3597 {
3598         ClearLastResult();
3599
3600         return Variant(GetSharedData().isSurfaceOpaque);
3601 }
3602
3603 result
3604 _VisualElementImpl::SetSurfaceOpaqueProperty(const Variant& v)
3605 {
3606         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_BOOL, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
3607
3608         bool isSurfaceOpaque = v.ToBool();
3609         if (isSurfaceOpaque == GetSharedData().isSurfaceOpaque)
3610                 return E_SUCCESS;
3611
3612         InvalidateHierarchyProps(HIERARCHY_PROPERTY_CONTENTOPACITY, false, false); //don't have to apply the changed opacity to children.
3613
3614         if (IS_PRESENTATION(this))
3615         {
3616                 GetSharedData().isSurfaceOpaque = isSurfaceOpaque;
3617
3618 #ifndef LAZY_EVALUATION
3619                 // not needed when no surface
3620                 if (HAVE_SURFACE(this))
3621                         GetSharedData().NodeReconfigure(*this);
3622 #endif
3623         }
3624         else
3625         {
3626                 if(IS_NEEDED_UPDATE_PRESENTATION(this))
3627                 {
3628                         __pPresentation->SetSurfaceOpaqueProperty(isSurfaceOpaque);
3629                 }
3630         }
3631
3632         return E_SUCCESS;
3633 }
3634
3635 Canvas*
3636 _VisualElementImpl::GetCanvasN(void)
3637 {
3638         return GetCanvasN(Rectangle(0, 0, __bounds.width, __bounds.height));
3639 }
3640
3641 Canvas*
3642 _VisualElementImpl::GetCanvasN(const Rectangle& bounds)
3643 {
3644         SysTryReturn(NID_UI_ANIM, !GetSharedData().fixedSurfaceSize, null, E_INVALID_OPERATION, "[E_INVALID_OPERATION] Canvas can't be instantiated for fixed-size user surface.");
3645         SysTryReturn(NID_UI_ANIM, bounds.width >= 0 && bounds.height >= 0, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Canvas size is out of range. size = (%f, %f)", bounds.width, bounds.height);
3646         SysTryReturn(NID_UI_ANIM, __imageFilePath.IsEmpty(), null, E_OPERATION_FAILED, "[E_OPERATION_FAILED] Can't get canvas for surface which is from image file.");
3647         SysTryReturn(NID_UI_ANIM, GetRoot(), null,  E_INVALID_STATE, "[E_INVALID_STATE] VisualElement is not attached to main tree.");
3648
3649
3650         // WARNING: WARNING: WARNING:
3651         //      If need-redraw and surface is set by user, VE do *NOT* allow GetCanvasN
3652         //      because 'bounds' is for the VE does not comply with size of surface.
3653         //      (in which case the surface will be displayed scaled)
3654
3655         _VisualElementImpl* pRenderTarget = null;
3656
3657         pRenderTarget = GetRenderTarget();
3658         SysTryReturn(NID_UI_ANIM, pRenderTarget, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Target VisualElement is not available.");
3659         SysTryReturn(NID_UI_ANIM, pRenderTarget->__pSharedData, null, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Target VisualElement is not constructed.");
3660
3661         // WARNING:
3662         //      Forcefully create surface if GetCanvasN is called.
3663         //      Without followings, surface may not be created if size of bounds == 0 (the initial size)
3664         if (!HAVE_SURFACE(this))
3665                 __needRecreateSurface = true;
3666
3667         pRenderTarget->RebuildHierarchyProps(0, true, true);
3668 #if 1
3669         SysTryReturn(NID_UI_ANIM, pRenderTarget->GetSharedData().pNativeNode->GetSurface(), null, E_SYSTEM, "[E_INVALID_STATE] Target VisualElement's surface is not constructed.");
3670 #else
3671         SysTryReturn(NID_UI_ANIM, pRenderTarget->GetSharedData().pSurface, null, E_SYSTEM, "[E_INVALID_STATE] Target VisualElement's surface is not constructed.");
3672 #endif
3673
3674
3675         FloatRectangle canvasBounds;
3676         FloatRectangle clipBounds;
3677
3678         // TODO: FIXME:
3679         //      Use surface size, not bounds !!!
3680
3681         int canvasX, canvasY, canvasW, canvasH;
3682
3683         if (bounds.width == 0 || bounds.height == 0)
3684         {
3685                 float surfaceWidth = __bounds.width;
3686                 float surfaceHeight = __bounds.height;
3687                 AdjustSizeForSurface(surfaceWidth, surfaceHeight);
3688
3689                 SysTryReturn(NID_UI_ANIM, bounds.x >= 0.0f && bounds.y >= 0.0f && bounds.x <= int(surfaceWidth) && bounds.y <= int(surfaceHeight), null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Bounds is out of range.");
3690
3691                 canvasX = bounds.x;
3692                 canvasY = bounds.y;
3693                 canvasW = 0;
3694                 canvasH = 0;
3695         }
3696         else
3697         {
3698                 clipBounds.x = 0.0f;
3699                 clipBounds.y = 0.0f;
3700                 clipBounds.width = __bounds.width;
3701                 clipBounds.height = __bounds.height;
3702
3703                 canvasBounds.x = bounds.x;
3704                 canvasBounds.y = bounds.y;
3705                 canvasBounds.width = bounds.width;
3706                 canvasBounds.height = bounds.height;
3707
3708                 canvasBounds = canvasBounds.GetIntersection(clipBounds);
3709                 pRenderTarget->__pPresentation->ConvertCoordinates(canvasBounds, this->__pPresentation);
3710                 canvasBounds = canvasBounds.GetIntersection(pRenderTarget->GetDrawableRect());
3711
3712                 SysTryReturn(NID_UI_ANIM, canvasBounds.width > 0 && canvasBounds.height > 0, null, E_OUT_OF_RANGE, "[E_OUT_OF_RANGE] Bounds is out of range.");
3713                 _VisualElementCoordinateSystem::MakeIntegralPoint(canvasBounds.x, canvasBounds.y, canvasX, canvasY);
3714                 _VisualElementCoordinateSystem::MakeIntegralDimension(canvasBounds.width, canvasBounds.height, canvasW, canvasH);
3715         }
3716
3717         // WARNING:
3718         //      From now, canvasBounds contains the clipping area, not subcanvas area.
3719         //      (0, 0) of the canvas should be placed on the left-top of the VE !
3720
3721         unique_ptr<_VisualElementCanvas> pCanvas(new (std::nothrow) _VisualElementCanvas);
3722
3723         result r = pCanvas->Construct(*pRenderTarget->GetSharedData().pNativeNode->GetSurface(), Rectangle(canvasX, canvasY, canvasW, canvasH));
3724         SysTryReturn(NID_UI_ANIM, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] VisualElement is not constructed.");
3725
3726         pRenderTarget->SetFlushNeeded();
3727
3728         ClearLastResult();
3729
3730         return pCanvas.release();
3731 }
3732
3733 _VisualElementImpl*
3734 _VisualElementImpl::GetRoot(void) const
3735 {
3736         ClearLastResult();
3737
3738         if (IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES))
3739         {
3740                 const_cast< _VisualElementImpl* >(this)->RebuildCoordinates();
3741         }
3742
3743         return __pRoot;
3744 }
3745
3746 _VisualElementImpl*
3747 _VisualElementImpl::GetParent(void) const
3748 {
3749         ClearLastResult();
3750
3751         return __pParent;
3752 }
3753
3754 int
3755 _VisualElementImpl::GetChildrenCount(void) const
3756 {
3757         ClearLastResult();
3758
3759         return __children.GetCount();
3760 }
3761
3762 Tizen::Base::Collection::IList*
3763 _VisualElementImpl::GetPublicChildrenN(void) const
3764 {
3765         unique_ptr<Tizen::Base::Collection::ArrayList> pArrayList(new (std::nothrow) Tizen::Base::Collection::ArrayList());
3766         SysTryReturn(NID_UI_ANIM, pArrayList, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3767
3768         int count = __children.GetCount();
3769         SysTryReturn(NID_UI_ANIM, !IsFailed(pArrayList->Construct(count)), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3770
3771         for (int i = 0; i < count; i++)
3772         {
3773                 const _VisualElementImpl* pChild = __children.GetChildAt(i);
3774
3775                 if (likely(pChild) && likely(pChild->__pPublicInstance))
3776                 {
3777                         SysTryReturn(NID_UI_ANIM, !IsFailed(pArrayList->Add(*pChild->__pPublicInstance)), null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
3778                 }
3779         }
3780
3781         ClearLastResult();
3782
3783         return pArrayList.release();
3784 }
3785
3786 bool
3787 _VisualElementImpl::IsChildOf(const _VisualElementImpl& element) const
3788 {
3789         ClearLastResult();
3790
3791         if (unlikely(this == &element))
3792         {
3793                 return false;
3794         }
3795
3796         if (unlikely(!__pParent))
3797         {
3798                 return false;
3799         }
3800
3801         if (likely(__pParent == &element))
3802         {
3803                 return true;
3804         }
3805
3806         return __pParent->IsChildOf(element);
3807 }
3808
3809 result
3810 _VisualElementImpl::SetZOrder(const _VisualElementImpl* pReference, bool above)
3811 {
3812         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3813         SysTryReturnResult(NID_UI_ANIM, !pReference || pReference->__pParent, E_INVALID_ARG, "pReference doesn't have parent.");
3814         SysTryReturnResult(NID_UI_ANIM, __pParent, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement doesn't have a parent.");
3815         SysTryReturnResult(NID_UI_ANIM, __isAllowedTreeModification == true, E_INVALID_OPERATION, "Z-order cannot be modified inside the OnAttached() or OnDetached() method of VisualElementEventListener.");
3816
3817         return __pParent->InsertChild(*this, pReference, above);
3818 }
3819
3820 void
3821 _VisualElementImpl::RemoveFromParent(void)
3822 {
3823         if (likely(__pParent))
3824         {
3825                 __pParent->RemoveChild(*this);
3826         }
3827 }
3828
3829 result
3830 _VisualElementImpl::AddChild(_VisualElementImpl& child)
3831 {
3832         //SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3833         SysTryReturnResult(NID_UI_ANIM, child.__pSharedData, E_INVALID_ARG, "Child VisualElement is not constructed.");
3834         SysTryReturnResult(NID_UI_ANIM, child.__isAllowedTreeModification == true, E_INVALID_OPERATION, "Z-order cannot be modified inside the OnAttached() or OnDetached() method of VisualElementEventListener.");
3835
3836         return ChangeZOrder(child, null, true, child._zOrderGroup);
3837 }
3838
3839 int
3840 _VisualElementImpl::GetChildIndex(const _VisualElementImpl& child) const
3841 {
3842         int index = 0;
3843         result r = __children.IndexOf(const_cast< _VisualElementImpl* >(&child), index);
3844
3845         if (r == E_SUCCESS)
3846         {
3847                 return index;
3848         }
3849
3850         // r == E_OUT_OF_RANGE or E_OBJ_NOT_FOUND
3851         return -1;
3852 }
3853
3854 /**
3855  * @param[in]   group           will be changed group of the visualemenet.
3856  * @param[out]  belowIndex  the index of last item of below group's item.
3857  * @param[out]  aboveIndex      the index of first item of above group's item.
3858  *
3859  * if group is lower than __children's lowest item, belowIndex = -1 , aboveIndex = 0
3860  * if group is higher than __children's highest item, belowIndex is last index of children, aboveIndex is 1 bigger than belowIndex.
3861  *
3862  *(ex)
3863  * B = Z_ORDER_GROUP_ALWAYS_BELOW_BOTTOM        // lowest drawing gadget.(Background)
3864  * N = Z_ORDER_GROUP_NORMAL;                            // level of the default group.
3865  * T = Z_ORDER_GROUP_ALWAYS_ON_TOP;             // highest drawing gadget.
3866  *  0  1  2  3  4  5  6  7  8  9
3867  * [B][B][B][N][N][N][N][T][T][T]
3868  * __GetZOrderGroupIndex(Z_ORDER_GROUP_NORMAL, below, above);
3869  *                                            below = 2
3870  *                                            above = 7
3871  * __GetZOrderGroupIndex(Z_ORDER_GROUP_ALWAYS_ON_TOP, below, above);
3872  *                                            below = 6
3873  *                                            above = 10
3874  * __GetZOrderGroupIndex(Z_ORDER_GROUP_ALWAYS_BELOW_BOTTOM, below, above);
3875  *                                            below = -1
3876  *                                            above = 3
3877  *  0  1  2  3  4  5  6  7  8  9
3878  * [B][B][B][B][B][T][T][T][T][T]
3879  * __GetZOrderGroupIndex(Z_ORDER_GROUP_NORMAL, below, above);
3880  *                                            below = 4
3881  *                                            above = 5
3882  * __GetZOrderGroupIndex(Z_ORDER_GROUP_ALWAYS_ON_TOP, below, above);
3883  *                                            below = 4
3884  *                                            above = 10
3885  * __GetZOrderGroupIndex(Z_ORDER_GROUP_ALWAYS_BELOW_BOTTOM, below, above);
3886  *                                            below = -1
3887  *                                            above = 5
3888  *
3889  */
3890
3891 int
3892 _VisualElementImpl::GetZOrderGroupIndex(int group, int& belowIndex, int& aboveIndex) const
3893 {
3894         int lastIndex = __children.GetCount() - 1;
3895         if (lastIndex < 0) // _children is empty.
3896         {
3897                 belowIndex = -1;
3898                 aboveIndex = 0;
3899                 return 0;
3900         }
3901
3902         if (group < (__children.GetChildAt(0))->_zOrderGroup)  // group is lower than __children's lowest item.
3903         {
3904                 belowIndex = -1;
3905                 aboveIndex = 0;
3906                 return -1;
3907         }
3908
3909         if (group > (__children.GetChildAt(lastIndex))->_zOrderGroup)  // group is higher than __children's highest item.
3910         {
3911                 belowIndex = lastIndex;
3912                 aboveIndex = lastIndex + 1;
3913                 return 1;
3914         }
3915
3916         int i = lastIndex;
3917
3918         for (; i >= 0; i--)
3919         {
3920                 if (group >= __children.GetChildAt(i)->_zOrderGroup)
3921                 {
3922                         break;
3923                 }
3924         }
3925
3926         aboveIndex = i + 1;
3927
3928         for (; i >= 0; i--)
3929         {
3930                 if (group > __children.GetChildAt(i)->_zOrderGroup)
3931                 {
3932                         break;
3933                 }
3934         }
3935
3936         belowIndex = i;
3937
3938         return 0;
3939 }
3940
3941 result
3942 _VisualElementImpl::InsertChild(_VisualElementImpl& child, const _VisualElementImpl* pReference, bool above)
3943 {
3944         //SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
3945         SysTryReturnResult(NID_UI_ANIM, child.__pSharedData, E_INVALID_ARG, "Child VisualElement is not constructed.");
3946         SysTryReturnResult(NID_UI_ANIM, child.__isAllowedTreeModification == true, E_INVALID_OPERATION, "Z-order cannot be modified inside the OnAttached() or OnDetached() method of VisualElementEventListener.");
3947
3948         int zOrderGroup = child._zOrderGroup;
3949
3950         if (unlikely(pReference))
3951         {
3952                 zOrderGroup = pReference->_zOrderGroup;
3953         }
3954
3955         return ChangeZOrder(child, pReference, above, zOrderGroup);
3956 }
3957
3958 result
3959 _VisualElementImpl::ChangeZOrder(_VisualElementImpl& child, const _VisualElementImpl* pReference, bool above, int group)
3960 {
3961         int indexChild;
3962         int indexReference = -1;
3963         int indexInsert = -1;
3964
3965         // If not constructed well, disallow attaching !
3966
3967         if (IsChildOf(child) || this == &child || &child == pReference || (pReference && pReference->__pParent != this))
3968         {
3969                 return E_INVALID_ARG;
3970         }
3971
3972         // TBD: check ownership!!!
3973         if (IS_PRESENTATION(this))
3974         {
3975                 _RootVisualElement* pChildRoot = child.GetRootPublic();
3976
3977                 if (GetRootPublic() != null && pChildRoot != GetRootPublic())
3978                 {
3979                         child.RebuildNativeNodeTree(*this);
3980                 }
3981         }
3982
3983         if (pReference)
3984         {
3985                 indexReference = GetChildIndex(*pReference);
3986                 SysTryReturnResult(NID_UI_ANIM, indexReference >= 0, E_INVALID_ARG, "Invalid argument(s) is used. pReference is not a child of this instance.");
3987
3988                 if (above)
3989                 {
3990                         indexReference++;
3991                 }
3992         }
3993         else
3994         {
3995                 if (above)
3996                 {
3997                         indexReference = __children.GetCount();
3998                 }
3999                 else
4000                 {
4001                         indexReference = 0;
4002                 }
4003         }
4004
4005         int belowIndex, aboveIndex, indexRange;
4006
4007         indexRange = GetZOrderGroupIndex(group, belowIndex, aboveIndex);
4008
4009         if (indexRange < 0)
4010         {
4011                 indexInsert = 0;
4012         }
4013         else if (indexRange > 0)
4014         {
4015                 indexInsert = __children.GetCount();
4016         }
4017         else
4018         {
4019                 if (indexReference <= belowIndex + 1)
4020                 {
4021                         indexInsert = belowIndex + 1;
4022                 }
4023                 else if (indexReference >= aboveIndex)
4024                 {
4025                         indexInsert = aboveIndex;
4026                 }
4027                 else
4028                 {
4029                         indexInsert = indexReference;
4030                 }
4031
4032                 if (indexInsert < 0)
4033                 {
4034                         indexInsert = 0;
4035                 }
4036         }
4037
4038         if (child.__pParent == this) //case 1: move to the same parent. (just changed order )
4039         {
4040                 indexChild = GetChildIndex(child);
4041                 SysTryReturn(NID_UI_ANIM, indexChild >= 0,
4042                                         E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. The child(%p) isn't managed by this instance.", &child);
4043
4044                 if (indexChild < indexInsert)
4045                 {
4046                         indexInsert--; // one of child item is removed so total item index is decreased.
4047                 }
4048
4049                 if (indexChild == indexInsert) //same position. don't have to do any action.
4050                 {
4051                         child._zOrderGroup = group;
4052
4053                         //update presentation zorder group
4054                         if (!IS_PRESENTATION(this))
4055                         {
4056                                 child.UpdatePresentationWhenZOrderChanged(pReference, above);
4057                         }
4058                         return E_SUCCESS;
4059                 }
4060
4061                 SysTryReturn(NID_UI_ANIM, RemoveChildWithoutReconfiguring(indexChild, true) == E_SUCCESS,
4062                                                 E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument(s) is used. Failed to remove a child(%p) from this instance.", &child);
4063
4064         }
4065         else //case 2: move to the other parent.
4066         {    //case 3: child never been attached to the any parent.
4067                 if (child.__pParent)
4068                 {
4069                         child.__pParent->RemoveChild(child);
4070                 }
4071
4072                 // Setting implicit animation to the child.
4073                 if (!IS_PRESENTATION(this) && _AnimationManager::GetInstance()->IsImplicitAnimationEnabled() && child.__isImplicitAnimationEnabled)
4074                 {
4075                         RemoveAnimation(*pVePropActionAttach);
4076
4077 #if defined(SUPPORT_CUSTOMIZING_ATTACH_DETACH_ANIMATION)
4078                         VisualElementAnimation* pAnimation = child.InvokeCreateAnimationForProperty(*pVePropActionAttach);
4079 #else
4080                         VisualElementPropertyAnimation* pAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4081                         SysTryReturn(NID_UI_ANIM, pAnimation != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4082                         pAnimation->SetPropertyName(*pVePropOpacity);
4083                         pAnimation->SetStartValue(Variant(0.0f));
4084 #endif
4085                         if (pAnimation != null)
4086                         {
4087                                 pAnimation->SetVisualElementAnimationStatusEventListener(null);
4088                                 (child.GetPublic())->AddAnimation(*pVePropActionAttach, *pAnimation);
4089                         }
4090                         delete pAnimation;
4091                 }
4092         }
4093
4094         // set ZOrder group
4095         child._zOrderGroup = group;
4096
4097         //SysLog(NID_UI_ANIM, "Insert child %p(%d)", &child, indexInsert);
4098
4099         if (!IS_PRESENTATION(this))
4100         {
4101                 VE_DELEGATE(this, InvokeOnChildAttaching, child);
4102                 VE_DELEGATE(&child, InvokeOnAttaching, *this);
4103         }
4104
4105         __children.InsertAt(&child, indexInsert);    // need addref -> jobs -> release ...
4106         child.__pParent = this;
4107
4108         child.InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES | HIERARCHY_PROPERTY_OPACITY | HIERARCHY_PROPERTY_SHOWSTATE, true, false);
4109
4110         // propagate child's prop. status to parents
4111         //__InvalidateHierarchyProps(child.__childrenNeedsUpdateProps, false, true);
4112         InvalidateHierarchyProps(child.__childrenNeedsUpdateProps, true, false);
4113
4114         //SetRootNeedsContentUpdate();
4115
4116         // WARNING:
4117         //      When no surface, it is needed to invalidated.
4118         //
4119         if (unlikely(!NEED_SURFACE(&child)))
4120         {
4121                 child.ExposeRectangle(null, true);
4122         }
4123
4124         //
4125         // Because tree hierarchy is not a property, VE hierarchy tree changes are not
4126         // notified by property observer. So, we invoke method in presentation VE directly.
4127         //
4128
4129         if (!IS_PRESENTATION(this))
4130         {
4131                 child.UpdatePresentationWhenZOrderChanged(pReference, above);
4132         }
4133         else
4134         {
4135                 if (likely(GetSharedData().pNativeNode) && likely(child.GetSharedData().pNativeNode))
4136                 {
4137                         _VisualElementImpl* pReferenceNode = null;
4138
4139                         if (indexInsert > 0)
4140                         {
4141                                 pReferenceNode = __children.GetChildAt(indexInsert - 1);
4142                         }
4143
4144                         // exceptional case:  the pRefenreceNode is null and indexInsert are more than __children.count() + 1, then this case is something wrong.
4145                         // normal case : when pReferenceNode is null , indexInsert has 0 or more small value.
4146
4147                         GetSharedData().pNativeNode->InsertChild(
4148                                 *child.GetSharedData().pNativeNode,
4149                                 (pReferenceNode ? pReferenceNode->GetSharedData().pNativeNode : null),
4150                                 (pReferenceNode ? true : false)
4151                         );
4152                 }
4153         }
4154
4155         return E_SUCCESS;
4156 }
4157
4158 result
4159 _VisualElementImpl::UpdatePresentationWhenCustomPropertyChanged(const String& property, const Variant& value)
4160 {
4161         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
4162         result r = E_SUCCESS;
4163
4164         if (IS_NEEDED_UPDATE_PRESENTATION(this))
4165         {
4166
4167                 Variant oldV = __pPresentation->InvokeOnGetPropertyRequested(property);
4168
4169                 if(CreateImplicitAnimationIfNeeded(property,value,oldV, NULL) == false)
4170                 {
4171                         r = __pPresentation->InvokeOnSetPropertyRequested(property, value);
4172                 }
4173         }
4174         return r;
4175 }
4176
4177 void
4178 _VisualElementImpl::UpdatePresentationWhenZOrderChanged(const _VisualElementImpl* pReferenceModel, bool above)
4179 {
4180         if(!IS_MODEL(this) || !__pParent)
4181         {
4182                 return;
4183         }
4184
4185         _VisualElementImpl* pReferencePresenter = (pReferenceModel ? (pReferenceModel->__pPresentation ? pReferenceModel->__pPresentation : null) : null);
4186
4187         if (likely(__pParent->__pPresentation) && likely(__pPresentation))
4188         {
4189                 __pParent->__pPresentation->ChangeZOrder(*__pPresentation, pReferencePresenter, above, _zOrderGroup);
4190
4191                 if (GetSharedData().pEventListener != null)
4192                 {
4193                         InvokeOnAttached();
4194                 }
4195
4196                 if (__pParent->GetSharedData().pEventListener != null)
4197                 {
4198                         __pParent->InvokeOnChildAttached(*this);
4199                 }
4200         }
4201 }
4202
4203 void
4204 _VisualElementImpl::UpdatePresentationWhenChildRemoved(_VisualElementImpl& child, bool deallocate)
4205 {
4206         if(!IS_MODEL(this))
4207         {
4208                 return;
4209         }
4210
4211         if (likely(__pPresentation) && likely(child.GetPresentation()))
4212         {
4213                 __pPresentation->RemoveChild(*child.GetPresentation(), deallocate);
4214         }
4215
4216         // IMPORTANT! When destroying, don't have to invoke OnDetached and OnDetaching after invoked OnDestructing.
4217         // call OnDestructing  -> call OnDetaching it is ambiguous operation
4218         // it is called by RemoveFromParent() method, so pChild is destroying currently.
4219         if (!child.__isDestroying && child.GetSharedData().pEventListener != null)
4220         {
4221                 child.InvokeOnDetached(*this);
4222         }
4223
4224         if (GetSharedData().pEventListener != null)
4225         {
4226                 InvokeOnChildDetached(child);
4227         }
4228 }
4229
4230 result
4231 _VisualElementImpl::RemoveChildWithoutReconfiguring(int indexChild, bool invalidate)
4232 {
4233         SysTryReturnResult(NID_UI_ANIM, indexChild >= 0 && indexChild < __children.GetCount(), E_OBJ_NOT_FOUND, "There is no VisualElement at %d th index.", indexChild);
4234
4235         _VisualElementImpl* pChild = __children.GetChildAt(indexChild);
4236         SysTryReturnResult(NID_UI_ANIM, pChild, E_OBJ_NOT_FOUND, "There is no VisualElement at %d th index.", indexChild);
4237
4238         if (!IS_PRESENTATION(this))
4239         {
4240
4241                 VE_DELEGATE(this, InvokeOnChildDetaching, *pChild);
4242
4243                 // IMPORTANT! When destroying, don't have to invoke OnDetached and OnDetaching after invoked OnDestructing.
4244                 // call OnDestructing  -> call OnDetaching it is ambiguous operation
4245                 // it is called by RemoveFromParent() method, so pChild is destroying currently.
4246                 if (!pChild->__isDestroying)
4247                 {
4248                         VE_DELEGATE(pChild, InvokeOnDetaching);
4249                 }
4250         }
4251
4252         //SysLog(NID_UI_ANIM, "Remove child %p(%d)", pChild, indexChild);
4253         __children.RemoveAt(indexChild);
4254         pChild->__pParent = null;
4255 //      pChild->__ClearHierarchyInfo();
4256
4257
4258         if (!IS_PRESENTATION(this))
4259         {
4260                 // removed element need not invalidation !
4261                 if (invalidate)
4262                 {
4263                         if (NEED_SURFACE(pChild))
4264                         {
4265                                 pChild->ExposeRectangle(null, false);
4266                         }
4267                         else
4268                         {
4269                                 pChild->InvalidateVisibleRectToRenderTarget(null);
4270                         }
4271                 }
4272         }
4273         else
4274         {
4275                 if (GetSharedData().pNativeNode && pChild->GetSharedData().pNativeNode)
4276                 {
4277                         GetSharedData().pNativeNode->RemoveChild(*pChild->GetSharedData().pNativeNode);
4278                 }
4279         }
4280
4281         // WARNING:
4282         //      Because some properties such as root, visible rect and etc. can be accessed detached, invalidating is needed here !
4283         //      (Will be invalidated again on attaching)
4284         //
4285         pChild->InvalidateHierarchyProps(HIERARCHY_PROPERTY_COORDINATES, true, false);
4286
4287         return E_SUCCESS;
4288 }
4289
4290 result
4291 _VisualElementImpl::CreateElementTreeForDetachImplicitAnimation(_VisualElementImpl& child)
4292 {
4293         result r = E_SYSTEM;
4294
4295         VisualElement* pRoot = child.CreateElementForImplicitAnimationN();
4296         if (pRoot == null)
4297         {
4298                 return r;
4299         }
4300
4301         pRoot->_pVisualElementImpl->SetInternal(true);
4302
4303 #if defined(SUPPORT_CUSTOMIZING_ATTACH_DETACH_ANIMATION)
4304         VisualElementAnimation* pAnimation = child.InvokeCreateAnimationForProperty(*pVePropActionDetach);
4305 #else
4306         VisualElementPropertyAnimation* pAnimation = new (std::nothrow) VisualElementPropertyAnimation();
4307         pAnimation->SetPropertyName(*pVePropOpacity);
4308         pAnimation->SetEndValue(Variant(0.0f));
4309 #endif
4310         if (pAnimation)
4311         {
4312                 _VisualElementImplicitAnimationEventListener* pListener = new (std::nothrow) _VisualElementImplicitAnimationEventListener();
4313                 if (pListener)
4314                 {
4315                         pAnimation->SetVisualElementAnimationStatusEventListener(pListener);
4316
4317                         r = pRoot->AddAnimation(*pVePropActionDetach, *pAnimation);
4318                         if (r == E_SUCCESS)
4319                         {
4320                                 if (!GetPublic())
4321                                 {
4322                                         return E_SYSTEM;
4323                                 }
4324
4325                                 r = GetPublic()->AttachChild(*pRoot);
4326                                 if (r == E_SUCCESS)
4327                                 {
4328                                         delete pAnimation;
4329
4330                                         return r;
4331                                 }
4332                         }
4333
4334                         delete pListener;
4335                 }
4336
4337                 delete pAnimation;
4338         }
4339
4340         return r;
4341 }
4342
4343 VisualElement*
4344 _VisualElementImpl::CreateElementForImplicitAnimationN(void) const
4345 {
4346         VisualElement* pElement = new (std::nothrow) VisualElement(*GetPublic());
4347         if (pElement == null)
4348         {
4349                 return null;
4350         }
4351
4352         result r = pElement->Construct();
4353         if (r != E_SUCCESS)
4354         {
4355                 pElement->Destroy();
4356                 return null;
4357         }
4358
4359         pElement->SetImplicitAnimationEnabled(false);
4360
4361         if (HAVE_SURFACE(this))
4362         {
4363                 VisualElementSurface* pSurface = GetSurfaceN();
4364                 if (pSurface)
4365                 {
4366                         pElement->SetSurface(pSurface);
4367                         delete pSurface;
4368                 }
4369         }
4370
4371         int count = __children.GetCount();
4372         for (int i = 0; i < count; i++)
4373         {
4374                 _VisualElementImpl* pVisualElementImpl = __children.GetChildAt(i);
4375                 if (likely(pVisualElementImpl))
4376                 {
4377                         r = pElement->AttachChild(*pVisualElementImpl->CreateElementForImplicitAnimationN());
4378                         SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4379                 }
4380         }
4381
4382         return pElement;
4383
4384 CATCH:
4385         delete pElement;
4386         return null;
4387 }
4388
4389
4390 result
4391 _VisualElementImpl::RemoveChild(_VisualElementImpl& child, bool deallocate)
4392 {
4393         //SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
4394         SysTryReturnResult(NID_UI_ANIM, child.__isAllowedTreeModification == true, E_INVALID_OPERATION, "Z-order cannot be modified inside the OnAttached() or OnDetached() method of VisualElementEventListener.");
4395
4396         int indexChild = GetChildIndex(child);
4397         SysTryReturnResult(NID_UI_ANIM, indexChild >= 0, E_OBJ_NOT_FOUND, "child is not a child of this instance.");
4398         if (unlikely(indexChild < 0))
4399                 return E_OBJ_NOT_FOUND;
4400
4401
4402         result r = RemoveChildWithoutReconfiguring(indexChild, true);
4403         if (unlikely(r != E_SUCCESS))
4404         {
4405                 return E_OBJ_NOT_FOUND;
4406         }
4407
4408         if (!IS_PRESENTATION(this) && (_AnimationManager::GetInstance()->IsImplicitAnimationEnabled()
4409                 && child.__isImplicitAnimationEnabled) && child.IsAncestorDestroying() == false)
4410         {
4411                 r = CreateElementTreeForDetachImplicitAnimation(child);
4412                 if (unlikely(r != E_SUCCESS))
4413                 {
4414                         SysLogException(NID_UI_ANIM, E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Dummy VisualElement cannot be attached.");
4415                 }
4416         }
4417
4418         //
4419         // Because tree hierarchy is not a property, VE hierarchy tree changes are not
4420         // notified by property observer. So, we invoke method in presentation VE directly.
4421         //
4422         if (!IS_PRESENTATION(this))
4423         {
4424                 UpdatePresentationWhenChildRemoved(child,deallocate);
4425         }
4426
4427         // TODO:
4428         //      DEALLOCATE !!!
4429         //
4430
4431         return E_SUCCESS;
4432 }
4433
4434 result
4435 _VisualElementImpl::RemoveAllChild(void)
4436 {
4437         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
4438         return E_SUCCESS;
4439 }
4440
4441
4442 void
4443 _VisualElementImpl::RebuildNativeNodeTree(_VisualElementImpl& parent)
4444 {
4445         if (!IS_PRESENTATION(this))
4446         {
4447                 return;
4448         }
4449
4450         _INativeNode* pNode = GetNativeNode();
4451         _INativeNode* pParentNode = parent.GetNativeNode();
4452
4453         if (!pNode || !pParentNode)
4454         {
4455                 return;
4456         }
4457
4458         pNode->RebuildIfNeeded(*pParentNode);
4459
4460 //TODO : must check ,don't you need to rebuild???
4461 //      RebuildCoordinates();
4462
4463         const int nativeProps = _VisualElementImpl::HIERARCHY_PROPERTY_COORDINATES
4464                                                         | _VisualElementImpl::HIERARCHY_PROPERTY_OPACITY
4465                                                         | _VisualElementImpl::HIERARCHY_PROPERTY_CONTENTOPACITY
4466                                                         | _VisualElementImpl::HIERARCHY_PROPERTY_CONTENTBOUNDS;
4467
4468
4469         InvalidateHierarchyProps(nativeProps, false, false);
4470
4471         int count = __children.GetCount();
4472         for ( int i = 0 ; i < count ; i++ )
4473         {
4474                 _VisualElementImpl* pVe = __children.GetChildAt(i);
4475                 if (pVe)
4476                 {
4477                         pVe->RebuildNativeNodeTree(*this);
4478                         _INativeNode* pChildNode = pVe->GetNativeNode();
4479                         pNode->InsertChild(*pChildNode,null, true);
4480                 }
4481         }
4482
4483 }
4484
4485
4486 Tizen::Base::String
4487 _VisualElementImpl::GetName(void) const
4488 {
4489         ClearLastResult();
4490
4491 #if 0
4492         return InvokeOnGetPropertyRequested(*pVePropName).ToString();
4493 #else
4494         return GetSharedData().name;
4495 #endif
4496 }
4497
4498 result
4499 _VisualElementImpl::SetName(const Tizen::Base::String& name)
4500 {
4501         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
4502         result r = InvokeOnSetPropertyRequested(*pVePropName, Variant(name));
4503         SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
4504
4505         return r;
4506 }
4507
4508
4509 Variant
4510 _VisualElementImpl::GetNameProperty(void) const
4511 {
4512         ClearLastResult();
4513
4514         return Variant(GetSharedData().name);
4515 }
4516
4517 result
4518 _VisualElementImpl::SetNameProperty(const Variant& v)
4519 {
4520         SysTryReturn(NID_UI_ANIM, v.GetType() == VARIANT_TYPE_STRING, E_INVALID_ARG, E_INVALID_ARG, STR_ERROR_INVALID_VARIANT_ARG_TYPE);
4521
4522         const Tizen::Base::String& name = v.ToString();
4523         if (name == GetSharedData().name)
4524         {
4525                 return E_SUCCESS;
4526         }
4527
4528         GetSharedData().name = name;
4529
4530         return E_SUCCESS;
4531 }
4532
4533 result
4534 _VisualElementImpl::SetUserData(void* pUserData)
4535 {
4536         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
4537
4538         GetSharedData().pUserData = pUserData;
4539
4540         return E_SUCCESS;
4541 }
4542
4543 void*
4544 _VisualElementImpl::GetUserData(void) const
4545 {
4546         ClearLastResult();
4547
4548         return GetSharedData().pUserData;
4549 }
4550
4551 _VisualElementImpl*
4552 _VisualElementImpl::GetChild(const Tizen::Base::String& name, bool searchAllDescendants) const
4553 {
4554         ClearLastResult();
4555
4556         int count = __children.GetCount();
4557
4558         // for performance, look children directly
4559         for (int i = 0; i < count; i++)
4560         {
4561                 const _VisualElementImpl* pChild = __children.GetChildAt(i);
4562                 if (unlikely(pChild->GetSharedData().name == name))
4563                 {
4564                         return const_cast< _VisualElementImpl* >(pChild);
4565                 }
4566         }
4567
4568         if (searchAllDescendants)
4569         {
4570                 for (int i = 0; i < count; i++)
4571                 {
4572                         const _VisualElementImpl* pChild = __children.GetChildAt(i)->GetChild(name, true);
4573                         if (likely(pChild))
4574                         {
4575                                 return const_cast< _VisualElementImpl* >(pChild);
4576                         }
4577                 }
4578         }
4579
4580         SetLastResult(E_OBJ_NOT_FOUND);
4581
4582         return null;
4583 }
4584
4585 FloatRectangle
4586 _VisualElementImpl::GetVisibleRect(void) const
4587 {
4588         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4589
4590         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4591                 pThis->RebuildCoordinates();
4592
4593         if (!IsVisibleI())
4594                 return FloatRectangle();
4595
4596         if (likely(__visibleRectValid))
4597                 return __visibleRect;
4598
4599         if (__pClipSource)
4600         {
4601                 FloatRectangle parentVisibleRect(__pClipSource->GetVisibleRect());
4602                 ConvertCoordinates(parentVisibleRect, __pClipSource);
4603                 pThis->__visibleRect = parentVisibleRect.GetIntersection(__visibleRect);
4604         }
4605
4606         pThis->__visibleRectValid = true;
4607
4608         return __visibleRect;
4609 }
4610
4611 FloatRectangle
4612 _VisualElementImpl::GetDrawableRect(void) const
4613 {
4614         // If VE has backing-buffer, visible status is not important for drawing...
4615         bool needSurface = NEED_SURFACE(this);
4616
4617         if (unlikely(!needSurface))
4618         {
4619                 return FloatRectangle();
4620         }
4621
4622         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4623         {
4624                 _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4625                 pThis->RebuildCoordinates();
4626         }
4627
4628         // WARNING:
4629         //      Even when surface exists, the size might be invalidated by changing bounds.
4630         //
4631 #if 0
4632         RebuildHierarchyProps(HIERARCHY_PROPERTY_MASK & (~HIERARCHY_PROPERTY_CONTENT), true);
4633         if (!HAVE_SURFACE(this))
4634         {
4635                 return __visibleRect;
4636         }
4637 #endif
4638         if (HAVE_SURFACE(this) && GetSharedData().fixedSurfaceSize)
4639         {
4640                 return FloatRectangle(0.0f, 0.0f, static_cast< float >(GetSharedData().pSurface->GetSize().width), static_cast< float >(GetSharedData().pSurface->GetSize().height));
4641         }
4642
4643         return FloatRectangle(0.0f, 0.0f, __bounds.width, __bounds.height);
4644 }
4645
4646 float
4647 _VisualElementImpl::GetOpacityFromRoot(void) const
4648 {
4649         float opacity = __contentOpacity * __opacity * __showOpacity;
4650         const _VisualElementImpl* pElement = __pParent;
4651         while (pElement)
4652         {
4653                 if (!VE_VISIBLE(pElement))
4654                 {
4655                         return 0.0f;
4656                 }
4657
4658                 opacity *= pElement->__opacity * pElement->__showOpacity;
4659                 pElement = pElement->__pParent;
4660         }
4661
4662         return opacity;
4663 }
4664
4665 const FloatRectangle&
4666 _VisualElementImpl::GetBoundingBoxI(void) const
4667 {
4668         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4669
4670         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4671         {
4672                 pThis->RebuildCoordinates();
4673         }
4674
4675         if (unlikely(!__boundingBoxValid))
4676         {
4677 #if 0
4678                 float x[4] = { 0.0f, __bounds.width, 0.0f, __bounds.width };
4679                 float y[4] = { 0.0f, 0.0f, __bounds.height, __bounds.height };
4680                 float z[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
4681
4682                 for (int i = 0; i < 4; i++)
4683                 {
4684                         _MatrixUtilTransform(GetMatrixToTop(), &x[i], &y[i], &z[i]);
4685                 }
4686
4687                 pThis->__boundingBox.SetBounds(x[0], y[0], x[0], y[0]);
4688
4689                 float l = x[0];
4690                 float r = x[0];
4691                 float t = y[0];
4692                 float b = y[0];
4693                 for (int i = 1; i < 4; i++)
4694                 {
4695                         if (x[i] < l)
4696                         {
4697                                 l = x[i];
4698                         }
4699
4700                         if (y[i] < t)
4701                         {
4702                                 t = y[i];
4703                         }
4704
4705                         if (x[i] > r)
4706                         {
4707                                 r = x[i];
4708                         }
4709
4710                         if (y[i] > b)
4711                         {
4712                                 b = y[i];
4713                         }
4714                 }
4715
4716                 pThis->__boundingBox.SetBounds(l, t, r - l, b - t);
4717 #else
4718                 float x[4] = { 0.0f, __bounds.width, 0.0f, __bounds.width };
4719                 float y[4] = { 0.0f, 0.0f, __bounds.height, __bounds.height };
4720                 CalculateBoundingBox(x, y, pThis->__boundingBox);
4721 #endif
4722
4723                 pThis->__boundingBoxValid = true;
4724         }
4725
4726         return __boundingBox;
4727 }
4728
4729 const FloatMatrix4&
4730 _VisualElementImpl::GetMatrixToSuper(void) const
4731 {
4732         if (unlikely(__matrixToSuperValid))
4733                 return __matrixToSuper;
4734
4735
4736         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4737
4738         pThis->__matrixToSuperValid = true;
4739
4740         if (unlikely(__pParent == null))
4741         {
4742                 _MatrixUtilSetIdentity(pThis->__matrixToSuper);
4743                 return __matrixToSuper;
4744         }
4745
4746         const bool needSurface = NEED_SURFACE(this);
4747
4748         // apply subprojection && translation
4749         if (likely(needSurface))
4750         {
4751                 MatrixUtilCopy(pThis->__matrixToSuper, __pParent->__childrenTransform);
4752                 _MatrixUtilTranslate(pThis->__matrixToSuper, __bounds.x, __bounds.y, __zPosition);
4753         }
4754         else
4755         {
4756                 _MatrixUtilSetTranslation(pThis->__matrixToSuper, __bounds.x, __bounds.y, __zPosition);
4757         }
4758
4759
4760         // apply transform
4761         if (likely(needSurface))
4762         {
4763                 if (likely(__decomposedTransform.GetMatrixType() != MATRIX4_Identity))
4764                 {
4765                         bool needAnchor = (unlikely(__anchorZ != 0.0f) || unlikely(__anchor.x != 0.0f) || unlikely(__anchor.y != 0.0f));
4766                         if (unlikely(needAnchor))
4767                                 _MatrixUtilTranslate(pThis->__matrixToSuper, __anchor.x * __bounds.width, __anchor.y * __bounds.height, __anchorZ);
4768
4769                         _MatrixUtilMultiply(pThis->__matrixToSuper, __matrixToSuper, __transform);
4770
4771                         if (unlikely(needAnchor))
4772                                 _MatrixUtilTranslate(pThis->__matrixToSuper, -__anchor.x * __bounds.width, -__anchor.y * __bounds.height, -__anchorZ);
4773                 }
4774         }
4775
4776         return __matrixToSuper;
4777 }
4778
4779 const FloatMatrix4&
4780 _VisualElementImpl::GetMatrixToTop(void) const
4781 {
4782         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4783
4784         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4785         {
4786                 pThis->RebuildCoordinates();
4787         }
4788
4789
4790         if (unlikely(!__matrixToTopValid))
4791         {
4792                 _MatrixUtilMultiply(pThis->__matrixToTop, __pParent->GetMatrixToTop(), GetMatrixToSuper());
4793                 pThis->__matrixToTopValid = true;
4794         }
4795
4796         return __matrixToTop;
4797 }
4798
4799 const FloatMatrix4&
4800 _VisualElementImpl::GetMatrixFromTop(void) const
4801 {
4802         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4803
4804         if (IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES))
4805         {
4806                 pThis->RebuildCoordinates();
4807         }
4808
4809         if (!__matrixFromTopValid)
4810         {
4811                 MatrixUtilCopy(pThis->__matrixFromTop, GetMatrixToTop());
4812                 pThis->__matrixFromTopInvertible = _MatrixUtilInvert(pThis->__matrixFromTop);
4813                 pThis->__matrixFromTopValid = true;
4814         }
4815
4816         return __matrixFromTop;
4817 }
4818
4819 FloatMatrix4
4820 _VisualElementImpl::CalcMatrixToBase(const _VisualElementImpl& base) const
4821 {
4822         if (this == &base)
4823                 return FloatMatrix4();
4824
4825         FloatMatrix4 matrixToBase(GetMatrixToSuper());
4826
4827         const _VisualElementImpl* pParent = GetParent();
4828         if (pParent)
4829         {
4830                 pParent = pParent->GetParent();
4831                 while (pParent)
4832                 {
4833                         _MatrixUtilMultiply(matrixToBase, pParent->GetMatrixToSuper(), matrixToBase);
4834                         pParent = pParent->GetParent();
4835                 }
4836         }
4837
4838         return matrixToBase;
4839 }
4840
4841 const FloatMatrix4&
4842 _VisualElementImpl::GetMatrixToClipSource(void) const
4843 {
4844         _VisualElementImpl* pThis = const_cast< _VisualElementImpl* >(this);
4845
4846         if (IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES))
4847         {
4848                 pThis->RebuildCoordinates();
4849         }
4850
4851
4852         if (unlikely(!__matrixToClipSourceValid))
4853         {
4854                 if (likely(__pParent))
4855                 {
4856                         if (__pParent->__isClipChildren)
4857                         {
4858                                 MatrixUtilCopy(pThis->__matrixToClipSource, GetMatrixToSuper());
4859                         }
4860                         else
4861                         {
4862                                 _MatrixUtilMultiply(pThis->__matrixToClipSource, __pParent->GetMatrixToClipSource(), GetMatrixToSuper());
4863                         }
4864                 }
4865                 else
4866                 {
4867                         _MatrixUtilSetIdentity(pThis->__matrixToClipSource);
4868                 }
4869
4870                 pThis->__matrixToClipSourceValid = true;
4871         }
4872
4873         return __matrixToClipSource;
4874 }
4875
4876 void
4877 _VisualElementImpl::InvalidateVisibleRectToRenderTarget(const FloatRectangle* pDirtyRectangle)
4878 {
4879         if (unlikely(GetSharedData().invalidationLockCount > 0))
4880                 return;
4881
4882         if (!IsDrawingObject())
4883                 return;
4884
4885         FloatRectangle bounds;
4886
4887         bounds = __pPresentation->GetVisibleRect();
4888         if (pDirtyRectangle)
4889         {
4890                 bounds = bounds.GetIntersection(*pDirtyRectangle);
4891         }
4892
4893         if (!bounds.IsEmpty())
4894         {
4895                 _VisualElementImpl* pRenderTarget = __pPresentation->GetRenderTarget();
4896                 if (pRenderTarget)
4897                 {
4898                         pRenderTarget->ConvertCoordinates(bounds, this);
4899                         pRenderTarget->InvalidateRectangleI(&bounds);
4900                 }
4901         }
4902 }
4903
4904 void
4905 _VisualElementImpl::RebuildCoordinates(void)
4906 {
4907         if (unlikely(!IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4908         {
4909                 return;
4910         }
4911
4912         SetPropsValidaty(HIERARCHY_PROPERTY_COORDINATES, 0);
4913
4914         __visibleRect.x = 0.0f;
4915         __visibleRect.y = 0.0f;
4916         __visibleRect.width = __bounds.width;
4917         __visibleRect.height = __bounds.height;
4918
4919
4920         if (unlikely(!__pParent))
4921         {
4922                 // FIXME:
4923                 //      Need to allowing transform to root element !
4924
4925                 _MatrixUtilSetIdentity(__matrixToTop);
4926                 _MatrixUtilSetIdentity(__matrixFromTop);
4927                 _MatrixUtilSetIdentity(__matrixToClipSource);
4928                 __pClipSource = null;
4929
4930                 GetMatrixToSuper();
4931
4932                 RectUtilCopy(__boundingBox, __bounds);
4933                 RectUtilCopy(__boundingBoxToClipSource, __bounds);
4934
4935                 _RootVisualElement* pRoot = dynamic_cast< _RootVisualElement* >(__pPublicInstance);
4936
4937                 if (likely(pRoot))
4938                 {
4939                         __pRoot = pRoot->_pVisualElementImpl;
4940                 }
4941                 else
4942                 {
4943                         __pRoot = null;
4944                 }
4945
4946                 __needTransform = false;
4947                 __needClipForUntransformed = false;
4948
4949
4950                 __matrixFromTopValid = true;
4951                 __matrixToTopValid = true;
4952                 __matrixToClipSourceValid = true;
4953                 __matrixToSuperValid = true;
4954
4955                 __boundingBoxValid = true;
4956                 __visibleRectValid = true;
4957         }
4958         else
4959         {
4960                 if (unlikely(__pParent->IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
4961                 {
4962                         __pParent->RebuildCoordinates();
4963                 }
4964
4965                 __pRoot = __pParent->__pRoot;
4966
4967                 Matrix4Type transformType = __decomposedTransform.GetMatrixType();
4968                 const Matrix4Type parentChildrenTransformType = __pParent->__decomposedChildrenTransform.GetMatrixType();
4969
4970                 if (parentChildrenTransformType > MATRIX4_Translation)
4971                         transformType = MATRIX4_Generic;
4972
4973
4974                 if (unlikely(__pParent->__isClipChildren))
4975                 {
4976                         __pClipSource = __pParent;
4977
4978                         __needTransform = (transformType > MATRIX4_Translation);
4979                         if (likely(!__needTransform))
4980                         {
4981                                 __boundingBoxToClipSource.x = __bounds.x + __transform.matrix[3][0];
4982                                 __boundingBoxToClipSource.y = __bounds.y + __transform.matrix[3][1];
4983                                 __boundingBoxToClipSource.width = __bounds.width;
4984                                 __boundingBoxToClipSource.height = __bounds.height;
4985                         }
4986                 }
4987                 else
4988                 {
4989                         __pClipSource = __pParent->__pClipSource;
4990
4991                         if (unlikely(transformType > MATRIX4_Translation))
4992                                 __needTransform = true;
4993                         else
4994                                 __needTransform = __pParent->__needTransform;
4995
4996                         if (likely(!__needTransform))
4997                         {
4998                                 __boundingBoxToClipSource.x = __pParent->__boundingBoxToClipSource.x + __bounds.x + __transform.matrix[3][0];
4999                                 __boundingBoxToClipSource.y = __pParent->__boundingBoxToClipSource.y + __bounds.y + __transform.matrix[3][1];
5000                                 __boundingBoxToClipSource.width = __bounds.width;
5001                                 __boundingBoxToClipSource.height = __bounds.height;
5002 #if 0
5003                                 if (unlikely(parentChildrenTransformType == MATRIX4_Translation))
5004                                 {
5005                                         __boundingBoxToClipSource.x += __pParent->__childrenTransform.matrix[3][0];
5006                                         __boundingBoxToClipSource.y += __pParent->__childrenTransform.matrix[3][1];
5007                                 }
5008 #endif
5009                         }
5010                 }
5011
5012                 if (likely(!__needTransform))
5013                 {
5014                         if (unlikely(parentChildrenTransformType == MATRIX4_Translation))
5015                         {
5016                                 __boundingBoxToClipSource.x += __pParent->__childrenTransform.matrix[3][0];
5017                                 __boundingBoxToClipSource.y += __pParent->__childrenTransform.matrix[3][1];
5018                         }
5019                 }
5020
5021                 __needClipForUntransformed = __pParent->__needClipForUntransformed;
5022                 if (likely(!__needClipForUntransformed) && likely(__pClipSource))
5023                 {
5024                         if (likely(__boundingBoxToClipSource.x >= 0.0f) &&
5025                                 likely(__boundingBoxToClipSource.y >= 0.0f) &&
5026                                 likely(__boundingBoxToClipSource.x + __boundingBoxToClipSource.width <= __pClipSource->__bounds.width) &&
5027                                 likely(__boundingBoxToClipSource.y + __boundingBoxToClipSource.height <= __pClipSource->__bounds.height))
5028                                 __needClipForUntransformed = false;
5029                         else
5030                                 __needClipForUntransformed = true;
5031                 }
5032                 else
5033                 {
5034                         __needClipForUntransformed = true;
5035                 }
5036
5037
5038                 __matrixFromTopValid = false;
5039                 __matrixToTopValid = false;
5040                 __matrixToClipSourceValid = false;
5041                 __matrixToSuperValid = false;
5042
5043                 __boundingBoxValid = false;
5044                 __visibleRectValid = false;
5045         }
5046 }
5047
5048 void
5049 _VisualElementImpl::RebuildVisibility(void)
5050 {
5051         const int mask = HIERARCHY_PROPERTY_COORDINATES | HIERARCHY_PROPERTY_SHOWSTATE | HIERARCHY_PROPERTY_OPACITY | HIERARCHY_PROPERTY_CONTENTOPACITY;
5052
5053         if (unlikely(!IsPropsInvalidated(mask)))
5054         {
5055                 return;
5056         }
5057
5058         if (unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
5059         {
5060                 RebuildCoordinates();
5061         }
5062
5063
5064         SetPropsValidaty(mask, 0);
5065
5066         if (unlikely(!__pParent))
5067         {
5068                 // FIXME:
5069                 //      Need to allowing transform to root element !
5070
5071                 if(!__isRoot)
5072                         __isVisible = false;
5073                 else
5074                         __isVisible = VE_VISIBLE(this);
5075         }
5076         else
5077         {
5078                 if (unlikely(__pParent->IsPropsInvalidated(mask)))
5079                 {
5080                         __pParent->RebuildVisibility();
5081                 }
5082
5083                 if (likely(__pParent->__isVisible))
5084                         __isVisible = VE_VISIBLE(this);
5085                 else
5086                         __isVisible = false;
5087         }
5088 }
5089
5090 void
5091 _VisualElementImpl::LockInvalidate(bool lock)
5092 {
5093         GetSharedData().LockInvalidate(lock);
5094 }
5095
5096 void
5097 _VisualElementImpl::InvalidateHierarchyPropsDownward(int invalidProps, bool broadcastToChildren, bool propagateToParentsOnly)
5098 {
5099         invalidProps &= HIERARCHY_PROPERTY_MASK;
5100
5101         __childrenNeedsUpdateProps |= invalidProps;
5102
5103         if (likely(!propagateToParentsOnly))
5104         {
5105                 SetPropsValidaty(0, invalidProps);
5106
5107                 if (likely(invalidProps & HIERARCHY_PROPERTY_COORDINATES))
5108                 {
5109                         __matrixFromTopValid = false;
5110                         __matrixToSuperValid = false;
5111                         __boundingBoxValid = false;
5112                 }
5113         }
5114
5115         if (unlikely(!broadcastToChildren))
5116         {
5117                 return;
5118         }
5119
5120         int count = __children.GetCount();
5121         for (int i = 0; i < count; i++)
5122         {
5123                 __children.GetChildAt(i)->InvalidateHierarchyPropsDownward(invalidProps, broadcastToChildren, propagateToParentsOnly);
5124         }
5125
5126         // may need update some attribute variables for other hierarchy properties
5127 }
5128
5129 void
5130 _VisualElementImpl::InvalidateHierarchyProps(int invalidProps, bool broadcastToChildren, bool propagateToParentsOnly)
5131 {
5132         invalidProps &= HIERARCHY_PROPERTY_MASK;
5133
5134 //      // For model tree, it is not needed to invalidate children-opacity and show-state
5135 //      if (!IS_PRESENTATION(this))
5136 //      {
5137 //              invalidProps &= ~(HIERARCHY_PROPERTY_OPACITY | HIERARCHY_PROPERTY_SHOWSTATE);
5138 //      }
5139
5140         if (unlikely(!invalidProps))
5141         {
5142                 return;
5143         }
5144
5145         InvalidateHierarchyPropsDownward(invalidProps, broadcastToChildren, propagateToParentsOnly);
5146
5147         _VisualElementImpl* pElement = __pParent;       // WARNING: 'this' is updated in '__InvalidateHierarchyPropsDownward'
5148         while (pElement)
5149         {
5150                 pElement->__childrenNeedsUpdateProps |= invalidProps;
5151                 pElement = pElement->__pParent;
5152         }
5153 }
5154
5155 // HIERARCHY_PROPERTY_CONTENT is not handled here, but in drawing logic
5156 void
5157 _VisualElementImpl::RebuildHierarchyProps(int props, bool checkSurface, bool reconfSurfaceOnly)
5158 {
5159         if (likely(__pParent) && (unlikely(__pParent->IsPropsInvalidated(props)) || unlikely(__pParent->GetSharedData().NeedNativeReconfigure())))
5160         {
5161                 // WARNING:
5162                 //      'checkSurface' for parent will make surface !
5163                 __pParent->RebuildHierarchyProps(props, false, false);
5164         }
5165
5166
5167         // TBD: Recreating surface may have to be done in presentation layer (thread!)
5168         if (unlikely(checkSurface))
5169         {
5170                 if (likely(IsDrawingObject()))
5171                 {
5172                         ResetSurfaceIfNeeded(); // may invalidate GetSharedData().surfaceChanged
5173                 }
5174         }
5175
5176         const bool needApplyNatives = GetSharedData().NeedNativeReconfigure();
5177
5178         props &= HIERARCHY_PROPERTY_MASK;
5179         if (unlikely(!IsPropsInvalidated(props)) && likely(!checkSurface) && unlikely(needApplyNatives == 0))
5180         {
5181                 return;
5182         }
5183
5184         if (unlikely(props & HIERARCHY_PROPERTY_SURFACE) && unlikely(IsPropsInvalidated(HIERARCHY_PROPERTY_SURFACE)))
5185         {
5186                 SetPropsValidaty(HIERARCHY_PROPERTY_SURFACE, 0);
5187         }
5188
5189         if (likely(props & HIERARCHY_PROPERTY_CONTENTBOUNDS) && likely(IsPropsInvalidated(HIERARCHY_PROPERTY_CONTENTBOUNDS)))
5190         {
5191                 SetPropsValidaty(HIERARCHY_PROPERTY_CONTENTBOUNDS, 0);
5192         }
5193
5194         if (likely(props & HIERARCHY_PROPERTY_COORDINATES) && likely(IsPropsInvalidated(HIERARCHY_PROPERTY_COORDINATES)))
5195         {
5196                 RebuildCoordinates();
5197                 //__SetPropsValidaty(HIERARCHY_PROPERTY_COORDINATES, 0); --> need not. __RebuildCoordinates will validate.
5198         }
5199
5200         // WARNING:
5201         //      'Visibility' should be checked after validating tree-hierarchy information.
5202         //      (For example, attaching/detaching may affect visibility.)
5203         const int mask = HIERARCHY_PROPERTY_OPACITY | HIERARCHY_PROPERTY_SHOWSTATE | HIERARCHY_PROPERTY_CONTENTOPACITY;
5204         if (unlikely((props & mask) != 0) && unlikely(IsPropsInvalidated(props & mask)))
5205         {
5206                 RebuildVisibility();
5207         }
5208
5209         if (likely(__pPresentation) && likely(needApplyNatives))
5210         {
5211                 if (unlikely(!IS_PRESENTATION(this)))
5212                 {
5213                         // WARNING:
5214                         //      In model, native nodes are updated only when the surface was changed.
5215                         //if (unlikely(GetSharedData().surfaceChanged))
5216                         {
5217                                 __pPresentation->FlushNativeChanges();
5218                         }
5219                 }
5220                 else
5221                 {
5222                         GetSharedData().NodeReconfigure(*__pPresentation, false);
5223                 }
5224         }
5225 }
5226
5227 void
5228 _VisualElementImpl::FlushNativeChanges(void)
5229 {
5230         if (unlikely(!IS_PRESENTATION(this)))
5231                 return;
5232
5233         if (likely(__pPresentation))
5234                 GetSharedData().NodeReconfigure(*__pPresentation, false);
5235 }
5236
5237 void
5238 _VisualElementImpl::UpdateHierarchyProps(void)
5239 {
5240         // WARNING:
5241         //      HIERARCHY_PROPERTY_CONTENT is not handled here, but in drawing logic.
5242         const int mask = HIERARCHY_PROPERTY_MASK & (~HIERARCHY_PROPERTY_CONTENT);
5243
5244         if (unlikely((__childrenNeedsUpdateProps & mask) == 0))
5245                 return;
5246
5247         // Node will be reconfigured later(before OnDraw, or DrawRectangle, ...)
5248         if (likely(IsPropsInvalidated(mask)) || likely(GetSharedData().NeedNativeReconfigure()))
5249                 RebuildHierarchyProps(mask, false, false);
5250
5251         // WARNING:
5252         //      __childrenNeedsUpdateProps should be cleared *ONLY AFTER* flushing native nodes !
5253         __childrenNeedsUpdateProps &= ~mask;
5254
5255         int count = __children.GetCount();
5256         for (int i = 0; i < count; i++)
5257         {
5258                 _VisualElementImpl* pChild = __children.GetChildAt(i);
5259                 if (likely((pChild->__childrenNeedsUpdateProps & mask) != 0))
5260                         pChild->UpdateHierarchyProps();
5261         }
5262 }
5263
5264 void
5265 _VisualElementImpl::ExposeRectangle(const FloatRectangle* pDirtyRectangle, bool invalidate)
5266 {
5267         if (unlikely(!IsDrawingObject()))
5268                 return;
5269
5270         if (unlikely(invalidate))
5271         {
5272                 InvalidateRectangleI(pDirtyRectangle);
5273         }
5274 #if 0   // exposing object without content changes is not needed for EFL
5275         else
5276         {
5277                 SetFlushNeeded();
5278         }
5279 #endif
5280 }
5281
5282 result
5283 _VisualElementImpl::SetFlushNeeded(void)
5284 {
5285         FloatRectangle rect;
5286
5287         if (!IS_PRESENTATION(this))
5288         {
5289                 return __pPresentation->SetFlushNeeded();
5290         }
5291
5292         rect = __bounds;
5293         rect.SetPosition(0.0f, 0.0f);
5294
5295         if (likely(HAVE_SURFACE(this)))
5296         {
5297                 GetSharedData().pNativeNode->SetFlushNeeded();
5298         }
5299         else
5300         {
5301                 _VisualElementImpl* pRenderTarget = GetRenderTarget();
5302
5303                 if (likely(pRenderTarget && pRenderTarget->GetSharedData().pNativeNode))
5304                 {
5305                         pRenderTarget->__pPresentation->ConvertCoordinates(rect, this->__pPresentation);
5306                         pRenderTarget->GetSharedData().pNativeNode->SetFlushNeeded();
5307                 }
5308         }
5309
5310         return E_SUCCESS;
5311 }
5312
5313 result
5314 _VisualElementImpl::Flush(void)
5315 {
5316         if (likely(GetSharedData().pNativeNode))
5317         {
5318                 GetSharedData().pNativeNode->Flush();
5319         }
5320
5321         return E_SUCCESS;
5322 }
5323
5324 result
5325 _VisualElementImpl::InvalidateRectangle(const FloatRectangle* pRectangle)
5326 {
5327 //!!! don't have to check attached state
5328 //      SysTryReturnResult(NID_UI_ANIM, IS_ATTACHED(this), E_INVALID_STATE, "Invalidating VisualElement should be attached to the root tree.");
5329
5330         return InvalidateRectangleI(pRectangle);
5331 }
5332
5333 result
5334 _VisualElementImpl::InvalidateRectangleI(const FloatRectangle* pRectangle)
5335 {
5336         SysTryReturnResult(NID_UI_ANIM, !GetSharedData().fixedSurfaceSize, E_INVALID_OPERATION, "VisualElement with User-Surface do not allow invalidating and redrawing.");
5337         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "Invalidating VisualElement should be performed on a model layer.");
5338
5339         if (unlikely(GetSharedData().invalidationLockCount > 0))
5340         {
5341                 return E_SUCCESS;
5342         }
5343
5344
5345         FloatRectangle invRect;
5346
5347         if (unlikely(pRectangle))
5348         {
5349                 if (unlikely(pRectangle->IsEmpty()))
5350                 {
5351                         return E_SUCCESS;
5352                 }
5353
5354                 invRect = *pRectangle;
5355         }
5356         else
5357         {
5358                 invRect = __bounds;
5359                 invRect.SetPosition(0.0f, 0.0f);
5360         }
5361
5362         if (unlikely(invRect.IsEmpty()))
5363         {
5364                 return E_SUCCESS;
5365         }
5366
5367
5368         // WARNING:
5369         //      'GetUnion' method will not behave as our intention.
5370         //      If the parameter or self is empty, the union of rectangle should ignore it !
5371         //invRect = GetSharedData().invalidatedRegion.GetUnion(invRect);
5372         RectUtilUnion(invRect, GetSharedData().invalidatedRegion);
5373
5374
5375         // TODO:
5376         //      If new requested invalidate region is already included currently,
5377         //      we can skip the following calculations (but invalidating flags are STILL needed !)
5378
5379         _VisualElementImpl* pRenderTarget = GetRenderTarget();
5380
5381         if (likely(pRenderTarget == this))
5382         {
5383                 // Make invalidated area a bit larger to be aligned on the render target
5384                 RectUtilMakeIntegral(invRect);
5385         }
5386
5387         GetSharedData().invalidatedRegion = invRect;
5388
5389         InvalidateHierarchyProps(HIERARCHY_PROPERTY_CONTENT, false, false);
5390         SetRootNeedsContentUpdate();
5391
5392         return E_SUCCESS;
5393 }
5394
5395 FloatRectangle
5396 _VisualElementImpl::GetInvalidatedRectangle(void) const
5397 {
5398         ClearLastResult();
5399
5400         if (IS_PRESENTATION(this))
5401         {
5402                 if (__pModel)
5403                 {
5404                         return __pModel->GetInvalidatedRectangle();
5405                 }
5406         }
5407
5408         return GetSharedData().invalidatedRegion;
5409 }
5410
5411 FloatRectangle
5412 _VisualElementImpl::GetUpdateRectangle(void) const
5413 {
5414         ClearLastResult();
5415
5416         return GetSharedData().updateRegion;
5417 }
5418
5419 bool
5420 _VisualElementImpl::IsOpaque(void) const
5421 {
5422         ClearLastResult();
5423
5424         if (HAVE_SURFACE(this))
5425         {
5426                 return IsSurfaceOpaque();
5427         }
5428
5429         return true;
5430 }
5431
5432 result
5433 _VisualElementImpl::Draw(void)
5434 {
5435         SysTryReturnResult(NID_UI_ANIM, IS_ATTACHED(this),  E_INVALID_STATE, "Drawing VisualElement should be attached to the root tree.");
5436         if (!IS_MODEL(this))
5437         {
5438                 //SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
5439         }
5440
5441         // WARNING:
5442         //      Not a good position to apply property changes into native(EFL) system.
5443         //      Because of no-compositor in VE, we cannot control each element's
5444         //      visibilities (show-state, bounds, opacity, etc.) !
5445         //      Is there any good idea ?
5446         //
5447 //      if (IS_PRESENTATION(this))
5448 //              __UpdateHierarchyProps();
5449
5450         if (unlikely((__childrenNeedsUpdateProps & HIERARCHY_PROPERTY_CONTENT) != 0))
5451         {
5452 //              if (unlikely(!IS_PRESENTATION(this)))
5453 //                      __UpdateHierarchyProps();
5454
5455
5456                 //
5457                 // Drawing must be done from first opaque.
5458                 // But, because we assume all VE's are transparent, all drawings are done from root !!!
5459
5460                 _VisualElementImpl* pRenderTarget = GetRenderTarget();
5461                 bool needFullScreenDraw = __isRoot;
5462
5463                 if (unlikely(!pRenderTarget))
5464                 {
5465                         // On no render target, flush invalidated area from root
5466                         pRenderTarget = GetRoot();
5467                         SysTryReturnResult(NID_UI_ANIM, pRenderTarget, E_SYSTEM, "A system error has been occurred. This VisualElement doesn't have rendering target.");
5468                         needFullScreenDraw = true;
5469                 }
5470
5471
5472                 // WARNING
5473                 //      To minimize drawing area(with clip), use '__DrawRectangleIfNeeded'
5474                 //      To reduce drawing calls such as 'OnDraw', use '__DrawRectangle' directly
5475                 //
5476                 int maxScreenSize = _Max(_VisualElementCoordinateSystem::logScreenWidth, _VisualElementCoordinateSystem::logScreenHeight);
5477                 pRenderTarget->DrawRectangleIfNeeded(
5478                         needFullScreenDraw ? FloatRectangle(0.0f, 0.0f, maxScreenSize, maxScreenSize) : GetDrawableRect()
5479                 );
5480         }
5481
5482         if (IS_PRESENTATION(this))
5483                 UpdateHierarchyProps();
5484
5485         return E_SUCCESS;
5486 }
5487
5488 void
5489 _VisualElementImpl::DrawRectangleIfNeeded(const FloatRectangle& drawRect)
5490 {
5491         if ((__childrenNeedsUpdateProps & HIERARCHY_PROPERTY_CONTENT) == 0 || unlikely(!IsVisibleI()))
5492         {
5493                 return;
5494         }
5495
5496         // WARNING:
5497         //      VE with surface redraws *ALL INVALIDATED* region !! --> TBD: make an option/flags for this???
5498         //
5499         FloatRectangle drawableRect;
5500
5501         if (NEED_SURFACE(this))
5502         {
5503                 // WARNING:
5504                 //      Redraw only if the request has some valid region to draw.
5505                 drawableRect = GetDrawableRect();
5506                 if (!drawRect.IsIntersected(drawableRect))
5507                         drawableRect.SetSize(0.0f, 0.0f);       // Make empty
5508         }
5509         else
5510         {
5511                 drawableRect = drawRect;
5512         }
5513
5514         DrawRectangle(drawableRect.GetIntersection(GetSharedData().invalidatedRegion));
5515
5516         //
5517         // needUpdate flag may be 'true' after drawring invalidated region.
5518         // This means that some children still need to be updated !
5519         //
5520         if (likely((__childrenNeedsUpdateProps & HIERARCHY_PROPERTY_CONTENT) == 0))
5521         {
5522                 return;
5523         }
5524
5525         //
5526         // Some children still need to update in case that invalidated rect of this
5527         // is smaller than 'drawRect' which can overlap the invalid rect of children
5528         //
5529
5530         //
5531         // Because user can do anything in drawing logic,
5532         // adding-reference may be safe.......
5533         //
5534         _VisualElementImpl* pChild = null;
5535         FloatRectangle updateRect, childBounds;
5536         bool childrenNeedUpdate = false;
5537         int count = __children.GetCount();
5538         for (int i = 0; i < count; i++)
5539         {
5540                 pChild = __children.GetChildAt(i);
5541                 if (!pChild)
5542                 {
5543                         continue;
5544                 }
5545
5546                 if ((pChild->__childrenNeedsUpdateProps & HIERARCHY_PROPERTY_CONTENT) == 0)
5547                 {
5548                         continue;
5549                 }
5550
5551
5552                 // WARNING:
5553                 //      Draw all children with surface.
5554                 //      Children with empty invalidated region will ignore re-drawing.
5555
5556                 updateRect = drawRect;
5557                 pChild->__pPresentation->ConvertCoordinates(updateRect, this->__pPresentation);
5558
5559                 if (likely(NEED_SURFACE(pChild)))
5560                 {
5561                         pChild->DrawRectangleIfNeeded(updateRect);
5562                 }
5563                 else
5564                 {
5565                         childBounds = pChild->__pPresentation->__bounds;
5566                         childBounds.SetPosition(0.0f, 0.0f);
5567                         updateRect = updateRect.GetIntersection(childBounds);
5568                         if (unlikely(!updateRect.IsEmpty()))
5569                                 pChild->DrawRectangleIfNeeded(updateRect);
5570                 }
5571
5572                 if ((pChild->__childrenNeedsUpdateProps & HIERARCHY_PROPERTY_CONTENT) != 0)
5573                 {
5574                         childrenNeedUpdate = true;
5575                 }
5576         }
5577
5578         // update 'needUpdate' flag regarding children only if no invalidated-region
5579         if (GetSharedData().invalidatedRegion.IsEmpty())
5580         {
5581                 SetPropsValidaty(HIERARCHY_PROPERTY_CONTENT, 0);
5582                 if (childrenNeedUpdate)
5583                 {
5584                         __childrenNeedsUpdateProps |= HIERARCHY_PROPERTY_CONTENT;
5585                 }
5586                 else
5587                 {
5588                         __childrenNeedsUpdateProps &= ~HIERARCHY_PROPERTY_CONTENT;
5589                 }
5590         }
5591 }
5592
5593 // TODO: change name(remove 'rectangle')
5594 void
5595 _VisualElementImpl::DrawRectangle(const FloatRectangle& drawRect)
5596 {
5597         if (unlikely(!GetRootPublic()) || unlikely(!IsVisibleI()) || unlikely(drawRect.IsEmpty()))
5598         {
5599                 return;
5600         }
5601
5602         //SysLog(NID_UI_ANIM, "DrawRectangle");
5603
5604         bool needDraw = false;
5605         bool fullValidated = false;
5606         FloatRectangle drawableRect(GetDrawableRect());
5607         FloatRectangle drawRectVisible(drawRect.GetIntersection(drawableRect));
5608         FloatRectangle invalidatedRectVisible(GetSharedData().invalidatedRegion.GetIntersection(drawableRect));
5609
5610         if (unlikely(!drawRectVisible.IsEmpty()))
5611         {
5612 #if 0
5613                 // Draw full-invalidated-content (not partial) if VE has surface.
5614                 if (likely(NEED_SURFACE(this)))
5615                         drawRectVisible = drawableRect;
5616 #endif
5617
5618                 needDraw = true;
5619         }
5620
5621         // WARNING:
5622         //      Make dirty/draw area a bit larger to be pixel-aligned and prevent drawing-artifacts caused by float-error.
5623         RectUtilMakeIntegral(drawRectVisible);
5624         RectUtilMakeIntegral(invalidatedRectVisible);
5625
5626         //      DO NOT USE drawRectVisible.Contains(invalidatedRectVisible))
5627         if (invalidatedRectVisible.IsEmpty() || (drawRectVisible.x <= invalidatedRectVisible.x &&
5628                                                                                         drawRectVisible.y <= invalidatedRectVisible.y &&
5629                                                                                         drawRectVisible.x + drawRectVisible.width >= invalidatedRectVisible.x + invalidatedRectVisible.width &&
5630                                                                                         drawRectVisible.y + drawRectVisible.height >= invalidatedRectVisible.y + invalidatedRectVisible.height))
5631         {
5632                 fullValidated = true;
5633         }
5634
5635
5636
5637         // WARNING:
5638         //      VisualElement with User-Set surface does not allow invalidating and redrawing.
5639         //      Because there should be no invalidated region in this case, checking User-Surface may redundant.
5640         //
5641         if (GetSharedData().fixedSurfaceSize)
5642         {
5643                 needDraw = false;
5644                 fullValidated = true;
5645                 drawRectVisible = GetSharedData().invalidatedRegion;
5646         }
5647
5648
5649         // WARNING:
5650         //      Set update region before 'CanDraw' and 'OnDraw' delegations to check real-update region
5651         //
5652         GetSharedData().updateRegion = drawRectVisible;
5653
5654         if (fullValidated)
5655         {
5656                 // WARNING:
5657                 //      Clear *BEFORE* drawing because 'OnDraw' may add invalidated regions...
5658                 //
5659                 GetSharedData().invalidatedRegion.SetBounds(0.0f, 0.0f, 0.0f, 0.0f); // SetEmpty()
5660
5661                 SetPropsValidaty(HIERARCHY_PROPERTY_CONTENT, 0);
5662                 __childrenNeedsUpdateProps &= ~HIERARCHY_PROPERTY_CONTENT;
5663         }
5664
5665
5666         if (needDraw)
5667         {
5668                 if (!VE_DELEGATE(this, InvokePrepareDraw))
5669                 {
5670                         needDraw = false;
5671                 }
5672         }
5673
5674         if (needDraw)
5675         {
5676                 Canvas* pCanvas = null;
5677                 pCanvas = GetCanvasN();
5678
5679                 if (pCanvas)
5680                 {
5681                         result r = pCanvas->SetClipBounds(Rectangle(drawRectVisible.x,
5682                                                                                                                 drawRectVisible.y,
5683                                                                                                                 drawRectVisible.width,
5684                                                                                                                 drawRectVisible.height));
5685                         if (IsFailed(r))
5686                         {
5687                                 SysLogException(NID_UI_ANIM, r, "[%s] Failed to set clip-bounds on canvas", GetErrorMessage(r));
5688                         }
5689
5690                         VE_DELEGATE(this, InvokeOnDraw, *pCanvas);
5691                         delete pCanvas;
5692                 }
5693
5694                 // WARNING:
5695                 //      Flushing canvas is done at GetCanvasN.
5696                 //
5697                 //SetFlushNeeded();
5698         }
5699
5700
5701         // Clear update region after drawing
5702         GetSharedData().updateRegion.SetBounds(0.0f, 0.0f, 0.0f, 0.0f);
5703
5704
5705         //
5706         // Because user can do anything in drawing logic,
5707         // adding-reference/copying-list may be safe.......
5708         //
5709         _VisualElementImpl* pChild = null;
5710         int count = __children.GetCount();
5711         bool childrenNeedUpdate = false;
5712         FloatRectangle childBounds;
5713         for (int i = 0; i < count; i++)
5714         {
5715                 pChild = __children.GetChildAt(i);
5716                 if (likely(!NEED_SURFACE(pChild)))
5717                 {
5718                         drawRectVisible = drawRect;
5719                         pChild->__pPresentation->ConvertCoordinates(drawRectVisible, this->__pPresentation);
5720                         childBounds = pChild->__pPresentation->__bounds;
5721
5722                         childBounds.SetPosition(0.0f, 0.0f);
5723
5724                         drawRectVisible = drawRectVisible.GetIntersection(childBounds);
5725                         if (likely(!drawRectVisible.IsEmpty()))
5726                                 pChild->DrawRectangle(drawRectVisible);
5727                 }
5728
5729                 if ((pChild->__childrenNeedsUpdateProps & HIERARCHY_PROPERTY_CONTENT) != 0)
5730                 {
5731                         childrenNeedUpdate = true;
5732                 }
5733         }
5734
5735         //
5736         // If not all children have been validated during update,
5737         // we should not clear update flag to flush them later.
5738         //
5739         if (childrenNeedUpdate)
5740         {
5741                 __childrenNeedsUpdateProps |= HIERARCHY_PROPERTY_CONTENT;
5742         }
5743 }
5744
5745 // for a cumstom property animation
5746 result
5747 _VisualElementImpl::SetPropertyI(const String& property, const Variant& value)
5748 {
5749         result r = E_SUCCESS;
5750
5751         if (likely(__pPublicInstance))
5752         {
5753                 r = __pPublicInstance->OnSetPropertyRequested(property, value);
5754                 SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
5755         }
5756
5757         return r;
5758 }
5759
5760 result
5761 _VisualElementImpl::InvokeOnSetPropertyRequested(const String& property, const Variant& value)
5762 {
5763         SysTryReturnResult(NID_UI_ANIM, IS_MODEL(this), E_INVALID_OPERATION, "VisualElement is not Model object.");
5764         result r = E_SUCCESS;
5765
5766         if (likely(__pPublicInstance))
5767         {
5768                 r = __pPublicInstance->OnSetPropertyRequested(property, value);
5769                 SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
5770         }
5771
5772         return r;
5773 }
5774
5775 int
5776 _VisualElementImpl::HitTestI(const FloatPoint& point)
5777 {
5778         if (!IsVisibleI())
5779         {
5780                 return HITTEST_NOWHERE;
5781         }
5782
5783         if (//NEED_SURFACE(&target) &&
5784                 !GetSharedData().isSurfaceOpaque &&
5785                 _FloatHardCompare(GetOpacityFromRoot(), 0.0f))
5786         {
5787                 return HITTEST_NOWHERE;
5788         }
5789
5790         if (!GetVisibleRect().Contains(point))
5791         {
5792                 return HITTEST_NOWHERE;
5793         }
5794
5795         _VisualElementImpl* pClipSource = GetClipSource();
5796         while (pClipSource)
5797         {
5798                 FloatPoint pt = point;
5799                 pClipSource->ConvertCoordinates(pt, this);
5800
5801                 if (!pClipSource->GetVisibleRect().Contains(pt))
5802                 {
5803                         return HITTEST_NOWHERE;
5804                 }
5805                 else
5806                 {
5807                         pClipSource = pClipSource->GetClipSource();
5808                 }
5809         }
5810
5811         return HITTEST_MATCH;
5812 }
5813
5814 _VisualElementImpl*
5815 _VisualElementImpl::GetChildAtPointI(const FloatPoint& point, int parentHitTest)
5816 {
5817         _VisualElementImpl* pHitTarget = null;
5818         FloatPoint hitPoint = point;
5819         int hitTest;
5820
5821         hitTest = VE_DELEGATE(this, InvokeHitTest, point);
5822         if ((hitTest & HITTEST_MATCH) != 0)
5823         {
5824                 // passed hittest
5825                 pHitTarget = this;
5826         }
5827
5828         if ((hitTest & HITTEST_NOMORECHILDREN) == 0)
5829         {
5830                 int count = __children.GetCount();
5831                 for (int i = count - 1; i >= 0; i--)    // from top to bottom
5832                 {
5833                         _VisualElementImpl* pChild = __children.GetChildAt(i);
5834                         if (!pChild)
5835                         {
5836                                 continue;
5837                         }
5838
5839                         FloatPoint childHitPoint = point;
5840                         pChild->ConvertCoordinates(childHitPoint, this);
5841
5842                         _VisualElementImpl* pChildHitTarget = pChild->GetChildAtPointI(childHitPoint, hitTest);
5843                         if (pChildHitTarget)
5844                         {
5845                                 pHitTarget = pChildHitTarget;
5846                                 hitPoint = childHitPoint;
5847                                 break;
5848                         }
5849                 }
5850         }
5851
5852
5853         if (pHitTarget)
5854         {
5855 //              point = hitPoint;
5856                 return pHitTarget;
5857         }
5858
5859         return null;
5860 }
5861
5862 // WARNING:
5863 //      Because Hit-Testing from self, clipping flags of self will be ignored.
5864 //
5865 _VisualElementImpl*
5866 _VisualElementImpl::GetChildAt(const FloatPoint& point)
5867 {
5868         _VisualElementImpl* pHitTarget = GetChildAtPointI(point, HITTEST_MATCH);
5869         if (unlikely(!pHitTarget))
5870         {
5871                 SetLastResult(E_OBJ_NOT_FOUND);
5872         }
5873         else
5874         {
5875                 ClearLastResult();
5876         }
5877
5878         return pHitTarget;
5879 }
5880
5881 result
5882 _VisualElementImpl::ScrollByPoint(const FloatPoint& pointOffset, bool scrollSelf)
5883 {
5884         if (_FloatCompare(pointOffset.x, 0.0f) && _FloatCompare(pointOffset.y, 0.0f))
5885         {
5886                 return E_SUCCESS;
5887         }
5888
5889         result r;
5890         FloatMatrix4 xform = __childrenTransform;
5891         FloatMatrix4 xformOrg = xform;
5892         FloatRectangle rectInvalidated;
5893
5894         _MatrixUtilTranslate(xform, pointOffset.x, pointOffset.y, 0.0f);
5895
5896         if (HAVE_SURFACE(this))
5897         {
5898                 int count = __children.GetCount();
5899
5900                 LockInvalidate(true);
5901                 for (int i = 0; i < count; i++)
5902                 {
5903                         __children.GetChildAt(i)->LockInvalidate(true);
5904                 }
5905
5906                 r = SetChildrenTransformMatrix(xform);
5907
5908                 LockInvalidate(false);
5909                 for (int i = 0; i < count; i++)
5910                 {
5911                         __children.GetChildAt(i)->LockInvalidate(false);
5912                 }
5913         }
5914         else
5915         {
5916                 r = SetChildrenTransformMatrix(xform);
5917         }
5918
5919         SysTryReturnResult(NID_UI_ANIM, r == E_SUCCESS, E_SYSTEM, "Failed to translate matrix for scrolling ");
5920
5921         if (!NEED_SURFACE(this))
5922         {
5923                 InvalidateVisibleRectToRenderTarget(null);
5924         }
5925         else if (scrollSelf)
5926         {
5927                 Canvas* pCanvas = null;
5928                 _CanvasImpl* pCanvasImpl = null;
5929
5930                 pCanvas = GetCanvasN(); // TODO: clip rect......
5931                 if (pCanvas)
5932                 {
5933                         pCanvasImpl = _CanvasImpl::GetInstance(*pCanvas);
5934                         if (pCanvasImpl)
5935                         {
5936                                 Point pointDest;
5937                                 Rectangle rectSource;
5938
5939                                 rectSource.SetBounds(0, 0, __bounds.width, __bounds.height);
5940
5941                                 rectInvalidated = __bounds;
5942                                 rectInvalidated.SetPosition(0.0f, 0.0f);
5943                                 if (pointOffset.x > 0)
5944                                 {
5945                                         rectSource.width -= pointOffset.x;
5946                                         pointDest.x = pointOffset.x;
5947                                         rectInvalidated.width = pointOffset.x;
5948                                 }
5949                                 else
5950                                 {
5951                                         rectSource.x += -pointOffset.x;
5952                                         rectSource.width -= -pointOffset.x;
5953                                         pointDest.x = 0;
5954                                         rectInvalidated.x = rectSource.width;
5955                                         rectInvalidated.width = -pointOffset.x;
5956                                 }
5957
5958                                 InvalidateVisibleRectToRenderTarget(&rectInvalidated);
5959
5960
5961                                 rectInvalidated = __bounds;
5962                                 rectInvalidated.SetPosition(0.0f, 0.0f);
5963                                 if (pointOffset.y > 0)
5964                                 {
5965                                         rectSource.height -= pointOffset.y;
5966                                         pointDest.y = pointOffset.y;
5967                                         rectInvalidated.height = pointOffset.y;
5968                                 }
5969                                 else
5970                                 {
5971                                         rectSource.y += -pointOffset.y;
5972                                         rectSource.height -= -pointOffset.y;
5973                                         pointDest.y = 0;
5974                                         rectInvalidated.y = rectSource.height;
5975                                         rectInvalidated.height = -pointOffset.y;
5976                                 }
5977
5978                                 InvalidateVisibleRectToRenderTarget(&rectInvalidated);
5979
5980
5981                                 r = pCanvasImpl->CopyEx(pointDest, *pCanvasImpl, rectSource);
5982                                 if (r != E_SUCCESS)
5983                                 {
5984                                         // revert...
5985                                         SysLogException(NID_UI_ANIM, r, "[%s] Can't copy area.", GetErrorMessage(r));
5986                                         SetChildrenTransformMatrix(xformOrg); // ???????????????????
5987                                 }
5988                                 else
5989                                 {
5990                                         SetFlushNeeded();
5991                                 }
5992                         }
5993
5994                         delete pCanvas;
5995                 }
5996         }
5997
5998         return r;
5999 }
6000
6001 result
6002 _VisualElementImpl::ConvertCoordinates(FloatPoint& point, const _VisualElementImpl* pFromElement) const
6003 {
6004         if (unlikely(this == pFromElement))
6005         {
6006                 return E_SUCCESS;
6007         }
6008
6009         _VisualElementImpl* pFromRoot = null;
6010         float x = point.x;
6011         float y = point.y;
6012         float z = 0.0f;
6013
6014         if (likely(pFromElement))
6015         {
6016                 pFromRoot = pFromElement->GetRoot();
6017                 SysTryReturnResult(NID_UI_ANIM, GetRoot() == pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement and pFromElement is not belong to the same tree.");
6018                 SysTryReturnResult(NID_UI_ANIM, pFromRoot || pFromElement->IsChildOf(*this) || IsChildOf(*pFromElement),
6019                                         E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement(%p) and pFromElement(%p) is not related.", this, pFromElement);
6020         }
6021         else
6022         {
6023                 pFromRoot = GetRoot();
6024                 SysTryReturnResult(NID_UI_ANIM, pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement is not attached to main tree.");
6025         }
6026
6027
6028         const FloatMatrix4& toTopMatrix = (pFromElement ? pFromElement->GetMatrixToTop() : pFromRoot->GetMatrixToTop());
6029         _MatrixUtilTransform(toTopMatrix, &x, &y, &z);
6030
6031         if (this != pFromRoot)
6032         {
6033                 const FloatMatrix4& fromTopMatrix = GetMatrixFromTop();
6034
6035                 if (!__matrixFromTopInvertible)
6036                         return E_INVALID_OPERATION;
6037
6038
6039                 // WARNING:
6040                 //      We should calculate z of world-coordinate mapped x-y plane of depth==0 in VE coordinate !
6041                 z = -(fromTopMatrix.matrix[0][2] * x + fromTopMatrix.matrix[1][2] * y + fromTopMatrix.matrix[3][2]) / fromTopMatrix.matrix[2][2];
6042
6043                 _MatrixUtilTransform(fromTopMatrix, &x, &y, &z);
6044         }
6045
6046
6047         point.SetPosition(x, y);   // z is omitted
6048
6049         return E_SUCCESS;
6050 }
6051
6052 result
6053 _VisualElementImpl::ConvertCoordinates(FloatRectangle& rectangle, const _VisualElementImpl* pFromElement) const
6054 {
6055         if (unlikely(this == pFromElement))
6056         {
6057                 return E_SUCCESS;
6058         }
6059
6060         _VisualElementImpl* pFromRoot = null;
6061         float x[4] = { rectangle.x, rectangle.x + rectangle.width, rectangle.x, rectangle.x + rectangle.width };
6062         float y[4] = { rectangle.y, rectangle.y, rectangle.y + rectangle.height, rectangle.y + rectangle.height };
6063         float z[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
6064
6065         if (likely(pFromElement))
6066         {
6067                 pFromRoot = pFromElement->GetRoot();
6068                 SysTryReturnResult(NID_UI_ANIM, GetRoot() == pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement and pFromElement is not belong to the same main tree.");
6069                 SysTryReturnResult(NID_UI_ANIM, pFromRoot || pFromElement->IsChildOf(*this) || IsChildOf(*pFromElement),
6070                                         E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement(%p) and pFromElement(%p) is not related.", this, pFromElement);
6071         }
6072         else
6073         {
6074                 pFromRoot = GetRoot();
6075                 SysTryReturnResult(NID_UI_ANIM, pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement is not attached to main tree.");
6076         }
6077
6078         const FloatMatrix4& toTopMatrix = (pFromElement ? pFromElement->GetMatrixToTop() : pFromRoot->GetMatrixToTop());
6079
6080         for (int i = 0; i < 4; i++)
6081         {
6082                 _MatrixUtilTransform(toTopMatrix, &x[i], &y[i], &z[i]);
6083         }
6084
6085         if (this != pFromRoot)
6086         {
6087                 const FloatMatrix4& fromTopMatrix = GetMatrixFromTop();
6088
6089                 if (!__matrixFromTopInvertible)
6090                         return E_INVALID_OPERATION;
6091
6092                 for (int i = 0; i < 4; i++)
6093                 {
6094                         // WARNING:
6095                         //      We should calculate z of world-coordinate mapped x-y plane of depth==0 in VE coordinate !
6096                         z[i] = -(fromTopMatrix.matrix[0][2] * x[i] + fromTopMatrix.matrix[1][2] * y[i] + fromTopMatrix.matrix[3][2]) / fromTopMatrix.matrix[2][2];
6097                         _MatrixUtilTransform(fromTopMatrix, &x[i], &y[i], &z[i]);
6098                 }
6099
6100         }
6101
6102         CalculateBoundingBox(x, y, rectangle);
6103
6104         return E_SUCCESS;
6105 }
6106
6107 result
6108 _VisualElementImpl::ConvertCoordinates(float* x, float* y, float* z, int count, const _VisualElementImpl* pFromElement) const
6109 {
6110         if (unlikely(this == pFromElement) || unlikely(count <= 0))
6111         {
6112                 return E_SUCCESS;
6113         }
6114
6115         _VisualElementImpl* pFromRoot = null;
6116
6117         if (likely(pFromElement))
6118         {
6119                 pFromRoot = pFromElement->GetRoot();
6120                 SysTryReturnResult(NID_UI_ANIM, GetRoot() == pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement and pFromElement is not belong to the same main tree.");
6121                 SysTryReturnResult(NID_UI_ANIM, pFromRoot || pFromElement->IsChildOf(*this) || IsChildOf(*pFromElement),
6122                                         E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement(%p) and pFromElement(%p) is not related.", this, pFromElement);
6123         }
6124         else
6125         {
6126                 pFromRoot = GetRoot();
6127                 SysTryReturnResult(NID_UI_ANIM, pFromRoot, E_INVALID_ARG, "Invalid argument(s) is used. This VisualElement is not attached to main tree.");
6128         }
6129
6130
6131         bool isUpwardConvertOnly = (pFromElement && pFromElement->IsChildOf(*this));
6132         const FloatMatrix4& toTopMatrix = (isUpwardConvertOnly ? pFromElement->CalcMatrixToBase(*this) :
6133                                                                                                                          pFromElement ? pFromElement->GetMatrixToTop() : pFromRoot->GetMatrixToTop());
6134
6135         for (int i = 0; i < count; i++)
6136         {
6137                 _MatrixUtilTransform(toTopMatrix, &x[i], &y[i], &z[i]);
6138         }
6139
6140         if (!isUpwardConvertOnly)
6141         {
6142                 const FloatMatrix4& fromTopMatrix = GetMatrixFromTop();
6143
6144                 if (!__matrixFromTopInvertible)
6145                         return E_INVALID_OPERATION;
6146
6147                 for (int i = 0; i < count; i++)
6148                 {
6149                         // WARNING:
6150                         //      We should calculate z of world-coordinate mapped x-y plane of depth==0 in VE coordinate !
6151                         z[i] = -(fromTopMatrix.matrix[0][2] * x[i] + fromTopMatrix.matrix[1][2] * y[i] + fromTopMatrix.matrix[3][2]) / fromTopMatrix.matrix[2][2];
6152                         _MatrixUtilTransform(fromTopMatrix, &x[i], &y[i], &z[i]);
6153                 }
6154         }
6155
6156         return E_SUCCESS;
6157 }
6158
6159 result
6160 _VisualElementImpl::CaptureI(Canvas& outputCanvas, const FloatRectangle& rectDest, _VisualElementImpl& reference, const FloatRectangle& clipRect, bool withChilren, int depth)
6161 {
6162         _CanvasImpl* pOutput = _CanvasImpl::GetInstance(outputCanvas);
6163
6164         SysTryReturnResult(NID_UI_ANIM, pOutput, E_INVALID_ARG, "Invalid argument(s) is used. Output canvas is invalid.");
6165         SysTryReturnResult(NID_UI_ANIM, GetRoot(), E_INVALID_STATE, "Invalid argument(s) is used. VisualElement is not attached to main tree.");
6166
6167         FloatRectangle bounds = __bounds;//GetDrawableRect();
6168
6169         bounds.x = 0.0f;
6170         bounds.y = 0.0f;
6171
6172         reference.ConvertCoordinates(bounds, this);
6173         FloatRectangle drawRect = bounds;
6174
6175         _VisualElementImpl* pRenderTarget = this->GetRenderTarget();
6176         drawRect = bounds.GetIntersection(clipRect);
6177
6178         FloatRectangle tempRect = drawRect;
6179
6180
6181         drawRect.x -= bounds.x;
6182         drawRect.y -= bounds.y;  //--> 0 - -20  = 20  : 20 - 20 = 0
6183
6184
6185         bounds = tempRect;
6186
6187         if (!drawRect.IsEmpty())
6188         {
6189                 if (pRenderTarget && HAVE_SURFACE(pRenderTarget))  // If element have surface , justly draw to the canvas
6190                 {
6191                         //Canvas* pCanvas = GetCanvasN(elementbounds);
6192 #ifdef USE_CANVAS_FOR_CAPTURE
6193                         Canvas* pCanvas = GetCanvasN();
6194                         if (pCanvas)
6195                         {
6196                                 Bitmap bitmap;
6197                                 bitmap.Construct(*pCanvas, Rectangle(drawRect.x, drawRect.y, drawRect.width, drawRect.height));
6198                                 bitmap.SetAlphaConstant((int)(pRenderTarget->GetOpacityFromRoot()*255));
6199
6200                                 Point point;
6201                                 point.x = rectDest.x + bounds.x;
6202                                 point.y = rectDest.y + bounds.y;
6203                                 outputCanvas.DrawBitmap(point, bitmap);
6204                                 delete pCanvas;
6205
6206 #else
6207                         if (__pSharedData->pSurface)
6208                         {
6209                                 BufferInfo info;
6210                                 __pSharedData->pSurface->GetBufferInfo(info);
6211
6212                                 _VisualElementSurfaceImpl* pSurfImpl = _VisualElementSurfaceImpl::GetInstance(*__pSharedData->pSurface);
6213
6214                                 if(pSurfImpl && pSurfImpl->GetNativeHandle())
6215                                 {
6216                                         byte* pStart = (byte*)evas_object_image_data_get((Evas_Object*)pSurfImpl->GetNativeHandle(), false);
6217
6218                                         if(pStart)
6219                                         {
6220                                                 byte* pCopy = new (std::nothrow) byte[info.height*(info.pitch)];
6221                                                 if (pCopy)
6222                                                 {
6223                                                         memcpy(pCopy, pStart, info.height*(info.pitch));
6224
6225                                                         for (int y = 0; y < info.height; y++)
6226                                                         {
6227                                                                 for (int x = 0; x < info.width; x++)
6228                                                                 {
6229                                                                         unsigned int* pAddr = (unsigned int*)((unsigned char*)pCopy + info.pitch * y + x * 4);
6230                                                                         int a = ((*pAddr) >> 24) & 0xff;
6231                                                                         int r = ((*pAddr) >> 16) & 0xff;
6232                                                                         int g = ((*pAddr) >> 8) & 0xff;
6233                                                                         int b = ((*pAddr) >> 0) & 0xff;
6234                                                                         if (a > 0)
6235                                                                         {
6236                                                                                 float fa = (float)a / 255.0f;
6237                                                                                 r = r / fa;
6238                                                                                 g = g / fa;
6239                                                                                 b = b / fa;
6240                                                                                 *pAddr = (a << 24) | (r << 16) | (g << 8) | b;
6241                                                                         }
6242                                                                 }
6243                                                         }
6244
6245                                                         ByteBuffer buffer;
6246                                                         result r = buffer.Construct(pCopy, 0, info.height*(info.pitch), info.height*(info.pitch));
6247
6248                                                         if (r == E_SUCCESS)
6249                                                         {
6250                                                                 Bitmap* pBitmap = Bitmap::GetNonScaledBitmapN(buffer, Dimension(info.width, info.height), BITMAP_PIXEL_FORMAT_ARGB8888);
6251                                                                 if (pBitmap)
6252                                                                 {
6253                                                                         pBitmap->SetAlphaConstant((int)(pRenderTarget->GetOpacityFromRoot() * 255.0f));
6254                                                                         Rectangle outputR(drawRect.x, drawRect.y, drawRect.width, drawRect.height);
6255                                                                         Rectangle srcRect =  outputR;
6256                                                                         outputR.x = rectDest.x + bounds.x;
6257                                                                         outputR.y = rectDest.y + bounds.y;
6258                                                                         outputCanvas.DrawBitmap(outputR, *pBitmap, srcRect);
6259
6260                                                                         delete pBitmap;
6261                                                                 }
6262                                                         }
6263
6264                                                         delete [] pCopy;
6265                                                 }
6266                                         }
6267                                 }
6268 #endif
6269                         }
6270                 }
6271                 else
6272                 {
6273                         _EflNode* pNativeNode = dynamic_cast< _EflNode* >(GetNativeNode());
6274
6275                         SysTryReturnResult(NID_UI_ANIM, pNativeNode, E_INVALID_STATE, "No object for background");   // CHECKME: Default BG?
6276                         _Colorf bgcolorf = pNativeNode->GetBackgroundColor();
6277                         Color color(bgcolorf.Red()*255, bgcolorf.Green()*255, bgcolorf.Blue()*255, bgcolorf.Alpha()*255);
6278
6279                         Point point;
6280                         point.x = rectDest.x + bounds.x;
6281                         point.y = rectDest.y + bounds.y;
6282
6283                         //pOutput->FillRectangle(color, Rectangle(drawRect.x + bounds.x, drawRect.y + bounds.y, drawRect.width, drawRect.height));
6284                         pOutput->FillRectangle(color, Rectangle(point.x, point.y, drawRect.width, drawRect.height));
6285                 }
6286         }
6287
6288         if (withChilren) // child draw
6289         {
6290                 _VisualElementImpl* pChild = null;
6291
6292                 FloatRectangle clipBounds = clipRect;
6293
6294                 int count = __children.GetCount();
6295
6296                 if(count > 0 && __isClipChildren)
6297                 {
6298                         clipBounds = clipRect.GetIntersection(bounds);
6299                 }
6300
6301                 for (int i = 0; i < count; i++)
6302                 {
6303                         pChild = __children.GetChildAt(i);
6304                         if (unlikely(!pChild) || unlikely(!VE_VISIBLE(pChild)))
6305                         {
6306                                 continue;
6307                         }
6308                         pChild->CaptureI(outputCanvas, rectDest, reference, clipBounds, true, depth + 1);
6309                 }
6310         }
6311
6312         return E_SUCCESS;
6313 }
6314
6315
6316
6317 result
6318 _VisualElementImpl::Capture(Canvas& outputCanvas, const FloatRectangle& rectDest, bool withChildren)
6319 {
6320         FloatRectangle tempDestRect = rectDest;
6321         tempDestRect.x = __bounds.x;
6322         tempDestRect.y = __bounds.y;
6323         FloatRectangle clipBounds = __bounds;
6324
6325         clipBounds = tempDestRect.GetIntersection(__bounds);
6326         clipBounds.x = 0;
6327         clipBounds.y = 0;
6328
6329         if(!VE_VISIBLE(this))
6330                 return E_SUCCESS;
6331
6332         return CaptureI(outputCanvas, rectDest, *this, clipBounds, withChildren, 0);
6333 // test boundray
6334 //      Rectangle cBounds = outputCanvas.GetBounds();
6335 //      outputCanvas.SetForegroundColor(Color(10,110,20));
6336 //      outputCanvas.DrawRectangle(Rectangle(cBounds.x+1,cBounds.y+1,cBounds.width-2,cBounds.height-2));
6337 //      outputCanvas.SetForegroundColor(Color(10,20,20));
6338 //      outputCanvas.DrawRectangle(Rectangle(rectDest.x+1,rectDest.y+1,rectDest.width-2,rectDest.height-2));
6339 //      return E_SUCCESS;
6340 }
6341 #if 0
6342 result
6343 _VisualElementImpl::Capture(Canvas& outputCanvas, const FloatRectangle& rectDest, bool withChildren)
6344 {
6345         result r = E_SUCCESS;
6346
6347         Rectangle rect;
6348
6349         rect.x = rectDest.x;
6350         rect.y = rectDest.y;
6351         rect.width = rectDest.width;
6352         rect.height = rectDest.height;
6353
6354         if (!withChildren)
6355         {
6356                 Canvas* pCanvas = GetCanvasN();
6357                 if (pCanvas)
6358                 {
6359                         r = outputCanvas.Copy(Point(0,0), *pCanvas, rect);
6360                         delete pCanvas;
6361                         return r;
6362                 }
6363
6364                 return GetLastResult();
6365         }
6366         else
6367         {
6368                 _EflNode* pNode = dynamic_cast<_EflNode*>(GetNativeNode());
6369                 SysTryReturnResult(pNode, E_INVALID_STATE, "VisualElement is invalid.");
6370                 if (pNode)
6371                 {
6372                         r = pNode->Capture(outputCanvas, Point(0,0), rect);
6373                 }
6374
6375                 SysTryReturn(r == E_SUCCESS, r, r,"[%s] Propagating.", GetErrorMessage(r));
6376         }
6377
6378         return r;
6379 }
6380 #endif
6381 result
6382 _VisualElementImpl::AddAnimation(const Tizen::Base::String* pKeyName, VisualElementAnimation& animation)
6383 {
6384         SysTryReturnResult(NID_UI_ANIM, !IS_PRESENTATION(this), E_INVALID_OPERATION, "This is not model.");
6385
6386         result r = E_SUCCESS;
6387
6388         bool isPropertyPropagationEnabled = __isPropertyPropagationEnabled;
6389
6390         __isPropertyPropagationEnabled = false;
6391
6392         if (dynamic_cast< VisualElementAnimationGroup* >(&animation) != null)
6393         {
6394                 VisualElementAnimation* pCloned = animation.CloneN();
6395                 SysTryReturnResult(NID_UI_ANIM, pCloned != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
6396
6397                 r = AddAnimationGroupI(pKeyName, *pCloned);
6398                 SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
6399
6400                 if (r != E_SUCCESS)
6401                 {
6402                         delete pCloned;
6403                 }
6404         }
6405         else
6406         {
6407                 r = AddAnimationI(pKeyName, animation);
6408                 SysTryLog(NID_UI_ANIM, r == E_SUCCESS, "[%s] Propagating.", GetErrorMessage(r));
6409         }
6410
6411         __isPropertyPropagationEnabled = isPropertyPropagationEnabled;
6412
6413         return r;
6414 }
6415
6416 result
6417 _VisualElementImpl::AddAnimationI(const Tizen::Base::String* pKeyName, VisualElementAnimation& animation)
6418 {
6419         result r = E_SUCCESS;
6420
6421         IVisualElementAnimationTickEventListener* pTickListener = null;
6422
6423         // Validate
6424         VisualElementValueAnimation* pValueAnimation = dynamic_cast< VisualElementValueAnimation* >(&animation);
6425         if (pValueAnimation != null)
6426         {
6427                 _VisualElementValueAnimationImpl* pValueAnimationImpl = _VisualElementValueAnimationImpl::GetInstance(*pValueAnimation);
6428                 SysTryReturnResult(NID_UI_ANIM, (pValueAnimationImpl->IsValid()), E_INVALID_ARG, "Invalid argument(s) is used. Animation value is invalid.");
6429
6430                 pTickListener = pValueAnimationImpl->GetTickEventListener();
6431         }
6432
6433         // Copy animation
6434         VisualElementAnimation* pCloned = animation.CloneN();
6435         SysTryReturnResult(NID_UI_ANIM, (pCloned != null), E_OUT_OF_MEMORY, "Memory allocation failed.");
6436
6437         _VisualElementAnimationImpl* pAnimationImpl = _VisualElementAnimationImpl::GetInstance(*pCloned);
6438
6439         if (pAnimationImpl->GetStatusEventListener() != null || pTickListener != null)
6440         {
6441                 pAnimationImpl->SetEventTarget(*GetPublic());
6442         }
6443
6444         // Use presentation tree for animation
6445         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6446
6447         r = _AnimationManager::GetInstance()->AddAnimation(*pPresentation, pKeyName, *pCloned);
6448         if (r != E_SUCCESS)
6449         {
6450                 SysTryLog(NID_UI_ANIM, "[%s] Failed to add animation.", GetErrorMessage(r));
6451
6452                 delete pCloned;
6453                 return r;
6454         }
6455
6456         // Change model tree value if endValueApplied is true
6457         VisualElementPropertyAnimation* pPropertyAnimation = dynamic_cast< VisualElementPropertyAnimation* >(pCloned);
6458
6459         if (pPropertyAnimation
6460                  && pPropertyAnimation->IsEndValueApplied()
6461                  && !pPropertyAnimation->IsAutoReverseEnabled()
6462                  && pPropertyAnimation->GetRepeatCount() != 0)
6463         {
6464                 const String& propertyName = pPropertyAnimation->GetPropertyName();
6465                 const Variant& endValue = pPropertyAnimation->GetEndValue();
6466
6467                 if (endValue.IsEmpty() == false && InvokeOnGetPropertyRequested(propertyName) != endValue)
6468                 {
6469                         (void) InvokeOnSetPropertyRequested(propertyName, endValue);
6470                 }
6471         }
6472
6473         return E_SUCCESS;
6474 }
6475
6476 result
6477 _VisualElementImpl::AddAnimationGroupI(const Tizen::Base::String* pKeyName, VisualElementAnimation& animation)
6478 {
6479         _AnimationManager* pAnimationManager = _AnimationManager::GetInstance();
6480
6481         // Get presentation tree
6482         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6483
6484         VisualElementAnimationGroup* pAnimationGroup = dynamic_cast< VisualElementAnimationGroup* >(&animation);
6485
6486         SysTryReturnResult(NID_UI_ANIM, (pAnimationGroup != null), E_INVALID_ARG, "Invalid argument(s) is used. Failed to add animation group.");
6487         SysTryReturnResult(NID_UI_ANIM, (pAnimationGroup->GetAnimationCount() > 0), E_INVALID_ARG, "Invalid argument(s) is used. Animation group has no animation.");
6488
6489         _VisualElementAnimationGroupImpl* pAnimationGroupImpl = _VisualElementAnimationGroupImpl::GetInstance(*pAnimationGroup);
6490
6491         if (pAnimationGroupImpl->GetStatusEventListener() != null)
6492         {
6493                 pAnimationGroupImpl->SetEventTarget(*GetPublic());
6494         }
6495
6496         result r = E_SUCCESS;
6497
6498         VisualElementAnimation* pAnimation = null;
6499         Tizen::Base::String name;
6500         int animationCount = 0;
6501
6502         int transactionID = pAnimationManager->BeginGroupTransaction(*pPresentation, pKeyName, *pAnimationGroup);
6503
6504         r = GetLastResult();
6505         SysTryCatch(NID_UI_ANIM, (transactionID > 0), , r, "[%s] Transaction is not created.", GetErrorMessage(r));
6506
6507         animationCount = pAnimationGroupImpl->GetAnimationCount();
6508
6509         for (int index = 0; index < animationCount; index++)
6510         {
6511                 pAnimation = pAnimationGroupImpl->GetAnimation(index);
6512
6513                 if (pAnimation == null)
6514                 {
6515                         continue;
6516                 }
6517
6518                 if (dynamic_cast< VisualElementAnimationGroup* >(pAnimation) != null)
6519                 {
6520                         r = AddAnimationGroupI(&name, *pAnimation);
6521                 }
6522                 else
6523                 {
6524                         r = AddAnimationI(&name, *pAnimation);
6525                 }
6526
6527                 SysTryCatch(NID_UI_ANIM, r == E_SUCCESS, , r, "[%s] animation manager is null.", GetErrorMessage(r));
6528         }
6529
6530         pAnimationManager->CommitTransaction();
6531
6532         return E_SUCCESS;
6533
6534 CATCH:
6535
6536         if (transactionID > 0)
6537         {
6538                 pAnimationManager->CancelTransaction(transactionID);
6539         }
6540
6541         return r;
6542 }
6543
6544 result
6545 _VisualElementImpl::RemoveAnimation(const Tizen::Base::String& keyName)
6546 {
6547         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6548
6549         return _AnimationManager::GetInstance()->RemoveAnimation(*pPresentation, keyName);
6550 }
6551
6552 result
6553 _VisualElementImpl::RemoveAllAnimations(void)
6554 {
6555         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6556
6557         _AnimationManager::GetInstance()->RemoveAllAnimations(*pPresentation);
6558
6559         return E_SUCCESS;
6560 }
6561
6562 VisualElementAnimation*
6563 _VisualElementImpl::GetAnimationN(const Tizen::Base::String& keyName) const
6564 {
6565         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6566
6567         ClearLastResult();
6568
6569         return _AnimationManager::GetInstance()->GetAnimationN(*pPresentation, keyName);
6570 }
6571
6572 VisualElementAnimation*
6573 _VisualElementImpl::GetAnimationForPropertyN(const Tizen::Base::String& property) const
6574 {
6575         VisualElement* pPresentation = __pPresentation->__pPublicInstance;
6576
6577         ClearLastResult();
6578
6579         return _AnimationManager::GetInstance()->GetAnimationForPropertyN(*pPresentation, property);
6580 }
6581
6582 bool
6583 _VisualElementImpl::CheckIfAnimatable(const String& property) const
6584 {
6585         // TODO:
6586         //      Optimize using map or other algorithms !
6587         //
6588
6589 #if 0
6590         static const wchar_t* supportedProperties[] = {
6591                 VeSubPropTransformScaleXY,
6592
6593                 VePropBounds,
6594                 VePropContentOpacity,
6595                 VePropOpacity,
6596                 VePropTransform,
6597                 VePropChildrenTransform,
6598                 VePropZPosition,        // TBD:
6599                 VeSubPropBoundsPosition,
6600                 VeSubPropBoundsSize,
6601
6602                 VeSubPropTransformRotationX,
6603                 VeSubPropTransformRotationY,
6604                 VeSubPropTransformRotationZ,
6605                 VeSubPropTransformRotationXY,
6606                 VeSubPropTransformScaleX,
6607                 VeSubPropTransformScaleY,
6608                 VeSubPropTransformScaleZ,
6609
6610                 VeSubPropTransformTranslationX,
6611                 VeSubPropTransformTranslationY,
6612                 VeSubPropTransformTranslationZ,
6613                 VeSubPropTransformTranslationXY,
6614                 VeSubPropChildrenTransformRotationX,
6615                 VeSubPropChildrenTransformRotationY,
6616                 VeSubPropChildrenTransformRotationZ,
6617                 VeSubPropChildrenTransformRotationXY,
6618                 VeSubPropChildrenTransformScaleX,
6619                 VeSubPropChildrenTransformScaleY,
6620                 VeSubPropChildrenTransformScaleZ,
6621                 VeSubPropChildrenTransformScaleXY,
6622                 VeSubPropChildrenTransformTranslationX,
6623                 VeSubPropChildrenTransformTranslationY,
6624                 VeSubPropChildrenTransformTranslationZ,
6625                 VeSubPropChildrenTransformTranslationXY
6626         };
6627 #else
6628         static String* const* supportedProperties[] = {
6629                 &pVePropBounds,
6630                 &pVePropContentOpacity,
6631                 &pVePropOpacity,
6632                 &pVePropTransform,
6633                 &pVePropChildrenTransform,
6634                 &pVePropZPosition,      // TBD:
6635                 &pVeSubPropBoundsPosition,
6636                 &pVeSubPropBoundsSize,
6637
6638                 &pVePropContentBounds,
6639 #if defined(SUPPORT_CUSTOMIZING_ATTACH_DETACH_ANIMATION)
6640                 &pVePropActionDetach,
6641                 &pVePropActionAttach,
6642 #endif
6643                 &pVeSubPropTransformRotationX,
6644                 &pVeSubPropTransformRotationY,
6645                 &pVeSubPropTransformRotationZ,
6646                 &pVeSubPropTransformRotationXY,
6647                 &pVeSubPropTransformScaleX,
6648                 &pVeSubPropTransformScaleY,
6649                 &pVeSubPropTransformScaleZ,
6650                 &pVeSubPropTransformScaleXY,
6651                 &pVeSubPropTransformTranslationX,
6652                 &pVeSubPropTransformTranslationY,
6653                 &pVeSubPropTransformTranslationZ,
6654                 &pVeSubPropTransformTranslationXY,
6655                 &pVeSubPropChildrenTransformRotationX,
6656                 &pVeSubPropChildrenTransformRotationY,
6657                 &pVeSubPropChildrenTransformRotationZ,
6658                 &pVeSubPropChildrenTransformRotationXY,
6659                 &pVeSubPropChildrenTransformScaleX,
6660                 &pVeSubPropChildrenTransformScaleY,
6661                 &pVeSubPropChildrenTransformScaleZ,
6662                 &pVeSubPropChildrenTransformScaleXY,
6663                 &pVeSubPropChildrenTransformTranslationX,
6664                 &pVeSubPropChildrenTransformTranslationY,
6665                 &pVeSubPropChildrenTransformTranslationZ,
6666                 &pVeSubPropChildrenTransformTranslationXY
6667         };
6668 #endif
6669
6670         for (int i = 0; i < static_cast< int >(sizeof(supportedProperties) / sizeof(supportedProperties[0])); i++)
6671         {
6672                 //if (wcscmp(property.GetPointer(), supportedProperties[i]) == 0)
6673                 if (property.GetPointer() == (*supportedProperties[i])->GetPointer() || property == **supportedProperties[i])
6674                 {
6675                         return true;
6676                 }
6677         }
6678
6679         return false;
6680 }
6681
6682 VisualElementAnimation*
6683 _VisualElementImpl::CreateAnimationForPropertyI(const Tizen::Base::String& property)
6684 {
6685         if (IS_PRESENTATION(this) || !CheckIfAnimatable(property))
6686         {
6687                 return null;
6688         }
6689
6690 #if 0
6691         if (property.CompareTo(String(VePropBounds)) == 0)
6692         {
6693                 //ToDo: default implementation
6694         }
6695         else if (property.CompareTo(String(VePropOpacity)) == 0)
6696         {
6697                 //ToDo: default implementation
6698         }
6699         else if (property.CompareTo(String(VePropChildrenOpacity)) == 0)
6700         {
6701                 //ToDo: default implementation
6702         }
6703         else if (property.CompareTo(String(VePropShowState)) == 0)
6704         {
6705                 //ToDo: default implementation
6706         }
6707         else if (property.CompareTo(String(VePropTransform)) == 0)
6708         {
6709                 //ToDo: default implementation
6710         }
6711         else if (property.CompareTo(String(VePropChildrenTransform)) == 0)
6712         {
6713                 //ToDo: default implementation
6714         }
6715         else if (property.CompareTo(String(VePropZPosition)) == 0)
6716         {
6717                 //ToDo: default implementation
6718         }
6719         else
6720                 return null;
6721 #endif
6722         VisualElementPropertyAnimation* pAnimation = new (std::nothrow) VisualElementPropertyAnimation();
6723         SysTryReturn(NID_UI_ANIM, pAnimation != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
6724
6725 #if defined(SUPPORT_CUSTOMIZING_ATTACH_DETACH_ANIMATION)
6726         if (unlikely(property == *pVePropActionAttach))
6727         {
6728                 pAnimation->SetPropertyName(*pVePropOpacity);
6729                 pAnimation->SetStartValue(Variant(0.0f));
6730         }
6731         else if (unlikely(property == *pVePropActionDetach))
6732         {
6733                 pAnimation->SetPropertyName(*pVePropOpacity);
6734                 pAnimation->SetEndValue(Variant(0.0f));
6735         }
6736         else
6737 #endif
6738         {
6739                 _VisualElementImpl* pPresentation = GetPresentation();
6740
6741                 const Variant& curValue = pPresentation->InvokeOnGetPropertyRequested(property);
6742                 result r = GetLastResult();
6743                 SysTryCatch(NID_UI_ANIM, !IsFailed(r), , r, "[%s] No property for animation exists.", GetErrorMessage(r));
6744
6745                 pAnimation->SetPropertyName(property);
6746                 pAnimation->SetStartValue(curValue);
6747         }
6748
6749         return pAnimation;
6750
6751
6752 CATCH:
6753         delete pAnimation;
6754
6755         return null;
6756 }
6757
6758 void
6759 _VisualElementImpl::SetBoundsChangedCallback(BoundsChangedCallback pCallback, void* pData)
6760 {
6761         __pBoundsChangedCallback = pCallback;
6762         __pBoundsChangedCallbackData = pData;
6763 }
6764
6765
6766 // delegate---------------------------------------------------------------------------------
6767
6768 void
6769 _VisualElementImpl::InvokeOnConstructed(void)
6770 {
6771         if (__pPublicInstance)
6772         {
6773                 if (IS_MODEL(this))
6774                 {
6775                         __pPublicInstance->OnConstructed();
6776                 }
6777         }
6778
6779         ClearLastResult();
6780 }
6781
6782 void
6783 _VisualElementImpl::InvokeOnDestructing(void)
6784 {
6785         if (__pPublicInstance)
6786         {
6787                 if (IS_MODEL(this))
6788                 {
6789                         __pPublicInstance->OnDestructing();
6790                 }
6791         }
6792
6793         ClearLastResult();
6794 }
6795
6796 int
6797 _VisualElementImpl::InvokeHitTest(const Tizen::Graphics::FloatPoint& point)
6798 {
6799         int hitTest = _VisualElementImpl::HITTEST_NOWHERE;
6800
6801         if (__pPublicInstance && !__isInternal)
6802         {
6803                 HitTestResult hitResult = HIT_TEST_NOWHERE;
6804
6805                 if (GetSharedData().pContentProvider)
6806                 {
6807                         hitResult = GetSharedData().pContentProvider->HitTest(*__pPublicInstance, point);
6808                 }
6809                 else
6810                 {
6811                         hitResult = __pPublicInstance->OnHitTest(point);
6812                 }
6813
6814                 if (hitResult == HIT_TEST_NOWHERE)
6815                 {
6816                         hitTest = _VisualElementImpl::HITTEST_NOWHERE;
6817                 }
6818                 else
6819                 {
6820                         hitTest = _VisualElementImpl::HITTEST_MATCH;
6821                 }
6822         }
6823         else
6824         {
6825                 return HitTestI(point);
6826         }
6827
6828         ClearLastResult();
6829
6830         return hitTest;
6831 }
6832
6833 bool
6834 _VisualElementImpl::InvokePrepareDraw(void)
6835 {
6836         bool result = true;
6837
6838         if (__pPublicInstance)
6839         {
6840                 if (GetSharedData().pContentProvider)
6841                 {
6842                         result = GetSharedData().pContentProvider->PrepareDraw(*__pPublicInstance);
6843                 }
6844                 else
6845                 {
6846                         result = __pPublicInstance->OnPrepareDraw();
6847                 }
6848         }
6849
6850         ClearLastResult();
6851
6852         return result;
6853 }
6854
6855 void
6856 _VisualElementImpl::InvokeOnDraw(Tizen::Graphics::Canvas& canvas)
6857 {
6858         if (__pPublicInstance)
6859         {
6860                 if (GetSharedData().pContentProvider)
6861                 {
6862                         GetSharedData().pContentProvider->DrawContent(*__pPublicInstance, canvas);
6863                 }
6864                 else
6865                 {
6866                         __pPublicInstance->OnDraw(canvas);
6867                 }
6868         }
6869
6870         ClearLastResult();
6871 }
6872
6873 VisualElementAnimation*
6874 _VisualElementImpl::InvokeCreateAnimationForProperty(const Tizen::Base::String& property)
6875 {
6876         VisualElementAnimation* pAnimation = null;
6877
6878         if (__pPublicInstance)
6879         {
6880                 if (GetSharedData().pAnimationProvider)
6881                 {
6882                         pAnimation = GetSharedData().pAnimationProvider->CreateAnimationForProperty(*__pPublicInstance, property);
6883                 }
6884                 else
6885                 {
6886                         pAnimation = __pPublicInstance->OnCreateAnimationForProperty(property);
6887                 }
6888         }
6889
6890         ClearLastResult();
6891
6892         return pAnimation;
6893 }
6894
6895 result
6896 _VisualElementImpl::InvokeOnChildAttaching(_VisualElementImpl& child)
6897 {
6898         ClearLastResult();
6899         return E_SUCCESS;
6900 }
6901
6902 void
6903 _VisualElementImpl::InvokeOnChildAttached(_VisualElementImpl& child)
6904 {
6905         if (__pPublicInstance && !__isInternal)
6906         {
6907                 VisualElement* pChild = child.__pPublicInstance;
6908
6909                 if (GetSharedData().pEventListener)
6910                 {
6911                         GetSharedData().pEventListener->OnChildAttached(*__pPublicInstance, *pChild);
6912                 }
6913         }
6914
6915         ClearLastResult();
6916 }
6917
6918 result
6919 _VisualElementImpl::InvokeOnChildDetaching(_VisualElementImpl& child)
6920 {
6921         ClearLastResult();
6922         return E_SUCCESS;
6923 }
6924
6925 void
6926 _VisualElementImpl::InvokeOnChildDetached(_VisualElementImpl& child)
6927 {
6928         if (__pPublicInstance && !__isInternal)
6929         {
6930                 VisualElement* pChild = child.__pPublicInstance;
6931
6932                 if (GetSharedData().pEventListener)
6933                 {
6934                         GetSharedData().pEventListener->OnChildDetached(*__pPublicInstance, *pChild);
6935                 }
6936         }
6937
6938         ClearLastResult();
6939 }
6940
6941 result
6942 _VisualElementImpl::InvokeOnAttaching(_VisualElementImpl& parent)
6943 {
6944         ClearLastResult();
6945         return E_SUCCESS;
6946 }
6947
6948 void
6949 _VisualElementImpl::InvokeOnAttached(void)
6950 {
6951         if (__pPublicInstance && !__isInternal)
6952         {
6953                 _VisualElementImpl* pParentInternal = GetParent();
6954                 if (pParentInternal)
6955                 {
6956                         VisualElement* pParent = pParentInternal->__pPublicInstance;
6957
6958                         if (GetSharedData().pEventListener)
6959                         {
6960                                 __isAllowedTreeModification = false;
6961                                 GetSharedData().pEventListener->OnAttached(*__pPublicInstance, *pParent);
6962                                 __isAllowedTreeModification = true;
6963                         }
6964                 }
6965         }
6966
6967         ClearLastResult();
6968 }
6969
6970 result
6971 _VisualElementImpl::InvokeOnDetaching(void)
6972 {
6973         ClearLastResult();
6974         return E_SUCCESS;
6975 }
6976
6977 void
6978 _VisualElementImpl::InvokeOnDetached(_VisualElementImpl& parent)
6979 {
6980         if (__pPublicInstance && !__isInternal)
6981         {
6982                 VisualElement* pParent = parent.__pPublicInstance;
6983
6984                 if (GetSharedData().pEventListener)
6985                 {
6986                         __isAllowedTreeModification = false;
6987                         GetSharedData().pEventListener->OnDetached(*__pPublicInstance, *pParent);
6988                         __isAllowedTreeModification = true;
6989                 }
6990         }
6991 }
6992
6993 result
6994 _VisualElementImpl::InvokeOnAnimationAdded(const VisualElementAnimation* pAnimation)
6995 {
6996         //TODO: Implementation
6997         ClearLastResult();
6998         return E_SUCCESS;
6999 }
7000
7001 result
7002 _VisualElementImpl::InvokeOnAnimationRemoved(const VisualElementAnimation* pAnimation)
7003 {
7004         //TODO: Implementation
7005         ClearLastResult();
7006         return E_SUCCESS;
7007 }
7008
7009 void
7010 _VisualElementImpl::InvokeOnShowStateChanged(bool showState)
7011 {
7012         if (__pPublicInstance && !__isInternal)
7013         {
7014                 if (GetSharedData().pEventListener)
7015                 {
7016                         GetSharedData().pEventListener->OnShowStateChanged(*__pPublicInstance, showState);
7017                 }
7018         }
7019
7020         ClearLastResult();
7021 }
7022
7023 result
7024 _VisualElementImpl::InvokeOnTransformMatrixChanging(FloatMatrix4& newTransform)
7025 {
7026         if (__pPublicInstance && !__isInternal)
7027         {
7028                 if (GetSharedData().pEventListener)
7029                 {
7030                         return GetSharedData().pEventListener->OnTransformChanging(*__pPublicInstance, newTransform);
7031                 }
7032
7033                 return E_SUCCESS;
7034         }
7035
7036         return E_INVALID_STATE;
7037 }
7038
7039 void
7040 _VisualElementImpl::InvokeOnTransformMatrixChanged(const FloatMatrix4& oldTransform)
7041 {
7042         if (__pPublicInstance && !__isInternal)
7043         {
7044                 if (GetSharedData().pEventListener)
7045                 {
7046                         GetSharedData().pEventListener->OnTransformChanged(*__pPublicInstance, oldTransform);
7047                 }
7048         }
7049
7050         ClearLastResult();
7051 }
7052
7053 result
7054 _VisualElementImpl::InvokeOnChildrenTransformMatrixChanging(FloatMatrix4& newTransform)
7055 {
7056         if (__pPublicInstance && !__isInternal)
7057         {
7058                 if (GetSharedData().pEventListener)
7059                 {
7060                         return GetSharedData().pEventListener->OnChildrenTransformChanging(*__pPublicInstance, newTransform);
7061                 }
7062
7063                 return E_SUCCESS;
7064         }
7065
7066         return E_INVALID_STATE;
7067 }
7068
7069 void
7070 _VisualElementImpl::InvokeOnChildrenTransformMatrixChanged(const FloatMatrix4& oldTransform)
7071 {
7072         if (__pPublicInstance && !__isInternal)
7073         {
7074                 if (GetSharedData().pEventListener)
7075                 {
7076                         GetSharedData().pEventListener->OnChildrenTransformChanged(*__pPublicInstance, oldTransform);
7077                 }
7078         }
7079
7080         ClearLastResult();
7081 }
7082
7083 result
7084 _VisualElementImpl::InvokeOnBoundsChanging(FloatRectangle& newBounds)
7085 {
7086         if (__pPublicInstance && !__isInternal)
7087         {
7088                 if (GetSharedData().pEventListener)
7089                 {
7090                         return GetSharedData().pEventListener->OnBoundsChanging(*__pPublicInstance, newBounds);
7091                 }
7092
7093                 return E_SUCCESS;
7094         }
7095
7096         return E_INVALID_STATE;
7097 }
7098
7099 void
7100 _VisualElementImpl::InvokeOnBoundsChanged(const FloatRectangle& oldBounds)
7101 {
7102         if (__pPublicInstance && !__isInternal)
7103         {
7104                 if (GetSharedData().pEventListener)
7105                 {
7106                         GetSharedData().pEventListener->OnBoundsChanged(*__pPublicInstance, oldBounds);
7107                 }
7108         }
7109
7110         ClearLastResult();
7111 }
7112
7113 }}}
7114