1 #ifndef DALI_WEB_ENGINE_H
2 #define DALI_WEB_ENGINE_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/object/base-handle.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
26 #include <dali/public-api/dali-adaptor-common.h>
35 } // namespace Adaptor
37 } // namespace Internal
40 * @brief Proxy class to dynamically load, use and unload web engine plugin.
42 * The purpose of this class is to dynamically load the web engine plugin if and when its needed.
43 * So we don't slow down every application startup if they never need web engine.
45 class DALI_ADAPTOR_API WebEngine : public BaseHandle
59 * @brief Creates a new instance of a WebEngine.
61 static WebEngine New();
64 * @brief Copy constructor.
66 * @param[in] WebEngine WebEngine to copy. The copied WebEngine will point at the same implementation
68 WebEngine(const WebEngine& WebEngine);
71 * @brief Assignment operator.
73 * @param[in] WebEngine The WebEngine to assign from.
74 * @return The updated WebEngine.
76 WebEngine& operator=(const WebEngine& WebEngine);
79 * @brief Downcast a handle to WebEngine handle.
81 * If handle points to a WebEngine the downcast produces valid
82 * handle. If not the returned handle is left uninitialized.
84 * @param[in] handle Handle to an object
85 * @return Handle to a WebEngine or an uninitialized handle
87 static WebEngine DownCast(BaseHandle handle);
90 * @brief Creates WebEngine instance.
92 * @param [in] width The width of Web
93 * @param [in] height The height of Web
94 * @param [in] locale The locale of Web
95 * @param [in] timezoneId The timezoneID of Web
97 void Create(int width, int height, const std::string& locale, const std::string& timezoneId);
100 * @brief Destroys WebEngine instance.
105 * @brief Gets native image source to render.
107 NativeImageInterfacePtr GetNativeImageSource();
110 * @brief Get settings of WebEngine.
112 Dali::WebEngineSettings& GetSettings() const;
115 * @brief Get context of WebEngine.
117 Dali::WebEngineContext& GetContext() const;
120 * @brief Get cookie manager of WebEngine.
122 Dali::WebEngineCookieManager& GetCookieManager() const;
125 * @brief Get back-forward list of WebEngine.
127 Dali::WebEngineBackForwardList& GetBackForwardList() const;
130 * @brief Loads a web page based on a given URL.
132 * @param [in] url The URL of the resource to load
134 void LoadUrl(const std::string& url);
137 * @brief Gets the url.
139 const std::string& GetUrl();
142 * @brief Loads a given string as web contents.
144 * @param [in] htmlString The string to use as the contents of the web page
146 void LoadHtmlString(const std::string& htmlString);
149 * @brief Reloads the Web.
154 * @brief Stops loading web contents on the current page.
159 * @brief Suspends the operation associated with the view.
164 * @brief Resumes the operation associated with the view object after calling Suspend().
169 * @brief Scrolls the webpage of view by deltaX and deltaY.
171 void ScrollBy( int deltaX, int deltaY );
174 * @brief Sets an absolute scroll of the given view.
176 void SetScrollPosition( int x, int y );
179 * @brief Gets the current scroll position of the given view.
181 void GetScrollPosition( int& x, int& y ) const;
184 * @brief Gets the possible scroll size of the given view.
186 void GetScrollSize( int& width, int& height ) const;
189 * @brief Gets the last known content's size.
191 void GetContentSize( int& width, int& height ) const;
194 * @brief Returns whether forward is possible.
196 * @return True if forward is possible, false otherwise
201 * @brief Goes to forward.
206 * @brief Returns whether backward is possible.
208 * @return True if backward is possible, false otherwise
213 * @brief Goes to back.
218 * @brief Evaluates JavaScript code represented as a string.
220 * @param[in] script The JavaScript code
221 * @param[in] resultHandler The callback function to be called by the JavaScript runtime. This carries evaluation result.
223 void EvaluateJavaScript(const std::string& script, std::function<void(const std::string&)> resultHandler);
226 * @brief Add a message handler into JavaScript.
228 * @param[in] exposedObjectName The name of exposed object
229 * @param[in] handler The callback function
231 void AddJavaScriptMessageHandler(const std::string& exposedObjectName, std::function<void(const std::string&)> handler);
234 * @brief Clears the history of Web.
239 * @brief Get user agent string.
241 * @return The string value of user agent
243 const std::string& GetUserAgent() const;
246 * @brief Set user agent string.
248 * @param[in] userAgent The string value of user agent
250 void SetUserAgent(const std::string& userAgent);
253 * @brief Sets the size of Web Pages.
255 void SetSize(int width, int height);
258 * @brief Sends Touch Events.
260 bool SendTouchEvent(const TouchEvent& touch);
263 * @brief Sends key Events.
265 bool SendKeyEvent(const KeyEvent& event);
270 void SetFocus( bool focused );
273 * @brief Connects to this signal to be notified when page loading is started.
275 * @return A signal object to connect with.
277 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal();
280 * @brief Connects to this signal to be notified when page loading is finished.
282 * @return A signal object to connect with.
284 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal();
287 * @brief Connects to this signal to be notified when an error occurs in page loading.
289 * @return A signal object to connect with.
291 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal();
294 * @brief Connects to this signal to be notified when scroll edge is reached.
296 * @return A signal object to connect with.
298 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
300 private: // Not intended for application developers
302 * @brief Internal constructor
304 explicit DALI_INTERNAL WebEngine(Internal::Adaptor::WebEngine* internal);
309 #endif // DALI_WEB_ENGINE_H