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-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-context.h>
48 #include <dali-toolkit/devel-api/controls/web-view/web-cookie-manager.h>
49 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
50 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
51 #include <dali-toolkit/public-api/image-loader/image.h>
52 #include <dali-toolkit/public-api/image-loader/image-url.h>
53 #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 #define GET_ENUM_STRING(structName, inputExp) \
95 Scripting::GetLinearEnumerationName<Toolkit::WebView::structName::Type>(static_cast<Toolkit::WebView::structName::Type>(inputExp), structName##_TABLE, structName##_TABLE_COUNT)
97 #define GET_ENUM_VALUE(structName, inputExp, outputExp) \
98 Scripting::GetEnumerationProperty<Toolkit::WebView::structName::Type>(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp)
100 WebView::WebView(const std::string& locale, const std::string& timezoneId)
101 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
103 mWebViewSize(Stage::GetCurrent().GetSize()),
105 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
106 mVideoHoleEnabled(false),
107 mMouseEventsEnabled(true),
108 mKeyEventsEnabled(true),
109 mScreenshotCapturedCallback(nullptr)
111 mWebEngine = Dali::WebEngine::New();
113 // WebEngine is empty when it is not properly initialized.
116 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
120 WebView::WebView(uint32_t argc, char** argv)
121 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
123 mWebViewSize(Stage::GetCurrent().GetSize()),
125 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
126 mVideoHoleEnabled(false),
127 mMouseEventsEnabled(true),
128 mKeyEventsEnabled(true),
129 mScreenshotCapturedCallback(nullptr)
131 mWebEngine = Dali::WebEngine::New();
133 // WebEngine is empty when it is not properly initialized.
136 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
149 mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnFrameRendered);
150 mWebEngine.Destroy();
154 Toolkit::WebView WebView::New()
156 WebView* impl = new WebView();
157 Toolkit::WebView handle = Toolkit::WebView(*impl);
163 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
165 WebView* impl = new WebView(locale, timezoneId);
166 Toolkit::WebView handle = Toolkit::WebView(*impl);
172 Toolkit::WebView WebView::New(uint32_t argc, char** argv)
174 WebView* impl = new WebView(argc, argv);
175 Toolkit::WebView handle = Toolkit::WebView(*impl);
181 void WebView::OnInitialize()
185 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
186 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
187 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
188 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
189 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
191 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
192 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
193 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
194 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
195 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
196 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
200 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered);
201 mWebContext = std::unique_ptr<Dali::Toolkit::WebContext>(new WebContext(mWebEngine.GetContext()));
202 mWebCookieManager = std::unique_ptr<Dali::Toolkit::WebCookieManager>(new WebCookieManager(mWebEngine.GetCookieManager()));
203 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
204 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
208 Dali::Toolkit::WebSettings* WebView::GetSettings() const
210 return mWebSettings.get();
213 Dali::Toolkit::WebContext* WebView::GetContext() const
215 return mWebContext.get();
218 Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const
220 return mWebCookieManager.get();
223 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
225 return mWebBackForwardList.get();
228 Dali::Toolkit::ImageView WebView::GetFavicon() const
230 Dali::Toolkit::ImageView faviconView;
233 Dali::PixelData pixelData = mWebEngine.GetFavicon();
234 faviconView = CreateImageView(pixelData);
239 void WebView::LoadUrl(const std::string& url)
245 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
248 mWebEngine.LoadUrl(url);
252 void WebView::LoadHtmlString(const std::string& htmlString)
258 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
261 mWebEngine.LoadHtmlString(htmlString);
265 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
272 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
275 return mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
278 bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
285 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnInitialFrameRendered);
288 return mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
291 void WebView::Reload()
299 bool WebView::ReloadWithoutCache()
301 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
304 void WebView::StopLoading()
308 mWebEngine.StopLoading();
312 void WebView::Suspend()
316 mWebEngine.Suspend();
320 void WebView::Resume()
328 void WebView::SuspendNetworkLoading()
332 mWebEngine.SuspendNetworkLoading();
336 void WebView::ResumeNetworkLoading()
340 mWebEngine.ResumeNetworkLoading();
344 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
346 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
349 bool WebView::RemoveCustomHeader(const std::string& name)
351 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
354 uint32_t WebView::StartInspectorServer(uint32_t port)
356 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
359 bool WebView::StopInspectorServer()
361 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
364 void WebView::ScrollBy(int32_t deltaX, int32_t deltaY)
368 mWebEngine.ScrollBy(deltaX, deltaY);
372 bool WebView::ScrollEdgeBy(int32_t deltaX, int32_t deltaY)
374 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
377 bool WebView::CanGoForward()
379 return mWebEngine ? mWebEngine.CanGoForward() : false;
382 void WebView::GoForward()
386 mWebEngine.GoForward();
390 bool WebView::CanGoBack()
392 return mWebEngine ? mWebEngine.CanGoBack() : false;
395 void WebView::GoBack()
403 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
407 mWebEngine.EvaluateJavaScript(script, resultHandler);
411 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
415 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
419 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
423 mWebEngine.RegisterJavaScriptAlertCallback(callback);
427 void WebView::JavaScriptAlertReply()
431 mWebEngine.JavaScriptAlertReply();
435 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
439 mWebEngine.RegisterJavaScriptConfirmCallback(callback);
443 void WebView::JavaScriptConfirmReply(bool confirmed)
447 mWebEngine.JavaScriptConfirmReply(confirmed);
451 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
455 mWebEngine.RegisterJavaScriptPromptCallback(callback);
459 void WebView::JavaScriptPromptReply(const std::string& result)
463 mWebEngine.JavaScriptPromptReply(result);
467 std::unique_ptr<Dali::WebEngineHitTest> WebView::CreateHitTest(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode)
469 std::unique_ptr<Dali::WebEngineHitTest> webHitTest;
475 return mWebEngine.CreateHitTest(x, y, mode);
478 bool WebView::CreateHitTestAsynchronously(int32_t x, int32_t y, Dali::WebEngineHitTest::HitTestMode mode, Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback callback)
483 result = mWebEngine.CreateHitTestAsynchronously(x, y, mode, callback);
488 void WebView::ClearHistory()
492 mWebEngine.ClearHistory();
496 void WebView::ClearAllTilesResources()
500 mWebEngine.ClearAllTilesResources();
504 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
508 mWebEngine.SetScaleFactor(scaleFactor, point);
512 float WebView::GetScaleFactor() const
514 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
517 void WebView::ActivateAccessibility(bool activated)
521 mWebEngine.ActivateAccessibility(activated);
525 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
527 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
530 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
534 mWebEngine.AddDynamicCertificatePath(host, certPath);
538 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int32_t> viewArea, float scaleFactor)
540 Dali::Toolkit::ImageView imageView;
543 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
544 imageView = CreateImageView(pixelData);
549 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int32_t> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
551 mScreenshotCapturedCallback = callback;
552 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
555 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
557 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
560 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
564 mWebEngine.RegisterGeolocationPermissionCallback(callback);
568 void WebView::SetTtsFocus(bool focused)
570 if(mWebEngine && !HasKeyInputFocus())
572 mWebEngine.SetFocus(focused);
576 void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/)
583 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
584 Vector3 actorSize = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
585 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
586 Vector2 screenPosition = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
588 Dali::Rect<int32_t> displayArea;
589 displayArea.x = screenPosition.x - anchorPointOffSet.x;
590 displayArea.y = screenPosition.y - anchorPointOffSet.y;
591 displayArea.width = actorSize.x;
592 displayArea.height = actorSize.y;
594 Size displaySize = Size(displayArea.width, displayArea.height);
595 if(mWebViewSize != displaySize)
597 mWebViewSize = displaySize;
600 if(mWebViewArea != displayArea)
602 mWebViewArea = displayArea;
603 mWebEngine.UpdateDisplayArea(mWebViewArea);
607 void WebView::EnableVideoHole(bool enabled)
609 mVideoHoleEnabled = enabled;
611 EnableBlendMode(!mVideoHoleEnabled);
615 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
619 void WebView::EnableBlendMode(bool blendEnabled)
622 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
624 Dali::Renderer render = self.GetRendererAt(i);
625 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
629 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
633 return Dali::Toolkit::ImageView();
636 Dali::Toolkit::ImageUrl url = Dali::Toolkit::Image::GenerateUrl(pixel);
637 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url.GetUrl());
638 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
642 void WebView::RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
646 mWebEngine.RegisterPageLoadStartedCallback(callback);
650 void WebView::RegisterPageLoadInProgressCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
654 mWebEngine.RegisterPageLoadInProgressCallback(callback);
658 void WebView::RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback)
662 mWebEngine.RegisterPageLoadFinishedCallback(callback);
666 void WebView::RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback)
670 mWebEngine.RegisterPageLoadErrorCallback(callback);
674 void WebView::RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback)
678 mWebEngine.RegisterScrollEdgeReachedCallback(callback);
682 void WebView::RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback)
686 mWebEngine.RegisterUrlChangedCallback(callback);
690 void WebView::RegisterFormRepostDecidedCallback(Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback callback)
694 mWebEngine.RegisterFormRepostDecidedCallback(callback);
698 void WebView::RegisterFrameRenderedCallback(Dali::WebEnginePlugin::WebEngineFrameRenderedCallback callback)
700 mFrameRenderedCallback = callback;
703 void WebView::RegisterConsoleMessageReceivedCallback(Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback callback)
707 mWebEngine.RegisterConsoleMessageReceivedCallback(callback);
711 void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback)
715 mWebEngine.RegisterResponsePolicyDecidedCallback(callback);
719 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
723 mWebEngine.RegisterCertificateConfirmedCallback(callback);
727 void WebView::RegisterSslCertificateChangedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
731 mWebEngine.RegisterSslCertificateChangedCallback(callback);
735 void WebView::RegisterHttpAuthHandlerCallback(Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback callback)
739 mWebEngine.RegisterHttpAuthHandlerCallback(callback);
743 void WebView::RegisterContextMenuShownCallback(Dali::WebEnginePlugin::WebEngineContextMenuShownCallback callback)
747 mWebEngine.RegisterContextMenuShownCallback(callback);
751 void WebView::RegisterContextMenuHiddenCallback(Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback callback)
755 mWebEngine.RegisterContextMenuHiddenCallback(callback);
759 void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
763 mWebEngine.GetPlainTextAsynchronously(callback);
767 void WebView::OnFrameRendered()
769 if(mFrameRenderedCallback)
771 mFrameRenderedCallback();
775 void WebView::OnInitialFrameRendered()
777 mWebEngine.FrameRenderedSignal().Disconnect(this, &WebView::OnInitialFrameRendered);
779 Dali::Toolkit::ImageUrl nativeImageUrl = Dali::Toolkit::Image::GenerateUrl(mWebEngine.GetNativeImageSource());
780 mVisual = Toolkit::VisualFactory::Get().CreateVisual({{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, {Toolkit::ImageVisual::Property::URL, nativeImageUrl.GetUrl()}});
784 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
785 EnableBlendMode(!mVideoHoleEnabled);
789 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
791 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
793 SetVisibility(isVisible);
797 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
799 if(mScreenshotCapturedCallback)
801 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
802 mScreenshotCapturedCallback(imageView);
806 void WebView::OnSceneConnection(int depth)
808 Control::OnSceneConnection(depth);
809 EnableBlendMode(!mVideoHoleEnabled);
812 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
818 result = mWebEngine.SendTouchEvent(touch);
823 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
829 result = mWebEngine.SendKeyEvent(event);
834 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
837 if(mWebEngine && mMouseEventsEnabled)
839 result = mWebEngine.SendHoverEvent(hover);
844 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
847 if(mWebEngine && mMouseEventsEnabled)
849 result = mWebEngine.SendWheelEvent(wheel);
854 void WebView::OnKeyInputFocusGained()
858 mWebEngine.SetFocus(true);
861 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
864 void WebView::OnKeyInputFocusLost()
868 mWebEngine.SetFocus(false);
871 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
874 Vector3 WebView::GetNaturalSize()
878 Vector2 rendererNaturalSize;
879 mVisual.GetNaturalSize(rendererNaturalSize);
880 return Vector3(rendererNaturalSize);
883 return Vector3(mWebViewSize);
886 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
888 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
892 WebView& impl = GetImpl(webView);
895 case Toolkit::WebView::Property::URL:
904 case Toolkit::WebView::Property::USER_AGENT:
909 impl.SetUserAgent(input);
913 case Toolkit::WebView::Property::SCROLL_POSITION:
918 impl.SetScrollPosition(input.x, input.y);
922 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
927 impl.EnableVideoHole(input);
931 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
936 impl.EnableMouseEvents(input);
940 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
945 impl.EnableKeyEvents(input);
949 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
954 impl.SetDocumentBackgroundColor(input);
958 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
963 impl.ClearTilesWhenHidden(input);
967 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
972 impl.SetTileCoverAreaMultiplier(input);
976 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
981 impl.EnableCursorByClient(input);
985 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
990 impl.SetPageZoomFactor(input);
994 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
999 impl.SetTextZoomFactor(input);
1009 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1011 Property::Value value;
1013 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1017 WebView& impl = GetImpl(webView);
1018 switch(propertyIndex)
1020 case Toolkit::WebView::Property::URL:
1022 value = impl.GetUrl();
1025 case Toolkit::WebView::Property::USER_AGENT:
1027 value = impl.GetUserAgent();
1030 case Toolkit::WebView::Property::SCROLL_POSITION:
1032 value = impl.GetScrollPosition();
1035 case Toolkit::WebView::Property::SCROLL_SIZE:
1037 value = impl.GetScrollSize();
1040 case Toolkit::WebView::Property::CONTENT_SIZE:
1042 value = impl.GetContentSize();
1045 case Toolkit::WebView::Property::TITLE:
1047 value = impl.GetTitle();
1050 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1052 value = impl.mVideoHoleEnabled;
1055 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1057 value = impl.mMouseEventsEnabled;
1060 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1062 value = impl.mKeyEventsEnabled;
1065 case Toolkit::WebView::Property::SELECTED_TEXT:
1067 value = impl.GetSelectedText();
1070 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1072 value = impl.GetPageZoomFactor();
1075 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1077 value = impl.GetTextZoomFactor();
1080 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1082 value = impl.GetLoadProgressPercentage();
1093 void WebView::SetScrollPosition(int32_t x, int32_t y)
1097 mWebEngine.SetScrollPosition(x, y);
1101 Dali::Vector2 WebView::GetScrollPosition() const
1103 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1106 Dali::Vector2 WebView::GetScrollSize() const
1108 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1111 Dali::Vector2 WebView::GetContentSize() const
1113 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1116 std::string WebView::GetTitle() const
1118 return mWebEngine ? mWebEngine.GetTitle() : std::string();
1121 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1125 mWebEngine.SetDocumentBackgroundColor(color);
1129 void WebView::ClearTilesWhenHidden(bool cleared)
1133 mWebEngine.ClearTilesWhenHidden(cleared);
1137 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1141 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1145 void WebView::EnableCursorByClient(bool enabled)
1149 mWebEngine.EnableCursorByClient(enabled);
1153 std::string WebView::GetSelectedText() const
1155 return mWebEngine ? mWebEngine.GetSelectedText() : std::string();
1158 std::string WebView::GetUrl() const
1160 return mWebEngine ? mWebEngine.GetUrl() : std::string();
1163 std::string WebView::GetUserAgent() const
1165 return mWebEngine ? mWebEngine.GetUserAgent() : std::string();
1168 void WebView::SetUserAgent(const std::string& userAgent)
1172 mWebEngine.SetUserAgent(userAgent);
1176 void WebView::EnableMouseEvents(bool enabled)
1180 mMouseEventsEnabled = enabled;
1181 mWebEngine.EnableMouseEvents(enabled);
1185 void WebView::EnableKeyEvents(bool enabled)
1189 mKeyEventsEnabled = enabled;
1190 mWebEngine.EnableKeyEvents(enabled);
1194 void WebView::SetPageZoomFactor(float zoomFactor)
1198 mWebEngine.SetPageZoomFactor(zoomFactor);
1202 float WebView::GetPageZoomFactor() const
1204 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1207 void WebView::SetTextZoomFactor(float zoomFactor)
1211 mWebEngine.SetTextZoomFactor(zoomFactor);
1215 float WebView::GetTextZoomFactor() const
1217 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1220 float WebView::GetLoadProgressPercentage() const
1222 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1225 bool WebView::SetVisibility(bool visible)
1227 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1230 #undef GET_ENUM_STRING
1231 #undef GET_ENUM_VALUE
1233 } // namespace Internal
1235 } // namespace Toolkit