1 #ifndef DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_WEB_VIEW_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/devel-api/adaptor-framework/web-engine.h>
23 #include <dali/public-api/images/image-operations.h>
26 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
43 class WebView : public Control
49 WebView( const std::string& locale, const std::string& timezoneId );
56 * @copydoc Dali::Toolkit::WebView::New()
58 static Toolkit::WebView New();
61 * @copydoc Dali::Toolkit::WebView::New( const std::string&, const std::string& )
63 static Toolkit::WebView New( const std::string& locale, const std::string& timezoneId );
66 * @copydoc Dali::Toolkit::WebView::LoadUrl()
68 void LoadUrl( const std::string& url );
71 * @copydoc Dali::WebEngine::LoadHTMLString()
73 void LoadHTMLString( const std::string& htmlString );
76 * @copydoc Dali::Toolkit::WebView::Reload()
81 * @copydoc Dali::Toolkit::WebView::StopLoading()
86 * @copydoc Dali::Toolkit::WebView::StopLoading()
91 * @copydoc Dali::Toolkit::WebView::Resume()
96 * @copydoc Dali::Toolkit::WebView::CanGoForward()
101 * @copydoc Dali::Toolkit::WebView::GoForward()
106 * @copydoc Dali::Toolkit::WebView::CanGoBack()
111 * @copydoc Dali::Toolkit::WebView::GoBack()
116 * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
118 void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler );
121 * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
123 void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
126 * @copydoc Dali::Toolkit::WebView::ClearHistory()
131 * @copydoc Dali::Toolkit::WebView::ClearCache()
136 * @copydoc Dali::Toolkit::WebView::ClearCookies()
141 * @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal()
143 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadStartedSignal();
146 * @copydoc Dali::Toolkit::WebView::PageLoadFinishedSignal()
148 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadFinishedSignal();
151 * @copydoc Dali::Toolkit::WebView::PageLoadErrorSignal()
153 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
155 public: // Properties
158 * @brief Called when a property of an object of this type is set.
160 * @param[in] object The object whose property is set.
161 * @param[in] index The property index.
162 * @param[in] value The new property value.
164 static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
167 * @brief Called to retrieve a property of an object of this type.
169 * @param[in] object The object whose property is to be retrieved.
170 * @param[in] index The property index.
171 * @return The current value of the property.
173 static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
176 * Connects a callback function with the object's signals.
177 * @param[in] object The object providing the signal.
178 * @param[in] tracker Used to disconnect the signal.
179 * @param[in] signalName The signal to connect to.
180 * @param[in] functor A newly allocated FunctorDelegate.
181 * @return True if the signal was connected.
182 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
184 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
186 private: // From Control
189 * @copydoc Toolkit::Control::OnInitialize()
191 void OnInitialize() override;
194 * @copydoc Toolkit::Control::GetNaturalSize
196 Vector3 GetNaturalSize() override;
199 * @copydoc Toolkit::Control::OnRelayout()
201 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
204 * Signal occurs when the Web View has been touched.
205 * @param[in] actor The Actor Touched
206 * @param[in] touch The Touch Data.
207 * @return Whether to consume event or not.
209 bool OnTouchEvent( Actor actor, const Dali::TouchEvent& touch );
212 * @copydoc Toolkit::Control::OnKeyEvent()
214 bool OnKeyEvent( const Dali::KeyEvent& event ) override;
217 * @copydoc Toolkit::Control::OnKeyInputFocusGained()
219 void OnKeyInputFocusGained() override;
222 * @copydoc Toolkit::Control::OnKeyInputFocusLost()
224 void OnKeyInputFocusLost() override;
229 WebView( const WebView& webView );
231 WebView& operator=( const WebView& webView );
234 * @brief Get cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER.
235 * @see Toolkit::WebView::CacheModel::Type
237 Toolkit::WebView::CacheModel::Type GetCacheModel() const;
240 * @brief Set cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER.
241 * @param[in] cacheModel The cache model option
242 * @see Toolkit::WebView::CacheModel::Type
244 void SetCacheModel( Toolkit::WebView::CacheModel::Type cacheModel );
247 * @brief Gets the cookie acceptance policy. The default is Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
248 * @see Toolkit::WebView::CookieAcceptPolicy::Type
250 Toolkit::WebView::CookieAcceptPolicy::Type GetCookieAcceptPolicy() const;
253 * @brief Sets the cookie acceptance policy. The default is Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
254 * @param[in] policy The cookie acceptance policy
255 * @see Toolkit::WebView::CookieAcceptPolicy::Type
257 void SetCookieAcceptPolicy( Toolkit::WebView::CookieAcceptPolicy::Type policy );
260 * @brief Get user agent string.
261 * @return The string value of user agent
263 const std::string& GetUserAgent() const;
266 * @brief Set user agent string.
267 * @param[in] userAgent The string value of user agent
269 void SetUserAgent( const std::string& userAgent );
272 * @brief Returns whether JavaScript can be executable. The default is true.
274 * @return true if JavaScript executing is enabled, false otherwise
276 bool IsJavaScriptEnabled() const;
279 * @brief Enables/disables JavaScript executing. The default is enabled.
281 * @param[in] enabled True if JavaScript executing is enabled, false otherwise
283 void EnableJavaScript( bool enabled );
286 * @brief Returns whether images can be loaded automatically. The default is true.
288 * @return true if images are loaded automatically, false otherwise
290 bool AreImagesAutomaticallyLoaded() const;
293 * @brief Enables/disables auto loading of images. The default is enabled.
295 * @param[in] automatic True if images are loaded automatically, false otherwise
297 void LoadImagesAutomatically( bool automatic );
300 * @brief Gets the default text encoding name (e.g. UTF-8).
302 * @return The default text encoding name
304 const std::string& GetDefaultTextEncodingName() const;
307 * @brief Sets the default text encoding name (e.g. UTF-8).
309 * @param[in] defaultTextEncodingName The default text encoding name
311 void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName );
314 * @brief Returns the default font size in pixel. The default value is 16.
316 * @return The default font size
318 int GetDefaultFontSize() const;
321 * @brief Sets the default font size in pixel. The default value is 16.
323 * @param[in] defaultFontSize A new default font size to set
325 void SetDefaultFontSize( int defaultFontSize );
328 * @brief Callback function to be called when page load started.
329 * @param[in] url The url currently being loaded
331 void OnPageLoadStarted( const std::string& url );
334 * @brief Callback function to be called when page load finished.
335 * @param[in] url The url currently being loaded
337 void OnPageLoadFinished( const std::string& url );
340 * @brief Callback function to be called when there is an error in page loading.
341 * @param[in] url The url currently being loaded
342 * @param[in] errorCode The error code
344 void OnPageLoadError( const std::string& url, int errorCode );
349 Dali::Toolkit::Visual::Base mVisual;
350 Dali::Size mWebViewSize;
351 Dali::WebEngine mWebEngine;
353 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadStartedSignal;
354 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadFinishedSignal;
355 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal;
358 } // namespace Internal
360 inline Toolkit::Internal::WebView& GetImpl( Toolkit::WebView& handle )
362 DALI_ASSERT_ALWAYS( handle );
363 Dali::RefObject& impl = handle.GetImplementation();
364 return static_cast< Toolkit::Internal::WebView& >( impl );
367 inline const Toolkit::Internal::WebView& GetImpl( const Toolkit::WebView& handle )
369 DALI_ASSERT_ALWAYS( handle );
370 const Dali::RefObject& impl = handle.GetImplementation();
371 return static_cast< const Toolkit::Internal::WebView& >( impl );
374 } // namespace Toolkit
378 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H