X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fweb-view%2Fweb-view-impl.cpp;h=9edac2ddf76628dd62655662ed49db4bd6241569;hb=HEAD;hp=09bea4528f0c4aa50f95c8ab30d043f520c3addd;hpb=d165d8d6936dfe8746d720dd82ee1b033ce3e4c8;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp old mode 100755 new mode 100644 index 09bea45..ff4665e --- a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -16,41 +16,47 @@ */ // CLASS HEADER -#include "web-view-impl.h" +#include // EXTERNAL INCLUDES -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include +#include #include #include #include -#include -#include // INTERNAL INCLUDES +#include #include #include -#include -#include #include +#include +#include #include -#include #include +#include #include +#include + +#include +#include +#include namespace Dali { @@ -89,24 +95,80 @@ DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage", FLOAT, DALI_TYPE_REGISTRATION_END() // clang-format on -} // namespace +std::unordered_map>& GetPluginWebViewTable() +{ + static std::unordered_map> pluginWebViewMap; + return pluginWebViewMap; +} -#define GET_ENUM_STRING(structName, inputExp) \ - Scripting::GetLinearEnumerationName(static_cast(inputExp), structName##_TABLE, structName##_TABLE_COUNT) +enum class DisplayAreaCalculateOption +{ + PROPERTY = 0, ///< Calculate display update area by property + CURRENT_PROPERTY = 1, ///< Calculate display update area by current property +}; -#define GET_ENUM_VALUE(structName, inputExp, outputExp) \ - Scripting::GetEnumerationProperty(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp) +/** + * @brief Helper function to calculate exact display area, offset and size. + * It will be useful when view size is not integer value, or view size is not matched with texture size. + * + * @param[in] self The view itself. + * @param[in] option Option of this calculation. Let we decide what kind of property will be used. + * @return DisplayArea for this view. + */ +Rect CalculateDisplayArea(Dali::Actor self, DisplayAreaCalculateOption option) +{ + bool positionUsesAnchorPoint = self.GetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT); + Vector3 actorSize = (option == DisplayAreaCalculateOption::CURRENT_PROPERTY) ? self.GetCurrentProperty(Actor::Property::SIZE) * self.GetCurrentProperty(Actor::Property::SCALE) + : self.GetProperty(Actor::Property::SIZE) * self.GetProperty(Actor::Property::SCALE); + Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT); + Vector2 screenPosition = (option == DisplayAreaCalculateOption::CURRENT_PROPERTY) ? self.GetProperty(Actor::Property::SCREEN_POSITION) + : Dali::DevelActor::CalculateScreenPosition(self); + + Dali::Rect displayArea; + displayArea.x = screenPosition.x - anchorPointOffSet.x; + displayArea.y = screenPosition.y - anchorPointOffSet.y; + displayArea.width = actorSize.x; + displayArea.height = actorSize.y; + + return displayArea; +} + +constexpr Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f); + +/** + * @brief Helper function to calculate exact pixel area value by view and texture size. + * It will be useful when view size is not integer value, or view size is not matched with texture size. + * + * @param[in] viewSize The size of view. + * @param[in] textureWidth The width of texture, that must be integer type. + * @param[in] textureHeight The height of texture, that must be integer type. + * @return PixelArea value that image visual can use. + */ +Vector4 CalculatePixelArea(const Size& viewSize, const uint32_t textureWidth, const uint32_t textureHeight) +{ + float widthRatio = textureWidth == 0u ? 1.0f : viewSize.width / static_cast(textureWidth); + float heightRatio = textureHeight == 0u ? 1.0f : viewSize.height / static_cast(textureHeight); + return Vector4(0.0f, 0.0f, widthRatio, heightRatio); +} + +} // namespace WebView::WebView(const std::string& locale, const std::string& timezoneId) : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)), mVisual(), mWebViewSize(Stage::GetCurrent().GetSize()), mWebEngine(), + mLastRenderedNativeImageWidth(0u), + mLastRenderedNativeImageHeight(0u), mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height), mVideoHoleEnabled(false), mMouseEventsEnabled(true), mKeyEventsEnabled(true), - mScreenshotCapturedCallback(nullptr) + mVisualChangeRequired(false), + mScreenshotCapturedCallback{nullptr}, + mFrameRenderedCallback{nullptr}, + mCornerRadius(Vector4::ZERO), + mCornerRadiusPolicy(1.0f) { mWebEngine = Dali::WebEngine::New(); @@ -122,11 +184,17 @@ WebView::WebView(uint32_t argc, char** argv) mVisual(), mWebViewSize(Stage::GetCurrent().GetSize()), mWebEngine(), + mLastRenderedNativeImageWidth(0u), + mLastRenderedNativeImageHeight(0u), mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height), mVideoHoleEnabled(false), mMouseEventsEnabled(true), mKeyEventsEnabled(true), - mScreenshotCapturedCallback(nullptr) + mVisualChangeRequired(false), + mScreenshotCapturedCallback{nullptr}, + mFrameRenderedCallback{nullptr}, + mCornerRadius(Vector4::ZERO), + mCornerRadiusPolicy(1.0f) { mWebEngine = Dali::WebEngine::New(); @@ -146,7 +214,11 @@ WebView::~WebView() { if(mWebEngine) { - mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnFrameRendered); + auto iter = GetPluginWebViewTable().find(mWebEngine.GetPlugin()); + if(iter != GetPluginWebViewTable().end()) + { + GetPluginWebViewTable().erase(iter); + } mWebEngine.Destroy(); } } @@ -155,7 +227,10 @@ Toolkit::WebView WebView::New() { WebView* impl = new WebView(); Toolkit::WebView handle = Toolkit::WebView(*impl); - + if(impl->GetPlugin()) + { + GetPluginWebViewTable()[impl->GetPlugin()] = handle; + } impl->Initialize(); return handle; } @@ -164,7 +239,10 @@ Toolkit::WebView WebView::New(const std::string& locale, const std::string& time { WebView* impl = new WebView(locale, timezoneId); Toolkit::WebView handle = Toolkit::WebView(*impl); - + if(impl->GetPlugin()) + { + GetPluginWebViewTable()[impl->GetPlugin()] = handle; + } impl->Initialize(); return handle; } @@ -173,34 +251,69 @@ Toolkit::WebView WebView::New(uint32_t argc, char** argv) { WebView* impl = new WebView(argc, argv); Toolkit::WebView handle = Toolkit::WebView(*impl); - + if(impl->GetPlugin()) + { + GetPluginWebViewTable()[impl->GetPlugin()] = handle; + } impl->Initialize(); return handle; } +Toolkit::WebView WebView::FindWebView(Dali::WebEnginePlugin* plugin) +{ + auto iter = GetPluginWebViewTable().find(plugin); + if(iter != GetPluginWebViewTable().end()) + { + return iter->second.GetHandle(); + } + return Toolkit::WebView(); +} + +Dali::WebEngineContext* WebView::GetContext() +{ + return Dali::WebEngine::GetContext(); +} + +Dali::WebEngineCookieManager* WebView::GetCookieManager() +{ + return Dali::WebEngine::GetCookieManager(); +} + void WebView::OnInitialize() { Actor self = Self(); self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); - self.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true); self.TouchedSignal().Connect(this, &WebView::OnTouchEvent); self.HoveredSignal().Connect(this, &WebView::OnHoverEvent); self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent); - Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged); + self.InheritedVisibilityChangedSignal().Connect(this, &WebView::OnInheritedVisibilityChanged); 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); + mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated); + mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated); + mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated); + + // Create WebVisual for WebView + Property::Map propertyMap; + propertyMap.Insert(Dali::Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::COLOR); + propertyMap.Insert(Dali::Toolkit::Visual::Property::MIX_COLOR, Color::TRANSPARENT); + Toolkit::Visual::Base webVisual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap); + if(webVisual) + { + Dali::Toolkit::DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, webVisual); + } + else + { + DALI_LOG_ERROR("fail to create webVisual for CornerRadius"); + Dali::Toolkit::DevelControl::UnregisterVisual(*this, Toolkit::WebView::Property::URL); + } if(mWebEngine) { - mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered); - mWebContext = std::unique_ptr(new WebContext(mWebEngine.GetContext())); - mWebCookieManager = std::unique_ptr(new WebCookieManager(mWebEngine.GetCookieManager())); + mWebEngine.RegisterFrameRenderedCallback(std::bind(&WebView::OnFrameRendered, this)); mWebSettings = std::unique_ptr(new WebSettings(mWebEngine.GetSettings())); mWebBackForwardList = std::unique_ptr(new WebBackForwardList(mWebEngine.GetBackForwardList())); } @@ -213,19 +326,29 @@ DevelControl::ControlAccessible* WebView::CreateAccessibleObject() return new WebViewAccessible(Self(), mWebEngine); } -Dali::Toolkit::WebSettings* WebView::GetSettings() const +void WebView::OnRelayout(const Vector2& size, RelayoutContainer& container) { - return mWebSettings.get(); + if(!mWebEngine) + { + return; + } + + auto displayArea = CalculateDisplayArea(Self(), DisplayAreaCalculateOption::PROPERTY); + + SetDisplayArea(displayArea); } -Dali::Toolkit::WebContext* WebView::GetContext() const +void WebView::ChangeOrientation(int orientation) { - return mWebContext.get(); + if(mWebEngine) + { + mWebEngine.ChangeOrientation(orientation); + } } -Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const +Dali::Toolkit::WebSettings* WebView::GetSettings() const { - return mWebCookieManager.get(); + return mWebSettings.get(); } Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const @@ -233,6 +356,11 @@ Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const return mWebBackForwardList.get(); } +Dali::WebEnginePlugin* WebView::GetPlugin() const +{ + return mWebEngine ? mWebEngine.GetPlugin() : nullptr; +} + Dali::Toolkit::ImageView WebView::GetFavicon() const { Dali::Toolkit::ImageView faviconView; @@ -248,11 +376,6 @@ void WebView::LoadUrl(const std::string& url) { if(mWebEngine) { - if(!mVisual) - { - mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered); - } - mWebEngine.LoadUrl(url); } } @@ -261,11 +384,6 @@ void WebView::LoadHtmlString(const std::string& htmlString) { if(mWebEngine) { - if(!mVisual) - { - mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered); - } - mWebEngine.LoadHtmlString(htmlString); } } @@ -275,24 +393,14 @@ bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const if(!mWebEngine) return false; - if(!mVisual) - { - mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered); - } - return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl); } -bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) +bool WebView::LoadContents(const int8_t* contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri) { if(!mWebEngine) return false; - if(!mVisual) - { - mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered); - } - return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri); } @@ -412,7 +520,7 @@ void WebView::EvaluateJavaScript(const std::string& script, std::function viewArea, fl bool WebView::GetScreenshotAsynchronously(Dali::Rect viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback) { - mScreenshotCapturedCallback = callback; + mScreenshotCapturedCallback = std::move(callback); return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false; } bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback) { - return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false; + return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(std::move(callback)) : false; } -void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback) +void WebView::ExitFullscreen() { if(mWebEngine) { - mWebEngine.RegisterGeolocationPermissionCallback(callback); + mWebEngine.ExitFullscreen(); } } -void WebView::SetTtsFocus(bool focused) +void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback) { - if(mWebEngine && !HasKeyInputFocus()) + if(mWebEngine) { - mWebEngine.SetFocus(focused); + mWebEngine.RegisterGeolocationPermissionCallback(std::move(callback)); } } -void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/) +void WebView::SetTtsFocus(bool focused) { - if(!mWebEngine) - return; - - Actor self(Self()); - - bool positionUsesAnchorPoint = self.GetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT); - Vector3 actorSize = self.GetCurrentProperty(Actor::Property::SIZE) * self.GetCurrentProperty(Actor::Property::SCALE); - Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT); - Vector2 screenPosition = self.GetProperty(Actor::Property::SCREEN_POSITION); - - Dali::Rect 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) + if(mWebEngine && !HasKeyInputFocus()) { - mWebViewArea = displayArea; - mWebEngine.UpdateDisplayArea(mWebViewArea); + mWebEngine.SetFocus(focused); } } @@ -651,7 +744,7 @@ void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePa { if(mWebEngine) { - mWebEngine.RegisterPageLoadStartedCallback(callback); + mWebEngine.RegisterPageLoadStartedCallback(std::move(callback)); } } @@ -659,7 +752,7 @@ void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEngin { if(mWebEngine) { - mWebEngine.RegisterPageLoadInProgressCallback(callback); + mWebEngine.RegisterPageLoadInProgressCallback(std::move(callback)); } } @@ -667,7 +760,7 @@ void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEngineP { if(mWebEngine) { - mWebEngine.RegisterPageLoadFinishedCallback(callback); + mWebEngine.RegisterPageLoadFinishedCallback(std::move(callback)); } } @@ -675,7 +768,7 @@ void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePage { if(mWebEngine) { - mWebEngine.RegisterPageLoadErrorCallback(callback); + mWebEngine.RegisterPageLoadErrorCallback(std::move(callback)); } } @@ -683,7 +776,7 @@ void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngine { if(mWebEngine) { - mWebEngine.RegisterScrollEdgeReachedCallback(callback); + mWebEngine.RegisterScrollEdgeReachedCallback(std::move(callback)); } } @@ -691,7 +784,7 @@ void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChan { if(mWebEngine) { - mWebEngine.RegisterUrlChangedCallback(callback); + mWebEngine.RegisterUrlChangedCallback(std::move(callback)); } } @@ -699,20 +792,20 @@ void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngine { if(mWebEngine) { - mWebEngine.RegisterFormRepostDecidedCallback(callback); + mWebEngine.RegisterFormRepostDecidedCallback(std::move(callback)); } } void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback) { - mFrameRenderedCallback = callback; + mFrameRenderedCallback = std::move(callback); } void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback) { if(mWebEngine) { - mWebEngine.RegisterConsoleMessageReceivedCallback(callback); + mWebEngine.RegisterConsoleMessageReceivedCallback(std::move(callback)); } } @@ -720,7 +813,7 @@ void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEn { if(mWebEngine) { - mWebEngine.RegisterResponsePolicyDecidedCallback(callback); + mWebEngine.RegisterResponsePolicyDecidedCallback(std::move(callback)); } } @@ -728,7 +821,23 @@ void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::Web { if(mWebEngine) { - mWebEngine.RegisterNavigationPolicyDecidedCallback(callback); + mWebEngine.RegisterNavigationPolicyDecidedCallback(std::move(callback)); + } +} + +void WebView::RegisterNewWindowPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNewWindowPolicyDecidedCallback callback) +{ + if(mWebEngine) + { + mWebEngine.RegisterNewWindowPolicyDecidedCallback(callback); + } +} + +void WebView::RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback) +{ + if(mWebEngine) + { + mWebEngine.RegisterNewWindowCreatedCallback(std::move(callback)); } } @@ -736,7 +845,7 @@ void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEng { if(mWebEngine) { - mWebEngine.RegisterCertificateConfirmedCallback(callback); + mWebEngine.RegisterCertificateConfirmedCallback(std::move(callback)); } } @@ -744,7 +853,7 @@ void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEn { if(mWebEngine) { - mWebEngine.RegisterSslCertificateChangedCallback(callback); + mWebEngine.RegisterSslCertificateChangedCallback(std::move(callback)); } } @@ -752,7 +861,7 @@ void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHt { if(mWebEngine) { - mWebEngine.RegisterHttpAuthHandlerCallback(callback); + mWebEngine.RegisterHttpAuthHandlerCallback(std::move(callback)); } } @@ -760,7 +869,7 @@ void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineC { if(mWebEngine) { - mWebEngine.RegisterContextMenuShownCallback(callback); + mWebEngine.RegisterContextMenuShownCallback(std::move(callback)); } } @@ -768,7 +877,31 @@ void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngine { if(mWebEngine) { - mWebEngine.RegisterContextMenuHiddenCallback(callback); + mWebEngine.RegisterContextMenuHiddenCallback(std::move(callback)); + } +} + +void WebView::RegisterFullscreenEnteredCallback(Dali::WebEnginePlugin::WebEngineFullscreenEnteredCallback callback) +{ + if(mWebEngine) + { + mWebEngine.RegisterFullscreenEnteredCallback(callback); + } +} + +void WebView::RegisterFullscreenExitedCallback(Dali::WebEnginePlugin::WebEngineFullscreenExitedCallback callback) +{ + if(mWebEngine) + { + mWebEngine.RegisterFullscreenExitedCallback(callback); + } +} + +void WebView::RegisterTextFoundCallback(Dali::WebEnginePlugin::WebEngineTextFoundCallback callback) +{ + if(mWebEngine) + { + mWebEngine.RegisterTextFoundCallback(callback); } } @@ -776,7 +909,7 @@ void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceive { if(mWebEngine) { - mWebEngine.GetPlainTextAsynchronously(callback); + mWebEngine.GetPlainTextAsynchronously(std::move(callback)); } } @@ -786,28 +919,75 @@ void WebView::OnFrameRendered() { mFrameRenderedCallback(); } -} -void WebView::OnInitialFrameRendered() -{ - mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnInitialFrameRendered); + // Make sure that mVisual is created only once. + if (mVisual) + return; - Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(mWebEngine.GetNativeImageSource()); - mVisual = Toolkit::VisualFactory::Get().CreateVisual({{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, {Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()}}); + // Get webVisual for checking corner radius + Toolkit::Visual::Base webVisual = Dali::Toolkit::DevelControl::GetVisual(*this, Toolkit::WebView::Property::URL); + Property::Map webMap; + webVisual.CreatePropertyMap(webMap); + Property::Value* cornerRadiusValue = webMap.Find(Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS); + if(cornerRadiusValue) + { + mCornerRadius = cornerRadiusValue->Get(); + } + Property::Value* cornerRadiusValuePolicy = webMap.Find(Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY); + if(cornerRadiusValuePolicy) + { + mCornerRadiusPolicy = cornerRadiusValuePolicy->Get(); + } + Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(mWebEngine.GetNativeImageSource()); + Property::Map propertyMap; + propertyMap.Insert(Dali::Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::IMAGE); + propertyMap.Insert(Dali::Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()); + propertyMap.Insert(Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS, mCornerRadius); + propertyMap.Insert(Dali::Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, mCornerRadiusPolicy); + mVisual = Toolkit::VisualFactory::Get().CreateVisual(propertyMap); if(mVisual) { - DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual); - EnableBlendMode(!mVideoHoleEnabled); + // Reset flag + mVisualChangeRequired = false; + + auto nativeImageSourcePtr = mWebEngine.GetNativeImageSource(); + + mLastRenderedNativeImageWidth = nativeImageSourcePtr->GetWidth(); + mLastRenderedNativeImageHeight = nativeImageSourcePtr->GetHeight(); + + Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSourcePtr); + + mVisual = Toolkit::VisualFactory::Get().CreateVisual( + {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, + {Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()}, + {Toolkit::ImageVisual::Property::PIXEL_AREA, FULL_TEXTURE_RECT}, + {Toolkit::ImageVisual::Property::WRAP_MODE_U, Dali::WrapMode::CLAMP_TO_EDGE}, + {Toolkit::ImageVisual::Property::WRAP_MODE_V, Dali::WrapMode::CLAMP_TO_EDGE}}); + + if(mVisual) + { + DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual, DepthIndex::CONTENT); + EnableBlendMode(!mVideoHoleEnabled); + } } } -void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type) +void WebView::OnDisplayAreaUpdated(Dali::PropertyNotification& /*source*/) { - if(type == Dali::DevelActor::VisibilityChange::Type::SELF) + if(!mWebEngine) { - SetVisibility(isVisible); + return; } + + auto displayArea = CalculateDisplayArea(Self(), DisplayAreaCalculateOption::CURRENT_PROPERTY); + + SetDisplayArea(displayArea); +} + +void WebView::OnInheritedVisibilityChanged(Actor actor, bool isVisible) +{ + SetVisibility(isVisible); } void WebView::OnScreenshotCaptured(Dali::PixelData pixel) @@ -819,12 +999,42 @@ void WebView::OnScreenshotCaptured(Dali::PixelData pixel) } } +void WebView::SetDisplayArea(const Dali::Rect& displayArea) +{ + Size displaySize = Size(displayArea.width, displayArea.height); + if(mWebViewSize != displaySize) + { + mWebViewSize = displaySize; + } + + if(mWebViewArea != displayArea) + { + // WebEngine visual size changed. we have to re-create visual. + mVisualChangeRequired = true; + + // Change old visual's pixel area matched as changed web view size + if(mVisual) + { + auto pixelArea = CalculatePixelArea(mWebViewSize, mLastRenderedNativeImageWidth, mLastRenderedNativeImageHeight); + Toolkit::GetImplementation(mVisual).DoAction(Toolkit::DevelVisual::Action::UPDATE_PROPERTY, {{Toolkit::ImageVisual::Property::PIXEL_AREA, pixelArea}}); + } + + mWebViewArea = displayArea; + mWebEngine.UpdateDisplayArea(mWebViewArea); + } +} + void WebView::OnSceneConnection(int depth) { Control::OnSceneConnection(depth); EnableBlendMode(!mVideoHoleEnabled); } +void WebView::OnSceneDisconnection() +{ + Control::OnSceneDisconnection(); +} + bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch) { bool result = false; @@ -1244,7 +1454,9 @@ bool WebView::SetVisibility(bool visible) } WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine) -: ControlAccessible(self), mRemoteChild{}, mWebEngine{webEngine} +: ControlAccessible(self), + mRemoteChild{}, + mWebEngine{webEngine} { mRemoteChild.SetParent(this); @@ -1261,10 +1473,31 @@ WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& } } +Dali::Accessibility::Attributes WebView::WebViewAccessible::GetAttributes() const +{ + auto attributes = DevelControl::ControlAccessible::GetAttributes(); + + if(mRemoteChild.GetAddress()) + { + attributes.insert_or_assign("child_bus", mRemoteChild.GetAddress().GetBus()); + } + + return attributes; +} + void WebView::WebViewAccessible::DoGetChildren(std::vector& children) { + if(Dali::Accessibility::IsUp() && !mRemoteChild.GetAddress()) + { + DALI_LOG_DEBUG_INFO("Try setting address as it has not not been set on initialize.\n"); + SetRemoteChildAddress(mWebEngine.GetAccessibilityAddress()); + } + if(mRemoteChild.GetAddress()) { + // DoGetChildren is called at most once per every OnChildrenChanged. + // We have only one OnChildrenChanged in this case, so EmbedSocket will be called only once. + Accessibility::Bridge::GetCurrentBridge()->EmbedSocket(GetAddress(), mRemoteChild.GetAddress()); children.push_back(&mRemoteChild); } } @@ -1295,16 +1528,8 @@ void WebView::WebViewAccessible::SetRemoteChildAddress(Dali::Accessibility::Addr { mRemoteChild.SetAddress(address); OnChildrenChanged(); - - if(address) - { - Accessibility::Bridge::GetCurrentBridge()->EmbedAtkSocket(GetAddress(), address); - } } -#undef GET_ENUM_STRING -#undef GET_ENUM_VALUE - } // namespace Internal } // namespace Toolkit