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