Using UrlHistoryList do display history list (on urientry edition).
[profile/tv/apps/web/browser.git] / services / QuickAccess / UrlHistoryList / UrlHistoryList.h
1 /*
2  * Copyright (c) 2015 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 #ifndef URLHISTORYLIST_H_
18 #define URLHISTORYLIST_H_
19
20 #include <memory>
21 #include <Evas.h>
22
23 #include "services/HistoryService/HistoryItem.h"
24 #include <boost/signals2/signal.hpp>
25
26 using namespace std;
27
28 namespace tizen_browser {
29 namespace base_ui {
30
31 class QuickAccess;
32 class GenlistManager;
33 typedef shared_ptr<GenlistManager> GenlistManagerPtr;
34
35 enum class EditedUrlState
36 {
37     // url was edited by a user (by typing)
38     EDITED_BY_USER,
39     // url was edited in other way than typing (but for the first time after previous user edition)
40     EDITED_OTHER_FIRST,
41     // url was edited in other way than typing (and previously was not edited by the user)
42     EDITED_OTHER_MANY_TIMES
43 };
44
45 /**
46  * Needed to indicate who did the last url entry edition (user/other/other many times). Used
47  * to indicate when widget can be hidden in a pretty way or an instant way.
48  */
49 class EditedUrlStatesHelper
50 {
51 public:
52     EditedUrlStatesHelper()
53     {
54     }
55     void changeState(bool editedByUser)
56     {
57         if (editedByUser) {
58             currentState = EditedUrlState::EDITED_BY_USER;
59         } else {
60             if (currentState == EditedUrlState::EDITED_BY_USER) {
61                 currentState = EditedUrlState::EDITED_OTHER_FIRST;
62             } else {
63                 currentState = EditedUrlState::EDITED_OTHER_MANY_TIMES;
64             }
65         }
66     }
67     EditedUrlState getCurrentState()
68     {
69         return currentState;
70     }
71 private:
72     EditedUrlState currentState = EditedUrlState::EDITED_BY_USER;
73 };
74
75 /**
76  * Manages list of url matches (URL from history). Manages top layout, creates
77  * widget displaying url items.
78  */
79 class UrlHistoryList
80 {
81 public:
82     UrlHistoryList(QuickAccess* quickAccess);
83     virtual ~UrlHistoryList();
84     void createLayout(Evas_Object* parentLayout);
85     Evas_Object* getLayout();
86
87     // // on uri entry widget "changed,user" signal
88     void onURLEntryEditedByUser(const string& editedUrl,
89             shared_ptr<services::HistoryItemVector> matchedEntries);
90     // on uri entry widget "changed" signal
91     void onURLEntryEdited();
92
93     void onMouseClick();
94
95     boost::signals2::signal<void(shared_ptr<services::HistoryItem>, bool)> openURLInNewTab;
96
97     int getVisibleItemsMax() const
98     {
99         return VISIBLE_ITEMS_MAX;
100     }
101
102     int getMinKeywordLength() const
103     {
104         return MIN_KEYWORD_LENGTH;
105     }
106
107 private:
108     void onListItemSelect(std::string content);
109     void onListWidgetFocused();
110     void onListWidgetUnfocused();
111
112     EditedUrlStatesHelper editedUrlStatesHelper;
113
114     // the maximum items number on a list
115     const int VISIBLE_ITEMS_MAX = 12;
116     // the minimum length of the keyword used to search matches
117     const int MIN_KEYWORD_LENGTH = 3;
118     Evas_Object* m_layout;
119     string m_edjFilePath;
120
121     GenlistManagerPtr m_genlistListManager = nullptr;
122     QuickAccess* m_quickAccess;
123
124 };
125
126 } /* namespace base_ui */
127 } /* namespace tizen_browser */
128
129 #endif /* URLHISTORYLIST_H_ */