[NUI] Fix TV Gallary crash (#975)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / View.cs
index 8e2b522..dd4ac21 100755 (executable)
@@ -63,21 +63,6 @@ namespace Tizen.NUI.BaseComponents
         public const int WrapContent = -2;
     }
 
-    /// <summary>
-    /// [Draft] Replaced by LayoutParamPolicies, will be removed once occurrences replaced.
-    /// </summary>
-    internal enum ChildLayoutData
-    {
-        /// <summary>
-        /// Constant which indicates child size should match parent size
-        /// </summary>
-        MatchParent = LayoutParamPolicies.MatchParent,
-        /// <summary>
-        /// Constant which indicates parent should take the smallest size possible to wrap it's children with their desired size
-        /// </summary>
-        WrapContent = LayoutParamPolicies.WrapContent,
-    }
-
     internal enum ResourceLoadingStatusType
     {
         Invalid = -1,
@@ -1275,7 +1260,7 @@ namespace Tizen.NUI.BaseComponents
         });
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static readonly BindableProperty StyleProperty = BindableProperty.Create("Style", typeof(Style), typeof(View), default(Style), propertyChanged: (bindable, oldvalue, newvalue) => ((View)bindable)._mergedStyle.Style = (Style)newvalue);
+        public static readonly BindableProperty XamlStyleProperty = BindableProperty.Create("XamlStyle", typeof(Style), typeof(View), default(Style), propertyChanged: (bindable, oldvalue, newvalue) => ((View)bindable)._mergedStyle.Style = (Style)newvalue);
 
         /// <summary>
         /// Flag to indicate if layout set explicitly via API call or View was automatically given a Layout.
@@ -1309,6 +1294,9 @@ namespace Tizen.NUI.BaseComponents
 
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
         private LayoutItem _layout; // Exclusive layout assigned to this View.
+
+        // List of transitions paired with the condition that uses the transition.
+        private Dictionary<TransitionCondition, TransitionList> _layoutTransitions;
         private int _widthPolicy = LayoutParamPolicies.WrapContent; // Layout width policy
         private int _heightPolicy = LayoutParamPolicies.WrapContent; // Layout height policy
         private float _weight = 0.0f; // Weighting of child View in a Layout
@@ -2278,7 +2266,7 @@ namespace Tizen.NUI.BaseComponents
         /// This means by default others are impossible so it is recommended that NUI object typed properties are configured by their constructor with parameters. <br />
         /// For example, this code is working fine : view.Scale = new Vector3( 2.0f, 1.5f, 0.0f); <br />
         /// but this will not work! : view.Scale.X = 2.0f; view.Scale.Y = 1.5f; <br />
-        /// It may not match the current value in some cases, i.e. when the animation is progressing or the maximum or minimu size is set. <br />
+        /// It may not match the current value in some cases, i.e. when the animation is progressing or the maximum or minimum size is set. <br />
         /// </remarks>
         /// <since_tizen> 3 </since_tizen>
         public Size2D Size2D
@@ -2295,6 +2283,9 @@ namespace Tizen.NUI.BaseComponents
                 // All Views are currently Layouts.
                 MeasureSpecificationWidth = new MeasureSpecification(new LayoutLength(value.Width), MeasureSpecification.ModeType.Exactly);
                 MeasureSpecificationHeight = new MeasureSpecification(new LayoutLength(value.Height), MeasureSpecification.ModeType.Exactly);
+                _widthPolicy = value.Width;
+                _heightPolicy = value.Height;
+                _layout?.RequestLayout();
                 NotifyPropertyChanged();
             }
         }
@@ -3411,9 +3402,12 @@ namespace Tizen.NUI.BaseComponents
         }
 
         ///<summary>
-        /// The required policy for this dimension, ChildLayoutData enum or exact value.
+        /// The required policy for this dimension, LayoutParamPolicies enum or exact value.
         ///</summary>
         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
+        /// <remarks>
+        /// Previously named LayoutWidthSpecification
+        /// </remarks>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public int WidthSpecification
         {
@@ -3427,6 +3421,7 @@ namespace Tizen.NUI.BaseComponents
                 if (_widthPolicy >= 0)
                 {
                     _measureSpecificationWidth = new MeasureSpecification( new LayoutLength(value), MeasureSpecification.ModeType.Exactly );
+                    //Tizen.NUI.Object.SetProperty(swigCPtr, View.Property.SIZE_WIDTH, new Tizen.NUI.PropertyValue(value));
                     Size2D.Width = _widthPolicy;
                 }
                 _layout?.RequestLayout();
@@ -3434,9 +3429,12 @@ namespace Tizen.NUI.BaseComponents
         }
 
         ///<summary>
-        /// The required policy for this dimension, ChildLayoutData enum or exact value.
+        /// The required policy for this dimension, LayoutParamPolicies enum or exact value.
         ///</summary>
         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
