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