Update position & size of web view. 72/247972/13
authorhuayong.xu <huayong.xu@samsung.com>
Mon, 9 Nov 2020 10:20:07 +0000 (18:20 +0800)
committerhuayong.xu <huayong.xu@samsung.com>
Fri, 29 Jan 2021 10:37:56 +0000 (18:37 +0800)
Originally position of web engine is not updated when position of
web view is changed.
This patch is to update position & size of web view.

Change-Id: I84ff062363ff0d20c8e60c26d57a9f00d47c7305

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.h
dali-toolkit/internal/controls/web-view/web-view-impl.cpp
dali-toolkit/internal/controls/web-view/web-view-impl.h

index d6419ff..9aa5155 100755 (executable)
 #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/adaptor-framework/native-image-source.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>
 #include <toolkit-application.h>
 
 namespace Dali
@@ -799,6 +799,14 @@ void WebEngine::SetFocus( bool focused )
 {
 }
 
+void WebEngine::UpdateDisplayArea( Dali::Rect< int > displayArea )
+{
+}
+
+void WebEngine::EnableVideoHole( bool enabled )
+{
+}
+
 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadStartedSignal()
 {
   return Internal::Adaptor::GetImplementation( *this ).PageLoadStartedSignal();
index 0d02ccf..28863cf 100644 (file)
@@ -290,6 +290,54 @@ int UtcDaliWebViewFocusGainedAndLost(void)
   END_TEST;
 }
 
