From 8b032d2e370771de4410b0b82bfd83025bae3490 Mon Sep 17 00:00:00 2001 From: "huayong.xu" Date: Thu, 8 Dec 2022 20:08:53 +0800 Subject: [PATCH] [NUI][Tizen] Add an API for create,window event. --- .../src/internal/Interop/Interop.WebView.cs | 3 + src/Tizen.NUI/src/internal/WebView.cs | 97 +++++++++++++++------- 2 files changed, 69 insertions(+), 31 deletions(-) diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs index 7e852ab..dd083d0 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs @@ -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); } diff --git a/src/Tizen.NUI/src/internal/WebView.cs b/src/Tizen.NUI/src/internal/WebView.cs index 0894b1b..3bed57e 100755 --- a/src/Tizen.NUI/src/internal/WebView.cs +++ b/src/Tizen.NUI/src/internal/WebView.cs @@ -30,6 +30,20 @@ namespace Tizen.NUI [EditorBrowsable(EditorBrowsableState.Never)] public class WebView : View { + /// + /// The callback function that is invoked when the message is received from the script. + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + [EditorBrowsable(EditorBrowsableState.Never)] + public delegate void JavaScriptMessageHandler(string message); + + /// + /// The callback function that is invoked when the plain text of the current page is received. + /// + [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 pageLoadStartedEventHandler; private WebViewPageLoadCallback pageLoadStartedCallback; @@ -63,14 +80,10 @@ namespace Tizen.NUI private EventHandler navigationPolicyDecidedEventHandler; private WebViewPolicyDecidedCallback navigationPolicyDecidedCallback; - private PlainTextReceivedCallback plainTextReceivedCallback; + private EventHandlerWithReturnType newWindowCreatedEventHandler; + private WebViewNewWindowCreatedCallback newWindowCreatedCallback; - /// - /// The callback function that is invoked when the plain text of the current page is received. - /// - [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 } /// + /// Gets title of web page. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public string Title + { + get + { + return (string)GetValue(TitleProperty); + } + } + + /// + /// Gets fav icon. + /// + [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); + } + } + + /// /// Event for the PageLoadStarted signal which can be used to subscribe or unsubscribe the event handler.
/// This signal is emitted when page loading has started.
///
@@ -669,29 +715,25 @@ namespace Tizen.NUI } /// - /// Gets title of web page. + /// Event for the NewWindowCreated signal which can be used to subscribe or unsubscribe the event handler.
+ /// This signal is emitted when a new window would be created.
///
[EditorBrowsable(EditorBrowsableState.Never)] - public string Title + public event EventHandlerWithReturnType 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; } - } - - /// - /// Gets fav icon. - /// - [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 } /// - /// The callback function that is invoked when the message is received from the script. - /// - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - [EditorBrowsable(EditorBrowsableState.Never)] - public delegate void JavaScriptMessageHandler(string message); - - /// /// Evaluates JavaScript code represented as a string. /// The JavaScript code /// -- 2.7.4