Merge "(Vector) Change event processing" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / web-view / web-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_WEB_VIEW_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/devel-api/adaptor-framework/web-engine.h>
23 #include <dali/public-api/images/image-operations.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 class KeyEvent;
37 class TouchEvent;
38 class WebView;
39
40 namespace Internal
41 {
42
43 class WebView : public Control
44 {
45 protected:
46
47   WebView();
48
49   WebView( const std::string& locale, const std::string& timezoneId );
50
51   virtual ~WebView();
52
53 public:
54
55   /**
56    * @copydoc Dali::Toolkit::WebView::New()
57    */
58   static Toolkit::WebView New();
59
60   /**
61    * @copydoc Dali::Toolkit::WebView::New( const std::string&, const std::string& )
62    */
63   static Toolkit::WebView New( const std::string& locale, const std::string& timezoneId );
64
65   /**
66    * @copydoc Dali::Toolkit::WebView::LoadUrl()
67    */
68   void LoadUrl( const std::string& url );
69
70   /**
71    * @copydoc Dali::WebEngine::LoadHTMLString()
72    */
73   void LoadHTMLString( const std::string& htmlString );
74
75   /**
76    * @copydoc Dali::Toolkit::WebView::Reload()
77    */
78   void Reload();
79
80   /**
81    * @copydoc Dali::Toolkit::WebView::StopLoading()
82    */
83   void StopLoading();
84
85   /**
86    * @copydoc Dali::Toolkit::WebView::StopLoading()
87    */
88   void Suspend();
89
90   /**
91    * @copydoc Dali::Toolkit::WebView::Resume()
92    */
93   void Resume();
94
95   /**
96    * @copydoc Dali::Toolkit::WebView::CanGoForward()
97    */
98   bool CanGoForward();
99
100   /**
101    * @copydoc Dali::Toolkit::WebView::GoForward()
102    */
103   void GoForward();
104
105   /**
106    * @copydoc Dali::Toolkit::WebView::CanGoBack()
107    */
108   bool CanGoBack();
109
110   /**
111    * @copydoc Dali::Toolkit::WebView::GoBack()
112    */
113   void GoBack();
114
115   /**
116    * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
117    */
118   void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler );
119
120   /**
121    * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
122    */
123   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
124
125   /**
126    * @copydoc Dali::Toolkit::WebView::ClearHistory()
127    */
128   void ClearHistory();
129
130   /**
131    * @copydoc Dali::Toolkit::WebView::ClearCache()
132    */
133   void ClearCache();
134
135   /**
136    * @copydoc Dali::Toolkit::WebView::ClearCookies()
137    */
138   void ClearCookies();
139
140   /**
141    * @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal()
142    */
143   Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadStartedSignal();
144
145   /**
146    * @copydoc Dali::Toolkit::WebView::PageLoadFinishedSignal()
147    */
148   Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadFinishedSignal();
149
150   /**
151    * @copydoc Dali::Toolkit::WebView::PageLoadErrorSignal()
152    */
153   Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
154
155 public: // Properties
156
157   /**
158    * @brief Called when a property of an object of this type is set.
159    *
160    * @param[in] object The object whose property is set.
161    * @param[in] index The property index.
162    * @param[in] value The new property value.
163    */
164   static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
165
166   /**
167    * @brief Called to retrieve a property of an object of this type.
168    *
169    * @param[in] object The object whose property is to be retrieved.
170    * @param[in] index The property index.
171    * @return The current value of the property.
172    */
173   static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
174
175   /**
176    * Connects a callback function with the object's signals.
177    * @param[in] object The object providing the signal.
178    * @param[in] tracker Used to disconnect the signal.
179    * @param[in] signalName The signal to connect to.
180    * @param[in] functor A newly allocated FunctorDelegate.
181    * @return True if the signal was connected.
182    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
183    */
184   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
185
186 private: // From Control
187
188   /**
189    * @copydoc Toolkit::Control::OnInitialize()
190    */
191   virtual void OnInitialize();
192
193   /**
194    * @copydoc Toolkit::Control::GetNaturalSize
195    */
196   virtual Vector3 GetNaturalSize();
197
198   /**
199    * @copydoc Toolkit::Control::OnRelayout()
200    */
201   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
202
203   /**
204    * Signal occurs when the Web View has been touched.
205    * @param[in] actor The Actor Touched
206    * @param[in] touch The Touch Data.
207    * @return Whether to consume event or not.
208    */
209   bool OnTouchEvent( Actor actor, const Dali::TouchEvent& touch );
210
211   /**
212    * @copydoc Toolkit::Control::OnKeyEvent()
213    */
214   virtual bool OnKeyEvent( const Dali::KeyEvent& event );
215
216 private:
217
218   // Undefined
219   WebView( const WebView& webView );
220
221   WebView& operator=( const WebView& webView );
222
223   /**
224    * @brief Get cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER.
225    * @see Toolkit::WebView::CacheModel::Type
226    */
227   Toolkit::WebView::CacheModel::Type GetCacheModel() const;
228
229   /**
230    * @brief Set cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER.
231    * @param[in] cacheModel The cache model option
232    * @see Toolkit::WebView::CacheModel::Type
233    */
234   void SetCacheModel( Toolkit::WebView::CacheModel::Type cacheModel );
235
236   /**
237    * @brief Gets the cookie acceptance policy. The default is Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
238    * @see Toolkit::WebView::CookieAcceptPolicy::Type
239    */
240   Toolkit::WebView::CookieAcceptPolicy::Type GetCookieAcceptPolicy() const;
241
242   /**
243    * @brief Sets the cookie acceptance policy. The default is Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
244    * @param[in] policy The cookie acceptance policy
245    * @see Toolkit::WebView::CookieAcceptPolicy::Type
246    */
247   void SetCookieAcceptPolicy( Toolkit::WebView::CookieAcceptPolicy::Type policy );
248
249   /**
250    * @brief Get user agent string.
251    * @return The string value of user agent
252    */
253   const std::string& GetUserAgent() const;
254
255   /**
256    * @brief Set user agent string.
257    * @param[in] userAgent The string value of user agent
258    */
259   void SetUserAgent( const std::string& userAgent );
260
261   /**
262    * @brief Returns whether JavaScript can be executable. The default is true.
263    *
264    * @return true if JavaScript executing is enabled, false otherwise
265    */
266   bool IsJavaScriptEnabled() const;
267
268   /**
269    * @brief Enables/disables JavaScript executing. The default is enabled.
270    *
271    * @param[in] enabled True if JavaScript executing is enabled, false otherwise
272    */
273   void EnableJavaScript( bool enabled );
274
275   /**
276    * @brief Returns whether images can be loaded automatically. The default is true.
277    *
278    * @return true if images are loaded automatically, false otherwise
279    */
280   bool AreImagesAutomaticallyLoaded() const;
281
282   /**
283    * @brief Enables/disables auto loading of images. The default is enabled.
284    *
285    * @param[in] automatic True if images are loaded automatically, false otherwise
286    */
287   void LoadImagesAutomatically( bool automatic );
288
289   /**
290    * @brief Gets the default text encoding name (e.g. UTF-8).
291    *
292    * @return The default text encoding name
293    */
294   const std::string& GetDefaultTextEncodingName() const;
295
296   /**
297    * @brief Sets the default text encoding name (e.g. UTF-8).
298    *
299    * @param[in] defaultTextEncodingName The default text encoding name
300    */
301   void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName );
302
303   /**
304    * @brief Returns the default font size in pixel. The default value is 16.
305    *
306    * @return The default font size
307    */
308   int GetDefaultFontSize() const;
309
310   /**
311    * @brief Sets the default font size in pixel. The default value is 16.
312    *
313    * @param[in] defaultFontSize A new default font size to set
314    */
315   void SetDefaultFontSize( int defaultFontSize );
316
317   /**
318    * @brief Callback function to be called when page load started.
319    * @param[in] url The url currently being loaded
320    */
321   void OnPageLoadStarted( const std::string& url );
322
323   /**
324    * @brief Callback function to be called when page load finished.
325    * @param[in] url The url currently being loaded
326    */
327   void OnPageLoadFinished( const std::string& url );
328
329   /**
330    * @brief Callback function to be called when there is an error in page loading.
331    * @param[in] url The url currently being loaded
332    * @param[in] errorCode The error code
333    */
334   void OnPageLoadError( const std::string& url, int errorCode );
335
336 private:
337
338   std::string                                            mUrl;
339   Dali::Toolkit::Visual::Base                            mVisual;
340   Dali::Size                                             mWebViewSize;
341   Dali::WebEngine                                        mWebEngine;
342
343   Dali::Toolkit::WebView::WebViewPageLoadSignalType      mPageLoadStartedSignal;
344   Dali::Toolkit::WebView::WebViewPageLoadSignalType      mPageLoadFinishedSignal;
345   Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal;
346 };
347
348 } // namespace Internal
349
350 inline Toolkit::Internal::WebView& GetImpl( Toolkit::WebView& handle )
351 {
352   DALI_ASSERT_ALWAYS( handle );
353   Dali::RefObject& impl = handle.GetImplementation();
354   return static_cast< Toolkit::Internal::WebView& >( impl );
355 }
356
357 inline const Toolkit::Internal::WebView& GetImpl( const Toolkit::WebView& handle )
358 {
359   DALI_ASSERT_ALWAYS( handle );
360   const Dali::RefObject& impl = handle.GetImplementation();
361   return static_cast< const Toolkit::Internal::WebView& >( impl );
362 }
363
364 } // namespace Toolkit
365
366 } // namespace Dali
367
368 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H