+int UtcDaliWebViewMove(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK( view );
+
+  view.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+  view.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+  view.SetProperty( Actor::Property::POSITION, Vector2( 0, 0 ));
+  view.SetProperty( Actor::Property::SIZE, Vector2( 800, 600 ) );
+
+  application.GetScene().Add( view );
+  application.SendNotification();
+  application.Render();
+
+  view.SetProperty( Actor::Property::POSITION, Vector2( 100, 100 ));
+  Vector3 viewPos = view.GetProperty<Vector3>( Actor::Property::POSITION );
+  DALI_TEST_EQUALS( viewPos, Vector3( 100, 100, 0 ), TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliWebViewPropertyVideoHole(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK( view );
+
+  const bool kDefaultValue = true;
+  const bool kTestValue = false;
+
+  // Check default value
+  bool output;
+  Property::Value value = view.GetProperty( WebView::Property::VIDEO_HOLE_ENABLED );
+  DALI_TEST_CHECK( value.Get( output ) );
+  DALI_TEST_EQUALS( output, kDefaultValue, TEST_LOCATION );
+
+  // Check Set/GetProperty
+  view.SetProperty( WebView::Property::VIDEO_HOLE_ENABLED, kTestValue );
+  value = view.GetProperty( WebView::Property::VIDEO_HOLE_ENABLED );
+  DALI_TEST_CHECK( value.Get( output ) );
+  DALI_TEST_EQUALS( output, kTestValue, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliWebViewGetWebBackForwardList(void)
 {
   ToolkitTestApplication application;
index 0380c26..48e57ce 100755 (executable)
@@ -81,34 +81,43 @@ public:
 
       /**
        * @brief The user agent string.
-       * @details Name "userAgent", type Property::STRING.
+       * @details name "userAgent", type Property::STRING.
        */
       USER_AGENT,
 
       /**
        * @brief The current position of scroll.
-       * @details Name "scrollPosition", type Property::VECTOR2.
+       * @details name "scrollPosition", type Property::VECTOR2.
        */
       SCROLL_POSITION,
 
       /**
-       * @brief The current position of scroll.
-       * @details Name "scrollSize", type Property::VECTOR2. Read-only.
+       * @brief The current size of scroll.
+       * @details name "scrollSize", type Property::VECTOR2.
+       * @note The value is read-only.
        */
       SCROLL_SIZE,
 
       /**
-       * @brief The current position of scroll.
-       * @details Name "contentSize", type Property::VECTOR2. Read-only.
+       * @brief The current size of content.
+       * @details name "contentSize", type Property::VECTOR2.
+       * @note The value is read-only.
        */
       CONTENT_SIZE,
 
       /**
        * @brief The title of web page.
-       * @details Name "title", type Property::STRING.
+       * @details name "title", type Property::STRING.
        * @note The value is read-only.
        */
       TITLE,
+
+      /**
+       * @brief Whether video hole is enabled or not.
+       * @details name "videoHoleEnabled", type Property::BOOLEAN.
+       * @note The value is read-only.
+       */
+      VIDEO_HOLE_ENABLED,
     };
   };
 
@@ -117,80 +126,21 @@ 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.
   };
 
   /**
index 78015c9..27fee70 100755 (executable)
@@ -67,6 +67,7 @@ DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "scrollPosition",          VECTOR2
 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_PROPERTY_REGISTRATION( Toolkit, WebView, "videoHoleEnabled",        BOOLEAN, VIDEO_HOLE_ENABLED         )
 
 DALI_SIGNAL_REGISTRATION(   Toolkit, WebView, "pageLoadStarted",         PAGE_LOAD_STARTED_SIGNAL            )
 DALI_SIGNAL_REGISTRATION(   Toolkit, WebView, "pageLoadFinished",        PAGE_LOAD_FINISHED_SIGNAL           )
@@ -93,7 +94,9 @@ WebView::WebView( const std::string& locale, const std::string& timezoneId )
   mWebEngine(),
   mPageLoadStartedSignal(),
   mPageLoadFinishedSignal(),
-  mPageLoadErrorSignal()
+  mPageLoadErrorSignal(),
+  mVideoHoleEnabled( true ),
+  mWebViewArea ( 0, 0, mWebViewSize.width, mWebViewSize.height )
 {
   mWebEngine = Dali::WebEngine::New();
 
@@ -112,7 +115,9 @@ WebView::WebView( int argc, char** argv )
   mWebEngine(),
   mPageLoadStartedSignal(),
   mPageLoadFinishedSignal(),
-  mPageLoadErrorSignal()
+  mPageLoadErrorSignal(),
+  mVideoHoleEnabled( true ),
+  mWebViewArea ( 0, 0, mWebViewSize.width, mWebViewSize.height )
 {
   mWebEngine = Dali::WebEngine::New();
 
@@ -130,6 +135,10 @@ WebView::WebView()
 
 WebView::~WebView()
 {
+  if( mWebEngine )
+  {
+    mWebEngine.Destroy();
+  }
 }
 
 Toolkit::WebView WebView::New()
@@ -161,8 +170,17 @@ Toolkit::WebView WebView::New( int argc, char** argv )
 
 void WebView::OnInitialize()
 {
-  Self().SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
-  Self().TouchedSignal().Connect( this, &WebView::OnTouchEvent );
+  Actor self = Self();
+
+  self.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE, true );
+  self.TouchedSignal().Connect( this, &WebView::OnTouchEvent );
+
+  mPositionUpdateNotification = self.AddPropertyNotification( Actor::Property::WORLD_POSITION, StepCondition( 1.0f, 1.0f ) );
+  mSizeUpdateNotification = self.AddPropertyNotification( Actor::Property::SIZE, StepCondition( 1.0f, 1.0f ) );
+  mScaleUpdateNotification = self.AddPropertyNotification( Actor::Property::WORLD_SCALE, StepCondition( 0.1f, 1.0f ) );
+  mPositionUpdateNotification.NotifySignal().Connect( this, &WebView::UpdateDisplayArea );
+  mSizeUpdateNotification.NotifySignal().Connect( this, &WebView::UpdateDisplayArea );
+  mScaleUpdateNotification.NotifySignal().Connect( this, &WebView::UpdateDisplayArea );
 
   if( mWebEngine )
   {
@@ -228,6 +246,11 @@ void WebView::LoadUrl( const std::string& url )
       DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual );
       mWebEngine.LoadUrl( url );
     }
+
+    if ( mVideoHoleEnabled )
+    {
+      EnableBlendMode( false );
+    }
   }
 }
 
@@ -246,6 +269,11 @@ void WebView::LoadHtmlString( const std::string& htmlString )
       DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual );
       mWebEngine.LoadHtmlString( htmlString );
     }
+
+    if ( mVideoHoleEnabled )
+    {
+      EnableBlendMode( false );
+    }
   }
 }
 
@@ -347,6 +375,59 @@ void WebView::ClearHistory()
   }
 }
 
+void WebView::UpdateDisplayArea( Dali::PropertyNotification& /*source*/ )
+{
+  if( !mWebEngine )
+    return;
+
+  Actor self( Self() );
+
+  bool positionUsesAnchorPoint = self.GetProperty< bool >( Actor::Property::POSITION_USES_ANCHOR_POINT );
+  Vector3 actorSize = self.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) * self.GetCurrentProperty< Vector3 >( Actor::Property::SCALE );
+  Vector3 anchorPointOffSet = actorSize * ( positionUsesAnchorPoint ? self.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ) : AnchorPoint::TOP_LEFT );
+  Vector2 screenPosition = self.GetProperty< Vector2 >( Actor::Property::SCREEN_POSITION );
+
+  Dali::Rect< int > displayArea;
+  displayArea.x = screenPosition.x - anchorPointOffSet.x;
+  displayArea.y = screenPosition.y - anchorPointOffSet.y;
+  displayArea.width = actorSize.x;
+  displayArea.height = actorSize.y;
+
+  Size displaySize = Size( displayArea.width, displayArea.height );
+  if ( mWebViewSize != displaySize )
+  {
+    mWebViewSize = displaySize;
+  }
+
+  if (mWebViewArea != displayArea )
+  {
+    mWebViewArea = displayArea;
+    mWebEngine.UpdateDisplayArea( mWebViewArea );
+  }
+}
+
+void WebView::EnableVideoHole( bool enabled )
+{
+  mVideoHoleEnabled = enabled;
+
+  EnableBlendMode( !mVideoHoleEnabled );
+
+  if( mWebEngine )
+  {
+    mWebEngine.EnableVideoHole( mVideoHoleEnabled );
+  }
+}
+
+void WebView::EnableBlendMode( bool blendEnabled )
+{
+  Actor self = Self();
+  for (uint32_t i = 0; i < self.GetRendererCount(); i++)
+  {
+    Dali::Renderer render = self.GetRendererAt( i );
+    render.SetProperty( Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF );
+  }
+}
+
 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal()
 {
   return mPageLoadStartedSignal;
@@ -446,19 +527,11 @@ Vector3 WebView::GetNaturalSize()
   return Vector3( mWebViewSize );
 }
 
