069339f86dc839c12e3f69db4db6c4be3a875e34
[platform/core/uifw/dali-adaptor.git] / dali / internal / web-engine / common / web-engine-impl.h
1 #ifndef DALI_WEB_ENGINE_IMPL_H
2 #define DALI_WEB_ENGINE_IMPL_H
3
4 /*
5  * Copyright (c) 2021 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-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
26 #include <dali/devel-api/adaptor-framework/web-engine.h>
27
28 namespace Dali
29 {
30 // forward declaration
31 class WebEngineBackForwardList;
32 class WebEngineContext;
33 class WebEngineCookieManager;
34 class WebEngineSettings;
35
36 namespace Internal
37 {
38 namespace Adaptor
39 {
40 class WebEngine;
41
42 typedef IntrusivePtr<WebEngine> WebEnginePtr;
43
44 /**
45  * @brief WebEngine class is used for Web.
46  */
47 class WebEngine : public Dali::BaseObject
48 {
49 public:
50   /**
51    * @brief Creates a new WebEngine handle
52    *
53    * @return WebEngine pointer
54    */
55   static WebEnginePtr New();
56
57   /**
58    * @copydoc Dali::WebEngine::Create()
59    */
60   void Create(int width, int height, const std::string& locale, const std::string& timezoneId);
61
62   /**
63    * @copydoc Dali::WebEngine::Create()
64    */
65   void Create(int width, int height, int argc, char** argv);
66
67   /**
68    * @copydoc Dali::WebEngine::Destroy()
69    */
70   void Destroy();
71
72   /**
73    * @copydoc Dali::WebEngine::GetNativeImageSource()
74    */
75   Dali::NativeImageInterfacePtr GetNativeImageSource();
76
77   /**
78    * @copydoc Dali::WebEngine::GetSettings()
79    */
80   Dali::WebEngineSettings& GetSettings() const;
81
82   /**
83    * @copydoc Dali::WebEngine::GetContext()
84    */
85   Dali::WebEngineContext& GetContext() const;
86
87   /**
88    * @copydoc Dali::WebEngine::GetCookieManager()
89    */
90   Dali::WebEngineCookieManager& GetCookieManager() const;
91
92   /**
93    * @copydoc Dali::WebEngine::GetBackForwardList()
94    */
95   Dali::WebEngineBackForwardList& GetBackForwardList() const;
96
97   /**
98    * @copydoc Dali::WebEngine::LoadUrl()
99    */
100   void LoadUrl(const std::string& url);
101
102   /**
103    * @copydoc Dali::WebEngine::GetTitle()
104    */
105   std::string GetTitle() const;
106
107   /**
108    * @copydoc Dali::WebEngine::GetFavicon()
109    */
110   Dali::PixelData GetFavicon() const;
111
112   /**
113    * @copydoc Dali::WebEngine::GetUrl()
114    */
115   const std::string& GetUrl();
116
117   /**
118    * @copydoc Dali::WebEngine::GetUserAgent()
119    */
120   const std::string& GetUserAgent() const;
121
122   /**
123    * @copydoc Dali::WebEngine::SetUserAgent()
124    */
125   void SetUserAgent(const std::string& userAgent);
126
127   /**
128    * @copydoc Dali::WebEngine::LoadHtmlString()
129    */
130   void LoadHtmlString(const std::string& htmlString);
131
132   /**
133    * @copydoc Dali::WebEngine::Reload()
134    */
135   void Reload();
136
137   /**
138    * @copydoc Dali::WebEngine::StopLoading()
139    */
140   void StopLoading();
141
142   /**
143    * @copydoc Dali::WebEngine::Suspend()
144    */
145   void Suspend();
146
147   /**
148    * @copydoc Dali::WebEngine::Resume()
149    */
150   void Resume();
151
152   /**
153    * @copydoc Dali::WebEngine::ScrollBy()
154    */
155   void ScrollBy(int deltaX, int deltaY);
156
157   /**
158    * @copydoc Dali::WebEngine::SetScrollPosition()
159    */
160   void SetScrollPosition(int x, int y);
161
162   /**
163    * @copydoc Dali::WebEngine::GetScrollPosition()
164    */
165   Dali::Vector2 GetScrollPosition() const;
166
167   /**
168    * @copydoc Dali::WebEngine::GetScrollSize()
169    */
170   Dali::Vector2 GetScrollSize() const;
171
172   /**
173    * @copydoc Dali::WebEngine::GetContentSize()
174    */
175   Dali::Vector2 GetContentSize() const;
176
177   /**
178    * @copydoc Dali::WebEngine::CanGoForward()
179    */
180   bool CanGoForward();
181
182   /**
183    * @copydoc Dali::WebEngine::GoForward()
184    */
185   void GoForward();
186
187   /**
188    * @copydoc Dali::WebEngine::CanGoBack()
189    */
190   bool CanGoBack();
191
192   /**
193    * @copydoc Dali::WebEngine::GoBack()
194    */
195   void GoBack();
196
197   /**
198    * @copydoc Dali::WebEngine::EvaluateJavaScript()
199    */
200   void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
201
202   /**
203    * @copydoc Dali::WebEngine::AddJavaScriptMessageHandler()
204    */
205   void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
206
207   /**
208    * @copydoc Dali::WebEngine::ClearAllTilesResources()
209    */
210   void ClearAllTilesResources();
211
212   /**
213    * @copydoc Dali::WebEngine::ClearHistory()
214    */
215   void ClearHistory();
216
217   /**
218    * @copydoc Dali::WebEngine::SetSize()
219    */
220   void SetSize(int width, int height);
221
222   /**
223    * @copydoc Dali::WebEngine::SendTouchEvent()
224    */
225   bool SendTouchEvent(const Dali::TouchEvent& touch);
226
227   /**
228    * @copydoc Dali::WebEngine::SendKeyEvent()
229    */
230   bool SendKeyEvent(const Dali::KeyEvent& event);
231
232   /**
233    * @copydoc Dali::WebEngine::SetFocus()
234    */
235   void SetFocus(bool focused);
236
237   /**
238    * @copydoc Dali::WebEngine::UpdateDisplayArea()
239    */
240   void UpdateDisplayArea(Dali::Rect<int> displayArea);
241
242   /**
243    * @copydoc Dali::WebEngine::EnableVideoHole()
244    */
245   void EnableVideoHole(bool enabled);
246
247   /**
248    * @copydoc Dali::WebEngine::PageLoadStartedSignal()
249    */
250   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
251
252   /**
253    * @copydoc Dali::WebEngine::PageLoadFinishedSignal()
254    */
255   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
256
257   /**
258    * @copydoc Dali::WebEngine::PageLoadErrorSignal()
259    */
260   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
261
262   /**
263    * @copydoc Dali::WebEngine::ScrollEdgeReachedSignal()
264    */
265   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
266
267 private:
268   /**
269    * @brief Constructor.
270    */
271   WebEngine();
272
273   /**
274    * @brief Destructor.
275    */
276   virtual ~WebEngine();
277
278   // Undefined copy constructor
279   WebEngine(const WebEngine& WebEngine);
280
281   // Undefined assignment operator
282   WebEngine& operator=(const WebEngine& WebEngine);
283
284   /**
285    * @brief Initializes member data.
286    *
287    * @return Whether the initialization succeed or not.
288    */
289   bool Initialize();
290
291   /**
292    * @brief Initializes library handle by loading web engine plugin.
293    *
294    * @return Whether the initialization succeed or not.
295    */
296   bool InitializePluginHandle();
297
298 private:
299   typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();
300   typedef void (*DestroyWebEngineFunction)(Dali::WebEnginePlugin* plugin);
301
302   Dali::WebEnginePlugin*   mPlugin;              ///< WebEnginePlugin instance
303   void*                    mHandle;              ///< Handle for the loaded library
304   CreateWebEngineFunction  mCreateWebEnginePtr;  ///< Function to create plugin instance
305   DestroyWebEngineFunction mDestroyWebEnginePtr; ///< Function to destroy plugin instance
306 };
307
308 } // namespace Adaptor
309 } // namespace Internal
310
311 inline static Internal::Adaptor::WebEngine& GetImplementation(Dali::WebEngine& webEngine)
312 {
313   DALI_ASSERT_ALWAYS(webEngine && "WebEngine handle is empty.");
314
315   BaseObject& handle = webEngine.GetBaseObject();
316
317   return static_cast<Internal::Adaptor::WebEngine&>(handle);
318 }
319
320 inline static const Internal::Adaptor::WebEngine& GetImplementation(const Dali::WebEngine& webEngine)
321 {
322   DALI_ASSERT_ALWAYS(webEngine && "WebEngine handle is empty.");
323
324   const BaseObject& handle = webEngine.GetBaseObject();
325
326   return static_cast<const Internal::Adaptor::WebEngine&>(handle);
327 }
328
329 } // namespace Dali
330
331 #endif