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>
65 return Toolkit::WebView::New();
69 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
71 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url", STRING, URL )
72 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent", STRING, USER_AGENT )
73 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION )
74 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE )
75 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE )
76 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title", STRING, TITLE )
77 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled", BOOLEAN, VIDEO_HOLE_ENABLED )
78 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled", BOOLEAN, MOUSE_EVENTS_ENABLED )
79 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled", BOOLEAN, KEY_EVENTS_ENABLED )
80 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR )
81 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden", BOOLEAN, TILES_CLEARED_WHEN_HIDDEN )
82 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT, TILE_COVER_AREA_MULTIPLIER)
83 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient", BOOLEAN, CURSOR_ENABLED_BY_CLIENT )
84 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText", STRING, SELECTED_TEXT )
85 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor", FLOAT, PAGE_ZOOM_FACTOR )
86 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor", FLOAT, TEXT_ZOOM_FACTOR )
87 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage", FLOAT, LOAD_PROGRESS_PERCENTAGE )
89 DALI_TYPE_REGISTRATION_END()
94 std::unordered_map<Dali::WebEnginePlugin*, Dali::WeakHandle<Toolkit::WebView>> WebView::mPluginWebViewMap;
96 WebView::WebView(const std::string& locale, const std::string& timezoneId)
97 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
99 mWebViewSize(Stage::GetCurrent().GetSize()),
101 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
102 mVideoHoleEnabled(false),
103 mMouseEventsEnabled(true),
104 mKeyEventsEnabled(true),
105 mScreenshotCapturedCallback{nullptr},
106 mFrameRenderedCallback{nullptr}
108 mWebEngine = Dali::WebEngine::New();
110 // WebEngine is empty when it is not properly initialized.
113 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
117 WebView::WebView(uint32_t argc, char** argv)
118 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
120 mWebViewSize(Stage::GetCurrent().GetSize()),
122 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
123 mVideoHoleEnabled(false),
124 mMouseEventsEnabled(true),
125 mKeyEventsEnabled(true),
126 mScreenshotCapturedCallback{nullptr},
127 mFrameRenderedCallback{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 auto iter = mPluginWebViewMap.find(mWebEngine.GetPlugin());
148 if (iter != mPluginWebViewMap.end())
150 mPluginWebViewMap.erase(iter);
152 mWebEngine.Destroy();
156 Toolkit::WebView WebView::New()
158 WebView* impl = new WebView();
159 Toolkit::WebView handle = Toolkit::WebView(*impl);
160 if (impl->GetPlugin())
162 mPluginWebViewMap[impl->GetPlugin()] = handle;
168 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
170 WebView* impl = new WebView(locale, timezoneId);
171 Toolkit::WebView handle = Toolkit::WebView(*impl);
172 if (impl->GetPlugin())
174 mPluginWebViewMap[impl->GetPlugin()] = handle;
180 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
182 WebView* impl = new WebView(argc, argv);
183 Toolkit::WebView handle = Toolkit::WebView(*impl);
184 if (impl->GetPlugin())
186 mPluginWebViewMap[impl->GetPlugin()] = handle;
192 Toolkit::WebView WebView::FindWebView(Dali::WebEnginePlugin* plugin)
194 auto iter = mPluginWebViewMap.find(plugin);
195 if (iter != mPluginWebViewMap.end())
197 return iter->second.GetHandle();
199 return Toolkit::WebView();
202 Dali::WebEngineContext* WebView::GetContext()
204 return Dali::WebEngine::GetContext();
207 Dali::WebEngineCookieManager* WebView::GetCookieManager()
209 return Dali::WebEngine::GetCookieManager();
212 void WebView::OnInitialize()
216 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
217 self.SetProperty(DevelActor::Property::TOUCH_FOCUSABLE, true);
218 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
219 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
220 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
221 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
223 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
224 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
225 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
226 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
227 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
228 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::OnDisplayAreaUpdated);
232 mWebEngine.RegisterFrameRenderedCallback(std::bind(&WebView::OnFrameRendered, this));
233 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
234 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
237 self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::FILLER);
240 DevelControl::ControlAccessible* WebView::CreateAccessibleObject()
242 return new WebViewAccessible(Self(), mWebEngine);
245 Dali::Toolkit::WebSettings* WebView::GetSettings() const
247 return mWebSettings.get();
250 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
252 return mWebBackForwardList.get();
255 Dali::WebEnginePlugin* WebView::GetPlugin() const
257 return mWebEngine ? mWebEngine.GetPlugin() : nullptr;
260 Dali::Toolkit::ImageView WebView::GetFavicon() const
262 Dali::Toolkit::ImageView faviconView;
265 Dali::PixelData pixelData = mWebEngine.GetFavicon();
266 faviconView = CreateImageView(pixelData);
271 void WebView::LoadUrl(const std::string& url)
275 mWebEngine.LoadUrl(url);
279 void WebView::LoadHtmlString(const std::string& htmlString)
283 mWebEngine.LoadHtmlString(htmlString);
287 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
292 return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
295 bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
300 return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
303 void WebView::Reload()
311 bool WebView::ReloadWithoutCache()
313 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
316 void WebView::StopLoading()
320 mWebEngine.StopLoading();
324 void WebView::Suspend()
328 mWebEngine.Suspend();
332 void WebView::Resume()
340 void WebView::SuspendNetworkLoading()
344 mWebEngine.SuspendNetworkLoading();
348 void WebView::ResumeNetworkLoading()
352 mWebEngine.ResumeNetworkLoading();
356 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
358 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
361 bool WebView::RemoveCustomHeader(const std::string& name)
363 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
366 uint32_t WebView::StartInspectorServer(uint32_t port)
368 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
371 bool WebView::StopInspectorServer()
373 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
376 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
380 mWebEngine.ScrollBy(deltaX, deltaY);
384 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
386 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
389 bool WebView::CanGoForward()
391 return mWebEngine ? mWebEngine.CanGoForward() : false;
394 void WebView::GoForward()
398 mWebEngine.GoForward();
402 bool WebView::CanGoBack()
404 return mWebEngine ? mWebEngine.CanGoBack() : false;
407 void WebView::GoBack()
415 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
419 mWebEngine.EvaluateJavaScript(script, resultHandler);
423 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
427 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
431 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
435 mWebEngine.RegisterJavaScriptAlertCallback(callback);
439 void WebView::JavaScriptAlertReply()
443 mWebEngine.JavaScriptAlertReply();
447 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
451 mWebEngine.RegisterJavaScriptConfirmCallback(callback);
455 void WebView::JavaScriptConfirmReply(bool confirmed)
459 mWebEngine.JavaScriptConfirmReply(confirmed);
463 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
467 mWebEngine.RegisterJavaScriptPromptCallback(callback);
471 void WebView::JavaScriptPromptReply(const std::string& result)
475 mWebEngine.JavaScriptPromptReply(result);
479 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
481 std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
487 return mWebEngine.CreateHitTest(x, y, mode);
490 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
495 result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, callback);
500 void WebView::ClearHistory()
504 mWebEngine.ClearHistory();
508 void WebView::ClearAllTilesResources()
512 mWebEngine.ClearAllTilesResources();
516 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
520 mWebEngine.SetScaleFactor(scaleFactor, point);
524 float WebView::GetScaleFactor() const
526 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
529 void WebView::ActivateAccessibility(bool activated)
533 mWebEngine.ActivateAccessibility(activated);
537 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
539 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
542 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
546 mWebEngine.AddDynamicCertificatePath(host, certPath);
550 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
552 Dali::Toolkit::ImageView imageView;
555 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
556 imageView = CreateImageView(pixelData);
561 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
563 mScreenshotCapturedCallback = callback;
564 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
567 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
569 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
572 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
576 mWebEngine.RegisterGeolocationPermissionCallback(callback);
580 void WebView::SetTtsFocus(bool focused)
582 if(mWebEngine && !HasKeyInputFocus())
584 mWebEngine.SetFocus(focused);
588 void WebView::EnableVideoHole(bool enabled)
590 mVideoHoleEnabled = enabled;
592 EnableBlendMode(!mVideoHoleEnabled);
596 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
600 void WebView::EnableBlendMode(bool blendEnabled)
603 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
605 Dali::Renderer render = self.GetRendererAt(i);
606 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
610 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
614 return Dali::Toolkit::ImageView();
617 Dali::Toolkit::ImageUrl url = Dali::Toolkit::Image::GenerateUrl(pixel);
618 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url.GetUrl());
619 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
623 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
627 mWebEngine.RegisterPageLoadStartedCallback(callback);
631 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
635 mWebEngine.RegisterPageLoadInProgressCallback(callback);
639 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
643 mWebEngine.RegisterPageLoadFinishedCallback(callback);
647 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
651 mWebEngine.RegisterPageLoadErrorCallback(callback);
655 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
659 mWebEngine.RegisterScrollEdgeReachedCallback(callback);
663 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
667 mWebEngine.RegisterUrlChangedCallback(callback);
671 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
675 mWebEngine.RegisterFormRepostDecidedCallback(callback);
679 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
681 mFrameRenderedCallback = callback;
684 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
688 mWebEngine.RegisterConsoleMessageReceivedCallback(callback);
692 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
696 mWebEngine.RegisterResponsePolicyDecidedCallback(callback);
700 void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
704 mWebEngine.RegisterNavigationPolicyDecidedCallback(callback);
708 void WebView::RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback)
712 mWebEngine.RegisterNewWindowCreatedCallback(callback);
716 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
720 mWebEngine.RegisterCertificateConfirmedCallback(callback);
724 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
728 mWebEngine.RegisterSslCertificateChangedCallback(callback);
732 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
736 mWebEngine.RegisterHttpAuthHandlerCallback(callback);
740 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
744 mWebEngine.RegisterContextMenuShownCallback(callback);
748 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
752 mWebEngine.RegisterContextMenuHiddenCallback(callback);
756 void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
760 mWebEngine.GetPlainTextAsynchronously(callback);
764 void WebView::OnFrameRendered()
766 if(mFrameRenderedCallback)
768 mFrameRenderedCallback();
771 // Make sure that mVisual is created only once.
775 Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(mWebEngine.GetNativeImageSource());
776 mVisual = Toolkit::VisualFactory::Get().CreateVisual({{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, {Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()}});
779 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
780 EnableBlendMode(!mVideoHoleEnabled);
784 void WebView::OnDisplayAreaUpdated(Dali::PropertyNotification& /*source*/)
791 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
792 Vector3 actorSize = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
793 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
794 Vector2 screenPosition = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
796 Dali::Rect<int32_t> displayArea;
797 displayArea.x = screenPosition.x - anchorPointOffSet.x;
798 displayArea.y = screenPosition.y - anchorPointOffSet.y;
799 displayArea.width = actorSize.x;
800 displayArea.height = actorSize.y;
802 Size displaySize = Size(displayArea.width, displayArea.height);
803 if(mWebViewSize != displaySize)
805 mWebViewSize = displaySize;
808 if(mWebViewArea != displayArea)
810 mWebViewArea = displayArea;
811 mWebEngine.UpdateDisplayArea(mWebViewArea);
815 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
817 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
819 SetVisibility(isVisible);
823 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
825 if(mScreenshotCapturedCallback)
827 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
828 mScreenshotCapturedCallback(imageView);
832 void WebView::OnSceneConnection(int depth)
834 Control::OnSceneConnection(depth);
835 EnableBlendMode(!mVideoHoleEnabled);
838 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
844 result = mWebEngine.SendTouchEvent(touch);
849 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
855 result = mWebEngine.SendKeyEvent(event);
860 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
863 if(mWebEngine && mMouseEventsEnabled)
865 result = mWebEngine.SendHoverEvent(hover);
870 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
873 if(mWebEngine && mMouseEventsEnabled)
875 result = mWebEngine.SendWheelEvent(wheel);
880 void WebView::OnKeyInputFocusGained()
884 mWebEngine.SetFocus(true);
887 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
890 void WebView::OnKeyInputFocusLost()
894 mWebEngine.SetFocus(false);
897 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
900 Vector3 WebView::GetNaturalSize()
904 Vector2 rendererNaturalSize;
905 mVisual.GetNaturalSize(rendererNaturalSize);
906 return Vector3(rendererNaturalSize);
909 return Vector3(mWebViewSize);
912 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
914 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
918 WebView& impl = GetImpl(webView);
921 case Toolkit::WebView::Property::URL:
930 case Toolkit::WebView::Property::USER_AGENT:
935 impl.SetUserAgent(input);
939 case Toolkit::WebView::Property::SCROLL_POSITION:
944 impl.SetScrollPosition(input.x, input.y);
948 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
953 impl.EnableVideoHole(input);
957 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
962 impl.EnableMouseEvents(input);
966 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
971 impl.EnableKeyEvents(input);
975 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
980 impl.SetDocumentBackgroundColor(input);
984 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
989 impl.ClearTilesWhenHidden(input);
993 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
998 impl.SetTileCoverAreaMultiplier(input);
1002 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
1005 if(value.Get(input))
1007 impl.EnableCursorByClient(input);
1011 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1014 if(value.Get(input))
1016 impl.SetPageZoomFactor(input);
1020 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1023 if(value.Get(input))
1025 impl.SetTextZoomFactor(input);
1035 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1037 Property::Value value;
1039 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1043 WebView& impl = GetImpl(webView);
1044 switch(propertyIndex)
1046 case Toolkit::WebView::Property::URL:
1048 value = impl.GetUrl();
1051 case Toolkit::WebView::Property::USER_AGENT:
1053 value = impl.GetUserAgent();
1056 case Toolkit::WebView::Property::SCROLL_POSITION:
1058 value = impl.GetScrollPosition();
1061 case Toolkit::WebView::Property::SCROLL_SIZE:
1063 value = impl.GetScrollSize();
1066 case Toolkit::WebView::Property::CONTENT_SIZE:
1068 value = impl.GetContentSize();
1071 case Toolkit::WebView::Property::TITLE:
1073 value = impl.GetTitle();
1076 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1078 value = impl.mVideoHoleEnabled;
1081 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1083 value = impl.mMouseEventsEnabled;
1086 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1088 value = impl.mKeyEventsEnabled;
1091 case Toolkit::WebView::Property::SELECTED_TEXT:
1093 value = impl.GetSelectedText();
1096 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1098 value = impl.GetPageZoomFactor();
1101 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1103 value = impl.GetTextZoomFactor();
1106 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1108 value = impl.GetLoadProgressPercentage();
1119 void WebView::SetScrollPosition(int32_t x, int32_t y)
1123 mWebEngine.SetScrollPosition(x, y);
1127 Dali::Vector2 WebView::GetScrollPosition() const
1129 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1132 Dali::Vector2 WebView::GetScrollSize() const
1134 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1137 Dali::Vector2 WebView::GetContentSize() const
1139 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1142 std::string WebView::GetTitle() const
1144 return mWebEngine ? mWebEngine.GetTitle() : std::string();
1147 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1151 mWebEngine.SetDocumentBackgroundColor(color);
1155 void WebView::ClearTilesWhenHidden(bool cleared)
1159 mWebEngine.ClearTilesWhenHidden(cleared);
1163 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1167 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1171 void WebView::EnableCursorByClient(bool enabled)
1175 mWebEngine.EnableCursorByClient(enabled);
1179 std::string WebView::GetSelectedText() const
1181 return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1184 std::string WebView::GetUrl() const
1186 return mWebEngine ? mWebEngine.GetUrl() : std::string();
1189 std::string WebView::GetUserAgent() const
1191 return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1194 void WebView::SetUserAgent(const std::string& userAgent)
1198 mWebEngine.SetUserAgent(userAgent);
1202 void WebView::EnableMouseEvents(bool enabled)
1206 mMouseEventsEnabled = enabled;
1207 mWebEngine.EnableMouseEvents(enabled);
1211 void WebView::EnableKeyEvents(bool enabled)
1215 mKeyEventsEnabled = enabled;
1216 mWebEngine.EnableKeyEvents(enabled);
1220 void WebView::SetPageZoomFactor(float zoomFactor)
1224 mWebEngine.SetPageZoomFactor(zoomFactor);
1228 float WebView::GetPageZoomFactor() const
1230 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1233 void WebView::SetTextZoomFactor(float zoomFactor)
1237 mWebEngine.SetTextZoomFactor(zoomFactor);
1241 float WebView::GetTextZoomFactor() const
1243 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1246 float WebView::GetLoadProgressPercentage() const
1248 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1251 bool WebView::SetVisibility(bool visible)
1253 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1256 WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine)
1257 : ControlAccessible(self), mRemoteChild{}, mWebEngine{webEngine}
1259 mRemoteChild.SetParent(this);
1261 Dali::Accessibility::Bridge::EnabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityEnabled);
1262 Dali::Accessibility::Bridge::DisabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityDisabled);
1264 if(Dali::Accessibility::IsUp())
1266 OnAccessibilityEnabled();
1270 OnAccessibilityDisabled();
1274 Dali::Accessibility::Attributes WebView::WebViewAccessible::GetAttributes() const
1276 auto attributes = DevelControl::ControlAccessible::GetAttributes();
1278 if(mRemoteChild.GetAddress())
1280 attributes.insert_or_assign("child_bus", mRemoteChild.GetAddress().GetBus());
1286 void WebView::WebViewAccessible::DoGetChildren(std::vector<Dali::Accessibility::Accessible*>& children)
1288 if(mRemoteChild.GetAddress())
1290 // DoGetChildren is called at most once per every OnChildrenChanged.
1291 // We have only one OnChildrenChanged in this case, so EmbedAtkSocket will be called only once.
1292 Accessibility::Bridge::GetCurrentBridge()->EmbedAtkSocket(GetAddress(), mRemoteChild.GetAddress());
1293 children.push_back(&mRemoteChild);
1297 void WebView::WebViewAccessible::OnAccessibilityEnabled()
1304 mWebEngine.ActivateAccessibility(true);
1305 SetRemoteChildAddress(mWebEngine.GetAccessibilityAddress());
1308 void WebView::WebViewAccessible::OnAccessibilityDisabled()
1315 SetRemoteChildAddress({});
1316 mWebEngine.ActivateAccessibility(false);
1319 void WebView::WebViewAccessible::SetRemoteChildAddress(Dali::Accessibility::Address address)
1321 mRemoteChild.SetAddress(address);
1322 OnChildrenChanged();
1325 } // namespace Internal
1327 } // namespace Toolkit