From 51c005ed64749e6b7d10665d96cf216994adc8fb Mon Sep 17 00:00:00 2001 From: BasavarajPS <45586075+BasavarajPS@users.noreply.github.com> Date: Tue, 16 Apr 2019 05:20:21 +0530 Subject: [PATCH] [WebView] [TCSACR-219] Add view APIs (#675) * [WebView][TCSACR-219] Add view APIs Signed-off-by: basavarajps --- .../Interop/Interop.ChromiumEwk.View.cs | 51 ++++ src/Tizen.WebView/Interop/Interop.Eina.cs | 7 + src/Tizen.WebView/Tizen.WebView/WebView.cs | 255 ++++++++++++++++++ 3 files changed, 313 insertions(+) diff --git a/src/Tizen.WebView/Interop/Interop.ChromiumEwk.View.cs b/src/Tizen.WebView/Interop/Interop.ChromiumEwk.View.cs index 8ff960777..ac64477f2 100644 --- a/src/Tizen.WebView/Interop/Interop.ChromiumEwk.View.cs +++ b/src/Tizen.WebView/Interop/Interop.ChromiumEwk.View.cs @@ -16,6 +16,7 @@ using System; using System.Runtime.InteropServices; +using Tizen.WebView; internal static partial class Interop { @@ -113,6 +114,56 @@ internal static partial class Interop [return: MarshalAs(UnmanagedType.U1)] internal static extern bool ewk_view_focus_get(IntPtr obj); + [DllImport(Libraries.ChromiumEwk)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool ewk_view_contents_size_get(IntPtr obj, out int width, out int height); + + [DllImport(Libraries.ChromiumEwk)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool ewk_view_fullscreen_exit(IntPtr obj); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern double ewk_view_load_progress_get(IntPtr obj); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern void ewk_view_orientation_send(IntPtr obj, Orientation orientation); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern void ewk_view_suspend(IntPtr obj); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern void ewk_view_resume(IntPtr obj); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern double ewk_view_scale_get(IntPtr obj); + + [DllImport(Libraries.ChromiumEwk)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool ewk_view_scale_set(IntPtr obj, double scaleFactor, int cX, int cY); + + [DllImport(Libraries.ChromiumEwk)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool ewk_view_visibility_set(IntPtr obj, bool enable); + + [DllImport(Libraries.ChromiumEwk)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool ewk_view_scroll_pos_get(IntPtr obj, out int X, out int Y); + + [DllImport(Libraries.ChromiumEwk)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool ewk_view_scroll_set(IntPtr obj, int X, int Y); + + [DllImport(Libraries.ChromiumEwk)] + internal static extern void ewk_view_scroll_by(IntPtr obj, int X, int Y); + + [DllImport(Libraries.ChromiumEwk)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool ewk_view_text_find(IntPtr obj, string text, FindOption option, int maxMatchCount); + + [DllImport(Libraries.ChromiumEwk)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool ewk_view_url_request_set(IntPtr obj, string url, HttpMethod method, IntPtr headers, string body); + [StructLayout(LayoutKind.Sequential, CharSet =CharSet.Ansi)] internal struct ScriptMessage { diff --git a/src/Tizen.WebView/Interop/Interop.Eina.cs b/src/Tizen.WebView/Interop/Interop.Eina.cs index 4c49d4701..a80d61b49 100644 --- a/src/Tizen.WebView/Interop/Interop.Eina.cs +++ b/src/Tizen.WebView/Interop/Interop.Eina.cs @@ -21,6 +21,13 @@ internal static partial class Interop { internal static partial class Eina { + [DllImport(Libraries.Eina)] + internal static extern IntPtr eina_hash_string_small_new(); + + [DllImport(Libraries.Eina)] + [return: MarshalAs(UnmanagedType.U1)] + internal static extern bool eina_hash_add(IntPtr hash, string Key, string Value); + [DllImport(Libraries.Eina)] internal static extern uint eina_list_count(IntPtr list); diff --git a/src/Tizen.WebView/Tizen.WebView/WebView.cs b/src/Tizen.WebView/Tizen.WebView/WebView.cs index fd322d41c..ee9b58b3d 100644 --- a/src/Tizen.WebView/Tizen.WebView/WebView.cs +++ b/src/Tizen.WebView/Tizen.WebView/WebView.cs @@ -18,9 +18,107 @@ using ElmSharp; using System; using System.Collections.Generic; using System.Runtime.InteropServices; +using System.ComponentModel; namespace Tizen.WebView { + /// + /// Enumeration values used to specify search options. + /// + /// 6 + [Flags] + public enum FindOption + { + /// + /// No search flags, this means a case sensitive, no wrap, forward only search. + /// + None = 0, + /// + /// Case insensitive search. + /// + CaseInsensitive = 1 << 0, + /// + /// Search text only at the beginning of the words. + /// + AtWordStart = 1 << 1, + /// + /// Treat capital letters in the middle of words as word start. + /// + TreatMedialCapitalAsWordStart = 1 << 2, + /// + /// Search backwards. + /// + Backwards = 1 << 3, + /// + /// If not present the search stops at the end of the document. + /// + WrapAround = 1 << 4, + /// + /// Show overlay. + /// + ShowOverlay = 1 << 5, + /// + /// Show Indicator. + /// + ShowIndicator = 1 << 6, + /// + /// Show Highlight. + /// + ShowHighlight = 1 << 7, + } + + /// + /// Enumeration for Http Method. + /// + /// 6 + public enum HttpMethod + { + /// + /// Get. + /// + Get, + /// + /// Head. + /// + Head, + /// + /// Post. + /// + Post, + /// + /// Put. + /// + Put, + /// + /// Delete. + /// + Delete, + } + + /// + /// Enumeration for Orientation of the device. + /// + /// 6 + public enum Orientation + { + /// + /// 0 degrees when the device is oriented to natural position. + /// + Natural = 0, + /// + /// -90 degrees when it's left side is at the top. + /// + LeftAtTop = -90, + /// + /// 90 degrees when it's right side is at the top. + /// + RightAtTop = 90, + /// + /// 180 degrees when it is upside down. + /// + UpsideDown = 180, + } + /// /// A view used to render the web contents. /// @@ -390,6 +488,163 @@ namespace Tizen.WebView Interop.ChromiumEwk.ewk_view_focus_set(_realHandle, focused); } + /// + /// Gets size of the content. + /// + /// size of the coordinate. + /// 6 + public Size ContentsSize + { + get + { + int width, height; + Interop.ChromiumEwk.ewk_view_contents_size_get(_realHandle, out width, out height); + return new Size(width, height); + } + } + + /// + /// Exit full screen. + /// + /// 6 + public void ExitFullscreen () + { + Interop.ChromiumEwk.ewk_view_fullscreen_exit(_realHandle); + } + + /// + /// Gets the current load progress of the page. + /// + /// 'value 0.0 to 1.0' on success, otherwise '-1.0'. + /// 6 + public double LoadProgress + { + get + { + return Interop.ChromiumEwk.ewk_view_load_progress_get(_realHandle); + } + } + + /// + /// Sends the orientation of the device. + /// + /// The new orientation of the device in degree. + /// 6 + public void SendOrientation (Orientation orientation) + { + Interop.ChromiumEwk.ewk_view_orientation_send(_realHandle, orientation); + } + + /// + /// Suspends the operation associated with the view. + /// + /// 6 + public void Suspend () + { + Interop.ChromiumEwk.ewk_view_suspend(_realHandle); + } + + /// + /// Resumes the operation associated with the view. + /// + /// 6 + public void Resume () + { + Interop.ChromiumEwk.ewk_view_resume(_realHandle); + } + + /// + /// Gets the current scale factor of the page. + /// + /// 6 + public double Scale + { + get + { + return Interop.ChromiumEwk.ewk_view_scale_get(_realHandle); + } + } + + /// + /// Sets the current scale factor of the page. + /// + /// A new level to set. + /// The class Point object with X, Y coordinates. + /// 6 + public void SetScale (double scaleFactor, Point scrollTo) + { + Interop.ChromiumEwk.ewk_view_scale_set(_realHandle, scaleFactor, scrollTo.X, scrollTo.Y); + } + + /// + /// Sets the current page's visibility. + /// + /// 'true' to set on the visibility of the page, 'false' otherwise. + /// 6 + public void SetViewVisibility (bool enable) + { + Interop.ChromiumEwk.ewk_view_visibility_set(_realHandle, enable); + } + + /// + /// Get and Sets the scroll position of the page. + /// + /// The class Point object with X, Y coordinates. + /// 6 + public Point ScrollPosition + { + get + { + Point p; + Interop.ChromiumEwk.ewk_view_scroll_pos_get(_realHandle, out p.X, out p.Y); + return p; + } + set + { + Interop.ChromiumEwk.ewk_view_scroll_set(_realHandle, value.X, value.Y); + } + } + + /// + /// Scrolls the webpage by the given amount. + /// + /// The class Point object with X, Y coordinates. + /// 6 + public void ScrollBy (Point delta) + { + Interop.ChromiumEwk.ewk_view_scroll_by(_realHandle, delta.X, delta.Y); + } + + /// + /// Searches and highlights the given text string in the document. + /// + /// The text to find. + /// The options to find. + /// The maximum match count to find, unlimited if 0. + /// 6 + public void FindText (string text, FindOption option, int maxMatchCount) + { + Interop.ChromiumEwk.ewk_view_text_find(_realHandle, text, option, maxMatchCount); + } + + /// + /// Requests loading of the given request data. + /// + /// The uniform resource identifier to load. + /// The http method. + /// The http headers. + /// The http body data. + /// 6 + public void SetUrlRequest (string url, HttpMethod httpMethod, IDictionary httpHeaders, string httpBody) + { + IntPtr hashHttpHeaders = Interop.Eina.eina_hash_string_small_new(); + foreach (KeyValuePair entry in httpHeaders) + { + Interop.Eina.eina_hash_add(hashHttpHeaders, entry.Key, entry.Value); + } + Interop.ChromiumEwk.ewk_view_url_request_set(_realHandle, url, httpMethod, hashHttpHeaders, httpBody); + } + /// /// Creates a widget handle. /// -- 2.34.1