Removed dead code from SimpleUI
[profile/tv/apps/web/browser.git] / services / SimpleUI / ViewManager.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 /*
18  * ViewManager.cpp
19  *
20  *  Created on: Sep 11, 2015
21  *      Author: m.lapinski@samsung.com
22  */
23
24 #include <Elementary.h>
25 #include <Ecore.h>
26 #include <Ecore_Wayland.h>
27 #include <string>
28
29 #include "ViewManager.h"
30 #include "core/BrowserLogger.h"
31 #include "core/ServiceManager/Debug/BrowserAssert.h"
32
33 namespace tizen_browser{
34 namespace base_ui{
35
36 ViewManager::ViewManager(Evas_Object* parentWindow)
37    : m_mainLayout(nullptr)
38    , m_parentWindow(parentWindow)
39 {
40     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
41     M_ASSERT(parentWindow);
42     m_mainLayout = elm_layout_add(parentWindow);
43     evas_object_size_hint_weight_set(m_mainLayout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
44     evas_object_size_hint_align_set (m_mainLayout, EVAS_HINT_FILL, EVAS_HINT_FILL);
45
46     Eina_Bool ret = elm_layout_file_set(m_mainLayout,
47                                         (std::string(EDJE_DIR)
48                                         + std::string("SimpleUI/ViewManager.edj")).c_str(),
49                                         "main_layout");
50     if (!ret)
51         BROWSER_LOGD("[%s:%d]  elm_layout_file_set falied !!!",__PRETTY_FUNCTION__, __LINE__);
52
53     elm_win_resize_object_add(parentWindow, m_mainLayout);
54     evas_object_show(m_mainLayout);
55 }
56
57 void ViewManager::popStackTo(interfaces::AbstractUIComponent* view)
58 {
59     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
60     M_ASSERT(view);
61     interfaces::AbstractUIComponent* previousView = m_viewStack.top();
62
63     while(!m_viewStack.empty() && m_viewStack.top() != view)
64     {
65         m_viewStack.pop();
66     }
67     updateLayout(previousView);
68     BROWSER_LOGD("[%s:%d] new top: %p", __PRETTY_FUNCTION__, __LINE__, topOfStack());
69 }
70
71 void ViewManager::popTheStack()
72 {
73     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
74     if(!m_viewStack.empty())
75     {
76         interfaces::AbstractUIComponent* previousView = m_viewStack.top();
77         m_viewStack.pop();
78         updateLayout(previousView);
79     }
80     BROWSER_LOGD("[%s:%d] new top: %p", __PRETTY_FUNCTION__, __LINE__, topOfStack());
81 }
82
83 void ViewManager::pushViewToStack(interfaces::AbstractUIComponent* view)
84 {
85     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
86
87     M_ASSERT(view);
88     if (topOfStack() == view)
89     {
90        BROWSER_LOGD("[%s:%d] View %p is already on stack !!!",
91                           __PRETTY_FUNCTION__, __LINE__, view);
92        return;
93     }
94     interfaces::AbstractUIComponent* previousView = topOfStack();
95     m_viewStack.push(view);
96     updateLayout(previousView);
97     BROWSER_LOGD("[%s:%d] new top: %p", __PRETTY_FUNCTION__, __LINE__, topOfStack());
98 }
99
100
101 void ViewManager::updateLayout(interfaces::AbstractUIComponent* previousView)
102 {
103     BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
104     Evas_Object* swallowed = elm_layout_content_get(m_mainLayout, "content");
105     if (!m_viewStack.empty())
106     {
107         if (m_viewStack.top()->getContent() == swallowed)
108         {
109             BROWSER_LOGD("[%s:%d] Top of stack is already visible!!!",
110                          __PRETTY_FUNCTION__, __LINE__);
111             return;
112         }
113         if(previousView)
114             previousView->hideUI();
115         elm_layout_content_unset(m_mainLayout, "content");
116         elm_layout_content_set(m_mainLayout, "content", m_viewStack.top()->getContent());
117
118         m_viewStack.top()->showUI();
119     }
120     else
121     {
122         BROWSER_LOGD("[%s:%d] Stack is empty!!!",__PRETTY_FUNCTION__, __LINE__);
123         if(previousView)
124              previousView->hideUI();
125
126         elm_layout_content_unset(m_mainLayout, "content");
127         elm_layout_content_set(m_mainLayout, "content", nullptr);
128     }
129 }
130
131 Evas_Object* ViewManager::getContent()
132 {
133     M_ASSERT(m_mainLayout);
134     return m_mainLayout;
135 }
136
137
138 interfaces::AbstractUIComponent* ViewManager::topOfStack()
139 {
140     if(!m_viewStack.empty())
141         return m_viewStack.top();
142     else
143         return nullptr;
144 }
145
146 }//namespace base_ui
147 }//names1pace tizen_browser