[NUI] Fix ControlState issues. (#1563)
authorJiyun Yang <ji.yang@samsung.com>
Fri, 24 Apr 2020 03:16:39 +0000 (12:16 +0900)
committerGitHub <noreply@github.com>
Fri, 24 Apr 2020 03:16:39 +0000 (12:16 +0900)
* Fix ControlState propagation to false.
* Fix typo in class name : ControlStateChagedInfo -> ControlStateChangedInfo
* Enhance ControlStateChangeInfo to have InputMethod property.
* Remove combined ControlState handling in Selector: It needs to be well-designed first.
* Fix test/Tizen.NUI.Samples compile errors.

Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
src/Tizen.NUI.Components/Controls/Button.cs
src/Tizen.NUI.Components/Controls/Slider.cs
src/Tizen.NUI.Components/Controls/Tab.cs
src/Tizen.NUI/src/public/BaseComponents/Style/Selector.cs
src/Tizen.NUI/src/public/BaseComponents/TextLabel.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs
src/Tizen.NUI/src/public/BaseComponents/ViewInternal.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CheckBoxSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Tizen.NUI.Samples.csproj

index aa397c0..9b14e73 100755 (executable)
@@ -884,14 +884,22 @@ namespace Tizen.NUI.Components
 
             if (isEnabled)
             {
-                // Normal
-                targetState = ControlStates.Normal;
+                if (isPressed)
+                {
+                    // Pressed
+                    targetState = ControlStates.Pressed;
+                }
+                else
+                {
+                    // Normal
+                    targetState = ControlStates.Normal;
 
-                // Selected
-                targetState |= (IsSelected ? ControlStates.Selected : 0);
+                    // Selected
+                    targetState |= (IsSelected ? ControlStates.Selected : 0);
 
-                // Pressed, PressedSelected, Focused, SelectedFocused
-                targetState |= (isPressed ? ControlStates.Pressed : (IsFocused ? ControlStates.Focused : 0));
+                    // Focused, SelectedFocused
+                    targetState |= (IsFocused ? ControlStates.Focused : 0);
+                }
             }
             else
             {
@@ -929,6 +937,8 @@ namespace Tizen.NUI.Components
 
             CreateComponents();
 
+            EnableControlStatePropagation = true;
+
             if (ButtonOverlayImage != null)
             {
                 Add(ButtonOverlayImage);
index 2973c1c..76733e6 100755 (executable)
@@ -849,6 +849,8 @@ namespace Tizen.NUI.Components
             {
                 CreateThumb();
             }
+
+            EnableControlStatePropagation = true;
         }
 
         private void Initialize()
index 892be3e..0cb441e 100755 (executable)
@@ -691,6 +691,8 @@ namespace Tizen.NUI.Components
                     VerticalAlignment = VerticalAlignment.Center
                 };
                 Add(TextItem);
+
+                EnableControlStatePropagation = true;
             }
 
             internal int Index
index 558fc89..add26fe 100755 (executable)
@@ -193,15 +193,7 @@ namespace Tizen.NUI.BaseComponents
                     return SelectedFocused != null ? SelectedFocused : (Selected != null ? Selected : Other);
                 default:
                 {
-                    // Handle combined states
-                    if ((int)(state & ControlStates.Selected) != 0 && Selected != null)
-                    {
-                        return Selected;
-                    }
-                    else if ((int)(state & ControlStates.Pressed) != 0 && Pressed != null)
-                    {
-                        return Pressed;
-                    }
+                    // TODO Handle combined states
                     return Other;
                 }
             }
@@ -256,7 +248,7 @@ namespace Tizen.NUI.BaseComponents
         {
             targetView = view;
             targetBindableProperty = bindableProperty;
-            view.ControlStateChangeEvent += OnViewControlState;
+            view.ControlStateChangeEventInternal += OnViewControlState;
         }
 
         /// <summary>
@@ -275,7 +267,7 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        private void OnViewControlState(View obj, View.ControlStateChagedInfo controlStateChangedInfo)
+        private void OnViewControlState(View obj, View.ControlStateChangedInfo controlStateChangedInfo)
         {
             if (null != obj && null != GetValue(controlStateChangedInfo.CurrentState))
             {
@@ -336,8 +328,8 @@ namespace Tizen.NUI.BaseComponents
 
             if (hadMultiValue != HasMultiValue())
             {
-                if (hadMultiValue) view.ControlStateChangeEvent -= controlStateChanged;
-                else view.ControlStateChangeEvent += controlStateChanged;
+                if (hadMultiValue) view.ControlStateChangeEventInternal -= controlStateChanged;
+                else view.ControlStateChangeEventInternal += controlStateChanged;
             }
         }
 
@@ -357,7 +349,7 @@ namespace Tizen.NUI.BaseComponents
         {
             if (HasMultiValue())
             {
-                view.ControlStateChangeEvent -= controlStateChanged;
+                view.ControlStateChangeEventInternal -= controlStateChanged;
             }
             selector = null;
         }
index 35f38a3..f87721d 100755 (executable)
@@ -1583,7 +1583,7 @@ namespace Tizen.NUI.BaseComponents
             TextShadow = instance;
         }
 
