2bc7ddf719894701c808a5ddcc6d07ff1307098c
[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) 2018 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 TouchData;
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::Toolkit::WebView::GetUrl()
72    */
73   const std::string& GetUrl();
74
75   /**
76    * @copydoc Dali::WebEngine::LoadHTMLString()
77    */
78   void LoadHTMLString( const std::string& htmlString );
79
80   /**
81    * @copydoc Dali::WebEngine::Reload()
82    */
83   void Reload();
84
85   /**
86    * @copydoc Dali::WebEngine::StopLoading()
87    */
88   void StopLoading();
89
90   /**
91    * @copydoc Dali::WebEngine::CanGoForward()
92    */
93   bool CanGoForward();
94
95   /**
96    * @copydoc Dali::WebEngine::GoForward()
97    */
98   void GoForward();
99
100   /**
101    * @copydoc Dali::WebEngine::CanGoBack()
102    */
103   bool CanGoBack();
104
105   /**
106    * @copydoc Dali::WebEngine::GoBack()
107    */
108   void GoBack();
109
110   /**
111    * @copydoc Dali::WebEngine::EvaluateJavaScript()
112    */
113   void EvaluateJavaScript( const std::string& script );
114
115   /**
116    * @copydoc Dali::WebEngine::AddJavaScriptMessageHandler()
117    */
118   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void( const std::string& ) > handler );
119
120   /**
121    * @copydoc Dali::WebEngine::ClearHistory()
122    */
123   void ClearHistory();
124
125   /**
126    * @copydoc Dali::WebEngine::ClearCache()
127    */
128   void ClearCache();
129
130   /**
131    * @copydoc Dali::Toolkit::WebView::PageLoadStartedSignal()
132    */
133   Dali::Toolkit::WebView::WebViewSignalType& PageLoadStartedSignal();
134
135   /**
136    * @copydoc Dali::Toolkit::WebView::PageLoadFinishedSignal()
137    */
138   Dali::Toolkit::WebView::WebViewSignalType& PageLoadFinishedSignal();
139
140 public: // Properties
141
142   /**
143    * @brief Called when a property of an object of this type is set.
144    *
145    * @param[in] object The object whose property is set.
146    * @param[in] index The property index.
147    * @param[in] value The new property value.
148    */
149   static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
150
151   /**
152    * @brief Called to retrieve a property of an object of this type.
153    *
154    * @param[in] object The object whose property is to be retrieved.
155    * @param[in] index The property index.
156    * @return The current value of the property.
157    */
158   static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
159
160   /**
161    * Connects a callback function with the object's signals.
162    * @param[in] object The object providing the signal.
163    * @param[in] tracker Used to disconnect the signal.
164    * @param[in] signalName The signal to connect to.
165    * @param[in] functor A newly allocated FunctorDelegate.
166    * @return True if the signal was connected.
167    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the c
168    */
169   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
170
171 private: // From Control
172
173   /**
174    * @copydoc Toolkit::Control::OnInitialize()
175    */
176   virtual void OnInitialize();
177
178   /**
179    * @copydoc Toolkit::Control::GetNaturalSize
180    */
181   virtual Vector3 GetNaturalSize();
182
183   /**
184    * @copydoc Toolkit::Control::OnRelayout()
185    */
186   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
187
188   /**
189    * Signal occurs when the Web View has been touched.
190    * @param[in] actor The Actor Touched
191    * @param[in] touch The Touch Data.
192    * @return Whether to consume event or not.
193    */
194   bool OnTouchEvent( Actor actor, const Dali::TouchData& touch );
195
196   /**
197    * @copydoc Toolkit::Control::OnKeyEvent()
198    */
199   virtual bool OnKeyEvent( const Dali::KeyEvent& event );
200
201 private:
202
203   // Undefined
204   WebView( const WebView& webView );
205
206   WebView& operator=( const WebView& webView );
207
208   void OnPageLoadStarted( const std::string& url );
209
210   void OnPageLoadFinished( const std::string& url );
211
212 private:
213
214   std::string mUrl;
215   Dali::Toolkit::Visual::Base mVisual;
216   Dali::Size mWebViewSize;
217   Dali::WebEngine mWebEngine;
218   Dali::Toolkit::WebView::WebViewSignalType mPageLoadStartedSignal;
219   Dali::Toolkit::WebView::WebViewSignalType mPageLoadFinishedSignal;
220 };
221
222 } // namespace Internal
223
224 inline Toolkit::Internal::WebView& GetImpl( Toolkit::WebView& handle )
225 {
226   DALI_ASSERT_ALWAYS( handle );
227   Dali::RefObject& impl = handle.GetImplementation();
228   return static_cast< Toolkit::Internal::WebView& >( impl );
229 }
230
231 inline const Toolkit::Internal::WebView& GetImpl( const Toolkit::WebView& handle )
232 {
233   DALI_ASSERT_ALWAYS( handle );
234   const Dali::RefObject& impl = handle.GetImplementation();
235   return static_cast< const Toolkit::Internal::WebView& >( impl );
236 }
237
238 } // namespace Toolkit
239
240 } // namespace Dali
241
242 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H