ViewManager class added. 55/48055/7
authorMarcin Lapinski <m.lapinski@samsung.com>
Fri, 11 Sep 2015 13:37:24 +0000 (15:37 +0200)
committerMarcin Lapinski <m.lapinski@samsung.com>
Wed, 16 Sep 2015 10:36:10 +0000 (12:36 +0200)
[Issue#:]   https://bugs.tizen.org/jira/browse/TT-157
[Problem:]  New window management class is needed.
[Cause:]    N/A
[Solution:] Implemented new class with following public methods:
            popStackTo
            popTheStack
            pushViewToStack
            getContent

[Verify:]   Class is not used. Changes builds and doesn't crash.

Merge this after merging this patch:
https://review.tizen.org/gerrit/#/c/48052/

Change-Id: I4b8ca2866fa1cecbf858b4aed41e42112620a9f7

services/SimpleUI/CMakeLists.txt
services/SimpleUI/ViewManager.cpp [new file with mode: 0644]
services/SimpleUI/ViewManager.h [new file with mode: 0644]

index af5a134e1489cb787b7a3868ed24e110b8191ebb..4c77390b64c3bd76cef6781eab0e18d398225ecf 100644 (file)
@@ -5,6 +5,7 @@ set(SimpleUI_SRCS
     ButtonBar.cpp
     SimplePopup.cpp
     BookmarksManager.cpp
+    ViewManager.cpp
     )
 
 set(SimpleUI_HEADERS
@@ -12,6 +13,7 @@ set(SimpleUI_HEADERS
     ButtonBar.h
     SimplePopup.h
     BookmarksManager.h
+    ViewManager.h
     )
 
 include(Coreheaders)
diff --git a/services/SimpleUI/ViewManager.cpp b/services/SimpleUI/ViewManager.cpp
new file mode 100644 (file)
index 0000000..eab2bbc
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyrm_previousTopight (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * ViewManager.cpp
+ *
+ *  Created on: Sep 11, 2015
+ *      Author: m.lapinski@samsung.com
+ */
+
+#include <Elementary.h>
+
+#include "ViewManager.h"
+#include "core/BrowserLogger.h"
+#include "core/ServiceManager/Debug/BrowserAssert.h"
+
+namespace tizen_browser{
+namespace base_ui{
+
+ViewManager::ViewManager(Evas_Object* parentWindow)
+   :m_mainLayout(nullptr)
+   ,m_previousTop(nullptr)
+{
+    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    M_ASSERT(parentWindow);
+    m_mainLayout = elm_layout_add(parentWindow);
+    evas_object_size_hint_weight_set(m_mainLayout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+    evas_object_size_hint_align_set (m_mainLayout, EVAS_HINT_FILL, EVAS_HINT_FILL);
+    if(!elm_object_style_set (m_mainLayout,"content-back"))
+        BROWSER_LOGD("[%s:%d]  elm_object_style_set falied.",__PRETTY_FUNCTION__, __LINE__);
+    elm_win_resize_object_add(parentWindow, m_mainLayout);
+    evas_object_show(m_mainLayout);
+}
+
+void ViewManager::popStackTo(interfaces::AbstractUIComponent* view)
+{
+    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    M_ASSERT(view);
+
+    if(!m_viewStack.empty())
+        m_previousTop = m_viewStack.top();
+
+    while(!m_viewStack.empty())
+    {
+        if (m_viewStack.top() == view)
+            break;
+        m_viewStack.pop();
+    }
+    updateLayout();
+}
+
+void ViewManager::popTheStack()
+{
+    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    if(!m_viewStack.empty())
+    {
+        m_previousTop = m_viewStack.top();
+        m_viewStack.pop();
+        updateLayout();
+    }
+}
+
+void ViewManager::pushViewToStack(interfaces::AbstractUIComponent* view)
+{
+    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    M_ASSERT(view);
+    m_viewStack.push(view);
+    updateLayout();
+}
+
+
+void ViewManager::updateLayout()
+{
+    BROWSER_LOGD("[%s:%d] ", __PRETTY_FUNCTION__, __LINE__);
+    Evas_Object* swallowed = elm_layout_content_get(m_mainLayout, "elm.swallow.content");
+
+    if (!m_viewStack.empty())
+    {
+        if (m_viewStack.top()->getContent() == swallowed)
+        {
+            BROWSER_LOGD("[%s:%d] Top of stack is already visible!!!",
+                         __PRETTY_FUNCTION__, __LINE__);
+            return;
+        }
+        if(m_previousTop)
+            m_previousTop->hideUI();
+        elm_layout_content_unset(m_mainLayout, "elm.swallow.content");
+        elm_layout_content_set(m_mainLayout, "elm.swallow.content", m_viewStack.top()->getContent());
+        m_viewStack.top()->showUI();
+    }
+    else
+    {
+        BROWSER_LOGD("[%s:%d] Stack is empty!!!",__PRETTY_FUNCTION__, __LINE__);
+        if(m_previousTop)
+             m_previousTop->hideUI();
+
+        elm_layout_content_unset(m_mainLayout, "elm.swallow.content");
+        elm_layout_content_set(m_mainLayout, "elm.swallow.content", nullptr);
+    }
+}
+
+Evas_Object* ViewManager::getContent()
+{
+    M_ASSERT(m_mainLayout);
+    return m_mainLayout;
+}
+
+}//namespace base_ui
+}//names1pace tizen_browser
diff --git a/services/SimpleUI/ViewManager.h b/services/SimpleUI/ViewManager.h
new file mode 100644 (file)
index 0000000..06d385d
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * ViewManager.h
+ *
+ *  Created on: Sep 11, 2015
+ *      Author: m.lapinski@samsung.com
+ */
+
+#ifndef VIEWMANAGER_H_
+#define VIEWMANAGER_H_
+
+#include <Evas.h>
+
+#include <stack>
+
+#include "core/AbstractInterfaces/AbstractUIComponent.h"
+
+namespace tizen_browser{
+namespace base_ui{
+
+
+/**
+ * @brief This class simplifies UI component management. It is a views stack.
+ * It handles all widget framework issues related to changing active view.
+ */
+class ViewManager
+{
+public:
+/**
+ * @brief constructor.
+ *
+ * @param A window which will contatin ViewManager's main layout.
+ */
+    ViewManager(Evas_Object* parentWindow);
+
+/**
+ * @brief Pops stack to specified view. Hides actual view (if there is any) and
+ *        make specified view visible. Does nothing if stack is empty. If view
+ *        is not in the stack, it pops whole stack.
+ *
+ * @param A view which stack should be popped to. Do not use nullptr.
+ */
+    void popStackTo(interfaces::AbstractUIComponent* view);
+
+/**
+ * @brief Pops actual view from the stack, hides it and if there is any view
+ *        under it makes it visible.
+ */
+    void popTheStack();
+
+/**
+ * @brief Pushes view to the stack, hides if any wiew was visible hides it and
+ *        new one visible visible.
+ *
+ * @param View pushed to stack. Do not use nullptr.
+ */
+    void pushViewToStack(interfaces::AbstractUIComponent* view);
+
+/**
+ * @brief Function returns elm layout used in view management. It's parent is
+ * specified in constructor.
+ *
+ * @return ViewManager's main layout.
+ */
+    Evas_Object* getContent();
+
+private:
+    void updateLayout();
+private:
+    Evas_Object* m_mainLayout;
+    std::stack<interfaces::AbstractUIComponent*> m_viewStack;
+    interfaces::AbstractUIComponent* m_previousTop;
+};
+
+}//namespace base_ui
+}//namespace tizen_browser
+#endif //VIEWMANAGER_H_