2 * Copyright (c) 2021 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-back-forward-list.h>
23 #include <dali/devel-api/adaptor-framework/web-engine-certificate.h>
24 #include <dali/devel-api/adaptor-framework/web-engine-console-message.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-context-menu-item.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-context-menu.h>
27 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
28 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
29 #include <dali/devel-api/adaptor-framework/web-engine-form-repost-decision.h>
30 #include <dali/devel-api/adaptor-framework/web-engine-hit-test.h>
31 #include <dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h>
32 #include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
33 #include <dali/devel-api/adaptor-framework/web-engine-policy-decision.h>
34 #include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
35 #include <dali/devel-api/adaptor-framework/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>
46 #include <dali-toolkit/devel-api/controls/control-devel.h>
47 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
48 #include <dali-toolkit/devel-api/controls/web-view/web-context.h>
49 #include <dali-toolkit/devel-api/controls/web-view/web-cookie-manager.h>
50 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
51 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
52 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
53 #include <dali-toolkit/public-api/image-loader/image.h>
54 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
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()
95 #define GET_ENUM_STRING(structName, inputExp) \
96 Scripting::GetLinearEnumerationName<Toolkit::WebView::structName::Type>(static_cast<Toolkit::WebView::structName::Type>(inputExp), structName##_TABLE, structName##_TABLE_COUNT)
98 #define GET_ENUM_VALUE(structName, inputExp, outputExp) \
99 Scripting::GetEnumerationProperty<Toolkit::WebView::structName::Type>(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp)
101 WebView::WebView(const std::string& locale, const std::string& timezoneId)
102 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
104 mWebViewSize(Stage::GetCurrent().GetSize()),
106 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
107 mVideoHoleEnabled(false),
108 mMouseEventsEnabled(true),
109 mKeyEventsEnabled(true),
110 mScreenshotCapturedCallback(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)
132 mWebEngine = Dali::WebEngine::New();
134 // WebEngine is empty when it is not properly initialized.
137 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
150 mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnFrameRendered);
151 mWebEngine.Destroy();
155 Toolkit::WebView WebView::New()
157 WebView* impl = new WebView();
158 Toolkit::WebView handle = Toolkit::WebView(*impl);
164 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
166 WebView* impl = new WebView(locale, timezoneId);
167 Toolkit::WebView handle = Toolkit::WebView(*impl);
173 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
175 WebView* impl = new WebView(argc, argv);
176 Toolkit::WebView handle = Toolkit::WebView(*impl);
182 void WebView::OnInitialize()
186 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
187 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
188 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
189 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
190 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
192 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
193 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
194 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
195 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
196 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
197 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
201 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered);
202 mWebContext = std::unique_ptr<Dali::Toolkit::WebContext>(new WebContext(mWebEngine.GetContext()));
203 mWebCookieManager = std::unique_ptr<Dali::Toolkit::WebCookieManager>(new WebCookieManager(mWebEngine.GetCookieManager()));
204 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
205 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
209 Dali::Toolkit::WebSettings* WebView::GetSettings() const
211 return mWebSettings.get();
214 Dali::Toolkit::WebContext* WebView::GetContext() const
216 return mWebContext.get();
219 Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const
221 return mWebCookieManager.get();
224 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
226 return mWebBackForwardList.get();
229 Dali::Toolkit::ImageView WebView::GetFavicon() const
231 Dali::Toolkit::ImageView faviconView;
234 Dali::PixelData pixelData = mWebEngine.GetFavicon();
235 faviconView = CreateImageView(pixelData);
240 void WebView::LoadUrl(const std::string& url)
246 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
249 mWebEngine.LoadUrl(url);
253 void WebView::LoadHtmlString(const std::string& htmlString)
259 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
262 mWebEngine.LoadHtmlString(htmlString);
266 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
273 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
276 return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
279 bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
286 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
289 return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
292 void WebView::Reload()
300 bool WebView::ReloadWithoutCache()
302 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
305 void WebView::StopLoading()
309 mWebEngine.StopLoading();
313 void WebView::Suspend()
317 mWebEngine.Suspend();
321 void WebView::Resume()
329 void WebView::SuspendNetworkLoading()
333 mWebEngine.SuspendNetworkLoading();
337 void WebView::ResumeNetworkLoading()
341 mWebEngine.ResumeNetworkLoading();
345 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
347 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
350 bool WebView::RemoveCustomHeader(const std::string& name)
352 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
355 uint32_t WebView::StartInspectorServer(uint32_t port)
357 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
360 bool WebView::StopInspectorServer()
362 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
365 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
369 mWebEngine.ScrollBy(deltaX, deltaY);
373 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
375 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
378 bool WebView::CanGoForward()
380 return mWebEngine ? mWebEngine.CanGoForward() : false;
383 void WebView::GoForward()
387 mWebEngine.GoForward();
391 bool WebView::CanGoBack()
393 return mWebEngine ? mWebEngine.CanGoBack() : false;
396 void WebView::GoBack()
404 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
408 mWebEngine.EvaluateJavaScript(script, resultHandler);
412 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
416 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
420 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
424 mWebEngine.RegisterJavaScriptAlertCallback(callback);
428 void WebView::JavaScriptAlertReply()
432 mWebEngine.JavaScriptAlertReply();
436 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
440 mWebEngine.RegisterJavaScriptConfirmCallback(callback);
444 void WebView::JavaScriptConfirmReply(bool confirmed)
448 mWebEngine.JavaScriptConfirmReply(confirmed);
452 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
456 mWebEngine.RegisterJavaScriptPromptCallback(callback);
460 void WebView::JavaScriptPromptReply(const std::string& result)
464 mWebEngine.JavaScriptPromptReply(result);
468 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
470 std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
476 return mWebEngine.CreateHitTest(x, y, mode);
479 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
484 result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, callback);
489 void WebView::ClearHistory()
493 mWebEngine.ClearHistory();
497 void WebView::ClearAllTilesResources()
501 mWebEngine.ClearAllTilesResources();
505 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
509 mWebEngine.SetScaleFactor(scaleFactor, point);
513 float WebView::GetScaleFactor() const
515 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
518 void WebView::ActivateAccessibility(bool activated)
522 mWebEngine.ActivateAccessibility(activated);
526 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
528 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
531 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
535 mWebEngine.AddDynamicCertificatePath(host, certPath);
539 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
541 Dali::Toolkit::ImageView imageView;
544 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
545 imageView = CreateImageView(pixelData);
550 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
552 mScreenshotCapturedCallback = callback;
553 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
556 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
558 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
561 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
565 mWebEngine.RegisterGeolocationPermissionCallback(callback);
569 void WebView::SetTtsFocus(bool focused)
571 if(mWebEngine && !HasKeyInputFocus())
573 mWebEngine.SetFocus(focused);
577 void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/)
584 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
585 Vector3 actorSize = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
586 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
587 Vector2 screenPosition = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
589 Dali::Rect<int32_t> displayArea;
590 displayArea.x = screenPosition.x - anchorPointOffSet.x;
591 displayArea.y = screenPosition.y - anchorPointOffSet.y;
592 displayArea.width = actorSize.x;
593 displayArea.height = actorSize.y;
595 Size displaySize = Size(displayArea.width, displayArea.height);
596 if(mWebViewSize != displaySize)
598 mWebViewSize = displaySize;
601 if(mWebViewArea != displayArea)
603 mWebViewArea = displayArea;
604 mWebEngine.UpdateDisplayArea(mWebViewArea);
608 void WebView::EnableVideoHole(bool enabled)
610 mVideoHoleEnabled = enabled;
612 EnableBlendMode(!mVideoHoleEnabled);
616 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
620 void WebView::EnableBlendMode(bool blendEnabled)
623 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
625 Dali::Renderer render = self.GetRendererAt(i);
626 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
630 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
634 return Dali::Toolkit::ImageView();
637 std::string url = Dali::Toolkit::Image::GenerateUrl(pixel);
638 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url);
639 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
643 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
647 mWebEngine.RegisterPageLoadStartedCallback(callback);
651 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
655 mWebEngine.RegisterPageLoadInProgressCallback(callback);
659 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
663 mWebEngine.RegisterPageLoadFinishedCallback(callback);
667 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
671 mWebEngine.RegisterPageLoadErrorCallback(callback);
675 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
679 mWebEngine.RegisterScrollEdgeReachedCallback(callback);
683 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
687 mWebEngine.RegisterUrlChangedCallback(callback);
691 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
695 mWebEngine.RegisterFormRepostDecidedCallback(callback);
699 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
701 mFrameRenderedCallback = callback;
704 void WebView::RegisterRequestInterceptorCallback(Dali::WebEnginePlugin::WebEngineRequestInterceptorCallback callback)
708 mWebEngine.RegisterRequestInterceptorCallback(callback);
712 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
716 mWebEngine.RegisterConsoleMessageReceivedCallback(callback);
720 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
724 mWebEngine.RegisterResponsePolicyDecidedCallback(callback);
728 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
732 mWebEngine.RegisterCertificateConfirmedCallback(callback);
736 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
740 mWebEngine.RegisterSslCertificateChangedCallback(callback);
744 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
748 mWebEngine.RegisterHttpAuthHandlerCallback(callback);
752 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
756 mWebEngine.RegisterContextMenuShownCallback(callback);
760 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
764 mWebEngine.RegisterContextMenuHiddenCallback(callback);
768 void WebView::OnFrameRendered()
770 if(mFrameRenderedCallback)
772 mFrameRenderedCallback();
776 void WebView::OnInitialFrameRendered()
778 mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnInitialFrameRendered);
780 Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
781 const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
782 mVisual = Toolkit::VisualFactory::Get().CreateVisual({{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
786 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
787 EnableBlendMode(!mVideoHoleEnabled);
791 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
793 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
795 SetVisibility(isVisible);
799 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
801 if(mScreenshotCapturedCallback)
803 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
804 mScreenshotCapturedCallback(imageView);
808 void WebView::OnSceneConnection(int depth)
810 Control::OnSceneConnection(depth);
811 EnableBlendMode(!mVideoHoleEnabled);
814 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
820 result = mWebEngine.SendTouchEvent(touch);
825 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
831 result = mWebEngine.SendKeyEvent(event);
836 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
839 if(mWebEngine && mMouseEventsEnabled)
841 result = mWebEngine.SendHoverEvent(hover);
846 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
849 if(mWebEngine && mMouseEventsEnabled)
851 result = mWebEngine.SendWheelEvent(wheel);
856 void WebView::OnKeyInputFocusGained()
860 mWebEngine.SetFocus(true);
863 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
866 void WebView::OnKeyInputFocusLost()
870 mWebEngine.SetFocus(false);
873 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
876 Vector3 WebView::GetNaturalSize()
880 Vector2 rendererNaturalSize;
881 mVisual.GetNaturalSize(rendererNaturalSize);
882 return Vector3(rendererNaturalSize);
885 return Vector3(mWebViewSize);
888 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
890 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
894 WebView& impl = GetImpl(webView);
897 case Toolkit::WebView::Property::URL:
906 case Toolkit::WebView::Property::USER_AGENT:
911 impl.SetUserAgent(input);
915 case Toolkit::WebView::Property::SCROLL_POSITION:
920 impl.SetScrollPosition(input.x, input.y);
924 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
929 impl.EnableVideoHole(input);
933 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
938 impl.EnableMouseEvents(input);
942 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
947 impl.EnableKeyEvents(input);
951 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
956 impl.SetDocumentBackgroundColor(input);
960 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
965 impl.ClearTilesWhenHidden(input);
969 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
974 impl.SetTileCoverAreaMultiplier(input);
978 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
983 impl.EnableCursorByClient(input);
987 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
992 impl.SetPageZoomFactor(input);
996 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1001 impl.SetTextZoomFactor(input);
1011 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1013 Property::Value value;
1015 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1019 WebView& impl = GetImpl(webView);
1020 switch(propertyIndex)
1022 case Toolkit::WebView::Property::URL:
1024 value = impl.GetUrl();
1027 case Toolkit::WebView::Property::USER_AGENT:
1029 value = impl.GetUserAgent();
1032 case Toolkit::WebView::Property::SCROLL_POSITION:
1034 value = impl.GetScrollPosition();
1037 case Toolkit::WebView::Property::SCROLL_SIZE:
1039 value = impl.GetScrollSize();
1042 case Toolkit::WebView::Property::CONTENT_SIZE:
1044 value = impl.GetContentSize();
1047 case Toolkit::WebView::Property::TITLE:
1049 value = impl.GetTitle();
1052 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1054 value = impl.mVideoHoleEnabled;
1057 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1059 value = impl.mMouseEventsEnabled;
1062 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1064 value = impl.mKeyEventsEnabled;
1067 case Toolkit::WebView::Property::SELECTED_TEXT:
1069 value = impl.GetSelectedText();
1072 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1074 value = impl.GetPageZoomFactor();
1077 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1079 value = impl.GetTextZoomFactor();
1082 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1084 value = impl.GetLoadProgressPercentage();
1095 void WebView::SetScrollPosition(int32_t x, int32_t y)
1099 mWebEngine.SetScrollPosition(x, y);
1103 Dali::Vector2 WebView::GetScrollPosition() const
1105 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1108 Dali::Vector2 WebView::GetScrollSize() const
1110 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1113 Dali::Vector2 WebView::GetContentSize() const
1115 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1118 std::string WebView::GetTitle() const
1120 return mWebEngine ? mWebEngine.GetTitle() : std::string();
1123 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1127 mWebEngine.SetDocumentBackgroundColor(color);
1131 void WebView::ClearTilesWhenHidden(bool cleared)
1135 mWebEngine.ClearTilesWhenHidden(cleared);
1139 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1143 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1147 void WebView::EnableCursorByClient(bool enabled)
1151 mWebEngine.EnableCursorByClient(enabled);
1155 std::string WebView::GetSelectedText() const
1157 return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1160 std::string WebView::GetUrl() const
1162 return mWebEngine ? mWebEngine.GetUrl() : std::string();
1165 std::string WebView::GetUserAgent() const
1167 return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1170 void WebView::SetUserAgent(const std::string& userAgent)
1174 mWebEngine.SetUserAgent(userAgent);
1178 void WebView::EnableMouseEvents(bool enabled)
1182 mMouseEventsEnabled = enabled;
1183 mWebEngine.EnableMouseEvents(enabled);
1187 void WebView::EnableKeyEvents(bool enabled)
1191 mKeyEventsEnabled = enabled;
1192 mWebEngine.EnableKeyEvents(enabled);
1196 void WebView::SetPageZoomFactor(float zoomFactor)
1200 mWebEngine.SetPageZoomFactor(zoomFactor);
1204 float WebView::GetPageZoomFactor() const
1206 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1209 void WebView::SetTextZoomFactor(float zoomFactor)
1213 mWebEngine.SetTextZoomFactor(zoomFactor);
1217 float WebView::GetTextZoomFactor() const
1219 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1222 float WebView::GetLoadProgressPercentage() const
1224 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1227 bool WebView::SetVisibility(bool visible)
1229 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1232 #undef GET_ENUM_STRING
1233 #undef GET_ENUM_VALUE
1235 } // namespace Internal
1237 } // namespace Toolkit