[NUI] Add DispatchHoverEvents and DispatchPrentHoverEvents
authorjoogab.yun <joogab.yun@samsung.com>
Wed, 14 Jun 2023 07:20:38 +0000 (16:20 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 14 Jun 2023 07:16:58 +0000 (16:16 +0900)
If DispatchHoverEvents sets false, view will not receive any HoverEvent including own.
If DispatchPrentHoverEvents sets false, the parent view does not receive HoverEvent.

src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/BaseComponents/ViewEvent.cs

index fa6392e..652211e 100755 (executable)
@@ -81,6 +81,8 @@ namespace Tizen.NUI.BaseComponents
         private int configGestureCount = 0;
         private bool dispatchTouchEvents = true;
         private bool dispatchParentTouchEvents = true;
+        private bool dispatchHoverEvents = true;
+        private bool dispatchParentHoverEvents = true;
         private bool dispatchGestureEvents = true;
         private bool dispatchParentGestureEvents = true;
         private string internalName = string.Empty;
@@ -3546,6 +3548,80 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Gets or sets the status of whether hover events can be dispatched.
+        /// If a View's DispatchHoverEvents is set to false, then it's can not will receive hover event and parents will not receive a hover event signal either.
+        /// This works without adding a HoverEvent callback in the View.
+        /// <note>
+        /// If the <see cref="Tizen.NUI.BaseComponents.View.Sensitive"/> is a property that determines whether or not to be hittable, then this property prevents the propagation of the hit hover event.
+        /// </note>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool DispatchHoverEvents
+        {
+            get
+            {
+                return dispatchHoverEvents;
+            }
+            set
+            {
+                if (dispatchHoverEvents != value)
+                {
+                    dispatchHoverEvents = value;
+                    if (dispatchHoverEvents == false)
+                    {
+                        HoverEvent += OnDispatchHoverEvent;
+                    }
+                    else
+                    {
+                        HoverEvent -= OnDispatchHoverEvent;
+                    }
+                }
+            }
+        }
+
+        private bool OnDispatchHoverEvent(object source, View.HoverEventArgs e)
+        {
+            return true;
+        }
+
+        /// <summary>
+        /// Gets or sets the status of whether hover events can be dispatched to the parent.
+        /// If a View's DispatchParentHoverEvents is set to false, then parents will not receive a hover event signal either.
+        /// This works without adding a HoverEvent callback in the View.
+        /// <note>
+        /// If the <see cref="Tizen.NUI.BaseComponents.View.Sensitive"/> is a property that determines whether or not to be hittable, then this property prevents the propagation of the hit hover event.
+        /// </note>
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool DispatchParentHoverEvents
+        {
+            get
+            {
+                return dispatchParentHoverEvents;
+            }
+            set
+            {
+                if (dispatchParentHoverEvents != value)
+                {
+                    dispatchParentHoverEvents = value;
+                    if (dispatchParentHoverEvents == false)
+                    {
+                        HoverEvent += OnDispatchParentHoverEvent;
+                    }
+                    else
+                    {
+                        HoverEvent -= OnDispatchParentHoverEvent;
+                    }
+                }
+            }
+        }
+
+        private bool OnDispatchParentHoverEvent(object source, View.HoverEventArgs e)
+        {
+            return true;
+        }
+
+        /// <summary>
         /// Gets or sets the status of whether the view should emit Gesture event signals.
         /// If a View's DispatchGestureEvents is set to false, then itself and parents will not receive all gesture event signals.
         /// The itself and parents does not receive tap, pinch, pan, rotation, or longpress gestures.
index eb0a781..e41cb78 100755 (executable)
@@ -835,15 +835,30 @@ namespace Tizen.NUI.BaseComponents
                 return true;
             }
 
+            if (DispatchHoverEvents == false)
+            {
+                NUILog.Debug("If DispatchHoverEvents is false, it can not dispatch.");
+                return true;
+            }
+
             HoverEventArgs e = new HoverEventArgs();
 
             e.Hover = Tizen.NUI.Hover.GetHoverFromPtr(hoverEvent);
 
+            bool consumed = false;
+
             if (hoverEventHandler != null)
             {
-                return hoverEventHandler(this, e);
+                consumed = hoverEventHandler(this, e);
             }
-            return false;
+
+            if (DispatchParentHoverEvents == false && consumed == false)
+            {
+                NUILog.Debug("If DispatchParentHoverEvents is false, it can not dispatch to parent.");
+                return true;
+            }
+
+            return consumed;
         }
 
         // Callback for View Wheel signal