Support scroll in web engine.
[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) 2020 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/signals/dali-signal.h>
24 #include <functional>
25
26 namespace Dali
27 {
28 class KeyEvent;
29 class TouchEvent;
30
31 /**
32  * @brief WebEnginePlugin is an abstract interface, used by dali-adaptor to access WebEngine plugin.
33  * A concrete implementation must be created for each platform and provided as dynamic library.
34  */
35 class WebEnginePlugin
36 {
37 public:
38   /**
39    * @brief WebEngine signal type related with page loading.
40    */
41   typedef Signal<void(const std::string&)> WebEnginePageLoadSignalType;
42
43   /**
44    * @brief WebView signal type related with page loading error.
45    */
46   typedef Signal<void(const std::string&, int)> WebEnginePageLoadErrorSignalType;
47
48   // forward declaration.
49   enum class ScrollEdge;
50
51   /**
52    * @brief WebView signal type related with scroll edge reached.
53    */
54   typedef Signal< void( const ScrollEdge )> WebEngineScrollEdgeReachedSignalType;
55
56   /**
57    * @brief Enumeration for cache model options.
58    */
59   enum class CacheModel
60   {
61     /**
62      * @brief Use the smallest cache capacity.
63      */
64     DOCUMENT_VIEWER,
65
66     /**
67      * @brief Use the bigger cache capacity than DocumentBrowser.
68      */
69     DOCUMENT_BROWSER,
70
71     /**
72      * @brief Use the biggest cache capacity.
73      */
74     PRIMARY_WEB_BROWSER
75   };
76
77   /**
78    * @brief Enumeration for the cookies accept policies.
79    */
80   enum class CookieAcceptPolicy
81   {
82     /**
83      * @brief Accepts every cookie sent from any page.
84      */
85     ALWAYS,
86
87     /**
88      * @brief Rejects all the cookies.
89      */
90     NEVER,
91
92     /**
93      * @brief Accepts only cookies set by the main document that is loaded.
94      */
95     NO_THIRD_PARTY
96   };
97
98   /**
99    * @brief Enumeration for the scroll edge.
100    */
101   enum class ScrollEdge
102   {
103     LEFT,   ///< Left edge reached.
104     RIGHT,  ///< Right edge reached.
105     TOP,    ///< Top edge reached.
106     BOTTOM, ///< Bottom edge reached.
107   };
108
109   /**
110    * @brief Constructor.
111    */
112   WebEnginePlugin() = default;
113
114   /**
115    * @brief Destructor.
116    */
117   virtual ~WebEnginePlugin() = default;
118
119   /**
120    * @brief Creates WebEngine instance.
121    *
122    * @param [in] width The width of Web
123    * @param [in] height The height of Web
124    * @param [in] locale The locale of Web
125    * @param [in] timezoneId The timezoneID of Web
126    */
127   virtual void Create(int width, int height, const std::string& locale, const std::string& timezoneId) = 0;
128
129   /**
130    * @brief Destroys WebEngine instance.
131    */
132   virtual void Destroy() = 0;
133
134   /**
135    * @brief Loads a web page based on a given URL.
136    *
137    * @param [in] url The URL of the resource to load
138    */
139   virtual void LoadUrl(const std::string& url) = 0;
140
141   /**
142    * @brief Gets image to render.
143    */
144   virtual NativeImageInterfacePtr GetNativeImageSource() = 0;
145
146   /**
147    * @brief Returns the URL of the Web.
148    *
149    * @return Url of string type
150    */
151   virtual const std::string& GetUrl() = 0;
152
153   /**
154    * @brief Loads a given string as web contents.
155    *
156    * @param [in] htmlString The string to use as the contents of the web page
157    */
158   virtual void LoadHTMLString(const std::string& htmlString) = 0;
159
160   /**
161    * @brief Reloads the Web.
162    */
163   virtual void Reload() = 0;
164
165   /**
166    * @brief Stops loading web contents on the current page.
167    */
168   virtual void StopLoading() = 0;
169
170   /**
171    * @brief Suspends the operation associated with the view.
172    */
173   virtual void Suspend() = 0;
174
175   /**
176    * @brief Resumes the operation associated with the view object after calling Suspend().
177    */
178   virtual void Resume() = 0;
179
180   /**
181    * @brief Scrolls the webpage of view by deltaX and deltaY.
182    */
183   virtual void ScrollBy( int deltaX, int deltaY ) = 0;
184
185   /**
186    * @brief Scroll to the specified position of the given view.
187    */
188   virtual void SetScrollPosition( int x, int y ) = 0;
189
190   /**
191    * @brief Gets the current scroll position of the given view.
192    */
193   virtual void GetScrollPosition( int& x, int& y ) const = 0;
194
195   /**
196    * @brief Gets the possible scroll size of the given view.
197    */
198   virtual void GetScrollSize( int& width, int& height ) const = 0;
199
200   /**
201    * @brief Gets the last known content's size.
202    */
203   virtual void GetContentSize( int& width, int& height ) const = 0;
204
205   /**
206    * @brief Returns whether forward is possible.
207    *
208    * @return True if forward is possible, false otherwise
209    */
210   virtual bool CanGoForward() = 0;
211
212   /**
213    * @brief Goes to forward.
214    */
215   virtual void GoForward() = 0;
216
217   /**
218    * @brief Returns whether backward is possible.
219    *
220    * @return True if backward is possible, false otherwise
221    */
222   virtual bool CanGoBack() = 0;
223
224   /**
225    * @brief Goes to back.
226    */
227   virtual void GoBack() = 0;
228
229   /**
230    * @brief Evaluates JavaScript code represented as a string.
231    *
232    * @param[in] script The JavaScript code
233    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
234    */
235   virtual void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler) = 0;
236
237   /**
238    * @brief Add a message handler into JavaScript.
239    *
240    * @param[in] exposedObjectName The name of exposed object
241    * @param[in] handler The callback function
242    */
243   virtual void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler) = 0;
244
245   /**
246    * @brief Clears the history of Web.
247    */
248   virtual void ClearHistory() = 0;
249
250   /**
251    * @brief Clears the cache of Web.
252    */
253   virtual void ClearCache() = 0;
254
255   /**
256    * @brief Clears all the cookies of Web.
257    */
258   virtual void ClearCookies() = 0;
259
260   /**
261    * @brief Get cache model option. The default is DOCUMENT_VIEWER.
262    *
263    * @return The cache model option
264    */
265   virtual CacheModel GetCacheModel() const = 0;
266
267   /**
268    * @brief Set cache model option. The default is DOCUMENT_VIEWER.
269    *
270    * @param[in] cacheModel The cache model option
271    */
272   virtual void SetCacheModel(CacheModel cacheModel) = 0;
273
274   /**
275    * @brief Gets the cookie acceptance policy. The default is NO_THIRD_PARTY.
276    *
277    * @return The cookie acceptance policy
278    */
279   virtual CookieAcceptPolicy GetCookieAcceptPolicy() const = 0;
280
281   /**
282    * @brief Sets the cookie acceptance policy. The default is NO_THIRD_PARTY.
283    *
284    * @param[in] policy The cookie acceptance policy
285    */
286   virtual void SetCookieAcceptPolicy(CookieAcceptPolicy policy) = 0;
287
288   /**
289    * @brief Get user agent string.
290    *
291    * @return The string value of user agent
292    */
293   virtual const std::string& GetUserAgent() const = 0;
294
295   /**
296    * @brief Set user agent string.
297    *
298    * @param[in] userAgent The string value of user agent
299    */
300   virtual void SetUserAgent(const std::string& userAgent) = 0;
301
302   /**
303    * @brief Returns whether JavaScript can be executable. The default is true.
304    *
305    * @return true if JavaScript executing is enabled, false otherwise
306    */
307   virtual bool IsJavaScriptEnabled() const = 0;
308
309   /**
310    * @brief Enables/disables JavaScript executing. The default is enabled.
311    *
312    * @param[in] enabled True if JavaScript executing is enabled, false otherwise
313    */
314   virtual void EnableJavaScript(bool enabled) = 0;
315
316   /**
317    * @brief Returns whether images can be loaded automatically. The default is true.
318    *
319    * @return true if images are loaded automatically, false otherwise
320    */
321   virtual bool AreImagesAutomaticallyLoaded() const = 0;
322
323   /**
324    * @brief Enables/disables auto loading of images. The default is enabled.
325    *
326    * @param[in] automatic True if images are loaded automatically, false otherwise
327    */
328   virtual void LoadImagesAutomatically(bool automatic) = 0;
329
330   /**
331    * @brief Gets the default text encoding name (e.g. UTF-8).
332    *
333    * @return The default text encoding name
334    */
335   virtual const std::string& GetDefaultTextEncodingName() const = 0;
336
337   /**
338    * @brief Sets the default text encoding name (e.g. UTF-8).
339    *
340    * @param[in] defaultTextEncodingName The default text encoding name
341    */
342   virtual void SetDefaultTextEncodingName(const std::string& defaultTextEncodingName) = 0;
343
344   /**
345    * @brief Returns the default font size in pixel. The default value is 16.
346    *
347    * @return The default font size
348    */
349   virtual int GetDefaultFontSize() const = 0;
350
351   /**
352    * @brief Sets the default font size in pixel. The default value is 16.
353    *
354    * @param[in] defaultFontSize A new default font size to set
355    */
356   virtual void SetDefaultFontSize(int defaultFontSize) = 0;
357
358   /**
359    * @brief Sets size of Web Page.
360    */
361   virtual void SetSize(int width, int height) = 0;
362
363   /**
364    * @brief Sends Touch Events.
365    */
366   virtual bool SendTouchEvent(const TouchEvent& touch) = 0;
367
368   /**
369    * @brief Sends Key Events.
370    */
371   virtual bool SendKeyEvent(const KeyEvent& event) = 0;
372
373   /**
374    * @brief Sets focus.
375    */
376   virtual void SetFocus( bool focused ) = 0;
377
378   /**
379    * @brief Connects to this signal to be notified when page loading is started.
380    *
381    * @return A signal object to connect with.
382    */
383   virtual WebEnginePageLoadSignalType& PageLoadStartedSignal() = 0;
384
385   /**
386    * @brief Connects to this signal to be notified when page loading is finished.
387    *
388    * @return A signal object to connect with.
389    */
390   virtual WebEnginePageLoadSignalType& PageLoadFinishedSignal() = 0;
391
392   /**
393    * @brief Connects to this signal to be notified when an error occurs in page loading.
394    *
395    * @return A signal object to connect with.
396    */
397   virtual WebEnginePageLoadErrorSignalType& PageLoadErrorSignal() = 0;
398
399   /**
400    * @brief Connects to this signal to be notified when scroll edge is reached.
401    *
402    * @return A signal object to connect with.
403    */
404   virtual WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal() = 0;
405 };
406
407 } // namespace Dali
408
409 #endif