2 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/controls/web-view/web-view-impl.h>
22 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-back-forward-list.h>
23 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-certificate.h>
24 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-console-message.h>
25 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context-menu-item.h>
26 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context-menu.h>
27 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context.h>
28 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-cookie-manager.h>
29 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-form-repost-decision.h>
30 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-hit-test.h>
31 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-http-auth-handler.h>
32 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-load-error.h>
33 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-policy-decision.h>
34 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-settings.h>
35 #include <dali/devel-api/adaptor-framework/window-devel.h>
36 #include <dali/devel-api/common/stage.h>
37 #include <dali/devel-api/scripting/enum-helper.h>
38 #include <dali/devel-api/scripting/scripting.h>
39 #include <dali/integration-api/debug.h>
40 #include <dali/public-api/adaptor-framework/native-image-source.h>
41 #include <dali/public-api/object/type-registry-helper.h>
42 #include <dali/public-api/object/type-registry.h>
45 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
46 #include <dali-toolkit/devel-api/controls/control-devel.h>
47 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
48 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
49 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
50 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
51 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
52 #include <dali-toolkit/public-api/image-loader/image-url.h>
53 #include <dali-toolkit/public-api/image-loader/image.h>
54 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
58 #include <unordered_map>
70 return Toolkit::WebView::New();
74 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
76 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url", STRING, URL )
77 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent", STRING, USER_AGENT )
78 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION )
79 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE )
80 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE )
81 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title", STRING, TITLE )
82 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled", BOOLEAN, VIDEO_HOLE_ENABLED )
83 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled", BOOLEAN, MOUSE_EVENTS_ENABLED )
84 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled", BOOLEAN, KEY_EVENTS_ENABLED )
85 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR )
86 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden", BOOLEAN, TILES_CLEARED_WHEN_HIDDEN )
87 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT, TILE_COVER_AREA_MULTIPLIER)
88 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient", BOOLEAN, CURSOR_ENABLED_BY_CLIENT )
89 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText", STRING, SELECTED_TEXT )
90 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor", FLOAT, PAGE_ZOOM_FACTOR )
91 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor", FLOAT, TEXT_ZOOM_FACTOR )
92 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage", FLOAT, LOAD_PROGRESS_PERCENTAGE )
94 DALI_TYPE_REGISTRATION_END()
97 std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>>& GetPluginWebViewTable()
99 static std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>> pluginWebViewMap;
100 return pluginWebViewMap;
103 enum class DisplayAreaCalculateOption
105 PROPERTY = 0, ///< Calculate display update area by property
106 CURRENT_PROPERTY = 1, ///< Calculate display update area by current property
110 * @brief Helper function to calculate exact display area, offset and size.
111 * It will be useful when view size is not integer value, or view size is not matched with texture size.
113 * @param[in] self The view itself.
114 * @param[in] option Option of this calculation. Let we decide what kind of property will be used.
115 * @return DisplayArea for this view.
117 Rect<int32_t> CalculateDisplayArea(Dali::Actor self, DisplayAreaCalculateOption option)
119 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
120 Vector3 actorSize = (option == DisplayAreaCalculateOption::CURRENT_PROPERTY) ? self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE)
121 : self.GetProperty<Vector3>(Actor::Property::SIZE) * self.GetProperty<Vector3>(Actor::Property::SCALE);
122 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
123 Vector2 screenPosition = (option == DisplayAreaCalculateOption::CURRENT_PROPERTY) ? self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION)
124 : Dali::DevelActor::CalculateScreenPosition(self);
126 Dali::Rect<int32_t> displayArea;
127 displayArea.x = screenPosition.x - anchorPointOffSet.x;
128 displayArea.y = screenPosition.y - anchorPointOffSet.y;
129 displayArea.width = actorSize.x;
130 displayArea.height = actorSize.y;
135 constexpr Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
138 * @brief Helper function to calculate exact pixel area value by view and texture size.
139 * It will be useful when view size is not integer value, or view size is not matched with texture size.
141 * @param[in] viewSize The size of view.
142 * @param[in] textureWidth The width of texture, that must be integer type.
143 * @param[in] textureHeight The height of texture, that must be integer type.
144 * @return PixelArea value that image visual can use.
146 Vector4 CalculatePixelArea(const Size& viewSize, const uint32_t textureWidth, const uint32_t textureHeight)
148 float widthRatio = textureWidth == 0u ? 1.0f : viewSize.width / static_cast<float>(textureWidth);
149 float heightRatio = textureHeight == 0u ? 1.0f : viewSize.height / static_cast<float>(textureHeight);
150 return Vector4(0.0f, 0.0f, widthRatio, heightRatio);
155 WebView::WebView(const std::string& locale, const std::string& timezoneId)
156 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
158 mWebViewSize(Stage::GetCurrent().GetSize()),
160 mLastRenderedNativeImageWidth(0u),
161 mLastRenderedNativeImageHeight(0u),
162 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
163 mVideoHoleEnabled(false),
164 mMouseEventsEnabled(true),
165 mKeyEventsEnabled(true),
166 mVisualChangeRequired(false),
167 mScreenshotCapturedCallback{nullptr},
168 mFrameRenderedCallback{nullptr}
170 mWebEngine = Dali::WebEngine::New();
172 // WebEngine is empty when it is not properly initialized.
175 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
179 WebView::WebView(uint32_t argc, char** argv)
180 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
182 mWebViewSize(Stage::GetCurrent().GetSize()),
184 mLastRenderedNativeImageWidth(0u),
185 mLastRenderedNativeImageHeight(0u),
186 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
187 mVideoHoleEnabled(false),
188 mMouseEventsEnabled(true),
189 mKeyEventsEnabled(true),
190 mVisualChangeRequired(false),
191 mScreenshotCapturedCallback{nullptr},
192 mFrameRenderedCallback{nullptr}
194 mWebEngine = Dali::WebEngine::New();
196 // WebEngine is empty when it is not properly initialized.
199 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
212 auto iter = GetPluginWebViewTable().find(mWebEngine.GetPlugin());
213 if(iter != GetPluginWebViewTable().end())
215 GetPluginWebViewTable().erase(iter);
217 mWebEngine.Destroy();
221 Toolkit::WebView WebView::New()
223 WebView* impl = new WebView();
224 Toolkit::WebView handle = Toolkit::WebView(*impl);
225 if(impl->GetPlugin())
227 GetPluginWebViewTable()[impl->GetPlugin()] = handle;
233 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
235 WebView* impl = new WebView(locale, timezoneId);
236 Toolkit::WebView handle = Toolkit::WebView(*impl);
237 if(impl->GetPlugin())
239 GetPluginWebViewTable()[impl->GetPlugin()] = handle;
245 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
247 WebView* impl = new WebView(argc, argv);
248 Toolkit::WebView handle = Toolkit::WebView(*impl);
249 if(impl->GetPlugin())
251 GetPluginWebViewTable()[impl->GetPlugin()] = handle;
257 Toolkit::WebView WebView::FindWebView(Dali::WebEnginePlugin* plugin)
259 auto iter = GetPluginWebViewTable().find(plugin);
260 if(iter != GetPluginWebViewTable().end())
262 return iter->second.GetHandle();
264 return Toolkit::WebView();
267 Dali::WebEngineContext* WebView::GetContext()
269 return Dali::WebEngine::GetContext();
272 Dali::WebEngineCookieManager* WebView::GetCookieManager()
274 return Dali::WebEngine::GetCookieManager();
277 void WebView::OnInitialize()
281 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
282 self.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
283 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
284 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
285 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
286 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
288 mWebViewVisibleState |= WebViewVisibleStateFlag::SELF_SHOW;
290 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
291 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
292 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
293 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
294 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
295 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
299 mWebEngine.RegisterFrameRenderedCallback(std::bind(&WebView::OnFrameRendered, this));
300 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
301 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
304 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER);
307 DevelControl::ControlAccessible* WebView::CreateAccessibleObject()
309 return new WebViewAccessible(Self(), mWebEngine);
312 void WebView::OnRelayout(const Vector2& size, RelayoutContainer& container)
319 auto displayArea = CalculateDisplayArea(Self(), DisplayAreaCalculateOption::PROPERTY);
321 SetDisplayArea(displayArea);
324 Dali::Toolkit::WebSettings* WebView::GetSettings() const
326 return mWebSettings.get();
329 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
331 return mWebBackForwardList.get();
334 Dali::WebEnginePlugin* WebView::GetPlugin() const
336 return mWebEngine ? mWebEngine.GetPlugin() : nullptr;
339 Dali::Toolkit::ImageView WebView::GetFavicon() const
341 Dali::Toolkit::ImageView faviconView;
344 Dali::PixelData pixelData = mWebEngine.GetFavicon();
345 faviconView = CreateImageView(pixelData);
350 void WebView::LoadUrl(const std::string& url)
354 mWebEngine.LoadUrl(url);
358 void WebView::LoadHtmlString(const std::string& htmlString)
362 mWebEngine.LoadHtmlString(htmlString);
366 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
371 return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
374 bool WebView::LoadContents(const int8_t* contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
379 return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
382 void WebView::Reload()
390 bool WebView::ReloadWithoutCache()
392 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
395 void WebView::StopLoading()
399 mWebEngine.StopLoading();
403 void WebView::Suspend()
407 mWebEngine.Suspend();
411 void WebView::Resume()
419 void WebView::SuspendNetworkLoading()
423 mWebEngine.SuspendNetworkLoading();
427 void WebView::ResumeNetworkLoading()
431 mWebEngine.ResumeNetworkLoading();
435 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
437 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
440 bool WebView::RemoveCustomHeader(const std::string& name)
442 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
445 uint32_t WebView::StartInspectorServer(uint32_t port)
447 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
450 bool WebView::StopInspectorServer()
452 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
455 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
459 mWebEngine.ScrollBy(deltaX, deltaY);
463 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
465 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
468 bool WebView::CanGoForward()
470 return mWebEngine ? mWebEngine.CanGoForward() : false;
473 void WebView::GoForward()
477 mWebEngine.GoForward();
481 bool WebView::CanGoBack()
483 return mWebEngine ? mWebEngine.CanGoBack() : false;
486 void WebView::GoBack()
494 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
498 mWebEngine.EvaluateJavaScript(script, std::move(resultHandler));
502 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
506 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, std::move(handler));
510 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
514 mWebEngine.RegisterJavaScriptAlertCallback(std::move(callback));
518 void WebView::JavaScriptAlertReply()
522 mWebEngine.JavaScriptAlertReply();
526 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
530 mWebEngine.RegisterJavaScriptConfirmCallback(std::move(callback));
534 void WebView::JavaScriptConfirmReply(bool confirmed)
538 mWebEngine.JavaScriptConfirmReply(confirmed);
542 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
546 mWebEngine.RegisterJavaScriptPromptCallback(std::move(callback));
550 void WebView::JavaScriptPromptReply(const std::string& result)
554 mWebEngine.JavaScriptPromptReply(result);
558 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
560 std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
566 return mWebEngine.CreateHitTest(x, y, mode);
569 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
574 result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, std::move(callback));
579 void WebView::ClearHistory()
583 mWebEngine.ClearHistory();
587 void WebView::ClearAllTilesResources()
591 mWebEngine.ClearAllTilesResources();
595 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
599 mWebEngine.SetScaleFactor(scaleFactor, point);
603 float WebView::GetScaleFactor() const
605 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
608 void WebView::ActivateAccessibility(bool activated)
612 mWebEngine.ActivateAccessibility(activated);
616 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
618 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
621 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
625 mWebEngine.AddDynamicCertificatePath(host, certPath);
629 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
631 Dali::Toolkit::ImageView imageView;
634 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
635 imageView = CreateImageView(pixelData);
640 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
642 mScreenshotCapturedCallback = std::move(callback);
643 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
646 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
648 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(std::move(callback)) : false;
651 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
655 mWebEngine.RegisterGeolocationPermissionCallback(std::move(callback));
659 void WebView::SetTtsFocus(bool focused)
661 if(mWebEngine && !HasKeyInputFocus())
663 mWebEngine.SetFocus(focused);
667 void WebView::EnableVideoHole(bool enabled)
669 mVideoHoleEnabled = enabled;
671 EnableBlendMode(!mVideoHoleEnabled);
675 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
679 void WebView::EnableBlendMode(bool blendEnabled)
682 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
684 Dali::Renderer render = self.GetRendererAt(i);
685 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
689 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
693 return Dali::Toolkit::ImageView();
696 Dali::Toolkit::ImageUrl url = Dali::Toolkit::Image::GenerateUrl(pixel);
697 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url.GetUrl());
698 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
702 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
706 mWebEngine.RegisterPageLoadStartedCallback(std::move(callback));
710 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
714 mWebEngine.RegisterPageLoadInProgressCallback(std::move(callback));
718 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
722 mWebEngine.RegisterPageLoadFinishedCallback(std::move(callback));
726 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
730 mWebEngine.RegisterPageLoadErrorCallback(std::move(callback));
734 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
738 mWebEngine.RegisterScrollEdgeReachedCallback(std::move(callback));
742 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
746 mWebEngine.RegisterUrlChangedCallback(std::move(callback));
750 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
754 mWebEngine.RegisterFormRepostDecidedCallback(std::move(callback));
758 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
760 mFrameRenderedCallback = std::move(callback);
763 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
767 mWebEngine.RegisterConsoleMessageReceivedCallback(std::move(callback));
771 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
775 mWebEngine.RegisterResponsePolicyDecidedCallback(std::move(callback));
779 void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
783 mWebEngine.RegisterNavigationPolicyDecidedCallback(std::move(callback));
787 void WebView::RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback)
791 mWebEngine.RegisterNewWindowCreatedCallback(std::move(callback));
795 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
799 mWebEngine.RegisterCertificateConfirmedCallback(std::move(callback));
803 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
807 mWebEngine.RegisterSslCertificateChangedCallback(std::move(callback));
811 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
815 mWebEngine.RegisterHttpAuthHandlerCallback(std::move(callback));
819 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
823 mWebEngine.RegisterContextMenuShownCallback(std::move(callback));
827 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
831 mWebEngine.RegisterContextMenuHiddenCallback(std::move(callback));
835 void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
839 mWebEngine.GetPlainTextAsynchronously(std::move(callback));
843 void WebView::OnFrameRendered()
845 if(mFrameRenderedCallback)
847 mFrameRenderedCallback();
850 // Make sure that mVisual is created only if required.
851 if(mVisualChangeRequired || !mVisual)
854 mVisualChangeRequired = false;
856 auto nativeImageSourcePtr = mWebEngine.GetNativeImageSource();
858 mLastRenderedNativeImageWidth = nativeImageSourcePtr->GetWidth();
859 mLastRenderedNativeImageHeight = nativeImageSourcePtr->GetHeight();
861 Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSourcePtr);
863 mVisual = Toolkit::VisualFactory::Get().CreateVisual(
864 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
865 {Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()},
866 {Toolkit::ImageVisual::Property::PIXEL_AREA, FULL_TEXTURE_RECT},
867 {Toolkit::ImageVisual::Property::WRAP_MODE_U, Dali::WrapMode::CLAMP_TO_EDGE},
868 {Toolkit::ImageVisual::Property::WRAP_MODE_V, Dali::WrapMode::CLAMP_TO_EDGE}});
872 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual, DepthIndex::CONTENT);
873 EnableBlendMode(!mVideoHoleEnabled);
878 void WebView::OnDisplayAreaUpdated(Dali::PropertyNotification& /*source*/)
885 auto displayArea = CalculateDisplayArea(Self(), DisplayAreaCalculateOption::CURRENT_PROPERTY);
887 SetDisplayArea(displayArea);
890 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
892 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
896 mWebViewVisibleState |= WebViewVisibleStateFlag::SELF_SHOW;
900 mWebViewVisibleState &= ~WebViewVisibleStateFlag::SELF_SHOW;
903 else if(type == Dali::DevelActor::VisibilityChange::Type::PARENT)
907 mWebViewVisibleState |= WebViewVisibleStateFlag::PARENT_SHOW;
908 // TODO : We should consider double-hide called from parent
912 mWebViewVisibleState &= ~WebViewVisibleStateFlag::PARENT_SHOW;
915 ApplyVisibilityCheck();
918 void WebView::OnWindowVisibilityChanged(Window window, bool visible)
922 mWebViewVisibleState |= WebViewVisibleStateFlag::WINDOW_SHOW;
926 mWebViewVisibleState &= ~WebViewVisibleStateFlag::WINDOW_SHOW;
928 ApplyVisibilityCheck();
931 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
933 if(mScreenshotCapturedCallback)
935 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
936 mScreenshotCapturedCallback(imageView);
940 void WebView::SetDisplayArea(const Dali::Rect<int32_t>& displayArea)
942 Size displaySize = Size(displayArea.width, displayArea.height);
943 if(mWebViewSize != displaySize)
945 mWebViewSize = displaySize;
948 if(mWebViewArea != displayArea)
950 // WebEngine visual size changed. we have to re-create visual.
951 mVisualChangeRequired = true;
953 // Change old visual's pixel area matched as changed web view size
956 auto pixelArea = CalculatePixelArea(mWebViewSize, mLastRenderedNativeImageWidth, mLastRenderedNativeImageHeight);
957 Toolkit::GetImplementation(mVisual).DoAction(Toolkit::DevelVisual::Action::UPDATE_PROPERTY, {{Toolkit::ImageVisual::Property::PIXEL_AREA, pixelArea}});
960 mWebViewArea = displayArea;
961 mWebEngine.UpdateDisplayArea(mWebViewArea);
965 void WebView::OnSceneConnection(int depth)
967 mWebViewVisibleState |= WebViewVisibleStateFlag::SCENE_ON;
968 mWebViewVisibleState |= WebViewVisibleStateFlag::PARENT_SHOW;
969 // TODO : We should consider already hided parent
970 Window window = DevelWindow::Get(Self());
973 // Hold the weak handle of the placement window.
974 mPlacementWindow = window;
975 if(window.IsVisible())
977 mWebViewVisibleState |= WebViewVisibleStateFlag::WINDOW_SHOW;
981 mWebViewVisibleState &= ~WebViewVisibleStateFlag::WINDOW_SHOW;
983 DevelWindow::VisibilityChangedSignal(window).Connect(this, &WebView::OnWindowVisibilityChanged);
985 ApplyVisibilityCheck();
986 Control::OnSceneConnection(depth);
987 EnableBlendMode(!mVideoHoleEnabled);
990 void WebView::OnSceneDisconnection()
992 mWebViewVisibleState &= ~WebViewVisibleStateFlag::SCENE_ON;
993 mWebViewVisibleState &= ~WebViewVisibleStateFlag::WINDOW_SHOW;
994 mWebViewVisibleState &= ~WebViewVisibleStateFlag::PARENT_SHOW;
995 Window window = mPlacementWindow.GetHandle();
998 DevelWindow::VisibilityChangedSignal(window).Disconnect(this, &WebView::OnWindowVisibilityChanged);
999 mPlacementWindow.Reset();
1001 ApplyVisibilityCheck();
1002 Control::OnSceneDisconnection();
1005 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
1007 bool result = false;
1011 result = mWebEngine.SendTouchEvent(touch);
1016 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
1018 bool result = false;
1022 result = mWebEngine.SendKeyEvent(event);
1027 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
1029 bool result = false;
1030 if(mWebEngine && mMouseEventsEnabled)
1032 result = mWebEngine.SendHoverEvent(hover);
1037 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
1039 bool result = false;
1040 if(mWebEngine && mMouseEventsEnabled)
1042 result = mWebEngine.SendWheelEvent(wheel);
1047 void WebView::OnKeyInputFocusGained()
1051 mWebEngine.SetFocus(true);
1054 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
1057 void WebView::OnKeyInputFocusLost()
1061 mWebEngine.SetFocus(false);
1064 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
1067 Vector3 WebView::GetNaturalSize()
1071 Vector2 rendererNaturalSize;
1072 mVisual.GetNaturalSize(rendererNaturalSize);
1073 return Vector3(rendererNaturalSize);
1076 return Vector3(mWebViewSize);
1079 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
1081 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1085 WebView& impl = GetImpl(webView);
1088 case Toolkit::WebView::Property::URL:
1097 case Toolkit::WebView::Property::USER_AGENT:
1100 if(value.Get(input))
1102 impl.SetUserAgent(input);
1106 case Toolkit::WebView::Property::SCROLL_POSITION:
1109 if(value.Get(input))
1111 impl.SetScrollPosition(input.x, input.y);
1115 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1118 if(value.Get(input))
1120 impl.EnableVideoHole(input);
1124 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1127 if(value.Get(input))
1129 impl.EnableMouseEvents(input);
1133 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1136 if(value.Get(input))
1138 impl.EnableKeyEvents(input);
1142 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
1145 if(value.Get(input))
1147 impl.SetDocumentBackgroundColor(input);
1151 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
1154 if(value.Get(input))
1156 impl.ClearTilesWhenHidden(input);
1160 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
1163 if(value.Get(input))
1165 impl.SetTileCoverAreaMultiplier(input);
1169 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
1172 if(value.Get(input))
1174 impl.EnableCursorByClient(input);
1178 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1181 if(value.Get(input))
1183 impl.SetPageZoomFactor(input);
1187 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1190 if(value.Get(input))
1192 impl.SetTextZoomFactor(input);
1202 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1204 Property::Value value;
1206 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1210 WebView& impl = GetImpl(webView);
1211 switch(propertyIndex)
1213 case Toolkit::WebView::Property::URL:
1215 value = impl.GetUrl();
1218 case Toolkit::WebView::Property::USER_AGENT:
1220 value = impl.GetUserAgent();
1223 case Toolkit::WebView::Property::SCROLL_POSITION:
1225 value = impl.GetScrollPosition();
1228 case Toolkit::WebView::Property::SCROLL_SIZE:
1230 value = impl.GetScrollSize();
1233 case Toolkit::WebView::Property::CONTENT_SIZE:
1235 value = impl.GetContentSize();
1238 case Toolkit::WebView::Property::TITLE:
1240 value = impl.GetTitle();
1243 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1245 value = impl.mVideoHoleEnabled;
1248 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1250 value = impl.mMouseEventsEnabled;
1253 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1255 value = impl.mKeyEventsEnabled;
1258 case Toolkit::WebView::Property::SELECTED_TEXT:
1260 value = impl.GetSelectedText();
1263 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1265 value = impl.GetPageZoomFactor();
1268 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1270 value = impl.GetTextZoomFactor();
1273 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1275 value = impl.GetLoadProgressPercentage();
1286 void WebView::SetScrollPosition(int32_t x, int32_t y)
1290 mWebEngine.SetScrollPosition(x, y);
1294 Dali::Vector2 WebView::GetScrollPosition() const
1296 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1299 Dali::Vector2 WebView::GetScrollSize() const
1301 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1304 Dali::Vector2 WebView::GetContentSize() const
1306 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1309 std::string WebView::GetTitle() const
1311 return mWebEngine ? mWebEngine.GetTitle() : std::string();
1314 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1318 mWebEngine.SetDocumentBackgroundColor(color);
1322 void WebView::ClearTilesWhenHidden(bool cleared)
1326 mWebEngine.ClearTilesWhenHidden(cleared);
1330 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1334 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1338 void WebView::EnableCursorByClient(bool enabled)
1342 mWebEngine.EnableCursorByClient(enabled);
1346 std::string WebView::GetSelectedText() const
1348 return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1351 std::string WebView::GetUrl() const
1353 return mWebEngine ? mWebEngine.GetUrl() : std::string();
1356 std::string WebView::GetUserAgent() const
1358 return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1361 void WebView::SetUserAgent(const std::string& userAgent)
1365 mWebEngine.SetUserAgent(userAgent);
1369 void WebView::EnableMouseEvents(bool enabled)
1373 mMouseEventsEnabled = enabled;
1374 mWebEngine.EnableMouseEvents(enabled);
1378 void WebView::EnableKeyEvents(bool enabled)
1382 mKeyEventsEnabled = enabled;
1383 mWebEngine.EnableKeyEvents(enabled);
1387 void WebView::SetPageZoomFactor(float zoomFactor)
1391 mWebEngine.SetPageZoomFactor(zoomFactor);
1395 float WebView::GetPageZoomFactor() const
1397 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1400 void WebView::SetTextZoomFactor(float zoomFactor)
1404 mWebEngine.SetTextZoomFactor(zoomFactor);
1408 float WebView::GetTextZoomFactor() const
1410 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1413 float WebView::GetLoadProgressPercentage() const
1415 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1418 bool WebView::SetVisibility(bool visible)
1420 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1423 void WebView::ApplyVisibilityCheck()
1425 SetVisibility(mWebViewVisibleState == WebViewVisibleStateFlag::VISIBLE);
1428 WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine)
1429 : ControlAccessible(self),
1431 mWebEngine{webEngine}
1433 mRemoteChild.SetParent(this);
1435 Dali::Accessibility::Bridge::EnabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityEnabled);
1436 Dali::Accessibility::Bridge::DisabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityDisabled);
1438 if(Dali::Accessibility::IsUp())
1440 OnAccessibilityEnabled();
1444 OnAccessibilityDisabled();
1448 Dali::Accessibility::Attributes WebView::WebViewAccessible::GetAttributes() const
1450 auto attributes = DevelControl::ControlAccessible::GetAttributes();
1452 if(mRemoteChild.GetAddress())
1454 attributes.insert_or_assign("child_bus", mRemoteChild.GetAddress().GetBus());
1460 void WebView::WebViewAccessible::DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children)
1462 if(Dali::Accessibility::IsUp() && !mRemoteChild.GetAddress())
1464 DALI_LOG_DEBUG_INFO("Try setting address as it has not not been set on initialize.\n");
1465 SetRemoteChildAddress(mWebEngine.GetAccessibilityAddress());
1468 if(mRemoteChild.GetAddress())
1470 // DoGetChildren is called at most once per every OnChildrenChanged.
1471 // We have only one OnChildrenChanged in this case, so EmbedAtkSocket will be called only once.
1472 Accessibility::Bridge::GetCurrentBridge()->EmbedAtkSocket(GetAddress(), mRemoteChild.GetAddress());
1473 children.push_back(&mRemoteChild);
1477 void WebView::WebViewAccessible::OnAccessibilityEnabled()
1484 mWebEngine.ActivateAccessibility(true);
1485 SetRemoteChildAddress(mWebEngine.GetAccessibilityAddress());
1488 void WebView::WebViewAccessible::OnAccessibilityDisabled()
1495 SetRemoteChildAddress({});
1496 mWebEngine.ActivateAccessibility(false);
1499 void WebView::WebViewAccessible::SetRemoteChildAddress(Dali::Accessibility::Address address)
1501 mRemoteChild.SetAddress(address);
1502 OnChildrenChanged();
1505 } // namespace Internal
1507 } // namespace Toolkit