2 * Copyright (c) 2022 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 "web-view-impl.h"
23 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-back-forward-list.h>
24 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-certificate.h>
25 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-console-message.h>
26 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context-menu-item.h>
27 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context-menu.h>
28 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-context.h>
29 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-cookie-manager.h>
30 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-form-repost-decision.h>
31 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-hit-test.h>
32 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-http-auth-handler.h>
33 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-load-error.h>
34 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-policy-decision.h>
35 #include <dali/devel-api/adaptor-framework/web-engine/web-engine-settings.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/public-api/adaptor-framework/native-image-source.h>
40 #include <dali/public-api/object/type-registry-helper.h>
41 #include <dali/public-api/object/type-registry.h>
44 #include <dali-toolkit/devel-api/controls/control-devel.h>
45 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
46 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
47 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
48 #include <dali-toolkit/public-api/image-loader/image.h>
49 #include <dali-toolkit/public-api/image-loader/image-url.h>
50 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
54 #include <unordered_map>
66 return Toolkit::WebView::New();
70 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
72 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url", STRING, URL )
73 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent", STRING, USER_AGENT )
74 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION )
75 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE )
76 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE )
77 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title", STRING, TITLE )
78 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled", BOOLEAN, VIDEO_HOLE_ENABLED )
79 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled", BOOLEAN, MOUSE_EVENTS_ENABLED )
80 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled", BOOLEAN, KEY_EVENTS_ENABLED )
81 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR )
82 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden", BOOLEAN, TILES_CLEARED_WHEN_HIDDEN )
83 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT, TILE_COVER_AREA_MULTIPLIER)
84 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient", BOOLEAN, CURSOR_ENABLED_BY_CLIENT )
85 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText", STRING, SELECTED_TEXT )
86 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor", FLOAT, PAGE_ZOOM_FACTOR )
87 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor", FLOAT, TEXT_ZOOM_FACTOR )
88 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage", FLOAT, LOAD_PROGRESS_PERCENTAGE )
90 DALI_TYPE_REGISTRATION_END()
93 std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>>& GetPluginWebViewTable()
95 static std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>> pluginWebViewMap;
96 return pluginWebViewMap;
100 WebView::WebView(const std::string& locale, const std::string& timezoneId)
101 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
103 mWebViewSize(Stage::GetCurrent().GetSize()),
105 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
106 mVideoHoleEnabled(false),
107 mMouseEventsEnabled(true),
108 mKeyEventsEnabled(true),
109 mScreenshotCapturedCallback{nullptr},
110 mFrameRenderedCallback{nullptr}
112 mWebEngine = Dali::WebEngine::New();
114 // WebEngine is empty when it is not properly initialized.
117 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
121 WebView::WebView(uint32_t argc, char** argv)
122 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
124 mWebViewSize(Stage::GetCurrent().GetSize()),
126 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
127 mVideoHoleEnabled(false),
128 mMouseEventsEnabled(true),
129 mKeyEventsEnabled(true),
130 mScreenshotCapturedCallback{nullptr},
131 mFrameRenderedCallback{nullptr}
133 mWebEngine = Dali::WebEngine::New();
135 // WebEngine is empty when it is not properly initialized.
138 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
151 auto iter = GetPluginWebViewTable().find(mWebEngine.GetPlugin());
152 if (iter != GetPluginWebViewTable().end())
154 GetPluginWebViewTable().erase(iter);
156 mWebEngine.Destroy();
160 Toolkit::WebView WebView::New()
162 WebView* impl = new WebView();
163 Toolkit::WebView handle = Toolkit::WebView(*impl);
164 if (impl->GetPlugin())
166 GetPluginWebViewTable()[impl->GetPlugin()] = handle;
172 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
174 WebView* impl = new WebView(locale, timezoneId);
175 Toolkit::WebView handle = Toolkit::WebView(*impl);
176 if (impl->GetPlugin())
178 GetPluginWebViewTable()[impl->GetPlugin()] = handle;
184 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
186 WebView* impl = new WebView(argc, argv);
187 Toolkit::WebView handle = Toolkit::WebView(*impl);
188 if (impl->GetPlugin())
190 GetPluginWebViewTable()[impl->GetPlugin()] = handle;
196 Toolkit::WebView WebView::FindWebView(Dali::WebEnginePlugin* plugin)
198 auto iter = GetPluginWebViewTable().find(plugin);
199 if (iter != GetPluginWebViewTable().end())
201 return iter->second.GetHandle();
203 return Toolkit::WebView();
206 Dali::WebEngineContext* WebView::GetContext()
208 return Dali::WebEngine::GetContext();
211 Dali::WebEngineCookieManager* WebView::GetCookieManager()
213 return Dali::WebEngine::GetCookieManager();
216 void WebView::OnInitialize()
220 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
221 self.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
222 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
223 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
224 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
225 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
227 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
228 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
229 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
230 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
231 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
232 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
236 mWebEngine.RegisterFrameRenderedCallback(std::bind(&WebView::OnFrameRendered, this));
237 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
238 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
241 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER);
244 DevelControl::ControlAccessible* WebView::CreateAccessibleObject()
246 return new WebViewAccessible(Self(), mWebEngine);
249 Dali::Toolkit::WebSettings* WebView::GetSettings() const
251 return mWebSettings.get();
254 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
256 return mWebBackForwardList.get();
259 Dali::WebEnginePlugin* WebView::GetPlugin() const
261 return mWebEngine ? mWebEngine.GetPlugin() : nullptr;
264 Dali::Toolkit::ImageView WebView::GetFavicon() const
266 Dali::Toolkit::ImageView faviconView;
269 Dali::PixelData pixelData = mWebEngine.GetFavicon();
270 faviconView = CreateImageView(pixelData);
275 void WebView::LoadUrl(const std::string& url)
279 mWebEngine.LoadUrl(url);
283 void WebView::LoadHtmlString(const std::string& htmlString)
287 mWebEngine.LoadHtmlString(htmlString);
291 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
296 return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
299 bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
304 return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
307 void WebView::Reload()
315 bool WebView::ReloadWithoutCache()
317 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
320 void WebView::StopLoading()
324 mWebEngine.StopLoading();
328 void WebView::Suspend()
332 mWebEngine.Suspend();
336 void WebView::Resume()
344 void WebView::SuspendNetworkLoading()
348 mWebEngine.SuspendNetworkLoading();
352 void WebView::ResumeNetworkLoading()
356 mWebEngine.ResumeNetworkLoading();
360 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
362 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
365 bool WebView::RemoveCustomHeader(const std::string& name)
367 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
370 uint32_t WebView::StartInspectorServer(uint32_t port)
372 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
375 bool WebView::StopInspectorServer()
377 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
380 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
384 mWebEngine.ScrollBy(deltaX, deltaY);
388 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
390 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
393 bool WebView::CanGoForward()
395 return mWebEngine ? mWebEngine.CanGoForward() : false;
398 void WebView::GoForward()
402 mWebEngine.GoForward();
406 bool WebView::CanGoBack()
408 return mWebEngine ? mWebEngine.CanGoBack() : false;
411 void WebView::GoBack()
419 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
423 mWebEngine.EvaluateJavaScript(script, resultHandler);
427 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
431 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
435 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
439 mWebEngine.RegisterJavaScriptAlertCallback(callback);
443 void WebView::JavaScriptAlertReply()
447 mWebEngine.JavaScriptAlertReply();
451 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
455 mWebEngine.RegisterJavaScriptConfirmCallback(callback);
459 void WebView::JavaScriptConfirmReply(bool confirmed)
463 mWebEngine.JavaScriptConfirmReply(confirmed);
467 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
471 mWebEngine.RegisterJavaScriptPromptCallback(callback);
475 void WebView::JavaScriptPromptReply(const std::string& result)
479 mWebEngine.JavaScriptPromptReply(result);
483 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
485 std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
491 return mWebEngine.CreateHitTest(x, y, mode);
494 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
499 result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, callback);
504 void WebView::ClearHistory()
508 mWebEngine.ClearHistory();
512 void WebView::ClearAllTilesResources()
516 mWebEngine.ClearAllTilesResources();
520 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
524 mWebEngine.SetScaleFactor(scaleFactor, point);
528 float WebView::GetScaleFactor() const
530 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
533 void WebView::ActivateAccessibility(bool activated)
537 mWebEngine.ActivateAccessibility(activated);
541 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
543 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
546 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
550 mWebEngine.AddDynamicCertificatePath(host, certPath);
554 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
556 Dali::Toolkit::ImageView imageView;
559 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
560 imageView = CreateImageView(pixelData);
565 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
567 mScreenshotCapturedCallback = callback;
568 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
571 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
573 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
576 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
580 mWebEngine.RegisterGeolocationPermissionCallback(callback);
584 void WebView::SetTtsFocus(bool focused)
586 if(mWebEngine && !HasKeyInputFocus())
588 mWebEngine.SetFocus(focused);
592 void WebView::EnableVideoHole(bool enabled)
594 mVideoHoleEnabled = enabled;
596 EnableBlendMode(!mVideoHoleEnabled);
600 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
604 void WebView::EnableBlendMode(bool blendEnabled)
607 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
609 Dali::Renderer render = self.GetRendererAt(i);
610 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
614 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
618 return Dali::Toolkit::ImageView();
621 Dali::Toolkit::ImageUrl url = Dali::Toolkit::Image::GenerateUrl(pixel);
622 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url.GetUrl());
623 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
627 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
631 mWebEngine.RegisterPageLoadStartedCallback(callback);
635 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
639 mWebEngine.RegisterPageLoadInProgressCallback(callback);
643 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
647 mWebEngine.RegisterPageLoadFinishedCallback(callback);
651 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
655 mWebEngine.RegisterPageLoadErrorCallback(callback);
659 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
663 mWebEngine.RegisterScrollEdgeReachedCallback(callback);
667 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
671 mWebEngine.RegisterUrlChangedCallback(callback);
675 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
679 mWebEngine.RegisterFormRepostDecidedCallback(callback);
683 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
685 mFrameRenderedCallback = callback;
688 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
692 mWebEngine.RegisterConsoleMessageReceivedCallback(callback);
696 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
700 mWebEngine.RegisterResponsePolicyDecidedCallback(callback);
704 void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
708 mWebEngine.RegisterNavigationPolicyDecidedCallback(callback);
712 void WebView::RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback)
716 mWebEngine.RegisterNewWindowCreatedCallback(callback);
720 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
724 mWebEngine.RegisterCertificateConfirmedCallback(callback);
728 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
732 mWebEngine.RegisterSslCertificateChangedCallback(callback);
736 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
740 mWebEngine.RegisterHttpAuthHandlerCallback(callback);
744 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
748 mWebEngine.RegisterContextMenuShownCallback(callback);
752 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
756 mWebEngine.RegisterContextMenuHiddenCallback(callback);
760 void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
764 mWebEngine.GetPlainTextAsynchronously(callback);
768 void WebView::OnFrameRendered()
770 if(mFrameRenderedCallback)
772 mFrameRenderedCallback();
775 // Make sure that mVisual is created only once.
779 Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(mWebEngine.GetNativeImageSource());
780 mVisual = Toolkit::VisualFactory::Get().CreateVisual({{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, {Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()}});
783 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
784 EnableBlendMode(!mVideoHoleEnabled);
788 void WebView::OnDisplayAreaUpdated(Dali::PropertyNotification& /*source*/)
795 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
796 Vector3 actorSize = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
797 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
798 Vector2 screenPosition = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
800 Dali::Rect<int32_t> displayArea;
801 displayArea.x = screenPosition.x - anchorPointOffSet.x;
802 displayArea.y = screenPosition.y - anchorPointOffSet.y;
803 displayArea.width = actorSize.x;
804 displayArea.height = actorSize.y;
806 Size displaySize = Size(displayArea.width, displayArea.height);
807 if(mWebViewSize != displaySize)
809 mWebViewSize = displaySize;
812 if(mWebViewArea != displayArea)
814 mWebViewArea = displayArea;
815 mWebEngine.UpdateDisplayArea(mWebViewArea);
819 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
821 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
823 SetVisibility(isVisible);
827 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
829 if(mScreenshotCapturedCallback)
831 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
832 mScreenshotCapturedCallback(imageView);
836 void WebView::OnSceneConnection(int depth)
838 Control::OnSceneConnection(depth);
839 EnableBlendMode(!mVideoHoleEnabled);
842 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
848 result = mWebEngine.SendTouchEvent(touch);
853 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
859 result = mWebEngine.SendKeyEvent(event);
864 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
867 if(mWebEngine && mMouseEventsEnabled)
869 result = mWebEngine.SendHoverEvent(hover);
874 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
877 if(mWebEngine && mMouseEventsEnabled)
879 result = mWebEngine.SendWheelEvent(wheel);
884 void WebView::OnKeyInputFocusGained()
888 mWebEngine.SetFocus(true);
891 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
894 void WebView::OnKeyInputFocusLost()
898 mWebEngine.SetFocus(false);
901 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
904 Vector3 WebView::GetNaturalSize()
908 Vector2 rendererNaturalSize;
909 mVisual.GetNaturalSize(rendererNaturalSize);
910 return Vector3(rendererNaturalSize);
913 return Vector3(mWebViewSize);
916 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
918 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
922 WebView& impl = GetImpl(webView);
925 case Toolkit::WebView::Property::URL:
934 case Toolkit::WebView::Property::USER_AGENT:
939 impl.SetUserAgent(input);
943 case Toolkit::WebView::Property::SCROLL_POSITION:
948 impl.SetScrollPosition(input.x, input.y);
952 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
957 impl.EnableVideoHole(input);
961 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
966 impl.EnableMouseEvents(input);
970 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
975 impl.EnableKeyEvents(input);
979 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
984 impl.SetDocumentBackgroundColor(input);
988 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
993 impl.ClearTilesWhenHidden(input);
997 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
1000 if(value.Get(input))
1002 impl.SetTileCoverAreaMultiplier(input);
1006 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
1009 if(value.Get(input))
1011 impl.EnableCursorByClient(input);
1015 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1018 if(value.Get(input))
1020 impl.SetPageZoomFactor(input);
1024 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1027 if(value.Get(input))
1029 impl.SetTextZoomFactor(input);
1039 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1041 Property::Value value;
1043 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1047 WebView& impl = GetImpl(webView);
1048 switch(propertyIndex)
1050 case Toolkit::WebView::Property::URL:
1052 value = impl.GetUrl();
1055 case Toolkit::WebView::Property::USER_AGENT:
1057 value = impl.GetUserAgent();
1060 case Toolkit::WebView::Property::SCROLL_POSITION:
1062 value = impl.GetScrollPosition();
1065 case Toolkit::WebView::Property::SCROLL_SIZE:
1067 value = impl.GetScrollSize();
1070 case Toolkit::WebView::Property::CONTENT_SIZE:
1072 value = impl.GetContentSize();
1075 case Toolkit::WebView::Property::TITLE:
1077 value = impl.GetTitle();
1080 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1082 value = impl.mVideoHoleEnabled;
1085 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1087 value = impl.mMouseEventsEnabled;
1090 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1092 value = impl.mKeyEventsEnabled;
1095 case Toolkit::WebView::Property::SELECTED_TEXT:
1097 value = impl.GetSelectedText();
1100 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1102 value = impl.GetPageZoomFactor();
1105 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1107 value = impl.GetTextZoomFactor();
1110 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1112 value = impl.GetLoadProgressPercentage();
1123 void WebView::SetScrollPosition(int32_t x, int32_t y)
1127 mWebEngine.SetScrollPosition(x, y);
1131 Dali::Vector2 WebView::GetScrollPosition() const
1133 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1136 Dali::Vector2 WebView::GetScrollSize() const
1138 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1141 Dali::Vector2 WebView::GetContentSize() const
1143 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1146 std::string WebView::GetTitle() const
1148 return mWebEngine ? mWebEngine.GetTitle() : std::string();
1151 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1155 mWebEngine.SetDocumentBackgroundColor(color);
1159 void WebView::ClearTilesWhenHidden(bool cleared)
1163 mWebEngine.ClearTilesWhenHidden(cleared);
1167 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1171 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1175 void WebView::EnableCursorByClient(bool enabled)
1179 mWebEngine.EnableCursorByClient(enabled);
1183 std::string WebView::GetSelectedText() const
1185 return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1188 std::string WebView::GetUrl() const
1190 return mWebEngine ? mWebEngine.GetUrl() : std::string();
1193 std::string WebView::GetUserAgent() const
1195 return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1198 void WebView::SetUserAgent(const std::string& userAgent)
1202 mWebEngine.SetUserAgent(userAgent);
1206 void WebView::EnableMouseEvents(bool enabled)
1210 mMouseEventsEnabled = enabled;
1211 mWebEngine.EnableMouseEvents(enabled);
1215 void WebView::EnableKeyEvents(bool enabled)
1219 mKeyEventsEnabled = enabled;
1220 mWebEngine.EnableKeyEvents(enabled);
1224 void WebView::SetPageZoomFactor(float zoomFactor)
1228 mWebEngine.SetPageZoomFactor(zoomFactor);
1232 float WebView::GetPageZoomFactor() const
1234 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1237 void WebView::SetTextZoomFactor(float zoomFactor)
1241 mWebEngine.SetTextZoomFactor(zoomFactor);
1245 float WebView::GetTextZoomFactor() const
1247 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1250 float WebView::GetLoadProgressPercentage() const
1252 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1255 bool WebView::SetVisibility(bool visible)
1257 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1260 WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine)
1261 : ControlAccessible(self), mRemoteChild{}, mWebEngine{webEngine}
1263 mRemoteChild.SetParent(this);
1265 Dali::Accessibility::Bridge::EnabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityEnabled);
1266 Dali::Accessibility::Bridge::DisabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityDisabled);
1268 if(Dali::Accessibility::IsUp())
1270 OnAccessibilityEnabled();
1274 OnAccessibilityDisabled();
1278 Dali::Accessibility::Attributes WebView::WebViewAccessible::GetAttributes() const
1280 auto attributes = DevelControl::ControlAccessible::GetAttributes();
1282 if(mRemoteChild.GetAddress())
1284 attributes.insert_or_assign("child_bus", mRemoteChild.GetAddress().GetBus());
1290 void WebView::WebViewAccessible::DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children)
1292 if(mRemoteChild.GetAddress())
1294 // DoGetChildren is called at most once per every OnChildrenChanged.
1295 // We have only one OnChildrenChanged in this case, so EmbedAtkSocket will be called only once.
1296 Accessibility::Bridge::GetCurrentBridge()->EmbedAtkSocket(GetAddress(), mRemoteChild.GetAddress());
1297 children.push_back(&mRemoteChild);
1301 void WebView::WebViewAccessible::OnAccessibilityEnabled()
1308 mWebEngine.ActivateAccessibility(true);
1309 SetRemoteChildAddress(mWebEngine.GetAccessibilityAddress());
1312 void WebView::WebViewAccessible::OnAccessibilityDisabled()
1319 SetRemoteChildAddress({});
1320 mWebEngine.ActivateAccessibility(false);
1323 void WebView::WebViewAccessible::SetRemoteChildAddress(Dali::Accessibility::Address address)
1325 mRemoteChild.SetAddress(address);
1326 OnChildrenChanged();
1329 } // namespace Internal
1331 } // namespace Toolkit