[Tizen][API10] Add WebView APIs for fullscreen, text found, etc.
authorhuayong.xu <huayong.xu@samsung.com>
Mon, 16 Oct 2023 02:46:38 +0000 (10:46 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 16 Oct 2023 07:57:20 +0000 (16:57 +0900)
src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs
src/Tizen.NUI/src/internal/WebView/WebViewPolicyDecidedEventArgs.cs
src/Tizen.NUI/src/internal/WebView/WebViewTextFoundEventArgs.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/WebView/WebView.cs

index 01c7d10..0235d7c 100755 (executable)
@@ -216,6 +216,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_ClearHistory")]
             public static extern void ClearHistory(global::System.Runtime.InteropServices.HandleRef jarg1);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_ExitFullscreen")]
+            public static extern void ExitFullscreen(global::System.Runtime.InteropServices.HandleRef jarg1);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_SetScaleFactor")]
             public static extern void SetScaleFactor(global::System.Runtime.InteropServices.HandleRef jarg1, float jarg2, global::System.Runtime.InteropServices.HandleRef jarg3);
 
@@ -292,6 +295,9 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterNavigationPolicyDecidedCallback")]
             public static extern void RegisterNavigationPolicyDecidedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterNewWindowPolicyDecidedCallback")]
+            public static extern void RegisterNewWindowPolicyDecidedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterNewWindowCreatedCallback")]
             public static extern void RegisterNewWindowCreatedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
@@ -310,6 +316,15 @@ namespace Tizen.NUI
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterContextMenuHiddenCallback")]
             public static extern void RegisterContextMenuHiddenCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
 
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterFullscreenEnteredCallback")]
+            public static extern void RegisterFullscreenEnteredCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterFullscreenExitedCallback")]
+            public static extern void RegisterFullscreenExitedCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_RegisterTextFoundCallback")]
+            public static extern void RegisterTextFoundCallback(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2);
+
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_GetPlainTextAsynchronously")]
             public static extern void GetPlainTextAsynchronously(global::System.Runtime.InteropServices.HandleRef webViewRef, global::System.Runtime.InteropServices.HandleRef callbackRef);
         }
index 43e719b..43ed244 100755 (executable)
@@ -21,20 +21,33 @@ using System.ComponentModel;
 namespace Tizen.NUI
 {
     /// <summary>
-    /// Event arguments that passed via the WebView.ResponsePolicyDecided.
+    /// Event arguments that passed via the WebView.ResponsePolicyDecided,
+    /// WebView.NavigationPolicyDecided or WebView.NewWindowPolicyDecided.
     /// </summary>
     [EditorBrowsable(EditorBrowsableState.Never)]
     public class WebViewPolicyDecidedEventArgs : EventArgs
     {
         internal WebViewPolicyDecidedEventArgs(WebPolicyDecisionMaker maker)
         {
-            ResponsePolicyDecisionMaker = maker;
+            PolicyDecisionMaker = maker;
         }
 
         /// <summary>
-        /// The response policy decision maker.
+        /// Deprecated. The response policy decision maker.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public WebPolicyDecisionMaker ResponsePolicyDecisionMaker { get; }
+        public WebPolicyDecisionMaker ResponsePolicyDecisionMaker
+        {
+            get
+            {
+                return PolicyDecisionMaker;
+            }
+        }
+
+        /// <summary>
+        /// The policy decision maker.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public WebPolicyDecisionMaker PolicyDecisionMaker { get; }
     }
 }
diff --git a/src/Tizen.NUI/src/internal/WebView/WebViewTextFoundEventArgs.cs b/src/Tizen.NUI/src/internal/WebView/WebViewTextFoundEventArgs.cs
new file mode 100755 (executable)
index 0000000..8c76f04
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System;
+using System.ComponentModel;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// Event arguments that passed via the WebView.TextFound.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class WebViewTextFoundEventArgs : EventArgs
+    {
+        internal WebViewTextFoundEventArgs(uint count)
+        {
+            Count = count;
+        }
+
+        /// <summary>
+        /// The count of text found.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public uint Count { get; }
+    }
+}
index 5c3fab1..62bce76 100755 (executable)
@@ -73,6 +73,9 @@ namespace Tizen.NUI.BaseComponents
         private EventHandler<WebViewPolicyDecidedEventArgs> navigationPolicyDecidedEventHandler;
         private WebViewPolicyDecidedCallback navigationPolicyDecidedCallback;
 
