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 WebView::WebView(const std::string& locale, const std::string& timezoneId)
99 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
101 mWebViewSize(Stage::GetCurrent().GetSize()),
103 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
104 mVideoHoleEnabled(false),
105 mMouseEventsEnabled(true),
106 mKeyEventsEnabled(true),
107 mScreenshotCapturedCallback(nullptr)
109 mWebEngine = Dali::WebEngine::New();
111 // WebEngine is empty when it is not properly initialized.
114 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
118 WebView::WebView(uint32_t argc, char** argv)
119 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
121 mWebViewSize(Stage::GetCurrent().GetSize()),
123 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
124 mVideoHoleEnabled(false),
125 mMouseEventsEnabled(true),
126 mKeyEventsEnabled(true),
127 mScreenshotCapturedCallback(nullptr)
129 mWebEngine = Dali::WebEngine::New();
131 // WebEngine is empty when it is not properly initialized.
134 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
147 mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnFrameRendered);
148 mWebEngine.Destroy();
152 Toolkit::WebView WebView::New()
154 WebView* impl = new WebView();
155 Toolkit::WebView handle = Toolkit::WebView(*impl);
161 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
163 WebView* impl = new WebView(locale, timezoneId);
164 Toolkit::WebView handle = Toolkit::WebView(*impl);
170 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
172 WebView* impl = new WebView(argc, argv);
173 Toolkit::WebView handle = Toolkit::WebView(*impl);
179 Dali::WebEngineContext* WebView::GetContext()
181 return Dali::WebEngine::GetContext();
184 Dali::WebEngineCookieManager* WebView::GetCookieManager()
186 return Dali::WebEngine::GetCookieManager();
189 void WebView::OnInitialize()
193 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
194 self.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
195 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
196 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
197 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
198 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
200 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
201 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
202 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
203 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
204 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
205 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
209 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered);
210 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
211 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
214 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER);
217 DevelControl::ControlAccessible* WebView::CreateAccessibleObject()
219 return new WebViewAccessible(Self(), mWebEngine);
222 Dali::Toolkit::WebSettings* WebView::GetSettings() const
224 return mWebSettings.get();
227 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
229 return mWebBackForwardList.get();
232 Dali::Toolkit::ImageView WebView::GetFavicon() const
234 Dali::Toolkit::ImageView faviconView;
237 Dali::PixelData pixelData = mWebEngine.GetFavicon();
238 faviconView = CreateImageView(pixelData);
243 void WebView::LoadUrl(const std::string& url)
249 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
252 mWebEngine.LoadUrl(url);
256 void WebView::LoadHtmlString(const std::string& htmlString)
262 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
265 mWebEngine.LoadHtmlString(htmlString);
269 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
276 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
279 return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
282 bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
289 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
292 return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
295 void WebView::Reload()
303 bool WebView::ReloadWithoutCache()
305 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
308 void WebView::StopLoading()
312 mWebEngine.StopLoading();
316 void WebView::Suspend()
320 mWebEngine.Suspend();
324 void WebView::Resume()
332 void WebView::SuspendNetworkLoading()
336 mWebEngine.SuspendNetworkLoading();
340 void WebView::ResumeNetworkLoading()
344 mWebEngine.ResumeNetworkLoading();
348 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
350 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
353 bool WebView::RemoveCustomHeader(const std::string& name)
355 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
358 uint32_t WebView::StartInspectorServer(uint32_t port)
360 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
363 bool WebView::StopInspectorServer()
365 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
368 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
372 mWebEngine.ScrollBy(deltaX, deltaY);
376 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
378 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
381 bool WebView::CanGoForward()
383 return mWebEngine ? mWebEngine.CanGoForward() : false;
386 void WebView::GoForward()
390 mWebEngine.GoForward();
394 bool WebView::CanGoBack()
396 return mWebEngine ? mWebEngine.CanGoBack() : false;
399 void WebView::GoBack()
407 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
411 mWebEngine.EvaluateJavaScript(script, resultHandler);
415 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
419 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
423 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
427 mWebEngine.RegisterJavaScriptAlertCallback(callback);
431 void WebView::JavaScriptAlertReply()
435 mWebEngine.JavaScriptAlertReply();
439 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
443 mWebEngine.RegisterJavaScriptConfirmCallback(callback);
447 void WebView::JavaScriptConfirmReply(bool confirmed)
451 mWebEngine.JavaScriptConfirmReply(confirmed);
455 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
459 mWebEngine.RegisterJavaScriptPromptCallback(callback);
463 void WebView::JavaScriptPromptReply(const std::string& result)
467 mWebEngine.JavaScriptPromptReply(result);
471 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
473 std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
479 return mWebEngine.CreateHitTest(x, y, mode);
482 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
487 result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, callback);
492 void WebView::ClearHistory()
496 mWebEngine.ClearHistory();
500 void WebView::ClearAllTilesResources()
504 mWebEngine.ClearAllTilesResources();
508 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
512 mWebEngine.SetScaleFactor(scaleFactor, point);
516 float WebView::GetScaleFactor() const
518 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
521 void WebView::ActivateAccessibility(bool activated)
525 mWebEngine.ActivateAccessibility(activated);
529 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
531 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
534 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
538 mWebEngine.AddDynamicCertificatePath(host, certPath);
542 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
544 Dali::Toolkit::ImageView imageView;
547 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
548 imageView = CreateImageView(pixelData);
553 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
555 mScreenshotCapturedCallback = callback;
556 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
559 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
561 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
564 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
568 mWebEngine.RegisterGeolocationPermissionCallback(callback);
572 void WebView::SetTtsFocus(bool focused)
574 if(mWebEngine && !HasKeyInputFocus())
576 mWebEngine.SetFocus(focused);
580 void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/)
587 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
588 Vector3 actorSize = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
589 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
590 Vector2 screenPosition = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
592 Dali::Rect<int32_t> displayArea;
593 displayArea.x = screenPosition.x - anchorPointOffSet.x;
594 displayArea.y = screenPosition.y - anchorPointOffSet.y;
595 displayArea.width = actorSize.x;
596 displayArea.height = actorSize.y;
598 Size displaySize = Size(displayArea.width, displayArea.height);
599 if(mWebViewSize != displaySize)
601 mWebViewSize = displaySize;
604 if(mWebViewArea != displayArea)
606 mWebViewArea = displayArea;
607 mWebEngine.UpdateDisplayArea(mWebViewArea);
611 void WebView::EnableVideoHole(bool enabled)
613 mVideoHoleEnabled = enabled;
615 EnableBlendMode(!mVideoHoleEnabled);
619 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
623 void WebView::EnableBlendMode(bool blendEnabled)
626 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
628 Dali::Renderer render = self.GetRendererAt(i);
629 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
633 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
637 return Dali::Toolkit::ImageView();
640 Dali::Toolkit::ImageUrl url = Dali::Toolkit::Image::GenerateUrl(pixel);
641 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url.GetUrl());
642 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
646 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
650 mWebEngine.RegisterPageLoadStartedCallback(callback);
654 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
658 mWebEngine.RegisterPageLoadInProgressCallback(callback);
662 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
666 mWebEngine.RegisterPageLoadFinishedCallback(callback);
670 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
674 mWebEngine.RegisterPageLoadErrorCallback(callback);
678 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
682 mWebEngine.RegisterScrollEdgeReachedCallback(callback);
686 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
690 mWebEngine.RegisterUrlChangedCallback(callback);
694 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
698 mWebEngine.RegisterFormRepostDecidedCallback(callback);
702 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
704 mFrameRenderedCallback = callback;
707 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
711 mWebEngine.RegisterConsoleMessageReceivedCallback(callback);
715 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
719 mWebEngine.RegisterResponsePolicyDecidedCallback(callback);
723 void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
727 mWebEngine.RegisterNavigationPolicyDecidedCallback(callback);
731 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
735 mWebEngine.RegisterCertificateConfirmedCallback(callback);
739 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
743 mWebEngine.RegisterSslCertificateChangedCallback(callback);
747 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
751 mWebEngine.RegisterHttpAuthHandlerCallback(callback);
755 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
759 mWebEngine.RegisterContextMenuShownCallback(callback);
763 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
767 mWebEngine.RegisterContextMenuHiddenCallback(callback);
771 void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
775 mWebEngine.GetPlainTextAsynchronously(callback);
779 void WebView::OnFrameRendered()
781 if(mFrameRenderedCallback)
783 mFrameRenderedCallback();
787 void WebView::OnInitialFrameRendered()
789 mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnInitialFrameRendered);
791 Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(mWebEngine.GetNativeImageSource());
792 mVisual = Toolkit::VisualFactory::Get().CreateVisual({{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, {Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()}});
796 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
797 EnableBlendMode(!mVideoHoleEnabled);
801 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
803 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
805 SetVisibility(isVisible);
809 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
811 if(mScreenshotCapturedCallback)
813 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
814 mScreenshotCapturedCallback(imageView);
818 void WebView::OnSceneConnection(int depth)
820 Control::OnSceneConnection(depth);
821 EnableBlendMode(!mVideoHoleEnabled);
824 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
830 result = mWebEngine.SendTouchEvent(touch);
835 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
841 result = mWebEngine.SendKeyEvent(event);
846 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
849 if(mWebEngine && mMouseEventsEnabled)
851 result = mWebEngine.SendHoverEvent(hover);
856 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
859 if(mWebEngine && mMouseEventsEnabled)
861 result = mWebEngine.SendWheelEvent(wheel);
866 void WebView::OnKeyInputFocusGained()
870 mWebEngine.SetFocus(true);
873 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
876 void WebView::OnKeyInputFocusLost()
880 mWebEngine.SetFocus(false);
883 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
886 Vector3 WebView::GetNaturalSize()
890 Vector2 rendererNaturalSize;
891 mVisual.GetNaturalSize(rendererNaturalSize);
892 return Vector3(rendererNaturalSize);
895 return Vector3(mWebViewSize);
898 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
900 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
904 WebView& impl = GetImpl(webView);
907 case Toolkit::WebView::Property::URL:
916 case Toolkit::WebView::Property::USER_AGENT:
921 impl.SetUserAgent(input);
925 case Toolkit::WebView::Property::SCROLL_POSITION:
930 impl.SetScrollPosition(input.x, input.y);
934 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
939 impl.EnableVideoHole(input);
943 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
948 impl.EnableMouseEvents(input);
952 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
957 impl.EnableKeyEvents(input);
961 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
966 impl.SetDocumentBackgroundColor(input);
970 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
975 impl.ClearTilesWhenHidden(input);
979 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
984 impl.SetTileCoverAreaMultiplier(input);
988 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
993 impl.EnableCursorByClient(input);
997 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1000 if(value.Get(input))
1002 impl.SetPageZoomFactor(input);
1006 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1009 if(value.Get(input))
1011 impl.SetTextZoomFactor(input);
1021 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1023 Property::Value value;
1025 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1029 WebView& impl = GetImpl(webView);
1030 switch(propertyIndex)
1032 case Toolkit::WebView::Property::URL:
1034 value = impl.GetUrl();
1037 case Toolkit::WebView::Property::USER_AGENT:
1039 value = impl.GetUserAgent();
1042 case Toolkit::WebView::Property::SCROLL_POSITION:
1044 value = impl.GetScrollPosition();
1047 case Toolkit::WebView::Property::SCROLL_SIZE:
1049 value = impl.GetScrollSize();
1052 case Toolkit::WebView::Property::CONTENT_SIZE:
1054 value = impl.GetContentSize();
1057 case Toolkit::WebView::Property::TITLE:
1059 value = impl.GetTitle();
1062 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1064 value = impl.mVideoHoleEnabled;
1067 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1069 value = impl.mMouseEventsEnabled;
1072 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1074 value = impl.mKeyEventsEnabled;
1077 case Toolkit::WebView::Property::SELECTED_TEXT:
1079 value = impl.GetSelectedText();
1082 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1084 value = impl.GetPageZoomFactor();
1087 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1089 value = impl.GetTextZoomFactor();
1092 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1094 value = impl.GetLoadProgressPercentage();
1105 void WebView::SetScrollPosition(int32_t x, int32_t y)
1109 mWebEngine.SetScrollPosition(x, y);
1113 Dali::Vector2 WebView::GetScrollPosition() const
1115 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1118 Dali::Vector2 WebView::GetScrollSize() const
1120 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1123 Dali::Vector2 WebView::GetContentSize() const
1125 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1128 std::string WebView::GetTitle() const
1130 return mWebEngine ? mWebEngine.GetTitle() : std::string();
1133 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1137 mWebEngine.SetDocumentBackgroundColor(color);
1141 void WebView::ClearTilesWhenHidden(bool cleared)
1145 mWebEngine.ClearTilesWhenHidden(cleared);
1149 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1153 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1157 void WebView::EnableCursorByClient(bool enabled)
1161 mWebEngine.EnableCursorByClient(enabled);
1165 std::string WebView::GetSelectedText() const
1167 return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1170 std::string WebView::GetUrl() const
1172 return mWebEngine ? mWebEngine.GetUrl() : std::string();
1175 std::string WebView::GetUserAgent() const
1177 return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1180 void WebView::SetUserAgent(const std::string& userAgent)
1184 mWebEngine.SetUserAgent(userAgent);
1188 void WebView::EnableMouseEvents(bool enabled)
1192 mMouseEventsEnabled = enabled;
1193 mWebEngine.EnableMouseEvents(enabled);
1197 void WebView::EnableKeyEvents(bool enabled)
1201 mKeyEventsEnabled = enabled;
1202 mWebEngine.EnableKeyEvents(enabled);
1206 void WebView::SetPageZoomFactor(float zoomFactor)
1210 mWebEngine.SetPageZoomFactor(zoomFactor);
1214 float WebView::GetPageZoomFactor() const
1216 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1219 void WebView::SetTextZoomFactor(float zoomFactor)
1223 mWebEngine.SetTextZoomFactor(zoomFactor);
1227 float WebView::GetTextZoomFactor() const
1229 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1232 float WebView::GetLoadProgressPercentage() const
1234 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1237 bool WebView::SetVisibility(bool visible)
1239 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1242 WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine)
1243 : ControlAccessible(self), mRemoteChild{}, mWebEngine{webEngine}
1245 mRemoteChild.SetParent(this);
1247 Dali::Accessibility::Bridge::EnabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityEnabled);
1248 Dali::Accessibility::Bridge::DisabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityDisabled);
1250 if(Dali::Accessibility::IsUp())
1252 OnAccessibilityEnabled();
1256 OnAccessibilityDisabled();
1260 void WebView::WebViewAccessible::DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children)
1262 if(mRemoteChild.GetAddress())
1264 children.push_back(&mRemoteChild);
1268 void WebView::WebViewAccessible::OnAccessibilityEnabled()
1275 mWebEngine.ActivateAccessibility(true);
1276 SetRemoteChildAddress(mWebEngine.GetAccessibilityAddress());
1279 void WebView::WebViewAccessible::OnAccessibilityDisabled()
1286 SetRemoteChildAddress({});
1287 mWebEngine.ActivateAccessibility(false);
1290 void WebView::WebViewAccessible::SetRemoteChildAddress(Dali::Accessibility::Address address)
1292 mRemoteChild.SetAddress(address);
1293 OnChildrenChanged();
1297 Accessibility::Bridge::GetCurrentBridge()->EmbedAtkSocket(GetAddress(), address);
1301 #undef GET_ENUM_STRING
1302 #undef GET_ENUM_VALUE
1304 } // namespace Internal
1306 } // namespace Toolkit