[NUI] Add interceptTouchEvent at WindowEvent
authorjoogab.yun <joogab.yun@samsung.com>
Mon, 27 Mar 2023 07:47:50 +0000 (16:47 +0900)
committerJoogabYun <40262755+JoogabYun@users.noreply.github.com>
Tue, 28 Mar 2023 05:36:01 +0000 (14:36 +0900)
src/Tizen.NUI/src/public/Window/WindowEvent.cs

index c57765d..d39e376 100755 (executable)
@@ -32,6 +32,7 @@ namespace Tizen.NUI
     {
         private WindowFocusChangedEventCallbackType windowFocusChangedEventCallback;
         private RootLayerTouchDataCallbackType rootLayerTouchDataCallback;
+        private RootLayerTouchDataCallbackType rootLayerInterceptTouchDataCallback;
         private WheelEventCallbackType wheelEventCallback;
         private EventCallbackDelegateType1 stageKeyCallbackDelegate;
         private InterceptKeyEventDelegateType stageInterceptKeyCallbackDelegate;
@@ -136,6 +137,40 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// An event for the touched signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
+        /// The touched signal is emitted when the touch input is received.<br />
+        /// This can receive touch events before child. <br />
+        /// If it returns false, the child can receive the touch event. If it returns true, the touch event is intercepted. So child cannot receive touch event.<br />
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event ReturnTypeEventHandler<object, TouchEventArgs, bool> InterceptTouchEvent
+        {
+            add
+            {
+                if (rootLayerInterceptTouchDataEventHandler == null)
+                {
+                    rootLayerInterceptTouchDataCallback = OnWindowInterceptTouch;
+                    using TouchDataSignal signal = new TouchDataSignal(Interop.ActorSignal.ActorInterceptTouchSignal(Layer.getCPtr(GetRootLayer())), false);
+                    signal?.Connect(rootLayerInterceptTouchDataCallback);
+                }
+                rootLayerInterceptTouchDataEventHandler += value;
+            }
+            remove
+            {
+                rootLayerInterceptTouchDataEventHandler -= value;
+                if (rootLayerInterceptTouchDataEventHandler == null && rootLayerInterceptTouchDataCallback != null)
+                {
+                    using TouchDataSignal signal = new TouchDataSignal(Interop.ActorSignal.ActorInterceptTouchSignal(Layer.getCPtr(GetRootLayer())), false);
+                    signal?.Disconnect(rootLayerInterceptTouchDataCallback);
+                    if (signal?.Empty() == true)
+                    {
+                        rootLayerInterceptTouchDataCallback = null;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
         /// Emits the event when the wheel event is received.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -389,6 +424,7 @@ namespace Tizen.NUI
         public event EventHandler ViewAdded;
         private event EventHandler<FocusChangedEventArgs> windowFocusChangedEventHandler;
         private event EventHandler<TouchEventArgs> rootLayerTouchDataEventHandler;
+        private ReturnTypeEventHandler<object, TouchEventArgs, bool> rootLayerInterceptTouchDataEventHandler;
         private event EventHandler<WheelEventArgs> stageWheelHandler;
         private event EventHandler<KeyEventArgs> stageKeyHandler;
         private ReturnTypeEventHandler<object, KeyEventArgs, bool> stageInterceptKeyHandler;
@@ -544,6 +580,14 @@ namespace Tizen.NUI
                 signal?.Disconnect(rootLayerTouchDataCallback);
                 rootLayerTouchDataCallback = null;
             }
+
+            if (rootLayerInterceptTouchDataCallback != null)
+            {
+                using TouchDataSignal signal = new TouchDataSignal(Interop.ActorSignal.ActorInterceptTouchSignal(Layer.getCPtr(GetRootLayer())), false);
+                signal?.Disconnect(rootLayerInterceptTouchDataCallback);
+                rootLayerInterceptTouchDataCallback = null;
+            }
+
             if (wheelEventCallback != null)
             {
                 using WheelSignal signal = new WheelSignal(Interop.ActorSignal.ActorWheelEventSignal(Layer.getCPtr(this.GetRootLayer())), false);
@@ -669,6 +713,24 @@ namespace Tizen.NUI
             return false;
         }
 
+        private bool OnWindowInterceptTouch(IntPtr view, IntPtr touchData)
+        {
+            if (touchData == global::System.IntPtr.Zero)
+            {
+                NUILog.Error("touchData should not be null!");
+                return true;
+            }
+
+            bool consumed = false;
+            if (rootLayerInterceptTouchDataEventHandler != null)
+            {
+                TouchEventArgs e = new TouchEventArgs();
+                e.Touch = Tizen.NUI.Touch.GetTouchFromPtr(touchData);
+                consumed = rootLayerInterceptTouchDataEventHandler(this, e);
+            }
+            return consumed;
+        }
+
         private bool OnStageWheel(IntPtr rootLayer, IntPtr wheelEvent)
         {
             if (wheelEvent == global::System.IntPtr.Zero)