+        private EventHandler<WebViewPolicyDecidedEventArgs> newWindowPolicyDecidedEventHandler;
+        private WebViewPolicyDecidedCallback newWindowPolicyDecidedCallback;
+
         private EventHandlerWithReturnType<object, EventArgs, WebView> newWindowCreatedEventHandler;
         private WebViewNewWindowCreatedCallback newWindowCreatedCallback;
 
@@ -94,8 +97,16 @@ namespace Tizen.NUI.BaseComponents
         private EventHandler<WebViewContextMenuHiddenEventArgs> contextMenuHiddenEventHandler;
         private WebViewContextMenuHiddenCallback contextMenuHiddenCallback;
 
-        private PlainTextReceivedCallback plainTextReceivedCallback;
+        private EventHandler<EventArgs> fullscreenEnteredEventHandler;
+        private WebViewFullscreenEnteredCallback fullscreenEnteredCallback;
 
+        private EventHandler<EventArgs> fullscreenExitedEventHandler;
+        private WebViewFullscreenExitedCallback fullscreenExitedCallback;
+
+        private EventHandler<WebViewTextFoundEventArgs> textFoundEventHandler;
+        private WebViewTextFoundCallback textFoundCallback;
+
+        private PlainTextReceivedCallback plainTextReceivedCallback;
 
         /// <summary>
         /// Creates a WebView.
@@ -285,6 +296,15 @@ namespace Tizen.NUI.BaseComponents
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void WebViewContextMenuHiddenCallback(IntPtr menu);
 
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void WebViewFullscreenEnteredCallback();
+
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void WebViewFullscreenExitedCallback();
+
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void WebViewTextFoundCallback(uint count);
+
         /// <summary>
         /// Event for the PageLoadStarted signal which can be used to subscribe or unsubscribe the event handler.<br />
         /// This signal is emitted when page loading has started.<br />
