summaryrefslogtreecommitdiff
path: root/services/SimpleUI/SimpleUI.h
blob: 276832a76a53d5771826e4798ea7ebbf225ac361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/*
 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * SimpleUI.h
 *
 *  Created on: Mar 18, 2014
 *      Author: k.szalilow
 */

#ifndef SIMPLEUI_H_
#define SIMPLEUI_H_

#include <Evas.h>

#include "AbstractMainWindow.h"
#include "AbstractService.h"
#include "AbstractFavoriteService.h"
#include "ServiceFactory.h"
#include "service_macros.h"

// components
#include "WebPageUI.h"
#include "AbstractWebEngine.h"
#include "TabOrigin.h"
#include "MoreMenuUI.h"
#include "HistoryUI.h"
#if PROFILE_MOBILE
#include "FindOnPageUI.h"
#include "SettingsUI_mob.h"
#include "TextPopup_mob.h"
#else
#include "SettingsUI.h"
#include "ZoomUI.h"
#endif
#include "QuickAccess.h"
#include "TabUI.h"
#include "TabId.h"
#include "HistoryService.h"
#include "TabServiceTypedef.h"
#include "BookmarkDetailsUI.h"
#include "BookmarkFlowUI.h"
#include "BookmarkManagerUI.h"
#include "PlatformInputManager.h"
#include "StorageService.h"
#include "CertificateContents.h"

// other
#include "Action.h"
#include "InputPopup.h"
#include "SimplePopup.h"
#include "ContentPopup_mob.h"
#include "WebConfirmation.h"
#include "ViewManager.h"
#include "MenuButton.h"

namespace tizen_browser{
namespace base_ui{

template <>
void AbstractMainWindow<Evas_Object>::setMainWindow(Evas_Object * rawPtr)
{
    m_window = std::shared_ptr<Evas_Object>(rawPtr, evas_object_del);
}

class BROWSER_EXPORT SimpleUI : public AbstractMainWindow<Evas_Object>
{
public:
    SimpleUI(/*Evas_Object *window*/);
    virtual ~SimpleUI();
    virtual int exec(const std::string& _url, const std::string& _caller);
    virtual std::string getName();
    void suspend();
    void resume();

    void destroyUI();
private:
    // setup functions
    void loadUIServices();
    void connectUISignals();
    void loadModelServices();
    void initModelServices();
    void initUIServices();
    void connectModelSignals();
    void pushViewToStack(interfaces::AbstractUIComponent* view);
    void popTheStack();
    void popStackTo(interfaces::AbstractUIComponent* view);
    void titleChanged(const std::string& title);
    void faviconChanged(tools::BrowserImagePtr favicon);
    void restoreLastSession();
    Evas_Object* createWebLayout(Evas_Object* parent);
    Evas_Object* createErrorLayout(Evas_Object* parent);

    void forwardEnable(bool enable);
    void stopEnable(bool enable);
    void reloadEnable(bool enable);

    void downloadStarted(int status);
    void loadFinished();
    void progressChanged(double progress);
    void loadStarted();
    void loadError();

    void setErrorButtons();

    void bookmarkAdded();
    void bookmarkDeleted();

    void showQuickAccess();
    void switchViewToQuickAccess();
    void switchViewToIncognitoPage();
    void switchViewToWebPage();
    void updateView();
    void windowCreated();
    void minimizeBrowser();

#if PROFILE_MOBILE
    void openNewTab(const std::string &uri, const std::string& title =
            std::string(), const boost::optional<int> adaptorId = boost::none,
            bool desktopMode = false, bool incognitoMode = false,
            basic_webengine::TabOrigin origin = basic_webengine::TabOrigin::UNKNOWN);
#else
    void openNewTab(const std::string &uri, const std::string& title =
            std::string(), const boost::optional<int> adaptorId = boost::none,
            bool desktopMode = true, bool incognitoMode = false,
            basic_webengine::TabOrigin origin = basic_webengine::TabOrigin::UNKNOWN);
#endif

    void switchToTab(const tizen_browser::basic_webengine::TabId& tabId);
    void newTabClicked();
    void tabClicked(const tizen_browser::basic_webengine::TabId& tabId);
    void closeTabsClicked(const tizen_browser::basic_webengine::TabId& tabId);
    bool isIncognito(const tizen_browser::basic_webengine::TabId& tabId);
    void tabCreated();
    bool checkIfCreate();
    void tabClosed(const tizen_browser::basic_webengine::TabId& id);

