88500cc7e9dbbb9e819d6c545c2505966155d0ef
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / web-engine-plugin.h
1 #ifndef DALI_WEB_ENGINE_PLUGIN_H
2 #define DALI_WEB_ENGINE_PLUGIN_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
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>
25 #include <functional>
26
27 namespace Dali
28 {
29 class KeyEvent;
30 class PixelData;
31 class TouchEvent;
32 class WebEngineBackForwardList;
33 class WebEngineContext;
34 class WebEngineCookieManager;
35 class WebEngineSettings;
36
37 /**
38  * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
39  * A concrete implementation must be created for each platform and provided as dynamic library.
40  */
41 class WebEnginePlugin
42 {
43 public:
44   /**
45    * @brief WebEngine signal type related with page loading.
46    */
47   using WebEnginePageLoadSignalType = Signal<void(const std::string&)>;
48
49   /**
50    * @brief WebView signal type related with page loading error.
51    */
52   using WebEnginePageLoadErrorSignalType = Signal<void(const std::string&, int)>;
53
54   // forward declaration.
55   enum class ScrollEdge;
56
57   /**
58    * @brief WebView signal type related with scroll edge reached.
59    */
60   using WebEngineScrollEdgeReachedSignalType = Signal<void(const ScrollEdge)>;
61
62   /**
63    * @brief Enumeration for the scroll edge.
64    */
65   enum class ScrollEdge
66   {
67     LEFT,   ///< Left edge reached.
68     RIGHT,  ///< Right edge reached.
69     TOP,    ///< Top edge reached.
70     BOTTOM, ///< Bottom edge reached.
71   };
72
73   /**
74    * @brief Constructor.
75    */
76   WebEnginePlugin() = default;
77
78   /**
79    * @brief Destructor.
80    */
81   virtual ~WebEnginePlugin() = default;
82
83   /**
84    * @brief Creates WebEngine instance.
85    *
86    * @param [in] width The width of Web
87    * @param [in] height The height of Web
88    * @param [in] locale The locale of Web
89    * @param [in] timezoneId The timezoneID of Web
90    */
91   virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
92
93   /**
94    * @brief Creates WebEngine instance.
95    *
96    * @param [in] width The width of Web
97    * @param [in] height The height of Web
98    * @param [in] argc The count of application arguments
99    * @param [in] argv The string array of application arguments
100    */
101   virtual void Create(int width, int height, int argc, char** argv) = 0;
102
103   /**
104    * @brief Destroys WebEngine instance.
105    */
106   virtual void Destroy() = 0;
107
108   /**
109    * @brief Get settings of WebEngine.
110    */
111   virtual WebEngineSettings& GetSettings() const = 0;
112
113   /**
114    * @brief Get context of WebEngine.
115    */
116   virtual WebEngineContext& GetContext() const = 0;
117
118   /**
119    * @brief Get cookie manager of WebEngine.
120    */
121   virtual WebEngineCookieManager& GetCookieManager() const = 0;
122
123   /**
124    * @brief Get back-forward list of WebEngine.
125    */
126   virtual WebEngineBackForwardList& GetBackForwardList() const = 0;
127
128   /**
129    * @brief Loads a web page based on a given URL.
130    *
131    * @param [in] url The URL of the resource to load
132    */
133   virtual void LoadUrl(const std::string& url) = 0;
134
135   /**
136    * @brief Returns the title of the Web.
137    *
138    * @return The title of web page
139    */
140   virtual std::string GetTitle() const = 0;
141
142   /**
143    * @brief Returns the Favicon of the Web.
144    *
145    * @return Favicon of Dali::PixelData& type
146    */
147   virtual Dali::PixelData GetFavicon() const = 0;
148
149   /**
150    * @brief Gets image to render.
151    */
152   virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
153
154   /**
155    * @brief Returns the URL of the Web.
156    *
157    * @return Url of string type
158    */
159   virtual const std::string& GetUrl() = 0;
160
161   /**
162    * @brief Loads a given string as web contents.
163    *
164    * @param [in] htmlString The string to use as the contents of the web page
165    */
166   virtual void LoadHtmlString(const std::string& htmlString) = 0;
167
168   /**
169    * @brief Reloads the Web.
170    */
171   virtual void Reload() = 0;
172
173   /**
174    * @brief Stops loading web contents on the current page.
175    */
176   virtual void StopLoading() = 0;
177
178   /**
179    * @brief Suspends the operation associated with the view.
180    */
181   virtual void Suspend() = 0;
182
183   /**
184    * @brief Resumes the operation associated with the view object after calling Suspend().
185    */
186   virtual void Resume() = 0;
187
188   /**
189    * @brief Scrolls the webpage of view by deltaX and deltaY.
190    */
191   virtual void ScrollBy(int deltaX, int deltaY) = 0;
192
193   /**
194    * @brief Scroll to the specified position of the given view.
195    */
196   virtual void SetScrollPosition(int x, int y) = 0;
197
198   /**
199    * @brief Gets the current scroll position of the given view.
200    */
201   virtual Dali::Vector2 GetScrollPosition() const = 0;
202
203   /**
204    * @brief Gets the possible scroll size of the given view.
205    */
206   virtual Dali::Vector2 GetScrollSize() const = 0;
207
208   /**
209    * @brief Gets the last known content's size.
210    */
211   virtual Dali::Vector2 GetContentSize() const = 0;
212
213   /**
214    * @brief Returns whether forward is possible.
215    *
216    * @return True if forward is possible, false otherwise
217    */
218   virtual bool CanGoForward() = 0;
219
220   /**
221    * @brief Goes to forward.
222    */
223   virtual void GoForward() = 0;
224
225   /**
226    * @brief Returns whether backward is possible.
227    *
228    * @return True if backward is possible, false otherwise
229    */
230   virtual bool CanGoBack() = 0;
231
232   /**
233    * @brief Goes to back.
234    */
235   virtual void GoBack() = 0;
236
237   /**
238    * @brief Evaluates JavaScript code represented as a string.
239    *
240    * @param[in] script The JavaScript code
241    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
242    */
243   virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
244
245   /**
246    * @brief Add a message handler into JavaScript.
247    *
248    * @param[in] exposedObjectName The name of exposed object
249    * @param[in] handler The callback function
250    */
251   virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
252
253   /**
254    * @brief Clears all tiles resources of Web.
255    */
256   virtual void ClearAllTilesResources() = 0;
257
258   /**
259    * @brief Clears the history of Web.
260    */
261   virtual void ClearHistory() = 0;
262
263   /**
264    * @brief Get user agent string.
265    *
266    * @return The string value of user agent
267    */
268   virtual const std::string& GetUserAgent() const = 0;
269
270   /**
271    * @brief Set user agent string.
272    *
273    * @param[in] userAgent The string value of user agent
274    */
275   virtual void SetUserAgent(const std::string& userAgent) = 0;
276
277   /**
278    * @brief Sets size of Web Page.
279    */
280   virtual void SetSize(int width, int height) = 0;
281
282   /**
283    * @brief Sends Touch Events.
284    */
285   virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
286
287   /**
288    * @brief Sends Key Events.
289    */
290   virtual bool SendKeyEvent(const KeyEvent& event) = 0;
291
292   /**
293    * @brief Sets focus.
294    */
295   virtual void SetFocus(bool focused) = 0;
296
297   /**
298    * @brief Update display area.
299    * @param[in] displayArea The display area need be updated.
300    */
301   virtual void UpdateDisplayArea(Dali::Rect<int> displayArea) = 0;
302
303   /**
304    * @brief Enable video hole.
305    * @param[in] enabled True if enabled, false othewise.
306    */
307   virtual void EnableVideoHole(bool enabled) = 0;
308
309   /**
310    * @brief Connects to this signal to be notified when page loading is started.
311    *
312    * @return A signal object to connect with.
313    */
314   virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
315
316   /**
317    * @brief Connects to this signal to be notified when page loading is finished.
318    *
319    * @return A signal object to connect with.
320    */
321   virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
322
323   /**
324    * @brief Connects to this signal to be notified when an error occurs in page loading.
325    *
326    * @return A signal object to connect with.
327    */
328   virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
329
330   /**
331    * @brief Connects to this signal to be notified when scroll edge is reached.
332    *
333    * @return A signal object to connect with.
334    */
335   virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
336 };
337
338 } // namespace Dali
339
340 #endif