Support mouse & wheel events in web view.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / web-view / web-view.h
index ad39718..d347824 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_WEB_VIEW_H
 
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * 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.
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control.h>
+#include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
 
 namespace Dali
 {
-
 namespace Toolkit
 {
+class ImageView;
+class WebBackForwardList;
+class WebContext;
+class WebCookieManager;
+class WebSettings;
 
 namespace Internal DALI_INTERNAL
 {
-  class WebView;
-} // namespace Internal
+class WebView;
+} // namespace DALI_INTERNAL
 
 /**
  * @addtogroup dali_toolkit_controls_web_view
@@ -51,68 +56,13 @@ namespace Internal DALI_INTERNAL
 class DALI_TOOLKIT_API WebView : public Control
 {
 public:
-
-  /**
-   * @brief A structure used to contain the cache model enumeration.
-   */
-  struct CacheModel
-  {
-    /**
-     * @brief Enumeration for cache model options.
-     */
-    enum Type
-    {
-      /**
-       * @brief Use the smallest cache capacity.
-       */
-      DOCUMENT_VIEWER,
-
-      /**
-       * @brief Use the bigger cache capacity than DocumentBrowser.
-       */
-      DOCUMENT_BROWSER,
-
-      /**
-       * @brief Use the biggest cache capacity.
-       */
-      PRIMARY_WEB_BROWSER
-    };
-  };
-
-  /**
-   * @brief A structure used to contain the cookie acceptance policy enumeration.
-   */
-  struct CookieAcceptPolicy
-  {
-    /**
-     * @brief Enumeration for the cookies accept policies.
-     */
-    enum Type
-    {
-      /**
-       * @brief Accepts every cookie sent from any page.
-       */
-      ALWAYS,
-
-      /**
-       * @brief Rejects all the cookies.
-       */
-      NEVER,
-
-      /**
-       * @brief Accepts only cookies set by the main document that is loaded.
-       */
-      NO_THIRD_PARTY
-    };
-  };
-
   /**
    * @brief Enumeration for the start and end property ranges for this control.
    */
   enum PropertyRange
   {
     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
-    PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000,
+    PROPERTY_END_INDEX   = PROPERTY_START_INDEX + 1000,
   };
 
   /**
@@ -129,54 +79,58 @@ public:
       URL = PROPERTY_START_INDEX,
 
       /**
-       * @brief The cache model.
-       * @details Name "cacheModel", type WebView::CacheModel::Type (Property::INTEGER) or Property::STRING.
-       * @note Default is WebView::CacheModel::DOCUMENT_VIEWER.
-       * @see WebView::CacheModel::Type
+       * @brief The user agent string.
+       * @details name "userAgent", type Property::STRING.
        */
-      CACHE_MODEL,
+      USER_AGENT,
 
       /**
-       * @brief The cookie acceptance policy.
-       * @details Name "cookieAcceptPolicy", type WebView::CookieAcceptPolicy::Type (Property::INTEGER) or Property::STRING.
-       * @note Default is WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
-       * @see WebView::CookieAcceptPolicy::Type
+       * @brief The current position of scroll.
+       * @details name "scrollPosition", type Property::VECTOR2.
        */
-      COOKIE_ACCEPT_POLICY,
+      SCROLL_POSITION,
 
       /**
-       * @brief The user agent string.
-       * @details Name "userAgent", type Property::STRING.
+       * @brief The current size of scroll.
+       * @details name "scrollSize", type Property::VECTOR2.
+       * @note The value is read-only.
        */
-      USER_AGENT,
+      SCROLL_SIZE,
 
       /**
-       * @brief Whether JavaScript is enabled.
-       * @details Name "enableJavaScript", type Property::BOOLEAN.
-       * @note Default is true.
+       * @brief The current size of content.
+       * @details name "contentSize", type Property::VECTOR2.
+       * @note The value is read-only.
        */
-      ENABLE_JAVASCRIPT,
+      CONTENT_SIZE,
 
       /**
-       * @brief Whether images can be loaded automatically.
-       * @details Name "loadImagesAutomatically", type Property::BOOLEAN.
-       * @note Default is true.
+       * @brief The title of web page.
+       * @details name "title", type Property::STRING.
+       * @note The value is read-only.
        */
-      LOAD_IMAGES_AUTOMATICALLY,
+      TITLE,
 
       /**
-       * @brief The default text encoding name.
-       * @details Name "defaultTextEncodingName", type Property::STRING.
-       * @note If the value is not set, the web engine detects web page's text encoding.
+       * @brief Whether video hole is enabled or not.
+       * @details name "videoHoleEnabled", type Property::BOOLEAN.
+       * @note The value is read-only.
        */
-      DEFAULT_TEXT_ENCODING_NAME,
+      VIDEO_HOLE_ENABLED,
 
       /**
-       * @brief The default font size in pixel.
-       * @details Name "defaultFontSize", type Property::INT.
-       * @note Default is 16.
+       * @brief Whether mouse event is enabled.
+       * @details name "mouseEventsEnabled", type Property::BOOLEAN.
+       * @note Default is true.
+       */
+      MOUSE_EVENTS_ENABLED,
+
+      /**
+       * @brief Whether key event is enabled.
+       * @details name "keyEventsEnabled", type Property::BOOLEAN.
+       * @note Default is true.
        */
-      DEFAULT_FONT_SIZE
+      KEY_EVENTS_ENABLED,
     };
   };
 
