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"
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>
45 #include <dali-toolkit/devel-api/controls/control-devel.h>
46 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
47 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
48 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
49 #include <dali-toolkit/public-api/image-loader/image.h>
50 #include <dali-toolkit/public-api/image-loader/image-url.h>
51 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
63 return Toolkit::WebView::New();
67 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
69 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url", STRING, URL )
70 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent", STRING, USER_AGENT )
71 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION )
72 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE )
73 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE )
74 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title", STRING, TITLE )
75 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled", BOOLEAN, VIDEO_HOLE_ENABLED )
76 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled", BOOLEAN, MOUSE_EVENTS_ENABLED )
77 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled", BOOLEAN, KEY_EVENTS_ENABLED )
78 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR )
79 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden", BOOLEAN, TILES_CLEARED_WHEN_HIDDEN )
80 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT, TILE_COVER_AREA_MULTIPLIER)
81 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient", BOOLEAN, CURSOR_ENABLED_BY_CLIENT )
82 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText", STRING, SELECTED_TEXT )
83 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor", FLOAT, PAGE_ZOOM_FACTOR )
84 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor", FLOAT, TEXT_ZOOM_FACTOR )
85 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage", FLOAT, LOAD_PROGRESS_PERCENTAGE )
87 DALI_TYPE_REGISTRATION_END()
92 #define GET_ENUM_STRING(structName, inputExp) \
93 Scripting::GetLinearEnumerationName<Toolkit::WebView::structName::Type>(static_cast<Toolkit::WebView::structName::Type>(inputExp), structName##_TABLE, structName##_TABLE_COUNT)
95 #define GET_ENUM_VALUE(structName, inputExp, outputExp) \
96 Scripting::GetEnumerationProperty<Toolkit::WebView::structName::Type>(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp)
98 std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>> WebView::mPluginWebViewMap;
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)
111 mWebEngine = Dali::WebEngine::New();
113 // WebEngine is empty when it is not properly initialized.
116 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
120 WebView::WebView(uint32_t argc, char** argv)
121 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
123 mWebViewSize(Stage::GetCurrent().GetSize()),
125 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
126 mVideoHoleEnabled(false),
127 mMouseEventsEnabled(true),
128 mKeyEventsEnabled(true),
129 mScreenshotCapturedCallback(nullptr)
131 mWebEngine = Dali::WebEngine::New();
133 // WebEngine is empty when it is not properly initialized.
136 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
149 mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnFrameRendered);
150 auto iter = mPluginWebViewMap.find(mWebEngine.GetPlugin());
151 if (iter != mPluginWebViewMap.end())
153 mPluginWebViewMap.erase(iter);
155 mWebEngine.Destroy();
159 Toolkit::WebView WebView::New()
161 WebView* impl = new WebView();
162 Toolkit::WebView handle = Toolkit::WebView(*impl);
163 if (impl->GetPlugin())
165 mPluginWebViewMap[impl->GetPlugin()] = handle;
171 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
173 WebView* impl = new WebView(locale, timezoneId);
174 Toolkit::WebView handle = Toolkit::WebView(*impl);
175 if (impl->GetPlugin())
177 mPluginWebViewMap[impl->GetPlugin()] = handle;
183 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
185 WebView* impl = new WebView(argc, argv);
186 Toolkit::WebView handle = Toolkit::WebView(*impl);
187 if (impl->GetPlugin())
189 mPluginWebViewMap[impl->GetPlugin()] = handle;
195 Toolkit::WebView WebView::FindWebView(Dali::WebEnginePlugin* plugin)
197 auto iter = mPluginWebViewMap.find(plugin);
198 if (iter != mPluginWebViewMap.end())
200 return iter->second.GetHandle();
202 return Toolkit::WebView();
205 Dali::WebEngineContext* WebView::GetContext()
207 return Dali::WebEngine::GetContext();
210 Dali::WebEngineCookieManager* WebView::GetCookieManager()
212 return Dali::WebEngine::GetCookieManager();
215 void WebView::OnInitialize()
219 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
220 self.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
221 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
222 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
223 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
224 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
226 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
227 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
228 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
229 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
230 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
231 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
235 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered);
236 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
237 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
240 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER);
243 Dali::WebEnginePlugin* WebView::GetPlugin() const
245 return mWebEngine ? mWebEngine.GetPlugin() : nullptr;
248 DevelControl::ControlAccessible* WebView::CreateAccessibleObject()
250 return new WebViewAccessible(Self(), mWebEngine);
253 Dali::Toolkit::WebSettings* WebView::GetSettings() const
255 return mWebSettings.get();
258 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
260 return mWebBackForwardList.get();
263 Dali::Toolkit::ImageView WebView::GetFavicon() const
265 Dali::Toolkit::ImageView faviconView;
268 Dali::PixelData pixelData = mWebEngine.GetFavicon();
269 faviconView = CreateImageView(pixelData);
274 void WebView::LoadUrl(const std::string& url)
280 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
283 mWebEngine.LoadUrl(url);
287 void WebView::LoadHtmlString(const std::string& htmlString)
293 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
296 mWebEngine.LoadHtmlString(htmlString);
300 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
307 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
310 return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
313 bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
320 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
323 return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
326 void WebView::Reload()
334 bool WebView::ReloadWithoutCache()
336 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
339 void WebView::StopLoading()
343 mWebEngine.StopLoading();
347 void WebView::Suspend()
351 mWebEngine.Suspend();
355 void WebView::Resume()
363 void WebView::SuspendNetworkLoading()
367 mWebEngine.SuspendNetworkLoading();
371 void WebView::ResumeNetworkLoading()
375 mWebEngine.ResumeNetworkLoading();
379 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
381 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
384 bool WebView::RemoveCustomHeader(const std::string& name)
386 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
389 uint32_t WebView::StartInspectorServer(uint32_t port)
391 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
394 bool WebView::StopInspectorServer()
396 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
399 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
403 mWebEngine.ScrollBy(deltaX, deltaY);
407 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
409 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
412 bool WebView::CanGoForward()
414 return mWebEngine ? mWebEngine.CanGoForward() : false;
417 void WebView::GoForward()
421 mWebEngine.GoForward();
425 bool WebView::CanGoBack()
427 return mWebEngine ? mWebEngine.CanGoBack() : false;
430 void WebView::GoBack()
438 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
442 mWebEngine.EvaluateJavaScript(script, resultHandler);
446 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
450 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
454 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
458 mWebEngine.RegisterJavaScriptAlertCallback(callback);
462 void WebView::JavaScriptAlertReply()
466 mWebEngine.JavaScriptAlertReply();
470 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
474 mWebEngine.RegisterJavaScriptConfirmCallback(callback);
478 void WebView::JavaScriptConfirmReply(bool confirmed)
482 mWebEngine.JavaScriptConfirmReply(confirmed);
486 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
490 mWebEngine.RegisterJavaScriptPromptCallback(callback);
494 void WebView::JavaScriptPromptReply(const std::string& result)
498 mWebEngine.JavaScriptPromptReply(result);
502 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
504 std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
510 return mWebEngine.CreateHitTest(x, y, mode);
513 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
518 result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, callback);
523 void WebView::ClearHistory()
527 mWebEngine.ClearHistory();
531 void WebView::ClearAllTilesResources()
535 mWebEngine.ClearAllTilesResources();
539 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
543 mWebEngine.SetScaleFactor(scaleFactor, point);
547 float WebView::GetScaleFactor() const
549 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
552 void WebView::ActivateAccessibility(bool activated)
556 mWebEngine.ActivateAccessibility(activated);
560 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
562 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
565 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
569 mWebEngine.AddDynamicCertificatePath(host, certPath);
573 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
575 Dali::Toolkit::ImageView imageView;
578 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
579 imageView = CreateImageView(pixelData);
584 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
586 mScreenshotCapturedCallback = callback;
587 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
590 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
592 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
595 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
599 mWebEngine.RegisterGeolocationPermissionCallback(callback);
603 void WebView::SetTtsFocus(bool focused)
605 if(mWebEngine && !HasKeyInputFocus())
607 mWebEngine.SetFocus(focused);
611 void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/)
618 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
619 Vector3 actorSize = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
620 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
621 Vector2 screenPosition = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
623 Dali::Rect<int32_t> displayArea;
624 displayArea.x = screenPosition.x - anchorPointOffSet.x;
625 displayArea.y = screenPosition.y - anchorPointOffSet.y;
626 displayArea.width = actorSize.x;
627 displayArea.height = actorSize.y;
629 Size displaySize = Size(displayArea.width, displayArea.height);
630 if(mWebViewSize != displaySize)
632 mWebViewSize = displaySize;
635 if(mWebViewArea != displayArea)
637 mWebViewArea = displayArea;
638 mWebEngine.UpdateDisplayArea(mWebViewArea);
642 void WebView::EnableVideoHole(bool enabled)
644 mVideoHoleEnabled = enabled;
646 EnableBlendMode(!mVideoHoleEnabled);
650 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
654 void WebView::EnableBlendMode(bool blendEnabled)
657 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
659 Dali::Renderer render = self.GetRendererAt(i);
660 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
664 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
668 return Dali::Toolkit::ImageView();
671 Dali::Toolkit::ImageUrl url = Dali::Toolkit::Image::GenerateUrl(pixel);
672 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url.GetUrl());
673 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
677 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
681 mWebEngine.RegisterPageLoadStartedCallback(callback);
685 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
689 mWebEngine.RegisterPageLoadInProgressCallback(callback);
693 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
697 mWebEngine.RegisterPageLoadFinishedCallback(callback);
701 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
705 mWebEngine.RegisterPageLoadErrorCallback(callback);
709 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
713 mWebEngine.RegisterScrollEdgeReachedCallback(callback);
717 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
721 mWebEngine.RegisterUrlChangedCallback(callback);
725 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
729 mWebEngine.RegisterFormRepostDecidedCallback(callback);
733 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
735 mFrameRenderedCallback = callback;
738 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
742 mWebEngine.RegisterConsoleMessageReceivedCallback(callback);
746 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
750 mWebEngine.RegisterResponsePolicyDecidedCallback(callback);
754 void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
758 mWebEngine.RegisterNavigationPolicyDecidedCallback(callback);
762 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
766 mWebEngine.RegisterCertificateConfirmedCallback(callback);
770 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
774 mWebEngine.RegisterSslCertificateChangedCallback(callback);
778 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
782 mWebEngine.RegisterHttpAuthHandlerCallback(callback);
786 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
790 mWebEngine.RegisterContextMenuShownCallback(callback);
794 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
798 mWebEngine.RegisterContextMenuHiddenCallback(callback);
802 void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
806 mWebEngine.GetPlainTextAsynchronously(callback);
810 void WebView::OnFrameRendered()
812 if(mFrameRenderedCallback)
814 mFrameRenderedCallback();
818 void WebView::OnInitialFrameRendered()
820 mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnInitialFrameRendered);
822 Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(mWebEngine.GetNativeImageSource());
823 mVisual = Toolkit::VisualFactory::Get().CreateVisual({{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, {Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()}});
827 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
828 EnableBlendMode(!mVideoHoleEnabled);
832 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
834 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
836 SetVisibility(isVisible);
840 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
842 if(mScreenshotCapturedCallback)
844 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
845 mScreenshotCapturedCallback(imageView);
849 void WebView::OnSceneConnection(int depth)
851 Control::OnSceneConnection(depth);
852 EnableBlendMode(!mVideoHoleEnabled);
855 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
861 result = mWebEngine.SendTouchEvent(touch);
866 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
872 result = mWebEngine.SendKeyEvent(event);
877 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
880 if(mWebEngine && mMouseEventsEnabled)
882 result = mWebEngine.SendHoverEvent(hover);
887 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
890 if(mWebEngine && mMouseEventsEnabled)
892 result = mWebEngine.SendWheelEvent(wheel);
897 void WebView::OnKeyInputFocusGained()
901 mWebEngine.SetFocus(true);
904 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
907 void WebView::OnKeyInputFocusLost()
911 mWebEngine.SetFocus(false);
914 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
917 Vector3 WebView::GetNaturalSize()
921 Vector2 rendererNaturalSize;
922 mVisual.GetNaturalSize(rendererNaturalSize);
923 return Vector3(rendererNaturalSize);
926 return Vector3(mWebViewSize);
929 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
931 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
935 WebView& impl = GetImpl(webView);
938 case Toolkit::WebView::Property::URL:
947 case Toolkit::WebView::Property::USER_AGENT:
952 impl.SetUserAgent(input);
956 case Toolkit::WebView::Property::SCROLL_POSITION:
961 impl.SetScrollPosition(input.x, input.y);
965 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
970 impl.EnableVideoHole(input);
974 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
979 impl.EnableMouseEvents(input);
983 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
988 impl.EnableKeyEvents(input);
992 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
997 impl.SetDocumentBackgroundColor(input);
1001 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
1004 if(value.Get(input))
1006 impl.ClearTilesWhenHidden(input);
1010 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
1013 if(value.Get(input))
1015 impl.SetTileCoverAreaMultiplier(input);
1019 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
1022 if(value.Get(input))
1024 impl.EnableCursorByClient(input);
1028 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1031 if(value.Get(input))
1033 impl.SetPageZoomFactor(input);
1037 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1040 if(value.Get(input))
1042 impl.SetTextZoomFactor(input);
1052 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1054 Property::Value value;
1056 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1060 WebView& impl = GetImpl(webView);
1061 switch(propertyIndex)
1063 case Toolkit::WebView::Property::URL:
1065 value = impl.GetUrl();
1068 case Toolkit::WebView::Property::USER_AGENT:
1070 value = impl.GetUserAgent();
1073 case Toolkit::WebView::Property::SCROLL_POSITION:
1075 value = impl.GetScrollPosition();
1078 case Toolkit::WebView::Property::SCROLL_SIZE:
1080 value = impl.GetScrollSize();
1083 case Toolkit::WebView::Property::CONTENT_SIZE:
1085 value = impl.GetContentSize();
1088 case Toolkit::WebView::Property::TITLE:
1090 value = impl.GetTitle();
1093 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1095 value = impl.mVideoHoleEnabled;
1098 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1100 value = impl.mMouseEventsEnabled;
1103 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1105 value = impl.mKeyEventsEnabled;
1108 case Toolkit::WebView::Property::SELECTED_TEXT:
1110 value = impl.GetSelectedText();
1113 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1115 value = impl.GetPageZoomFactor();
1118 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1120 value = impl.GetTextZoomFactor();
1123 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1125 value = impl.GetLoadProgressPercentage();
1136 void WebView::SetScrollPosition(int32_t x, int32_t y)
1140 mWebEngine.SetScrollPosition(x, y);
1144 Dali::Vector2 WebView::GetScrollPosition() const
1146 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1149 Dali::Vector2 WebView::GetScrollSize() const
1151 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1154 Dali::Vector2 WebView::GetContentSize() const
1156 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1159 std::string WebView::GetTitle() const
1161 return mWebEngine ? mWebEngine.GetTitle() : std::string();
1164 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1168 mWebEngine.SetDocumentBackgroundColor(color);
1172 void WebView::ClearTilesWhenHidden(bool cleared)
1176 mWebEngine.ClearTilesWhenHidden(cleared);
1180 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1184 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1188 void WebView::EnableCursorByClient(bool enabled)
1192 mWebEngine.EnableCursorByClient(enabled);
1196 std::string WebView::GetSelectedText() const
1198 return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1201 std::string WebView::GetUrl() const
1203 return mWebEngine ? mWebEngine.GetUrl() : std::string();
1206 std::string WebView::GetUserAgent() const
1208 return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1211 void WebView::SetUserAgent(const std::string& userAgent)
1215 mWebEngine.SetUserAgent(userAgent);
1219 void WebView::EnableMouseEvents(bool enabled)
1223 mMouseEventsEnabled = enabled;
1224 mWebEngine.EnableMouseEvents(enabled);
1228 void WebView::EnableKeyEvents(bool enabled)
1232 mKeyEventsEnabled = enabled;
1233 mWebEngine.EnableKeyEvents(enabled);
1237 void WebView::SetPageZoomFactor(float zoomFactor)
1241 mWebEngine.SetPageZoomFactor(zoomFactor);
1245 float WebView::GetPageZoomFactor() const
1247 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1250 void WebView::SetTextZoomFactor(float zoomFactor)
1254 mWebEngine.SetTextZoomFactor(zoomFactor);
1258 float WebView::GetTextZoomFactor() const
1260 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1263 float WebView::GetLoadProgressPercentage() const
1265 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1268 bool WebView::SetVisibility(bool visible)
1270 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1273 WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine)
1274 : ControlAccessible(self), mRemoteChild{}, mWebEngine{webEngine}
1276 mRemoteChild.SetParent(this);
1278 Dali::Accessibility::Bridge::EnabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityEnabled);
1279 Dali::Accessibility::Bridge::DisabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityDisabled);
1281 if(Dali::Accessibility::IsUp())
1283 OnAccessibilityEnabled();
1287 OnAccessibilityDisabled();
1291 void WebView::WebViewAccessible::DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children)
1293 if(mRemoteChild.GetAddress())
1295 children.push_back(&mRemoteChild);
1299 void WebView::WebViewAccessible::OnAccessibilityEnabled()
1306 mWebEngine.ActivateAccessibility(true);
1307 SetRemoteChildAddress(mWebEngine.GetAccessibilityAddress());
1310 void WebView::WebViewAccessible::OnAccessibilityDisabled()
1317 SetRemoteChildAddress({});
1318 mWebEngine.ActivateAccessibility(false);
1321 void WebView::WebViewAccessible::SetRemoteChildAddress(Dali::Accessibility::Address address)
1323 mRemoteChild.SetAddress(address);
1324 OnChildrenChanged();
1328 Accessibility::Bridge::GetCurrentBridge()->EmbedAtkSocket(GetAddress(), address);
1332 #undef GET_ENUM_STRING
1333 #undef GET_ENUM_VALUE
1335 } // namespace Internal
1337 } // namespace Toolkit