Using UrlHistoryList do display history list (on urientry edition).
[profile/tv/apps/web/browser.git] / services / QuickAccess / UrlHistoryList / GenlistManager.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 GENLISTMANAGER_H_
18 #define GENLISTMANAGER_H_
19
20 #include <Elementary.h>
21 #include "services/HistoryService/HistoryItem.h"
22 #include <boost/signals2/signal.hpp>
23 #include "BrowserLogger.h"
24
25 using namespace std;
26
27 namespace tizen_browser {
28 namespace base_ui {
29
30 class GenlistManagerCallbacks;
31 class UrlMatchesStyler;
32 typedef shared_ptr<UrlMatchesStyler> UrlMatchesStylerPtr;
33
34 typedef struct UrlPair_s {
35     UrlPair_s(string a, string b) : urlOriginal(a), urlHighlighted(b) {}
36     string urlOriginal;
37     string urlHighlighted;
38 } UrlPair;
39
40 class GenlistManager
41 {
42     friend class GenlistManagerCallbacks;
43 public:
44     GenlistManager();
45     ~GenlistManager();
46
47     Evas_Object* createWidget(Evas_Object* parentLayout);
48     Evas_Object* getWidget();
49
50     void showWidget(const string& editedUrl,
51             shared_ptr<services::HistoryItemVector> matchedEntries);
52     void hideWidgetPretty();
53     void hideWidgetInstant();
54     bool isWidgetHidden();
55     void onMouseClick();
56
57     /**
58      * Add empty list elements to allow scroll in effect.
59      */
60     void addSpaces();
61     void removeSpaces();
62     void clearWidget();
63
64     boost::signals2::signal<void(string)> signalItemSelected;
65     boost::signals2::signal<void()> signalWidgetFocused;
66     boost::signals2::signal<void()> signalWidgetUnfocused;
67
68 private:
69     static Evas_Object* m_contentGet(void *data, Evas_Object *obj,
70             const char *part);
71     bool widgetExists()
72     {
73         return m_genlist != nullptr;
74     }
75     void prepareUrlsVector(const string& editedUrl,
76             shared_ptr<services::HistoryItemVector> matchedEntries);
77
78     void setLastEdgeTop(bool edgeTop);
79     bool getLastEdgeTop();
80     void onMouseFocusChange(bool mouseInsideWidget);
81
82     void startScrollIn();
83     void startScrollOut();
84
85     Evas_Object* m_parentLayout = nullptr;
86     Evas_Object* m_genlist = nullptr;
87     const bool genlistShowScrollbar = false;
88
89     // don't know how to get from edc:
90     const int HISTORY_ITEM_H = 82;
91     const int HISTORY_ITEMS_VISIBLE_MAX = 5;
92     // don't know how to calculate:
93     const int GENLIST_H = HISTORY_ITEM_H * HISTORY_ITEMS_VISIBLE_MAX;
94
95     /*
96      * Set to true, whenever hide request occurs. Set to false, whenever show
97      * request occurs. Needed to indicate when genlist should slide in.
98      */
99     bool widgetPreviouslyHidden = true;
100     /*
101      * If mouse click received and mouse is outside widget, hide it.
102      */
103     bool mouseInsideWidget = true;
104     /*
105      * needed to indicate direction of the scroll in 'anim,stop' callback
106      */
107     bool lastEdgeTop = true;
108
109     Elm_Gengrid_Item_Class* m_historyItemClass;
110     Elm_Gengrid_Item_Class* m_historyItemSpaceClass;
111     Elm_Object_Item* m_itemUrlFirst = nullptr;
112     Elm_Object_Item* m_itemUrlLast = nullptr;
113     Elm_Object_Item* m_itemSpaceFirst = nullptr;
114     Elm_Object_Item* m_itemSpaceLast = nullptr;
115
116     /*
117      * keeps shared pointers to strings, that are ready to be displayed, so they can be
118      * passed through EFL, until they're not needed. IMPORTANT: it has to be
119      * assured, that list is not cleared until all EFL items has created their
120      * labels from these pointers in m_contentGet(). in case of segfaults, delete copy of pointers
121      * manually in m_contentGet().
122      */
123     vector<shared_ptr<string>> m_readyUrls;
124     vector<shared_ptr<UrlPair>> m_readyUrlPairs;
125     UrlMatchesStylerPtr m_urlMatchesStyler;
126
127 };
128
129 } /* namespace base_ui */
130 } /* namespace tizen_browser */
131
132 #endif /* GENLISTMANAGER_H_ */