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