Implemented ZoomUI service
[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 "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 showMainUI();
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     void tabClosed(const tizen_browser::basic_webengine::TabId& id);
117
118     std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem> > getBookmarks(int folder_id = -1);
119     std::shared_ptr<services::HistoryItemVector> getHistory();
120     std::shared_ptr<services::HistoryItemVector> getMostVisitedItems();
121
122     //UI signal handling functions
123     void onBookmarkAdded(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
124
125     void onBookmarkClicked(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
126     void onBookmarkRemoved(const std::string& uri);
127
128     void onHistoryRemoved(const std::string& uri);
129     void onOpenURLInNewTab(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, bool desktopMode);
130     void onMostVisitedTileClicked(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, int itemsNumber);
131     void onClearHistoryClicked();
132
133     void onMostVisitedClicked();
134     void onBookmarkButtonClicked();
135
136     void handleConfirmationRequest(basic_webengine::WebConfirmationPtr webConfirmation);
137     void authPopupButtonClicked(PopupButtons button, std::shared_ptr<PopupData> popupData);
138
139     void onActionTriggered(const Action& action);
140     void setwvIMEStatus(bool status);
141
142     sharedAction m_showBookmarkManagerUI;
143     sharedAction m_settingPrivateBrowsing;
144
145     /**
146      * \brief filters URL before it is passed to WebEngine.
147      *
148      * This function should be connected with m_simpleURI->uriChanged.
149      * it is a good place to check for special urls (like "about:home"),
150      * filter forbidden addresses and to check set favorite icon.
151      */
152     void filterURL(const std::string& url);
153
154     /**
155      * Checks if correct tab is visible to user, and if not, it update browser view
156      * @param id of tab that should be visible to user
157      */
158     void checkTabId(const tizen_browser::basic_webengine::TabId& id);
159
160     /**
161      * \brief check if url comming back from WebEngine should be passed to URI.
162      *
163      * For filtered addresses we need to hide real URI so the user would be confused.
164      * and this is a back function that checks if address emited from browser should be changed.
165      */
166     void webEngineURLChanged(const std::string url);
167     void onmostHistoryvisitedClicked();
168     void onBookmarkvisitedClicked();
169     /**
170      * @brief Check if the current page exists as a bookmark.
171      *
172      */
173     bool checkBookmark();
174     /**
175      * @brief Adds current page to bookmarks.
176      *
177      */
178     void addToBookmarks(int);
179     /**
180      * @brief Remove current page from bookmarks
181      *
182      * @param  ...
183      * @return void
184      */
185     void deleteBookmark(void);
186
187     /**
188      * @brief show Zoom Menu
189      */
190     void showZoomUI();
191     void closeZoomUI();
192     void setZoomFactor(int level);
193     void scrollView(const int& dx, const int& dy);
194
195     void showTabUI();
196     void closeTabUI();
197     void showMoreMenu();
198     void closeMoreMenu();
199     void switchToMobileMode();
200     void switchToDesktopMode();
201     void showHistoryUI();
202     void closeHistoryUI();
203     void showSettingsUI();
204     void closeSettingsUI();
205     void closeBookmarkManagerUI();
206     void showBookmarkManagerUI();
207     void showPopup(Evas_Object *content, char* btn1_text, char* btn2_text);
208
209     void closeTab();
210     void closeTab(const tizen_browser::basic_webengine::TabId& id);
211
212     void settingsPrivateModeSwitch(bool newState);
213     void settingsDeleteSelectedData(const std::string& str);
214     void settingsResetMostVisited();
215     void settingsResetBrowser();
216     void onDeleteSelectedDataButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
217     void onDeleteMostVisitedButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
218     void onResetBrowserButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
219     void tabLimitPopupButtonClicked(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/);
220     int tabsCount();
221
222     void onReturnPressed(MenuButton *m);
223     void onBackPressed();
224
225     void searchWebPage(std::string &text, int flags);
226
227     std::string edjePath(const std::string &);
228
229     Evas_Object *m_popup;
230
231     std::shared_ptr<WebPageUI> m_webPageUI;
232     std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>>  m_webEngine;
233     std::shared_ptr<interfaces::AbstractFavoriteService> m_favoriteService;
234     std::shared_ptr<services::HistoryService> m_historyService;
235     std::shared_ptr<MoreMenuUI> m_moreMenuUI;
236     std::shared_ptr<BookmarkManagerUI> m_bookmarkManagerUI;
237     std::shared_ptr<MainUI> m_mainUI;
238     std::shared_ptr<HistoryUI> m_historyUI;
239     std::shared_ptr<SettingsUI> m_settingsUI;
240     std::shared_ptr<TabUI> m_tabUI;
241     std::shared_ptr<services::PlatformInputManager> m_platformInputManager;
242     std::shared_ptr<services::SessionStorage> m_sessionService;
243     Session::Session m_currentSession;
244     std::shared_ptr<tizen_browser::base_ui::ZoomUI> m_zoomUI;
245     std::shared_ptr<BookmarksManager> m_bookmarks_manager;
246     bool m_initialised;
247     int m_tabLimit;
248     int m_favoritesLimit;
249     bool m_wvIMEStatus;
250
251     //helper object used to view management
252     ViewManager* m_viewManager;
253
254     // This context object is used to implicitly init internal ewk data used by opengl to create the first and
255     // consecutive webviews in the application, otherwise we would encounter a crash after creating
256     // the first web view
257     Ewk_Context *m_ewkContext;
258 };
259
260 }
261 }
262
263 #endif /* SIMPLEUI_H_ */