Fixed navigating by D-pad in History and Settings
[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
56 namespace tizen_browser{
57 namespace base_ui{
58
59 template <>
60 void AbstractMainWindow<Evas_Object>::setMainWindow(Evas_Object * rawPtr)
61 {
62     m_window = std::shared_ptr<Evas_Object>(rawPtr, evas_object_del);
63 }
64
65 class BROWSER_EXPORT SimpleUI : public AbstractMainWindow<Evas_Object>
66 {
67 public:
68     SimpleUI(/*Evas_Object *window*/);
69     virtual ~SimpleUI();
70     virtual int exec(const std::string& url);
71     virtual std::string getName();
72
73     void destroyUI();
74 private:
75     // setup functions
76     void createActions();
77     void connectActions();
78     void loadUIServices();
79     void connectUISignals();
80     void loadModelServices();
81     void initModelServices();
82     void initUIServices();
83     void connectModelSignals();
84     void restoreLastSession();
85     Evas_Object* createWebLayout(Evas_Object* parent);
86     Evas_Object* createErrorLayout(Evas_Object* parent);
87
88
89     void backEnable(bool enable);
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 switchViewToQuickAccess();
111     void switchViewToWebPage();
112     void updateView();
113
114     void openNewTab(const std::string &uri, bool desktopMode = true);
115     void switchToTab(const tizen_browser::basic_webengine::TabId& tabId);
116     void newTabClicked(const std::string &);
117     void tabClicked(const tizen_browser::basic_webengine::TabId& tabId);
118     void closeTabsClicked(const tizen_browser::basic_webengine::TabId& tabId);
119     void tabCreated();
120     void tabClosed(const tizen_browser::basic_webengine::TabId& id);
121
122     std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > getBookmarks(int folder_id = -1);
123     std::shared_ptr<services::HistoryItemVector> getHistory();
124     std::shared_ptr<services::HistoryItemVector> getMostVisitedItems();
125
126     //UI signal handling functions
127     void onBookmarkAdded(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
128
129     void onBookmarkClicked(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
130     void onBookmarkRemoved(const std::string& uri);
131
132     void onHistoryAdded(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem);
133     void onHistoryRemoved(const std::string& uri);
134     void onOpenURLInNewTab(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, bool desktopMode);
135     void onMostVisitedTileClicked(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, int itemsNumber);
136     void onClearHistoryClicked(const std::string&);
137
138     void onMostVisitedClicked(const std::string&);
139     void onBookmarkButtonClicked(const std::string&);
140     void onBookmarkManagerButtonClicked(const std::string&);
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 showHistory();
203     void hideHistory();
204
205     void showTabUI();
206     void closeTabUI(const std::string& str);
207     void showMoreMenu();
208     void closeMoreMenu(const std::string& str);
209     void switchToMobileMode();
210     void switchToDesktopMode();
211     void showHistoryUI(const std::string& str);
212     void closeHistoryUI();
213     void showURIBar();
214     void hideURIBar();
215     void hideSettingsMenu();
216     void showSettingsUI(const std::string&);
217     void closeSettingsUI(const std::string&);
218
219     void closeBookmarkManagerMenu(const std::string& str);
220     void showBookmarkManagerMenu();
221
222     void showPopup(Evas_Object *content, char* btn1_text, char* btn2_text);
223
224     void closeTab();
225     void closeTab(const tizen_browser::basic_webengine::TabId& id);
226
227     void settingsPointerModeSwitch(bool newState);
228     void settingsPrivateModeSwitch(bool newState);
229     void settingsDeleteData();
230     void settingsDeleteFavorite();
231     void settingsDeleteSelectedData(const std::string& str);
232     void settingsResetMostVisited(const std::string& str);
233     void settingsResetBrowser(const std::string& str);
234     void onDeleteSelectedDataButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
235     void onDeleteMostVisitedButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
236     void onResetBrowserButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
237     void onDeleteDataButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
238     void onDeleteFavoriteButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
239     void tabLimitPopupButtonClicked(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/);
240     void disableHistoryButton(bool flag);
241     int tabsCount();
242
243     void onNetworkError();
244     void onNetworkConnected();
245     void onNetErrorButtonPressed(PopupButtons, std::shared_ptr<PopupData>);
246
247     void onReturnPressed(MenuButton *m);
248     void onBackPressed();
249
250     boost::signals2::signal<void ()> hidePopup;
251
252     std::string edjePath(const std::string &);
253
254     Evas_Object *m_popup;
255     Evas_Object *m_entry;
256     Evas_Object *m_errorLayout;
257
258     std::shared_ptr<WebPageUI> m_webPageUI;
259     std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>>  m_webEngine;
260 //     std::shared_ptr<tizen_browser::base_ui::URIEntry> m_simpleURI;
261     std::shared_ptr<tizen_browser::interfaces::AbstractFavoriteService> m_favoriteService;
262     std::shared_ptr<tizen_browser::services::HistoryService> m_historyService;
263     std::shared_ptr<tizen_browser::base_ui::MoreMenuUI> m_moreMenuUI;
264     std::shared_ptr<tizen_browser::base_ui::BookmarkManagerUI> m_bookmarkManagerUI;
265     std::shared_ptr<tizen_browser::base_ui::MainUI> m_mainUI;
266     std::shared_ptr<tizen_browser::base_ui::HistoryUI> m_historyUI;
267     std::shared_ptr<tizen_browser::base_ui::SettingsUI> m_settingsUI;
268     std::shared_ptr<tizen_browser::base_ui::TabUI> m_tabUI;
269     std::shared_ptr<tizen_browser::services::PlatformInputManager> m_platformInputManager;
270     std::shared_ptr<tizen_browser::services::SessionStorage> m_sessionService;
271     tizen_browser::Session::Session m_currentSession;
272     std::shared_ptr<BookmarksManager> m_bookmarks_manager;
273     bool m_initialised;
274     int m_tabLimit;
275     int m_favoritesLimit;
276     bool m_wvIMEStatus;
277     // This context object is used to implicitly init internal ewk data used by opengl to create the first and
278     // consecutive webviews in the application, otherwise we would encounter a crash after creating
279     // the first web view
280     Ewk_Context *m_ewkContext;
281
282     std::vector<std::shared_ptr<tizen_browser::services::HistoryItem>> items_vector;
283     SimplePopup* m_networkErrorPopup;
284
285     void searchWebPage(std::string &text, int flags);
286 };
287
288 }
289 }
290
291 #endif /* SIMPLEUI_H_ */