Merge "Add render threading for GlWindow" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / web-engine.h
1 #ifndef DALI_WEB_ENGINE_H
2 #define DALI_WEB_ENGINE_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/object/base-handle.h>
23
24 //INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
26 #include <dali/public-api/dali-adaptor-common.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 namespace Adaptor
33 {
34 class WebEngine;
35 } // namespace Adaptor
36
37 } // namespace Internal
38
39 /**
40  * @brief Proxy class to dynamically load, use and unload web engine plugin.
41  *
42  * The purpose of this class is to dynamically load the web engine plugin if and when its needed.
43  * So we don't slow down every application startup if they never need web engine.
44  */
45 class DALI_ADAPTOR_API WebEngine : public BaseHandle
46 {
47 public:
48   /**
49    * @brief Constructor.
50    */
51   WebEngine();
52
53   /**
54    * @brief Destructor.
55    */
56   ~WebEngine();
57
58   /**
59    * @brief Creates a new instance of a WebEngine.
60    */
61   static WebEngine New();
62
63   /**
64    * @brief Copy constructor.
65    *
66    * @param[in] WebEngine WebEngine to copy. The copied WebEngine will point at the same implementation
67    */
68   WebEngine(const WebEngine& WebEngine);
69
70   /**
71    * @brief Assignment operator.
72    *
73    * @param[in] WebEngine The WebEngine to assign from.
74    * @return The updated WebEngine.
75    */
76   WebEngine& operator=(const WebEngine& WebEngine);
77
78   /**
79    * @brief Downcast a handle to WebEngine handle.
80    *
81    * If handle points to a WebEngine the downcast produces valid
82    * handle. If not the returned handle is left uninitialized.
83    *
84    * @param[in] handle Handle to an object
85    * @return Handle to a WebEngine or an uninitialized handle
86    */
87   static WebEngine DownCast(BaseHandle handle);
88
89   /**
90    * @brief Creates WebEngine instance.
91    *
92    * @param [in] width The width of Web
93    * @param [in] height The height of Web
94    * @param [in] locale The locale of Web
95    * @param [in] timezoneId The timezoneID of Web
96    */
97   void Create(int width, int height, const std::string& locale, const std::string& timezoneId);
98
99   /**
100    * @brief Destroys WebEngine instance.
101    */
102   void Destroy();
103
104   /**
105    * @brief Gets native image source to render.
106    */
107   NativeImageInterfacePtr GetNativeImageSource();
108
109   /**
110    * @brief Get settings of WebEngine.
111    */
112   Dali::WebEngineSettings& GetSettings() const;
113
114   /**
115    * @brief Get context of WebEngine.
116    */
117   Dali::WebEngineContext& GetContext() const;
118
119   /**
120    * @brief Get cookie manager of WebEngine.
121    */
122   Dali::WebEngineCookieManager& GetCookieManager() const;
123
124   /**
125    * @brief Get back-forward list of WebEngine.
126    */
127   Dali::WebEngineBackForwardList& GetBackForwardList() const;
128
129   /**
130    * @brief Loads a web page based on a given URL.
131    *
132    * @param [in] url The URL of the resource to load
133    */
134   void LoadUrl(const std::string& url);
135
136   /**
137    * @brief Gets the url.
138    */
139   const std::string& GetUrl();
140
141   /**
142    * @brief Loads a given string as web contents.
143    *
144    * @param [in] htmlString The string to use as the contents of the web page
145    */
146   void LoadHtmlString(const std::string& htmlString);
147
148   /**
149    * @brief Reloads the Web.
150    */
151   void Reload();
152
153   /**
154    * @brief Stops loading web contents on the current page.
155    */
156   void StopLoading();
157
158   /**
159    * @brief Suspends the operation associated with the view.
160    */
161   void Suspend();
162
163   /**
164    * @brief Resumes the operation associated with the view object after calling Suspend().
165    */
166   void Resume();
167
168   /**
169    * @brief Scrolls the webpage of view by deltaX and deltaY.
170    */
171   void ScrollBy( int deltaX, int deltaY );
172
173   /**
174    * @brief Sets an absolute scroll of the given view.
175    */
176   void SetScrollPosition( int x, int y );
177
178   /**
179    * @brief Gets the current scroll position of the given view.
180    */
181   void GetScrollPosition( int& x, int& y ) const;
182
183   /**
184    * @brief Gets the possible scroll size of the given view.
185    */
186   void GetScrollSize( int& width, int& height ) const;
187
188   /**
189    * @brief Gets the last known content's size.
190    */
191   void GetContentSize( int& width, int& height ) const;
192
193   /**
194    * @brief Returns whether forward is possible.
195    *
196    * @return True if forward is possible, false otherwise
197    */
198   bool CanGoForward();
199
200   /**
201    * @brief Goes to forward.
202    */
203   void GoForward();
204
205   /**
206    * @brief Returns whether backward is possible.
207    *
208    * @return True if backward is possible, false otherwise
209    */
210   bool CanGoBack();
211
212   /**
213    * @brief Goes to back.
214    */
215   void GoBack();
216
217   /**
218    * @brief Evaluates JavaScript code represented as a string.
219    *
220    * @param[in] script The JavaScript code
221    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
222    */
223   void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
224
225   /**
226    * @brief Add a message handler into JavaScript.
227    *
228    * @param[in] exposedObjectName The name of exposed object
229    * @param[in] handler The callback function
230    */
231   void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
232
233   /**
234    * @brief Clears the history of Web.
235    */
236   void ClearHistory();
237
238   /**
239    * @brief Get user agent string.
240    *
241    * @return The string value of user agent
242    */
243   const std::string& GetUserAgent() const;
244
245   /**
246    * @brief Set user agent string.
247    *
248    * @param[in] userAgent The string value of user agent
249    */
250   void SetUserAgent(const std::string& userAgent);
251
252   /**
253    * @brief Sets the size of Web Pages.
254    */
255   void SetSize(int width, int height);
256
257   /**
258    * @brief Sends Touch Events.
259    */
260   bool SendTouchEvent(const TouchEvent& touch);
261
262   /**
263    * @brief Sends key Events.
264    */
265   bool SendKeyEvent(const KeyEvent& event);
266
267   /**
268    * @brief Set focus.
269    */
270   void SetFocus( bool focused );
271
272   /**
273    * @brief Connects to this signal to be notified when page loading is started.
274    *
275    * @return A signal object to connect with.
276    */
277   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
278
279   /**
280    * @brief Connects to this signal to be notified when page loading is finished.
281    *
282    * @return A signal object to connect with.
283    */
284   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
285
286   /**
287    * @brief Connects to this signal to be notified when an error occurs in page loading.
288    *
289    * @return A signal object to connect with.
290    */
291   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
292
293   /**
294    * @brief Connects to this signal to be notified when scroll edge is reached.
295    *
296    * @return A signal object to connect with.
297    */
298   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
299
300 private: // Not intended for application developers
301   /**
302    * @brief Internal constructor
303    */
304   explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
305 };
306
307 } // namespace Dali
308
309 #endif // DALI_WEB_ENGINE_H