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 * @copydoc Dali::Toolkit::WebView::GetPlugin()
102 Dali::WebEnginePlugin* GetPlugin() const;
105 * @brief Get favicon of web page.
107 * @return Handle to a favicon
109 Dali::Toolkit::ImageView GetFavicon() const;
112 * @copydoc Dali::Toolkit::WebView::LoadUrl()
114 void LoadUrl( const std::string& url );
117 * @copydoc Dali::WebEngine::LoadHTMLString()
119 void LoadHtmlString( const std::string& htmlString );
122 * @copydoc Dali::Toolkit::WebView::Reload()
127 * @copydoc Dali::Toolkit::WebView::StopLoading()
132 * @copydoc Dali::Toolkit::WebView::StopLoading()
137 * @copydoc Dali::Toolkit::WebView::Resume()
142 * @copydoc Dali::Toolkit::WebView::ScrollBy()
144 void ScrollBy( int deltaX, int deltaY );
147 * @copydoc Dali::Toolkit::WebView::CanGoForward()
152 * @copydoc Dali::Toolkit::WebView::GoForward()
157 * @copydoc Dali::Toolkit::WebView::CanGoBack()
162 * @copydoc Dali::Toolkit::WebView::GoBack()
167 * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
169 void EvaluateJavaScript( const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler );
172 * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
174 void AddJavaScriptMessageHandler( const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler );
177 * @brief Clears all tiles resources of Web.
179 void ClearAllTilesResources();
182 * @copydoc Dali::Toolkit::WebView::ClearHistory()
187 * @copydoc Dali::Toolkit::WebView::SetTtsFocus()
189 void SetTtsFocus(bool focused);
192 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadStartedCallback()
194 void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
197 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadFinishedCallback()
199 void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
202 * @copydoc Dali::Toolkit::WebView::RegisterPageLoadErrorCallback()
204 void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
207 * @copydoc Dali::Toolkit::WebView::RegisterScrollEdgeReachedCallback()
209 void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
212 * @copydoc Dali::Toolkit::WebView::RegisterUrlChangedCallback()
214 void RegisterUrlChangedCallback(Dali::WebEnginePlugin::WebEngineUrlChangedCallback callback);
217 * @copydoc Dali::Toolkit::WebView::RegisterNavigationPolicyDecidedCallback()
219 void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
222 * @copydoc Dali::Toolkit::WebView::RegisterNewWindowCreatedCallback()
224 void RegisterNewWindowCreatedCallback(Dali::WebEnginePlugin::WebEngineNewWindowCreatedCallback callback);
227 * @copydoc Dali::Toolkit::WebView::GetPlainTextAsynchronously()
229 void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
231 public: // Properties
234 * @brief Called when a property of an object of this type is set.
236 * @param[in] object The object whose property is set.
237 * @param[in] index The property index.
238 * @param[in] value The new property value.
240 static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
243 * @brief Called to retrieve a property of an object of this type.
245 * @param[in] object The object whose property is to be retrieved.
246 * @param[in] index The property index.
247 * @return The current value of the property.
249 static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
251 private: // From Control
254 * @copydoc Toolkit::Control::OnInitialize()
256 void OnInitialize() override;
259 * @copydoc Toolkit::Control::GetNaturalSize
261 Vector3 GetNaturalSize() override;
264 * Signal occurs when the Web View has been touched.
265 * @param[in] actor The Actor Touched
266 * @param[in] touch The Touch Data.
267 * @return Whether to consume event or not.
269 bool OnTouchEvent( Actor actor, const Dali::TouchEvent& touch );
272 * @copydoc Toolkit::Control::OnKeyEvent()
274 bool OnKeyEvent( const Dali::KeyEvent& event ) override;
277 * @copydoc Toolkit::Control::OnKeyInputFocusGained()
279 void OnKeyInputFocusGained() override;
282 * @copydoc Toolkit::Control::OnKeyInputFocusLost()
284 void OnKeyInputFocusLost() override;
287 * @copydoc Toolkit::Control::OnSceneConnection()
289 void OnSceneConnection( int depth ) override;
294 WebView( const WebView& webView );
296 WebView& operator=( const WebView& webView );
299 * @brief Sets an absolute scroll of the given view.
300 * @param[in] x The coordinate x of scroll
301 * @param[in] y The coordinate y of scroll
303 void SetScrollPosition( int x, int y );
306 * @brief Gets the current scroll position of the given view.
307 * @param[out] x The coordinate x of scroll
308 * @param[out] y The coordinate y of scroll
310 void GetScrollPosition( int& x, int& y ) const;
313 * @brief Gets the possible scroll size of the given view.
314 * @param[out] width The width of scroll size
315 * @param[out] height The height of scroll size
317 void GetScrollSize( int& width, int& height ) const;
320 * @brief Gets the last known content's size.
321 * @param[out] width The width of content's size
322 * @param[out] height The height of content's size
324 void GetContentSize( int& width, int& height ) const;
327 * @brief Get current url.
328 * @return The string value of current url
330 std::string GetUrl() const;
333 * @brief Returns the title of the Web.
335 * @return The title of web page
337 std::string GetTitle() const;
340 * @brief Get user agent string.
341 * @return The string value of user agent
343 std::string GetUserAgent() const;
346 * @brief Set user agent string.
347 * @param[in] userAgent The string value of user agent
349 void SetUserAgent( const std::string& userAgent );
352 * @brief Updates display area of web view.
353 * @param[in] source The soource triggers Notification.
355 void UpdateDisplayArea( Dali::PropertyNotification& source );
358 * @brief Enable/Disable video hole for video playing.
359 * @param[in] enabled True if video hole is enabled, false otherwise.
361 void EnableVideoHole( bool enabled );
364 * @brief Enable blend mode.
365 * @param[in] blendEnabled True if turn on blend mode, false otherwise.
367 void EnableBlendMode( bool blendEnabled );
371 Dali::Toolkit::Visual::Base mVisual;
372 Dali::Size mWebViewSize;
373 Dali::WebEngine mWebEngine;
375 std::unique_ptr<Dali::Toolkit::WebContext> mWebContext;
376 std::unique_ptr<Dali::Toolkit::WebCookieManager> mWebCookieManager;
377 std::unique_ptr<Dali::Toolkit::WebSettings> mWebSettings;
378 std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
380 Dali::PropertyNotification mPositionUpdateNotification;
381 Dali::PropertyNotification mSizeUpdateNotification;
382 Dali::PropertyNotification mScaleUpdateNotification;
383 bool mVideoHoleEnabled;
384 Dali::Rect< int > mWebViewArea;
387 } // namespace Internal
389 inline Toolkit::Internal::WebView& GetImpl( Toolkit::WebView& handle )
391 DALI_ASSERT_ALWAYS( handle );
392 Dali::RefObject& impl = handle.GetImplementation();
393 return static_cast< Toolkit::Internal::WebView& >( impl );
396 inline const Toolkit::Internal::WebView& GetImpl( const Toolkit::WebView& handle )
398 DALI_ASSERT_ALWAYS( handle );
399 const Dali::RefObject& impl = handle.GetImplementation();
400 return static_cast< const Toolkit::Internal::WebView& >( impl );
403 } // namespace Toolkit
407 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H