[NUI] If borderView is in overlay mode, pass the hittest so that the lower layer...
authorjoogab.yun <joogab.yun@samsung.com>
Fri, 10 Jun 2022 03:48:57 +0000 (12:48 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 21 Jun 2022 10:27:08 +0000 (19:27 +0900)
When in overlay mode, the border layer is raised to the top.

In this case, a touch is received from the border layer, and the touch event is not received from the lower root layer.

So let's pass the hittest of the border layer.

src/Tizen.NUI/src/public/Window/BorderWindow.cs
src/Tizen.NUI/src/public/Window/DefaultBorder.cs
src/Tizen.NUI/src/public/Window/IBorderInterface.cs

index c5664cf..3d8a29e 100755 (executable)
@@ -37,11 +37,9 @@ namespace Tizen.NUI
         private Layer borderWindowBottomLayer = null;
         private bool isBorderWindow = false;
 
-        private Color overlayBackgroundColor;
-
         // for border area
         private View rootView = null;
-        private View borderView = null;
+        private BorderView borderView = null;
         private View topView = null;
         private View contentsView = null;
         private View bottomView = null;
@@ -217,14 +215,7 @@ namespace Tizen.NUI
                 // Add a view to the border layer.
                 GetBorderWindowBottomLayer().Add(rootView);
 
-                InterceptTouchEvent += (s, e) =>
-                {
-                    if (e.Touch.GetState(0) == PointStateType.Down && IsMaximized() == false)
-                    {
-                        Raise();
-                    }
-                    return false;
-                };
+                FocusChanged += OnWindowFocusChanged;
 
                 return true;
             }
@@ -235,6 +226,15 @@ namespace Tizen.NUI
             }
         }
 
+        private void OnWindowFocusChanged(object sender, Window.FocusChangedEventArgs e)
+        {
+            if (e.FocusGained == true && IsMaximized() == false)
+            {
+                // Raises the window when the window is focused.
+                Raise();
+            }
+        }
+
         /// Create the border UI.
         private bool CreateBorder()
         {
@@ -246,7 +246,7 @@ namespace Tizen.NUI
             };
 
             ushort padding = (ushort) borderInterface.BorderLineThickness;
-            borderView = new View()
+            borderView = new BorderView()
             {
                 GrabTouchAfterLeave = true,
                 WidthResizePolicy = ResizePolicyType.FillToParent,
@@ -357,27 +357,19 @@ namespace Tizen.NUI
             return direction;
         }
 
-        private void OverlayMode(bool enable)
+        private void DoOverlayMode(bool enable)
         {
             if (borderInterface.OverlayMode == true)
             {
+                borderInterface.OnOverlayMode(enable);
+                borderView?.OverlayMode(enable);
                 if (enable == true)
                 {
-                    if (borderView != null)
-                    {
-                        overlayBackgroundColor = new Color(borderView.BackgroundColor);
-                        borderView.BackgroundColor = Color.Transparent;
-                        borderView.Hide();
-                    }
+                    GetBorderWindowBottomLayer().RaiseToTop();
                 }
                 else
                 {
                     GetBorderWindowBottomLayer().LowerToBottom();
-                    if (borderView != null)
-                    {
-                        borderView.BackgroundColor = overlayBackgroundColor;
-                        borderView.Show();
-                    }
                 }
             }
         }
@@ -423,7 +415,7 @@ namespace Tizen.NUI
                 {
                     contentsView.SizeHeight = resizeHeight - borderHeight - borderInterface.BorderLineThickness * 2;
                 }
-                OverlayMode(true);
+                DoOverlayMode(true);
             }
             else
             {
@@ -435,7 +427,7 @@ namespace Tizen.NUI
                 {
                     contentsView.SizeHeight = resizeHeight;
                 }
-                OverlayMode(false);
+                DoOverlayMode(false);
             }
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) { throw NDalicPINVOKE.SWIGPendingException.Retrieve(); }
@@ -485,10 +477,6 @@ namespace Tizen.NUI
         internal void DisposeBorder()
         {
             Resized -= OnBorderWindowResized;
-            if (borderInterface.OverlayMode == true)
-            {
-                OverlayMode(false);
-            }
             borderInterface.Dispose();
             GetBorderWindowBottomLayer().Dispose();
         }
@@ -520,9 +508,33 @@ namespace Tizen.NUI
         #endregion //Structs
 
         #region Classes
+        // View class for border view.
+        private class BorderView : View
+        {
+            private bool overlayEnabled = false;
+
+            /// <summary>
+            /// Set whether or not it is in overlay mode.
+            /// The borderView's OverlayMode means that it is displayed at the top of the screen.
+            /// In this case, the borderView should pass the event so that lower layers can receive the event.
+            /// </summary>
+            /// <param name="enabled">The true if borderView is Overlay mode. false otherwise.</param>
+            [EditorBrowsable(EditorBrowsableState.Never)]
+            public void OverlayMode(bool enabled)
+            {
+                overlayEnabled = enabled;
+            }
+            
+            protected override bool HitTest(Touch touch)
+            {
+                // If borderView is in overlay mode, pass the hittest.
+                if (overlayEnabled == true)
+                {
+                    return false;
+                }
+                return true;
+            }
+        }
         #endregion //Classes
     }
-
-
-
 }
index aaaa145..e21582f 100755 (executable)
@@ -44,7 +44,7 @@ namespace Tizen.NUI
 
         private const float DefaultHeight = 50;
         private const uint DefaultLineThickness = 5;
