Exiting from Screen zoom by pressing "Escape" or "Backspace" key.
[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     void suspend() {m_webEngine->suspend();}
75     void resume() {m_webEngine->resume();}
76
77     void destroyUI();
78 private:
79     // setup functions
80     void createActions();
81     void connectActions();
82     void loadUIServices();
83     void connectUISignals();
84     void loadModelServices();
85     void initModelServices();
86     void initUIServices();
87     void connectModelSignals();
88     void restoreLastSession();
89     Evas_Object* createWebLayout(Evas_Object* parent);
90     Evas_Object* createErrorLayout(Evas_Object* parent);
91
92     void forwardEnable(bool enable);
93     void stopEnable(bool enable);
94     void reloadEnable(bool enable);
95
96     void loadFinished();
97     void progressChanged(double progress);
98     void loadStarted();
99
100     void loadError();
101     void setErrorButtons();
102     bool isErrorPageActive();
103
104     void bookmarkAdded();
105     void bookmarkDeleted();
106
107     void showQuickAccess();
108     void switchViewToQuickAccess();
109     void switchViewToIncognitoPage();
110     void switchViewToWebPage();
111     void updateView();
112
113     void openNewTab(const std::string &uri, bool desktopMode = true);
114     void switchToTab(const tizen_browser::basic_webengine::TabId& tabId);
115     void newTabClicked();
116     void tabClicked(const tizen_browser::basic_webengine::TabId& tabId);
117     void closeTabsClicked(const tizen_browser::basic_webengine::TabId& tabId);
118     void tabCreated();
119     bool checkIfCreate();
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 onHistoryRemoved(const std::string& uri);
133     void onOpenURLInNewTab(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, bool desktopMode);
134     void onMostVisitedTileClicked(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, int itemsNumber);
135     void onClearHistoryClicked();
136
137     void onMostVisitedClicked();
138     void onBookmarkButtonClicked();
139
140     void handleConfirmationRequest(basic_webengine::WebConfirmationPtr webConfirmation);
141     void authPopupButtonClicked(PopupButtons button, std::shared_ptr<PopupData> popupData);
142
143     void onActionTriggered(const Action& action);
144     void onMouseClick();
145     void setwvIMEStatus(bool status);
146
147     sharedAction m_showBookmarkManagerUI;
148     sharedAction m_settingPrivateBrowsing;
149
150     /**
151      * \brief filters URL before it is passed to WebEngine.
152      *
153      * This function should be connected with m_simpleURI->uriChanged.
154      * it is a good place to check for special urls (like "about:home"),
155      * filter forbidden addresses and to check set favorite icon.
156      */
157     void filterURL(const std::string& url);
158
159     // // on uri entry widget "changed,user" signal
160     void onURLEntryEditedByUser(const std::shared_ptr<std::string> editedUrlPtr);
161     // on uri entry widget "changed" signal
162     void onURLEntryEdited();
163
164     /**
165      * \brief check if url comming back from WebEngine should be passed to URI.
166      *
167      * For filtered addresses we need to hide real URI so the user would be confused.
168      * and this is a back function that checks if address emited from browser should be changed.
169      */
170     void webEngineURLChanged(const std::string url);
171     void onmostHistoryvisitedClicked();
172     void onBookmarkvisitedClicked();
173     /**
174      * @brief Check if the current page exists as a bookmark.
175      *
176      */
177     bool checkBookmark();
178     /**
179      * @brief Adds current page to bookmarks.
180      *
181      */
182     void addToBookmarks(int);
183     /**
184      * @brief Remove current page from bookmarks
185      *
186      * @param  ...
187      * @return void
188      */
189     void deleteBookmark(void);
190
191     /**
192      * @brief show Zoom Menu
193      */
194     void showZoomUI();
195     void closeZoomUI();
196     void setZoomFactor(int level);
197     int getZoomFactor();
198     void scrollView(const int& dx, const int& dy);
199
200     void showTabUI();
201     void closeTabUI();
202     void showMoreMenu();
203     void closeMoreMenu();
204     void switchToMobileMode();
205     void switchToDesktopMode();
206     void showHistoryUI();
207     void closeHistoryUI();
208     void showSettingsUI();
209     void closeSettingsUI();
210     void closeBookmarkManagerUI();
211     void showBookmarkManagerUI();
212     void showPopup(Evas_Object *content, char* btn1_text, char* btn2_text);
213
214     void closeTab();
215     void closeTab(const tizen_browser::basic_webengine::TabId& id);
216
217     void settingsPrivateModeSwitch(bool newState);
218     void applyPrivateModeToTab(const tizen_browser::basic_webengine::TabId& id);
219     void settingsDeleteSelectedData(const std::string& str);
220     void settingsResetMostVisited();
221     void settingsResetBrowser();
222     void onDeleteSelectedDataButton(const std::string &dataText);
223     void onDeleteMostVisitedButton(std::shared_ptr<PopupData> popupData);
224     void onResetBrowserButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
225     void tabLimitPopupButtonClicked(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/);
226     int tabsCount();
227
228     void onReturnPressed(MenuButton *m);
229     void onBackPressed();
230     void onEscapePressed();
231
232     void searchWebPage(std::string &text, int flags);
233
234     std::string edjePath(const std::string &);
235
236     Evas_Object *m_popup;
237
238     std::shared_ptr<WebPageUI> m_webPageUI;
239     std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>>  m_webEngine;
240     std::shared_ptr<interfaces::AbstractFavoriteService> m_favoriteService;
241     std::shared_ptr<services::HistoryService> m_historyService;
242     std::shared_ptr<MoreMenuUI> m_moreMenuUI;
243     std::shared_ptr<BookmarkManagerUI> m_bookmarkManagerUI;
244     std::shared_ptr<QuickAccess> m_quickAccess;
245     std::shared_ptr<HistoryUI> m_historyUI;
246     std::shared_ptr<SettingsUI> m_settingsUI;
247     std::shared_ptr<TabUI> m_tabUI;
248     std::shared_ptr<services::PlatformInputManager> m_platformInputManager;
249     std::shared_ptr<services::SessionStorage> m_sessionService;
250     Session::Session m_currentSession;
251     std::shared_ptr<tizen_browser::base_ui::ZoomUI> m_zoomUI;
252     std::shared_ptr<BookmarksManager> m_bookmarks_manager;
253     bool m_initialised;
254     int m_tabLimit;
255     int m_favoritesLimit;
256     bool m_wvIMEStatus;
257     bool m_incognito;
258
259     //helper object used to view management
260     ViewManager* m_viewManager;
261
262     // This context object is used to implicitly init internal ewk data used by opengl to create the first and
263     // consecutive webviews in the application, otherwise we would encounter a crash after creating
264     // the first web view
265     Ewk_Context *m_ewkContext;
266 };
267
268 }
269 }
270
271 #endif /* SIMPLEUI_H_ */