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-console-message.h>
24 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-form-repost-decision.h>
27 #include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
28 #include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
29 #include <dali/devel-api/adaptor-framework/web-engine-settings.h>
30 #include <dali/devel-api/common/stage.h>
31 #include <dali/devel-api/scripting/enum-helper.h>
32 #include <dali/devel-api/scripting/scripting.h>
33 #include <dali/public-api/adaptor-framework/native-image-source.h>
34 #include <dali/public-api/object/type-registry-helper.h>
35 #include <dali/public-api/object/type-registry.h>
40 #include <dali-toolkit/devel-api/controls/control-devel.h>
41 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
42 #include <dali-toolkit/devel-api/controls/web-view/web-context.h>
43 #include <dali-toolkit/devel-api/controls/web-view/web-cookie-manager.h>
44 #include <dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.h>
45 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
46 #include <dali-toolkit/devel-api/image-loader/texture-manager.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/visuals/image-visual-properties.h>
61 return Toolkit::WebView::New();
65 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
67 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url", STRING, URL )
68 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent", STRING, USER_AGENT )
69 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION )
70 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE )
71 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE )
72 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title", STRING, TITLE )
73 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled", BOOLEAN, VIDEO_HOLE_ENABLED )
74 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled", BOOLEAN, MOUSE_EVENTS_ENABLED )
75 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled", BOOLEAN, KEY_EVENTS_ENABLED )
76 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR )
77 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden", BOOLEAN, TILES_CLEARED_WHEN_HIDDEN )
78 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT, TILE_COVER_AREA_MULTIPLIER)
79 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient", BOOLEAN, CURSOR_ENABLED_BY_CLIENT )
80 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText", STRING, SELECTED_TEXT )
81 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor", FLOAT, PAGE_ZOOM_FACTOR )
82 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor", FLOAT, TEXT_ZOOM_FACTOR )
83 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage", FLOAT, LOAD_PROGRESS_PERCENTAGE )
85 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadStarted", PAGE_LOAD_STARTED_SIGNAL )
86 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadInProgress", PAGE_LOAD_IN_PROGRESS_SIGNAL)
87 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadFinished", PAGE_LOAD_FINISHED_SIGNAL )
88 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadError", PAGE_LOAD_ERROR_SIGNAL )
89 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "scrollEdgeReached", SCROLL_EDGE_REACHED_SIGNAL )
90 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "urlChanged", URL_CHANGED_SIGNAL )
91 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "formRepostDecision", FORM_REPOST_DECISION_SIGNAL )
92 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "frameRendered", FRAME_RENDERED_SIGNAL )
93 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "requestInterceptor", REQUEST_INTERCEPTOR_SIGNAL )
94 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "consoleMessage", CONSOLE_MESSAGE_SIGNAL )
96 DALI_TYPE_REGISTRATION_END()
99 const std::string kEmptyString;
103 #define GET_ENUM_STRING(structName, inputExp) \
104 Scripting::GetLinearEnumerationName<Toolkit::WebView::structName::Type>(static_cast<Toolkit::WebView::structName::Type>(inputExp), structName##_TABLE, structName##_TABLE_COUNT)
106 #define GET_ENUM_VALUE(structName, inputExp, outputExp) \
107 Scripting::GetEnumerationProperty<Toolkit::WebView::structName::Type>(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp)
109 WebView::WebView(const std::string& locale, const std::string& timezoneId)
110 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
113 mWebViewSize(Stage::GetCurrent().GetSize()),
115 mPageLoadStartedSignal(),
116 mPageLoadFinishedSignal(),
117 mPageLoadErrorSignal(),
119 mVideoHoleEnabled(true),
120 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
121 mMouseEventsEnabled(true),
122 mKeyEventsEnabled(true)
124 mWebEngine = Dali::WebEngine::New();
126 // WebEngine is empty when it is not properly initialized.
129 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
133 WebView::WebView(int argc, char** argv)
134 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
137 mWebViewSize(Stage::GetCurrent().GetSize()),
139 mPageLoadStartedSignal(),
140 mPageLoadFinishedSignal(),
141 mPageLoadErrorSignal(),
143 mVideoHoleEnabled(true),
144 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
145 mMouseEventsEnabled(true),
146 mKeyEventsEnabled(true)
148 mWebEngine = Dali::WebEngine::New();
150 // WebEngine is empty when it is not properly initialized.
153 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
166 mWebEngine.Destroy();
170 Toolkit::WebView WebView::New()
172 WebView* impl = new WebView();
173 Toolkit::WebView handle = Toolkit::WebView(*impl);
179 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
181 WebView* impl = new WebView(locale, timezoneId);
182 Toolkit::WebView handle = Toolkit::WebView(*impl);
188 Toolkit::WebView WebView::New(int argc, char** argv)
190 WebView* impl = new WebView(argc, argv);
191 Toolkit::WebView handle = Toolkit::WebView(*impl);
197 void WebView::OnInitialize()
201 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
202 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
203 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
204 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
205 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
207 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
208 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
209 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
210 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
211 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
212 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
216 mWebEngine.PageLoadStartedSignal().Connect(this, &WebView::OnPageLoadStarted);
217 mWebEngine.PageLoadInProgressSignal().Connect(this, &WebView::OnPageLoadInProgress);
218 mWebEngine.PageLoadFinishedSignal().Connect(this, &WebView::OnPageLoadFinished);
219 mWebEngine.PageLoadErrorSignal().Connect(this, &WebView::OnPageLoadError);
220 mWebEngine.ScrollEdgeReachedSignal().Connect(this, &WebView::OnScrollEdgeReached);
221 mWebEngine.UrlChangedSignal().Connect(this, &WebView::OnUrlChanged);
222 mWebEngine.FormRepostDecisionSignal().Connect(this, &WebView::OnFormRepostDecision);
223 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered);
224 mWebEngine.RequestInterceptorSignal().Connect(this, &WebView::OnInterceptRequest);
225 mWebEngine.ConsoleMessageSignal().Connect(this, &WebView::OnConsoleMessage);
227 mWebContext = std::unique_ptr<Dali::Toolkit::WebContext>(new WebContext(mWebEngine.GetContext()));
228 mWebCookieManager = std::unique_ptr<Dali::Toolkit::WebCookieManager>(new WebCookieManager(mWebEngine.GetCookieManager()));
229 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
230 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
234 Dali::Toolkit::WebSettings* WebView::GetSettings() const
236 return mWebSettings.get();
239 Dali::Toolkit::WebContext* WebView::GetContext() const
241 return mWebContext.get();
244 Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const
246 return mWebCookieManager.get();
249 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
251 return mWebBackForwardList.get();
254 Dali::Toolkit::ImageView& WebView::GetFavicon()
258 Dali::PixelData pixelData = mWebEngine.GetFavicon();
259 mFaviconView = CreateImageView(pixelData);
264 void WebView::LoadUrl(const std::string& url)
269 Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
270 const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
271 mVisual = Toolkit::VisualFactory::Get().CreateVisual(
272 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
273 {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
277 // Clean up previously registered visual and add new one.
278 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
279 mWebEngine.LoadUrl(url);
282 if(mVideoHoleEnabled)
284 EnableBlendMode(false);
289 void WebView::LoadHtmlString(const std::string& htmlString)
293 Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
294 const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
295 mVisual = Toolkit::VisualFactory::Get().CreateVisual(
296 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
297 {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
301 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
302 mWebEngine.LoadHtmlString(htmlString);
305 if(mVideoHoleEnabled)
307 EnableBlendMode(false);
312 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
317 Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
318 const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
319 mVisual = Toolkit::VisualFactory::Get().CreateVisual(
320 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
321 {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
326 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
327 result = mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
330 if(mVideoHoleEnabled)
332 EnableBlendMode(false);
337 bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
342 Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
343 const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
344 mVisual = Toolkit::VisualFactory::Get().CreateVisual(
345 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
346 {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
351 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
352 result = mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
355 if(mVideoHoleEnabled)
357 EnableBlendMode(false);
362 void WebView::Reload()
370 bool WebView::ReloadWithoutCache()
372 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
375 void WebView::StopLoading()
379 mWebEngine.StopLoading();
383 void WebView::Suspend()
387 mWebEngine.Suspend();
391 void WebView::Resume()
399 void WebView::SuspendNetworkLoading()
403 mWebEngine.SuspendNetworkLoading();
407 void WebView::ResumeNetworkLoading()
411 mWebEngine.ResumeNetworkLoading();
415 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
417 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
420 bool WebView::RemoveCustomHeader(const std::string& name)
422 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
425 uint32_t WebView::StartInspectorServer(uint32_t port)
427 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
430 bool WebView::StopInspectorServer()
432 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
435 void WebView::ScrollBy(int deltaX, int deltaY)
439 mWebEngine.ScrollBy(deltaX, deltaY);
443 bool WebView::ScrollEdgeBy(int deltaX, int deltaY)
445 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
448 bool WebView::CanGoForward()
450 return mWebEngine ? mWebEngine.CanGoForward() : false;
453 void WebView::GoForward()
457 mWebEngine.GoForward();
461 bool WebView::CanGoBack()
463 return mWebEngine ? mWebEngine.CanGoBack() : false;
466 void WebView::GoBack()
474 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
478 mWebEngine.EvaluateJavaScript(script, resultHandler);
482 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
486 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
490 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
494 mWebEngine.RegisterJavaScriptAlertCallback(callback);
498 void WebView::JavaScriptAlertReply()
502 mWebEngine.JavaScriptAlertReply();
506 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
510 mWebEngine.RegisterJavaScriptConfirmCallback(callback);
514 void WebView::JavaScriptConfirmReply(bool confirmed)
518 mWebEngine.JavaScriptConfirmReply(confirmed);
522 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
526 mWebEngine.RegisterJavaScriptPromptCallback(callback);
530 void WebView::JavaScriptPromptReply(const std::string& result)
534 mWebEngine.JavaScriptPromptReply(result);
538 void WebView::ClearHistory()
542 mWebEngine.ClearHistory();
546 void WebView::ClearAllTilesResources()
550 mWebEngine.ClearAllTilesResources();
554 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
558 mWebEngine.SetScaleFactor(scaleFactor, point);
562 float WebView::GetScaleFactor() const
564 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
567 void WebView::ActivateAccessibility(bool activated)
571 mWebEngine.ActivateAccessibility(activated);
575 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
577 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
580 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
584 mWebEngine.AddDynamicCertificatePath(host, certPath);
588 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor)
590 Dali::Toolkit::ImageView imageView;
593 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
594 imageView = CreateImageView(pixelData);
599 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
601 mScreenshotCapturedCallback = callback;
602 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
605 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
607 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
610 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
614 mWebEngine.RegisterGeolocationPermissionCallback(callback);
618 void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/)
625 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
626 Vector3 actorSize = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
627 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
628 Vector2 screenPosition = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
630 Dali::Rect<int> displayArea;
631 displayArea.x = screenPosition.x - anchorPointOffSet.x;
632 displayArea.y = screenPosition.y - anchorPointOffSet.y;
633 displayArea.width = actorSize.x;
634 displayArea.height = actorSize.y;
636 Size displaySize = Size(displayArea.width, displayArea.height);
637 if(mWebViewSize != displaySize)
639 mWebViewSize = displaySize;
642 if(mWebViewArea != displayArea)
644 mWebViewArea = displayArea;
645 mWebEngine.UpdateDisplayArea(mWebViewArea);
649 void WebView::EnableVideoHole(bool enabled)
651 mVideoHoleEnabled = enabled;
653 EnableBlendMode(!mVideoHoleEnabled);
657 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
661 void WebView::EnableBlendMode(bool blendEnabled)
664 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
666 Dali::Renderer render = self.GetRendererAt(i);
667 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
671 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel)
673 std::string url = Dali::Toolkit::Image::GenerateUrl(pixel);
674 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url);
675 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
679 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal()
681 return mPageLoadStartedSignal;
684 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadInProgressSignal()
686 return mPageLoadInProgressSignal;
689 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadFinishedSignal()
691 return mPageLoadFinishedSignal;
694 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& WebView::PageLoadErrorSignal()
696 return mPageLoadErrorSignal;
699 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& WebView::ScrollEdgeReachedSignal()
701 return mScrollEdgeReachedSignal;
704 Dali::Toolkit::WebView::WebViewUrlChangedSignalType& WebView::UrlChangedSignal()
706 return mUrlChangedSignal;
709 Dali::Toolkit::WebView::WebViewFormRepostDecisionSignalType& WebView::FormRepostDecisionSignal()
711 return mFormRepostDecisionSignal;
714 Dali::Toolkit::WebView::WebViewFrameRenderedSignalType& WebView::FrameRenderedSignal()
716 return mFrameRenderedSignal;
719 Dali::Toolkit::WebView::WebViewRequestInterceptorSignalType& WebView::RequestInterceptorSignal()
721 return mRequestInterceptorSignal;
724 Dali::Toolkit::WebView::WebViewConsoleMessageSignalType& WebView::ConsoleMessageSignal()
726 return mConsoleMessageSignal;
729 void WebView::OnPageLoadStarted(const std::string& url)
731 if(!mPageLoadStartedSignal.Empty())
733 Dali::Toolkit::WebView handle(GetOwner());
734 mPageLoadStartedSignal.Emit(handle, url);
738 void WebView::OnPageLoadInProgress(const std::string& url)
740 if(!mPageLoadInProgressSignal.Empty())
742 Dali::Toolkit::WebView handle(GetOwner());
743 mPageLoadInProgressSignal.Emit(handle, url);
747 void WebView::OnPageLoadFinished(const std::string& url)
749 if(!mPageLoadFinishedSignal.Empty())
751 Dali::Toolkit::WebView handle(GetOwner());
752 mPageLoadFinishedSignal.Emit(handle, url);
756 void WebView::OnPageLoadError(std::shared_ptr<Dali::WebEngineLoadError> error)
758 if(!mPageLoadErrorSignal.Empty())
760 Dali::Toolkit::WebView handle(GetOwner());
761 mPageLoadErrorSignal.Emit(handle, std::move(error));
765 void WebView::OnScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge)
767 if(!mScrollEdgeReachedSignal.Empty())
769 Dali::Toolkit::WebView handle(GetOwner());
770 mScrollEdgeReachedSignal.Emit(handle, edge);
774 void WebView::OnUrlChanged(const std::string& url)
776 if(!mUrlChangedSignal.Empty())
778 Dali::Toolkit::WebView handle(GetOwner());
779 mUrlChangedSignal.Emit(handle, url);
783 void WebView::OnFormRepostDecision(std::shared_ptr<Dali::WebEngineFormRepostDecision> decision)
785 if(!mFormRepostDecisionSignal.Empty())
787 Dali::Toolkit::WebView handle(GetOwner());
788 std::shared_ptr<Dali::Toolkit::WebFormRepostDecision> repostDecision(new Dali::Toolkit::WebFormRepostDecision(decision));
789 mFormRepostDecisionSignal.Emit(handle, std::move(repostDecision));
793 void WebView::OnFrameRendered()
795 if(!mFrameRenderedSignal.Empty())
797 Dali::Toolkit::WebView handle(GetOwner());
798 mFrameRenderedSignal.Emit(handle);
802 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
804 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
806 SetVisibility(isVisible);
810 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
812 if(mScreenshotCapturedCallback)
814 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
815 mScreenshotCapturedCallback(imageView);
819 void WebView::OnInterceptRequest(std::shared_ptr<Dali::WebEngineRequestInterceptor> interceptor)
821 if(!mRequestInterceptorSignal.Empty())
823 Dali::Toolkit::WebView handle(GetOwner());
824 mRequestInterceptorSignal.Emit(handle, std::move(interceptor));
828 void WebView::OnConsoleMessage(std::shared_ptr<Dali::WebEngineConsoleMessage> message)
830 if(!mConsoleMessageSignal.Empty())
832 Dali::Toolkit::WebView handle(GetOwner());
833 mConsoleMessageSignal.Emit(handle, std::move(message));
837 bool WebView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
839 Dali::BaseHandle handle(object);
841 bool connected = false;
842 Toolkit::WebView webView = Toolkit::WebView::DownCast(handle);
844 if(0 == strcmp(signalName.c_str(), PAGE_LOAD_STARTED_SIGNAL))
846 webView.PageLoadStartedSignal().Connect(tracker, functor);
849 else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_IN_PROGRESS_SIGNAL))
851 webView.PageLoadInProgressSignal().Connect(tracker, functor);
854 else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_FINISHED_SIGNAL))
856 webView.PageLoadFinishedSignal().Connect(tracker, functor);
859 else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_ERROR_SIGNAL))
861 webView.PageLoadErrorSignal().Connect(tracker, functor);
864 else if(0 == strcmp(signalName.c_str(), SCROLL_EDGE_REACHED_SIGNAL))
866 webView.ScrollEdgeReachedSignal().Connect(tracker, functor);
869 else if(0 == strcmp(signalName.c_str(), URL_CHANGED_SIGNAL))
871 webView.UrlChangedSignal().Connect(tracker, functor);
874 else if(0 == strcmp(signalName.c_str(), FORM_REPOST_DECISION_SIGNAL))
876 webView.FormRepostDecisionSignal().Connect(tracker, functor);
879 else if(0 == strcmp(signalName.c_str(), FRAME_RENDERED_SIGNAL))
881 webView.FrameRenderedSignal().Connect(tracker, functor);
884 else if(0 == strcmp(signalName.c_str(), REQUEST_INTERCEPTOR_SIGNAL))
886 webView.RequestInterceptorSignal().Connect(tracker, functor);
889 else if(0 == strcmp(signalName.c_str(), CONSOLE_MESSAGE_SIGNAL))
891 webView.ConsoleMessageSignal().Connect(tracker, functor);
898 Vector3 WebView::GetNaturalSize()
902 Vector2 rendererNaturalSize;
903 mVisual.GetNaturalSize(rendererNaturalSize);
904 return Vector3(rendererNaturalSize);
907 return Vector3(mWebViewSize);
910 void WebView::OnSceneConnection(int depth)
912 Control::OnSceneConnection(depth);
914 EnableBlendMode(!mVideoHoleEnabled);
917 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
919 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
923 WebView& impl = GetImpl(webView);
926 case Toolkit::WebView::Property::URL:
935 case Toolkit::WebView::Property::USER_AGENT:
940 impl.SetUserAgent(input);
944 case Toolkit::WebView::Property::SCROLL_POSITION:
949 impl.SetScrollPosition(input.x, input.y);
953 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
958 impl.EnableVideoHole(input);
962 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
967 impl.EnableMouseEvents(input);
971 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
976 impl.EnableKeyEvents(input);
980 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
985 impl.SetDocumentBackgroundColor(input);
989 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
994 impl.ClearTilesWhenHidden(input);
998 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
1001 if(value.Get(input))
1003 impl.SetTileCoverAreaMultiplier(input);
1007 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
1010 if(value.Get(input))
1012 impl.EnableCursorByClient(input);
1016 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1019 if(value.Get(input))
1021 impl.SetPageZoomFactor(input);
1025 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1028 if(value.Get(input))
1030 impl.SetTextZoomFactor(input);
1040 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
1042 Property::Value value;
1044 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1048 WebView& impl = GetImpl(webView);
1049 switch(propertyIndex)
1051 case Toolkit::WebView::Property::URL:
1056 case Toolkit::WebView::Property::USER_AGENT:
1058 value = impl.GetUserAgent();
1061 case Toolkit::WebView::Property::SCROLL_POSITION:
1063 value = impl.GetScrollPosition();
1066 case Toolkit::WebView::Property::SCROLL_SIZE:
1068 value = impl.GetScrollSize();
1071 case Toolkit::WebView::Property::CONTENT_SIZE:
1073 value = impl.GetContentSize();
1076 case Toolkit::WebView::Property::TITLE:
1078 value = impl.GetTitle();
1081 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1083 value = impl.mVideoHoleEnabled;
1086 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1088 value = impl.mMouseEventsEnabled;
1091 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1093 value = impl.mKeyEventsEnabled;
1096 case Toolkit::WebView::Property::SELECTED_TEXT:
1098 value = impl.GetSelectedText();
1101 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1103 value = impl.GetPageZoomFactor();
1106 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1108 value = impl.GetTextZoomFactor();
1111 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1113 value = impl.GetLoadProgressPercentage();
1124 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
1126 bool result = false;
1130 result = mWebEngine.SendTouchEvent(touch);
1135 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
1137 bool result = false;
1141 result = mWebEngine.SendKeyEvent(event);
1146 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
1148 bool result = false;
1151 result = mWebEngine.SendHoverEvent(hover);
1156 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
1158 bool result = false;
1161 result = mWebEngine.SendWheelEvent(wheel);
1166 void WebView::OnKeyInputFocusGained()
1170 mWebEngine.SetFocus(true);
1173 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
1176 void WebView::OnKeyInputFocusLost()
1180 mWebEngine.SetFocus(false);
1183 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
1186 void WebView::SetScrollPosition(int x, int y)
1190 mWebEngine.SetScrollPosition(x, y);
1194 Dali::Vector2 WebView::GetScrollPosition() const
1196 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1199 Dali::Vector2 WebView::GetScrollSize() const
1201 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1204 Dali::Vector2 WebView::GetContentSize() const
1206 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1209 std::string WebView::GetTitle() const
1211 return mWebEngine ? mWebEngine.GetTitle() : kEmptyString;
1214 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1218 mWebEngine.SetDocumentBackgroundColor(color);
1222 void WebView::ClearTilesWhenHidden(bool cleared)
1226 mWebEngine.ClearTilesWhenHidden(cleared);
1230 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1234 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1238 void WebView::EnableCursorByClient(bool enabled)
1242 mWebEngine.EnableCursorByClient(enabled);
1246 std::string WebView::GetSelectedText() const
1248 return mWebEngine ? mWebEngine.GetSelectedText() : kEmptyString;
1251 const std::string& WebView::GetUserAgent() const
1253 return mWebEngine ? mWebEngine.GetUserAgent() : kEmptyString;
1256 void WebView::SetUserAgent(const std::string& userAgent)
1260 mWebEngine.SetUserAgent(userAgent);
1264 void WebView::EnableMouseEvents(bool enabled)
1268 mMouseEventsEnabled = enabled;
1269 mWebEngine.EnableMouseEvents(enabled);
1273 void WebView::EnableKeyEvents(bool enabled)
1277 mKeyEventsEnabled = enabled;
1278 mWebEngine.EnableKeyEvents(enabled);
1282 void WebView::SetPageZoomFactor(float zoomFactor)
1286 mWebEngine.SetPageZoomFactor(zoomFactor);
1290 float WebView::GetPageZoomFactor() const
1292 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1295 void WebView::SetTextZoomFactor(float zoomFactor)
1299 mWebEngine.SetTextZoomFactor(zoomFactor);
1303 float WebView::GetTextZoomFactor() const
1305 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1308 float WebView::GetLoadProgressPercentage() const
1310 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1313 bool WebView::SetVisibility(bool visible)
1315 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1318 #undef GET_ENUM_STRING
1319 #undef GET_ENUM_VALUE
1321 } // namespace Internal
1323 } // namespace Toolkit