From: Jiyun Yang Date: Tue, 2 Feb 2021 07:53:51 +0000 (+0900) Subject: [NUI] Support scroll in WebView. (#2605) X-Git-Tag: submit/tizen_5.5_tv/20210203.005220~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3610c1d69e14ebbfe78c3fbae17d5cf07132ec54;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] Support scroll in WebView. (#2605) 1) ScrollPosition, ScrollSize, ContentSize properties are added. 2) ScrollBy is added. 3) ScrollEdgeReached events are notified when scrolled to edge. 4) Support program argument in WebView constructor to control chromium scroll options. Co-authored-by: huayongxu <49056704+huayongxu@users.noreply.github.com> --- diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs b/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs index f86aa52a2..a70b7a3d0 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.WebView.cs @@ -15,6 +15,9 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_New_2")] public static extern global::System.IntPtr WebView_New_2(string jarg1, string jarg2); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_New_3")] + public static extern global::System.IntPtr WebView_New_3(int jarg1, string[] jarg2); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_WebView__SWIG_1")] public static extern global::System.IntPtr new_WebView__SWIG_1(global::System.Runtime.InteropServices.HandleRef jarg1); @@ -51,6 +54,15 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_Property_DEFAULT_FONT_SIZE_get")] public static extern int WebView_Property_DEFAULT_FONT_SIZE_get(); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_Property_SCROLL_POSITION_get")] + public static extern int ScrollPositionGet(); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_Property_SCROLL_SIZE_get")] + public static extern int ScrollSizeGet(); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_Property_CONTENT_SIZE_get")] + public static extern int ContentSizeGet(); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_LoadUrl")] public static extern void WebView_LoadUrl(global::System.Runtime.InteropServices.HandleRef jarg1, string jarg2); @@ -69,6 +81,9 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_Resume")] public static extern void WebView_Resume(global::System.Runtime.InteropServices.HandleRef jarg1); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_ScrollBy")] + public static extern void ScrollBy(global::System.Runtime.InteropServices.HandleRef jarg1, int jarg2, int jarg3); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebView_GoBack")] public static extern void WebView_GoBack(global::System.Runtime.InteropServices.HandleRef jarg1); @@ -125,6 +140,18 @@ namespace Tizen.NUI [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebViewPageLoadErrorSignal_Disconnect")] public static extern void WebViewPageLoadErrorSignal_Disconnect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_new_WebViewScrollEdgeReachedSignal_ScrollEdgeReached")] + public static extern global::System.IntPtr NewWebViewScrollEdgeReachedSignalScrollEdgeReached(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_WebViewScrollEdgeReachedSignal")] + public static extern void DeleteWebViewScrollEdgeReachedSignal(global::System.Runtime.InteropServices.HandleRef jarg1); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebViewScrollEdgeReachedSignal_Connect")] + public static extern void WebViewScrollEdgeReachedSignalConnect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); + + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_WebViewScrollEdgeReachedSignal_Disconnect")] + public static extern void WebViewScrollEdgeReachedSignalDisconnect(global::System.Runtime.InteropServices.HandleRef jarg1, global::System.Runtime.InteropServices.HandleRef jarg2); } } -} \ No newline at end of file +} diff --git a/src/Tizen.NUI/src/internal/WebView.cs b/src/Tizen.NUI/src/internal/WebView.cs index f6a195fdb..83819a921 100755 --- a/src/Tizen.NUI/src/internal/WebView.cs +++ b/src/Tizen.NUI/src/internal/WebView.cs @@ -38,6 +38,9 @@ namespace Tizen.NUI [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void WebViewPageLoadErrorCallbackDelegate(IntPtr data, string pageUrl, int errorCode); + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate void WebViewScrollEdgeReachedCallbackDelegate(IntPtr data, int edge); + private readonly WebViewPageLoadSignal pageLoadStartedSignal; private EventHandler pageLoadStartedEventHandler; private WebViewPageLoadCallbackDelegate pageLoadStartedCallback; @@ -50,6 +53,10 @@ namespace Tizen.NUI private EventHandler pageLoadErrorEventHandler; private WebViewPageLoadErrorCallbackDelegate pageLoadErrorCallback; + private readonly WebViewScrollEdgeReachedSignal scrollEdgeReachedSignal; + private EventHandler scrollEdgeReachedEventHandler; + private WebViewScrollEdgeReachedCallbackDelegate scrollEdgeReachedCallback; + internal WebView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.WebView.WebView_SWIGUpcast(cPtr), cMemoryOwn) { swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); @@ -57,6 +64,7 @@ namespace Tizen.NUI pageLoadStartedSignal = new WebViewPageLoadSignal(Interop.WebView.new_WebViewPageLoadSignal_PageLoadStarted(swigCPtr)); pageLoadFinishedSignal = new WebViewPageLoadSignal(Interop.WebView.new_WebViewPageLoadSignal_PageLoadFinished(swigCPtr)); pageLoadErrorSignal = new WebViewPageLoadErrorSignal(Interop.WebView.new_WebViewPageLoadErrorSignal_PageLoadError(swigCPtr)); + scrollEdgeReachedSignal = new WebViewScrollEdgeReachedSignal(Interop.WebView.NewWebViewScrollEdgeReachedSignalScrollEdgeReached(swigCPtr)); } internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WebView obj) @@ -156,6 +164,12 @@ namespace Tizen.NUI } } + private void OnScrollEdgeReached(IntPtr data, int edge) + { + WebViewScrollEdgeReachedEventArgs arg = new WebViewScrollEdgeReachedEventArgs((WebViewScrollEdgeReachedEventArgs.Edge)edge); + scrollEdgeReachedEventHandler?.Invoke(this, arg); + } + internal static new class Property { internal static readonly int URL = Interop.WebView.WebView_Property_URL_get(); @@ -166,6 +180,9 @@ namespace Tizen.NUI internal static readonly int LOAD_IMAGES_AUTOMATICALLY = Interop.WebView.WebView_Property_LOAD_IMAGES_AUTOMATICALLY_get(); internal static readonly int DEFAULT_TEXT_ENCODING_NAME = Interop.WebView.WebView_Property_DEFAULT_TEXT_ENCODING_NAME_get(); internal static readonly int DEFAULT_FONT_SIZE = Interop.WebView.WebView_Property_DEFAULT_FONT_SIZE_get(); + internal static readonly int ScrollPosition = Interop.WebView.ScrollPositionGet(); + internal static readonly int ScrollSize = Interop.WebView.ScrollSizeGet(); + internal static readonly int ContentSize = Interop.WebView.ContentSizeGet(); } private static readonly BindableProperty UrlProperty = BindableProperty.Create(nameof(Url), typeof(string), typeof(WebView), string.Empty, propertyChanged: (bindable, oldValue, newValue) => @@ -312,6 +329,39 @@ namespace Tizen.NUI return temp; }); + + private static readonly BindableProperty ScrollPositionProperty = BindableProperty.Create(nameof(ScrollPosition), typeof(Vector2), typeof(WebView), null, propertyChanged: (bindable, oldValue, newValue) => + { + var webview = (WebView)bindable; + if (newValue != null) + { + Tizen.NUI.Object.SetProperty(webview.swigCPtr, WebView.Property.ScrollPosition, new Tizen.NUI.PropertyValue((Vector2)newValue)); + } + }, + defaultValueCreator: (bindable) => + { + var webview = (WebView)bindable; + Vector2 temp = new Vector2(0.0f, 0.0f); + Tizen.NUI.Object.GetProperty(webview.swigCPtr, WebView.Property.ScrollPosition).Get(temp); + return temp; + }); + + private static readonly BindableProperty ScrollSizeProperty = BindableProperty.Create(nameof(ScrollSize), typeof(Vector2), typeof(WebView), null, defaultValueCreator: (bindable) => + { + var webview = (WebView)bindable; + Vector2 temp = new Vector2(0.0f, 0.0f); + Tizen.NUI.Object.GetProperty(webview.swigCPtr, WebView.Property.ScrollSize).Get(temp); + return temp; + }); + + private static readonly BindableProperty ContentSizeProperty = BindableProperty.Create(nameof(ContentSize), typeof(Vector2), typeof(WebView), null, defaultValueCreator: (bindable) => + { + var webview = (WebView)bindable; + Vector2 temp = new Vector2(0.0f, 0.0f); + Tizen.NUI.Object.GetProperty(webview.swigCPtr, WebView.Property.ContentSize).Get(temp); + return temp; + }); + /// /// Creates an uninitialized WebView. /// @@ -333,6 +383,16 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } + /// + /// Creates a WebView. + /// Argument array. The first value of array must be program's name. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public WebView(string[] args) : this(args == null ? Interop.WebView.WebView_New() : Interop.WebView.WebView_New_3(args.Length, args), true) + { + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + /// /// Copy constructor. /// WebView to copy. The copied WebView will point at the same implementation @@ -480,6 +540,55 @@ namespace Tizen.NUI } } + /// + /// The postion of scroll. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Position ScrollPosition + { + get + { + Vector2 pv = (Vector2)GetValue(ScrollPositionProperty); + return new Position(pv.X, pv.Y); + } + set + { + if (value != null) + { + Position pv = value; + Vector2 vpv = new Vector2(pv.X, pv.Y); + SetValue(ScrollPositionProperty, vpv); + NotifyPropertyChanged(); + } + } + } + + /// + /// The size of scroll, read-only. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Size ScrollSize + { + get + { + Vector2 sv = (Vector2)GetValue(ScrollSizeProperty); + return new Size(sv.Width, sv.Height); + } + } + + /// + /// The size of content, read-only. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Size ContentSize + { + get + { + Vector2 sv = (Vector2)GetValue(ContentSizeProperty); + return new Size(sv.Width, sv.Height); + } + } + /// /// 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.
@@ -558,6 +667,32 @@ namespace Tizen.NUI } } + /// + /// Event for the ScrollEdgeReached signal which can be used to subscribe or unsubscribe the event handler.
+ /// This signal is emitted when web view is scrolled to edge.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler ScrollEdgeReached + { + add + { + if (scrollEdgeReachedEventHandler == null) + { + scrollEdgeReachedCallback = OnScrollEdgeReached; + scrollEdgeReachedSignal.Connect(scrollEdgeReachedCallback); + } + scrollEdgeReachedEventHandler += value; + } + remove + { + scrollEdgeReachedEventHandler -= value; + if (scrollEdgeReachedEventHandler == null && scrollEdgeReachedCallback != null) + { + scrollEdgeReachedSignal.Disconnect(scrollEdgeReachedCallback); + } + } + } + /// /// Loads a html. /// The path of Web @@ -620,6 +755,18 @@ namespace Tizen.NUI if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } + /// + /// Scroll web view by deltaX and detlaY. + /// The deltaX of scroll + /// The deltaY of scroll + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public void ScrollBy(int deltaX, int deltaY) + { + Interop.WebView.ScrollBy(swigCPtr, deltaX, deltaY); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + /// /// Goes to the back /// diff --git a/src/Tizen.NUI/src/internal/WebViewScrollEdgeReachedEventArgs.cs b/src/Tizen.NUI/src/internal/WebViewScrollEdgeReachedEventArgs.cs new file mode 100755 index 000000000..8cf0464cd --- /dev/null +++ b/src/Tizen.NUI/src/internal/WebViewScrollEdgeReachedEventArgs.cs @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021 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.ScrollEdgeReached. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class WebViewScrollEdgeReachedEventArgs : EventArgs + { + /// + /// The enumeration for edge. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public enum Edge + { + [EditorBrowsable(EditorBrowsableState.Never)] + Left, + + [EditorBrowsable(EditorBrowsableState.Never)] + Right, + + [EditorBrowsable(EditorBrowsableState.Never)] + Top, + + [EditorBrowsable(EditorBrowsableState.Never)] + Bottom, + } + + /// + /// The edge, e.g. left, right, etc. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Edge ScrollEdge { get; } + + internal WebViewScrollEdgeReachedEventArgs(Edge e) + { + ScrollEdge = e; + } + } +} diff --git a/src/Tizen.NUI/src/internal/WebViewScrollEdgeReachedSignal.cs b/src/Tizen.NUI/src/internal/WebViewScrollEdgeReachedSignal.cs new file mode 100755 index 000000000..079963a4d --- /dev/null +++ b/src/Tizen.NUI/src/internal/WebViewScrollEdgeReachedSignal.cs @@ -0,0 +1,73 @@ +/* + * Copyright(c) 2021 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. + * + */ + +namespace Tizen.NUI +{ + internal class WebViewScrollEdgeReachedSignal : Disposable + { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + + public WebViewScrollEdgeReachedSignal(global::System.IntPtr cPtr) + { + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + + public void Connect(System.Delegate func) + { + System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); + { + Interop.WebView.WebViewScrollEdgeReachedSignalConnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); + if (NDalicPINVOKE.SWIGPendingException.Pending) + { + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + } + + public void Disconnect(System.Delegate func) + { + System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(func); + { + Interop.WebView.WebViewScrollEdgeReachedSignalDisconnect(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip)); + if (NDalicPINVOKE.SWIGPendingException.Pending) + { + throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + } + } + + protected override void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + //Release your own unmanaged resources here. + //You should not access any managed member here except static instance. + //because the execution order of Finalizes is non-deterministic. + + if (swigCPtr.Handle != global::System.IntPtr.Zero) + { + Interop.WebView.DeleteWebViewScrollEdgeReachedSignal(swigCPtr); + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + + base.Dispose(type); + } + } +}