X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fweb-view%2Fweb-view-impl.cpp;h=6a3af8d94c7099ddc2782829979c9fbcece8b36c;hp=e336f2cc999a6f2689a8ca3ddf528c44726b7598;hb=HEAD;hpb=bb7636f379eb67e93984aa0c2ae7208983a147ba diff --git a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp index e336f2c..9edac2d 100644 --- 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,43 +16,45 @@ */ // 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 { @@ -91,24 +93,78 @@ 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; +} + +enum class DisplayAreaCalculateOption +{ + PROPERTY = 0, ///< Calculate display update area by property + CURRENT_PROPERTY = 1, ///< Calculate display update area by current property +}; + +/** + * @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); -#define GET_ENUM_STRING(structName, inputExp) \ - Scripting::GetLinearEnumerationName(static_cast(inputExp), structName##_TABLE, structName##_TABLE_COUNT) +/** + * @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); +} -#define GET_ENUM_VALUE(structName, inputExp, outputExp) \ - Scripting::GetEnumerationProperty(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp) +} // 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} { mWebEngine = Dali::WebEngine::New(); @@ -124,11 +180,15 @@ 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} { mWebEngine = Dali::WebEngine::New(); @@ -148,7 +208,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(); } } @@ -157,7 +221,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; } @@ -166,7 +233,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; } @@ -175,51 +245,84 @@ 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); + mWebViewVisibleState |= WebViewVisibleStateFlag::SELF_SHOW; + 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); 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())); } + + self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER); } -Dali::Toolkit::WebSettings* WebView::GetSettings() const +DevelControl::ControlAccessible* WebView::CreateAccessibleObject() { - return mWebSettings.get(); + return new WebViewAccessible(Self(), mWebEngine); } -Dali::Toolkit::WebContext* WebView::GetContext() const +void WebView::OnRelayout(const Vector2& size, RelayoutContainer& container) { - return mWebContext.get(); + if(!mWebEngine) + { + return; + } + + auto displayArea = CalculateDisplayArea(Self(), DisplayAreaCalculateOption::PROPERTY); + + SetDisplayArea(displayArea); } -Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const +Dali::Toolkit::WebSettings* WebView::GetSettings() const { - return mWebCookieManager.get(); + return mWebSettings.get(); } Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const @@ -227,6 +330,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; @@ -242,11 +350,6 @@ void WebView::LoadUrl(const std::string& url) { if(mWebEngine) { - if(!mVisual) - { - mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered); - } - mWebEngine.LoadUrl(url); } } @@ -255,11 +358,6 @@ void WebView::LoadHtmlString(const std::string& htmlString) { if(mWebEngine) { - if(!mVisual) - { - mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered); - } - mWebEngine.LoadHtmlString(htmlString); } } @@ -269,24 +367,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); } @@ -406,7 +494,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) { if(mWebEngine) { - mWebEngine.RegisterGeolocationPermissionCallback(callback); + mWebEngine.RegisterGeolocationPermissionCallback(std::move(callback)); } } @@ -575,37 +663,6 @@ void WebView::SetTtsFocus(bool focused) } } -void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/) -{ - 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) - { - mWebViewArea = displayArea; - mWebEngine.UpdateDisplayArea(mWebViewArea); - } -} - void WebView::EnableVideoHole(bool enabled) { mVideoHoleEnabled = enabled; @@ -635,7 +692,7 @@ Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const return Dali::Toolkit::ImageView(); } - Dali::Toolkit::ImageUrl url = Dali::Toolkit::Image::GenerateUrl(pixel); + Dali::Toolkit::ImageUrl url = Dali::Toolkit::Image::GenerateUrl(pixel); Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url.GetUrl()); imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight())); return imageView; @@ -645,7 +702,7 @@ void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePa { if(mWebEngine) { - mWebEngine.RegisterPageLoadStartedCallback(callback); + mWebEngine.RegisterPageLoadStartedCallback(std::move(callback)); } } @@ -653,7 +710,7 @@ void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEngin { if(mWebEngine) { - mWebEngine.RegisterPageLoadInProgressCallback(callback); + mWebEngine.RegisterPageLoadInProgressCallback(std::move(callback)); } } @@ -661,7 +718,7 @@ void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEngineP { if(mWebEngine) { - mWebEngine.RegisterPageLoadFinishedCallback(callback); + mWebEngine.RegisterPageLoadFinishedCallback(std::move(callback)); } } @@ -669,7 +726,7 @@ void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePage { if(mWebEngine) { - mWebEngine.RegisterPageLoadErrorCallback(callback); + mWebEngine.RegisterPageLoadErrorCallback(std::move(callback)); } } @@ -677,7 +734,7 @@ void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngine { if(mWebEngine) { - mWebEngine.RegisterScrollEdgeReachedCallback(callback); + mWebEngine.RegisterScrollEdgeReachedCallback(std::move(callback)); } } @@ -685,7 +742,7 @@ void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChan { if(mWebEngine) { - mWebEngine.RegisterUrlChangedCallback(callback); + mWebEngine.RegisterUrlChangedCallback(std::move(callback)); } } @@ -693,36 +750,44 @@ 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::RegisterRequestInterceptorCallback(Dali::WebEnginePlugin::WebEngineRequestInterceptorCallback callback) +void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback) { if(mWebEngine) { - mWebEngine.RegisterRequestInterceptorCallback(callback); + mWebEngine.RegisterConsoleMessageReceivedCallback(std::move(callback)); } } -void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback) +void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback) { if(mWebEngine) { - mWebEngine.RegisterConsoleMessageReceivedCallback(callback); + mWebEngine.RegisterResponsePolicyDecidedCallback(std::move(callback)); } } -void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback) +void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback) { if(mWebEngine) { - mWebEngine.RegisterResponsePolicyDecidedCallback(callback); + mWebEngine.RegisterNavigationPolicyDecidedCallback(std::move(callback)); + } +} + +void WebView::RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback) +{ + if(mWebEngine) + { + mWebEngine.RegisterNewWindowCreatedCallback(std::move(callback)); } } @@ -730,7 +795,7 @@ void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEng { if(mWebEngine) { - mWebEngine.RegisterCertificateConfirmedCallback(callback); + mWebEngine.RegisterCertificateConfirmedCallback(std::move(callback)); } } @@ -738,7 +803,7 @@ void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEn { if(mWebEngine) { - mWebEngine.RegisterSslCertificateChangedCallback(callback); + mWebEngine.RegisterSslCertificateChangedCallback(std::move(callback)); } } @@ -746,7 +811,7 @@ void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHt { if(mWebEngine) { - mWebEngine.RegisterHttpAuthHandlerCallback(callback); + mWebEngine.RegisterHttpAuthHandlerCallback(std::move(callback)); } } @@ -754,7 +819,7 @@ void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineC { if(mWebEngine) { - mWebEngine.RegisterContextMenuShownCallback(callback); + mWebEngine.RegisterContextMenuShownCallback(std::move(callback)); } } @@ -762,7 +827,7 @@ void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngine { if(mWebEngine) { - mWebEngine.RegisterContextMenuHiddenCallback(callback); + mWebEngine.RegisterContextMenuHiddenCallback(std::move(callback)); } } @@ -770,7 +835,7 @@ void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceive { if(mWebEngine) { - mWebEngine.GetPlainTextAsynchronously(callback); + mWebEngine.GetPlainTextAsynchronously(std::move(callback)); } } @@ -780,29 +845,86 @@ void WebView::OnFrameRendered() { mFrameRenderedCallback(); } -} -void WebView::OnInitialFrameRendered() -{ - mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnInitialFrameRendered); + // Make sure that mVisual is created only if required. + if(mVisualChangeRequired || !mVisual) + { + // Reset flag + mVisualChangeRequired = false; - Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource()); - const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture); - mVisual = Toolkit::VisualFactory::Get().CreateVisual({{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, {Toolkit::ImageVisual::Property::URL, nativeImageUrl}}); + auto nativeImageSourcePtr = mWebEngine.GetNativeImageSource(); - if(mVisual) + 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::OnDisplayAreaUpdated(Dali::PropertyNotification& /*source*/) +{ + if(!mWebEngine) { - DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual); - EnableBlendMode(!mVideoHoleEnabled); + return; } + + auto displayArea = CalculateDisplayArea(Self(), DisplayAreaCalculateOption::CURRENT_PROPERTY); + + SetDisplayArea(displayArea); } void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type) { if(type == Dali::DevelActor::VisibilityChange::Type::SELF) { - SetVisibility(isVisible); + if(isVisible) + { + mWebViewVisibleState |= WebViewVisibleStateFlag::SELF_SHOW; + } + else + { + mWebViewVisibleState &= ~WebViewVisibleStateFlag::SELF_SHOW; + } } + else if(type == Dali::DevelActor::VisibilityChange::Type::PARENT) + { + if(isVisible) + { + mWebViewVisibleState |= WebViewVisibleStateFlag::PARENT_SHOW; + // TODO : We should consider double-hide called from parent + } + else + { + mWebViewVisibleState &= ~WebViewVisibleStateFlag::PARENT_SHOW; + } + } + ApplyVisibilityCheck(); +} + +void WebView::OnWindowVisibilityChanged(Window window, bool visible) +{ + if(visible) + { + mWebViewVisibleState |= WebViewVisibleStateFlag::WINDOW_SHOW; + } + else + { + mWebViewVisibleState &= ~WebViewVisibleStateFlag::WINDOW_SHOW; + } + ApplyVisibilityCheck(); } void WebView::OnScreenshotCaptured(Dali::PixelData pixel) @@ -814,12 +936,71 @@ 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) { + mWebViewVisibleState |= WebViewVisibleStateFlag::SCENE_ON; + mWebViewVisibleState |= WebViewVisibleStateFlag::PARENT_SHOW; + // TODO : We should consider already hided parent + Window window = DevelWindow::Get(Self()); + if(window) + { + // Hold the weak handle of the placement window. + mPlacementWindow = window; + if(window.IsVisible()) + { + mWebViewVisibleState |= WebViewVisibleStateFlag::WINDOW_SHOW; + } + else + { + mWebViewVisibleState &= ~WebViewVisibleStateFlag::WINDOW_SHOW; + } + DevelWindow::VisibilityChangedSignal(window).Connect(this, &WebView::OnWindowVisibilityChanged); + } + ApplyVisibilityCheck(); Control::OnSceneConnection(depth); EnableBlendMode(!mVideoHoleEnabled); } +void WebView::OnSceneDisconnection() +{ + mWebViewVisibleState &= ~WebViewVisibleStateFlag::SCENE_ON; + mWebViewVisibleState &= ~WebViewVisibleStateFlag::WINDOW_SHOW; + mWebViewVisibleState &= ~WebViewVisibleStateFlag::PARENT_SHOW; + Window window = mPlacementWindow.GetHandle(); + if(window) + { + DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &WebView::OnWindowVisibilityChanged); + mPlacementWindow.Reset(); + } + ApplyVisibilityCheck(); + Control::OnSceneDisconnection(); +} + bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch) { bool result = false; @@ -1238,8 +1419,81 @@ bool WebView::SetVisibility(bool visible) return mWebEngine ? mWebEngine.SetVisibility(visible) : false; } -#undef GET_ENUM_STRING -#undef GET_ENUM_VALUE +void WebView::ApplyVisibilityCheck() +{ + SetVisibility(mWebViewVisibleState == WebViewVisibleStateFlag::VISIBLE); +} + +WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine) +: ControlAccessible(self), + mRemoteChild{}, + mWebEngine{webEngine} +{ + mRemoteChild.SetParent(this); + + Dali::Accessibility::Bridge::EnabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityEnabled); + Dali::Accessibility::Bridge::DisabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityDisabled); + + if(Dali::Accessibility::IsUp()) + { + OnAccessibilityEnabled(); + } + else + { + OnAccessibilityDisabled(); + } +} + +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(mRemoteChild.GetAddress()) + { + // DoGetChildren is called at most once per every OnChildrenChanged. + // We have only one OnChildrenChanged in this case, so EmbedAtkSocket will be called only once. + Accessibility::Bridge::GetCurrentBridge()->EmbedAtkSocket(GetAddress(), mRemoteChild.GetAddress()); + children.push_back(&mRemoteChild); + } +} + +void WebView::WebViewAccessible::OnAccessibilityEnabled() +{ + if(!mWebEngine) + { + return; + } + + mWebEngine.ActivateAccessibility(true); + SetRemoteChildAddress(mWebEngine.GetAccessibilityAddress()); +} + +void WebView::WebViewAccessible::OnAccessibilityDisabled() +{ + if(!mWebEngine) + { + return; + } + + SetRemoteChildAddress({}); + mWebEngine.ActivateAccessibility(false); +} + +void WebView::WebViewAccessible::SetRemoteChildAddress(Dali::Accessibility::Address address) +{ + mRemoteChild.SetAddress(address); + OnChildrenChanged(); +} } // namespace Internal