1 #ifndef DALI_WEB_ENGINE_IMPL_H
2 #define DALI_WEB_ENGINE_IMPL_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/object/base-object.h>
25 #include <dali/devel-api/adaptor-framework/web-engine.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
39 typedef IntrusivePtr< WebEngine > WebEnginePtr;
42 * @brief WebEngine class is used for Web.
44 class WebEngine : public Dali::BaseObject
49 * @brief Creates a new WebEngine handle
51 * @return WebEngine pointer
53 static WebEnginePtr New();
56 * @copydoc Dali::WebEngine::Create()
58 void Create( int width, int height, const std::string& locale, const std::string& timezoneId );
61 * @copydoc Dali::WebEngine::Destroy()
66 * @copydoc Dali::WebEngine::GetNativeImageSource()
68 Dali::NativeImageInterfacePtr GetNativeImageSource();
71 * @copydoc Dali::WebEngine::LoadUrl()
73 void LoadUrl( const std::string& url );
76 * @copydoc Dali::WebEngine::GetUrl()
78 const std::string& GetUrl();
81 * @copydoc Dali::WebEngine::LoadHTMLString()
83 void LoadHTMLString( const std::string& htmlString );
86 * @copydoc Dali::WebEngine::Reload()
91 * @copydoc Dali::WebEngine::StopLoading()
96 * @copydoc Dali::WebEngine::Suspend()
101 * @copydoc Dali::WebEngine::Resume()
106 * @copydoc Dali::WebEngine::ScrollBy()
108 void ScrollBy( int deltaX, int deltaY );
111 * @copydoc Dali::WebEngine::SetScrollPosition()
113 void SetScrollPosition( int x, int y );
116 * @copydoc Dali::WebEngine::GetScrollPosition()
118 void GetScrollPosition( int& x, int& y ) const;
121 * @copydoc Dali::WebEngine::GetScrollSize()
123 void GetScrollSize( int& width, int& height ) const;
126 * @copydoc Dali::WebEngine::GetContentSize()
128 void GetContentSize( int& width, int& height ) const;
131 * @copydoc Dali::WebEngine::CanGoForward()
136 * @copydoc Dali::WebEngine::GoForward()
141 * @copydoc Dali::WebEngine::CanGoBack()
146 * @copydoc Dali::WebEngine::GoBack()
151 * @copydoc Dali::WebEngine::EvaluateJavaScript()
153 void EvaluateJavaScript( const std::string& script, std::function< void(const std::string&) > resultHandler );
156 * @copydoc Dali::WebEngine::AddJavaScriptMessageHandler()
158 void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void(const std::string&) > handler );
161 * @copydoc Dali::WebEngine::ClearHistory()
166 * @copydoc Dali::WebEngine::ClearCache()
171 * @copydoc Dali::WebEngine::ClearCookies()
176 * @copydoc Dali::WebEngine::GetCacheModel()
178 Dali::WebEnginePlugin::CacheModel GetCacheModel() const;
181 * @copydoc Dali::WebEngine::SetCacheModel()
183 void SetCacheModel( Dali::WebEnginePlugin::CacheModel cacheModel );
186 * @copydoc Dali::WebEngine::GetCookieAcceptPolicy()
188 Dali::WebEnginePlugin::CookieAcceptPolicy GetCookieAcceptPolicy() const;
191 * @copydoc Dali::WebEngine::SetCookieAcceptPolicy()
193 void SetCookieAcceptPolicy( Dali::WebEnginePlugin::CookieAcceptPolicy policy );
196 * @copydoc Dali::WebEngine::GetUserAgent()
198 const std::string& GetUserAgent() const;
201 * @copydoc Dali::WebEngine::SetUserAgent()
203 void SetUserAgent( const std::string& userAgent );
206 * @copydoc Dali::WebEngine::IsJavaScriptEnabled()
208 bool IsJavaScriptEnabled() const;
211 * @copydoc Dali::WebEngine::EnableJavaScript()
213 void EnableJavaScript( bool enabled );
216 * @copydoc Dali::WebEngine::AreImagesAutomaticallyLoaded()
218 bool AreImagesAutomaticallyLoaded() const;
221 * @copydoc Dali::WebEngine::LoadImagesAutomatically()
223 void LoadImagesAutomatically( bool automatic );
226 * @copydoc Dali::WebEngine::GetDefaultTextEncodingName()
228 const std::string& GetDefaultTextEncodingName() const;
231 * @copydoc Dali::WebEngine::SetDefaultTextEncodingName()
233 void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName );
236 * @copydoc Dali::WebEngine::GetDefaultFontSize()
238 int GetDefaultFontSize() const;
241 * @copydoc Dali::WebEngine::SetDefaultFontSize()
243 void SetDefaultFontSize( int defaultFontSize );
246 * @copydoc Dali::WebEngine::SetSize()
248 void SetSize( int width, int height );
251 * @copydoc Dali::WebEngine::SendTouchEvent()
253 bool SendTouchEvent( const Dali::TouchEvent& touch );
256 * @copydoc Dali::WebEngine::SendKeyEvent()
258 bool SendKeyEvent( const Dali::KeyEvent& event );
261 * @copydoc Dali::WebEngine::SetFocus()
263 void SetFocus( bool focused );
266 * @copydoc Dali::WebEngine::PageLoadStartedSignal()
268 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
271 * @copydoc Dali::WebEngine::PageLoadFinishedSignal()
273 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
276 * @copydoc Dali::WebEngine::PageLoadErrorSignal()
278 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
281 * @copydoc Dali::WebEngine::ScrollEdgeReachedSignal()
283 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
288 * @brief Constructor.
295 virtual ~WebEngine();
297 // Undefined copy constructor
298 WebEngine( const WebEngine& WebEngine );
300 // Undefined assignment operator
301 WebEngine& operator=( const WebEngine& WebEngine );
304 * @brief Initializes member data.
306 * @return Whether the initialization succeed or not.
311 * @brief Initializes library handle by loading web engine plugin.
313 * @return Whether the initialization succeed or not.
315 bool InitializePluginHandle();
319 typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();
320 typedef void (*DestroyWebEngineFunction)( Dali::WebEnginePlugin* plugin );
322 Dali::WebEnginePlugin* mPlugin; ///< WebEnginePlugin instance
323 void* mHandle; ///< Handle for the loaded library
324 CreateWebEngineFunction mCreateWebEnginePtr; ///< Function to create plugin instance
325 DestroyWebEngineFunction mDestroyWebEnginePtr; ///< Function to destroy plugin instance
328 } // namespace Adaptor
329 } // namespace Internal
331 inline static Internal::Adaptor::WebEngine& GetImplementation( Dali::WebEngine& webEngine )
333 DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
335 BaseObject& handle = webEngine.GetBaseObject();
337 return static_cast< Internal::Adaptor::WebEngine& >( handle );
340 inline static const Internal::Adaptor::WebEngine& GetImplementation( const Dali::WebEngine& webEngine )
342 DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
344 const BaseObject& handle = webEngine.GetBaseObject();
346 return static_cast< const Internal::Adaptor::WebEngine& >( handle );