-        private void OnControlStateChangedForShadow(View obj, ControlStateChagedInfo controlStateChangedInfo)
+        private void OnControlStateChangedForShadow(View obj, ControlStateChangedInfo controlStateChangedInfo)
         {
             UpdateTextShadowVisual();
         }
index 77a944a..fac5d60 100755 (executable)
@@ -60,6 +60,7 @@ namespace Tizen.NUI.BaseComponents
         private Dictionary<string, Transition> transDictionary = new Dictionary<string, Transition>();
         private string[] transitionNames;
         private BackgroundExtraData backgroundExtraData;
+        private bool controlStatePropagation = false;
 
         internal Size2D sizeSetExplicitly = new Size2D(); // Store size set by API, will be used in place of NaturalSize if not set.
 
@@ -163,8 +164,19 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        internal delegate void ControlStateChangesDelegate(View obj, ControlStateChagedInfo controlStateChangedInfo);
-        internal event ControlStateChangesDelegate ControlStateChangeEvent;
+        /// <summary>
+        /// The delegate for ControlState changed event.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public delegate void ControlStateChangesDelegate(View obj, ControlStateChangedInfo controlStateChangedInfo);
+
+        /// <summary>
+        /// The event that is triggered when the View's ControlState is changed.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event ControlStateChangesDelegate ControlStateChangeEvent;
+
+        internal event ControlStateChangesDelegate ControlStateChangeEventInternal;
 
         private ControlStates controlStates;
         /// <summary>
@@ -202,11 +214,13 @@ namespace Tizen.NUI.BaseComponents
 
             controlStates = state;
 
-            var changeInfo = new ControlStateChagedInfo(prevState, state, touchInfo);
+            var changeInfo = new ControlStateChangedInfo(prevState, state, ControlStateChangedInfo.InputMethodType.Touch, touchInfo);
 
-            ControlStateChangeEvent?.Invoke(this, changeInfo);
+            ControlStateChangeEventInternal?.Invoke(this, changeInfo);
+
+            OnControlStateChanged(changeInfo);
 
-            if (OnControlStateChanged(changeInfo))
+            if (controlStatePropagation)
             {
                 foreach (View child in Children)
                 {
@@ -214,6 +228,8 @@ namespace Tizen.NUI.BaseComponents
                 }
             }
 
+            ControlStateChangeEvent?.Invoke(this, changeInfo);
+
             return true;
         }
 
@@ -2297,6 +2313,27 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Enable/Disable ControlState propagation for children.
+        /// It is false by default.
+        /// If the View needs to share ControlState with descendants, please set it true.
+        /// Please note that, changing the value will also changes children's EnableControlStatePropagation value recursively.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool EnableControlStatePropagation
+        {
+            get => controlStatePropagation;
+            set
+            {
+                controlStatePropagation = value;
+
+                foreach (View child in Children)
+                {
+                    child.EnableControlStatePropagation = value;
+                }
+            }
+        }
+
+        /// <summary>
         /// Get Style, it is abstract function and must be override.
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
@@ -2311,12 +2348,9 @@ namespace Tizen.NUI.BaseComponents
         /// Called after the View's ControlStates changed.
         /// </summary>
         /// <param name="controlStateChangedInfo">The information including state changed variables.</param>
