Change WebEngine API
[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) 2018 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 Returns whether forward is possible.
143    *
144    * @return True if forward is possible, false otherwise
145    */
146   bool CanGoForward();
147
148   /**
149    * @brief Goes to forward.
150    */
151   void GoForward();
152
153   /**
154    * @brief Returns whether backward is possible.
155    *
156    * @return True if backward is possible, false otherwise
157    */
158   bool CanGoBack();
159
160   /**
161    * @brief Goes to back.
162    */
163   void GoBack();
164
165   /**
166    * @brief Evaluates JavaScript code represented as a string.
167    *
168    * @param[in] script The JavaScript code
169    */
170   void EvaluateJavaScript( const std::string& script );
171
172   /**
173    * @brief Add a message handler into JavaScript.
174    *
175    * @param[in] exposedObjectName The name of exposed object
176    * @param[in] handler The callback function
177    */
178   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
179
180   /**
181    * @brief Clears the history of Web.
182    */
183   void ClearHistory();
184
185   /**
186    * @brief Clears the cache of Web.
187    */
188   void ClearCache();
189
190   /**
191    * @brief Sets the size of Web Pages.
192    */
193   void SetSize( int width, int height );
194
195   /**
196    * @brief Sends Touch Events.
197    */
198   bool SendTouchEvent( const TouchData& touch );
199
200   /**
201    * @brief Sends key Events.
202    */
203   bool SendKeyEvent( const KeyEvent& event );
204
205   /**
206    * @brief Connects to this signal to be notified when page loading is started.
207    *
208    * @return A signal object to connect with.
209    */
210   Dali::WebEnginePlugin::WebEngineSignalType& PageLoadStartedSignal();
211
212   /**
213    * @brief Connects to this signal to be notified when page loading is finished.
214    *
215    * @return A signal object to connect with.
216    */
217   Dali::WebEnginePlugin::WebEngineSignalType& PageLoadFinishedSignal();
218
219 private: // Not intended for application developers
220
221   /**
222    * @brief Internal constructor
223    */
224   explicit DALI_INTERNAL WebEngine( Internal::Adaptor::WebEngine* internal );
225 };
226
227 } // namespace Dali;
228
229 #endif // DALI_WEB_ENGINE_H