[WebView] [TCSACR-219] Add view APIs (#675)
[platform/core/csapi/tizenfx.git] / src / Tizen.WebView / Tizen.WebView / WebView.cs
index 5a11337..ee9b58b 100644 (file)
@@ -18,14 +18,112 @@ using ElmSharp;
 using System;
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
+using System.ComponentModel;
 
 namespace Tizen.WebView
 {
     /// <summary>
+    /// Enumeration values used to specify search options.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    [Flags]
+    public enum FindOption
+    {
+        /// <summary>
+        /// No search flags, this means a case sensitive, no wrap, forward only search.
+        /// </summary>
+        None = 0,
+        /// <summary>
+        /// Case insensitive search.
+        /// </summary>
+        CaseInsensitive = 1 << 0,
+        /// <summary>
+        /// Search text only at the beginning of the words.
+        /// </summary>
+        AtWordStart = 1 << 1,
+        /// <summary>
+        /// Treat capital letters in the middle of words as word start.
+        /// </summary>
+        TreatMedialCapitalAsWordStart = 1 << 2,
+        /// <summary>
+        /// Search backwards.
+        /// </summary>
+        Backwards = 1 << 3,
+        /// <summary>
+        /// If not present the search stops at the end of the document.
+        /// </summary>
+        WrapAround = 1 << 4,
+        /// <summary>
+        /// Show overlay.
+        /// </summary>
+        ShowOverlay = 1 << 5,
+        /// <summary>
+        /// Show Indicator.
+        /// </summary>
+        ShowIndicator = 1 << 6,
+        /// <summary>
+        /// Show Highlight.
+        /// </summary>
+        ShowHighlight = 1 << 7,
+    }
+
+    /// <summary>
+    /// Enumeration for Http Method.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public enum HttpMethod
+    {
+        /// <summary>
+        /// Get.
+        /// </summary>
+        Get,
+        /// <summary>
+        /// Head.
+        /// </summary>
+        Head,
+        /// <summary>
+        /// Post.
+        /// </summary>
+        Post,
+        /// <summary>
+        /// Put.
+        /// </summary>
+        Put,
+        /// <summary>
+        /// Delete.
+        /// </summary>
+        Delete, 
+    }
+
+    /// <summary>
+    /// Enumeration for Orientation of the device.
+    /// </summary>
+    /// <since_tizen> 6 </since_tizen>
+    public enum Orientation
+    {
+        /// <summary>
+        /// 0 degrees when the device is oriented to natural position.
+        /// </summary>
+        Natural = 0,
+        /// <summary>
+        /// -90 degrees when it's left side is at the top.
+        /// </summary>
+        LeftAtTop = -90,
+        /// <summary>
+        /// 90 degrees when it's right side is at the top.
+        /// </summary>
+        RightAtTop = 90,
+        /// <summary>
+        /// 180 degrees when it is upside down.
+        /// </summary>
+        UpsideDown = 180,
+    }
+
+    /// <summary>
     /// A view used to render the web contents.
     /// </summary>
     /// <since_tizen> 4 </since_tizen>
-    public class WebView: EvasObject
+    public class WebView : EvasObject
     {
         private static IDictionary<string, JavaScriptMessageHandler> _javaScriptMessageHandlerMap = new Dictionary<string, JavaScriptMessageHandler>();
 
@@ -44,8 +142,14 @@ namespace Tizen.WebView
         private SmartEvent<SmartCallbackLoadErrorArgs> _loadError;
         private SmartEvent<SmartCallbackArgs> _titleChanged;
         private SmartEvent<SmartCallbackArgs> _urlChanged;
+        private SmartEvent<NavigationPolicyEventArgs> _policyNavigationDecide;
+        private SmartEvent<NewWindowPolicyEventArgs> _policyNewWindowDecide;
+        private SmartEvent<ResponsePolicyEventArgs> _policyResponseDecide;
 
+        private SmartEvent<ContextMenuItemEventArgs> _contextMenuItemSelected;
+        private SmartEvent<ContextMenuCustomizeEventArgs> _contextMenuCustomize;
 
+        private ContextMenuCustomize _contextMenuCustomizeDelegate;
 
         /// <summary>
         /// Event that occurs when the load is started.
@@ -78,6 +182,38 @@ namespace Tizen.WebView
         public event EventHandler<SmartCallbackArgs> UrlChanged;
 
         /// <summary>
+
+        /// Event that occurs when the policy navigation is decided.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public event EventHandler<NavigationPolicyEventArgs> NavigationPolicyDecideRequested;
+
+        /// <summary>
+        /// Event that occurs when the policy new window is decided.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public event EventHandler<NewWindowPolicyEventArgs> NewWindowPolicyDecideRequested;
+
+        /// <summary>
+        /// Event that occurs when the policy response is decided.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public event EventHandler<ResponsePolicyEventArgs> ResponsePolicyDecideRequested;
+
+        /// <summary>
+        /// Event that occurs when the context menu item selected.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public event EventHandler<ContextMenuItemEventArgs> ContextMenuItemSelected;
+        
+        /// The delegate is invoked when context menu customization is needed.
+        /// </summary>
+        /// <param name="menu">The instance of ContextMenu.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public delegate void ContextMenuCustomize(ContextMenu menu);
+
+
+        /// <summary>
         /// Current URL of the main frame.
         /// </summary>
         /// <since_tizen> 4 </since_tizen>
@@ -353,6 +489,163 @@ namespace Tizen.WebView
         }
 
         /// <summary>
+        /// Gets size of the content.
+        /// </summary>
+        /// <returns> size of the coordinate.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        public Size ContentsSize
+        {
+            get
+            {
+                int width, height;
+                Interop.ChromiumEwk.ewk_view_contents_size_get(_realHandle, out width, out height);
+                return new Size(width, height);
+            }
+        }
+
+        /// <summary>
+        /// Exit full screen.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public void ExitFullscreen ()
+        {
+            Interop.ChromiumEwk.ewk_view_fullscreen_exit(_realHandle);
+        }
+
+        /// <summary>
+        /// Gets the current load progress of the page.
+        /// </summary>
+        /// <returns>'value 0.0 to 1.0' on success, otherwise '-1.0'.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        public double LoadProgress
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_view_load_progress_get(_realHandle);
+            }
+        }
+
+        /// <summary>
+        /// Sends the orientation of the device.
+        /// </summary>
+        /// <param name="orientation">The new orientation of the device in degree.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void SendOrientation (Orientation orientation)
+        {
+            Interop.ChromiumEwk.ewk_view_orientation_send(_realHandle, orientation);
+        }
+
+        /// <summary>
+        /// Suspends the operation associated with the view.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public void Suspend ()
+        {
+            Interop.ChromiumEwk.ewk_view_suspend(_realHandle);
+        }
+
+        /// <summary>
+        /// Resumes the operation associated with the view.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public void Resume ()
+        {
+            Interop.ChromiumEwk.ewk_view_resume(_realHandle);
+        }
+
+        /// <summary>
+        /// Gets the current scale factor of the page.
+        /// </summary>
+        /// <since_tizen> 6 </since_tizen>
+        public double Scale
+        {
+            get
+            {
+                return Interop.ChromiumEwk.ewk_view_scale_get(_realHandle);
+            }
+        }
+
+        /// <summary>
+        /// Sets the current scale factor of the page.
+        /// </summary>
+        /// <param name="scaleFactor">A new level to set.</param>
+        /// <param name="scrollTo">The class Point object with X, Y coordinates.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void SetScale (double scaleFactor, Point scrollTo)
+        {
+            Interop.ChromiumEwk.ewk_view_scale_set(_realHandle, scaleFactor, scrollTo.X, scrollTo.Y);
+        }
+
+        /// <summary>
+        /// Sets the current page's visibility.
+        /// </summary>
+        /// <param name="enable">'true' to set on the visibility of the page, 'false' otherwise.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void SetViewVisibility (bool enable)
+        {
+            Interop.ChromiumEwk.ewk_view_visibility_set(_realHandle, enable);
+        }
+
+        /// <summary>
+        /// Get and Sets the scroll position of the page.
+        /// </summary>
+        /// <returns>The class Point object with X, Y coordinates.</returns>
+        /// <since_tizen> 6 </since_tizen>
+        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);
+            }
+        }
+
+        /// <summary>
+        /// Scrolls the webpage by the given amount.
+        /// </summary>
+        /// <param name="delta">The class Point object with X, Y coordinates.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void ScrollBy (Point delta)
+        {
+            Interop.ChromiumEwk.ewk_view_scroll_by(_realHandle, delta.X, delta.Y);
+        }
+
+        /// <summary>
+        /// Searches and highlights the given text string in the document.
+        /// </summary>
+        /// <param name="text">The text to find.</param>
+        /// <param name="option">The options to find.</param>
+        /// <param name="maxMatchCount">The maximum match count to find, unlimited if 0.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void FindText (string text, FindOption option, int maxMatchCount)
+        {
+            Interop.ChromiumEwk.ewk_view_text_find(_realHandle, text, option, maxMatchCount);
+        }
+
+        /// <summary>
+        /// Requests loading of the given request data.
+        /// </summary>
+        /// <param name="url">The uniform resource identifier to load.</param>
+        /// <param name="httpMethod">The http method.</param>
+        /// <param name="httpHeaders">The http headers.</param>
+        /// <param name="httpBody">The http body data.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void SetUrlRequest (string url, HttpMethod httpMethod, IDictionary<string, string> httpHeaders, string httpBody)
+        {
+            IntPtr hashHttpHeaders = Interop.Eina.eina_hash_string_small_new();
+            foreach (KeyValuePair<string, string> 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);
+        }
+
+        /// <summary>
         /// Creates a widget handle.
         /// </summary>
         /// <param name="parent">Parent EvasObject.</param>
