Add some APIs into web view. 33/250133/5
authorhuayong.xu <huayong.xu@samsung.com>
Mon, 21 Dec 2020 02:58:30 +0000 (10:58 +0800)
committerhuayong.xu <huayong.xu@samsung.com>
Fri, 22 Jan 2021 11:02:16 +0000 (19:02 +0800)
Create, GetTitle, GetFavicon, etc are added.

Change-Id: Ifc6b20704d416b19055b8d242d2aea9863783f29

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp
automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp
dali-toolkit/devel-api/controls/web-view/web-view.cpp
dali-toolkit/devel-api/controls/web-view/web-view.h
dali-toolkit/internal/controls/web-view/web-view-impl.cpp
dali-toolkit/internal/controls/web-view/web-view-impl.h

index e5077fe..48676ea 100755 (executable)
@@ -23,6 +23,7 @@
 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
 #include <dali/devel-api/adaptor-framework/web-engine-settings.h>
+#include <dali/public-api/images/pixel-data.h>
 #include <dali/public-api/object/any.h>
 #include <dali/public-api/object/base-object.h>
 #include <dali/public-api/adaptor-framework/native-image-source.h>
@@ -352,6 +353,37 @@ public:
     return mUrl;
   }
 
+  std::string GetTitle() const
+  {
+    return std::string("title");
+  }
+
+  Dali::PixelData GetFavicon() const
+  {
+    uint8_t* faviconData = new uint8_t[ 16 ];
+
+    faviconData[ 0 ] = 0xff;
+    faviconData[ 1 ] = 0x00;
+    faviconData[ 2 ] = 0x00;
+    faviconData[ 3 ] = 0xff;
+    faviconData[ 4 ] = 0xff;
+    faviconData[ 5 ] = 0x00;
+    faviconData[ 6 ] = 0x00;
+    faviconData[ 7 ] = 0xff;
+    faviconData[ 8 ] = 0xff;
+    faviconData[ 9 ] = 0x00;
+    faviconData[ 10 ] = 0x00;
+    faviconData[ 11 ] = 0xff;
+    faviconData[ 12 ] = 0xff;
+    faviconData[ 13 ] = 0x00;
+    faviconData[ 14 ] = 0x00;
+    faviconData[ 15 ] = 0xff;
+
+    return Dali::PixelData::New( faviconData, 16, 2, 2,
+                                 Dali::Pixel::Format::RGBA8888,
+                                 Dali::PixelData::ReleaseFunction::DELETE_ARRAY );
+  }
+
   bool CanGoForward() const
   {
     return mHistory.size() > mCurrentPlusOnePos;
@@ -604,6 +636,10 @@ void WebEngine::Create( int width, int height, const std::string& locale, const
 {
 }
 
+void WebEngine::Create( int width, int height, int argc, char** argv )
+{
+}
+
 void WebEngine::Destroy()
 {
 }
@@ -633,6 +669,16 @@ void WebEngine::LoadUrl( const std::string& url )
   return Internal::Adaptor::GetImplementation( *this ).LoadUrl( url );
 }
 
+std::string WebEngine::GetTitle() const
+{
+  return Internal::Adaptor::GetImplementation( *this ).GetTitle();
+}
+
+Dali::PixelData WebEngine::GetFavicon() const
+{
+  return Internal::Adaptor::GetImplementation( *this ).GetFavicon();
+}
+
 const std::string& WebEngine::GetUrl()
 {
   return Internal::Adaptor::GetImplementation( *this ).GetUrl();
@@ -694,6 +740,10 @@ void WebEngine::AddJavaScriptMessageHandler( const std::string& exposedObjectNam
 {
 }
 
+void WebEngine::ClearAllTilesResources()
+{
+}
+
 void WebEngine::ClearHistory()
 {
   Internal::Adaptor::GetImplementation( *this ).ClearHistory();
index 2088d90..0d02ccf 100644 (file)
@@ -24,6 +24,8 @@
 #include <dali.h>
 #include <dali/integration-api/events/key-event-integ.h>
 #include <dali/integration-api/events/touch-event-integ.h>
+#include <dali/public-api/images/pixel-data.h>
+#include <dali-toolkit/public-api/controls/image-view/image-view.h>
 #include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list-item.h>
@@ -32,7 +34,6 @@
 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
 
-
 using namespace Dali;
 using namespace Toolkit;
 
@@ -416,6 +417,33 @@ int UtcDaliWebViewProperty9(void)
   END_TEST;
 }
 
+int UtcDaliWebViewPropertyTitleFavicon(void)
+{
+  // SCROLL_POSITION
+  ToolkitTestApplication application;
+
+  char argv[] = "--test";
+  WebView view = WebView::New( 1, (char**)&argv );
+  DALI_TEST_CHECK( view );
+
+  // reset something
+  view.ClearAllTilesResources();
+
+  // Check default value of title
+  std::string testValue("title");
+  std::string output;
+  view.GetProperty( WebView::Property::TITLE ).Get( output );
+  DALI_TEST_EQUALS( output, testValue, TEST_LOCATION );
+
+  // Check default value of favicon
+  Dali::Toolkit::ImageView* favicon = &view.GetFavicon();
+  DALI_TEST_CHECK( favicon );
+  Dali::Vector3 iconsize = favicon->GetProperty< Vector3 >( Dali::Actor::Property::SIZE );
+  DALI_TEST_CHECK( ( int )iconsize.width == 2 && ( int )iconsize.height == 2 );
+
+  END_TEST;
+}
+
 int UtcDaliWebViewScrollBy(void)
 {
   ToolkitTestApplication application;
index 4c9de03..a0672ae 100755 (executable)
@@ -20,6 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/controls/web-view/web-view-impl.h>
+#include <dali-toolkit/public-api/controls/image-view/image-view.h>
 
 namespace Dali
 {
@@ -58,6 +59,11 @@ WebView WebView::New(const std::string& locale, const std::string& timezoneId)
   return Internal::WebView::New(locale, timezoneId);
 }
 
+WebView WebView::New( int argc, char** argv )
+{
+  return Internal::WebView::New( argc, argv );
+}
+
 WebView WebView::DownCast(BaseHandle handle)
 {
   return Control::DownCast<WebView, Internal::WebView>(handle);
@@ -83,6 +89,11 @@ Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
   return Dali::Toolkit::GetImpl( *this ).GetBackForwardList();
 }
 
+Dali::Toolkit::ImageView& WebView::GetFavicon()
+{
+  return Dali::Toolkit::GetImpl( *this ).GetFavicon();
+}
+
 void WebView::LoadUrl(const std::string& url)
 {
   Dali::Toolkit::GetImpl(*this).LoadUrl(url);
@@ -153,6 +164,11 @@ void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName,
   Dali::Toolkit::GetImpl(*this).AddJavaScriptMessageHandler(exposedObjectName, handler);
 }
 
+void WebView::ClearAllTilesResources()
+{
+  Dali::Toolkit::GetImpl( *this ).ClearAllTilesResources();
+}
+
 void WebView::ClearHistory()
 {
   Dali::Toolkit::GetImpl(*this).ClearHistory();
index 2fa6433..53dfb5a 100755 (executable)
@@ -29,6 +29,7 @@ namespace Dali
 {
 namespace Toolkit
 {
+class ImageView;
 class WebBackForwardList;
 class WebContext;
 class WebCookieManager;
@@ -101,6 +102,13 @@ public:
        * @details Name "contentSize", type Property::VECTOR2. Read-only.
        */
       CONTENT_SIZE,
+
+      /**
+       * @brief The title of web page.
+       * @details Name "title", type Property::STRING.
+       * @note The value is read-only.
+       */
+      TITLE,
     };
   };
 
@@ -218,6 +226,14 @@ public:
   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.
    */
   WebView();
@@ -276,6 +292,13 @@ public:
   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
@@ -382,6 +405,11 @@ public:
   void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
 
   /**
+   * @brief Clears all tiles resources of Web.
+   */
+  void ClearAllTilesResources();
+
+  /**
    * @brief Clears the history of Web.
    */
   void ClearHistory();
index 2369acf..e89afab 100755 (executable)
@@ -39,6 +39,7 @@
 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
+#include <dali-toolkit/public-api/image-loader/image.h>
 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
 
 namespace Dali
@@ -65,6 +66,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "userAgent",               STRING,
 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollPosition",          VECTOR2, SCROLL_POSITION            )
 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollSize",              VECTOR2, SCROLL_SIZE                )
 DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "contentSize",             VECTOR2, CONTENT_SIZE               )
+DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "title",                   STRING,  TITLE                      )
 
 DALI_SIGNAL_REGISTRATION(   Toolkit, WebView, "pageLoadStarted",         PAGE_LOAD_STARTED_SIGNAL            )
 DALI_SIGNAL_REGISTRATION(   Toolkit, WebView, "pageLoadFinished",        PAGE_LOAD_FINISHED_SIGNAL           )
@@ -102,6 +104,25 @@ WebView::WebView( const std::string& locale, const std::string& timezoneId )
   }
 }
 
+WebView::WebView( int argc, char** argv )
+: Control( ControlBehaviour( ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS ) ),
+  mUrl(),
+  mVisual(),
+  mWebViewSize( Stage::GetCurrent().GetSize() ),
+  mWebEngine(),
+  mPageLoadStartedSignal(),
+  mPageLoadFinishedSignal(),
+  mPageLoadErrorSignal()
+{
+  mWebEngine = Dali::WebEngine::New();
+
+  // WebEngine is empty when it is not properly initialized.
+  if ( mWebEngine )
+  {
+    mWebEngine.Create( mWebViewSize.width, mWebViewSize.height, argc, argv );
+  }
+}
+
 WebView::WebView()
 : WebView( "", "" )
 {
@@ -129,6 +150,15 @@ Toolkit::WebView WebView::New( const std::string& locale, const std::string& tim
   return handle;
 }
 
+Toolkit::WebView WebView::New( int argc, char** argv )
+{
+  WebView* impl = new WebView( argc, argv );
+  Toolkit::WebView handle = Toolkit::WebView( *impl );
+
+  impl->Initialize();
+  return handle;
+}
+
 void WebView::OnInitialize()
 {
   Self().SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
@@ -168,6 +198,19 @@ Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
   return mWebBackForwardList.get();
 }
 
+Dali::Toolkit::ImageView& WebView::GetFavicon()
+{
+  if ( mWebEngine )
+  {
+    Dali::PixelData pixelData = mWebEngine.GetFavicon();
+    std::string url = Dali::Toolkit::Image::GenerateUrl( pixelData );
+    mFaviconView = Dali::Toolkit::ImageView::New( url );
+    mFaviconView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+    mFaviconView.SetProperty( Dali::Actor::Property::SIZE, Vector2( pixelData.GetWidth(), pixelData.GetHeight() ) );
+  }
+  return mFaviconView;
+}
+
 void WebView::LoadUrl( const std::string& url )
 {
   mUrl = url;
@@ -288,6 +331,14 @@ void WebView::AddJavaScriptMessageHandler( const std::string& exposedObjectName,
   }
 }
 
+void WebView::ClearAllTilesResources()
+{
+  if( mWebEngine )
+  {
+    mWebEngine.ClearAllTilesResources();
+  }
+}
+
 void WebView::ClearHistory()
 {
   if( mWebEngine )
@@ -492,6 +543,11 @@ Property::Value WebView::GetProperty( BaseObject* object, Property::Index proper
         value = Vector2( width, height );
         break;
       }
+      case Toolkit::WebView::Property::TITLE:
+      {
+        value = impl.GetTitle();
+        break;
+      }
       default:
          break;
     }
@@ -574,6 +630,11 @@ void WebView::GetContentSize( int& width, int& height ) const
   }
 }
 
