2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 * Created on: Sep 11, 2015
21 * Author: m.lapinski@samsung.com
24 #include <Elementary.h>
26 #include <Ecore_Wayland.h>
29 #include "ViewManager.h"
30 #include "core/BrowserLogger.h"
31 #include "core/ServiceManager/Debug/BrowserAssert.h"
33 namespace tizen_browser{
36 ViewManager::ViewManager(Evas_Object* parentWindow)
37 : m_mainLayout(nullptr)
38 , m_parentWindow(parentWindow)
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);
46 Eina_Bool ret = elm_layout_file_set(m_mainLayout,
47 (std::string(EDJE_DIR)
48 + std::string("SimpleUI/ViewManager.edj")).c_str(),
51 BROWSER_LOGD("[%s:%d] elm_layout_file_set falied !!!",__PRETTY_FUNCTION__, __LINE__);
53 elm_win_resize_object_add(parentWindow, m_mainLayout);
54 evas_object_show(m_mainLayout);
57 void ViewManager::popStackTo(interfaces::AbstractUIComponent* view)
59 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
61 interfaces::AbstractUIComponent* previousView = m_viewStack.top();
63 while(!m_viewStack.empty() && m_viewStack.top() != view)
67 updateLayout(previousView);
68 BROWSER_LOGD("[%s:%d] new top: %p", __PRETTY_FUNCTION__, __LINE__, topOfStack());
71 void ViewManager::popTheStack()
73 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
74 if(!m_viewStack.empty())
76 interfaces::AbstractUIComponent* previousView = m_viewStack.top();
78 updateLayout(previousView);
80 BROWSER_LOGD("[%s:%d] new top: %p", __PRETTY_FUNCTION__, __LINE__, topOfStack());
83 void ViewManager::pushViewToStack(interfaces::AbstractUIComponent* view)
85 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
88 if (topOfStack() == view)
90 BROWSER_LOGD("[%s:%d] View %p is already on stack !!!",
91 __PRETTY_FUNCTION__, __LINE__, view);
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());
101 void ViewManager::updateLayout(interfaces::AbstractUIComponent* previousView)
103 BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
104 Evas_Object* swallowed = elm_layout_content_get(m_mainLayout, "content");
105 if (!m_viewStack.empty())
107 if (m_viewStack.top()->getContent() == swallowed)
109 BROWSER_LOGD("[%s:%d] Top of stack is already visible!!!",
110 __PRETTY_FUNCTION__, __LINE__);
114 previousView->hideUI();
115 elm_layout_content_unset(m_mainLayout, "content");
116 elm_layout_content_set(m_mainLayout, "content", m_viewStack.top()->getContent());
118 m_viewStack.top()->showUI();
122 BROWSER_LOGD("[%s:%d] Stack is empty!!!",__PRETTY_FUNCTION__, __LINE__);
124 previousView->hideUI();
126 elm_layout_content_unset(m_mainLayout, "content");
127 elm_layout_content_set(m_mainLayout, "content", nullptr);
131 Evas_Object* ViewManager::getContent()
133 M_ASSERT(m_mainLayout);
138 interfaces::AbstractUIComponent* ViewManager::topOfStack()
140 if(!m_viewStack.empty())
141 return m_viewStack.top();
147 }//names1pace tizen_browser