@@ -185,95 +139,45 @@ public:
    */
   enum class LoadErrorCode
   {
-    /**
-     * @brief Unknown.
-     */
-    UNKNOWN = 0,
-
-    /**
-     * @brief User canceled.
-     */
-    CANCELED,
-
-    /**
-     * @brief Can't show the page for this MIME type.
-     */
-    CANT_SUPPORT_MIMETYPE,
-
-    /**
-     * @brief File IO error.
-     */
-    FAILED_FILE_IO,
-
-    /**
-     * @brief Cannot connect to the network.
-     */
-    CANT_CONNECT,
-
-    /**
-     * @brief Fail to look up host from the DNS.
-     */
-    CANT_LOOKUP_HOST,
-
-    /**
-     * @brief Fail to SSL/TLS handshake.
-     */
-    FAILED_TLS_HANDSHAKE,
-
-    /**
-     * @brief Received certificate is invalid.
-     */
-    INVALID_CERTIFICATE,
-
-    /**
-     * @brief Connection timeout.
-     */
-    REQUEST_TIMEOUT,
-
-    /**
-     * @brief Too many redirects.
-     */
-    TOO_MANY_REDIRECTS,
-
-    /**
-     * @brief Too many requests during this load.
-     */
-    TOO_MANY_REQUESTS,
-
-    /**
-     * @brief Malformed URL.
-     */
-    BAD_URL,
-
-    /**
-     * @brief Unsupported scheme.
-     */
-    UNSUPPORTED_SCHEME,
-
-    /**
-     * @brief User authentication failed on the server.
-     */
-    AUTHENTICATION,
-
-    /**
-     * @brief Web server has an internal server error.
-     */
-    INTERNAL_SERVER
+    UNKNOWN = 0,           ///< Unknown.
+    CANCELED,              ///< User canceled.
+    CANT_SUPPORT_MIMETYPE, ///< Can't show the page for this MIME type.
+    FAILED_FILE_IO,        ///< File IO error.
+    CANT_CONNECT,          ///< Cannot connect to the network.
+    CANT_LOOKUP_HOST,      ///< Fail to look up host from the DNS.
+    FAILED_TLS_HANDSHAKE,  ///< Fail to SSL/TLS handshake.
+    INVALID_CERTIFICATE,   ///< Received certificate is invalid.
+    REQUEST_TIMEOUT,       ///< Connection timeout.
+    TOO_MANY_REDIRECTS,    ///< Too many redirects.
+    TOO_MANY_REQUESTS,     ///< Too many requests during this load.
+    BAD_URL,               ///< Malformed URL.
+    UNSUPPORTED_SCHEME,    ///< Unsupported scheme.
+    AUTHENTICATION,        ///< User authentication failed on the server.
+    INTERNAL_SERVER        ///< Web server has an internal server error.
   };
 
   /**
    * @brief WebView signal type related with page loading.
    */
