Merge "Update position & size of web view." 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 <memory>
23 #include <dali/devel-api/adaptor-framework/web-engine.h>
24 #include <dali/public-api/images/image-operations.h>
25 #include <dali/public-api/object/property-notification.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
29 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
30 #include <dali-toolkit/public-api/controls/control-impl.h>
31 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 class KeyEvent;
40 class TouchEvent;
41 class WebBackForwardList;
42 class WebContext;
43 class WebCookieManager;
44 class WebSettings;
45 class WebView;
46
47 namespace Internal
48 {
49
50 class WebView : public Control
51 {
52 protected:
53
54   WebView();
55
56   WebView( const std::string& locale, const std::string& timezoneId );
57
58   WebView( int argc, char** argv );
59
60   virtual ~WebView();
61
62 public:
63
64   /**
65    * @copydoc Dali::Toolkit::WebView::New()
66    */
67   static Toolkit::WebView New();
68
69   /**
70    * @copydoc Dali::Toolkit::WebView::New( const std::string&, const std::string& )
71    */
72   static Toolkit::WebView New( const std::string& locale, const std::string& timezoneId );
73
74   /**
75    * @brief Get settings of WebEngine.
76    */
77   Dali::Toolkit::WebSettings* GetSettings() const;
78
79   /**
80    * @brief Get context of WebEngine.
81    */
82   Dali::Toolkit::WebContext* GetContext() const;
83
84   /**
85    * @brief Get cookie manager of WebEngine.
86    */
87   Dali::Toolkit::WebCookieManager* GetCookieManager() const;
88
89   /**
90    * @brief Get WebBackForwardList of WebEngine.
91    */
92   Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
93
94   /**
95    * @copydoc Dali::Toolkit::WebView::New( int, char** )
96    */
97   static Toolkit::WebView New( int argc, char** argv );
98
99   /**
100    * @brief Get Favicon of web page.
101    *
102    * @return Handle to a fav icon
103    */
104   Dali::Toolkit::ImageView& GetFavicon();
105
106   /**
107    * @copydoc Dali::Toolkit::WebView::LoadUrl()
108    */
109   void LoadUrl( const std::string& url );
110
111   /**
112    * @copydoc Dali::WebEngine::LoadHTMLString()
113    */
114   void LoadHtmlString( const std::string& htmlString );
115
116   /**
117    * @copydoc Dali::Toolkit::WebView::Reload()
118    */
119   void Reload();
120
121   /**
122    * @copydoc Dali::Toolkit::WebView::StopLoading()
123    */
124   void StopLoading();
125
126   /**
127    * @copydoc Dali::Toolkit::WebView::StopLoading()
128    */
129   void Suspend();
130
131   /**
132    * @copydoc Dali::Toolkit::WebView::Resume()
133    */
134   void Resume();
135
136   /**
137    * @copydoc Dali::Toolkit::WebView::ScrollBy()
138    */
139   void ScrollBy( int deltaX, int deltaY );
140
141   /**
142    * @copydoc Dali::Toolkit::WebView::CanGoForward()
143    */
144   bool CanGoForward();
145
146   /**
147    * @copydoc Dali::Toolkit::WebView::GoForward()
148    */
149   void GoForward();
150
151   /**
152    * @copydoc Dali::Toolkit::WebView::CanGoBack()
153    */
154   bool CanGoBack();
155
156   /**
157    * @copydoc Dali::Toolkit::WebView::GoBack()
158    */
159   void GoBack();
160
161   /**
162    * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
163    */
164   void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler );
165
166   /**
167    * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
168    */
169   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
170
171   /**
172    * @brief Clears all tiles resources of Web.
173    */
174   void ClearAllTilesResources();
175
176   /**
177    * @copydoc Dali::Toolkit::WebView::ClearHistory()
178    */
179   void ClearHistory();
180
181   /**
182    * @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal()
183    */
184   Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadStartedSignal();
185
186   /**
187    * @copydoc Dali::Toolkit::WebView::PageLoadFinishedSignal()
188    */
189   Dali::Toolkit::WebView::WebViewPageLoadSignalType& PageLoadFinishedSignal();
190
191   /**
192    * @copydoc Dali::Toolkit::WebView::PageLoadErrorSignal()
193    */
194   Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType& PageLoadErrorSignal();
195
196   /**
197    * @copydoc Dali::Toolkit::WebView::ScrollEdgeReachedSignal()
198    */
199   Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
200
201 public: // Properties
202
203   /**
204    * @brief Called when a property of an object of this type is set.
205    *
206    * @param[in] object The object whose property is set.
207    * @param[in] index The property index.
208    * @param[in] value The new property value.
209    */
210   static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
211
212   /**
213    * @brief Called to retrieve a property of an object of this type.
214    *
215    * @param[in] object The object whose property is to be retrieved.
216    * @param[in] index The property index.
217    * @return The current value of the property.
218    */
219   static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
220
221   /**
222    * Connects a callback function with the object's signals.
223    * @param[in] object The object providing the signal.
224    * @param[in] tracker Used to disconnect the signal.
225    * @param[in] signalName The signal to connect to.
226    * @param[in] functor A newly allocated FunctorDelegate.
227    * @return True if the signal was connected.
228    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
229    */
230   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
231
232 private: // From Control
233
234   /**
235    * @copydoc Toolkit::Control::OnInitialize()
236    */
237   void OnInitialize() override;
238
239   /**
240    * @copydoc Toolkit::Control::GetNaturalSize
241    */
242   Vector3 GetNaturalSize() override;
243
244   /**
245    * Signal occurs when the Web View has been touched.
246    * @param[in] actor The Actor Touched
247    * @param[in] touch The Touch Data.
248    * @return Whether to consume event or not.
249    */
250   bool OnTouchEvent( Actor actor, const Dali::TouchEvent& touch );
251
252   /**
253    * @copydoc Toolkit::Control::OnKeyEvent()
254    */
255   bool OnKeyEvent( const Dali::KeyEvent& event ) override;
256
257   /**
258    * @copydoc Toolkit::Control::OnKeyInputFocusGained()
259    */
260   void OnKeyInputFocusGained() override;
261
262   /**
263    * @copydoc Toolkit::Control::OnKeyInputFocusLost()
264    */
265   void OnKeyInputFocusLost() override;
266
267   /**
268    * @copydoc Toolkit::Control::OnSceneConnection()
269    */
270   void OnSceneConnection( int depth ) override;
271
272 private:
273
274   // Undefined
275   WebView( const WebView& webView );
276
277   WebView& operator=( const WebView& webView );
278
279   /**
280    * @brief Sets an absolute scroll of the given view.
281    * @param[in] x The coordinate x of scroll
282    * @param[in] y The coordinate y of scroll
283    */
284   void SetScrollPosition( int x, int y );
285
286   /**
287    * @brief Gets the current scroll position of the given view.
288    * @param[out] x The coordinate x of scroll
289    * @param[out] y The coordinate y of scroll
290    */
291   Dali::Vector2 GetScrollPosition() const;
292
293   /**
294    * @brief Gets the possible scroll size of the given view.
295    * @param[out] width The width of scroll size
296    * @param[out] height The height of scroll size
297    */
298   Dali::Vector2 GetScrollSize() const;
299
300   /**
301    * @brief Gets the last known content's size.
302    * @param[out] width The width of content's size
303    * @param[out] height The height of content's size
304    */
305   Dali::Vector2 GetContentSize() const;
306
307   /**
308    * @brief Returns the title of the Web.
309    *
310    * @return The title of web page
311    */
312   std::string GetTitle() const;
313
314   /**
315    * @brief Get user agent string.
316    * @return The string value of user agent
317    */
318   const std::string& GetUserAgent() const;
319
320   /**
321    * @brief Set user agent string.
322    * @param[in] userAgent The string value of user agent
323    */
324   void SetUserAgent( const std::string& userAgent );
325
326   /**
327    * @brief Updates display area of web view.
328    * @param[in] source The soource triggers Notification.
329    */
330   void UpdateDisplayArea( Dali::PropertyNotification& source );
331
332   /**
333    * @brief Enable/Disable video hole for video playing.
334    * @param[in] enabled True if video hole is enabled, false otherwise.
335    */
336   void EnableVideoHole( bool enabled );
337
338   /**
339    * @brief Enable blend mode.
340    * @param[in] blendEnabled True if turn on blend mode, false otherwise.
341    */
342   void EnableBlendMode( bool blendEnabled );
343
344   /**
345    * @brief Callback function to be called when page load started.
346    * @param[in] url The url currently being loaded
347    */
348   void OnPageLoadStarted( const std::string& url );
349
350   /**
351    * @brief Callback function to be called when page load finished.
352    * @param[in] url The url currently being loaded
353    */
354   void OnPageLoadFinished( const std::string& url );
355
356   /**
357    * @brief Callback function to be called when there is an error in page loading.
358    * @param[in] url The url currently being loaded
359    * @param[in] errorCode The error code
360    */
361   void OnPageLoadError( const std::string& url, int errorCode );
362
363   /**
364    * @brief Callback function to be called when scroll edge is reached.
365    * @param[in] e The scroll edge reached.
366    */
367   void OnScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge );
368
369 private:
370
371   std::string                                            mUrl;
372   Dali::Toolkit::Visual::Base                            mVisual;
373   Dali::Size                                             mWebViewSize;
374   Dali::WebEngine                                        mWebEngine;
375
376   Dali::Toolkit::WebView::WebViewPageLoadSignalType      mPageLoadStartedSignal;
377   Dali::Toolkit::WebView::WebViewPageLoadSignalType      mPageLoadFinishedSignal;
378   Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal;
379   Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType mScrollEdgeReachedSignal;
380
381   std::unique_ptr<Dali::Toolkit::WebContext>             mWebContext;
382   std::unique_ptr<Dali::Toolkit::WebCookieManager>       mWebCookieManager;
383   std::unique_ptr<Dali::Toolkit::WebSettings>            mWebSettings;
384   std::unique_ptr<Dali::Toolkit::WebBackForwardList>     mWebBackForwardList;
385   Dali::Toolkit::ImageView mFaviconView;
386
387   Dali::PropertyNotification                             mPositionUpdateNotification;
388   Dali::PropertyNotification                             mSizeUpdateNotification;
389   Dali::PropertyNotification                             mScaleUpdateNotification;
390   bool                                                   mVideoHoleEnabled;
391   Dali::Rect< int >                                      mWebViewArea;
392 };
393
394 } // namespace Internal
395
396 inline Toolkit::Internal::WebView& GetImpl( Toolkit::WebView& handle )
397 {
398   DALI_ASSERT_ALWAYS( handle );
399   Dali::RefObject& impl = handle.GetImplementation();
400   return static_cast< Toolkit::Internal::WebView& >( impl );
401 }
402
403 inline const Toolkit::Internal::WebView& GetImpl( const Toolkit::WebView& handle )
404 {
405   DALI_ASSERT_ALWAYS( handle );
406   const Dali::RefObject& impl = handle.GetImplementation();
407   return static_cast< const Toolkit::Internal::WebView& >( impl );
408 }
409
410 } // namespace Toolkit
411
412 } // namespace Dali
413
414 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H