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::ScrollBy()
98 void ScrollBy( int deltaX, int deltaY );
101 * @copydoc Dali::Toolkit::WebView::CanGoForward()
106 * @copydoc Dali::Toolkit::WebView::GoForward()
111 * @copydoc Dali::Toolkit::WebView::CanGoBack()
116 * @copydoc Dali::Toolkit::WebView::GoBack()
121 * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
123 void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler );
126 * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
128 void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
131 * @copydoc Dali::Toolkit::WebView::ClearHistory()
136 * @copydoc Dali::Toolkit::WebView::ClearCache()
141 * @copydoc Dali::Toolkit::WebView::ClearCookies()
146 * @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal()
148 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadStartedSignal();
151 * @copydoc Dali::Toolkit::WebView::PageLoadFinishedSignal()
153 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadFinishedSignal();
156 * @copydoc Dali::Toolkit::WebView::PageLoadErrorSignal()
158 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
161 * @copydoc Dali::Toolkit::WebView::ScrollEdgeReachedSignal()
163 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
165 public: // Properties
168 * @brief Called when a property of an object of this type is set.
170 * @param[in] object The object whose property is set.
171 * @param[in] index The property index.
172 * @param[in] value The new property value.
174 static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
177 * @brief Called to retrieve a property of an object of this type.
179 * @param[in] object The object whose property is to be retrieved.
180 * @param[in] index The property index.
181 * @return The current value of the property.
183 static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
186 * Connects a callback function with the object's signals.
187 * @param[in] object The object providing the signal.
188 * @param[in] tracker Used to disconnect the signal.
189 * @param[in] signalName The signal to connect to.
190 * @param[in] functor A newly allocated FunctorDelegate.
191 * @return True if the signal was connected.
192 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
194 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
196 private: // From Control
199 * @copydoc Toolkit::Control::OnInitialize()
201 void OnInitialize() override;
204 * @copydoc Toolkit::Control::GetNaturalSize
206 Vector3 GetNaturalSize() override;
209 * @copydoc Toolkit::Control::OnRelayout()
211 void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
214 * Signal occurs when the Web View has been touched.
215 * @param[in] actor The Actor Touched
216 * @param[in] touch The Touch Data.
217 * @return Whether to consume event or not.
219 bool OnTouchEvent( Actor actor, const Dali::TouchEvent& touch );
222 * @copydoc Toolkit::Control::OnKeyEvent()
224 bool OnKeyEvent( const Dali::KeyEvent& event ) override;
227 * @copydoc Toolkit::Control::OnKeyInputFocusGained()
229 void OnKeyInputFocusGained() override;
232 * @copydoc Toolkit::Control::OnKeyInputFocusLost()
234 void OnKeyInputFocusLost() override;
239 WebView( const WebView& webView );
241 WebView& operator=( const WebView& webView );
244 * @brief Sets an absolute scroll of the given view.
245 * @param[in] x The coordinate x of scroll
246 * @param[in] y The coordinate y of scroll
248 void SetScrollPosition( int x, int y );
251 * @brief Gets the current scroll position of the given view.
252 * @param[out] x The coordinate x of scroll
253 * @param[out] y The coordinate y of scroll
255 void GetScrollPosition( int& x, int& y ) const;
258 * @brief Gets the possible scroll size of the given view.
259 * @param[out] width The width of scroll size
260 * @param[out] height The height of scroll size
262 void GetScrollSize( int& width, int& height ) const;
265 * @brief Gets the last known content's size.
266 * @param[out] width The width of content's size
267 * @param[out] height The height of content's size
269 void GetContentSize( int& width, int& height ) const;
272 * @brief Get cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER.
273 * @see Toolkit::WebView::CacheModel::Type
275 Toolkit::WebView::CacheModel::Type GetCacheModel() const;
278 * @brief Set cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER.
279 * @param[in] cacheModel The cache model option
280 * @see Toolkit::WebView::CacheModel::Type
282 void SetCacheModel( Toolkit::WebView::CacheModel::Type cacheModel );
285 * @brief Gets the cookie acceptance policy. The default is Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
286 * @see Toolkit::WebView::CookieAcceptPolicy::Type
288 Toolkit::WebView::CookieAcceptPolicy::Type GetCookieAcceptPolicy() const;
291 * @brief Sets the cookie acceptance policy. The default is Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
292 * @param[in] policy The cookie acceptance policy
293 * @see Toolkit::WebView::CookieAcceptPolicy::Type
295 void SetCookieAcceptPolicy( Toolkit::WebView::CookieAcceptPolicy::Type policy );
298 * @brief Get user agent string.
299 * @return The string value of user agent
301 const std::string& GetUserAgent() const;
304 * @brief Set user agent string.
305 * @param[in] userAgent The string value of user agent
307 void SetUserAgent( const std::string& userAgent );
310 * @brief Returns whether JavaScript can be executable. The default is true.
312 * @return true if JavaScript executing is enabled, false otherwise
314 bool IsJavaScriptEnabled() const;
317 * @brief Enables/disables JavaScript executing. The default is enabled.
319 * @param[in] enabled True if JavaScript executing is enabled, false otherwise
321 void EnableJavaScript( bool enabled );
324 * @brief Returns whether images can be loaded automatically. The default is true.
326 * @return true if images are loaded automatically, false otherwise
328 bool AreImagesAutomaticallyLoaded() const;
331 * @brief Enables/disables auto loading of images. The default is enabled.
333 * @param[in] automatic True if images are loaded automatically, false otherwise
335 void LoadImagesAutomatically( bool automatic );
338 * @brief Gets the default text encoding name (e.g. UTF-8).
340 * @return The default text encoding name
342 const std::string& GetDefaultTextEncodingName() const;
345 * @brief Sets the default text encoding name (e.g. UTF-8).
347 * @param[in] defaultTextEncodingName The default text encoding name
349 void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName );
352 * @brief Returns the default font size in pixel. The default value is 16.
354 * @return The default font size
356 int GetDefaultFontSize() const;
359 * @brief Sets the default font size in pixel. The default value is 16.
361 * @param[in] defaultFontSize A new default font size to set
363 void SetDefaultFontSize( int defaultFontSize );
366 * @brief Callback function to be called when page load started.
367 * @param[in] url The url currently being loaded
369 void OnPageLoadStarted( const std::string& url );
372 * @brief Callback function to be called when page load finished.
373 * @param[in] url The url currently being loaded
375 void OnPageLoadFinished( const std::string& url );
378 * @brief Callback function to be called when there is an error in page loading.
379 * @param[in] url The url currently being loaded
380 * @param[in] errorCode The error code
382 void OnPageLoadError( const std::string& url, int errorCode );
385 * @brief Callback function to be called when scroll edge is reached.
386 * @param[in] e The scroll edge reached.
388 void OnScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge );
393 Dali::Toolkit::Visual::Base mVisual;
394 Dali::Size mWebViewSize;
395 Dali::WebEngine mWebEngine;
397 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadStartedSignal;
398 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadFinishedSignal;
399 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal;
400 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
403 } // namespace Internal
405 inline Toolkit::Internal::WebView& GetImpl( Toolkit::WebView& handle )
407 DALI_ASSERT_ALWAYS( handle );
408 Dali::RefObject& impl = handle.GetImplementation();
409 return static_cast< Toolkit::Internal::WebView& >( impl );
412 inline const Toolkit::Internal::WebView& GetImpl( const Toolkit::WebView& handle )
414 DALI_ASSERT_ALWAYS( handle );
415 const Dali::RefObject& impl = handle.GetImplementation();
416 return static_cast< const Toolkit::Internal::WebView& >( impl );
419 } // namespace Toolkit
423 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H