-  typedef Signal< void ( WebView, const std::string& ) > WebViewPageLoadSignalType;
+  using WebViewPageLoadSignalType = Signal<void(WebView, const std::string&)>;
 
   /**
    * @brief WebView signal type related with page loading error.
    */
-  typedef Signal< void ( WebView, const std::string&, LoadErrorCode ) > WebViewPageLoadErrorSignalType;
+  using WebViewPageLoadErrorSignalType = Signal<void(WebView, const std::string&, LoadErrorCode)>;
 
-public:
+  /**
+   * @brief WebView signal type related with scroll edge reached.
+   */
+  using WebViewScrollEdgeReachedSignalType = Signal<void(WebView, Dali::WebEnginePlugin::ScrollEdge)>;
 
   /**
+   * @brief WebView signal type related with url changed.
+   */
+  using WebViewUrlChangedSignalType = Signal<void(WebView, const std::string&)>;
+
+public:
+  /**
    * @brief Creates an initialized WebView.
    * @return A handle to a newly allocated Dali WebView
    *
@@ -287,7 +191,15 @@ public:
    * @param [in] locale The locale of Web
    * @param [in] timezoneId The timezoneId of Web
    */
-  static WebView New( const std::string& locale, const std::string& timezoneId );
+  static WebView New(const std::string& locale, const std::string& timezoneId);
+
+  /**
+   * @brief Creates an initialized WebView.
+   *
+   * @param [in] argc The count of arguments of Applications
+   * @param [in] argv The string array of arguments of Applications
+   */
+  static WebView New(int argc, char** argv);
 
   /**
    * @brief Creates an uninitialized WebView.
@@ -306,7 +218,7 @@ public:
    *
    * @param[in] WebView WebView to copy. The copied WebView will point at the same implementation
    */
-  WebView( const WebView& WebView );
+  WebView(const WebView& WebView);
 
   /**
    * @brief Assignment operator.
@@ -314,7 +226,7 @@ public:
    * @param[in] WebView The WebView to assign from
    * @return The updated WebView
    */
-  WebView& operator=( const WebView& WebView );
+  WebView& operator=(const WebView& WebView);
 
   /**
    * @brief Downcasts a handle to WebView handle.
@@ -325,21 +237,48 @@ public:
    * @param[in] handle Handle to an object
    * @return Handle to a WebView or an uninitialized handle
    */
-  static WebView DownCast( BaseHandle handle );
+  static WebView DownCast(BaseHandle handle);
+
+  /**
+   * @brief Get WebSettings of WebEngine.
+   */
+  Dali::Toolkit::WebSettings* GetSettings() const;
+
+  /**
+   * @brief Get WebContext of WebEngine.
+   */
+  Dali::Toolkit::WebContext* GetContext() const;
+
+  /**
+   * @brief Get CookieManager of WebEngine.
+   */
+  Dali::Toolkit::WebCookieManager* GetCookieManager() const;
+
+  /**
+   * @brief Get WebBackForwardList of WebEngine.
+   */
+  Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
+
+  /**
+   * @brief Get Favicon of web page.
+   *
+   * @return Handle to a fav icon
+   */
+  Dali::Toolkit::ImageView& GetFavicon();
 
   /**
    * @brief Loads a web page based on a given URL.
    *
    * @param [in] url The URL of the resource to load
    */
-  void LoadUrl( const std::string& url );
+  void LoadUrl(const std::string& url);
 
   /**
    * @brief Loads a given string as web contents.
    *
    * @param [in] htmlString The string to use as the contents of the web page
    */
