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