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