+        /// <remarks>
+        /// Previously named LayoutHeightSpecification
+        /// </remarks>
         [EditorBrowsable(EditorBrowsableState.Never)]
         public int HeightSpecification
         {
@@ -3450,12 +3448,43 @@ namespace Tizen.NUI.BaseComponents
                 if (_heightPolicy >= 0)
                 {
                     _measureSpecificationHeight = new MeasureSpecification( new LayoutLength(value), MeasureSpecification.ModeType.Exactly );
+                    //Tizen.NUI.Object.SetProperty(swigCPtr, View.Property.SIZE_HEIGHT, new Tizen.NUI.PropertyValue(value));
                     Size2D.Height = _heightPolicy;
                 }
                _layout?.RequestLayout();
             }
         }
 
+        ///<summary>
+        /// Gets the List of transitions for this View.
+        ///</summary>
+        /// Hidden-API which is usually used as Inhouse-API. If required to be opened as Public-API, ACR process is needed.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Dictionary<TransitionCondition, TransitionList> LayoutTransitions
+        {
+            get
+            {
+                if (_layoutTransitions == null)
+                {
+                    _layoutTransitions = new Dictionary<TransitionCondition, TransitionList>();
+                }
+                return _layoutTransitions;
+            }
+        }
+
+        internal LayoutTransition LayoutTransition
+        {
+            set
+            {
+                if (_layoutTransitions == null)
+                {
+                    _layoutTransitions = new Dictionary<TransitionCondition, TransitionList>();
+                }
+                LayoutTransitionsHelper.AddTransitionForCondition(_layoutTransitions,value.Condition,value, true);
+
+                AttachTransitionsToChildren(value);
+            }
+        }
 
         /// <summary>
         /// [Obsolete("Please do not use! this will be deprecated")]
@@ -3484,81 +3513,49 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 6 </since_tizen>
         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public Style Style
+        public Style XamlStyle
         {
             get
             {
-                return (Style)GetValue(StyleProperty);
+                return (Style)GetValue(XamlStyleProperty);
             }
             set
             {
-                SetValue(StyleProperty, value);
+                SetValue(XamlStyleProperty, value);
             }
         }
 
         /// <summary>
-        /// Child property to specify desired width
+        /// The Color of View. This is an RGBA value.
         /// </summary>
-        internal int LayoutWidthSpecificationFixed
+        /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Color Color
         {
-            get
-            {
-                return _widthPolicy;
-            }
             set
             {
-                _widthPolicy = value;
-                _measureSpecificationWidth = new MeasureSpecification(new LayoutLength(value), MeasureSpecification.ModeType.Exactly);
-                Size2D.Width = value;
-                _layout?.RequestLayout();
+                SetColor(value);
             }
-        }
-
-        /// <summary>
-        /// Child property to specify desired height
-        /// </summary>
-        internal int LayoutHeightSpecificationFixed
-        {
             get
             {
-                return _heightPolicy;
-            }
-            set
-            {
-                _heightPolicy = value;
-                _measureSpecificationHeight = new MeasureSpecification(new LayoutLength(value), MeasureSpecification.ModeType.Exactly);
-                Size2D.Height = value;
-                _layout?.RequestLayout();
+                return GetCurrentColor();
             }
         }
 
         /// <summary>
-        /// Child property to specify desired width, use MatchParent/WrapContent)
+        /// The color mode of View.
+        /// This specifies whether the View uses its own color, or inherits its parent color.
+        /// The default is ColorMode.UseOwnMultiplyParentColor.
         /// </summary>
-        internal ChildLayoutData LayoutWidthSpecification
+        internal ColorMode ColorMode
         {
-            get
-            {
-                return (ChildLayoutData)_widthPolicy;
-            }
             set
             {
-                _widthPolicy = (int)value;
+                SetColorMode(value);
             }
-        }
-
-        /// <summary>
-        /// Child property to specify desired height, use MatchParent/WrapContent)
-        /// </summary>
-        internal ChildLayoutData LayoutHeightSpecification
-        {
             get
             {
-                return (ChildLayoutData)_heightPolicy;
-            }
-            set
-            {
-                _heightPolicy = (int)value;
+                return GetColorMode();
             }
         }
 
@@ -3571,11 +3568,18 @@ namespace Tizen.NUI.BaseComponents
             set
             {
                 _weight = value;
-                _layout.RequestLayout();
+                _layout?.RequestLayout();
             }
         }
 
