[NUI][Tizen] Add an API for create,window event.
authorhuayong.xu <huayong.xu@samsung.com>
Thu, 8 Dec 2022 12:08:53 +0000 (20:08 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Fri, 9 Dec 2022 05:47:03 +0000 (14:47 +0900)
src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs
src/Tizen.NUI/src/internal/WebView.cs

index 7e852ab..dd083d0 100755 (executable)
@@ -135,6 +135,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_RegisterNewWindowCreatedCallback")]
+            public static extern void RegisterNewWindowCreatedCallback(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 0894b1b..3bed57e 100755 (executable)
@@ -30,6 +30,20 @@ namespace Tizen.NUI
     [EditorBrowsable(EditorBrowsableState.Never)]
     public class WebView : View
     {
+        /// <summary>
+        /// The callback function that is invoked when the message is received from the script.
+        /// </summary>
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public delegate void JavaScriptMessageHandler(string message);
+
+        /// <summary>
+        /// The callback function that is invoked when the plain text of the current page is received.
+        /// </summary>
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public delegate void PlainTextReceivedCallback(string plainText);
+
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void WebViewPageLoadCallback(string pageUrl);
 
@@ -45,6 +59,9 @@ namespace Tizen.NUI
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void WebViewPolicyDecidedCallback(IntPtr maker);
 
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        private delegate void WebViewNewWindowCreatedCallback(out IntPtr outView);
+
         private EventHandler<WebViewPageLoadEventArgs> pageLoadStartedEventHandler;
         private WebViewPageLoadCallback pageLoadStartedCallback;
 
@@ -63,14 +80,10 @@ namespace Tizen.NUI
         private EventHandler<WebViewPolicyDecidedEventArgs> navigationPolicyDecidedEventHandler;
         private WebViewPolicyDecidedCallback navigationPolicyDecidedCallback;
 
-        private PlainTextReceivedCallback plainTextReceivedCallback;
+        private EventHandlerWithReturnType<object, EventArgs, WebView> newWindowCreatedEventHandler;
+        private WebViewNewWindowCreatedCallback newWindowCreatedCallback;
 
-        /// <summary>
-        /// The callback function that is invoked when the plain text of the current page is received.
-        /// </summary>
-        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public delegate void PlainTextReceivedCallback(string plainText);
+        private PlainTextReceivedCallback plainTextReceivedCallback;
 
         internal WebView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.WebView.WebView_SWIGUpcast(cPtr), cMemoryOwn)
         {
@@ -178,6 +191,12 @@ namespace Tizen.NUI
             navigationPolicyDecidedEventHandler?.Invoke(this, new WebViewPolicyDecidedEventArgs(new WebPolicyDecisionMaker(maker, true)));
         }
 
+        private void OnNewWindowCreated(out IntPtr viewHandle)
+        {
+            WebView view = newWindowCreatedEventHandler?.Invoke(this, new EventArgs());
+            viewHandle = (IntPtr)view.SwigCPtr;
+        }
+
         internal static new class Property
         {
             internal static readonly int URL = Interop.WebView.WebView_Property_URL_get();
@@ -539,6 +558,33 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Gets title of web page.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public string Title
+        {
+            get
+            {
+                return (string)GetValue(TitleProperty);
+            }
+        }
+
+        /// <summary>
+        /// Gets fav icon.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public ImageView Favicon
+        {
+            get
+            {
+                global::System.IntPtr imageView = Interop.WebView.WebView_GetFavicon(swigCPtr);
+                if (imageView == IntPtr.Zero)
+                    return null;
+                return new ImageView(imageView, false);
+            }
+        }
+
+        /// <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 />
         /// </summary>
@@ -669,29 +715,25 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// Gets title of web page.
+        /// 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>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public string Title
+        public event EventHandlerWithReturnType<object, EventArgs, WebView> NewWindowCreated
         {
-            get
+            add
             {
-                return (string)GetValue(TitleProperty);
+                if (newWindowCreatedEventHandler == null)
+                {
+                    newWindowCreatedCallback = OnNewWindowCreated;
+                    System.IntPtr ip = Marshal.GetFunctionPointerForDelegate(newWindowCreatedCallback);
+                    Interop.WebView.RegisterNewWindowCreatedCallback(SwigCPtr, new HandleRef(this, ip));
+                }
+                newWindowCreatedEventHandler += value;
             }
-        }
-
-        /// <summary>
-        /// Gets fav icon.
-        /// </summary>
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public ImageView Favicon
-        {
-            get
+            remove
             {
-                global::System.IntPtr imageView = Interop.WebView.WebView_GetFavicon(swigCPtr);
-                if (imageView == IntPtr.Zero)
-                    return null;
-                return new ImageView(imageView, false);
+                newWindowCreatedEventHandler -= value;
             }
         }
 
@@ -825,13 +867,6 @@ namespace Tizen.NUI
         }
 
         /// <summary>
-        /// The callback function that is invoked when the message is received from the script.
-        /// </summary>
-        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public delegate void JavaScriptMessageHandler(string message);
-
-        /// <summary>
         /// Evaluates JavaScript code represented as a string.
         /// <param name="script">The JavaScript code</param>
         /// </summary>