-        /// <return>True if it needs to apply the state to children recursively.</return>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        protected virtual bool OnControlStateChanged(ControlStateChagedInfo controlStateChangedInfo)
+        protected virtual void OnControlStateChanged(ControlStateChangedInfo controlStateChangedInfo)
         {
-            //If need to apply the state to all child, return true;
-            return true;
         }
 
         internal static readonly BindableProperty BackgroundImageSelectorProperty = BindableProperty.Create("BackgroundImageSelector", typeof(Selector<string>), typeof(View), null, propertyChanged: (bindable, oldValue, newValue) =>
index 7c5b557..6653d85 100755 (executable)
@@ -1059,35 +1059,77 @@ namespace Tizen.NUI.BaseComponents
         /// <summary>
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public class ControlStateChagedInfo
+        public class ControlStateChangedInfo
         {
             /// <summary>
             /// The previous control state.
             /// </summary>
-            public ControlStateChagedInfo(ControlStates previousState, ControlStates currentState, Touch touch)
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public ControlStateChangedInfo(ControlStates previousState, ControlStates currentState, InputMethodType inputMethod, object inputData)
             {
                 PreviousState = previousState;
                 CurrentState = currentState;
-                Touch = touch;
+                InputMethod = inputMethod;
+                InputData = inputData;
             }
 
             /// <summary>
             /// The previous control state.
             /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
             public ControlStates PreviousState { get; }
 
             /// <summary>
             /// The current control state.
             /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
             public ControlStates CurrentState { get; }
 
             /// <summary>
-            /// The touch information in case the state has changed by touching.
+            /// Indicates the input method that triggered this change.
             /// </summary>
-            /// <remarks>
-            /// The value is null if it is not the case.
-            /// </remarks>
-            public Touch Touch { get; }
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public InputMethodType InputMethod { get; }
+
+            /// <summary>
+            /// The input method data in detail.
+            ///
+            /// The type of data depends on the InputMethod,
+            /// ---------------------------------------
+            ///  InputMethod    |   Typep of InputData
+            /// ---------------------------------------
+            ///  None           |   (null)
+            ///  Touch          |   Tizen.NUI.Touch
+            ///  Key            |   Tizen.NUI.Key
+            /// ---------------------------------------
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public object InputData { get; }
+
+            /// <summary>
+            /// List of input method that can trigger ControlStates change.
+            /// </summary>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public enum InputMethodType
+            {
+                /// <summary>
+                /// ControlState has changed without user input.
+                /// </summary>
+                [EditorBrowsable(EditorBrowsableState.Never)]
+                None,
+
+                /// <summary>
+                /// ControlState has changed by a touch.
+                /// </summary>
+                [EditorBrowsable(EditorBrowsableState.Never)]
+                Touch,
+
+                /// <summary>
+                /// ControlState has changed by key input.
+                /// </summary>
+                [EditorBrowsable(EditorBrowsableState.Never)]
+                Key,
+            }
         }
 
         private EventHandlerWithReturnType<object, WheelEventArgs, bool> WindowWheelEventHandler;
index a784ee4..96cd06d 100755 (executable)
@@ -1259,7 +1259,7 @@ namespace Tizen.NUI.BaseComponents
             SizeModeFactor = new Vector3(x, y, z);
         }
 
-        private void OnControlStateChangedForShadow(View obj, ControlStateChagedInfo controlStateChangedInfo)
+        private void OnControlStateChangedForShadow(View obj, ControlStateChangedInfo controlStateChangedInfo)
         {
             var boxShadowSelector = (Selector<Shadow>)GetValue(BoxShadowSelectorProperty);
 
@@ -1298,7 +1298,7 @@ namespace Tizen.NUI.BaseComponents
 
         private void UpdateShadow(ShadowBase shadow, bool needToListenStateChanged)
         {
-            ControlStateChangeEvent -= OnControlStateChangedForShadow;
+            ControlStateChangeEventInternal -= OnControlStateChangedForShadow;
 
             if (shadow == null)
             {
@@ -1311,11 +1311,11 @@ namespace Tizen.NUI.BaseComponents
 
             if (needToListenStateChanged)
             {
-                ControlStateChangeEvent += OnControlStateChangedForShadow;
+                ControlStateChangeEventInternal += OnControlStateChangedForShadow;
             }
         }
 
-        private void OnControlStateChangedForCornerRadius(View obj, ControlStateChagedInfo controlStateChangedInfo)
+        private void OnControlStateChangedForCornerRadius(View obj, ControlStateChangedInfo controlStateChangedInfo)
         {
             var selector = (Selector<float?>)GetValue(CornerRadiusSelectorProperty);
 
@@ -1334,11 +1334,11 @@ namespace Tizen.NUI.BaseComponents
 
         private void UpdateCornerRadius(float value, bool needToListenStateChanged)
         {
-            ControlStateChangeEvent -= OnControlStateChangedForCornerRadius;
+            ControlStateChangeEventInternal -= OnControlStateChangedForCornerRadius;
 
             if (needToListenStateChanged)
             {
-                ControlStateChangeEvent += OnControlStateChangedForCornerRadius;
+                ControlStateChangeEventInternal += OnControlStateChangedForCornerRadius;
             }
 
             if (value != 0)
index ab766d4..11af1dc 100755 (executable)
@@ -417,7 +417,7 @@ namespace Tizen.NUI.Samples
                 createText[1].Dispose();
                 createText[1] = null;
 
-                window.Remove(root);
+                NUIApplication.GetDefaultWindow().Remove(root);
                 root.Dispose();
             }
         }
index bc471b2..865c32e 100755 (executable)
@@ -33,6 +33,7 @@
     <ProjectReference Include="../../../src/Tizen.System.SystemSettings/Tizen.System.SystemSettings.csproj" />
     <ProjectReference Include="../../../src/Tizen.NUI/Tizen.NUI.csproj" />
     <ProjectReference Include="../../../src/Tizen.NUI.Components/Tizen.NUI.Components.csproj" />
+    <ProjectReference Include="../../../src/Tizen.NUI.Wearable/Tizen.NUI.Wearable.csproj" />
   </ItemGroup>
 
 </Project>