1 #ifndef DALI_WEB_ENGINE_H
2 #define DALI_WEB_ENGINE_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/public-api/object/base-handle.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
26 #include <dali/public-api/dali-adaptor-common.h>
35 } // namespace Adaptor
37 } // namespace Internal
40 * @brief Proxy class to dynamically load, use and unload web engine plugin.
42 * The purpose of this class is to dynamically load the web engine plugin if and when its needed.
43 * So we don't slow down every application startup if they never need web engine.
45 class DALI_ADAPTOR_API WebEngine : public BaseHandle
59 * @brief Creates a new instance of a WebEngine.
61 static WebEngine New();
64 * @brief Copy constructor.
66 * @param[in] WebEngine WebEngine to copy. The copied WebEngine will point at the same implementation
68 WebEngine(const WebEngine& WebEngine);
71 * @brief Assignment operator.
73 * @param[in] WebEngine The WebEngine to assign from.
74 * @return The updated WebEngine.
76 WebEngine& operator=(const WebEngine& WebEngine);
79 * @brief Downcast a handle to WebEngine handle.
81 * If handle points to a WebEngine the downcast produces valid
82 * handle. If not the returned handle is left uninitialized.
84 * @param[in] handle Handle to an object
85 * @return Handle to a WebEngine or an uninitialized handle
87 static WebEngine DownCast(BaseHandle handle);
90 * @brief Creates WebEngine instance.
92 * @param [in] width The width of Web
93 * @param [in] height The height of Web
94 * @param [in] locale The locale of Web
95 * @param [in] timezoneId The timezoneID of Web
97 void Create(int width, int height, const std::string& locale, const std::string& timezoneId);
100 * @brief Creates WebEngine instance.
102 * @param [in] width The width of Web
103 * @param [in] height The height of Web
104 * @param [in] argc The count of application arguments
105 * @param [in] argv The string array of application arguments
107 void Create(int width, int height, int argc, char** argv);
110 * @brief Destroys WebEngine instance.
115 * @brief Gets native image source to render.
117 NativeImageInterfacePtr GetNativeImageSource();
120 * @brief Get settings of WebEngine.
122 Dali::WebEngineSettings& GetSettings() const;
125 * @brief Get context of WebEngine.
127 Dali::WebEngineContext& GetContext() const;
130 * @brief Get cookie manager of WebEngine.
132 Dali::WebEngineCookieManager& GetCookieManager() const;
135 * @brief Get back-forward list of WebEngine.
137 Dali::WebEngineBackForwardList& GetBackForwardList() const;
140 * @brief Loads a web page based on a given URL.
142 * @param [in] url The URL of the resource to load
144 void LoadUrl(const std::string& url);
147 * @brief Returns the title of the Web.
149 * @return The title of web page
151 std::string GetTitle() const;
154 * @brief Returns the Favicon of the Web.
156 * @return FavIcon of Dali::PixelData& type
158 Dali::PixelData GetFavicon() const;
161 * @brief Gets the url.
163 const std::string& GetUrl();
166 * @brief Loads a given string as web contents.
168 * @param [in] htmlString The string to use as the contents of the web page
170 void LoadHtmlString(const std::string& htmlString);
173 * @brief Reloads the Web.
178 * @brief Stops loading web contents on the current page.
183 * @brief Suspends the operation associated with the view.
188 * @brief Resumes the operation associated with the view object after calling Suspend().
193 * @brief Scrolls the webpage of view by deltaX and deltaY.
195 void ScrollBy(int deltaX, int deltaY);
198 * @brief Sets an absolute scroll of the given view.
200 void SetScrollPosition(int x, int y);
203 * @brief Gets the current scroll position of the given view.
205 Dali::Vector2 GetScrollPosition() const;
208 * @brief Gets the possible scroll size of the given view.
210 Dali::Vector2 GetScrollSize() const;
213 * @brief Gets the last known content's size.
215 Dali::Vector2 GetContentSize() const;
218 * @brief Returns whether forward is possible.
220 * @return True if forward is possible, false otherwise
225 * @brief Goes to forward.
230 * @brief Returns whether backward is possible.
232 * @return True if backward is possible, false otherwise
237 * @brief Goes to back.
242 * @brief Evaluates JavaScript code represented as a string.
244 * @param[in] script The JavaScript code
245 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
247 void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
250 * @brief Add a message handler into JavaScript.
252 * @param[in] exposedObjectName The name of exposed object
253 * @param[in] handler The callback function
255 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
258 * @brief Register a callback for JavaScript alert.
260 * @param[in] callback The callback function
262 void RegisterJavaScriptAlertCallback(Dali::WebEnginePlugin::JavaScriptAlertCallback callback);
265 * @brief Reply for JavaScript alert.
267 void JavaScriptAlertReply();
270 * @brief Register a callback for JavaScript confirm.
272 * @param[in] callback The callback function
274 void RegisterJavaScriptConfirmCallback(Dali::WebEnginePlugin::JavaScriptConfirmCallback callback);
277 * @brief Reply for JavaScript confirm.
278 * @param[in] confirmed True if confirmed, false otherwise.
280 void JavaScriptConfirmReply(bool confirmed);
283 * @brief Register a callback for JavaScript prompt.
285 * @param[in] callback The callback function
287 void RegisterJavaScriptPromptCallback(Dali::WebEnginePlugin::JavaScriptPromptCallback callback);
290 * @brief Reply for JavaScript prompt.
291 * @param[in] result The result returned from input-field in prompt popup.
293 void JavaScriptPromptReply(const std::string& result);
296 * @brief Clears the history of Web.
301 * @brief Clears all tiles resources of Web.
303 void ClearAllTilesResources();
306 * @brief Get user agent string.
308 * @return The string value of user agent
310 const std::string& GetUserAgent() const;
313 * @brief Set user agent string.
315 * @param[in] userAgent The string value of user agent
317 void SetUserAgent(const std::string& userAgent);
320 * @brief Sets the size of Web Pages.
322 void SetSize(int width, int height);
325 * @brief Sets background color of web page.
327 * @param[in] color Background color
329 void SetDocumentBackgroundColor(Dali::Vector4 color);
332 * @brief Clears tiles when hidden.
334 * @param[in] cleared Whether tiles are cleared or not
336 void ClearTilesWhenHidden(bool cleared);
339 * @brief Sets multiplier of cover area of tile.
341 * @param[in] multiplier The multiplier of cover area
343 void SetTileCoverAreaMultiplier(float multiplier);
346 * @brief Enables cursor by client.
348 * @param[in] enabled Whether cursor is enabled or not
350 void EnableCursorByClient(bool enabled);
353 * @brief Gets the selected text.
355 * @return the selected text
357 std::string GetSelectedText() const;
360 * @brief Sends Touch Events.
362 bool SendTouchEvent(const TouchEvent& touch);
365 * @brief Sends key Events.
367 bool SendKeyEvent(const KeyEvent& event);
371 * @param[in] focused True if web view is focused, false otherwise
373 void SetFocus(bool focused);
376 * @brief Enables/disables mouse events. The default is enabled.
378 * @param[in] enabled True if mouse events are enabled, false otherwise
380 void EnableMouseEvents( bool enabled );
383 * @brief Enables/disables key events. The default is enabled.
385 * @param[in] enabled True if key events are enabled, false otherwise
387 void EnableKeyEvents( bool enabled );
390 * @brief Update display area.
391 * @param[in] displayArea The area to display web page.
393 void UpdateDisplayArea(Dali::Rect<int> displayArea);
396 * @brief Enable video hole.
397 * @param[in] enabled True if video hole is enabled, false otherwise
399 void EnableVideoHole(bool enabled);
402 * @brief Sends hover events.
403 * @param[in] event The hover event would be sent.
405 bool SendHoverEvent( const HoverEvent& event );
408 * @brief Sends wheel events.
409 * @param[in] event The wheel event would be sent.
411 bool SendWheelEvent( const WheelEvent& event );
414 * @brief Connects to this signal to be notified when page loading is started.
416 * @return A signal object to connect with.
418 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
421 * @brief Connects to this signal to be notified when page loading is in progress.
423 * @return A signal object to connect with.
425 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal();
428 * @brief Connects to this signal to be notified when page loading is finished.
430 * @return A signal object to connect with.
432 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
435 * @brief Connects to this signal to be notified when an error occurs in page loading.
437 * @return A signal object to connect with.
439 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
442 * @brief Connects to this signal to be notified when scroll edge is reached.
444 * @return A signal object to connect with.
446 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
449 * @brief Connects to this signal to be notified when url is changed.
451 * @return A signal object to connect with.
453 Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal();
456 * @brief Connects to this signal to be notified when form repost decision is requested.
458 * @return A signal object to connect with.
460 Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal();
463 * @brief Connects to this signal to be notified when frame is rendered.
465 * @return A signal object to connect with.
467 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal();
469 private: // Not intended for application developers
471 * @brief Internal constructor
473 explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
478 #endif // DALI_WEB_ENGINE_H