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