    std::shared_ptr<services::HistoryItemVector> getHistory();
    std::shared_ptr<services::HistoryItemVector> getMostVisitedItems();

    //UI signal handling functions
    void onBookmarkAdded(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);

    void onBookmarkClicked(std::shared_ptr<tizen_browser::services::BookmarkItem> bookmarkItem);
    void onNewFolderClicked();
    void onNewFolderPopupClick(const std::string& folder_name);
#if PROFILE_MOBILE
    void onEditFolderClicked(const std::string& folder_name);
    void onDeleteFolderClicked(const std::string& folder_name);
    void onRemoveFoldersClicked(std::vector<std::shared_ptr<tizen_browser::services::BookmarkItem>> items);
    void onEditFolderPopupClicked(const std::string& newName);
    void onDeleteFolderPopupClicked(PopupButtons button);
    static void onUrlIMEOpened(void* data, Evas_Object*, void*);
    static void onUrlIMEClosed(void* data, Evas_Object*, void*);
#endif
    void onBookmarkRemoved(const std::string& uri);

    void onHistoryRemoved(const std::string& uri);
    void onOpenURL(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, bool desktopMode);
    /**
     * @brief Handles 'openUrlInNewTab' signals. Uses QuickAccess to indicate
     * desktop/mobile mode.
     * TODO: desktop mode should be checked in WebView or QuickAcces (depends
     * on which view is active)
     */
    void onOpenURL(const std::string& url);
    void onOpenURL(const std::string& url, const std::string& title, bool desktopMode);
    void onMostVisitedTileClicked(std::shared_ptr<tizen_browser::services::HistoryItem> historyItem, int itemsNumber);
    void onClearHistoryAllClicked();
    void onDeleteHistoryItems(std::shared_ptr<const std::vector<int>> itemIds);

    void onMostVisitedClicked();
    void onBookmarkButtonClicked();

    /**
     * @brief Handles 'generateThumb' signals.
     */
    void onGenerateThumb(basic_webengine::TabId tabId);
    void onSnapshotCaptured(std::shared_ptr<tools::BrowserImage> snapshot, tools::SnapshotType snapshot_type);
    void onCreateTabId();

    void authPopupButtonClicked(PopupButtons button, std::shared_ptr<PopupData> popupData);
    void certPopupButtonClicked(PopupButtons button, std::shared_ptr<PopupData> popupData);

    void onActionTriggered(const Action& action);
#if PROFILE_MOBILE
    void onMenuButtonPressed();
    void handleConfirmationRequest(basic_webengine::WebConfirmationPtr webConfirmation);

    /**
     * \brief check if url comming back from WebEngine should be passed to URI.
     *
     * For filtered addresses we need to hide real URI so the user would be confused.
     * and this is a back function that checks if address emited from browser should be changed.
     */
    void webEngineURLChanged(const std::string url);
#else
    void onRedKeyPressed();
    void onYellowKeyPressed();
#endif
    void setwvIMEStatus(bool status);

    sharedAction m_showBookmarkManagerUI;

    /**
     * \brief filters URL before it is passed to WebEngine.
     *
     * This function should be connected with m_simpleURI->uriChanged.
     * it is a good place to check for special urls (like "about:home"),
     * filter forbidden addresses and to check set favorite icon.
     */
    void filterURL(const std::string& url);

    // // on uri entry widget "changed,user" signal
    void onURLEntryEditedByUser(const std::shared_ptr<std::string> editedUrlPtr);
    // on uri entry widget "changed" signal
    void onURLEntryEdited();

    void onmostHistoryvisitedClicked();
    void onBookmarkvisitedClicked();

    /**
     * @brief Check if the current page exists as a bookmark.
     *
     */
    bool checkBookmark();

    /**
     * @brief Adds current page to bookmarks.
     *
     */
    void addBookmark(BookmarkUpdate bookmark_update);

    /**
     * @brief Edits currents page bookmark
     *
     */
    void editBookmark(BookmarkUpdate bookmark_update);

    /**
     * @brief Remove current page from bookmarks
     *
     * @param  ...
     * @return void
     */
    void deleteBookmark(void);

#if !PROFILE_MOBILE
    /**
     * @brief show Zoom Menu
     */
    void showZoomUI();
    void closeZoomUI();
    void setZoomFactor(int level);
    int getZoomFactor();
#endif
    void scrollView(const int& dx, const int& dy);

