Using UrlHistoryList do display history list (on urientry edition).
[profile/tv/apps/web/browser.git] / services / QuickAccess / UrlHistoryList / UrlHistoryList.cpp
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 #include <Elementary.h>
18 #include "UrlHistoryList.h"
19 #include "GenlistManager.h"
20 #include "BrowserLogger.h"
21 #include "../QuickAccess.h"
22
23 namespace tizen_browser {
24 namespace base_ui {
25
26 UrlHistoryList::UrlHistoryList(QuickAccess* quickAccess) :
27         m_layout(nullptr), m_quickAccess(quickAccess)
28 {
29     m_edjFilePath = EDJE_DIR;
30     m_edjFilePath.append("QuickAccess/UrlHistoryList.edj");
31     m_genlistListManager = make_shared<GenlistManager>();
32     m_genlistListManager->signalItemSelected.connect(
33             boost::bind(&UrlHistoryList::onListItemSelect, this, _1));
34     m_genlistListManager->signalWidgetFocused.connect(
35             boost::bind(&UrlHistoryList::onListWidgetFocused, this));
36     m_genlistListManager->signalWidgetUnfocused.connect(
37             boost::bind(&UrlHistoryList::onListWidgetUnfocused, this));
38 }
39
40 UrlHistoryList::~UrlHistoryList()
41 {
42 }
43
44 Evas_Object* UrlHistoryList::getLayout()
45 {
46     return m_layout;
47 }
48
49 void UrlHistoryList::createLayout(Evas_Object* parentLayout)
50 {
51     m_layout = elm_layout_add(parentLayout);
52     elm_layout_file_set(m_layout, m_edjFilePath.c_str(), "url_history_list");
53
54     Evas_Object* widgetList = m_genlistListManager->createWidget(m_layout);
55 }
56
57 void UrlHistoryList::onURLEntryEditedByUser(const string& editedUrl,
58         shared_ptr<services::HistoryItemVector> matchedEntries)
59 {
60     editedUrlStatesHelper.changeState(true);
61
62     if (matchedEntries->size() == 0) {
63         m_genlistListManager->hideWidgetPretty();
64     } else {
65         Evas_Object* widgetList = m_genlistListManager->getWidget();
66         elm_object_part_content_set(m_layout, "list_swallow", widgetList);
67         m_genlistListManager->showWidget(editedUrl, matchedEntries);
68         evas_object_show(widgetList);
69     }
70 }
71
72 void UrlHistoryList::onURLEntryEdited()
73 {
74     editedUrlStatesHelper.changeState(false);
75     if (editedUrlStatesHelper.getCurrentState()
76             == EditedUrlState::EDITED_OTHER_FIRST) {
77         m_genlistListManager->hideWidgetPretty();
78     } else {
79         // in this situation scroll will not work, it has to be hidden instantly
80         m_genlistListManager->hideWidgetInstant();
81     }
82 }
83
84 void UrlHistoryList::onMouseClick()
85 {
86     m_genlistListManager->onMouseClick();
87 }
88
89 void UrlHistoryList::onListItemSelect(std::string content)
90 {
91     openURLInNewTab(make_shared < services::HistoryItem > (content),
92             m_quickAccess->isDesktopMode());
93 }
94
95 void UrlHistoryList::onListWidgetFocused()
96 {
97     // will be used soon: in a proper focus-chain solution
98 }
99
100 void UrlHistoryList::onListWidgetUnfocused()
101 {
102     // will be used soon: in a proper focus-chain solution
103 }
104
105 }/* namespace base_ui */
106 } /* namespace tizen_browser */