X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fweb-view%2Fweb-view-impl.cpp;h=c4bf4e9da4186280399ac9a5c65f803ff268cc8f;hp=7da5f9d64393cd48fb6cc0563ca3a4dc71809584;hb=3890e8d5e0d6c13b7a20538b0de12125946f6d87;hpb=6f14d95105863d879b5888ad4eb964db9b70f9ff diff --git a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp old mode 100644 new mode 100755 index 7da5f9d..c4bf4e9 --- a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,79 +19,163 @@ #include "web-view-impl.h" // EXTERNAL INCLUDES -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include +#include +#include // INTERNAL INCLUDES #include +#include +#include +#include +#include +#include #include +#include +#include namespace Dali { - namespace Toolkit { - namespace Internal { - namespace { - BaseHandle Create() { return Toolkit::WebView::New(); } -DALI_TYPE_REGISTRATION_BEGIN( Toolkit::WebView, Toolkit::Control, Create ); +// clang-format off +DALI_TYPE_REGISTRATION_BEGIN(Toolkit::WebView, Toolkit::Control, Create) + +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "url", STRING, URL ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "userAgent", STRING, USER_AGENT ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollPosition", VECTOR2, SCROLL_POSITION ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "scrollSize", VECTOR2, SCROLL_SIZE ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "contentSize", VECTOR2, CONTENT_SIZE ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "title", STRING, TITLE ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "videoHoleEnabled", BOOLEAN, VIDEO_HOLE_ENABLED ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "mouseEventsEnabled", BOOLEAN, MOUSE_EVENTS_ENABLED ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "keyEventsEnabled", BOOLEAN, KEY_EVENTS_ENABLED ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "documentBackgroundColor", VECTOR4, DOCUMENT_BACKGROUND_COLOR ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tilesClearedWhenHidden", BOOLEAN, TILES_CLEARED_WHEN_HIDDEN ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "tileCoverAreaMultiplier", FLOAT, TILE_COVER_AREA_MULTIPLIER) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "cursorEnabledByClient", BOOLEAN, CURSOR_ENABLED_BY_CLIENT ) +DALI_PROPERTY_REGISTRATION(Toolkit, WebView, "selectedText", STRING, SELECTED_TEXT ) + +DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadStarted", PAGE_LOAD_STARTED_SIGNAL ) +DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadInProgress", PAGE_LOAD_IN_PROGRESS_SIGNAL) +DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadFinished", PAGE_LOAD_FINISHED_SIGNAL ) +DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "pageLoadError", PAGE_LOAD_ERROR_SIGNAL ) +DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "scrollEdgeReached", SCROLL_EDGE_REACHED_SIGNAL ) +DALI_SIGNAL_REGISTRATION(Toolkit, WebView, "urlChanged", URL_CHANGED_SIGNAL ) -DALI_PROPERTY_REGISTRATION( Toolkit, WebView, "url", STRING, URL ); +DALI_TYPE_REGISTRATION_END() +// clang-format on -DALI_SIGNAL_REGISTRATION( Toolkit, WebView, "pageLoadStarted", PAGE_LOAD_STARTED_SIGNAL ); -DALI_SIGNAL_REGISTRATION( Toolkit, WebView, "pageLoadFinished", PAGE_LOAD_FINISHED_SIGNAL ); +const std::string kEmptyString; -DALI_TYPE_REGISTRATION_END() +} // namespace + +#define GET_ENUM_STRING(structName, inputExp) \ + Scripting::GetLinearEnumerationName(static_cast(inputExp), structName##_TABLE, structName##_TABLE_COUNT) -} // anonymous namepsace +#define GET_ENUM_VALUE(structName, inputExp, outputExp) \ + Scripting::GetEnumerationProperty(inputExp, structName##_TABLE, structName##_TABLE_COUNT, outputExp) -WebView::WebView( const std::string& locale, const std::string& timezoneId ) -: Control( ControlBehaviour( ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS ) ), +WebView::WebView(const std::string& locale, const std::string& timezoneId) +: Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)), mUrl(), - mWebViewSize( Stage::GetCurrent().GetSize() ) + mVisual(), + mWebViewSize(Stage::GetCurrent().GetSize()), + mWebEngine(), + mPageLoadStartedSignal(), + mPageLoadFinishedSignal(), + mPageLoadErrorSignal(), + mUrlChangedSignal(), + mVideoHoleEnabled(true), + mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height), + mMouseEventsEnabled(true), + mKeyEventsEnabled(true) { mWebEngine = Dali::WebEngine::New(); - if ( mWebEngine ) + + // WebEngine is empty when it is not properly initialized. + if(mWebEngine) + { + mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, locale, timezoneId); + } +} + +WebView::WebView(int argc, char** argv) +: Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)), + mUrl(), + mVisual(), + mWebViewSize(Stage::GetCurrent().GetSize()), + mWebEngine(), + mPageLoadStartedSignal(), + mPageLoadFinishedSignal(), + mPageLoadErrorSignal(), + mUrlChangedSignal(), + mVideoHoleEnabled(true), + mWebViewArea(0, 0, mWebViewSize.width, mWebViewSize.height), + mMouseEventsEnabled(true), + mKeyEventsEnabled(true) +{ + mWebEngine = Dali::WebEngine::New(); + + // WebEngine is empty when it is not properly initialized. + if(mWebEngine) { - mWebEngine.Create( mWebViewSize.width, mWebViewSize.height, locale, timezoneId ); + mWebEngine.Create(mWebViewSize.width, mWebViewSize.height, argc, argv); } } WebView::WebView() -: WebView( "", "" ) +: WebView("", "") { } WebView::~WebView() { + if(mWebEngine) + { + mWebEngine.Destroy(); + } } Toolkit::WebView WebView::New() { - WebView* impl = new WebView(); - Toolkit::WebView handle = Toolkit::WebView( *impl ); + WebView* impl = new WebView(); + Toolkit::WebView handle = Toolkit::WebView(*impl); + + impl->Initialize(); + return handle; +} + +Toolkit::WebView WebView::New(const std::string& locale, const std::string& timezoneId) +{ + WebView* impl = new WebView(locale, timezoneId); + Toolkit::WebView handle = Toolkit::WebView(*impl); impl->Initialize(); return handle; } -Toolkit::WebView WebView::New( const std::string& locale, const std::string& timezoneId ) +Toolkit::WebView WebView::New(int argc, char** argv) { - WebView* impl = new WebView( locale, timezoneId ); - Toolkit::WebView handle = Toolkit::WebView( *impl ); + WebView* impl = new WebView(argc, argv); + Toolkit::WebView handle = Toolkit::WebView(*impl); impl->Initialize(); return handle; @@ -99,56 +183,120 @@ Toolkit::WebView WebView::New( const std::string& locale, const std::string& tim void WebView::OnInitialize() { - Self().SetKeyboardFocusable( true ); - Self().TouchSignal().Connect( this, &WebView::OnTouchEvent ); + Actor self = Self(); + + self.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + self.TouchedSignal().Connect(this, &WebView::OnTouchEvent); + self.HoveredSignal().Connect(this, &WebView::OnHoverEvent); + self.WheelEventSignal().Connect(this, &WebView::OnWheelEvent); + + mPositionUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_POSITION, StepCondition(1.0f, 1.0f)); + mSizeUpdateNotification = self.AddPropertyNotification(Actor::Property::SIZE, StepCondition(1.0f, 1.0f)); + mScaleUpdateNotification = self.AddPropertyNotification(Actor::Property::WORLD_SCALE, StepCondition(0.1f, 1.0f)); + mPositionUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea); + mSizeUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea); + mScaleUpdateNotification.NotifySignal().Connect(this, &WebView::UpdateDisplayArea); + + if(mWebEngine) + { + mWebEngine.PageLoadStartedSignal().Connect(this, &WebView::OnPageLoadStarted); + mWebEngine.PageLoadInProgressSignal().Connect(this, &WebView::OnPageLoadInProgress); + mWebEngine.PageLoadFinishedSignal().Connect(this, &WebView::OnPageLoadFinished); + mWebEngine.PageLoadErrorSignal().Connect(this, &WebView::OnPageLoadError); + mWebEngine.ScrollEdgeReachedSignal().Connect(this, &WebView::OnScrollEdgeReached); + mWebEngine.UrlChangedSignal().Connect(this, &WebView::OnUrlChanged); + + mWebContext = std::unique_ptr(new WebContext(mWebEngine.GetContext())); + mWebCookieManager = std::unique_ptr(new WebCookieManager(mWebEngine.GetCookieManager())); + mWebSettings = std::unique_ptr(new WebSettings(mWebEngine.GetSettings())); + mWebBackForwardList = std::unique_ptr(new WebBackForwardList(mWebEngine.GetBackForwardList())); + } +} + +Dali::Toolkit::WebSettings* WebView::GetSettings() const +{ + return mWebSettings.get(); +} + +Dali::Toolkit::WebContext* WebView::GetContext() const +{ + return mWebContext.get(); +} + +Dali::Toolkit::WebCookieManager* WebView::GetCookieManager() const +{ + return mWebCookieManager.get(); +} + +Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const +{ + return mWebBackForwardList.get(); +} - if ( mWebEngine ) +Dali::Toolkit::ImageView& WebView::GetFavicon() +{ + if(mWebEngine) { - mWebEngine.PageLoadStartedSignal().Connect( this, &WebView::OnPageLoadStarted ); - mWebEngine.PageLoadFinishedSignal().Connect( this, &WebView::OnPageLoadFinished ); + Dali::PixelData pixelData = mWebEngine.GetFavicon(); + std::string url = Dali::Toolkit::Image::GenerateUrl(pixelData); + mFaviconView = Dali::Toolkit::ImageView::New(url); + mFaviconView.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS); + mFaviconView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixelData.GetWidth(), pixelData.GetHeight())); } + return mFaviconView; } -void WebView::LoadUrl( const std::string& url ) +void WebView::LoadUrl(const std::string& url) { mUrl = url; - if ( mWebEngine ) + if(mWebEngine) { - Dali::Image image = Dali::NativeImage::New( *mWebEngine.GetNativeImageSource() ); - mVisual = Toolkit::VisualFactory::Get().CreateVisual( image ); + Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource()); + const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture); + mVisual = Toolkit::VisualFactory::Get().CreateVisual( + {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, + {Toolkit::ImageVisual::Property::URL, nativeImageUrl}}); - if ( mVisual ) + if(mVisual) { // Clean up previously registered visual and add new one. - DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual ); - mWebEngine.LoadUrl( url ); + DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual); + mWebEngine.LoadUrl(url); } - } -} -const std::string& WebView::GetUrl() -{ - return mWebEngine ? mWebEngine.GetUrl() : mUrl; + if(mVideoHoleEnabled) + { + EnableBlendMode(false); + } + } } -void WebView::LoadHTMLString( const std::string& htmlString ) +void WebView::LoadHtmlString(const std::string& htmlString) { - if ( mWebEngine ) + if(mWebEngine) { - Dali::Image image = Dali::NativeImage::New( *mWebEngine.GetNativeImageSource() ); - mVisual = Toolkit::VisualFactory::Get().CreateVisual( image ); + Texture texture = Dali::Texture::New(*mWebEngine.GetNativeImageSource()); + const std::string nativeImageUrl = Dali::Toolkit::TextureManager::AddTexture(texture); + mVisual = Toolkit::VisualFactory::Get().CreateVisual( + {{Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE}, + {Toolkit::ImageVisual::Property::URL, nativeImageUrl}}); - if ( mVisual ) + if(mVisual) { - DevelControl::RegisterVisual( *this, Toolkit::WebView::Property::URL, mVisual ); - mWebEngine.LoadHTMLString( htmlString ); + DevelControl::RegisterVisual(*this, Toolkit::WebView::Property::URL, mVisual); + mWebEngine.LoadHtmlString(htmlString); + } + + if(mVideoHoleEnabled) + { + EnableBlendMode(false); } } } void WebView::Reload() { - if ( mWebEngine ) + if(mWebEngine) { mWebEngine.Reload(); } @@ -156,12 +304,36 @@ void WebView::Reload() void WebView::StopLoading() { - if ( mWebEngine ) + if(mWebEngine) { mWebEngine.StopLoading(); } } +void WebView::Suspend() +{ + if(mWebEngine) + { + mWebEngine.Suspend(); + } +} + +void WebView::Resume() +{ + if(mWebEngine) + { + mWebEngine.Resume(); + } +} + +void WebView::ScrollBy(int deltaX, int deltaY) +{ + if(mWebEngine) + { + mWebEngine.ScrollBy(deltaX, deltaY); + } +} + bool WebView::CanGoForward() { return mWebEngine ? mWebEngine.CanGoForward() : false; @@ -169,7 +341,7 @@ bool WebView::CanGoForward() void WebView::GoForward() { - if ( mWebEngine ) + if(mWebEngine) { mWebEngine.GoForward(); } @@ -182,95 +354,264 @@ bool WebView::CanGoBack() void WebView::GoBack() { - if ( mWebEngine ) + if(mWebEngine) { mWebEngine.GoBack(); } } -void WebView::EvaluateJavaScript( const std::string& script ) +void WebView::EvaluateJavaScript(const std::string& script, std::function resultHandler) +{ + if(mWebEngine) + { + mWebEngine.EvaluateJavaScript(script, resultHandler); + } +} + +void WebView::AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function handler) +{ + if(mWebEngine) + { + mWebEngine.AddJavaScriptMessageHandler(exposedObjectName, handler); + } +} + +void WebView::RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback) +{ + if(mWebEngine) + { + mWebEngine.RegisterJavaScriptAlertCallback(callback); + } +} + +void WebView::JavaScriptAlertReply() { - if ( mWebEngine ) + if(mWebEngine) { - mWebEngine.EvaluateJavaScript( script ); + mWebEngine.JavaScriptAlertReply(); } } -void WebView::AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > callback ) +void WebView::RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback) { - if ( mWebEngine ) + if(mWebEngine) { - mWebEngine.AddJavaScriptInterface( exposedObjectName, jsFunctionName, callback ); + mWebEngine.RegisterJavaScriptConfirmCallback(callback); } } -void WebView::RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName ) +void WebView::JavaScriptConfirmReply(bool confirmed) { - if ( mWebEngine ) + if(mWebEngine) { - mWebEngine.RemoveJavascriptInterface( exposedObjectName, jsFunctionName ); + mWebEngine.JavaScriptConfirmReply(confirmed); + } +} + +void WebView::RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback) +{ + if(mWebEngine) + { + mWebEngine.RegisterJavaScriptPromptCallback(callback); + } +} + +void WebView::JavaScriptPromptReply(const std::string& result) +{ + if(mWebEngine) + { + mWebEngine.JavaScriptPromptReply(result); } } void WebView::ClearHistory() { - if ( mWebEngine ) + if(mWebEngine) { mWebEngine.ClearHistory(); } } -void WebView::ClearCache() +void WebView::UpdateDisplayArea(Dali::PropertyNotification& /*source*/) { - if ( mWebEngine ) + if(!mWebEngine) + return; + + Actor self(Self()); + + bool positionUsesAnchorPoint = self.GetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT); + Vector3 actorSize = self.GetCurrentProperty(Actor::Property::SIZE) * self.GetCurrentProperty(Actor::Property::SCALE); + Vector3 anchorPointOffSet = actorSize * (positionUsesAnchorPoint ? self.GetCurrentProperty(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT); + Vector2 screenPosition = self.GetProperty(Actor::Property::SCREEN_POSITION); + + Dali::Rect displayArea; + displayArea.x = screenPosition.x - anchorPointOffSet.x; + displayArea.y = screenPosition.y - anchorPointOffSet.y; + displayArea.width = actorSize.x; + displayArea.height = actorSize.y; + + Size displaySize = Size(displayArea.width, displayArea.height); + if(mWebViewSize != displaySize) + { + mWebViewSize = displaySize; + } + + if(mWebViewArea != displayArea) { - mWebEngine.ClearCache(); + mWebViewArea = displayArea; + mWebEngine.UpdateDisplayArea(mWebViewArea); } } -Dali::Toolkit::WebView::WebViewSignalType& WebView::PageLoadStartedSignal() +void WebView::EnableVideoHole(bool enabled) +{ + mVideoHoleEnabled = enabled; + + EnableBlendMode(!mVideoHoleEnabled); + + if(mWebEngine) + { + mWebEngine.EnableVideoHole(mVideoHoleEnabled); + } +} + +void WebView::EnableBlendMode(bool blendEnabled) +{ + Actor self = Self(); + for(uint32_t i = 0; i < self.GetRendererCount(); i++) + { + Dali::Renderer render = self.GetRendererAt(i); + render.SetProperty(Renderer::Property::BLEND_MODE, blendEnabled ? BlendMode::ON : BlendMode::OFF); + } +} + +void WebView::ClearAllTilesResources() +{ + if(mWebEngine) + { + mWebEngine.ClearAllTilesResources(); + } +} + +Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadStartedSignal() { return mPageLoadStartedSignal; } -Dali::Toolkit::WebView::WebViewSignalType& WebView::PageLoadFinishedSignal() +Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadInProgressSignal() +{ + return mPageLoadInProgressSignal; +} + +Dali::Toolkit::WebView::WebViewPageLoadSignalType& WebView::PageLoadFinishedSignal() { return mPageLoadFinishedSignal; } -void WebView::OnPageLoadStarted( const std::string& url ) +Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& WebView::PageLoadErrorSignal() { - if( !mPageLoadStartedSignal.Empty() ) + return mPageLoadErrorSignal; +} + +Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& WebView::ScrollEdgeReachedSignal() +{ + return mScrollEdgeReachedSignal; +} + +Dali::Toolkit::WebView::WebViewUrlChangedSignalType& WebView::UrlChangedSignal() +{ + return mUrlChangedSignal; +} + +void WebView::OnPageLoadStarted(const std::string& url) +{ + if(!mPageLoadStartedSignal.Empty()) { - Dali::Toolkit::WebView handle( GetOwner() ); - mPageLoadStartedSignal.Emit( handle, url ); + Dali::Toolkit::WebView handle(GetOwner()); + mPageLoadStartedSignal.Emit(handle, url); } } -void WebView::OnPageLoadFinished( const std::string& url ) +void WebView::OnPageLoadInProgress(const std::string& url) { - if( !mPageLoadFinishedSignal.Empty() ) + if(!mPageLoadInProgressSignal.Empty()) { - Dali::Toolkit::WebView handle( GetOwner() ); - mPageLoadFinishedSignal.Emit( handle, url ); + Dali::Toolkit::WebView handle(GetOwner()); + mPageLoadInProgressSignal.Emit(handle, url); } } -bool WebView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) +void WebView::OnPageLoadFinished(const std::string& url) { - Dali::BaseHandle handle( object ); + if(!mPageLoadFinishedSignal.Empty()) + { + Dali::Toolkit::WebView handle(GetOwner()); + mPageLoadFinishedSignal.Emit(handle, url); + } +} + +void WebView::OnPageLoadError(const std::string& url, int errorCode) +{ + if(!mPageLoadErrorSignal.Empty()) + { + Dali::Toolkit::WebView handle(GetOwner()); + mPageLoadErrorSignal.Emit(handle, url, static_cast(errorCode)); + } +} - bool connected = false; - Toolkit::WebView webView = Toolkit::WebView::DownCast( handle ); +void WebView::OnScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge) +{ + if(!mScrollEdgeReachedSignal.Empty()) + { + Dali::Toolkit::WebView handle(GetOwner()); + mScrollEdgeReachedSignal.Emit(handle, edge); + } +} - if( 0 == strcmp( signalName.c_str(), PAGE_LOAD_STARTED_SIGNAL ) ) +void WebView::OnUrlChanged(const std::string& url) +{ + if(!mUrlChangedSignal.Empty()) + { + Dali::Toolkit::WebView handle(GetOwner()); + mUrlChangedSignal.Emit(handle, url); + } +} + +bool WebView::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor) +{ + Dali::BaseHandle handle(object); + + bool connected = false; + Toolkit::WebView webView = Toolkit::WebView::DownCast(handle); + + if(0 == strcmp(signalName.c_str(), PAGE_LOAD_STARTED_SIGNAL)) + { + webView.PageLoadStartedSignal().Connect(tracker, functor); + connected = true; + } + else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_IN_PROGRESS_SIGNAL)) + { + webView.PageLoadInProgressSignal().Connect(tracker, functor); + connected = true; + } + else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_FINISHED_SIGNAL)) + { + webView.PageLoadFinishedSignal().Connect(tracker, functor); + connected = true; + } + else if(0 == strcmp(signalName.c_str(), PAGE_LOAD_ERROR_SIGNAL)) + { + webView.PageLoadErrorSignal().Connect(tracker, functor); + connected = true; + } + else if(0 == strcmp(signalName.c_str(), SCROLL_EDGE_REACHED_SIGNAL)) { - webView.PageLoadStartedSignal().Connect( tracker, functor ); + webView.ScrollEdgeReachedSignal().Connect(tracker, functor); connected = true; } - else if( 0 == strcmp( signalName.c_str(), PAGE_LOAD_FINISHED_SIGNAL ) ) + else if(0 == strcmp(signalName.c_str(), URL_CHANGED_SIGNAL)) { - webView.PageLoadFinishedSignal().Connect( tracker, functor ); + webView.UrlChangedSignal().Connect(tracker, functor); connected = true; } @@ -279,46 +620,119 @@ bool WebView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* t Vector3 WebView::GetNaturalSize() { - if( mVisual ) + if(mVisual) { Vector2 rendererNaturalSize; - mVisual.GetNaturalSize( rendererNaturalSize ); - return Vector3( rendererNaturalSize ); + mVisual.GetNaturalSize(rendererNaturalSize); + return Vector3(rendererNaturalSize); } - return Vector3( mWebViewSize ); + return Vector3(mWebViewSize); } -void WebView::OnRelayout( const Vector2& size, RelayoutContainer& container ) +void WebView::OnSceneConnection(int depth) { - Control::OnRelayout( size, container ); + Control::OnSceneConnection(depth); - if( size.width > 0 && size.height > 0 && mWebViewSize != size ) - { - mWebViewSize = size; - - if( mWebEngine ) - { - mWebEngine.SetSize( size.width, size.height ); - } - } + EnableBlendMode(!mVideoHoleEnabled); } -void WebView::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ) +void WebView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value) { - Toolkit::WebView webView = Toolkit::WebView::DownCast( Dali::BaseHandle( object ) ); + Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object)); - if( webView ) + if(webView) { - WebView& impl = GetImpl( webView ); - switch( index ) + WebView& impl = GetImpl(webView); + switch(index) { case Toolkit::WebView::Property::URL: { std::string url; - if( value.Get( url ) ) + if(value.Get(url)) + { + impl.LoadUrl(url); + } + break; + } + case Toolkit::WebView::Property::USER_AGENT: + { + std::string input; + if(value.Get(input)) + { + impl.SetUserAgent(input); + } + break; + } + case Toolkit::WebView::Property::SCROLL_POSITION: + { + Vector2 input; + if(value.Get(input)) + { + impl.SetScrollPosition(input.x, input.y); + } + break; + } + case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED: + { + bool input; + if(value.Get(input)) + { + impl.EnableVideoHole(input); + } + break; + } + case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED: + { + bool input; + if(value.Get(input)) + { + impl.EnableMouseEvents(input); + } + break; + } + case Toolkit::WebView::Property::KEY_EVENTS_ENABLED: + { + bool input; + if(value.Get(input)) + { + impl.EnableKeyEvents(input); + } + break; + } + case Toolkit::WebView::Property::DOCUMENT_BACKGROUND_COLOR: + { + Vector4 input; + if(value.Get(input)) + { + impl.SetDocumentBackgroundColor(input); + } + break; + } + case Toolkit::WebView::Property::TILES_CLEARED_WHEN_HIDDEN: + { + bool input; + if(value.Get(input)) + { + impl.ClearTilesWhenHidden(input); + } + break; + } + case Toolkit::WebView::Property::TILE_COVER_AREA_MULTIPLIER: + { + float input; + if(value.Get(input)) { - impl.LoadUrl( url ); + impl.SetTileCoverAreaMultiplier(input); + } + break; + } + case Toolkit::WebView::Property::CURSOR_ENABLED_BY_CLIENT: + { + bool input; + if(value.Get(input)) + { + impl.EnableCursorByClient(input); } break; } @@ -326,50 +740,236 @@ void WebView::SetProperty( BaseObject* object, Property::Index index, const Prop } } -Property::Value WebView::GetProperty( BaseObject* object, Property::Index propertyIndex ) +Property::Value WebView::GetProperty(BaseObject* object, Property::Index propertyIndex) { Property::Value value; - Toolkit::WebView webView = Toolkit::WebView::DownCast( Dali::BaseHandle( object ) ); + Toolkit::WebView webView = Toolkit::WebView::DownCast(Dali::BaseHandle(object)); - if( webView ) + if(webView) { - WebView& impl = GetImpl( webView ); - switch( propertyIndex ) + WebView& impl = GetImpl(webView); + switch(propertyIndex) { case Toolkit::WebView::Property::URL: { - value = impl.GetUrl(); + value = impl.mUrl; + break; + } + case Toolkit::WebView::Property::USER_AGENT: + { + value = impl.GetUserAgent(); + break; + } + case Toolkit::WebView::Property::SCROLL_POSITION: + { + value = impl.GetScrollPosition(); + break; + } + case Toolkit::WebView::Property::SCROLL_SIZE: + { + value = impl.GetScrollSize(); + break; + } + case Toolkit::WebView::Property::CONTENT_SIZE: + { + value = impl.GetContentSize(); break; } + case Toolkit::WebView::Property::TITLE: + { + value = impl.GetTitle(); + break; + } + case Toolkit::WebView::Property::VIDEO_HOLE_ENABLED: + { + value = impl.mVideoHoleEnabled; + break; + } + case Toolkit::WebView::Property::MOUSE_EVENTS_ENABLED: + { + value = impl.mMouseEventsEnabled; + break; + } + case Toolkit::WebView::Property::KEY_EVENTS_ENABLED: + { + value = impl.mKeyEventsEnabled; + break; + } + case Toolkit::WebView::Property::SELECTED_TEXT: + { + value = impl.GetSelectedText(); + break; + } + default: + break; } } return value; } -bool WebView::OnTouchEvent( Actor actor, const Dali::TouchData& touch ) +bool WebView::OnTouchEvent(Actor actor, const Dali::TouchEvent& touch) { bool result = false; - if ( mWebEngine ) + if(mWebEngine) { - result = mWebEngine.SendTouchEvent( touch ); + result = mWebEngine.SendTouchEvent(touch); } return result; } -bool WebView::OnKeyEvent( const Dali::KeyEvent& event ) +bool WebView::OnKeyEvent(const Dali::KeyEvent& event) { bool result = false; - if ( mWebEngine ) + if(mWebEngine) { - result = mWebEngine.SendKeyEvent( event ); + result = mWebEngine.SendKeyEvent(event); } return result; } +bool WebView::OnHoverEvent(Actor actor, const Dali::HoverEvent& hover) +{ + bool result = false; + if(mWebEngine) + { + result = mWebEngine.SendHoverEvent(hover); + } + return result; +} + +bool WebView::OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel) +{ + bool result = false; + if(mWebEngine) + { + result = mWebEngine.SendWheelEvent(wheel); + } + return result; +} + +void WebView::OnKeyInputFocusGained() +{ + if(mWebEngine) + { + mWebEngine.SetFocus(true); + } + + EmitKeyInputFocusSignal(true); // Calls back into the Control hence done last. +} + +void WebView::OnKeyInputFocusLost() +{ + if(mWebEngine) + { + mWebEngine.SetFocus(false); + } + + EmitKeyInputFocusSignal(false); // Calls back into the Control hence done last. +} + +void WebView::SetScrollPosition(int x, int y) +{ + if(mWebEngine) + { + mWebEngine.SetScrollPosition(x, y); + } +} + +Dali::Vector2 WebView::GetScrollPosition() const +{ + return mWebEngine ? mWebEngine.GetScrollPosition() : Dali::Vector2::ZERO; +} + +Dali::Vector2 WebView::GetScrollSize() const +{ + return mWebEngine ? mWebEngine.GetScrollSize() : Dali::Vector2::ZERO; +} + +Dali::Vector2 WebView::GetContentSize() const +{ + return mWebEngine ? mWebEngine.GetContentSize() : Dali::Vector2::ZERO; +} + +std::string WebView::GetTitle() const +{ + return mWebEngine ? mWebEngine.GetTitle() : kEmptyString; +} + +void WebView::SetDocumentBackgroundColor(Dali::Vector4 color) +{ + if(mWebEngine) + { + mWebEngine.SetDocumentBackgroundColor(color); + } +} + +void WebView::ClearTilesWhenHidden(bool cleared) +{ + if(mWebEngine) + { + mWebEngine.ClearTilesWhenHidden(cleared); + } +} + +void WebView::SetTileCoverAreaMultiplier(float multiplier) +{ + if(mWebEngine) + { + mWebEngine.SetTileCoverAreaMultiplier(multiplier); + } +} + +void WebView::EnableCursorByClient(bool enabled) +{ + if(mWebEngine) + { + mWebEngine.EnableCursorByClient(enabled); + } +} + +std::string WebView::GetSelectedText() const +{ + return mWebEngine ? mWebEngine.GetSelectedText() : kEmptyString; +} + +const std::string& WebView::GetUserAgent() const +{ + return mWebEngine ? mWebEngine.GetUserAgent() : kEmptyString; +} + +void WebView::SetUserAgent(const std::string& userAgent) +{ + if(mWebEngine) + { + mWebEngine.SetUserAgent(userAgent); + } +} + +void WebView::EnableMouseEvents(bool enabled) +{ + if(mWebEngine) + { + mMouseEventsEnabled = enabled; + mWebEngine.EnableMouseEvents(enabled); + } +} + +void WebView::EnableKeyEvents(bool enabled) +{ + if(mWebEngine) + { + mKeyEventsEnabled = enabled; + mWebEngine.EnableKeyEvents(enabled); + } +} + +#undef GET_ENUM_STRING +#undef GET_ENUM_VALUE + } // namespace Internal } // namespace Toolkit