-  void LoadHTMLString( const std::string& htmlString );
+  void LoadHtmlString(const std::string& htmlString);
 
   /**
    * @brief Reloads the Web.
@@ -362,6 +301,13 @@ public:
   void Resume();
 
   /**
+   * @brief Scrolls the webpage of view by deltaX and deltaY.
+   * @param[in] deltaX The delta x of scroll
+   * @param[in] deltaY The delta y of scroll
+   */
+  void ScrollBy(int deltaX, int deltaY);
+
+  /**
    * @brief Returns whether forward is possible.
    *
    * @return True if forward is possible, false otherwise
@@ -391,14 +337,14 @@ public:
    * @param[in] script The JavaScript code
    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
    */
-  void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler );
+  void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
 
   /**
    * @brief Evaluates JavaScript code represented as a string.
    *
    * @param[in] script The JavaScript code
    */
-  void EvaluateJavaScript( const std::string& script );
+  void EvaluateJavaScript(const std::string& script);
 
   /**
    * @brief Inject a JavaScript object with a message handler into the WebView.
@@ -424,22 +370,55 @@ public:
    * @param[in] exposedObjectName The name of exposed object
    * @param[in] handler The callback function
    */
-  void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
+  void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
 
   /**
-   * @brief Clears the history of Web.
+   * @brief Register alert callback for javascript.
+   *
+   * @param[in] callback The callback function to be called by the JavaScript runtime.
    */
-  void ClearHistory();
+  void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
+
+  /**
+   * @brief Reply for JavaScript alert.
+   */
+  void JavaScriptAlertReply();
+
+  /**
+   * @brief Register confirm callback for javascript.
+   *
+   * @param[in] callback The callback function to be called by the JavaScript runtime.
+   */
+  void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
+
+  /**
+   * @brief Reply for JavaScript confirm.
+   * @param[in] confirmed True if confirmed, false otherwise
+   */
+  void JavaScriptConfirmReply(bool confirmed);
+
+  /**
+   * @brief Register prompt callback for javascript.
+   *
+   * @param[in] callback The callback function to be called by the JavaScript runtime.
+   */
+  void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
+
+  /**
+   * @brief Reply for JavaScript prompt.
+   * @param[in] result The result from input-field of prompt popup.
+   */
+  void JavaScriptPromptReply(const std::string& result);
 
   /**
-   * @brief Clears the cache of Web.
+   * @brief Clears the history of Web.
    */
-  void ClearCache();
+  void ClearHistory();
 
   /**
-   * @brief Clears all the cookies of Web.
+   * @brief Clears all tiles resources of Web.
    */
-  void ClearCookies();
+  void ClearAllTilesResources();
 
   /**
    * @brief Connects to this signal to be notified when page loading is started.
@@ -449,6 +428,13 @@ public:
   WebViewPageLoadSignalType& PageLoadStartedSignal();
 
   /**
+   * @brief Connects to this signal to be notified when page loading is in progress.
+   *
+   * @return A signal object to connect with.
+   */
+  WebViewPageLoadSignalType& PageLoadInProgressSignal();
+
+  /**
    * @brief Connects to this signal to be notified when page loading is finished.
    *
    * @return A signal object to connect with
@@ -462,24 +448,36 @@ public:
    */
   WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
 
-public: // Not intended for application developers
+  /**
+   * @brief Connects to this signal to be notified when scroll edge is reached.
+   *
+   * @return A signal object to connect with.
+   */
+  WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
 
+  /**
+   * @brief Connects to this signal to be notified when url is changed.
+   *
+   * @return A signal object to connect with.
+   */
+  WebViewUrlChangedSignalType& UrlChangedSignal();
+
+public: // Not intended for application developers
   /// @cond internal
   /**
    * @brief Creates a handle using the Toolkit::Internal implementation.
    *
    * @param[in] implementation The WebView implementation
    */
-  DALI_INTERNAL WebView( Internal::WebView& implementation );
+  DALI_INTERNAL WebView(Internal::WebView& implementation);
 
   /**
    * @brief Allows the creation of this WebView from an Internal::CustomActor pointer.
    *
    * @param[in] internal A pointer to the internal CustomActor
    */
-  explicit DALI_INTERNAL WebView( Dali::Internal::CustomActor* internal );
+  explicit DALI_INTERNAL WebView(Dali::Internal::CustomActor* internal);
   /// @endcond
-
 };
 
 /**