using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
+using System.ComponentModel;
namespace Tizen.WebView
{
/// <summary>
- /// A view used to render web contents.
+ /// Enumeration values used to specify search options.
/// </summary>
- public class WebView: EvasObject
+ /// <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
{
private static IDictionary<string, JavaScriptMessageHandler> _javaScriptMessageHandlerMap = new Dictionary<string, JavaScriptMessageHandler>();
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 load started.
+ /// Event that occurs when the load is started.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public event EventHandler LoadStarted;
/// <summary>
- /// Event that occurs when load finished.
+ /// Event that occurs when the load is finished.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public event EventHandler LoadFinished;
/// <summary>
- /// Event that occurs when load error.
+ /// Event that occurs when the load throws an error.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public event EventHandler<SmartCallbackLoadErrorArgs> LoadError;
/// <summary>
- /// Event that occurs when title of main frame was changed.
+ /// Event that occurs when the title of the main frame is changed.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public event EventHandler<SmartCallbackArgs> TitleChanged;
/// <summary>
- /// Event that occurs when URL of main frame was changed.
+ /// Event that occurs when the URL of the main frame is changed.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
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>
public string Url
{
get
/// <summary>
/// Current title of the main frame.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public string Title
{
get
/// <summary>
/// Current user agent string of this view.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public string UserAgent
{
get
/// <summary>
/// Whether a view has the focus.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public bool HasFocus
{
get
}
/// <summary>
- /// Create a WebView object.
+ /// Creates a WebView object.
/// </summary>
- /// <param name="parent">Parent object of WebView</param>
+ /// <param name="parent">Parent object of the WebView.</param>
+ /// <since_tizen> 4 </since_tizen>
public WebView(EvasObject parent) : base(parent)
{
InitializeSmartEvent();
}
/// <summary>
- /// Gets the Context object of this view.
+ /// Gets the context object of this view.
/// </summary>
- /// <returns>The Context object of this view</returns>
+ /// <returns>The context object of this view.</returns>
+ /// <since_tizen> 4 </since_tizen>
public Context GetContext()
{
if (_context == null)
}
/// <summary>
- /// Gets the Settings object of this view.
+ /// Gets the settings object of this view.
/// </summary>
- /// <returns>The Settings object of this view</returns>
+ /// <returns>The settings object of this view.</returns>
+ /// <since_tizen> 4 </since_tizen>
public Settings GetSettings()
{
if (_settings == null)
}
/// <summary>
+ /// Gets the back/forward list object of this view.
+ /// </summary>
+ /// <returns>The BackForward List object of this view.</returns>
+ /// <since_tizen> 6 </since_tizen>
+ public BackForwardList GetBackForwardList()
+ {
+ IntPtr backforwardlistHandle = Interop.ChromiumEwk.ewk_view_back_forward_list_get(_realHandle);
+ if (backforwardlistHandle == IntPtr.Zero)
+ {
+ return null;
+ }
+ return new BackForwardList(backforwardlistHandle);
+ }
+
+ /// <summary>
+ /// Clear the back/forward list object of this view.
+ /// </summary>
+ /// <since_tizen> 6 </since_tizen>
+ public void ClearBackForwardList()
+ {
+ Interop.ChromiumEwk.ewk_view_back_forward_list_clear(_realHandle);
+ }
+
+ /// <summary>
/// Asks the object to load the given URL.
/// </summary>
/// <remarks>
- /// You can only be sure that url changed after UrlChanged event.
+ /// You can only be sure that the URL changes after UrlChanged event.
/// </remarks>
- /// <param name="url">The uniform resource identifier to load</param>
+ /// <param name="url">The uniform resource identifier to load.</param>
+ /// <since_tizen> 4 </since_tizen>
public void LoadUrl(string url)
{
Interop.ChromiumEwk.ewk_view_url_set(_realHandle, url);
}
/// <summary>
- /// Loads the specified html string as the content of the view.
+ /// Loads the specified HTML string as the content of the view.
/// </summary>
- /// <param name="html">HTML data to load</param>
- /// <param name="baseUrl">Base URL used for relative paths to external objects</param>
+ /// <param name="html">HTML data to load.</param>
+ /// <param name="baseUrl">Base URL used for relative paths to external objects.</param>
+ /// <since_tizen> 4 </since_tizen>
public void LoadHtml(string html, string baseUrl)
{
Interop.ChromiumEwk.ewk_view_html_string_load(_realHandle, html, baseUrl, null);
/// <summary>
/// Asks the main frame to stop loading.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public void StopLoading()
{
Interop.ChromiumEwk.ewk_view_stop(_realHandle);
/// <summary>
/// Asks the main frame to reload the current document.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public void Reload()
{
Interop.ChromiumEwk.ewk_view_reload(_realHandle);
/// <summary>
/// Asks the main frame to navigate back in history.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public void GoBack()
{
Interop.ChromiumEwk.ewk_view_back(_realHandle);
/// <summary>
/// Asks the main frame to navigate forward in history.
/// </summary>
+ /// <since_tizen> 4 </since_tizen>
public void GoForward()
{
Interop.ChromiumEwk.ewk_view_forward(_realHandle);
}
/// <summary>
- /// Checks whether it is possible to navigate backwards one item in history.
+ /// Checks whether it is possible to navigate backward one item in history.
/// </summary>
- /// <returns>Whether it is possible to navigate backwards one item in history</returns>
+ /// <returns>Whether it is possible to navigate backward one item in history.</returns>
+ /// <since_tizen> 4 </since_tizen>
public bool CanGoBack()
{
return Interop.ChromiumEwk.ewk_view_back_possible(_realHandle);
}
/// <summary>
- /// Checks whether it is possible to navigate forwards one item in history.
+ /// Checks whether it is possible to navigate forward one item in history.
/// </summary>
- /// <returns>Whether it is possible to navigate forwards one item in history</returns>
+ /// <returns>Whether it is possible to navigate forward one item in history.</returns>
+ /// <since_tizen> 4 </since_tizen>
public bool CanGoForward()
{
return Interop.ChromiumEwk.ewk_view_forward_possible(_realHandle);
/// <summary>
/// Injects the supplied javascript message handler into the view.
/// </summary>
- /// <param name="name"> The message callback</param>
- /// <param name="handler">The name used to expose the object in JavaScript</param>
- /// <returns>'true' on success, otherwise 'false'</returns>
+ /// <param name="name"> The message callback.</param>
+ /// <param name="handler">The name used to expose the object in JavaScript.</param>
+ /// <returns>'true' on success, otherwise 'false'.</returns>
+ /// <since_tizen> 4 </since_tizen>
public bool AddJavaScriptMessageHandler(string name, JavaScriptMessageHandler handler)
{
lock (_javaScriptMessageHandlerMap)
}
/// <summary>
- /// Requests the execution of given name and result to the JavaScript runtime.
+ /// Requests the execution of a given name and the result to the JavaScript runtime.
/// </summary>
- /// <param name="name">The name used to expose the object in JavaScript</param>
- /// <param name="result">The result to the JavaScript runtime</param>
+ /// <param name="name">The name used to expose the object in JavaScript.</param>
+ /// <param name="result">The result to the JavaScript runtime.</param>
+ /// <since_tizen> 4 </since_tizen>
public void EvalWithResult(string name, string result)
{
Interop.ChromiumEwk.ewk_view_evaluate_javascript(_realHandle, name, result);
/// <summary>
/// Requests the execution of the given script.
/// </summary>
- /// <param name="script">The JavaScript code string to execute</param>
+ /// <param name="script">The JavaScript code string to execute.</param>
+ /// <since_tizen> 4 </since_tizen>
public void Eval(string script)
{
Interop.ChromiumEwk.ewk_view_script_execute(_realHandle, script, null, IntPtr.Zero);
/// <summary>
/// Requests to set or unset a view as the currently focused one.
/// </summary>
- /// <param name="focused">'true' to set the focus on the view, 'false' to remove the focus from the view</param>
+ /// <param name="focused">'true' to set the focus on the view, 'false' to remove the focus from the view.</param>
+ /// <since_tizen> 4 </since_tizen>
public void SetFocus(bool focused)
{
Interop.ChromiumEwk.ewk_view_focus_set(_realHandle, focused);
}
+ /// <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>
+ /// <returns>IntPtr of the widget handle.</returns>
+ /// <since_tizen> 4 </since_tizen>
protected override IntPtr CreateHandle(EvasObject parent)
{
// focus dummy
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
_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); };
}
+
}
}