+std::string WebView::GetTitle() const
+{
+  return mWebEngine ?  mWebEngine.GetTitle() : kEmptyString;
+}
+
 const std::string& WebView::GetUserAgent() const
 {
   return mWebEngine ? mWebEngine.GetUserAgent() : kEmptyString;
index 4769110..e3e61b3 100755 (executable)
@@ -27,6 +27,7 @@
 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali-toolkit/public-api/controls/image-view/image-view.h>
 
 namespace Dali
 {
@@ -53,6 +54,8 @@ protected:
 
   WebView( const std::string& locale, const std::string& timezoneId );
 
+  WebView( int argc, char** argv );
+
   virtual ~WebView();
 
 public:
@@ -88,6 +91,18 @@ public:
   Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
 
   /**
+   * @copydoc Dali::Toolkit::WebView::New( int, char** )
+   */
+  static Toolkit::WebView New( int argc, char** argv );
+
+  /**
+   * @brief Get Favicon of web page.
+   *
+   * @return Handle to a fav icon
+   */
+  Dali::Toolkit::ImageView& GetFavicon();
+
+  /**
    * @copydoc Dali::Toolkit::WebView::LoadUrl()
    */
   void LoadUrl( const std::string& url );
@@ -153,6 +168,11 @@ public:
   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
 
   /**
+   * @brief Clears all tiles resources of Web.
+   */
+  void ClearAllTilesResources();
+
+  /**
    * @copydoc Dali::Toolkit::WebView::ClearHistory()
    */
   void ClearHistory();
@@ -284,6 +304,13 @@ private:
   void GetContentSize( int& width, int& height ) const;
 
   /**
+   * @brief Returns the title of the Web.
+   *
+   * @return The title of web page
+   */
+  std::string GetTitle() const;
+
+  /**
    * @brief Get user agent string.
    * @return The string value of user agent
    */
@@ -336,6 +363,7 @@ private:
   std::unique_ptr<Dali::Toolkit::WebCookieManager>       mWebCookieManager;
   std::unique_ptr<Dali::Toolkit::WebSettings>            mWebSettings;
   std::unique_ptr<Dali::Toolkit::WebBackForwardList>     mWebBackForwardList;
+  Dali::Toolkit::ImageView mFaviconView;
 };
 
 } // namespace Internal