TizenRefApp-7823 Implement closing Menu, Hoversel and Popup when view becomes not... 32/105832/4
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Tue, 20 Dec 2016 08:10:56 +0000 (10:10 +0200)
committerAleksandr Sapozhnik <a.sapozhnik@samsung.com>
Wed, 21 Dec 2016 11:48:13 +0000 (03:48 -0800)
Change-Id: I340077d9954f29d71be5f664f217504efcb69298
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-apps-common/inc/Ui/Hoversel.h
lib-apps-common/inc/Ui/Menu.h
lib-apps-common/inc/Ui/Popup.h
lib-apps-common/inc/Ui/View.h
lib-apps-common/src/Ui/Hoversel.cpp
lib-apps-common/src/Ui/Menu.cpp
lib-apps-common/src/Ui/Popup.cpp
lib-apps-common/src/Ui/ProcessPopup.cpp
lib-apps-common/src/Ui/View.cpp

index e5cfbbcc851c4c66a50e49fc1f4672b1aba401e8..3f62df783b30e624d0dc477f162677154d9d30a4 100644 (file)
 
 namespace Ui
 {
+       class View;
+
        class EXPORT_API Hoversel : public Selector
        {
        public:
+               Hoversel();
+               virtual ~Hoversel() override;
+
                /**
                 * @brief Add item with text.
                 * @param[in]   text        Item text
@@ -53,10 +58,13 @@ namespace Ui
                virtual Evas_Object *onCreate(Evas_Object *parent) override;
 
        private:
+               void onViewNavigation(Evas_Object *obj, void *eventInfo);
                void onSelected(Evas_Object *hoversel, Elm_Object_Item *item);
                static void onExpanded(void *data, Evas_Object *hoversel, void *eventInfo);
                static void onDismissed(void *data, Evas_Object *hoversel, void *eventInfo);
                static void onBackPressed(void *data, Evas_Object *hoversel, void *eventInfo);
+
+               View *m_View;
        };
 }
 
index e5c1080cc06d44fcd300026b69dda3e9302f0664..5b8a773d465c19dcad4fc2f84b98ba0852681c68 100644 (file)
@@ -22,6 +22,9 @@
 
 namespace Ui
 {
+       class View;
+       class Window;
+
        class EXPORT_API Menu : public Control
        {
        public:
@@ -30,6 +33,9 @@ namespace Ui
                 */
                typedef std::function<void()> ItemCallback;
 
+               Menu();
+               virtual ~Menu() override;
+
                /**
                 * @brief Add menu item
                 * @param[in]   text        Item text
@@ -47,9 +53,15 @@ namespace Ui
                virtual Evas_Object *onCreate(Evas_Object *parent) override;
 
        private:
+               void onViewNavigation(Evas_Object *obj, void *eventInfo);
+               void onWindowResized(Evas *e, Evas_Object *obj, void *eventInfo);
+
                static void onItemSelect(void *data, Evas_Object *obj, void *item);
                static void onItemDestroy(void *data, Evas_Object *obj, void *item);
                void onDismissed(Evas_Object *obj, void *eventInfo);
+
+               View *m_View;
+               Window *m_Window;
        };
 }
 
index 71662de85d539f94ca27860f8a82a876b75159c9..6737117902e92a9eaac85133673fbf27d01ca6f6 100644 (file)
@@ -22,6 +22,9 @@
 
 namespace Ui
 {
+       class View;
+       class Window;
+
        class EXPORT_API Popup : public Control
        {
        public:
@@ -32,6 +35,7 @@ namespace Ui
                typedef std::function<bool()> ButtonCallback;
 
                Popup();
+               virtual ~Popup() override;
 
                /**
                 * @brief Allows method overload instead of shadowing.
@@ -99,6 +103,10 @@ namespace Ui
 
        private:
                void onCanceled();
+
+               void onViewNavigation(Evas_Object *obj, void *eventInfo);
+               void onViewDestroy(Evas *e, Evas_Object *obj, void *eventInfo);
+
                void onButtonPressed(Evas_Object *obj, void *eventInfo);
                void onButtonDestroy(Evas *e, Evas_Object *obj, void *eventInfo);
                void onBackPressed(Evas_Object *obj, void *eventInfo);
@@ -107,6 +115,9 @@ namespace Ui
 
                size_t m_ButtonCount;
                ButtonCallback m_OnCanceled;
+
+               View *m_View;
+               Window *m_Window;
        };
 }
 
index b49100e120607b7833e68d3da7f54a40c882c97a..dde042818c04512dc7591573aff9e841553570df 100644 (file)
@@ -20,6 +20,8 @@
 #include "Ui/Control.h"
 #include "Ui/NavigatorPage.h"
 
+#define EVENT_VIEW_NAVIGATION "navigation"
+
 namespace Ui
 {
        class Navigator;
index 12943576d10db6f01c7acf1c6167b70d545630dd..8f78ca70f3df641630616b3b212999d8895f0e5c 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "Ui/Hoversel.h"
+#include "Ui/View.h"
 #include "Ui/Window.h"
 #include "Utils/Callback.h"
 
 
 using namespace Ui;
 
+Hoversel::Hoversel()
+       : m_View(nullptr)
+{
+}
+
+Hoversel::~Hoversel()
+{
+       if (m_View) {
+               evas_object_smart_callback_del_full(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+                               makeCallback(&Hoversel::onViewNavigation), this);
+       }
+}
+
 Elm_Object_Item *Hoversel::addItem(const char *text, void *data)
 {
        Elm_Object_Item *item = elm_hoversel_item_add(getEvasObject(), text,
@@ -47,15 +61,7 @@ void Hoversel::setSelectedItem(Elm_Object_Item *item)
 
 Evas_Object *Hoversel::onCreate(Evas_Object *parent)
 {
-       Evas_Object *hoverParent = parent;
-       Window *window = findParent<Window>(parent);
-       if (window) {
-               hoverParent = window->getBaseLayout();
-       }
-
        Evas_Object *hoversel = elm_hoversel_add(parent);
-       elm_hoversel_hover_parent_set(hoversel, hoverParent);
-
        evas_object_smart_callback_add(hoversel, "selected",
                        (Evas_Smart_Cb) makeCallback(&Hoversel::onSelected), this);
        evas_object_smart_callback_add(hoversel, "expanded",
@@ -63,9 +69,27 @@ Evas_Object *Hoversel::onCreate(Evas_Object *parent)
        evas_object_smart_callback_add(hoversel, "dismissed",
                        &Hoversel::onDismissed, this);
 
+       m_View = findParent<View>(parent);
+       if (m_View) {
+               evas_object_smart_callback_add(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+                               makeCallback(&Hoversel::onViewNavigation), this);
+       }
+
+       auto window = findParent<Window>(parent);
+       if (window) {
+               elm_hoversel_hover_parent_set(hoversel, window->getEvasObject());
+       }
+
        return hoversel;
 }
 
+void Hoversel::onViewNavigation(Evas_Object *obj, void *eventInfo)
+{
+       if (!eventInfo) {
+               elm_hoversel_hover_end(getEvasObject());
+       }
+}
+
 void Hoversel::onSelected(Evas_Object *hoversel, Elm_Object_Item *item)
 {
        if (Selector::onSelected(item)) {
index bfa2d8b0fecd6fee49afafd0c6262758845ea496..92781a3ef234fd0fedeb88c9aec3708bd3c4c3d9 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "Ui/Menu.h"
+#include "Ui/View.h"
 #include "Ui/Window.h"
 #include "Utils/Callback.h"
 
 
 using namespace Ui;
 
+Menu::Menu()
+       : m_View(nullptr), m_Window(nullptr)
+{
+}
+
+Menu::~Menu()
+{
+       if (m_View) {
+               evas_object_smart_callback_del_full(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+                               makeCallback(&Menu::onViewNavigation), this);
+       }
+       if (m_Window) {
+               evas_object_event_callback_del_full(m_Window->getEvasObject(), EVAS_CALLBACK_RESIZE,
+                               makeCallback(&Menu::onWindowResized), this);
+       }
+}
+
 Elm_Object_Item *Menu::addItem(const char *text, ItemCallback callback)
 {
        Elm_Object_Item *item = elm_ctxpopup_item_append(getEvasObject(), text, nullptr,
@@ -33,26 +51,19 @@ Elm_Object_Item *Menu::addItem(const char *text, ItemCallback callback)
 
 void Menu::show()
 {
-       Window *window = findParent<Window>();
-       if (!window) {
-               return;
-       }
-
-       Evas_Coord y = 0, h = 0;
-       evas_object_geometry_get(window->getEvasObject(), nullptr, &y, nullptr, &h);
+       Evas_Coord y = 0, w = 0, h = 0;
+       Evas_Object *parent = elm_ctxpopup_hover_parent_get(getEvasObject());
+       evas_object_geometry_get(parent, nullptr, &y, &w, &h);
 
        Evas_Object *menu = getEvasObject();
-       evas_object_move(menu, 0, y + h);
+       int menuWidth = 0;
+       evas_object_geometry_get(menu, nullptr, nullptr, &menuWidth, nullptr);
+       evas_object_move(menu, w / 2 - menuWidth / 2, y + h);
        evas_object_show(menu);
 }
 
 Evas_Object *Menu::onCreate(Evas_Object *parent)
 {
-       Window *window = findParent<Window>(parent);
-       if (window) {
-               parent = window->getEvasObject();
-       }
-
        Evas_Object *menu = elm_ctxpopup_add(parent);
        elm_object_style_set(menu, "more/default");
 
@@ -63,9 +74,34 @@ Evas_Object *Menu::onCreate(Evas_Object *parent)
        eext_object_event_callback_add(menu, EEXT_CALLBACK_MORE,
                        eext_ctxpopup_back_cb, nullptr);
 
+       m_View = findParent<View>(parent);
+       if (m_View) {
+               evas_object_smart_callback_add(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+                               makeCallback(&Menu::onViewNavigation), this);
+       }
+
+       m_Window = findParent<Window>(parent);
+       if (m_Window) {
+               elm_ctxpopup_hover_parent_set(menu, m_Window->getEvasObject());
+               evas_object_event_callback_add(m_Window->getEvasObject(), EVAS_CALLBACK_RESIZE,
+                               makeCallback(&Menu::onWindowResized), this);
+       }
+
        return menu;
 }
 
+void Menu::onViewNavigation(Evas_Object *obj, void *eventInfo)
+{
+       if (!eventInfo) {
+               elm_ctxpopup_dismiss(getEvasObject());
+       }
+}
+
+void Menu::onWindowResized(Evas *e, Evas_Object *obj, void *eventInfo)
+{
+       show();
+}
+
 void Menu::onItemSelect(void *data, Evas_Object *obj, void *item)
 {
        ItemCallback &callback = *(ItemCallback *) data;
index 7c8c85065be03ff0a6e519e707ea6957df7cb7ab..3489c3fe36015a95030b351f8da66c5a95b28440 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "Ui/Popup.h"
+#include "Ui/View.h"
 #include "Ui/Window.h"
 #include "Utils/Callback.h"
 #include "Utils/Range.h"
 using namespace Ui;
 
 Popup::Popup()
-       : m_ButtonCount(0)
+       : m_ButtonCount(0), m_View(nullptr), m_Window(nullptr)
 {
 }
 
+Popup::~Popup()
+{
+       if (m_View) {
+               evas_object_smart_callback_del_full(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+                               makeCallback(&Popup::onViewNavigation), this);
+               evas_object_event_callback_del_full(m_View->getEvasObject(), EVAS_CALLBACK_DEL,
+                               makeCallback(&Popup::onViewDestroy), this);
+       }
+}
+
 Popup *Popup::create(Evas_Object *parent, const char *title,
                const char *text, const char *buttonText)
 {
@@ -96,9 +107,17 @@ void Popup::close()
 
 Evas_Object *Popup::onCreate(Evas_Object *parent)
 {
-       Window *window = findParent<Window>(parent);
-       if (window) {
-               parent = window->getBaseLayout();
+       m_View = findParent<View>(parent);
+       if (m_View) {
+               evas_object_smart_callback_add(m_View->getEvasObject(), EVENT_VIEW_NAVIGATION,
+                               makeCallback(&Popup::onViewNavigation), this);
+               evas_object_event_callback_add(m_View->getEvasObject(), EVAS_CALLBACK_DEL,
+                               makeCallback(&Popup::onViewDestroy), this);
+       }
+
+       m_Window = findParent<Window>(parent);
+       if (m_Window) {
+               parent = m_Window->getBaseLayout();
        }
 
        Evas_Object *popup = elm_popup_add(parent);
@@ -120,6 +139,21 @@ void Popup::onCanceled()
        }
 }
 
+void Popup::onViewNavigation(Evas_Object *obj, void *eventInfo)
+{
+       if (!eventInfo) {
+               /* Don't close the popup if navigation is caused by window losing focus */
+               if (!m_Window || elm_win_focus_get(m_Window->getEvasObject())) {
+                       onCanceled();
+               }
+       }
+}
+
+void Popup::onViewDestroy(Evas *e, Evas_Object *obj, void *eventInfo)
+{
+       m_View = nullptr;
+}
+
 void Popup::onButtonPressed(Evas_Object *obj, void *eventInfo)
 {
        ButtonCallback *callback = (ButtonCallback *) evas_object_data_get(obj, BUTTON_DATA_KEY);
index 90763c4c3fd094edec6fc4d150fd6f7ec68a2c08..65dee29f6cd5b8bad0322eb74d10f285206cf621 100644 (file)
@@ -36,7 +36,7 @@ ProcessPopup::ProcessPopup(Size size, double showDelayTime, double showMinTime)
        ecore_timer_freeze(m_ShowMinTimer);
 
        setCancelCallback([this] {
-               return m_IsDestroyPending;
+               return false;
        });
 }
 
index 989853f88fee31420c4fc169890e6a73b95e32f8..72f1af32975db60b05b7d898d5a9dcc563ac9659 100644 (file)
@@ -64,6 +64,7 @@ void View::onNavigation(bool isCurrent, int degree)
        }
 
        onNavigation(m_IsCurrent);
+       evas_object_smart_callback_call(getEvasObject(), EVENT_VIEW_NAVIGATION, (void *) (long) m_IsCurrent);
 }
 
 void View::onRotation(int degree)