@@ -372,6 +665,16 @@ namespace Tizen.WebView
             return _handle;
         }
 
+        /// <summary>
+        /// Sets the delegate for context menu customization.
+        /// </summary>
+        /// <param name="contextMenuCustomizeDelegate">The delegate for context menu customization.</param>
+        /// <since_tizen> 6 </since_tizen>
+        public void SetContextMenuCustomizeDelegate(ContextMenuCustomize contextMenuCustomizeDelegate)
+        {
+            _contextMenuCustomizeDelegate = contextMenuCustomizeDelegate;
+        }
+
         private void InitializeSmartEvent()
         {
             // focus dummy
@@ -386,12 +689,23 @@ namespace Tizen.WebView
             _loadError = new SmartEvent<SmartCallbackLoadErrorArgs>(this, _realHandle, "load,error", SmartCallbackLoadErrorArgs.CreateFromSmartEvent);
             _titleChanged = new SmartEvent<SmartCallbackArgs>(this, _realHandle, "title,changed", SmartCallbackArgs.CreateFromSmartEvent);
             _urlChanged = new SmartEvent<SmartCallbackArgs>(this, _realHandle, "url,changed", SmartCallbackArgs.CreateFromSmartEvent);
+            _contextMenuCustomize = new SmartEvent<ContextMenuCustomizeEventArgs>(this, _realHandle, "contextmenu,customize", ContextMenuCustomizeEventArgs.CreateFromSmartEvent);
+            _contextMenuItemSelected = new SmartEvent<ContextMenuItemEventArgs>(this, _realHandle, "contextmenu,selected", ContextMenuItemEventArgs.CreateFromSmartEvent);
+            _policyNavigationDecide = new SmartEvent<NavigationPolicyEventArgs>(this, _realHandle, "policy,navigation,decide", NavigationPolicyEventArgs.CreateFromSmartEvent);
+            _policyNewWindowDecide = new SmartEvent<NewWindowPolicyEventArgs>(this, _realHandle, "policy,newwindow,decide", NewWindowPolicyEventArgs.CreateFromSmartEvent);
+            _policyResponseDecide = new SmartEvent<ResponsePolicyEventArgs>(this, _realHandle, "policy,response,decide", ResponsePolicyEventArgs.CreateFromSmartEvent);            
 
             _loadStarted.On += (s, e) => { LoadStarted?.Invoke(this, EventArgs.Empty); };
             _loadFinished.On += (s, e) => { LoadFinished?.Invoke(this, EventArgs.Empty); };
             _loadError.On += (s, e) => { LoadError?.Invoke(this, e); };
             _titleChanged.On += (s, e) => { TitleChanged?.Invoke(this, e); };
             _urlChanged.On += (s, e) => { UrlChanged?.Invoke(this, e); };
+            _policyNavigationDecide.On += (s, e) => { NavigationPolicyDecideRequested?.Invoke(this, e); };
+            _policyNewWindowDecide.On += (s, e) => { NewWindowPolicyDecideRequested?.Invoke(this, e); };
+            _policyResponseDecide.On += (s, e) => { ResponsePolicyDecideRequested?.Invoke(this, e); };
+            _contextMenuItemSelected.On += (s, e) => { ContextMenuItemSelected?.Invoke(this, e); };
+            _contextMenuCustomize.On += (s, e) => { _contextMenuCustomizeDelegate?.Invoke(e.Menu); };
         }
+        
     }
 }