    void showTabUI();
    void closeTabUI();
    void showMoreMenu();
    void closeMoreMenu();
    void switchToMobileMode();
    void switchToDesktopMode();
    void showHistoryUI();
    void closeHistoryUI();
    void showSettingsUI();
    void closeSettingsUI();

    void showBookmarkFlowUI(bool state);
#if PROFILE_MOBILE
    void showCertificatePopup();
    void showCertificatePopup(const std::string& host, const std::string& pem, services::CertificateContents::HOST_TYPE type);
    void showUnsecureConnectionPopup();
    void closeBookmarkFlowUI();

    void showFindOnPageUI(const std::string& str);
    void findWord(const struct FindData& fdata);
    void closeFindOnPageUI();

    void registerHWKeyCallback();
    void unregisterHWKeyCallback();

    bool isManualRotation(interfaces::AbstractUIComponent* view);
    void enableManualRotation(bool enable);
    void rotatePrepared();
    void onRotation();
    bool isLandscape();
    int getRotation();
    static void __orientation_changed(void* data, Evas_Object*, void*);
#endif
    void closeBookmarkDetailsUI();
    void closeBookmarkManagerUI();
    void showBookmarkManagerUI();
    void redirectedWebPage(const std::string& oldUrl, const std::string& newUrl);
    void onBookmarkCustomFolderClicked(int);
    void onBookmarkAllFolderClicked();
    void onBookmarkSpecialFolderClicked();

    void showPopup(interfaces::AbstractPopup* popup);
    void dismissPopup(interfaces::AbstractPopup* popup);

    void closeTab();
    void closeTab(const tizen_browser::basic_webengine::TabId& id);

    void settingsDeleteSelectedData(const std::string& str);
    void settingsResetMostVisited();
    void settingsResetBrowser();
    void onDeleteSelectedDataButton(const PopupButtons& button, const std::string &dataText);
    void onDeleteMostVisitedButton(std::shared_ptr<PopupData> popupData);
    void onResetBrowserButton(PopupButtons button, std::shared_ptr<PopupData> popupData);
#if PROFILE_MOBILE
    void settingsOverrideUseragent(const std::string& userAgent);
    void onOverrideUseragentButton(const std::string& str);
    void tabLimitPopupButtonClicked(PopupButtons button);
#else
    void tabLimitPopupButtonClicked(PopupButtons button, std::shared_ptr< PopupData > /*popupData*/);
    void onEscapePressed();
#endif
    int tabsCount();

    void onReturnPressed(MenuButton *m);
    void onXF86BackPressed();
    void onBackPressed();

    void searchWebPage(std::string &text, int flags);

    std::string edjePath(const std::string &);

    std::vector<interfaces::AbstractPopup*> m_popupVector;

    std::shared_ptr<WebPageUI> m_webPageUI;
    std::shared_ptr<basic_webengine::AbstractWebEngine<Evas_Object>>  m_webEngine;
    std::shared_ptr<interfaces::AbstractFavoriteService> m_favoriteService;
    std::shared_ptr<services::HistoryService> m_historyService;
    services::TabServicePtr m_tabService;
    std::shared_ptr<MoreMenuUI> m_moreMenuUI;
    std::shared_ptr<BookmarkDetailsUI> m_bookmarkDetailsUI;
#if PROFILE_MOBILE
    std::shared_ptr<BookmarkFlowUI> m_bookmarkFlowUI;
    std::shared_ptr<FindOnPageUI> m_findOnPageUI;
#else
    std::shared_ptr<tizen_browser::base_ui::ZoomUI> m_zoomUI;
#endif
    std::shared_ptr<services::CertificateContents> m_certificateContents;
    std::shared_ptr<BookmarkManagerUI> m_bookmarkManagerUI;
    std::shared_ptr<QuickAccess> m_quickAccess;
    std::shared_ptr<HistoryUI> m_historyUI;
    std::shared_ptr<SettingsUI> m_settingsUI;
    std::shared_ptr<TabUI> m_tabUI;
    std::shared_ptr<services::PlatformInputManager> m_platformInputManager;
    std::shared_ptr<services::StorageService> m_storageService;
    bool m_initialised;
    std::string m_caller;
    int m_tabLimit;
    int m_favoritesLimit;
    bool m_wvIMEStatus;
    std::string m_folder_name;

    //helper object used to view management
    ViewManager m_viewManager;
    Evas_Object *main_window;
#if PROFILE_MOBILE
    Evas_Object *m_conformant;
    bool m_manualRotation;
    int m_current_angle;
    int m_temp_angle;
#endif
};

}
}

#endif /* SIMPLEUI_H_ */