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>
55 #include <dali-toolkit/public-api/image-loader/image-url.h>
67 return Toolkit::WebView::New();
71 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
73 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url", STRING, URL )
74 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent", STRING, USER_AGENT )
75 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION )
76 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE )
77 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE )
78 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title", STRING, TITLE )
79 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled", BOOLEAN, VIDEO_HOLE_ENABLED )
80 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled", BOOLEAN, MOUSE_EVENTS_ENABLED )
81 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled", BOOLEAN, KEY_EVENTS_ENABLED )
82 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR )
83 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden", BOOLEAN, TILES_CLEARED_WHEN_HIDDEN )
84 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT, TILE_COVER_AREA_MULTIPLIER)
85 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient", BOOLEAN, CURSOR_ENABLED_BY_CLIENT )
86 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText", STRING, SELECTED_TEXT )
87 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor", FLOAT, PAGE_ZOOM_FACTOR )
88 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor", FLOAT, TEXT_ZOOM_FACTOR )
89 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage", FLOAT, LOAD_PROGRESS_PERCENTAGE )
91 DALI_TYPE_REGISTRATION_END()
96 #define GET_ENUM_STRING(structName, inputExp) \
97 Scripting::GetLinearEnumerationName<Toolkit::WebView::structName::Type>(static_cast<Toolkit::WebView::structName::Type>(inputExp), structName##_TABLE, structName##_TABLE_COUNT)
99 #define GET_ENUM_VALUE(structName, inputExp, outputExp) \
100 Scripting::GetEnumerationProperty<Toolkit::WebView::structName::Type>(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp)
102 WebView::WebView(const std::string& locale, const std::string& timezoneId)
103 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
105 mWebViewSize(Stage::GetCurrent().GetSize()),
107 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
108 mVideoHoleEnabled(false),
109 mMouseEventsEnabled(true),
110 mKeyEventsEnabled(true),
111 mScreenshotCapturedCallback(nullptr)
113 mWebEngine = Dali::WebEngine::New();
115 // WebEngine is empty when it is not properly initialized.
118 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
122 WebView::WebView(uint32_t argc, char** argv)
123 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
125 mWebViewSize(Stage::GetCurrent().GetSize()),
127 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
128 mVideoHoleEnabled(false),
129 mMouseEventsEnabled(true),
130 mKeyEventsEnabled(true),
131 mScreenshotCapturedCallback(nullptr)
133 mWebEngine = Dali::WebEngine::New();
135 // WebEngine is empty when it is not properly initialized.
138 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
151 mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnFrameRendered);
152 mWebEngine.Destroy();
156 Toolkit::WebView WebView::New()
158 WebView* impl = new WebView();
159 Toolkit::WebView handle = Toolkit::WebView(*impl);
165 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
167 WebView* impl = new WebView(locale, timezoneId);
168 Toolkit::WebView handle = Toolkit::WebView(*impl);
174 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
176 WebView* impl = new WebView(argc, argv);
177 Toolkit::WebView handle = Toolkit::WebView(*impl);
183 void WebView::OnInitialize()
187 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
188 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
189 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
190 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
191 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
193 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
194 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
195 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
196 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
197 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
198 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
202 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered);
203 mWebContext = std::unique_ptr<Dali::Toolkit::WebContext>(new WebContext(mWebEngine.GetContext()));
204 mWebCookieManager = std::unique_ptr<Dali::Toolkit::WebCookieManager>(new WebCookieManager(mWebEngine.GetCookieManager()));
205 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
206 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
210 Dali::Toolkit::WebSettings* WebView::GetSettings() const
212 return mWebSettings.get();
215 Dali::Toolkit::WebContext* WebView::GetContext() const
217 return mWebContext.get();
220 Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const
222 return mWebCookieManager.get();
225 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
227 return mWebBackForwardList.get();
230 Dali::Toolkit::ImageView WebView::GetFavicon() const
232 Dali::Toolkit::ImageView faviconView;
235 Dali::PixelData pixelData = mWebEngine.GetFavicon();
236 faviconView = CreateImageView(pixelData);
241 void WebView::LoadUrl(const std::string& url)
247 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
250 mWebEngine.LoadUrl(url);
254 void WebView::LoadHtmlString(const std::string& htmlString)
260 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
263 mWebEngine.LoadHtmlString(htmlString);
267 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
274 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
277 return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
280 bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
287 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
290 return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
293 void WebView::Reload()
301 bool WebView::ReloadWithoutCache()
303 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
306 void WebView::StopLoading()
310 mWebEngine.StopLoading();
314 void WebView::Suspend()
318 mWebEngine.Suspend();
322 void WebView::Resume()
330 void WebView::SuspendNetworkLoading()
334 mWebEngine.SuspendNetworkLoading();
338 void WebView::ResumeNetworkLoading()
342 mWebEngine.ResumeNetworkLoading();
346 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
348 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
351 bool WebView::RemoveCustomHeader(const std::string& name)
353 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
356 uint32_t WebView::StartInspectorServer(uint32_t port)
358 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
361 bool WebView::StopInspectorServer()
363 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
366 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
370 mWebEngine.ScrollBy(deltaX, deltaY);
374 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
376 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
379 bool WebView::CanGoForward()
381 return mWebEngine ? mWebEngine.CanGoForward() : false;
384 void WebView::GoForward()
388 mWebEngine.GoForward();
392 bool WebView::CanGoBack()
394 return mWebEngine ? mWebEngine.CanGoBack() : false;
397 void WebView::GoBack()
405 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
409 mWebEngine.EvaluateJavaScript(script, resultHandler);
413 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
417 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
421 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
425 mWebEngine.RegisterJavaScriptAlertCallback(callback);
429 void WebView::JavaScriptAlertReply()
433 mWebEngine.JavaScriptAlertReply();
437 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
441 mWebEngine.RegisterJavaScriptConfirmCallback(callback);
445 void WebView::JavaScriptConfirmReply(bool confirmed)
449 mWebEngine.JavaScriptConfirmReply(confirmed);
453 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
457 mWebEngine.RegisterJavaScriptPromptCallback(callback);
461 void WebView::JavaScriptPromptReply(const std::string& result)
465 mWebEngine.JavaScriptPromptReply(result);
469 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
471 std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
477 return mWebEngine.CreateHitTest(x, y, mode);
480 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
485 result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, callback);
490 void WebView::ClearHistory()
494 mWebEngine.ClearHistory();
498 void WebView::ClearAllTilesResources()
502 mWebEngine.ClearAllTilesResources();
506 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
510 mWebEngine.SetScaleFactor(scaleFactor, point);
514 float WebView::GetScaleFactor() const
516 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
519 void WebView::ActivateAccessibility(bool activated)
523 mWebEngine.ActivateAccessibility(activated);
527 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
529 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
532 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
536 mWebEngine.AddDynamicCertificatePath(host, certPath);
540 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
542 Dali::Toolkit::ImageView imageView;
545 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
546 imageView = CreateImageView(pixelData);
551 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
553 mScreenshotCapturedCallback = callback;
554 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
557 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
559 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
562 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
566 mWebEngine.RegisterGeolocationPermissionCallback(callback);
570 void WebView::SetTtsFocus(bool focused)
572 if(mWebEngine && !HasKeyInputFocus())
574 mWebEngine.SetFocus(focused);
578 void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/)
585 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
586 Vector3 actorSize = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
587 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
588 Vector2 screenPosition = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
590 Dali::Rect<int32_t> displayArea;
591 displayArea.x = screenPosition.x - anchorPointOffSet.x;
592 displayArea.y = screenPosition.y - anchorPointOffSet.y;
593 displayArea.width = actorSize.x;
594 displayArea.height = actorSize.y;
596 Size displaySize = Size(displayArea.width, displayArea.height);
597 if(mWebViewSize != displaySize)
599 mWebViewSize = displaySize;
602 if(mWebViewArea != displayArea)
604 mWebViewArea = displayArea;
605 mWebEngine.UpdateDisplayArea(mWebViewArea);
609 void WebView::EnableVideoHole(bool enabled)
611 mVideoHoleEnabled = enabled;
613 EnableBlendMode(!mVideoHoleEnabled);
617 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
621 void WebView::EnableBlendMode(bool blendEnabled)
624 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
626 Dali::Renderer render = self.GetRendererAt(i);
627 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
631 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
635 return Dali::Toolkit::ImageView();
638 Dali::Toolkit::ImageUrl url = Dali::Toolkit::Image::GenerateUrl(pixel);
639 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url.GetUrl());
640 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
644 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
648 mWebEngine.RegisterPageLoadStartedCallback(callback);
652 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
656 mWebEngine.RegisterPageLoadInProgressCallback(callback);
660 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
664 mWebEngine.RegisterPageLoadFinishedCallback(callback);
668 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
672 mWebEngine.RegisterPageLoadErrorCallback(callback);
676 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
680 mWebEngine.RegisterScrollEdgeReachedCallback(callback);
684 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
688 mWebEngine.RegisterUrlChangedCallback(callback);
692 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
696 mWebEngine.RegisterFormRepostDecidedCallback(callback);
700 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
702 mFrameRenderedCallback = callback;
705 void WebView::RegisterRequestInterceptorCallback(Dali::WebEnginePlugin::WebEngineRequestInterceptorCallback callback)
709 mWebEngine.RegisterRequestInterceptorCallback(callback);
713 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
717 mWebEngine.RegisterConsoleMessageReceivedCallback(callback);
721 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
725 mWebEngine.RegisterResponsePolicyDecidedCallback(callback);
729 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
733 mWebEngine.RegisterCertificateConfirmedCallback(callback);
737 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
741 mWebEngine.RegisterSslCertificateChangedCallback(callback);
745 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
749 mWebEngine.RegisterHttpAuthHandlerCallback(callback);
753 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
757 mWebEngine.RegisterContextMenuShownCallback(callback);
761 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
765 mWebEngine.RegisterContextMenuHiddenCallback(callback);
769 void WebView::OnFrameRendered()
771 if(mFrameRenderedCallback)
773 mFrameRenderedCallback();
777 void WebView::OnInitialFrameRendered()
779 mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnInitialFrameRendered);
781 Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
782 const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
783 mVisual = Toolkit::VisualFactory::Get().CreateVisual({{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
787 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
788 EnableBlendMode(!mVideoHoleEnabled);
792 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
794 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
796 SetVisibility(isVisible);
800 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
802 if(mScreenshotCapturedCallback)
804 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
805 mScreenshotCapturedCallback(imageView);
809 void WebView::OnSceneConnection(int depth)
811 Control::OnSceneConnection(depth);
812 EnableBlendMode(!mVideoHoleEnabled);
815 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
821 result = mWebEngine.SendTouchEvent(touch);
826 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
832 result = mWebEngine.SendKeyEvent(event);
837 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
840 if(mWebEngine && mMouseEventsEnabled)
842 result = mWebEngine.SendHoverEvent(hover);
847 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
850 if(mWebEngine && mMouseEventsEnabled)
852 result = mWebEngine.SendWheelEvent(wheel);
857 void WebView::OnKeyInputFocusGained()
861 mWebEngine.SetFocus(true);
864 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
867 void WebView::OnKeyInputFocusLost()
871 mWebEngine.SetFocus(false);
874 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
877 Vector3 WebView::GetNaturalSize()
881 Vector2 rendererNaturalSize;
882 mVisual.GetNaturalSize(rendererNaturalSize);
883 return Vector3(rendererNaturalSize);
886 return Vector3(mWebViewSize);
889 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
891 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
895 WebView& impl = GetImpl(webView);
898 case Toolkit::WebView::Property::URL:
907 case Toolkit::WebView::Property::USER_AGENT:
912 impl.SetUserAgent(input);
916 case Toolkit::WebView::Property::SCROLL_POSITION:
921 impl.SetScrollPosition(input.x, input.y);
925 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
930 impl.EnableVideoHole(input);
934 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
939 impl.EnableMouseEvents(input);
943 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
948 impl.EnableKeyEvents(input);
952 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
957 impl.SetDocumentBackgroundColor(input);
961 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
966 impl.ClearTilesWhenHidden(input);
970 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
975 impl.SetTileCoverAreaMultiplier(input);
979 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
984 impl.EnableCursorByClient(input);
988 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
993 impl.SetPageZoomFactor(input);
997 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1000 if(value.Get(input))
1002 impl.SetTextZoomFactor(input);
1012 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1014 Property::Value value;
1016 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1020 WebView& impl = GetImpl(webView);
1021 switch(propertyIndex)
1023 case Toolkit::WebView::Property::URL:
1025 value = impl.GetUrl();
1028 case Toolkit::WebView::Property::USER_AGENT:
1030 value = impl.GetUserAgent();
1033 case Toolkit::WebView::Property::SCROLL_POSITION:
1035 value = impl.GetScrollPosition();
1038 case Toolkit::WebView::Property::SCROLL_SIZE:
1040 value = impl.GetScrollSize();
1043 case Toolkit::WebView::Property::CONTENT_SIZE:
1045 value = impl.GetContentSize();
1048 case Toolkit::WebView::Property::TITLE:
1050 value = impl.GetTitle();
1053 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1055 value = impl.mVideoHoleEnabled;
1058 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1060 value = impl.mMouseEventsEnabled;
1063 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1065 value = impl.mKeyEventsEnabled;
1068 case Toolkit::WebView::Property::SELECTED_TEXT:
1070 value = impl.GetSelectedText();
1073 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1075 value = impl.GetPageZoomFactor();
1078 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1080 value = impl.GetTextZoomFactor();
1083 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1085 value = impl.GetLoadProgressPercentage();
1096 void WebView::SetScrollPosition(int32_t x, int32_t y)
1100 mWebEngine.SetScrollPosition(x, y);
1104 Dali::Vector2 WebView::GetScrollPosition() const
1106 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1109 Dali::Vector2 WebView::GetScrollSize() const
1111 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1114 Dali::Vector2 WebView::GetContentSize() const
1116 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1119 std::string WebView::GetTitle() const
1121 return mWebEngine ? mWebEngine.GetTitle() : std::string();
1124 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1128 mWebEngine.SetDocumentBackgroundColor(color);
1132 void WebView::ClearTilesWhenHidden(bool cleared)
1136 mWebEngine.ClearTilesWhenHidden(cleared);
1140 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1144 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1148 void WebView::EnableCursorByClient(bool enabled)
1152 mWebEngine.EnableCursorByClient(enabled);
1156 std::string WebView::GetSelectedText() const
1158 return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1161 std::string WebView::GetUrl() const
1163 return mWebEngine ? mWebEngine.GetUrl() : std::string();
1166 std::string WebView::GetUserAgent() const
1168 return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1171 void WebView::SetUserAgent(const std::string& userAgent)
1175 mWebEngine.SetUserAgent(userAgent);
1179 void WebView::EnableMouseEvents(bool enabled)
1183 mMouseEventsEnabled = enabled;
1184 mWebEngine.EnableMouseEvents(enabled);
1188 void WebView::EnableKeyEvents(bool enabled)
1192 mKeyEventsEnabled = enabled;
1193 mWebEngine.EnableKeyEvents(enabled);
1197 void WebView::SetPageZoomFactor(float zoomFactor)
1201 mWebEngine.SetPageZoomFactor(zoomFactor);
1205 float WebView::GetPageZoomFactor() const
1207 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1210 void WebView::SetTextZoomFactor(float zoomFactor)
1214 mWebEngine.SetTextZoomFactor(zoomFactor);
1218 float WebView::GetTextZoomFactor() const
1220 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1223 float WebView::GetLoadProgressPercentage() const
1225 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1228 bool WebView::SetVisibility(bool visible)
1230 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1233 #undef GET_ENUM_STRING
1234 #undef GET_ENUM_VALUE
1236 } // namespace Internal
1238 } // namespace Toolkit