@@ -566,6 +586,34 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Event for the NewWindowPolicyDecided signal which can be used to subscribe or unsubscribe the event handler.<br />
+        /// This signal is emitted when new window policy would be decided.<br />
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<WebViewPolicyDecidedEventArgs> NewWindowPolicyDecided
+        {
+            add
+            {
+                if (newWindowPolicyDecidedEventHandler == null)
+                {
+                    newWindowPolicyDecidedCallback = OnNewWindowPolicyDecided;
+                    IntPtr ip = Marshal.GetFunctionPointerForDelegate(newWindowPolicyDecidedCallback);
+                    Interop.WebView.RegisterNewWindowPolicyDecidedCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+                newWindowPolicyDecidedEventHandler += value;
+            }
+            remove
+            {
+                newWindowPolicyDecidedEventHandler -= value;
+                if (newWindowPolicyDecidedEventHandler == null)
+                {
+                    IntPtr ip = IntPtr.Zero;
+                    Interop.WebView.RegisterNewWindowPolicyDecidedCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+            }
+        }
+
+        /// <summary>
         /// Event for the NewWindowCreated signal which can be used to subscribe or unsubscribe the event handler.<br />
         /// This signal is emitted when a new window would be created.<br />
         /// </summary>
@@ -762,6 +810,90 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Event for the FullscreenEntered signal which can be used to subscribe or unsubscribe the event handler.<br />
+        /// This signal is emitted when fullscreen is entered.<br />
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<EventArgs> FullscreenEntered
+        {
+            add
+            {
+                if (fullscreenEnteredEventHandler == null)
+                {
+                    fullscreenEnteredCallback = OnFullscreenEntered;
+                    IntPtr ip = Marshal.GetFunctionPointerForDelegate(fullscreenEnteredCallback);
+                    Interop.WebView.RegisterFullscreenEnteredCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+                fullscreenEnteredEventHandler += value;
+            }
+            remove
+            {
+                fullscreenEnteredEventHandler -= value;
+                if (fullscreenEnteredEventHandler == null)
+                {
+                    IntPtr ip = IntPtr.Zero;
+                    Interop.WebView.RegisterFullscreenEnteredCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+            }
+        }
+
+        /// <summary>
+        /// Event for the FullscreenExited signal which can be used to subscribe or unsubscribe the event handler.<br />
+        /// This signal is emitted when fullscreen is exited.<br />
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<EventArgs> FullscreenExited
+        {
+            add
+            {
+                if (fullscreenExitedEventHandler == null)
+                {
+                    fullscreenExitedCallback = OnFullscreenExited;
+                    IntPtr ip = Marshal.GetFunctionPointerForDelegate(fullscreenExitedCallback);
+                    Interop.WebView.RegisterFullscreenExitedCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+                fullscreenExitedEventHandler += value;
+            }
+            remove
+            {
+                fullscreenExitedEventHandler -= value;
+                if (fullscreenExitedEventHandler == null)
+                {
+                    IntPtr ip = IntPtr.Zero;
+                    Interop.WebView.RegisterFullscreenExitedCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+            }
+        }
+
+        /// <summary>
+        /// Event for the TextFound signal which can be used to subscribe or unsubscribe the event handler.<br />
+        /// This signal is emitted when text is found.<br />
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public event EventHandler<WebViewTextFoundEventArgs> TextFound
+        {
+            add
+            {
+                if (textFoundEventHandler == null)
+                {
+                    textFoundCallback = OnTextFound;
+                    IntPtr ip = Marshal.GetFunctionPointerForDelegate(textFoundCallback);
+                    Interop.WebView.RegisterTextFoundCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+                textFoundEventHandler += value;
+            }
+            remove
+            {
+                textFoundEventHandler -= value;
+                if (textFoundEventHandler == null)
+                {
+                    IntPtr ip = IntPtr.Zero;
+                    Interop.WebView.RegisterTextFoundCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+            }
+        }
+
+        /// <summary>
         /// Options for searching texts.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
@@ -2023,6 +2155,16 @@ namespace Tizen.NUI.BaseComponents
         }
 
         /// <summary>
+        /// Exit fullscreen.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void ExitFullscreen()
+        {
+            Interop.WebView.ExitFullscreen(SwigCPtr);
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+        }
+
+        /// <summary>
         /// Scales the current page, centered at the given point.
         /// </summary>
         /// <param name="scaleFactor">The new factor to be scaled</param>
@@ -2294,6 +2436,11 @@ namespace Tizen.NUI.BaseComponents
             navigationPolicyDecidedEventHandler?.Invoke(this, new WebViewPolicyDecidedEventArgs(new WebPolicyDecisionMaker(maker, true)));
         }
 
+        private void OnNewWindowPolicyDecided(IntPtr maker)
+        {
+            newWindowPolicyDecidedEventHandler?.Invoke(this, new WebViewPolicyDecidedEventArgs(new WebPolicyDecisionMaker(maker, true)));
+        }
+
         private void OnNewWindowCreated(out IntPtr viewHandle)
         {
             WebView view = newWindowCreatedEventHandler?.Invoke(this, new EventArgs());
@@ -2336,5 +2483,20 @@ namespace Tizen.NUI.BaseComponents
             hitTestFinishedCallback?.Invoke(new WebHitTestResult(test, true));
 #pragma warning restore CA2000 // Dispose objects before losing scope
         }
+
+        private void OnFullscreenEntered()
+        {
+            fullscreenEnteredEventHandler?.Invoke(this, new EventArgs());
+        }
+
+        private void OnFullscreenExited()
+        {
+            fullscreenExitedEventHandler?.Invoke(this, new EventArgs());
+        }
+
+        private void OnTextFound(uint count)
+        {
+            textFoundEventHandler?.Invoke(this, new WebViewTextFoundEventArgs(count));
+        }
     }
 }