Revert "[NUI] Correct the meaning of ExcludeLayouting. (#2256)"
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Layouting / LayoutItem.cs
index 770f1d1..7ba44af 100755 (executable)
  *
  */
 
-
 using System;
+using System.ComponentModel;
 using System.Diagnostics;
+
 using Tizen.NUI.BaseComponents;
-using System.ComponentModel;
 
 namespace Tizen.NUI
 {
@@ -37,22 +37,23 @@ namespace Tizen.NUI
     /// [Draft] Base class for layouts. It is used to layout a View
     /// It can be laid out by a LayoutGroup.
     /// </summary>
-    public class LayoutItem : Disposable
+    public class LayoutItem
     {
         static bool LayoutDebugFrameData = false; // Debug flag
         private MeasureSpecification OldWidthMeasureSpec; // Store measure specification to compare against later
-        private MeasureSpecification OldHeightMeasureSpec;// Store measure specification to compare against later
+        private MeasureSpecification OldHeightMeasureSpec; // Store measure specification to compare against later
 
         private LayoutFlags Flags = LayoutFlags.None;
 
         private ILayoutParent Parent;
 
-        LayoutData layoutPositionData;
+        LayoutData _layoutPositionData;
 
-        private Extents padding;
-        private Extents margin;
+        private Extents _padding;
+        private Extents _margin;
 
         private bool parentReplacement = false;
+        private bool setPositionByLayout = true;
 
         /// <summary>
         /// [Draft] Condition event that is causing this Layout to transition.
@@ -77,7 +78,21 @@ namespace Tizen.NUI
         /// [Draft] Set position by layouting result
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool SetPositionByLayout { get; set; } = true;
+        public bool SetPositionByLayout
+        {
+            get
+            {
+                return setPositionByLayout;
+            }
+            set
+            {
+                setPositionByLayout = value;
+                if (Owner != null && Owner.ExcludeLayouting != value)
+                {
+                    Owner.ExcludeLayouting = value;
+                }
+            }
+        }
 
         /// <summary>
         /// [Draft] Margin for this LayoutItem
@@ -87,11 +102,11 @@ namespace Tizen.NUI
         {
             get
             {
-                return margin;
+                return _margin;
             }
             set
             {
-                margin = value;
+                _margin = value;
                 RequestLayout();
             }
         }
@@ -104,11 +119,11 @@ namespace Tizen.NUI
         {
             get
             {
-                return padding;
+                return _padding;
             }
             set
             {
-                padding = value;
+                _padding = value;
                 RequestLayout();
             }
         }
@@ -122,15 +137,6 @@ namespace Tizen.NUI
             Initialize();
         }
 
-        /// <summary>  
-        /// destructor. This is HiddenAPI. recommended not to use in public.   
-        /// </summary> 
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        ~LayoutItem()
-        {
-            Dispose();
-        }
-
         /// <summary>
         /// [Draft] Set parent to this layout.
         /// </summary>
@@ -161,9 +167,9 @@ namespace Tizen.NUI
         private void Initialize()
         {
             LayoutWithTransition = false;
-            layoutPositionData = new LayoutData(this, TransitionCondition.Unspecified, 0, 0, 0, 0);
-            padding = new Extents(0, 0, 0, 0);
-            margin = new Extents(0, 0, 0, 0);
+            _layoutPositionData = new LayoutData(this, TransitionCondition.Unspecified, 0, 0, 0, 0);
+            _padding = new Extents(0, 0, 0, 0);
+            _margin = new Extents(0, 0, 0, 0);
         }
 
         /// <summary>
@@ -199,15 +205,15 @@ namespace Tizen.NUI
         {
             // Check if relayouting is required.
             bool specChanged = (widthMeasureSpec.Size != OldWidthMeasureSpec.Size) ||
-                               (heightMeasureSpec.Size != OldHeightMeasureSpec.Size) ||
-                               (widthMeasureSpec.Mode != OldWidthMeasureSpec.Mode) ||
-                               (heightMeasureSpec.Mode != OldHeightMeasureSpec.Mode);
+                (heightMeasureSpec.Size != OldHeightMeasureSpec.Size) ||
+                (widthMeasureSpec.Mode != OldWidthMeasureSpec.Mode) ||
+                (heightMeasureSpec.Mode != OldHeightMeasureSpec.Mode);
 
             bool isSpecExactly = (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly) &&
-                                 (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly);
+                (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly);
 
             bool matchesSpecSize = (MeasuredWidth.Size == widthMeasureSpec.Size) &&
-                                   (MeasuredHeight.Size == heightMeasureSpec.Size);
+                (MeasuredHeight.Size == heightMeasureSpec.Size);
 
             bool needsLayout = specChanged && (!isSpecExactly || !matchesSpecSize);
             needsLayout = needsLayout || ((Flags & LayoutFlags.ForceLayout) == LayoutFlags.ForceLayout);
@@ -235,10 +241,40 @@ namespace Tizen.NUI
         /// <since_tizen> 6 </since_tizen>
         public void Layout(LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
         {
-            bool changed = SetFrame(left.AsRoundedValue(),
-                                    top.AsRoundedValue(),
-                                    right.AsRoundedValue(),
-                                    bottom.AsRoundedValue());
+            Layout(left, top, right, bottom, false);
+        }
+
+        /// <summary>
+        /// Assign a size and position to a layout and all of its descendants. <br />
+        /// This is the second phase of the layout mechanism.  (The first is measuring). In this phase, each parent
+        /// calls layout on all of its children to position them.  This is typically done using the child<br />
+        /// measurements that were stored in the measure pass.<br />
+        /// </summary>
+        /// <param name="left">Left position, relative to parent.</param>
+        /// <param name="top">Top position, relative to parent.</param>
+        /// <param name="right">Right position, relative to parent.</param>
+        /// <param name="bottom">Bottom position, relative to parent.</param>
+        /// <param name="independent">true, if this layout is not affected by parent layout.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void Layout(LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom, bool independent)
+        {
+            bool changed = true;
+            if (!independent)
+            {
+                changed = SetFrame(left.AsRoundedValue(),
+                    top.AsRoundedValue(),
+                    right.AsRoundedValue(),
+                    bottom.AsRoundedValue());
+            }
+            else
+            {
+                // If height or width specification is not explicitly defined,
+                // the size of the owner view must be reset even the ExcludeLayouting is false.
+                if (Owner.HeightSpecification < 0 || Owner.WidthSpecification < 0)
+                {
+                    Owner.SetSize(right.AsRoundedValue() - left.AsRoundedValue(), bottom.AsRoundedValue() - top.AsRoundedValue());
+                }
+            }
 
             // Check if Measure needed before Layouting
             if (changed || ((Flags & LayoutFlags.LayoutRequired) == LayoutFlags.LayoutRequired))
@@ -317,8 +353,8 @@ namespace Tizen.NUI
             Flags = Flags | LayoutFlags.ForceLayout;
             if (Parent != null)
             {
-                LayoutGroup layoutGroup = Parent as LayoutGroup;
-                if (!layoutGroup.LayoutRequested)
+                LayoutGroup layoutGroup =  Parent as LayoutGroup;
+                if (layoutGroup != null && !layoutGroup.LayoutRequested)
                 {
                     layoutGroup.RequestLayout();
                 }
@@ -513,41 +549,35 @@ namespace Tizen.NUI
         /// <param name="right">Right position, relative to parent.</param>
         /// <param name="bottom">Bottom position, relative to parent.</param>
         /// <since_tizen> 6 </since_tizen>
-        protected virtual void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
-        {
-        }
+        protected virtual void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom) { }
 
         /// <summary>
         /// Virtual method to allow derived classes to remove any children before it is removed from
         /// its parent.
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
-        protected virtual void OnUnparent()
-        {
-        }
+        protected virtual void OnUnparent() { }
 
         /// <summary>
         /// Virtual method called when this Layout is attached to it's owner.
         /// Allows derived layouts to take ownership of child Views and connect to any Owner signals required.
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
-        protected virtual void OnAttachedToOwner()
-        {
-        }
+        protected virtual void OnAttachedToOwner() { }
 
         private bool SetFrame(float left, float top, float right, float bottom)
         {
             bool changed = false;
 
-            if (layoutPositionData.Left != left ||
-                 layoutPositionData.Right != right ||
-                 layoutPositionData.Top != top ||
-                 layoutPositionData.Bottom != bottom)
+            if (_layoutPositionData.Left != left ||
+                 _layoutPositionData.Right != right ||
+                 _layoutPositionData.Top != top ||
+                 _layoutPositionData.Bottom != bottom)
             {
                 changed = true;
 
-                float oldWidth = layoutPositionData.Right - layoutPositionData.Left;
-                float oldHeight = layoutPositionData.Bottom - layoutPositionData.Top;
+                float oldWidth = _layoutPositionData.Right - _layoutPositionData.Left;
+                float oldHeight = _layoutPositionData.Bottom - _layoutPositionData.Top;
                 float newWidth = right - left;
                 float newHeight = bottom - top;
                 bool sizeChanged = (newWidth != oldWidth) || (newHeight != oldHeight);
@@ -559,52 +589,32 @@ namespace Tizen.NUI
                 }
 
                 // Store new layout position data
-                layoutPositionData = new LayoutData(this, ConditionForAnimation, left, top, right, bottom);
+                _layoutPositionData = new LayoutData(this, ConditionForAnimation, left, top, right, bottom);
 
-                Debug.WriteLineIf(LayoutDebugFrameData, "LayoutItem FramePositionData View:" + layoutPositionData.Item.Owner.Name +
-                                                         " left:" + layoutPositionData.Left +
-                                                         " top:" + layoutPositionData.Top +
-                                                         " right:" + layoutPositionData.Right +
-                                                         " bottom:" + layoutPositionData.Bottom);
+                Debug.WriteLineIf(LayoutDebugFrameData, "LayoutItem FramePositionData View:" + _layoutPositionData.Item.Owner.Name +
+                                                         " left:" + _layoutPositionData.Left +
+                                                         " top:" + _layoutPositionData.Top +
+                                                         " right:" + _layoutPositionData.Right +
+                                                         " bottom:" + _layoutPositionData.Bottom);
 
                 if (Owner.Parent != null && Owner.Parent.Layout != null && Owner.Parent.Layout.LayoutWithTransition)
                 {
-                    NUIApplication.GetDefaultWindow().LayoutController.AddTransitionDataEntry(layoutPositionData);
+                    NUIApplication.GetDefaultWindow().LayoutController.AddTransitionDataEntry(_layoutPositionData);
                 }
                 else
                 {
-                    Owner.SetSize(right - left, bottom - top, Owner.Position.Z);
-                    if (SetPositionByLayout)
+                    if (Owner.Position != null)
                     {
-                        Owner.SetPosition(left, top, Owner.Position.Z);
+                        Owner.SetSize(right - left, bottom - top);
+                        Owner.SetPosition(left, top);
                     }
                 }
 
-
                 // Reset condition for animation ready for next transition when required.
                 ConditionForAnimation = TransitionCondition.Unspecified;
             }
 
             return changed;
         }
-
-        /// <summary>
-        /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
-        /// </summary>
-        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        protected override void Dispose(DisposeTypes type)
-        {
-            if (disposed)
-            {
-                return;
-            }
-
-            margin?.Dispose();
-            padding?.Dispose();
-            Owner?.Dispose();
-
-            base.Dispose();
-        }
     }
 }