-void WebView::OnRelayout( const Vector2& size, RelayoutContainer& container )
+void WebView::OnSceneConnection( int depth )
 {
-  Control::OnRelayout( size, container );
-
-  if( size.width > 0 && size.height > 0 && mWebViewSize != size )
-  {
-    mWebViewSize = size;
+  Control::OnSceneConnection( depth );
 
-    if( mWebEngine )
-    {
-      mWebEngine.SetSize( size.width, size.height );
-    }
-  }
+  EnableBlendMode( !mVideoHoleEnabled );
 }
 
 void WebView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
@@ -497,6 +570,15 @@ void WebView::SetProperty( BaseObject* object, Property::Index index, const Prop
         }
         break;
       }
+      case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
+      {
+        bool input;
+        if( value.Get( input ) )
+        {
+          impl.EnableVideoHole( input );
+        }
+        break;
+      }
     }
   }
 }
@@ -542,6 +624,11 @@ Property::Value WebView::GetProperty( BaseObject* object, Property::Index proper
         value = impl.GetTitle();
         break;
       }
+      case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
+      {
+        value = impl.mVideoHoleEnabled;
+        break;
+      }
       default:
          break;
     }
index 14fb0b5..572688b 100755 (executable)
@@ -22,6 +22,7 @@
 #include <memory>
 #include <dali/devel-api/adaptor-framework/web-engine.h>
 #include <dali/public-api/images/image-operations.h>
+#include <dali/public-api/object/property-notification.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
@@ -241,11 +242,6 @@ private: // From Control
   Vector3 GetNaturalSize() override;
 
   /**
-   * @copydoc Toolkit::Control::OnRelayout()
-   */
-  void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
-
-  /**
    * Signal occurs when the Web View has been touched.
    * @param[in] actor The Actor Touched
    * @param[in] touch The Touch Data.
@@ -268,6 +264,11 @@ private: // From Control
    */
   void OnKeyInputFocusLost() override;
 
+  /**
+   * @copydoc Toolkit::Control::OnSceneConnection()
+   */
+  void OnSceneConnection( int depth ) override;
+
 private:
 
   // Undefined
@@ -323,6 +324,24 @@ private:
   void SetUserAgent( const std::string& userAgent );
 
   /**
+   * @brief Updates display area of web view.
+   * @param[in] source The soource triggers Notification.
+   */
+  void UpdateDisplayArea( Dali::PropertyNotification& source );
+
+  /**
+   * @brief Enable/Disable video hole for video playing.
+   * @param[in] enabled True if video hole is enabled, false otherwise.
+   */
+  void EnableVideoHole( bool enabled );
+
+  /**
+   * @brief Enable blend mode.
+   * @param[in] blendEnabled True if turn on blend mode, false otherwise.
+   */
+  void EnableBlendMode( bool blendEnabled );
+
+  /**
    * @brief Callback function to be called when page load started.
    * @param[in] url The url currently being loaded
    */
@@ -364,6 +383,12 @@ private:
   std::unique_ptr<Dali::Toolkit::WebSettings>            mWebSettings;
   std::unique_ptr<Dali::Toolkit::WebBackForwardList>     mWebBackForwardList;
   Dali::Toolkit::ImageView mFaviconView;
+
+  Dali::PropertyNotification                             mPositionUpdateNotification;
+  Dali::PropertyNotification                             mSizeUpdateNotification;
+  Dali::PropertyNotification                             mScaleUpdateNotification;
+  bool                                                   mVideoHoleEnabled;
+  Dali::Rect< int >                                      mWebViewArea;
 };
 
 } // namespace Internal