Changes after TouchData renamed to TouchEvent
[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
31 namespace Internal
32 {
33
34 namespace Adaptor
35 {
36   class WebEngine;
37 } // namespace Adaptor
38
39 } // namespace Internal
40
41 /**
42  * @brief Proxy class to dynamically load, use and unload web engine plugin.
43  *
44  * The purpose of this class is to dynamically load the web engine plugin if and when its needed.
45  * So we don't slow down every application startup if they never need web engine.
46  */
47 class DALI_ADAPTOR_API WebEngine : public BaseHandle
48 {
49 public:
50
51   /**
52    * @brief Constructor.
53    */
54   WebEngine();
55
56   /**
57    * @brief Destructor.
58    */
59   ~WebEngine();
60
61   /**
62    * @brief Creates a new instance of a WebEngine.
63    */
64   static WebEngine New();
65
66   /**
67    * @brief Copy constructor.
68    *
69    * @param[in] WebEngine WebEngine to copy. The copied WebEngine will point at the same implementation
70    */
71   WebEngine( const WebEngine& WebEngine );
72
73   /**
74    * @brief Assignment operator.
75    *
76    * @param[in] WebEngine The WebEngine to assign from.
77    * @return The updated WebEngine.
78    */
79   WebEngine& operator=( const WebEngine& WebEngine );
80
81   /**
82    * @brief Downcast a handle to WebEngine handle.
83    *
84    * If handle points to a WebEngine the downcast produces valid
85    * handle. If not the returned handle is left uninitialized.
86    *
87    * @param[in] handle Handle to an object
88    * @return Handle to a WebEngine or an uninitialized handle
89    */
90   static WebEngine DownCast( BaseHandle handle );
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] locale The locale of Web
98    * @param [in] timezoneId The timezoneID of Web
99    */
100   void Create( int width, int height, const std::string& locale, const std::string& timezoneId );
101
102   /**
103    * @brief Destroys WebEngine instance.
104    */
105   void Destroy();
106
107   /**
108    * @brief Gets native image source to render.
109    */
110   NativeImageInterfacePtr GetNativeImageSource();
111
112   /**
113    * @brief Loads a web page based on a given URL.
114    *
115    * @param [in] url The URL of the resource to load
116    */
117   void LoadUrl( const std::string& url );
118
119   /**
120    * @brief Gets the url.
121    */
122   const std::string& GetUrl();
123
124   /**
125    * @brief Loads a given string as web contents.
126    *
127    * @param [in] htmlString The string to use as the contents of the web page
128    */
129   void LoadHTMLString( const std::string& htmlString );
130
131   /**
132    * @brief Reloads the Web.
133    */
134   void Reload();
135
136   /**
137    * @brief Stops loading web contents on the current page.
138    */
139   void StopLoading();
140
141   /**
142    * @brief Suspends the operation associated with the view.
143    */
144   void Suspend();
145
146   /**
147    * @brief Resumes the operation associated with the view object after calling Suspend().
148    */
149   void Resume();
150
151   /**
152    * @brief Returns whether forward is possible.
153    *
154    * @return True if forward is possible, false otherwise
155    */
156   bool CanGoForward();
157
158   /**
159    * @brief Goes to forward.
160    */
161   void GoForward();
162
163   /**
164    * @brief Returns whether backward is possible.
165    *
166    * @return True if backward is possible, false otherwise
167    */
168   bool CanGoBack();
169
170   /**
171    * @brief Goes to back.
172    */
173   void GoBack();
174
175   /**
176    * @brief Evaluates JavaScript code represented as a string.
177    *
178    * @param[in] script The JavaScript code
179    * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
180    */
181   void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler );
182
183   /**
184    * @brief Add a message handler into JavaScript.
185    *
186    * @param[in] exposedObjectName The name of exposed object
187    * @param[in] handler The callback function
188    */
189   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
190
191   /**
192    * @brief Clears the history of Web.
193    */
194   void ClearHistory();
195
196   /**
197    * @brief Clears the cache of Web.
198    */
199   void ClearCache();
200
201   /**
202    * @brief Clears all the cookies of Web.
203    */
204   void ClearCookies();
205
206   /**
207    * @brief Get cache model option. The default is DOCUMENT_VIEWER.
208    *
209    * @return The cache model option
210    */
211   Dali::WebEnginePlugin::CacheModel GetCacheModel() const;
212
213   /**
214    * @brief Set cache model option. The default is DOCUMENT_VIEWER.
215    *
216    * @param[in] cacheModel The cache model option
217    */
218   void SetCacheModel( Dali::WebEnginePlugin::CacheModel cacheModel );
219
220   /**
221    * @brief Gets the cookie acceptance policy. The default is NO_THIRD_PARTY.
222    *
223    * @return The cookie acceptance policy
224    */
225   Dali::WebEnginePlugin::CookieAcceptPolicy GetCookieAcceptPolicy() const;
226
227   /**
228    * @brief Sets the cookie acceptance policy. The default is NO_THIRD_PARTY.
229    *
230    * @param[in] policy The cookie acceptance policy
231    */
232   void SetCookieAcceptPolicy( Dali::WebEnginePlugin::CookieAcceptPolicy policy );
233
234   /**
235    * @brief Get user agent string.
236    *
237    * @return The string value of user agent
238    */
239   const std::string& GetUserAgent() const;
240
241   /**
242    * @brief Set user agent string.
243    *
244    * @param[in] userAgent The string value of user agent
245    */
246   void SetUserAgent( const std::string& userAgent );
247
248   /**
249    * @brief Returns whether JavaScript can be executable. The default is true.
250    *
251    * @return true if JavaScript executing is enabled, false otherwise
252    */
253   bool IsJavaScriptEnabled() const;
254
255   /**
256    * @brief Enables/disables JavaScript executing. The default is enabled.
257    *
258    * @param[in] enabled True if JavaScript executing is enabled, false otherwise
259    */
260   void EnableJavaScript( bool enabled );
261
262   /**
263    * @brief Returns whether JavaScript can be executable. The default is true.
264    *
265    * @return true if images are loaded automatically, false otherwise
266    */
267   bool AreImagesAutomaticallyLoaded() const;
268
269   /**
270    * @brief Enables/disables auto loading of images. The default is enabled.
271    *
272    * @param[in] automatic True if images are loaded automatically, false otherwise
273    */
274   void LoadImagesAutomatically( bool automatic );
275
276   /**
277    * @brief Gets the default text encoding name.
278    *
279    * @return The default text encoding name
280    */
281   const std::string& GetDefaultTextEncodingName() const;
282
283   /**
284    * @brief Sets the default text encoding name.
285    *
286    * @param[in] defaultTextEncodingName The default text encoding name
287    */
288   void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName );
289
290   /**
291    * @brief Returns the default font size in pixel. The default value is 16.
292    *
293    * @return The default font size
294    */
295   int GetDefaultFontSize() const;
296
297   /**
298    * @brief Sets the default font size in pixel. The default value is 16.
299    *
300    * @param[in] defaultFontSize A new default font size to set
301    */
302   void SetDefaultFontSize( int defaultFontSize );
303
304   /**
305    * @brief Sets the size of Web Pages.
306    */
307   void SetSize( int width, int height );
308
309   /**
310    * @brief Sends Touch Events.
311    */
312   bool SendTouchEvent( const TouchEvent& touch );
313
314   /**
315    * @brief Sends key Events.
316    */
317   bool SendKeyEvent( const KeyEvent& event );
318
319   /**
320    * @brief Connects to this signal to be notified when page loading is started.
321    *
322    * @return A signal object to connect with.
323    */
324   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
325
326   /**
327    * @brief Connects to this signal to be notified when page loading is finished.
328    *
329    * @return A signal object to connect with.
330    */
331   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
332
333   /**
334    * @brief Connects to this signal to be notified when an error occurs in page loading.
335    *
336    * @return A signal object to connect with.
337    */
338   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
339
340 private: // Not intended for application developers
341
342   /**
343    * @brief Internal constructor
344    */
345   explicit DALI_INTERNAL WebEngine( Internal::Adaptor::WebEngine* internal );
346 };
347
348 } // namespace Dali;
349
350 #endif // DALI_WEB_ENGINE_H