Fixed navigating using 'Backspace' key
[profile/tv/apps/web/browser.git] / services / WebKitEngineService / WebKitEngineService.h
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef WEBKITENGINESERVICE_H_
18 #define WEBKITENGINESERVICE_H_
19
20 #include <boost/noncopyable.hpp>
21 #include <string>
22 #include <Evas.h>
23 #include <memory>
24
25 #include "ServiceFactory.h"
26 #include "service_macros.h"
27
28 #include "AbstractWebEngine/AbstractWebEngine.h"
29 #include "AbstractWebEngine/TabId.h"
30 #include "AbstractWebEngine/WebConfirmation.h"
31 #include "BrowserImage.h"
32
33 namespace tizen_browser {
34 namespace basic_webengine {
35 namespace webkitengine_service {
36
37 class WebView;
38
39 typedef std::shared_ptr<WebView> WebViewPtr;
40
41 class BROWSER_EXPORT WebKitEngineService: public AbstractWebEngine<Evas_Object>, boost::noncopyable
42 {
43 public:
44     WebKitEngineService();
45     virtual ~WebKitEngineService();
46     virtual std::string getName();
47
48     Evas_Object * getLayout();
49     void init(void * guiParent);
50
51     void setURI(const std::string &);
52     std::string getURI(void) const;
53
54     std::string getTitle(void) const;
55
56     void suspend(void);
57     void resume(void);
58     bool isSuspended(void) const;
59
60     void stopLoading(void);
61     void reload(void);
62
63     void back(void);
64     void forward(void);
65
66     bool isBackEnabled(void) const;
67     bool isForwardEnabled(void) const;
68
69     bool isLoading() const;
70
71     void clearPrivateData();
72
73     int tabsCount() const;
74     TabId currentTabId() const;
75     std::list<TabId> listTabs() const;
76     std::vector<std::shared_ptr<TabContent> > getTabContents() const;
77
78     /**
79      * Adds new tab. If uri is specified setURI(uri).
80      * If it first tab in WebEngine switch to this tab.
81      * @param uri
82      * @return TabId of created tab
83      */
84     TabId addTab(const std::string & uri = std::string(), const TabId * openerId = NULL, bool desktopMode = true, bool incognitoMode = false);
85     Evas_Object* getTabView(TabId id);
86     bool switchToTab(TabId);
87     bool closeTab();
88     bool closeTab(TabId);
89
90     /**
91      * Change tab to next created, dummy implementation.
92      * @return true if changed successfully, false otherwise
93      */
94     bool nextTab();
95     /**
96      * Change tab to previous created, dummy implementation.
97      * @return true if changed successfully, false otherwise
98      */
99     bool prevTab();
100
101     void confirmationResult(WebConfirmationPtr);
102
103     /**
104      * @brief Get snapshot of webpage
105      *
106      * @param width of snapshot
107      * @param height of snapshot
108      * @return Shared pointer to BrowserImage
109      */
110     std::shared_ptr<tizen_browser::tools::BrowserImage> getSnapshotData(int width, int height);
111
112     std::shared_ptr<tizen_browser::tools::BrowserImage> getSnapshotData(TabId id, int width, int height);
113
114     /**
115      * @brief Get the state of private mode for a specific tab
116      *
117      * @param id of snapshot
118      * @return state of private mode where:
119      *     -1 is "Not set"
120      *      0 is "False"
121      *      1 is "True"
122      */
123     bool isPrivateMode(const TabId& id);
124
125
126     /**
127      * @brief Check if current tab has load error.
128      *
129      */
130     bool isLoadError() const;
131
132      /**
133      * \brief Sets Focus to URI entry.
134      */
135     void setFocus();
136
137     /**
138      * @brief Remove focus form URI
139      */
140     void clearFocus();
141
142     /**
143      * @brief check if URI is focused
144      */
145     bool hasFocus() const;
146
147     virtual int getZoomFactor() const;
148
149     /**
150      * @brief check if autofit is enabled
151      */
152
153     virtual void setZoomFactor(int zoomFactor);
154
155
156     /**
157      * @brief Search string on searchOnWebsite
158      *
159      * @param string to search on searchOnWebsite
160      * @param flags for search options
161      */
162     void searchOnWebsite(const std::string &, int flags);
163
164     /**
165      * @brief Get favicon of current page loaded
166      */
167     std::shared_ptr<tizen_browser::tools::BrowserImage> getFavicon();
168
169     /**
170      * @brief back or exit when back key is pressed
171      */
172     void backButtonClicked();
173
174     void switchToMobileMode();
175     void switchToDesktopMode();
176     bool isDesktopMode() const;
177
178     void scrollView(const int& dx, const int& dy);
179
180 private:
181     // callbacks from WebView
182     void _favIconChanged(std::shared_ptr<tizen_browser::tools::BrowserImage> bi);
183     void _titleChanged(const std::string &);
184     void _uriChanged(const std::string &);
185     void _loadFinished();
186     void _loadStarted();
187     void _loadStop();
188     void _loadError();
189     void _forwardEnableChanged(bool);
190     void _backwardEnableChanged(bool);
191     void _loadProgress(double);
192     void _confirmationRequest(WebConfirmationPtr) ;
193     void _IMEStateChanged(bool);
194     void webViewClicked();
195
196     /**
197      * disconnect signals from specified WebView
198      * \param WebView
199      */
200     void disconnectSignals(WebViewPtr);
201
202     void disconnectCurrentWebViewSignals();
203
204     /**
205      * connect signals of specified WebView
206      * \param WebView
207      */
208     void connectSignals(WebViewPtr);
209
210 private:
211     bool m_initialised;
212     void * m_guiParent;
213     bool m_stopped;
214
215     // current TabId
216     TabId m_currentTabId;
217     // current WebView
218     WebViewPtr m_currentWebView;
219
220     // map of all tabs (WebViews)
221     std::map<TabId, WebViewPtr > m_tabs;
222     // Most recent tab list
223     std::list<TabId> m_mostRecentTab;
224     // recently added tabs first
225     std::list<TabId> m_chronoTabs;
226 };
227
228 } /* end of webkitengine_service */
229 } /* end of basic_webengine */
230 } /* end of tizen_browser */
231
232 #endif /* WEBKITENGINESERVICE_H_ */