-        private const uint DefaultTouchThickness = 20;
+        private const uint DefaultTouchThickness = 0;
         private static readonly Color DefaultBackgroundColor = new Color(1, 1, 1, 0.3f);
         private static readonly Color DefaultClickedBackgroundColor = new Color(1, 1, 1, 0.4f);
         private static readonly Size2D DefaultMinSize = new Size2D(100, 0);
@@ -298,10 +298,33 @@ namespace Tizen.NUI
             {
                 return;
             }
-            this.borderView = borderView;
             borderView.BackgroundColor = DefaultBackgroundColor;
+            borderView.BorderlineColor = new Color(0.5f, 0.5f, 0.5f, 0.3f);
+            borderView.BorderlineWidth = 1.0f;
+            borderView.BorderlineOffset = -1f;
             borderView.CornerRadius = new Vector4(0.03f, 0.03f, 0.03f, 0.03f);
             borderView.CornerRadiusPolicy = VisualTransformPolicyType.Relative;
+
+            // Register touch event for effect when border is touched.
+            borderView.LeaveRequired = true;
+            borderView.TouchEvent += OnBorderViewTouched;
+            this.borderView = borderView;
+        }
+
+        private bool OnBorderViewTouched(object sender, View.TouchEventArgs e)
+        {
+            if (e.Touch.GetState(0) == PointStateType.Started)
+            {
+                backgroundColor = new Color(borderView.BackgroundColor);
+                borderView.BackgroundColor = DefaultClickedBackgroundColor;
+            }
+            else if (e.Touch.GetState(0) == PointStateType.Finished ||
+                     e.Touch.GetState(0) == PointStateType.Leave ||
+                     e.Touch.GetState(0) == PointStateType.Interrupted)
+            {
+                borderView.BackgroundColor = backgroundColor;
+            }
+            return true;
         }
 
         /// Determines the behavior of pinch gesture.
@@ -588,7 +611,6 @@ namespace Tizen.NUI
             }
         }
 
-
         /// <summary>
         /// Called after the border UI is created.
         /// </summary>
@@ -606,28 +628,6 @@ namespace Tizen.NUI
             borderPanGestureDetector.Attach(borderView);
             borderPanGestureDetector.Detected += OnPanGestureDetected;
 
-            // Register touch event for effect when border is touched.
-            borderView.LeaveRequired = true;
-            borderView.TouchEvent += (s, e) =>
-            {
-                if (e.Touch.GetState(0) == PointStateType.Started)
-                {
-                    if (BorderWindow.IsMaximized() == false)
-                    {
-                        BorderWindow.Raise();
-                    }
-                    backgroundColor = new Color(borderView.BackgroundColor);
-                    borderView.BackgroundColor = DefaultClickedBackgroundColor;
-                }
-                else if (e.Touch.GetState(0) == PointStateType.Finished ||
-                         e.Touch.GetState(0) == PointStateType.Leave ||
-                         e.Touch.GetState(0) == PointStateType.Interrupted)
-                {
-                    borderView.BackgroundColor = backgroundColor;
-                }
-                return true;
-            };
-
             borderPinchGestureDetector = new PinchGestureDetector();
             borderPinchGestureDetector.Attach(borderView);
             borderPinchGestureDetector.Detected += OnPinchGestureDetected;
@@ -786,8 +786,6 @@ namespace Tizen.NUI
                 overlayTimer.Stop();
                 overlayTimer.Dispose();
                 overlayTimer = null;
-                BorderWindow?.GetBorderWindowBottomLayer().LowerToBottom();
-                borderView?.Show();
             }
             UpdateIcons();
         }
@@ -813,6 +811,29 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Called when there is a change in overlay mode.
+        /// </summary>
+        /// <param name="enabled">If true, borderView has entered overlayMode.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public virtual void OnOverlayMode(bool enabled)
+        {
+            if (borderView != null && OverlayMode == true)
+            {
+                if (enabled == true)
+                {
+                    backgroundColor = new Color(borderView.BackgroundColor);
+                    borderView.BackgroundColor = Color.Transparent;
+                    borderView.Hide();
+                }
+                else
+                {
+                    borderView.BackgroundColor = backgroundColor;
+                    borderView.Show();
+                }
+            }
+        }
+
+        /// <summary>
         /// Show the border when OverlayMode is true and the window is now Maximize.
         /// </summary>
         /// <param name="time">Time(ms) for borders to disappear again</param>
@@ -827,7 +848,6 @@ namespace Tizen.NUI
                     overlayTimer = new Timer(time);
                     overlayTimer.Tick += (s, e) =>
                     {
-                        BorderWindow.GetBorderWindowBottomLayer().LowerToBottom();
                         borderView?.Hide();
                         overlayTimer?.Stop();
                         overlayTimer?.Dispose();
@@ -835,7 +855,6 @@ namespace Tizen.NUI
                         return false;
                     };
                     overlayTimer.Start();
-                    BorderWindow.GetBorderWindowBottomLayer().RaiseToTop();
                     borderView?.Show();
                 }
                 else
index c7c7152..664170e 100755 (executable)
@@ -136,5 +136,12 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public void OnMinimize(bool isMinimized);
 
+        /// <summary>
+        /// Called when there is a change in overlay mode.
+        /// </summary>
+        /// <param name="enabled">If true, borderView has entered overlayMode.</param>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void OnOverlayMode(bool enabled);
+
     }
 }