-        internal bool BackgroundImageSynchronosLoading
+        /// <summary>
+        ///  Whether to load the BackgroundImage synchronously.
+        ///  If not specified, the default is false, i.e. the BackgroundImage is loaded asynchronously.
+        ///  Note: For Normal Quad images only.
+        /// </summary>
+        /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool BackgroundImageSynchronosLoading
         {
             get
             {
@@ -3648,8 +3652,6 @@ namespace Tizen.NUI.BaseComponents
         /// <summary>
         /// Set the layout on this View. Replaces any existing Layout.
         /// </summary>
-        /// <remarks>
-        /// </remarks>
         internal LayoutItem Layout
         {
             get
@@ -3772,6 +3774,17 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        internal void AttachTransitionsToChildren(LayoutTransition transition)
+        {
+            // Iterate children, adding the transition unless a transition
+            // for the same condition and property has already been
+            // explicitly added.
+            foreach (View view in Children)
+            {
+                LayoutTransitionsHelper.AddTransitionForCondition(view.LayoutTransitions,transition.Condition, transition, false);
+            }
+        }
+
         internal float ParentOriginX
         {
             get
@@ -4012,7 +4025,7 @@ namespace Tizen.NUI.BaseComponents
         public override void Add(View child)
         {
             bool hasLayout = (_layout != null);
-            Log.Info("NUI", "Add:" + child.Name + " to View:" + Name + "which has layout[" + hasLayout + "] + \n");
+            Log.Info("NUI", "Add:" + child.Name + " to View:" + Name + " which has layout[" + hasLayout + "] + \n");
 
             if (null == child)
             {
@@ -4055,23 +4068,22 @@ namespace Tizen.NUI.BaseComponents
         /// <since_tizen> 4 </since_tizen>
         public override void Remove(View child)
         {
-            bool hasLayout = (_layout != null);
-            Log.Info("NUI","Removing View:" + child.Name + "layout[" + hasLayout.ToString() +"]\n");
-
-            Interop.Actor.Actor_Remove(swigCPtr, View.getCPtr(child));
-            if (NDalicPINVOKE.SWIGPendingException.Pending)
-                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            if (!child || child.GetParent()==null) // Early out if child null.
+                return;
 
-            Children.Remove(child);
-            child.InternalParent = null;
+            bool hasLayout = (_layout != null);
+            Log.Info("NUI","Removing View:" + child.Name + " layout[" + hasLayout.ToString() +"]\n");
 
-            if (ChildRemoved != null)
+            // If View has a layout then do a deferred child removal
+            // Actual child removal is performed by the layouting system so
+            // transitions can be completed.
+            if (hasLayout)
             {
-                ChildRemovedEventArgs e = new ChildRemovedEventArgs
-                {
-                    Removed = child
-                };
-                ChildRemoved(this, e);
+                (_layout as LayoutGroup)?.RemoveChildFromLayoutGroup( child );
+            }
+            else
+            {
+                RemoveChild(child);
             }
         }
 
@@ -4979,7 +4991,9 @@ namespace Tizen.NUI.BaseComponents
             return ret;
         }
 
-        internal void SetColorMode(ColorMode colorMode)
+        /// This will be public opened in next tizen after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetColorMode(ColorMode colorMode)
         {
             Interop.ActorInternal.Actor_SetColorMode(swigCPtr, (int)colorMode);
             if (NDalicPINVOKE.SWIGPendingException.Pending)
@@ -5224,25 +5238,6 @@ namespace Tizen.NUI.BaseComponents
             return ret;
         }
 
-        internal void SetBackgroundColor(Vector4 color)
-        {
-            Interop.ViewInternal.View_SetBackgroundColor(swigCPtr, Vector4.getCPtr(color));
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        internal Vector4 GetBackgroundColor()
-        {
-            Vector4 ret = new Vector4(Interop.ViewInternal.View_GetBackgroundColor(swigCPtr), true);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
-        }
-
-        internal void SetBackgroundImage(Image image)
-        {
-            Interop.ViewInternal.View_SetBackgroundImage(swigCPtr, Image.getCPtr(image));
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
         internal ControlKeySignal KeyEventSignal()
         {
             ControlKeySignal ret = new ControlKeySignal(Interop.ViewSignal.View_KeyEventSignal(swigCPtr), false);
@@ -5269,6 +5264,26 @@ namespace Tizen.NUI.BaseComponents
             return (IntPtr)swigCPtr;
         }
 
+        internal void RemoveChild(View child)
+        {
+            // Do actual child removal
+            Interop.Actor.Actor_Remove(swigCPtr, View.getCPtr(child));
+            if (NDalicPINVOKE.SWIGPendingException.Pending)
+                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+            Children.Remove(child);
+            child.InternalParent = null;
+
+            if (ChildRemoved != null)
+            {
+                ChildRemovedEventArgs e = new ChildRemovedEventArgs
+                {
+                    Removed = child
+                };
+                ChildRemoved(this, e);
+            }
+        }
+
         /// <summary>
         /// Removes the layout from this View.
         /// </summary>
@@ -5294,6 +5309,8 @@ namespace Tizen.NUI.BaseComponents
                 return;
             }
 
+            //_mergedStyle = null;
+
             if (type == DisposeTypes.Explicit)
             {
                 //Called by User