2 * Copyright (c) 2023 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/common/stage.h>
36 #include <dali/devel-api/scripting/enum-helper.h>
37 #include <dali/devel-api/scripting/scripting.h>
38 #include <dali/public-api/adaptor-framework/native-image-source.h>
39 #include <dali/public-api/object/type-registry-helper.h>
40 #include <dali/public-api/object/type-registry.h>
43 #include <dali-toolkit/devel-api/controls/control-devel.h>
44 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
45 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
46 #include <dali-toolkit/devel-api/visuals/visual-actions-devel.h>
47 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
48 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
49 #include <dali-toolkit/public-api/image-loader/image-url.h>
50 #include <dali-toolkit/public-api/image-loader/image.h>
51 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
55 #include <unordered_map>
67 return Toolkit::WebView::New();
71 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
73 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url", STRING, URL )
74 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent", STRING, USER_AGENT )
75 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION )
76 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE )
77 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE )
78 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title", STRING, TITLE )
79 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled", BOOLEAN, VIDEO_HOLE_ENABLED )
80 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled", BOOLEAN, MOUSE_EVENTS_ENABLED )
81 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled", BOOLEAN, KEY_EVENTS_ENABLED )
82 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR )
83 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden", BOOLEAN, TILES_CLEARED_WHEN_HIDDEN )
84 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT, TILE_COVER_AREA_MULTIPLIER)
85 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient", BOOLEAN, CURSOR_ENABLED_BY_CLIENT )
86 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText", STRING, SELECTED_TEXT )
87 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor", FLOAT, PAGE_ZOOM_FACTOR )
88 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor", FLOAT, TEXT_ZOOM_FACTOR )
89 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage", FLOAT, LOAD_PROGRESS_PERCENTAGE )
91 DALI_TYPE_REGISTRATION_END()
94 std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>>& GetPluginWebViewTable()
96 static std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>> pluginWebViewMap;
97 return pluginWebViewMap;
100 enum class DisplayAreaCalculateOption
102 PROPERTY = 0, ///< Calculate display update area by property
103 CURRENT_PROPERTY = 1, ///< Calculate display update area by current property
107 * @brief Helper function to calculate exact display area, offset and size.
108 * It will be useful when view size is not integer value, or view size is not matched with texture size.
110 * @param[in] self The view itself.
111 * @param[in] option Option of this calculation. Let we decide what kind of property will be used.
112 * @return DisplayArea for this view.
114 Rect<int32_t> CalculateDisplayArea(Dali::Actor self, DisplayAreaCalculateOption option)
116 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
117 Vector3 actorSize = (option == DisplayAreaCalculateOption::CURRENT_PROPERTY) ? self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE)
118 : self.GetProperty<Vector3>(Actor::Property::SIZE) * self.GetProperty<Vector3>(Actor::Property::SCALE);
119 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
120 Vector2 screenPosition = (option == DisplayAreaCalculateOption::CURRENT_PROPERTY) ? self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION)
121 : Dali::DevelActor::CalculateScreenPosition(self);
123 Dali::Rect<int32_t> displayArea;
124 displayArea.x = screenPosition.x - anchorPointOffSet.x;
125 displayArea.y = screenPosition.y - anchorPointOffSet.y;
126 displayArea.width = actorSize.x;
127 displayArea.height = actorSize.y;
132 constexpr Vector4 FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
135 * @brief Helper function to calculate exact pixel area value by view and texture size.
136 * It will be useful when view size is not integer value, or view size is not matched with texture size.
138 * @param[in] viewSize The size of view.
139 * @param[in] textureWidth The width of texture, that must be integer type.
140 * @param[in] textureHeight The height of texture, that must be integer type.
141 * @return PixelArea value that image visual can use.
143 Vector4 CalculatePixelArea(const Size& viewSize, const uint32_t textureWidth, const uint32_t textureHeight)
145 float widthRatio = textureWidth == 0u ? 1.0f : viewSize.width / static_cast<float>(textureWidth);
146 float heightRatio = textureHeight == 0u ? 1.0f : viewSize.height / static_cast<float>(textureHeight);
147 return Vector4(0.0f, 0.0f, widthRatio, heightRatio);
152 WebView::WebView(const std::string& locale, const std::string& timezoneId)
153 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
155 mWebViewSize(Stage::GetCurrent().GetSize()),
157 mLastRenderedNativeImageWidth(0u),
158 mLastRenderedNativeImageHeight(0u),
159 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
160 mVideoHoleEnabled(false),
161 mMouseEventsEnabled(true),
162 mKeyEventsEnabled(true),
163 mVisualChangeRequired(false),
164 mScreenshotCapturedCallback{nullptr},
165 mFrameRenderedCallback{nullptr}
167 mWebEngine = Dali::WebEngine::New();
169 // WebEngine is empty when it is not properly initialized.
172 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
176 WebView::WebView(uint32_t argc, char** argv)
177 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
179 mWebViewSize(Stage::GetCurrent().GetSize()),
181 mLastRenderedNativeImageWidth(0u),
182 mLastRenderedNativeImageHeight(0u),
183 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
184 mVideoHoleEnabled(false),
185 mMouseEventsEnabled(true),
186 mKeyEventsEnabled(true),
187 mVisualChangeRequired(false),
188 mScreenshotCapturedCallback{nullptr},
189 mFrameRenderedCallback{nullptr}
191 mWebEngine = Dali::WebEngine::New();
193 // WebEngine is empty when it is not properly initialized.
196 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
209 auto iter = GetPluginWebViewTable().find(mWebEngine.GetPlugin());
210 if(iter != GetPluginWebViewTable().end())
212 GetPluginWebViewTable().erase(iter);
214 mWebEngine.Destroy();
218 Toolkit::WebView WebView::New()
220 WebView* impl = new WebView();
221 Toolkit::WebView handle = Toolkit::WebView(*impl);
222 if(impl->GetPlugin())
224 GetPluginWebViewTable()[impl->GetPlugin()] = handle;
230 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
232 WebView* impl = new WebView(locale, timezoneId);
233 Toolkit::WebView handle = Toolkit::WebView(*impl);
234 if(impl->GetPlugin())
236 GetPluginWebViewTable()[impl->GetPlugin()] = handle;
242 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
244 WebView* impl = new WebView(argc, argv);
245 Toolkit::WebView handle = Toolkit::WebView(*impl);
246 if(impl->GetPlugin())
248 GetPluginWebViewTable()[impl->GetPlugin()] = handle;
254 Toolkit::WebView WebView::FindWebView(Dali::WebEnginePlugin* plugin)
256 auto iter = GetPluginWebViewTable().find(plugin);
257 if(iter != GetPluginWebViewTable().end())
259 return iter->second.GetHandle();
261 return Toolkit::WebView();
264 Dali::WebEngineContext* WebView::GetContext()
266 return Dali::WebEngine::GetContext();
269 Dali::WebEngineCookieManager* WebView::GetCookieManager()
271 return Dali::WebEngine::GetCookieManager();
274 void WebView::OnInitialize()
278 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
279 self.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
280 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
281 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
282 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
283 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
285 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
286 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
287 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
288 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
289 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
290 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
294 mWebEngine.RegisterFrameRenderedCallback(std::bind(&WebView::OnFrameRendered, this));
295 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
296 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
299 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER);
302 DevelControl::ControlAccessible* WebView::CreateAccessibleObject()
304 return new WebViewAccessible(Self(), mWebEngine);
307 void WebView::OnRelayout(const Vector2& size, RelayoutContainer& container)
314 auto displayArea = CalculateDisplayArea(Self(), DisplayAreaCalculateOption::PROPERTY);
316 SetDisplayArea(displayArea);
319 Dali::Toolkit::WebSettings* WebView::GetSettings() const
321 return mWebSettings.get();
324 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
326 return mWebBackForwardList.get();
329 Dali::WebEnginePlugin* WebView::GetPlugin() const
331 return mWebEngine ? mWebEngine.GetPlugin() : nullptr;
334 Dali::Toolkit::ImageView WebView::GetFavicon() const
336 Dali::Toolkit::ImageView faviconView;
339 Dali::PixelData pixelData = mWebEngine.GetFavicon();
340 faviconView = CreateImageView(pixelData);
345 void WebView::LoadUrl(const std::string& url)
349 mWebEngine.LoadUrl(url);
353 void WebView::LoadHtmlString(const std::string& htmlString)
357 mWebEngine.LoadHtmlString(htmlString);
361 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
366 return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
369 bool WebView::LoadContents(const int8_t* contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
374 return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
377 void WebView::Reload()
385 bool WebView::ReloadWithoutCache()
387 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
390 void WebView::StopLoading()
394 mWebEngine.StopLoading();
398 void WebView::Suspend()
402 mWebEngine.Suspend();
406 void WebView::Resume()
414 void WebView::SuspendNetworkLoading()
418 mWebEngine.SuspendNetworkLoading();
422 void WebView::ResumeNetworkLoading()
426 mWebEngine.ResumeNetworkLoading();
430 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
432 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
435 bool WebView::RemoveCustomHeader(const std::string& name)
437 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
440 uint32_t WebView::StartInspectorServer(uint32_t port)
442 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
445 bool WebView::StopInspectorServer()
447 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
450 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
454 mWebEngine.ScrollBy(deltaX, deltaY);
458 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
460 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
463 bool WebView::CanGoForward()
465 return mWebEngine ? mWebEngine.CanGoForward() : false;
468 void WebView::GoForward()
472 mWebEngine.GoForward();
476 bool WebView::CanGoBack()
478 return mWebEngine ? mWebEngine.CanGoBack() : false;
481 void WebView::GoBack()
489 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
493 mWebEngine.EvaluateJavaScript(script, resultHandler);
497 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
501 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
505 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
509 mWebEngine.RegisterJavaScriptAlertCallback(callback);
513 void WebView::JavaScriptAlertReply()
517 mWebEngine.JavaScriptAlertReply();
521 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
525 mWebEngine.RegisterJavaScriptConfirmCallback(callback);
529 void WebView::JavaScriptConfirmReply(bool confirmed)
533 mWebEngine.JavaScriptConfirmReply(confirmed);
537 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
541 mWebEngine.RegisterJavaScriptPromptCallback(callback);
545 void WebView::JavaScriptPromptReply(const std::string& result)
549 mWebEngine.JavaScriptPromptReply(result);
553 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
555 std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
561 return mWebEngine.CreateHitTest(x, y, mode);
564 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
569 result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, callback);
574 void WebView::ClearHistory()
578 mWebEngine.ClearHistory();
582 void WebView::ClearAllTilesResources()
586 mWebEngine.ClearAllTilesResources();
590 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
594 mWebEngine.SetScaleFactor(scaleFactor, point);
598 float WebView::GetScaleFactor() const
600 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
603 void WebView::ActivateAccessibility(bool activated)
607 mWebEngine.ActivateAccessibility(activated);
611 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
613 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
616 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
620 mWebEngine.AddDynamicCertificatePath(host, certPath);
624 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
626 Dali::Toolkit::ImageView imageView;
629 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
630 imageView = CreateImageView(pixelData);
635 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
637 mScreenshotCapturedCallback = callback;
638 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
641 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
643 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
646 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
650 mWebEngine.RegisterGeolocationPermissionCallback(callback);
654 void WebView::SetTtsFocus(bool focused)
656 if(mWebEngine && !HasKeyInputFocus())
658 mWebEngine.SetFocus(focused);
662 void WebView::EnableVideoHole(bool enabled)
664 mVideoHoleEnabled = enabled;
666 EnableBlendMode(!mVideoHoleEnabled);
670 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
674 void WebView::EnableBlendMode(bool blendEnabled)
677 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
679 Dali::Renderer render = self.GetRendererAt(i);
680 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
684 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
688 return Dali::Toolkit::ImageView();
691 Dali::Toolkit::ImageUrl url = Dali::Toolkit::Image::GenerateUrl(pixel);
692 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url.GetUrl());
693 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
697 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
701 mWebEngine.RegisterPageLoadStartedCallback(callback);
705 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
709 mWebEngine.RegisterPageLoadInProgressCallback(callback);
713 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
717 mWebEngine.RegisterPageLoadFinishedCallback(callback);
721 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
725 mWebEngine.RegisterPageLoadErrorCallback(callback);
729 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
733 mWebEngine.RegisterScrollEdgeReachedCallback(callback);
737 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
741 mWebEngine.RegisterUrlChangedCallback(callback);
745 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
749 mWebEngine.RegisterFormRepostDecidedCallback(callback);
753 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
755 mFrameRenderedCallback = callback;
758 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
762 mWebEngine.RegisterConsoleMessageReceivedCallback(callback);
766 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
770 mWebEngine.RegisterResponsePolicyDecidedCallback(callback);
774 void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
778 mWebEngine.RegisterNavigationPolicyDecidedCallback(callback);
782 void WebView::RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback)
786 mWebEngine.RegisterNewWindowCreatedCallback(callback);
790 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
794 mWebEngine.RegisterCertificateConfirmedCallback(callback);
798 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
802 mWebEngine.RegisterSslCertificateChangedCallback(callback);
806 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
810 mWebEngine.RegisterHttpAuthHandlerCallback(callback);
814 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
818 mWebEngine.RegisterContextMenuShownCallback(callback);
822 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
826 mWebEngine.RegisterContextMenuHiddenCallback(callback);
830 void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
834 mWebEngine.GetPlainTextAsynchronously(callback);
838 void WebView::OnFrameRendered()
840 if(mFrameRenderedCallback)
842 mFrameRenderedCallback();
845 // Make sure that mVisual is created only if required.
846 if(mVisualChangeRequired || !mVisual)
849 mVisualChangeRequired = false;
851 auto nativeImageSourcePtr = mWebEngine.GetNativeImageSource();
853 mLastRenderedNativeImageWidth = nativeImageSourcePtr->GetWidth();
854 mLastRenderedNativeImageHeight = nativeImageSourcePtr->GetHeight();
856 Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(nativeImageSourcePtr);
858 mVisual = Toolkit::VisualFactory::Get().CreateVisual(
859 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
860 {Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()},
861 {Toolkit::ImageVisual::Property::PIXEL_AREA, FULL_TEXTURE_RECT},
862 {Toolkit::ImageVisual::Property::WRAP_MODE_U, Dali::WrapMode::CLAMP_TO_EDGE},
863 {Toolkit::ImageVisual::Property::WRAP_MODE_V, Dali::WrapMode::CLAMP_TO_EDGE}});
867 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
868 EnableBlendMode(!mVideoHoleEnabled);
873 void WebView::OnDisplayAreaUpdated(Dali::PropertyNotification& /*source*/)
880 auto displayArea = CalculateDisplayArea(Self(), DisplayAreaCalculateOption::CURRENT_PROPERTY);
882 SetDisplayArea(displayArea);
885 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
887 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
889 SetVisibility(isVisible);
893 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
895 if(mScreenshotCapturedCallback)
897 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
898 mScreenshotCapturedCallback(imageView);
902 void WebView::SetDisplayArea(const Dali::Rect<int32_t>& displayArea)
904 Size displaySize = Size(displayArea.width, displayArea.height);
905 if(mWebViewSize != displaySize)
907 mWebViewSize = displaySize;
910 if(mWebViewArea != displayArea)
912 // WebEngine visual size changed. we have to re-create visual.
913 mVisualChangeRequired = true;
915 // Change old visual's pixel area matched as changed web view size
918 auto pixelArea = CalculatePixelArea(mWebViewSize, mLastRenderedNativeImageWidth, mLastRenderedNativeImageHeight);
919 Toolkit::GetImplementation(mVisual).DoAction(Toolkit::DevelVisual::Action::UPDATE_PROPERTY, {{Toolkit::ImageVisual::Property::PIXEL_AREA, pixelArea}});
922 mWebViewArea = displayArea;
923 mWebEngine.UpdateDisplayArea(mWebViewArea);
927 void WebView::OnSceneConnection(int depth)
929 Control::OnSceneConnection(depth);
930 EnableBlendMode(!mVideoHoleEnabled);
933 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
939 result = mWebEngine.SendTouchEvent(touch);
944 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
950 result = mWebEngine.SendKeyEvent(event);
955 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
958 if(mWebEngine && mMouseEventsEnabled)
960 result = mWebEngine.SendHoverEvent(hover);
965 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
968 if(mWebEngine && mMouseEventsEnabled)
970 result = mWebEngine.SendWheelEvent(wheel);
975 void WebView::OnKeyInputFocusGained()
979 mWebEngine.SetFocus(true);
982 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
985 void WebView::OnKeyInputFocusLost()
989 mWebEngine.SetFocus(false);
992 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
995 Vector3 WebView::GetNaturalSize()
999 Vector2 rendererNaturalSize;
1000 mVisual.GetNaturalSize(rendererNaturalSize);
1001 return Vector3(rendererNaturalSize);
1004 return Vector3(mWebViewSize);
1007 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
1009 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1013 WebView& impl = GetImpl(webView);
1016 case Toolkit::WebView::Property::URL:
1025 case Toolkit::WebView::Property::USER_AGENT:
1028 if(value.Get(input))
1030 impl.SetUserAgent(input);
1034 case Toolkit::WebView::Property::SCROLL_POSITION:
1037 if(value.Get(input))
1039 impl.SetScrollPosition(input.x, input.y);
1043 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1046 if(value.Get(input))
1048 impl.EnableVideoHole(input);
1052 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1055 if(value.Get(input))
1057 impl.EnableMouseEvents(input);
1061 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1064 if(value.Get(input))
1066 impl.EnableKeyEvents(input);
1070 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
1073 if(value.Get(input))
1075 impl.SetDocumentBackgroundColor(input);
1079 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
1082 if(value.Get(input))
1084 impl.ClearTilesWhenHidden(input);
1088 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
1091 if(value.Get(input))
1093 impl.SetTileCoverAreaMultiplier(input);
1097 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
1100 if(value.Get(input))
1102 impl.EnableCursorByClient(input);
1106 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1109 if(value.Get(input))
1111 impl.SetPageZoomFactor(input);
1115 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1118 if(value.Get(input))
1120 impl.SetTextZoomFactor(input);
1130 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1132 Property::Value value;
1134 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1138 WebView& impl = GetImpl(webView);
1139 switch(propertyIndex)
1141 case Toolkit::WebView::Property::URL:
1143 value = impl.GetUrl();
1146 case Toolkit::WebView::Property::USER_AGENT:
1148 value = impl.GetUserAgent();
1151 case Toolkit::WebView::Property::SCROLL_POSITION:
1153 value = impl.GetScrollPosition();
1156 case Toolkit::WebView::Property::SCROLL_SIZE:
1158 value = impl.GetScrollSize();
1161 case Toolkit::WebView::Property::CONTENT_SIZE:
1163 value = impl.GetContentSize();
1166 case Toolkit::WebView::Property::TITLE:
1168 value = impl.GetTitle();
1171 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1173 value = impl.mVideoHoleEnabled;
1176 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1178 value = impl.mMouseEventsEnabled;
1181 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1183 value = impl.mKeyEventsEnabled;
1186 case Toolkit::WebView::Property::SELECTED_TEXT:
1188 value = impl.GetSelectedText();
1191 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1193 value = impl.GetPageZoomFactor();
1196 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1198 value = impl.GetTextZoomFactor();
1201 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1203 value = impl.GetLoadProgressPercentage();
1214 void WebView::SetScrollPosition(int32_t x, int32_t y)
1218 mWebEngine.SetScrollPosition(x, y);
1222 Dali::Vector2 WebView::GetScrollPosition() const
1224 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1227 Dali::Vector2 WebView::GetScrollSize() const
1229 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1232 Dali::Vector2 WebView::GetContentSize() const
1234 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1237 std::string WebView::GetTitle() const
1239 return mWebEngine ? mWebEngine.GetTitle() : std::string();
1242 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1246 mWebEngine.SetDocumentBackgroundColor(color);
1250 void WebView::ClearTilesWhenHidden(bool cleared)
1254 mWebEngine.ClearTilesWhenHidden(cleared);
1258 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1262 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1266 void WebView::EnableCursorByClient(bool enabled)
1270 mWebEngine.EnableCursorByClient(enabled);
1274 std::string WebView::GetSelectedText() const
1276 return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1279 std::string WebView::GetUrl() const
1281 return mWebEngine ? mWebEngine.GetUrl() : std::string();
1284 std::string WebView::GetUserAgent() const
1286 return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1289 void WebView::SetUserAgent(const std::string& userAgent)
1293 mWebEngine.SetUserAgent(userAgent);
1297 void WebView::EnableMouseEvents(bool enabled)
1301 mMouseEventsEnabled = enabled;
1302 mWebEngine.EnableMouseEvents(enabled);
1306 void WebView::EnableKeyEvents(bool enabled)
1310 mKeyEventsEnabled = enabled;
1311 mWebEngine.EnableKeyEvents(enabled);
1315 void WebView::SetPageZoomFactor(float zoomFactor)
1319 mWebEngine.SetPageZoomFactor(zoomFactor);
1323 float WebView::GetPageZoomFactor() const
1325 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1328 void WebView::SetTextZoomFactor(float zoomFactor)
1332 mWebEngine.SetTextZoomFactor(zoomFactor);
1336 float WebView::GetTextZoomFactor() const
1338 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1341 float WebView::GetLoadProgressPercentage() const
1343 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1346 bool WebView::SetVisibility(bool visible)
1348 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1351 WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine)
1352 : ControlAccessible(self),
1354 mWebEngine{webEngine}
1356 mRemoteChild.SetParent(this);
1358 Dali::Accessibility::Bridge::EnabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityEnabled);
1359 Dali::Accessibility::Bridge::DisabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityDisabled);
1361 if(Dali::Accessibility::IsUp())
1363 OnAccessibilityEnabled();
1367 OnAccessibilityDisabled();
1371 Dali::Accessibility::Attributes WebView::WebViewAccessible::GetAttributes() const
1373 auto attributes = DevelControl::ControlAccessible::GetAttributes();
1375 if(mRemoteChild.GetAddress())
1377 attributes.insert_or_assign("child_bus", mRemoteChild.GetAddress().GetBus());
1383 void WebView::WebViewAccessible::DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children)
1385 if(mRemoteChild.GetAddress())
1387 // DoGetChildren is called at most once per every OnChildrenChanged.
1388 // We have only one OnChildrenChanged in this case, so EmbedAtkSocket will be called only once.
1389 Accessibility::Bridge::GetCurrentBridge()->EmbedAtkSocket(GetAddress(), mRemoteChild.GetAddress());
1390 children.push_back(&mRemoteChild);
1394 void WebView::WebViewAccessible::OnAccessibilityEnabled()
1401 mWebEngine.ActivateAccessibility(true);
1402 SetRemoteChildAddress(mWebEngine.GetAccessibilityAddress());
1405 void WebView::WebViewAccessible::OnAccessibilityDisabled()
1412 SetRemoteChildAddress({});
1413 mWebEngine.ActivateAccessibility(false);
1416 void WebView::WebViewAccessible::SetRemoteChildAddress(Dali::Accessibility::Address address)
1418 mRemoteChild.SetAddress(address);
1419 OnChildrenChanged();
1422 } // namespace Internal
1424 } // namespace Toolkit