Limit number of opened tabs in brower
[profile/tv/apps/web/browser.git] / services / SimpleUI / SimpleUI.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 /*
18  * SimpleUI.h
19  *
20  *  Created on: Mar 18, 2014
21  *      Author: k.szalilow
22  */
23
24 #ifndef SIMPLEUI_H_
25 #define SIMPLEUI_H_
26
27 #include <Evas.h>
28
29 #include "AbstractMainWindow.h"
30 #include "AbstractService.h"
31 #include "AbstractFavoriteService.h"
32 #include "ServiceFactory.h"
33 #include "service_macros.h"
34
35 // components
36 #include "WebPageUI.h"
37 #include "AbstractWebEngine.h"
38 #include "MoreMenuUI.h"
39 #include "HistoryUI.h"
40 #include "SettingsUI.h"
41 #include "QuickAccess.h"
42 #include "TabUI.h"
43 #include "ZoomUI.h"
44 #include "HistoryService.h"
45 #include "BookmarkManagerUI.h"
46 #include "PlatformInputManager.h"
47 #include "SessionStorage.h"
48 #include "SqlStorage.h"
49
50 // other
51 #include "Action.h"
52 #include "SimplePopup.h"
53 #include "WebConfirmation.h"
54 #include "BookmarksManager.h"
55 #include "Config.h"
56 #include "ViewManager.h"
57
58 namespace tizen_browser{
59 namespace base_ui{
60
61 template <>
62 void AbstractMainWindow<Evas_Object>::setMainWindow(Evas_Object * rawPtr)
63 {
64     m_window = std::shared_ptr<Evas_Object>(rawPtr, evas_object_del);
65 }
66
67 class BROWSER_EXPORT SimpleUI : public AbstractMainWindow<Evas_Object>
68 {
69 public:
70     SimpleUI(/*Evas_Object *window*/);
71     virtual ~SimpleUI();
72     virtual int exec(const std::string& url);
73     virtual std::string getName();
74
75     void destroyUI();
76 private:
77     // setup functions
78     void createActions();
79     void connectActions();
80     void loadUIServices();
81     void connectUISignals();
82     void loadModelServices();
83     void initModelServices();
84     void initUIServices();
85     void connectModelSignals();
86     void restoreLastSession();
87     Evas_Object* createWebLayout(Evas_Object* parent);
88     Evas_Object* createErrorLayout(Evas_Object* parent);
89
90     void forwardEnable(bool enable);
91     void stopEnable(bool enable);
92     void reloadEnable(bool enable);
93
94     void loadFinished();
95     void progressChanged(double progress);
96     void loadStarted();
97
98     void loadError();
99     void setErrorButtons();
100     bool isErrorPageActive();
101
102     void bookmarkAdded();
103     void bookmarkDeleted();
104
105     void showQuickAccess();
106     void switchViewToQuickAccess();
107     void switchViewToWebPage();
108     void updateView();
109
110     void openNewTab(const std::string &uri, bool desktopMode = true);
111     void switchToTab(const tizen_browser::basic_webengine::TabId& tabId);
112     void newTabClicked();
113     void tabClicked(const tizen_browser::basic_webengine::TabId& tabId);
114     void closeTabsClicked(const tizen_browser::basic_webengine::TabId& tabId);
115     void tabCreated();
116     bool checkIfCreate();
117     void tabClosed(const tizen_browser::basic_webengine::TabId& id);
118
119     std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > getBookmarks(int folder_id = -1);
120     std::shared_ptr<services::HistoryItemVector> getHistory();
121     std::shared_ptr<services::HistoryItemVector> getMostVisitedItems();
122
123     //UI signal handling functions
124     void onBookmarkAdded(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
125
126     void onBookmarkClicked(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
127     void onBookmarkRemoved(const std::string& uri);
128
129     void onHistoryRemoved(const std::string& uri);
130     void onOpenURLInNewTab(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, bool desktopMode);
131     void onMostVisitedTileClicked(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, int itemsNumber);
132     void onClearHistoryClicked();
133
134     void onMostVisitedClicked();
135     void onBookmarkButtonClicked();
136
137     void handleConfirmationRequest(basic_webengine::WebConfirmationPtr webConfirmation);
138     void authPopupButtonClicked(PopupButtons button, std::shared_ptr<PopupData> popupData);
139
140     void onActionTriggered(const Action& action);
141     void setwvIMEStatus(bool status);
142
143     sharedAction m_showBookmarkManagerUI;
144     sharedAction m_settingPrivateBrowsing;
145
146     /**
147      * \brief filters URL before it is passed to WebEngine.
148      *
149      * This function should be connected with m_simpleURI->uriChanged.
150      * it is a good place to check for special urls (like "about:home"),
151      * filter forbidden addresses and to check set favorite icon.
152      */
153     void filterURL(const std::string& url);
154
155     /**
156      * Checks if correct tab is visible to user, and if not, it update browser view
157      * @param id of tab that should be visible to user
158      */
159     void checkTabId(const tizen_browser::basic_webengine::TabId& id);
160
161     /**
162      * \brief check if url comming back from WebEngine should be passed to URI.
163      *
164      * For filtered addresses we need to hide real URI so the user would be confused.
165      * and this is a back function that checks if address emited from browser should be changed.
166      */
167     void webEngineURLChanged(const std::string url);
168     void onmostHistoryvisitedClicked();
169     void onBookmarkvisitedClicked();
170     /**
171      * @brief Check if the current page exists as a bookmark.
172      *
173      */
174     bool checkBookmark();
175     /**
176      * @brief Adds current page to bookmarks.
177      *
178      */
179     void addToBookmarks(int);
180     /**
181      * @brief Remove current page from bookmarks
182      *
183      * @param  ...
184      * @return void
185      */
186     void deleteBookmark(void);
187
188     /**
189      * @brief show Zoom Menu
190      */
191     void showZoomUI();
192     void closeZoomUI();
193     void setZoomFactor(int level);
194     void scrollView(const int& dx, const int& dy);
195
196     void showTabUI();
197     void closeTabUI();
198     void showMoreMenu();
199     void closeMoreMenu();
200     void switchToMobileMode();
201     void switchToDesktopMode();
202     void showHistoryUI();
203     void closeHistoryUI();
204     void showSettingsUI();
205     void closeSettingsUI();
206     void closeBookmarkManagerUI();
207     void showBookmarkManagerUI();
208     void showPopup(Evas_Object *content, char* btn1_text, char* btn2_text);
209
210     void closeTab();
211     void closeTab(const tizen_browser::basic_webengine::TabId& id);
212
213     void settingsPrivateModeSwitch(bool newState);
214     void settingsDeleteSelectedData(const std::string& str);
215     void settingsResetMostVisited();
216     void settingsResetBrowser();
217     void onDeleteSelectedDataButton(const std::string &dataText);
218     void onDeleteMostVisitedButton(std::shared_ptr<PopupData> popupData);
219     void onResetBrowserButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
220     void tabLimitPopupButtonClicked(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/);
221     int tabsCount();
222
223     void onReturnPressed(MenuButton *m);
224     void onBackPressed();
225
226     void searchWebPage(std::string &text, int flags);
227
228     std::string edjePath(const std::string &);
229
230     Evas_Object *m_popup;
231
232     std::shared_ptr<WebPageUI> m_webPageUI;
233     std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>>  m_webEngine;
234     std::shared_ptr<interfaces::AbstractFavoriteService> m_favoriteService;
235     std::shared_ptr<services::HistoryService> m_historyService;
236     std::shared_ptr<MoreMenuUI> m_moreMenuUI;
237     std::shared_ptr<BookmarkManagerUI> m_bookmarkManagerUI;
238     std::shared_ptr<QuickAccess> m_quickAccess;
239     std::shared_ptr<HistoryUI> m_historyUI;
240     std::shared_ptr<SettingsUI> m_settingsUI;
241     std::shared_ptr<TabUI> m_tabUI;
242     std::shared_ptr<services::PlatformInputManager> m_platformInputManager;
243     std::shared_ptr<services::SessionStorage> m_sessionService;
244     Session::Session m_currentSession;
245     std::shared_ptr<tizen_browser::base_ui::ZoomUI> m_zoomUI;
246     std::shared_ptr<BookmarksManager> m_bookmarks_manager;
247     bool m_initialised;
248     int m_tabLimit;
249     int m_favoritesLimit;
250     bool m_wvIMEStatus;
251
252     //helper object used to view management
253     ViewManager* m_viewManager;
254
255     // This context object is used to implicitly init internal ewk data used by opengl to create the first and
256     // consecutive webviews in the application, otherwise we would encounter a crash after creating
257     // the first web view
258     Ewk_Context *m_ewkContext;
259 };
260
261 }
262 }
263
264 #endif /* SIMPLEUI_H_ */