1 #ifndef DALI_WEB_ENGINE_PLUGIN_H
2 #define DALI_WEB_ENGINE_PLUGIN_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/images/native-image-interface.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/signals/dali-signal.h>
33 class WebEngineBackForwardList;
34 class WebEngineContext;
35 class WebEngineCookieManager;
36 class WebEngineFormRepostDecision;
37 class WebEngineSettings;
42 * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
43 * A concrete implementation must be created for each platform and provided as dynamic library.
49 * @brief WebEngine signal type related with page loading.
51 using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
54 * @brief WebView signal type related with page loading error.
56 using WebEnginePageLoadErrorSignalType = Signal<void(const std::string&, int)>;
58 // forward declaration.
59 enum class ScrollEdge;
62 * @brief WebView signal type related with scroll edge reached.
64 using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
67 * @brief WebView signal type related with page url changed.
69 using WebEngineUrlChangedSignalType = Signal<void(const std::string&)>;
72 * @brief Alert callback when JavaScript alert is called with a message.
73 * It returns true if a pop-up is created successfully, false otherwise.
75 using JavaScriptAlertCallback = std::function<bool(const std::string&)>;
78 * @brief Confirm callback when JavaScript confirm is called with a message.
79 * It returns true if a pop-up is created successfully, false otherwise.
81 using JavaScriptConfirmCallback = std::function<bool(const std::string&)>;
84 * @brief Prompt callback when JavaScript prompt is called with a message
85 * and an optional value that is the default value for the input field.
86 * It returns true if a pop-up is created successfully, false otherwise.
88 using JavaScriptPromptCallback = std::function<bool(const std::string&, const std::string&)>;
91 * @brief WebView signal type related with form repost decision.
93 using WebEngineFormRepostDecisionSignalType = Signal<void(std::shared_ptr<Dali::WebEngineFormRepostDecision>)>;
96 * @brief WebView signal type related with frame rendered.
98 using WebEngineFrameRenderedSignalType = Signal<void(void)>;
101 * @brief Enumeration for the scroll edge.
103 enum class ScrollEdge
105 LEFT, ///< Left edge reached.
106 RIGHT, ///< Right edge reached.
107 TOP, ///< Top edge reached.
108 BOTTOM, ///< Bottom edge reached.
112 * @brief Constructor.
114 WebEnginePlugin() = default;
119 virtual ~WebEnginePlugin() = default;
122 * @brief Creates WebEngine instance.
124 * @param [in] width The width of Web
125 * @param [in] height The height of Web
126 * @param [in] locale The locale of Web
127 * @param [in] timezoneId The timezoneID of Web
129 virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
132 * @brief Creates WebEngine instance.
134 * @param [in] width The width of Web
135 * @param [in] height The height of Web
136 * @param [in] argc The count of application arguments
137 * @param [in] argv The string array of application arguments
139 virtual void Create(int width, int height, int argc, char** argv) = 0;
142 * @brief Destroys WebEngine instance.
144 virtual void Destroy() = 0;
147 * @brief Get settings of WebEngine.
149 virtual WebEngineSettings& GetSettings() const = 0;
152 * @brief Get context of WebEngine.
154 virtual WebEngineContext& GetContext() const = 0;
157 * @brief Get cookie manager of WebEngine.
159 virtual WebEngineCookieManager& GetCookieManager() const = 0;
162 * @brief Get back-forward list of WebEngine.
164 virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
167 * @brief Loads a web page based on a given URL.
169 * @param [in] url The URL of the resource to load
171 virtual void LoadUrl(const std::string& url) = 0;
174 * @brief Returns the title of the Web.
176 * @return The title of web page
178 virtual std::string GetTitle() const = 0;
181 * @brief Returns the Favicon of the Web.
183 * @return Favicon of Dali::PixelData& type
185 virtual Dali::PixelData GetFavicon() const = 0;
188 * @brief Gets image to render.
190 virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
193 * @brief Returns the URL of the Web.
195 * @return Url of string type
197 virtual const std::string& GetUrl() = 0;
200 * @brief Loads a given string as web contents.
202 * @param [in] htmlString The string to use as the contents of the web page
204 virtual void LoadHtmlString(const std::string& htmlString) = 0;
207 * @brief Reloads the Web.
209 virtual void Reload() = 0;
212 * @brief Stops loading web contents on the current page.
214 virtual void StopLoading() = 0;
217 * @brief Suspends the operation associated with the view.
219 virtual void Suspend() = 0;
222 * @brief Resumes the operation associated with the view object after calling Suspend().
224 virtual void Resume() = 0;
227 * @brief Scrolls the webpage of view by deltaX and deltaY.
229 virtual void ScrollBy(int deltaX, int deltaY) = 0;
232 * @brief Scroll to the specified position of the given view.
234 virtual void SetScrollPosition(int x, int y) = 0;
237 * @brief Gets the current scroll position of the given view.
239 virtual Dali::Vector2 GetScrollPosition() const = 0;
242 * @brief Gets the possible scroll size of the given view.
244 virtual Dali::Vector2 GetScrollSize() const = 0;
247 * @brief Gets the last known content's size.
249 virtual Dali::Vector2 GetContentSize() const = 0;
252 * @brief Returns whether forward is possible.
254 * @return True if forward is possible, false otherwise
256 virtual bool CanGoForward() = 0;
259 * @brief Goes to forward.
261 virtual void GoForward() = 0;
264 * @brief Returns whether backward is possible.
266 * @return True if backward is possible, false otherwise
268 virtual bool CanGoBack() = 0;
271 * @brief Goes to back.
273 virtual void GoBack() = 0;
276 * @brief Evaluates JavaScript code represented as a string.
278 * @param[in] script The JavaScript code
279 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
281 virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
284 * @brief Add a message handler into JavaScript.
286 * @param[in] exposedObjectName The name of exposed object
287 * @param[in] handler The callback function
289 virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
292 * @brief Register a callback for JavaScript alert.
294 * @param[in] callback The callback function
296 virtual void RegisterJavaScriptAlertCallback(JavaScriptAlertCallback callback) = 0;
299 * @brief Reply for JavaScript alert.
301 virtual void JavaScriptAlertReply() = 0;
304 * @brief Register a callback for JavaScript confirm.
306 * @param[in] callback The callback function
308 virtual void RegisterJavaScriptConfirmCallback(JavaScriptConfirmCallback callback) = 0;
311 * @brief Reply for JavaScript confirm.
313 virtual void JavaScriptConfirmReply(bool confirmed) = 0;
316 * @brief Register a callback for JavaScript prompt.
318 * @param[in] callback The callback function
320 virtual void RegisterJavaScriptPromptCallback(JavaScriptPromptCallback callback) = 0;
323 * @brief Reply for JavaScript prompt.
325 virtual void JavaScriptPromptReply(const std::string& result) = 0;
328 * @brief Clears the history of Web.
330 virtual void ClearHistory() = 0;
333 * @brief Clears all tiles resources of Web.
335 virtual void ClearAllTilesResources() = 0;
338 * @brief Get user agent string.
340 * @return The string value of user agent
342 virtual const std::string& GetUserAgent() const = 0;
345 * @brief Set user agent string.
347 * @param[in] userAgent The string value of user agent
349 virtual void SetUserAgent(const std::string& userAgent) = 0;
352 * @brief Sets size of Web Page.
354 virtual void SetSize(int width, int height) = 0;
357 * @brief Sets background color of web page.
359 * @param[in] color Background color
361 virtual void SetDocumentBackgroundColor(Dali::Vector4 color) = 0;
364 * @brief Clears tiles when hidden.
366 * @param[in] cleared Whether tiles are cleared or not
368 virtual void ClearTilesWhenHidden(bool cleared) = 0;
371 * @brief Sets multiplier of cover area of tile.
373 * @param[in] multiplier The multiplier of cover area
375 virtual void SetTileCoverAreaMultiplier(float multiplier) = 0;
378 * @brief Enables cursor by client.
380 * @param[in] enabled Whether cursor is enabled or not
382 virtual void EnableCursorByClient(bool enabled) = 0;
385 * @brief Gets the selected text.
387 * @return the selected text
389 virtual std::string GetSelectedText() const = 0;
392 * @brief Sends Touch Events.
394 virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
397 * @brief Sends Key Events.
399 virtual bool SendKeyEvent(const KeyEvent& event) = 0;
402 * @brief Support mouse events or not.
403 * @param[in] enabled True if enabled, false othewise.
405 virtual void EnableMouseEvents( bool enabled ) = 0;
408 * @brief Support key events or not.
409 * @param[in] enabled True if enabled, false othewise.
411 virtual void EnableKeyEvents( bool enabled ) = 0;
415 * @param[in] focused True if focus is gained, false lost.
417 virtual void SetFocus(bool focused) = 0;
420 * @brief Update display area.
421 * @param[in] displayArea The display area need be updated.
423 virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
426 * @brief Enable video hole.
427 * @param[in] enabled True if enabled, false othewise.
429 virtual void EnableVideoHole(bool enabled) = 0;
432 * @brief Sends Hover Events.
433 * @param[in] event The hover event would be sent.
435 virtual bool SendHoverEvent( const HoverEvent& event ) = 0;
438 * @brief Sends Wheel Events.
439 * @param[in] event The wheel event would be sent.
441 virtual bool SendWheelEvent( const WheelEvent& event ) = 0;
444 * @brief Connects to this signal to be notified when page loading is started.
446 * @return A signal object to connect with.
448 virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
451 * @brief Connects to this signal to be notified when page loading is in progress.
453 * @return A signal object to connect with.
455 virtual WebEnginePageLoadSignalType& PageLoadInProgressSignal() = 0;
458 * @brief Connects to this signal to be notified when page loading is finished.
460 * @return A signal object to connect with.
462 virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
465 * @brief Connects to this signal to be notified when an error occurs in page loading.
467 * @return A signal object to connect with.
469 virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
472 * @brief Connects to this signal to be notified when scroll edge is reached.
474 * @return A signal object to connect with.
476 virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
479 * @brief Connects to this signal to be notified when url is changed.
481 * @return A signal object to connect with.
483 virtual WebEngineUrlChangedSignalType& UrlChangedSignal() = 0;
486 * @brief Connects to this signal to be notified when form repost decision is requested.
488 * @return A signal object to connect with.
490 virtual WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal() = 0;
493 * @brief Connects to this signal to be notified when frame is rendered.
495 * @return A signal object to connect with.
497 virtual WebEngineFrameRenderedSignalType& FrameRenderedSignal() = 0;