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