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-context.h>
24 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-form-repost-decision.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-settings.h>
27 #include <dali/devel-api/common/stage.h>
28 #include <dali/devel-api/scripting/enum-helper.h>
29 #include <dali/devel-api/scripting/scripting.h>
30 #include <dali/public-api/adaptor-framework/native-image-source.h>
31 #include <dali/public-api/object/type-registry-helper.h>
32 #include <dali/public-api/object/type-registry.h>
37 #include <dali-toolkit/devel-api/controls/control-devel.h>
38 #include <dali-toolkit/devel-api/controls/web-view/web-back-forward-list.h>
39 #include <dali-toolkit/devel-api/controls/web-view/web-context.h>
40 #include <dali-toolkit/devel-api/controls/web-view/web-cookie-manager.h>
41 #include <dali-toolkit/devel-api/controls/web-view/web-form-repost-decision.h>
42 #include <dali-toolkit/devel-api/controls/web-view/web-settings.h>
43 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
44 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
45 #include <dali-toolkit/public-api/image-loader/image.h>
46 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
58 return Toolkit::WebView::New();
62 DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create)
64 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url", STRING, URL )
65 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent", STRING, USER_AGENT )
66 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION )
67 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE )
68 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE )
69 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title", STRING, TITLE )
70 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled", BOOLEAN, VIDEO_HOLE_ENABLED )
71 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled", BOOLEAN, MOUSE_EVENTS_ENABLED )
72 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled", BOOLEAN, KEY_EVENTS_ENABLED )
73 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR )
74 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden", BOOLEAN, TILES_CLEARED_WHEN_HIDDEN )
75 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT, TILE_COVER_AREA_MULTIPLIER)
76 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient", BOOLEAN, CURSOR_ENABLED_BY_CLIENT )
77 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText", STRING, SELECTED_TEXT )
78 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "pageZoomFactor", FLOAT, PAGE_ZOOM_FACTOR )
79 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "textZoomFactor", FLOAT, TEXT_ZOOM_FACTOR )
80 DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "loadProgressPercentage", FLOAT, LOAD_PROGRESS_PERCENTAGE )
82 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadStarted", PAGE_LOAD_STARTED_SIGNAL )
83 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadInProgress", PAGE_LOAD_IN_PROGRESS_SIGNAL)
84 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadFinished", PAGE_LOAD_FINISHED_SIGNAL )
85 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadError", PAGE_LOAD_ERROR_SIGNAL )
86 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "scrollEdgeReached", SCROLL_EDGE_REACHED_SIGNAL )
87 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "urlChanged", URL_CHANGED_SIGNAL )
88 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "formRepostDecision", FORM_REPOST_DECISION_SIGNAL )
89 DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "frameRendered", FRAME_RENDERED_SIGNAL )
91 DALI_TYPE_REGISTRATION_END()
94 const std::string kEmptyString;
98 #define GET_ENUM_STRING(structName, inputExp) \
99 Scripting::GetLinearEnumerationName<Toolkit::WebView::structName::Type>(static_cast<Toolkit::WebView::structName::Type>(inputExp), structName##_TABLE, structName##_TABLE_COUNT)
101 #define GET_ENUM_VALUE(structName, inputExp, outputExp) \
102 Scripting::GetEnumerationProperty<Toolkit::WebView::structName::Type>(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp)
104 WebView::WebView(const std::string& locale, const std::string& timezoneId)
105 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
108 mWebViewSize(Stage::GetCurrent().GetSize()),
110 mPageLoadStartedSignal(),
111 mPageLoadFinishedSignal(),
112 mPageLoadErrorSignal(),
114 mVideoHoleEnabled(true),
115 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
116 mMouseEventsEnabled(true),
117 mKeyEventsEnabled(true)
119 mWebEngine = Dali::WebEngine::New();
121 // WebEngine is empty when it is not properly initialized.
124 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId);
128 WebView::WebView(int argc, char** argv)
129 : Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
132 mWebViewSize(Stage::GetCurrent().GetSize()),
134 mPageLoadStartedSignal(),
135 mPageLoadFinishedSignal(),
136 mPageLoadErrorSignal(),
138 mVideoHoleEnabled(true),
139 mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height),
140 mMouseEventsEnabled(true),
141 mKeyEventsEnabled(true)
143 mWebEngine = Dali::WebEngine::New();
145 // WebEngine is empty when it is not properly initialized.
148 mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv);
161 mWebEngine.Destroy();
165 Toolkit::WebView WebView::New()
167 WebView* impl = new WebView();
168 Toolkit::WebView handle = Toolkit::WebView(*impl);
174 Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId)
176 WebView* impl = new WebView(locale, timezoneId);
177 Toolkit::WebView handle = Toolkit::WebView(*impl);
183 Toolkit::WebView WebView::New(int argc, char** argv)
185 WebView* impl = new WebView(argc, argv);
186 Toolkit::WebView handle = Toolkit::WebView(*impl);
192 void WebView::OnInitialize()
196 self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
197 self.TouchedSignal().Connect(this, &WebView::OnTouchEvent);
198 self.HoveredSignal().Connect(this, &WebView::OnHoverEvent);
199 self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent);
200 Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &WebView::OnVisibilityChanged);
202 mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f));
203 mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f));
204 mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f));
205 mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
206 mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
207 mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea);
211 mWebEngine.PageLoadStartedSignal().Connect(this, &WebView::OnPageLoadStarted);
212 mWebEngine.PageLoadInProgressSignal().Connect(this, &WebView::OnPageLoadInProgress);
213 mWebEngine.PageLoadFinishedSignal().Connect(this, &WebView::OnPageLoadFinished);
214 mWebEngine.PageLoadErrorSignal().Connect(this, &WebView::OnPageLoadError);
215 mWebEngine.ScrollEdgeReachedSignal().Connect(this, &WebView::OnScrollEdgeReached);
216 mWebEngine.UrlChangedSignal().Connect(this, &WebView::OnUrlChanged);
217 mWebEngine.FormRepostDecisionSignal().Connect(this, &WebView::OnFormRepostDecision);
218 mWebEngine.FrameRenderedSignal().Connect(this, &WebView::OnFrameRendered);
220 mWebContext = std::unique_ptr<Dali::Toolkit::WebContext>(new WebContext(mWebEngine.GetContext()));
221 mWebCookieManager = std::unique_ptr<Dali::Toolkit::WebCookieManager>(new WebCookieManager(mWebEngine.GetCookieManager()));
222 mWebSettings = std::unique_ptr<Dali::Toolkit::WebSettings>(new WebSettings(mWebEngine.GetSettings()));
223 mWebBackForwardList = std::unique_ptr<Dali::Toolkit::WebBackForwardList>(new WebBackForwardList(mWebEngine.GetBackForwardList()));
227 Dali::Toolkit::WebSettings* WebView::GetSettings() const
229 return mWebSettings.get();
232 Dali::Toolkit::WebContext* WebView::GetContext() const
234 return mWebContext.get();
237 Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const
239 return mWebCookieManager.get();
242 Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
244 return mWebBackForwardList.get();
247 Dali::Toolkit::ImageView& WebView::GetFavicon()
251 Dali::PixelData pixelData = mWebEngine.GetFavicon();
252 mFaviconView = CreateImageView(pixelData);
257 void WebView::LoadUrl(const std::string& url)
262 Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
263 const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
264 mVisual = Toolkit::VisualFactory::Get().CreateVisual(
265 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
266 {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
270 // Clean up previously registered visual and add new one.
271 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
272 mWebEngine.LoadUrl(url);
275 if(mVideoHoleEnabled)
277 EnableBlendMode(false);
282 void WebView::LoadHtmlString(const std::string& htmlString)
286 Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
287 const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
288 mVisual = Toolkit::VisualFactory::Get().CreateVisual(
289 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
290 {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
294 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
295 mWebEngine.LoadHtmlString(htmlString);
298 if(mVideoHoleEnabled)
300 EnableBlendMode(false);
305 bool WebView::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
310 Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
311 const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
312 mVisual = Toolkit::VisualFactory::Get().CreateVisual(
313 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
314 {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
319 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
320 result = mWebEngine.LoadHtmlStringOverrideCurrentEntry(html, basicUri, unreachableUrl);
323 if(mVideoHoleEnabled)
325 EnableBlendMode(false);
330 bool WebView::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
335 Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource());
336 const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture);
337 mVisual = Toolkit::VisualFactory::Get().CreateVisual(
338 {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE},
339 {Toolkit::ImageVisual::Property::URL, nativeImageUrl}});
344 DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual);
345 result = mWebEngine.LoadContents(contents, contentSize, mimeType, encoding, baseUri);
348 if(mVideoHoleEnabled)
350 EnableBlendMode(false);
355 void WebView::Reload()
363 bool WebView::ReloadWithoutCache()
365 return mWebEngine ? mWebEngine.ReloadWithoutCache() : false;
368 void WebView::StopLoading()
372 mWebEngine.StopLoading();
376 void WebView::Suspend()
380 mWebEngine.Suspend();
384 void WebView::Resume()
392 void WebView::SuspendNetworkLoading()
396 mWebEngine.SuspendNetworkLoading();
400 void WebView::ResumeNetworkLoading()
404 mWebEngine.ResumeNetworkLoading();
408 bool WebView::AddCustomHeader(const std::string& name, const std::string& value)
410 return mWebEngine ? mWebEngine.AddCustomHeader(name, value) : false;
413 bool WebView::RemoveCustomHeader(const std::string& name)
415 return mWebEngine ? mWebEngine.RemoveCustomHeader(name) : false;
418 uint32_t WebView::StartInspectorServer(uint32_t port)
420 return mWebEngine ? mWebEngine.StartInspectorServer(port) : false;
423 bool WebView::StopInspectorServer()
425 return mWebEngine ? mWebEngine.StopInspectorServer() : false;
428 void WebView::ScrollBy(int deltaX, int deltaY)
432 mWebEngine.ScrollBy(deltaX, deltaY);
436 bool WebView::ScrollEdgeBy(int deltaX, int deltaY)
438 return mWebEngine ? mWebEngine.ScrollEdgeBy(deltaX, deltaY) : false;
441 bool WebView::CanGoForward()
443 return mWebEngine ? mWebEngine.CanGoForward() : false;
446 void WebView::GoForward()
450 mWebEngine.GoForward();
454 bool WebView::CanGoBack()
456 return mWebEngine ? mWebEngine.CanGoBack() : false;
459 void WebView::GoBack()
467 void WebView::EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler)
471 mWebEngine.EvaluateJavaScript(script, resultHandler);
475 void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler)
479 mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler);
483 void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback)
487 mWebEngine.RegisterJavaScriptAlertCallback(callback);
491 void WebView::JavaScriptAlertReply()
495 mWebEngine.JavaScriptAlertReply();
499 void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback)
503 mWebEngine.RegisterJavaScriptConfirmCallback(callback);
507 void WebView::JavaScriptConfirmReply(bool confirmed)
511 mWebEngine.JavaScriptConfirmReply(confirmed);
515 void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback)
519 mWebEngine.RegisterJavaScriptPromptCallback(callback);
523 void WebView::JavaScriptPromptReply(const std::string& result)
527 mWebEngine.JavaScriptPromptReply(result);
531 void WebView::ClearHistory()
535 mWebEngine.ClearHistory();
539 void WebView::ClearAllTilesResources()
543 mWebEngine.ClearAllTilesResources();
547 void WebView::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
551 mWebEngine.SetScaleFactor(scaleFactor, point);
555 float WebView::GetScaleFactor() const
557 return mWebEngine ? mWebEngine.GetScaleFactor() : 0.0f;
560 void WebView::ActivateAccessibility(bool activated)
564 mWebEngine.ActivateAccessibility(activated);
568 bool WebView::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
570 return mWebEngine ? mWebEngine.HighlightText(text, options, maxMatchCount) : false;
573 void WebView::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
577 mWebEngine.AddDynamicCertificatePath(host, certPath);
581 Dali::Toolkit::ImageView WebView::GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor)
583 Dali::Toolkit::ImageView imageView;
586 Dali::PixelData pixelData = mWebEngine.GetScreenshot(viewArea, scaleFactor);
587 imageView = CreateImageView(pixelData);
592 bool WebView::GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, Dali::Toolkit::WebView::WebViewScreenshotCapturedCallback callback)
594 mScreenshotCapturedCallback = callback;
595 return mWebEngine ? mWebEngine.GetScreenshotAsynchronously(viewArea, scaleFactor, std::bind(&WebView::OnScreenshotCaptured, this, std::placeholders::_1)) : false;
598 bool WebView::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
600 return mWebEngine ? mWebEngine.CheckVideoPlayingAsynchronously(callback) : false;
603 void WebView::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
607 mWebEngine.RegisterGeolocationPermissionCallback(callback);
611 void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/)
618 bool positionUsesAnchorPoint = self.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
619 Vector3 actorSize = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::SCALE);
620 Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
621 Vector2 screenPosition = self.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
623 Dali::Rect<int> displayArea;
624 displayArea.x = screenPosition.x - anchorPointOffSet.x;
625 displayArea.y = screenPosition.y - anchorPointOffSet.y;
626 displayArea.width = actorSize.x;
627 displayArea.height = actorSize.y;
629 Size displaySize = Size(displayArea.width, displayArea.height);
630 if(mWebViewSize != displaySize)
632 mWebViewSize = displaySize;
635 if(mWebViewArea != displayArea)
637 mWebViewArea = displayArea;
638 mWebEngine.UpdateDisplayArea(mWebViewArea);
642 void WebView::EnableVideoHole(bool enabled)
644 mVideoHoleEnabled = enabled;
646 EnableBlendMode(!mVideoHoleEnabled);
650 mWebEngine.EnableVideoHole(mVideoHoleEnabled);
654 void WebView::EnableBlendMode(bool blendEnabled)
657 for(uint32_t i = 0; i < self.GetRendererCount(); i++)
659 Dali::Renderer render = self.GetRendererAt(i);
660 render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF);
664 Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel)
666 std::string url = Dali::Toolkit::Image::GenerateUrl(pixel);
667 Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url);
668 imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
672 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal()
674 return mPageLoadStartedSignal;
677 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadInProgressSignal()
679 return mPageLoadInProgressSignal;
682 Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadFinishedSignal()
684 return mPageLoadFinishedSignal;
687 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& WebView::PageLoadErrorSignal()
689 return mPageLoadErrorSignal;
692 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& WebView::ScrollEdgeReachedSignal()
694 return mScrollEdgeReachedSignal;
697 Dali::Toolkit::WebView::WebViewUrlChangedSignalType& WebView::UrlChangedSignal()
699 return mUrlChangedSignal;
702 Dali::Toolkit::WebView::WebViewFormRepostDecisionSignalType& WebView::FormRepostDecisionSignal()
704 return mFormRepostDecisionSignal;
707 Dali::Toolkit::WebView::WebViewFrameRenderedSignalType& WebView::FrameRenderedSignal()
709 return mFrameRenderedSignal;
712 void WebView::OnPageLoadStarted(const std::string& url)
714 if(!mPageLoadStartedSignal.Empty())
716 Dali::Toolkit::WebView handle(GetOwner());
717 mPageLoadStartedSignal.Emit(handle, url);
721 void WebView::OnPageLoadInProgress(const std::string& url)
723 if(!mPageLoadInProgressSignal.Empty())
725 Dali::Toolkit::WebView handle(GetOwner());
726 mPageLoadInProgressSignal.Emit(handle, url);
730 void WebView::OnPageLoadFinished(const std::string& url)
732 if(!mPageLoadFinishedSignal.Empty())
734 Dali::Toolkit::WebView handle(GetOwner());
735 mPageLoadFinishedSignal.Emit(handle, url);
739 void WebView::OnPageLoadError(const std::string& url, int errorCode)
741 if(!mPageLoadErrorSignal.Empty())
743 Dali::Toolkit::WebView handle(GetOwner());
744 mPageLoadErrorSignal.Emit(handle, url, static_cast<Toolkit::WebView::LoadErrorCode>(errorCode));
748 void WebView::OnScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge)
750 if(!mScrollEdgeReachedSignal.Empty())
752 Dali::Toolkit::WebView handle(GetOwner());
753 mScrollEdgeReachedSignal.Emit(handle, edge);
757 void WebView::OnUrlChanged(const std::string& url)
759 if(!mUrlChangedSignal.Empty())
761 Dali::Toolkit::WebView handle(GetOwner());
762 mUrlChangedSignal.Emit(handle, url);
766 void WebView::OnFormRepostDecision(std::shared_ptr<Dali::WebEngineFormRepostDecision> decision)
768 if(!mFormRepostDecisionSignal.Empty())
770 Dali::Toolkit::WebView handle(GetOwner());
771 std::shared_ptr<Dali::Toolkit::WebFormRepostDecision> repostDecision(new Dali::Toolkit::WebFormRepostDecision(decision));
772 mFormRepostDecisionSignal.Emit(handle, std::move(repostDecision));
776 void WebView::OnFrameRendered()
778 if(!mFrameRenderedSignal.Empty())
780 Dali::Toolkit::WebView handle(GetOwner());
781 mFrameRenderedSignal.Emit(handle);
785 void WebView::OnVisibilityChanged(Actor actor, bool isVisible, Dali::DevelActor::VisibilityChange::Type type)
787 if(type == Dali::DevelActor::VisibilityChange::Type::SELF)
789 SetVisibility(isVisible);
793 void WebView::OnScreenshotCaptured(Dali::PixelData pixel)
795 if(mScreenshotCapturedCallback)
797 Dali::Toolkit::ImageView imageView = CreateImageView(pixel);
798 mScreenshotCapturedCallback(imageView);
802 bool WebView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
804 Dali::BaseHandle handle(object);
806 bool connected = false;
807 Toolkit::WebView webView = Toolkit::WebView::DownCast(handle);
809 if(0 == strcmp(signalName.c_str(), PAGE_LOAD_STARTED_SIGNAL))
811 webView.PageLoadStartedSignal().Connect(tracker, functor);
814 else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_IN_PROGRESS_SIGNAL))
816 webView.PageLoadInProgressSignal().Connect(tracker, functor);
819 else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_FINISHED_SIGNAL))
821 webView.PageLoadFinishedSignal().Connect(tracker, functor);
824 else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_ERROR_SIGNAL))
826 webView.PageLoadErrorSignal().Connect(tracker, functor);
829 else if(0 == strcmp(signalName.c_str(), SCROLL_EDGE_REACHED_SIGNAL))
831 webView.ScrollEdgeReachedSignal().Connect(tracker, functor);
834 else if(0 == strcmp(signalName.c_str(), URL_CHANGED_SIGNAL))
836 webView.UrlChangedSignal().Connect(tracker, functor);
839 else if(0 == strcmp(signalName.c_str(), FORM_REPOST_DECISION_SIGNAL))
841 webView.FormRepostDecisionSignal().Connect(tracker, functor);
844 else if(0 == strcmp(signalName.c_str(), FRAME_RENDERED_SIGNAL))
846 webView.FrameRenderedSignal().Connect(tracker, functor);
853 Vector3 WebView::GetNaturalSize()
857 Vector2 rendererNaturalSize;
858 mVisual.GetNaturalSize(rendererNaturalSize);
859 return Vector3(rendererNaturalSize);
862 return Vector3(mWebViewSize);
865 void WebView::OnSceneConnection(int depth)
867 Control::OnSceneConnection(depth);
869 EnableBlendMode(!mVideoHoleEnabled);
872 void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
874 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
878 WebView& impl = GetImpl(webView);
881 case Toolkit::WebView::Property::URL:
890 case Toolkit::WebView::Property::USER_AGENT:
895 impl.SetUserAgent(input);
899 case Toolkit::WebView::Property::SCROLL_POSITION:
904 impl.SetScrollPosition(input.x, input.y);
908 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
913 impl.EnableVideoHole(input);
917 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
922 impl.EnableMouseEvents(input);
926 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
931 impl.EnableKeyEvents(input);
935 case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR:
940 impl.SetDocumentBackgroundColor(input);
944 case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN:
949 impl.ClearTilesWhenHidden(input);
953 case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER:
958 impl.SetTileCoverAreaMultiplier(input);
962 case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT:
967 impl.EnableCursorByClient(input);
971 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
976 impl.SetPageZoomFactor(input);
980 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
985 impl.SetTextZoomFactor(input);
995 Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex)
997 Property::Value value;
999 Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object));
1003 WebView& impl = GetImpl(webView);
1004 switch(propertyIndex)
1006 case Toolkit::WebView::Property::URL:
1011 case Toolkit::WebView::Property::USER_AGENT:
1013 value = impl.GetUserAgent();
1016 case Toolkit::WebView::Property::SCROLL_POSITION:
1018 value = impl.GetScrollPosition();
1021 case Toolkit::WebView::Property::SCROLL_SIZE:
1023 value = impl.GetScrollSize();
1026 case Toolkit::WebView::Property::CONTENT_SIZE:
1028 value = impl.GetContentSize();
1031 case Toolkit::WebView::Property::TITLE:
1033 value = impl.GetTitle();
1036 case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED:
1038 value = impl.mVideoHoleEnabled;
1041 case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED:
1043 value = impl.mMouseEventsEnabled;
1046 case Toolkit::WebView::Property::KEY_EVENTS_ENABLED:
1048 value = impl.mKeyEventsEnabled;
1051 case Toolkit::WebView::Property::SELECTED_TEXT:
1053 value = impl.GetSelectedText();
1056 case Toolkit::WebView::Property::PAGE_ZOOM_FACTOR:
1058 value = impl.GetPageZoomFactor();
1061 case Toolkit::WebView::Property::TEXT_ZOOM_FACTOR:
1063 value = impl.GetTextZoomFactor();
1066 case Toolkit::WebView::Property::LOAD_PROGRESS_PERCENTAGE:
1068 value = impl.GetLoadProgressPercentage();
1079 bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch)
1081 bool result = false;
1085 result = mWebEngine.SendTouchEvent(touch);
1090 bool WebView::OnKeyEvent(const Dali::KeyEvent& event)
1092 bool result = false;
1096 result = mWebEngine.SendKeyEvent(event);
1101 bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover)
1103 bool result = false;
1106 result = mWebEngine.SendHoverEvent(hover);
1111 bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel)
1113 bool result = false;
1116 result = mWebEngine.SendWheelEvent(wheel);
1121 void WebView::OnKeyInputFocusGained()
1125 mWebEngine.SetFocus(true);
1128 EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last.
1131 void WebView::OnKeyInputFocusLost()
1135 mWebEngine.SetFocus(false);
1138 EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last.
1141 void WebView::SetScrollPosition(int x, int y)
1145 mWebEngine.SetScrollPosition(x, y);
1149 Dali::Vector2 WebView::GetScrollPosition() const
1151 return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO;
1154 Dali::Vector2 WebView::GetScrollSize() const
1156 return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO;
1159 Dali::Vector2 WebView::GetContentSize() const
1161 return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO;
1164 std::string WebView::GetTitle() const
1166 return mWebEngine ? mWebEngine.GetTitle() : kEmptyString;
1169 void WebView::SetDocumentBackgroundColor(Dali::Vector4 color)
1173 mWebEngine.SetDocumentBackgroundColor(color);
1177 void WebView::ClearTilesWhenHidden(bool cleared)
1181 mWebEngine.ClearTilesWhenHidden(cleared);
1185 void WebView::SetTileCoverAreaMultiplier(float multiplier)
1189 mWebEngine.SetTileCoverAreaMultiplier(multiplier);
1193 void WebView::EnableCursorByClient(bool enabled)
1197 mWebEngine.EnableCursorByClient(enabled);
1201 std::string WebView::GetSelectedText() const
1203 return mWebEngine ? mWebEngine.GetSelectedText() : kEmptyString;
1206 const std::string& WebView::GetUserAgent() const
1208 return mWebEngine ? mWebEngine.GetUserAgent() : kEmptyString;
1211 void WebView::SetUserAgent(const std::string& userAgent)
1215 mWebEngine.SetUserAgent(userAgent);
1219 void WebView::EnableMouseEvents(bool enabled)
1223 mMouseEventsEnabled = enabled;
1224 mWebEngine.EnableMouseEvents(enabled);
1228 void WebView::EnableKeyEvents(bool enabled)
1232 mKeyEventsEnabled = enabled;
1233 mWebEngine.EnableKeyEvents(enabled);
1237 void WebView::SetPageZoomFactor(float zoomFactor)
1241 mWebEngine.SetPageZoomFactor(zoomFactor);
1245 float WebView::GetPageZoomFactor() const
1247 return mWebEngine ? mWebEngine.GetPageZoomFactor() : 0.0f;
1250 void WebView::SetTextZoomFactor(float zoomFactor)
1254 mWebEngine.SetTextZoomFactor(zoomFactor);
1258 float WebView::GetTextZoomFactor() const
1260 return mWebEngine ? mWebEngine.GetTextZoomFactor() : 0.0f;
1263 float WebView::GetLoadProgressPercentage() const
1265 return mWebEngine ? mWebEngine.GetLoadProgressPercentage() : 0.0f;
1268 bool WebView::SetVisibility(bool visible)
1270 return mWebEngine ? mWebEngine.SetVisibility(visible) : false;
1273 #undef GET_ENUM_STRING
1274 #undef GET_ENUM_VALUE
1276 } // namespace Internal
1278 } // namespace Toolkit