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.
23 #include <dali/devel-api/adaptor-framework/web-engine.h>
24 #include <dali/public-api/images/image-operations.h>
25 #include <dali/public-api/object/property-notification.h>
28 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
29 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
30 #include <dali-toolkit/public-api/controls/control-impl.h>
31 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
41 class WebBackForwardList;
43 class WebCookieManager;
50 class WebView : public Control
56 WebView( const std::string& locale, const std::string& timezoneId );
58 WebView( int argc, char** argv );
65 * @copydoc Dali::Toolkit::WebView::New()
67 static Toolkit::WebView New();
70 * @copydoc Dali::Toolkit::WebView::New( const std::string&, const std::string& )
72 static Toolkit::WebView New( const std::string& locale, const std::string& timezoneId );
75 * @brief Get settings of WebEngine.
77 Dali::Toolkit::WebSettings* GetSettings() const;
80 * @brief Get context of WebEngine.
82 Dali::Toolkit::WebContext* GetContext() const;
85 * @brief Get cookie manager of WebEngine.
87 Dali::Toolkit::WebCookieManager* GetCookieManager() const;
90 * @brief Get WebBackForwardList of WebEngine.
92 Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
95 * @copydoc Dali::Toolkit::WebView::New( int, char** )
97 static Toolkit::WebView New( int argc, char** argv );
100 * @brief Get favicon of web page.
102 * @return Handle to a favicon
104 Dali::Toolkit::ImageView GetFavicon() const;
107 * @copydoc Dali::Toolkit::WebView::LoadUrl()
109 void LoadUrl( const std::string& url );
112 * @copydoc Dali::WebEngine::LoadHTMLString()
114 void LoadHtmlString( const std::string& htmlString );
117 * @copydoc Dali::Toolkit::WebView::Reload()
122 * @copydoc Dali::Toolkit::WebView::StopLoading()
127 * @copydoc Dali::Toolkit::WebView::StopLoading()
132 * @copydoc Dali::Toolkit::WebView::Resume()
137 * @copydoc Dali::Toolkit::WebView::ScrollBy()
139 void ScrollBy( int deltaX, int deltaY );
142 * @copydoc Dali::Toolkit::WebView::CanGoForward()
147 * @copydoc Dali::Toolkit::WebView::GoForward()
152 * @copydoc Dali::Toolkit::WebView::CanGoBack()
157 * @copydoc Dali::Toolkit::WebView::GoBack()
162 * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
164 void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler );
167 * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
169 void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
172 * @brief Clears all tiles resources of Web.
174 void ClearAllTilesResources();
177 * @copydoc Dali::Toolkit::WebView::ClearHistory()
182 * @copydoc Dali::Toolkit::WebView::SetTtsFocus()
184 void SetTtsFocus(bool focused);
187 * @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal()
189 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadStartedSignal();
192 * @copydoc Dali::Toolkit::WebView::PageLoadFinishedSignal()
194 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadFinishedSignal();
197 * @copydoc Dali::Toolkit::WebView::PageLoadErrorSignal()
199 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
202 * @copydoc Dali::Toolkit::WebView::ScrollEdgeReachedSignal()
204 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
207 * @copydoc Dali::Toolkit::WebView::GetPlainTextAsynchronously()
209 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
211 public: // Properties
214 * @brief Called when a property of an object of this type is set.
216 * @param[in] object The object whose property is set.
217 * @param[in] index The property index.
218 * @param[in] value The new property value.
220 static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
223 * @brief Called to retrieve a property of an object of this type.
225 * @param[in] object The object whose property is to be retrieved.
226 * @param[in] index The property index.
227 * @return The current value of the property.
229 static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
232 * Connects a callback function with the object's signals.
233 * @param[in] object The object providing the signal.
234 * @param[in] tracker Used to disconnect the signal.
235 * @param[in] signalName The signal to connect to.
236 * @param[in] functor A newly allocated FunctorDelegate.
237 * @return True if the signal was connected.
238 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
240 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
242 private: // From Control
245 * @copydoc Toolkit::Control::OnInitialize()
247 void OnInitialize() override;
250 * @copydoc Toolkit::Control::GetNaturalSize
252 Vector3 GetNaturalSize() override;
255 * Signal occurs when the Web View has been touched.
256 * @param[in] actor The Actor Touched
257 * @param[in] touch The Touch Data.
258 * @return Whether to consume event or not.
260 bool OnTouchEvent( Actor actor, const Dali::TouchEvent& touch );
263 * @copydoc Toolkit::Control::OnKeyEvent()
265 bool OnKeyEvent( const Dali::KeyEvent& event ) override;
268 * @copydoc Toolkit::Control::OnKeyInputFocusGained()
270 void OnKeyInputFocusGained() override;
273 * @copydoc Toolkit::Control::OnKeyInputFocusLost()
275 void OnKeyInputFocusLost() override;
278 * @copydoc Toolkit::Control::OnSceneConnection()
280 void OnSceneConnection( int depth ) override;
285 WebView( const WebView& webView );
287 WebView& operator=( const WebView& webView );
290 * @brief Sets an absolute scroll of the given view.
291 * @param[in] x The coordinate x of scroll
292 * @param[in] y The coordinate y of scroll
294 void SetScrollPosition( int x, int y );
297 * @brief Gets the current scroll position of the given view.
298 * @param[out] x The coordinate x of scroll
299 * @param[out] y The coordinate y of scroll
301 void GetScrollPosition( int& x, int& y ) const;
304 * @brief Gets the possible scroll size of the given view.
305 * @param[out] width The width of scroll size
306 * @param[out] height The height of scroll size
308 void GetScrollSize( int& width, int& height ) const;
311 * @brief Gets the last known content's size.
312 * @param[out] width The width of content's size
313 * @param[out] height The height of content's size
315 void GetContentSize( int& width, int& height ) const;
318 * @brief Returns the title of the Web.
320 * @return The title of web page
322 std::string GetTitle() const;
325 * @brief Get user agent string.
326 * @return The string value of user agent
328 const std::string& GetUserAgent() const;
331 * @brief Set user agent string.
332 * @param[in] userAgent The string value of user agent
334 void SetUserAgent( const std::string& userAgent );
337 * @brief Updates display area of web view.
338 * @param[in] source The soource triggers Notification.
340 void UpdateDisplayArea( Dali::PropertyNotification& source );
343 * @brief Enable/Disable video hole for video playing.
344 * @param[in] enabled True if video hole is enabled, false otherwise.
346 void EnableVideoHole( bool enabled );
349 * @brief Enable blend mode.
350 * @param[in] blendEnabled True if turn on blend mode, false otherwise.
352 void EnableBlendMode( bool blendEnabled );
355 * @brief Callback function to be called when page load started.
356 * @param[in] url The url currently being loaded
358 void OnPageLoadStarted( const std::string& url );
361 * @brief Callback function to be called when page load finished.
362 * @param[in] url The url currently being loaded
364 void OnPageLoadFinished( const std::string& url );
367 * @brief Callback function to be called when there is an error in page loading.
368 * @param[in] url The url currently being loaded
369 * @param[in] errorCode The error code
371 void OnPageLoadError( const std::string& url, int errorCode );
374 * @brief Callback function to be called when scroll edge is reached.
375 * @param[in] e The scroll edge reached.
377 void OnScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge );
382 Dali::Toolkit::Visual::Base mVisual;
383 Dali::Size mWebViewSize;
384 Dali::WebEngine mWebEngine;
386 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadStartedSignal;
387 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadFinishedSignal;
388 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal;
389 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
391 std::unique_ptr<Dali::Toolkit::WebContext> mWebContext;
392 std::unique_ptr<Dali::Toolkit::WebCookieManager> mWebCookieManager;
393 std::unique_ptr<Dali::Toolkit::WebSettings> mWebSettings;
394 std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
396 Dali::PropertyNotification mPositionUpdateNotification;
397 Dali::PropertyNotification mSizeUpdateNotification;
398 Dali::PropertyNotification mScaleUpdateNotification;
399 bool mVideoHoleEnabled;
400 Dali::Rect< int > mWebViewArea;
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