Set focus to web engine.
[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   void OnInitialize() override;
192
193   /**
194    * @copydoc Toolkit::Control::GetNaturalSize
195    */
196   Vector3 GetNaturalSize() override;
197
198   /**
199    * @copydoc Toolkit::Control::OnRelayout()
200    */
201   void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
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   bool OnKeyEvent( const Dali::KeyEvent& event ) override;
215
216   /**
217    * @copydoc Toolkit::Control::OnKeyInputFocusGained()
218    */
219   void OnKeyInputFocusGained() override;
220
221   /**
222    * @copydoc Toolkit::Control::OnKeyInputFocusLost()
223    */
224   void OnKeyInputFocusLost() override;
225
226 private:
227
228   // Undefined
229   WebView( const WebView& webView );
230
231   WebView& operator=( const WebView& webView );
232
233   /**
234    * @brief Get cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER.
235    * @see Toolkit::WebView::CacheModel::Type
236    */
237   Toolkit::WebView::CacheModel::Type GetCacheModel() const;
238
239   /**
240    * @brief Set cache model option. The default isToolkit::WebView::CacheModel::DOCUMENT_VIEWER.
241    * @param[in] cacheModel The cache model option
242    * @see Toolkit::WebView::CacheModel::Type
243    */
244   void SetCacheModel( Toolkit::WebView::CacheModel::Type cacheModel );
245
246   /**
247    * @brief Gets the cookie acceptance policy. The default is Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
248    * @see Toolkit::WebView::CookieAcceptPolicy::Type
249    */
250   Toolkit::WebView::CookieAcceptPolicy::Type GetCookieAcceptPolicy() const;
251
252   /**
253    * @brief Sets the cookie acceptance policy. The default is Toolkit::WebView::CookieAcceptPolicy::NO_THIRD_PARTY.
254    * @param[in] policy The cookie acceptance policy
255    * @see Toolkit::WebView::CookieAcceptPolicy::Type
256    */
257   void SetCookieAcceptPolicy( Toolkit::WebView::CookieAcceptPolicy::Type policy );
258
259   /**
260    * @brief Get user agent string.
261    * @return The string value of user agent
262    */
263   const std::string& GetUserAgent() const;
264
265   /**
266    * @brief Set user agent string.
267    * @param[in] userAgent The string value of user agent
268    */
269   void SetUserAgent( const std::string& userAgent );
270
271   /**
272    * @brief Returns whether JavaScript can be executable. The default is true.
273    *
274    * @return true if JavaScript executing is enabled, false otherwise
275    */
276   bool IsJavaScriptEnabled() const;
277
278   /**
279    * @brief Enables/disables JavaScript executing. The default is enabled.
280    *
281    * @param[in] enabled True if JavaScript executing is enabled, false otherwise
282    */
283   void EnableJavaScript( bool enabled );
284
285   /**
286    * @brief Returns whether images can be loaded automatically. The default is true.
287    *
288    * @return true if images are loaded automatically, false otherwise
289    */
290   bool AreImagesAutomaticallyLoaded() const;
291
292   /**
293    * @brief Enables/disables auto loading of images. The default is enabled.
294    *
295    * @param[in] automatic True if images are loaded automatically, false otherwise
296    */
297   void LoadImagesAutomatically( bool automatic );
298
299   /**
300    * @brief Gets the default text encoding name (e.g. UTF-8).
301    *
302    * @return The default text encoding name
303    */
304   const std::string& GetDefaultTextEncodingName() const;
305
306   /**
307    * @brief Sets the default text encoding name (e.g. UTF-8).
308    *
309    * @param[in] defaultTextEncodingName The default text encoding name
310    */
311   void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName );
312
313   /**
314    * @brief Returns the default font size in pixel. The default value is 16.
315    *
316    * @return The default font size
317    */
318   int GetDefaultFontSize() const;
319
320   /**
321    * @brief Sets the default font size in pixel. The default value is 16.
322    *
323    * @param[in] defaultFontSize A new default font size to set
324    */
325   void SetDefaultFontSize( int defaultFontSize );
326
327   /**
328    * @brief Callback function to be called when page load started.
329    * @param[in] url The url currently being loaded
330    */
331   void OnPageLoadStarted( const std::string& url );
332
333   /**
334    * @brief Callback function to be called when page load finished.
335    * @param[in] url The url currently being loaded
336    */
337   void OnPageLoadFinished( const std::string& url );
338
339   /**
340    * @brief Callback function to be called when there is an error in page loading.
341    * @param[in] url The url currently being loaded
342    * @param[in] errorCode The error code
343    */
344   void OnPageLoadError( const std::string& url, int errorCode );
345
346 private:
347
348   std::string                                            mUrl;
349   Dali::Toolkit::Visual::Base                            mVisual;
350   Dali::Size                                             mWebViewSize;
351   Dali::WebEngine                                        mWebEngine;
352
353   Dali::Toolkit::WebView::WebViewPageLoadSignalType      mPageLoadStartedSignal;
354   Dali::Toolkit::WebView::WebViewPageLoadSignalType      mPageLoadFinishedSignal;
355   Dali::Toolkit::WebView::WebViewPageLoadErrorSignalType mPageLoadErrorSignal;
356 };
357
358 } // namespace Internal
359
360 inline Toolkit::Internal::WebView& GetImpl( Toolkit::WebView& handle )
361 {
362   DALI_ASSERT_ALWAYS( handle );
363   Dali::RefObject& impl = handle.GetImplementation();
364   return static_cast< Toolkit::Internal::WebView& >( impl );
365 }
366
367 inline const Toolkit::Internal::WebView& GetImpl( const Toolkit::WebView& handle )
368 {
369   DALI_ASSERT_ALWAYS( handle );
370   const Dali::RefObject& impl = handle.GetImplementation();
371   return static_cast< const Toolkit::Internal::WebView& >( impl );
372 }
373
374 } // namespace Toolkit
375
376 } // namespace Dali
377
378 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H