From: huayong.xu Date: Mon, 16 Oct 2023 02:46:38 +0000 (+0800) Subject: [NUI] Add WebView APIs for fullscreen, text found, etc. X-Git-Tag: submit/tizen_8.0/20240808.050718~1^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d83769807b833f557ab487e0f387ebfe52eb1598;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Add WebView APIs for fullscreen, text found, etc. --- diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs index c0f356789..c35ad24d0 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs @@ -219,6 +219,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); @@ -295,6 +298,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); @@ -313,6 +319,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); } diff --git a/src/Tizen.NUI/src/internal/WebView/WebViewPolicyDecidedEventArgs.cs b/src/Tizen.NUI/src/internal/WebView/WebViewPolicyDecidedEventArgs.cs index 43e719b69..43ed244e3 100755 --- a/src/Tizen.NUI/src/internal/WebView/WebViewPolicyDecidedEventArgs.cs +++ b/src/Tizen.NUI/src/internal/WebView/WebViewPolicyDecidedEventArgs.cs @@ -21,20 +21,33 @@ using System.ComponentModel; namespace Tizen.NUI { /// - /// Event arguments that passed via the WebView.ResponsePolicyDecided. + /// Event arguments that passed via the WebView.ResponsePolicyDecided, + /// WebView.NavigationPolicyDecided or WebView.NewWindowPolicyDecided. /// [EditorBrowsable(EditorBrowsableState.Never)] public class WebViewPolicyDecidedEventArgs : EventArgs { internal WebViewPolicyDecidedEventArgs(WebPolicyDecisionMaker maker) { - ResponsePolicyDecisionMaker = maker; + PolicyDecisionMaker = maker; } /// - /// The response policy decision maker. + /// Deprecated. The response policy decision maker. /// [EditorBrowsable(EditorBrowsableState.Never)] - public WebPolicyDecisionMaker ResponsePolicyDecisionMaker { get; } + public WebPolicyDecisionMaker ResponsePolicyDecisionMaker + { + get + { + return PolicyDecisionMaker; + } + } + + /// + /// The policy decision maker. + /// + [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 index 000000000..8c76f04f9 --- /dev/null +++ b/src/Tizen.NUI/src/internal/WebView/WebViewTextFoundEventArgs.cs @@ -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 +{ + /// + /// Event arguments that passed via the WebView.TextFound. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class WebViewTextFoundEventArgs : EventArgs + { + internal WebViewTextFoundEventArgs(uint count) + { + Count = count; + } + + /// + /// The count of text found. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public uint Count { get; } + } +} diff --git a/src/Tizen.NUI/src/public/WebView/WebView.cs b/src/Tizen.NUI/src/public/WebView/WebView.cs index e6fffe4f9..f674fff98 100755 --- a/src/Tizen.NUI/src/public/WebView/WebView.cs +++ b/src/Tizen.NUI/src/public/WebView/WebView.cs @@ -127,6 +127,9 @@ namespace Tizen.NUI.BaseComponents private EventHandler navigationPolicyDecidedEventHandler; private WebViewPolicyDecidedCallback navigationPolicyDecidedCallback; + private EventHandler newWindowPolicyDecidedEventHandler; + private WebViewPolicyDecidedCallback newWindowPolicyDecidedCallback; + private EventHandlerWithReturnType newWindowCreatedEventHandler; private WebViewNewWindowCreatedCallback newWindowCreatedCallback; @@ -148,8 +151,16 @@ namespace Tizen.NUI.BaseComponents private EventHandler contextMenuHiddenEventHandler; private WebViewContextMenuHiddenCallback contextMenuHiddenCallback; - private PlainTextReceivedCallback plainTextReceivedCallback; + private EventHandler fullscreenEnteredEventHandler; + private WebViewFullscreenEnteredCallback fullscreenEnteredCallback; + + private EventHandler fullscreenExitedEventHandler; + private WebViewFullscreenExitedCallback fullscreenExitedCallback; + private EventHandler textFoundEventHandler; + private WebViewTextFoundCallback textFoundCallback; + + private PlainTextReceivedCallback plainTextReceivedCallback; /// /// Creates a WebView. @@ -344,6 +355,15 @@ namespace Tizen.NUI.BaseComponents [UnmanagedFunctionPointer(CallingConvention.Cdecl)] 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); + /// /// 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.
@@ -624,6 +644,34 @@ namespace Tizen.NUI.BaseComponents } } + /// + /// Event for the NewWindowPolicyDecided signal which can be used to subscribe or unsubscribe the event handler.
+ /// This signal is emitted when new window policy would be decided.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler 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)); + } + } + } + /// /// 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.
@@ -820,6 +868,90 @@ namespace Tizen.NUI.BaseComponents } } + /// + /// Event for the FullscreenEntered signal which can be used to subscribe or unsubscribe the event handler.
+ /// This signal is emitted when fullscreen is entered.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler 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)); + } + } + } + + /// + /// Event for the FullscreenExited signal which can be used to subscribe or unsubscribe the event handler.
+ /// This signal is emitted when fullscreen is exited.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler 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)); + } + } + } + + /// + /// Event for the TextFound signal which can be used to subscribe or unsubscribe the event handler.
+ /// This signal is emitted when text is found.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler 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)); + } + } + } + /// /// Options for searching texts. /// @@ -2426,6 +2558,16 @@ namespace Tizen.NUI.BaseComponents if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } + /// + /// Exit fullscreen. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void ExitFullscreen() + { + Interop.WebView.ExitFullscreen(SwigCPtr); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + /// /// Scales the current page, centered at the given point. /// @@ -2698,6 +2840,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()); @@ -2740,5 +2887,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)); + } } }