1 #ifndef DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
5 * Copyright (c) 2021 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>
24 #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>
39 class WebBackForwardList;
41 class WebCookieManager;
47 class WebView : public Control
52 WebView(const std::string& locale, const std::string& timezoneId);
54 WebView(int argc, char** argv);
60 * @copydoc Dali::Toolkit::WebView::New()
62 static Toolkit::WebView New();
65 * @copydoc Dali::Toolkit::WebView::New( const std::string&, const std::string& )
67 static Toolkit::WebView New(const std::string& locale, const std::string& timezoneId);
70 * @brief Get settings of WebEngine.
72 Dali::Toolkit::WebSettings* GetSettings() const;
75 * @brief Get context of WebEngine.
77 Dali::Toolkit::WebContext* GetContext() const;
80 * @brief Get cookie manager of WebEngine.
82 Dali::Toolkit::WebCookieManager* GetCookieManager() const;
85 * @brief Get WebBackForwardList of WebEngine.
87 Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
90 * @copydoc Dali::Toolkit::WebView::New( int, char** )
92 static Toolkit::WebView New(int argc, char** argv);
95 * @brief Get Favicon of web page.
97 * @return Handle to a fav icon
99 Dali::Toolkit::ImageView& GetFavicon();
102 * @copydoc Dali::Toolkit::WebView::LoadUrl()
104 void LoadUrl(const std::string& url);
107 * @copydoc Dali::WebEngine::LoadHTMLString()
109 void LoadHtmlString(const std::string& htmlString);
112 * @copydoc Dali::Toolkit::WebView::Reload()
117 * @copydoc Dali::Toolkit::WebView::StopLoading()
122 * @copydoc Dali::Toolkit::WebView::StopLoading()
127 * @copydoc Dali::Toolkit::WebView::Resume()
132 * @copydoc Dali::Toolkit::WebView::ScrollBy()
134 void ScrollBy(int deltaX, int deltaY);
137 * @copydoc Dali::Toolkit::WebView::CanGoForward()
142 * @copydoc Dali::Toolkit::WebView::GoForward()
147 * @copydoc Dali::Toolkit::WebView::CanGoBack()
152 * @copydoc Dali::Toolkit::WebView::GoBack()
157 * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
159 void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
162 * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
164 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
167 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptAlertCallback()
169 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
172 * @copydoc Dali::Toolkit::WebView::JavaScriptAlertReply()
174 void JavaScriptAlertReply();
177 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptConfirmCallback()
179 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
182 * @copydoc Dali::Toolkit::WebView::JavaScriptConfirmReply()
184 void JavaScriptConfirmReply(bool confirmed);
187 * @copydoc Dali::Toolkit::WebView::RegisterJavaScriptPromptCallback()
189 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
192 * @copydoc Dali::Toolkit::WebView::JavaScriptPromptReply()
194 void JavaScriptPromptReply(const std::string& result);
197 * @copydoc Dali::Toolkit::WebView::ClearHistory()
202 * @brief Clears all tiles resources of Web.
204 void ClearAllTilesResources();
207 * @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal()
209 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadStartedSignal();
212 * @copydoc Dali::Toolkit::WebView::PageLoadInProgressSignal()
214 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadInProgressSignal();
217 * @copydoc Dali::Toolkit::WebView::PageLoadFinishedSignal()
219 Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadFinishedSignal();
222 * @copydoc Dali::Toolkit::WebView::PageLoadErrorSignal()
224 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
227 * @copydoc Dali::Toolkit::WebView::ScrollEdgeReachedSignal()
229 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
232 * @copydoc Dali::Toolkit::WebView::UrlChangedSignal()
234 Dali::Toolkit::WebView::WebViewUrlChangedSignalType& UrlChangedSignal();
236 public: // Properties
238 * @brief Called when a property of an object of this type is set.
240 * @param[in] object The object whose property is set.
241 * @param[in] index The property index.
242 * @param[in] value The new property value.
244 static void SetProperty(Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value);
247 * @brief Called to retrieve a property of an object of this type.
249 * @param[in] object The object whose property is to be retrieved.
250 * @param[in] index The property index.
251 * @return The current value of the property.
253 static Dali::Property::Value GetProperty(Dali::BaseObject* object, Dali::Property::Index propertyIndex);
256 * Connects a callback function with the object's signals.
257 * @param[in] object The object providing the signal.
258 * @param[in] tracker Used to disconnect the signal.
259 * @param[in] signalName The signal to connect to.
260 * @param[in] functor A newly allocated FunctorDelegate.
261 * @return True if the signal was connected.
262 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
264 static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
266 private: // From Control
268 * @copydoc Toolkit::Control::OnInitialize()
270 void OnInitialize() override;
273 * @copydoc Toolkit::Control::GetNaturalSize
275 Vector3 GetNaturalSize() override;
278 * @copydoc Toolkit::Control::OnKeyEvent()
280 bool OnKeyEvent(const Dali::KeyEvent& event) override;
283 * @copydoc Toolkit::Control::OnKeyInputFocusGained()
285 void OnKeyInputFocusGained() override;
288 * @copydoc Toolkit::Control::OnKeyInputFocusLost()
290 void OnKeyInputFocusLost() override;
293 * @copydoc Toolkit::Control::OnSceneConnection()
295 void OnSceneConnection(int depth) override;
299 WebView(const WebView& webView);
301 WebView& operator=(const WebView& webView);
304 * @brief Sets an absolute scroll of the given view.
305 * @param[in] x The coordinate x of scroll
306 * @param[in] y The coordinate y of scroll
308 void SetScrollPosition(int x, int y);
311 * @brief Gets the current scroll position of the given view.
312 * @param[out] x The coordinate x of scroll
313 * @param[out] y The coordinate y of scroll
315 Dali::Vector2 GetScrollPosition() const;
318 * @brief Gets the possible scroll size of the given view.
319 * @param[out] width The width of scroll size
320 * @param[out] height The height of scroll size
322 Dali::Vector2 GetScrollSize() const;
325 * @brief Gets the last known content's size.
326 * @param[out] width The width of content's size
327 * @param[out] height The height of content's size
329 Dali::Vector2 GetContentSize() const;
332 * @brief Returns the title of the Web.
334 * @return The title of web page
336 std::string GetTitle() const;
339 * @brief Sets the background color of web page.
340 * @param[in] color The value of background color.
342 void SetDocumentBackgroundColor(Dali::Vector4 color);
345 * @brief Clears tiles when hidden.
347 * @param[in] cleared Whether tiles are cleared or not
349 void ClearTilesWhenHidden(bool cleared);
352 * @brief Sets multiplier of cover area of tile.
354 * @param[in] multiplier The multiplier of cover area
356 void SetTileCoverAreaMultiplier(float multiplier);
359 * @brief Enables cursor by client.
360 * @param[in] enabled Whether cursor is enabled or not.
362 void EnableCursorByClient(bool enabled);
365 * @brief Gets the selected text.
366 * @return The selected text
368 std::string GetSelectedText() const;
371 * @brief Get user agent string.
372 * @return The string value of user agent
374 const std::string& GetUserAgent() const;
377 * @brief Set user agent string.
378 * @param[in] userAgent The string value of user agent
380 void SetUserAgent(const std::string& userAgent);
383 * @brief Updates display area of web view.
384 * @param[in] source The soource triggers Notification.
386 void UpdateDisplayArea(Dali::PropertyNotification& source);
389 * @brief Enable/Disable video hole for video playing.
390 * @param[in] enabled True if video hole is enabled, false otherwise.
392 void EnableVideoHole(bool enabled);
395 * @brief Enable blend mode.
396 * @param[in] blendEnabled True if turn on blend mode, false otherwise.
398 void EnableBlendMode(bool blendEnabled);
401 * @brief Enables/disables mouse events. The default is enabled.
403 * @param[in] enabled True if mouse events are enabled, false otherwise
405 void EnableMouseEvents(bool enabled);
408 * @brief Enables/disables key events. The default is enabled.
410 * @param[in] enabled True if key events enabled, false otherwise
412 void EnableKeyEvents(bool enabled);
415 * @brief Callback function to be called when page load started.
416 * @param[in] url The url currently being loaded
418 void OnPageLoadStarted(const std::string& url);
421 * @brief Callback function to be called when page is loading in progress.
422 * @param[in] url The url currently being loaded
424 void OnPageLoadInProgress(const std::string& url);
427 * @brief Callback function to be called when page load finished.
428 * @param[in] url The url currently being loaded
430 void OnPageLoadFinished(const std::string& url);
433 * @brief Callback function to be called when there is an error in page loading.
434 * @param[in] url The url currently being loaded
435 * @param[in] errorCode The error code
437 void OnPageLoadError(const std::string& url, int errorCode);
440 * @brief Callback function to be called when scroll edge is reached.
441 * @param[in] e The scroll edge reached.
443 void OnScrollEdgeReached(Dali::WebEnginePlugin::ScrollEdge edge);
446 * @brief Callback function to be called when url is changed.
447 * @param[in] url The url currently being loaded
449 void OnUrlChanged(const std::string& url);
452 * Signal occurs when the Web View has been touched.
453 * @param[in] actor The Actor Touched
454 * @param[in] touch The Touch Data.
455 * @return Whether to consume event or not.
457 bool OnTouchEvent(Actor actor, const Dali::TouchEvent& touch);
460 * Signal occurs when the Web View has been hovered.
461 * @param[in] actor The Actor Hovered
462 * @param[in] hover The Hover Data.
463 * @return Whether to consume event or not.
465 bool OnHoverEvent(Actor actor, const Dali::HoverEvent& hover);
468 * Signal occurs when the Web View receives wheel event.
469 * @param[in] actor The Actor that receives Wheel event.
470 * @param[in] wheel The Wheel Data.
471 * @return Whether to consume event or not.
473 bool OnWheelEvent(Actor actor, const Dali::WheelEvent& wheel);
477 Dali::Toolkit::Visual::Base mVisual;
478 Dali::Size mWebViewSize;
479 Dali::WebEngine mWebEngine;
481 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadStartedSignal;
482 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadInProgressSignal;
483 Dali::Toolkit::WebView::WebViewPageLoadSignalType mPageLoadFinishedSignal;
484 Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal;
485 Dali::Toolkit::WebView::WebViewUrlChangedSignalType mUrlChangedSignal;
486 Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
488 std::unique_ptr<Dali::Toolkit::WebContext> mWebContext;
489 std::unique_ptr<Dali::Toolkit::WebCookieManager> mWebCookieManager;
490 std::unique_ptr<Dali::Toolkit::WebSettings> mWebSettings;
491 std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
492 Dali::Toolkit::ImageView mFaviconView;
494 Dali::PropertyNotification mPositionUpdateNotification;
495 Dali::PropertyNotification mSizeUpdateNotification;
496 Dali::PropertyNotification mScaleUpdateNotification;
497 bool mVideoHoleEnabled;
498 Dali::Rect<int> mWebViewArea;
499 bool mMouseEventsEnabled;
500 bool mKeyEventsEnabled;
503 } // namespace Internal
505 inline Toolkit::Internal::WebView& GetImpl(Toolkit::WebView& handle)
507 DALI_ASSERT_ALWAYS(handle);
508 Dali::RefObject& impl = handle.GetImplementation();
509 return static_cast<Toolkit::Internal::WebView&>(impl);
512 inline const Toolkit::Internal::WebView& GetImpl(const Toolkit::WebView& handle)
514 DALI_ASSERT_ALWAYS(handle);
515 const Dali::RefObject& impl = handle.GetImplementation();
516 return static_cast<const Toolkit::Internal::WebView&>(impl);
519 } // namespace Toolkit
523 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H