implement hw key events propagation. 47/60147/1
authorHermet Park <hermet@hermet.pe.kr>
Tue, 23 Feb 2016 15:34:36 +0000 (00:34 +0900)
committerHermet Park <hermet@hermet.pe.kr>
Tue, 23 Feb 2016 15:34:36 +0000 (00:34 +0900)
now viewmgr support back/menu keys.

Change-Id: I579f8e9fbcbae647da83a8375c4d8c39a85a8828

25 files changed:
CMakeLists.txt
src/efl/example/main.cpp
src/efl/example/page1.h
src/efl/example/page2.h
src/efl/example/page3.h
src/efl/example/page4.h
src/efl/example/page5.h
src/efl/example/page6.h
src/efl/mobile/ui_basic_controller.cpp [new file with mode: 0644]
src/efl/mobile/ui_basic_controller.h [new file with mode: 0644]
src/efl/mobile/ui_basic_key_listener.cpp
src/efl/mobile/ui_basic_key_listener.h
src/efl/mobile/ui_basic_view.cpp
src/efl/mobile/ui_basic_view.h
src/efl/mobile/ui_basic_viewmgr.cpp [new file with mode: 0644]
src/efl/mobile/ui_basic_viewmgr.h [new file with mode: 0644]
src/efl/mobile/ui_viewmanager.h
src/efl/ui_controller.h
src/efl/ui_key_listener.cpp
src/efl/ui_key_listener.h
src/efl/ui_view.cpp
src/efl/ui_view.h
src/efl/ui_viewmgr.cpp
src/efl/ui_viewmgr.h
src/interface/ui_view_interface.h

index efecc3bcd48295f38d80c88f8dd543f2f79c233b..26c7143766f138d53f27fe6af233928e148c0fee 100644 (file)
@@ -10,8 +10,10 @@ SET(SRCS
        src/efl/ui_view.cpp
        src/efl/ui_viewmgr.cpp
        src/efl/ui_key_listener.cpp
+       src/efl/mobile/ui_basic_controller.cpp
        src/efl/mobile/ui_basic_view.cpp
        src/efl/mobile/ui_basic_key_listener.cpp
+       src/efl/mobile/ui_basic_viewmgr.cpp
        src/efl/example/main.cpp
    )
 
index 4b389506aaa390170f488394f2fa9c53fb73deaa..edcfdf7bf341bcbb8a4871d1b9bf37542b4f8aae 100644 (file)
@@ -30,6 +30,7 @@ create_tabbar(Evas_Object *parent)
 
        toolbar = elm_toolbar_add(parent);
 
+       //FIXME: :( UI_View can set this style instead.
        elm_object_style_set(toolbar, "tabbar_with_title");
        elm_toolbar_shrink_mode_set(toolbar, ELM_TOOLBAR_SHRINK_EXPAND);
        elm_toolbar_transverse_expanded_set(toolbar, EINA_TRUE);
@@ -41,6 +42,7 @@ create_tabbar(Evas_Object *parent)
 
        return toolbar;
 }
+
 Evas_Object*
 create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_clicked_cb, Evas_Smart_Cb next_btn_clicked_cb, appdata_s *ad)
 {
@@ -86,7 +88,7 @@ create_content(Evas_Object *parent, const char *text, Evas_Smart_Cb prev_btn_cli
 static void create_base_gui(appdata_s *ad)
 {
        //FIXME: Hide this creation.
-       ad->viewmgr = new ui_viewmgr(PACKAGE);
+       ad->viewmgr = new ui_basic_viewmgr(PACKAGE);
 
        create_page1(ad);
 
index 0951a61586de9f8da433556968917af7292c1d71..3c8bd062b1aa99d8d9160c8810758e7303ce1ec7 100644 (file)
@@ -14,7 +14,7 @@
  *  limitations under the License.
  *
  */
-class page1: public ui_controller
+class page1: public ui_basic_controller
 {
 private:
        appdata_s *ad;
@@ -55,6 +55,12 @@ public:
 
                view->set_content(content, "Title");
        }
+
+       bool menu()
+       {
+               LOGE("Menu!");
+               return true;
+       }
 };
 
 void create_page1(appdata_s *ad)
index 0f2a2d3ad4d6d1a712f51db24b8cfc46bb46db76..d36c313065a13a65f0aededb8a15fc06d82ad1be 100644 (file)
@@ -14,7 +14,7 @@
  *  limitations under the License.
  *
  */
-class page2: public ui_controller
+class page2: public ui_basic_controller
 {
 private:
        appdata_s *ad;
index dc5621b91b62ca9889d89e3518ad0a23bf5f02ac..f2a29eb906d68f32b23fa995d6efb86aca24b4bc 100644 (file)
@@ -14,7 +14,7 @@
  *  limitations under the License.
  *
  */
-class page3: public ui_controller
+class page3: public ui_basic_controller
 {
 private:
        appdata_s *ad;
index 6c22cf5029a42a276882dafd27dfb91a18ddaf66..168202d0975d81666661f872975e93b589acd57a 100644 (file)
@@ -14,7 +14,7 @@
  *  limitations under the License.
  *
  */
-class page4: public ui_controller
+class page4: public ui_basic_controller
 {
 private:
        appdata_s *ad;
index 202ce7b8a9ea5824515eebe2f21869b4f7b6988b..ca8c4f588fa55da04fbc44b6239d46d7320c3bd3 100644 (file)
@@ -14,7 +14,7 @@
  *  limitations under the License.
  *
  */
-class page5: public ui_controller
+class page5: public ui_basic_controller
 {
 private:
        appdata_s *ad;
index aa150244c1311904f27b1355db1d0c03d670ef14..2b11ed61dab0d4acf33d460c99951dd55852e6bc 100644 (file)
@@ -14,7 +14,7 @@
  *  limitations under the License.
  *
  */
-class page6: public ui_controller
+class page6: public ui_basic_controller
 {
 private:
        appdata_s *ad;
diff --git a/src/efl/mobile/ui_basic_controller.cpp b/src/efl/mobile/ui_basic_controller.cpp
new file mode 100644 (file)
index 0000000..9f53896
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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.
+ *
+ */
+#include "ui_viewmanager.h"
+
+using namespace efl_viewmgr;
+using namespace viewmgr;
+
+ui_basic_controller::~ui_basic_controller()
+{
+}
+
+bool ui_basic_controller::menu()
+{
+       return true;
+}
diff --git a/src/efl/mobile/ui_basic_controller.h b/src/efl/mobile/ui_basic_controller.h
new file mode 100644 (file)
index 0000000..a980e95
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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.
+ *
+ */
+#ifndef UI_BASIC_CONTROLLER_H
+#define UI_BASIC_CONTROLLER_H
+
+#include "../ui_viewmanager.h"
+
+namespace efl_viewmgr
+{
+class ui_basic_controller: public ui_controller
+{
+public:
+       virtual ~ui_basic_controller();
+       virtual bool menu();
+};
+}
+
+#endif /* UI_BASIC_CONTROLLER_H */
index 993aca4789a61720de539bd8f1d267b0355c64da..cff8b7060f80e98dc48c564a6d28c7c96a606a0c 100644 (file)
 using namespace efl_viewmgr;
 using namespace viewmgr;
 
-static const char *KEY_BACK = "XF86Back";
 static const char *KEY_MENU = "XF86Menu";
 
 enum ui_key_event_type
 {
-       UI_KEY_EVENT_BACK = 0,
        UI_KEY_EVENT_MENU
 };
 
@@ -33,89 +31,20 @@ ui_basic_key_listener::ui_basic_key_listener(ui_viewmgr *viewmgr)
 {
 }
 
-static void event_proc(ui_basic_key_listener *key_handler, Evas_Event_Key_Down *ev)
+void ui_basic_key_listener::extend_event_proc(ui_view *view, Evas_Event_Key_Down *ev)
 {
-   ui_key_event_type type;
-
-   if (!strcmp(ev->keyname, KEY_BACK))
-     type = UI_KEY_EVENT_BACK;
-   else if (!strcmp(ev->keyname, KEY_MENU))
-     type = UI_KEY_EVENT_MENU;
-   else return;
-
-   ui_viewmgr *viewmgr = key_handler->get_viewmgr();
-   if (!viewmgr->is_activated()) return;
-
-   //Get Top View
-   ui_view *view = reinterpret_cast<ui_view *>(viewmgr->get_last_view());
-   if (!view) return;
-
-   //call events
-   switch (type)
-   {
-   case UI_KEY_EVENT_BACK:
-          //view->back();
-          LOGE("BACK!");
-          break;
-   case UI_KEY_EVENT_MENU:
-          //view->menu();
-          LOGE("MENU!");
-          break;
-   }
-}
-
-bool ui_basic_key_listener::term()
-{
-       evas_object_del(this->key_grabber);
-       return true;
+       if (strcmp(ev->keyname, KEY_MENU)) return;
+       dynamic_cast<ui_basic_view *>(view)->menu();
 }
 
 bool ui_basic_key_listener::init()
 {
-       if (!this->viewmgr)
-       {
-               LOGE("No view manager??");
-               return false;
-       }
-
-       Evas *e = evas_object_evas_get(this->viewmgr->get_window());
-       if (!e)
-       {
-               LOGE("Failed to get Evas from window");
-               return false;
-       }
+       if (!ui_key_listener::init()) return false;
 
-       Evas_Object *key_grab_rect = evas_object_rectangle_add(e);
-       if (!key_grab_rect)
+       if (!evas_object_key_grab(this->key_grabber, KEY_MENU, 0, 0, EINA_FALSE))
        {
-               LOGE("Failed to create a key grabber rectangle");
+               LOGE("Failed to grab MENU KEY(%s)\n", KEY_MENU);
                return false;
        }
-
-       evas_object_event_callback_add(key_grab_rect, EVAS_CALLBACK_KEY_UP,
-                       [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void
-                       {
-                               Evas_Event_Key_Down *ev = static_cast<Evas_Event_Key_Down *>(event_info);
-                               ui_basic_key_listener *key_handler = static_cast<ui_basic_key_listener *>(data);
-                               event_proc(key_handler, ev);
-                       },
-                       this);
-
-       if (!evas_object_key_grab(key_grab_rect, KEY_BACK, 0, 0, EINA_FALSE))
-       {
-            LOGE("Failed to grab BACK KEY(%s)\n", KEY_BACK);
-            evas_object_del(key_grab_rect);
-            return false;
-       }
-
-       if (!evas_object_key_grab(key_grab_rect, KEY_MENU, 0, 0, EINA_FALSE))
-       {
-            LOGE("Failed to grab MENU KEY(%s)\n", KEY_MENU);
-            evas_object_del(key_grab_rect);
-            return false;
-       }
-
-       this->key_grabber = key_grab_rect;
-
        return true;
 }
index 203ebb54f5ac69d2f82ba6386b36697106f77408..2563d55735be39a4980ba1a6f5f980b29a11edeb 100644 (file)
@@ -28,10 +28,8 @@ class ui_basic_key_listener : public ui_key_listener
 public:
        ui_basic_key_listener(ui_viewmgr *viewmgr);
 
-       bool init();
-       bool term();
-
-       ui_viewmgr *get_viewmgr() { return this->viewmgr; }
+       virtual bool init();
+       virtual void extend_event_proc(ui_view *view, Evas_Event_Key_Down *ev);
 };
 
 }
index 83886f9f0d11de2228af24f9886469e13468af89..f1c2c136c6a22877bd6ee48090e7a7a642850ac9 100644 (file)
@@ -247,3 +247,9 @@ void ui_basic_view::unload_content()
        ui_view::set_content(NULL);
        this->destroy_layout();
 }
+
+void ui_basic_view::menu()
+{
+       if (!this->get_controller()) return;
+       (dynamic_cast<ui_basic_controller *>(this->get_controller()))->menu();
+}
index 8e37f2ac8f8070e920340fb6fd17129260460272..eff40440631ac9575e5c61edaf3d6ee1720ba38b 100644 (file)
@@ -48,6 +48,8 @@ public:
        bool set_title(const char *text);
        bool set_tabbar(Evas_Object *toolbar);
 
+       virtual void menu();
+
        virtual Evas_Object *get_base()
        {
                return this->layout;
diff --git a/src/efl/mobile/ui_basic_viewmgr.cpp b/src/efl/mobile/ui_basic_viewmgr.cpp
new file mode 100644 (file)
index 0000000..a2fc32c
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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.
+ *
+ */
+#include "ui_viewmanager.h"
+
+using namespace efl_viewmgr;
+using namespace viewmgr;
+
+ui_basic_viewmgr::ui_basic_viewmgr(const char *pkg)
+               : ui_viewmgr(pkg, new ui_basic_key_listener(this))
+{
+}
+
+ui_basic_viewmgr::~ui_basic_viewmgr()
+{
+}
diff --git a/src/efl/mobile/ui_basic_viewmgr.h b/src/efl/mobile/ui_basic_viewmgr.h
new file mode 100644 (file)
index 0000000..f0aa8d1
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  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.
+ *
+ */
+#ifndef UI_BASIC_VIEWMGR_H
+#define UI_BASIC_VIEWMGR_H
+
+#include <Elementary.h>
+#include "../ui_viewmanager.h"
+
+namespace efl_viewmgr
+{
+
+class ui_basic_view;
+
+class ui_basic_viewmgr: public ui_viewmgr
+{
+       friend class ui_basic_view;
+
+public:
+       ui_basic_viewmgr(const char *pkg);
+       virtual ~ui_basic_viewmgr();
+
+};
+}
+
+#endif /* UI_BASIC_VIEWMGR_H */
index a2a23b5fd4eef81c47ad6652b84db665ec279180..6910adeca6ecc07e6c9b440cb7d952b68bdac05d 100644 (file)
@@ -21,5 +21,7 @@
 #endif
 #define LOG_TAG "UI_VIEWMGR"
 
-#include "ui_basic_key_listener.h"
+#include "ui_basic_controller.h"
 #include "ui_basic_view.h"
+#include "ui_basic_key_listener.h"
+#include "ui_basic_viewmgr.h"
index 485b3c038ae35c7e6cdb572dd464e8b18ad2030f..1878e64e8eec034e2abaff21571f31b0d319f8f3 100644 (file)
@@ -34,6 +34,8 @@ public:
        virtual void pause() {}
        virtual void resume() {}
        virtual void destroy() {}
+
+       virtual bool back() { return true; }
 };
 }
 
index 5b12befd94cd24119848afbac6959938267ddefe..6a6144c3adb65f466a6adce5cb8864b5e70ac676 100644 (file)
@@ -21,40 +21,27 @@ using namespace viewmgr;
 
 static const char *KEY_BACK = "XF86Back";
 
-enum ui_key_event_type
-{
-       UI_KEY_EVENT_BACK = 0,
-};
-
 ui_key_listener::ui_key_listener(ui_viewmgr *viewmgr)
                : viewmgr(viewmgr), key_grabber(NULL)
 {
 
 }
 
-static void event_proc(ui_key_listener *key_handler, Evas_Event_Key_Down *ev)
+static void event_proc(ui_key_listener *key_listener, Evas_Event_Key_Down *ev)
 {
-   ui_key_event_type type;
-
-   if (!strcmp(ev->keyname, KEY_BACK))
-     type = UI_KEY_EVENT_BACK;
-   else return;
-
-   ui_viewmgr *viewmgr = key_handler->get_viewmgr();
-   if (!viewmgr->is_activated()) return;
-
-   //Get Top View
-   ui_view *view = reinterpret_cast<ui_view *>(viewmgr->get_last_view());
-   if (!view) return;
-
-   //call events
-   switch (type)
-   {
-   case UI_KEY_EVENT_BACK:
-          //view->back();
-          LOGE("BACK!");
-          break;
-   }
+       //Only if view manager is activated
+       ui_viewmgr *viewmgr = key_listener->get_viewmgr();
+       if (!viewmgr->is_activated()) return;
+
+       //Get Top View
+       ui_view *view = dynamic_cast<ui_view *>(viewmgr->get_last_view());
+       if (!view) return;
+
+       key_listener->extend_event_proc(view, ev);
+
+       if (strcmp(ev->keyname, KEY_BACK)) return;
+
+       view->back();
 }
 
 bool ui_key_listener::term()
@@ -85,20 +72,18 @@ bool ui_key_listener::init()
                return false;
        }
 
-       evas_object_event_callback_add(key_grab_rect, EVAS_CALLBACK_KEY_UP,
-                       [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void
-                       {
-                               Evas_Event_Key_Down *ev = static_cast<Evas_Event_Key_Down *>(event_info);
-                               ui_key_listener *key_handler = static_cast<ui_key_listener *>(data);
-                               event_proc(key_handler, ev);
-                       },
-                       this);
+       evas_object_event_callback_add(key_grab_rect, EVAS_CALLBACK_KEY_UP, [](void *data, Evas *e, Evas_Object *obj, void *event_info) -> void
+       {
+               Evas_Event_Key_Down *ev = static_cast<Evas_Event_Key_Down *>(event_info);
+               ui_key_listener *key_listener = static_cast<ui_key_listener *>(data);
+               event_proc(key_listener, ev);
+       }, this);
 
        if (!evas_object_key_grab(key_grab_rect, KEY_BACK, 0, 0, EINA_FALSE))
        {
-            LOGE("Failed to grab BACK KEY(%s)\n", KEY_BACK);
-            evas_object_del(key_grab_rect);
-            return false;
+               LOGE("Failed to grab BACK KEY(%s)\n", KEY_BACK);
+               evas_object_del(key_grab_rect);
+               return false;
        }
 
        this->key_grabber = key_grab_rect;
index 7921b5763db5409a8f4f24d4d8c913cbc3559ae3..62ee0f5ceb61a67e902873245166ff867c5e868c 100644 (file)
@@ -23,6 +23,7 @@
 namespace efl_viewmgr
 {
 class ui_viewmgr;
+class ui_view;
 
 class ui_key_listener
 {
@@ -36,6 +37,7 @@ public:
 
        virtual bool init();
        virtual bool term();
+       virtual void extend_event_proc(ui_view *view, Evas_Event_Key_Down *ev) {}
 
        ui_viewmgr *get_viewmgr() { return this->viewmgr; }
 };
index d4a4ec157405fe64b1428179116ceb57eb26e0db..ae35ceba95a5b6168e7329327b36c7bf492bd7a0 100644 (file)
@@ -70,3 +70,15 @@ void ui_view::set_indicator(ui_view_indicator indicator)
 
        viewmgr->set_indicator(indicator);
 }
+
+void ui_view::back()
+{
+       if (this->get_controller())
+       {
+               if (!dynamic_cast<ui_controller *>(this->get_controller())->back())
+               {
+                       return;
+               }
+       }
+       dynamic_cast<ui_viewmgr *>(this->get_viewmgr())->pop_view();
+}
index 09171aa6d57b8f2aa0f30c787b74889c3cc2bb78..87ce588abd3d22ad5c934dc3d08149a0c6c8a761 100644 (file)
@@ -38,6 +38,8 @@ public:
        virtual Evas_Object *set_content(Evas_Object *content);
        virtual Evas_Object *get_base();
 
+       virtual void back();
+
        void set_indicator(ui_view_indicator indicator);
 
 protected:
index f944b965b7b0651dbfdeca0fc7ec780559605560..62b163cb60ce8a8548d509713dba0b2cd574a689 100644 (file)
@@ -79,8 +79,8 @@ bool ui_viewmgr::create_base_layout(Evas_Object *conform)
        return true;
 }
 
-ui_viewmgr::ui_viewmgr(const char *pkg)
-               : ui_viewmgr_interface(), key_listener(NULL)
+ui_viewmgr::ui_viewmgr(const char *pkg, ui_key_listener *key_listener)
+               : ui_viewmgr_interface(), key_listener(key_listener)
 {
        if (!pkg)
        {
@@ -134,18 +134,18 @@ ui_viewmgr::ui_viewmgr(const char *pkg)
 
        elm_win_autodel_set(this->win, EINA_TRUE);
 
-       this->set_key_listener();
+       key_listener->init();
 }
 
-ui_viewmgr::~ui_viewmgr()
+ui_viewmgr::ui_viewmgr(const char *pkg)
+               : ui_viewmgr(pkg, new ui_key_listener(this))
 {
-       this->key_listener->term();
 }
 
-void ui_viewmgr::set_key_listener()
+ui_viewmgr::~ui_viewmgr()
 {
-       this->key_listener = new ui_key_listener(this);
-       this->key_listener->init();
+       this->key_listener->term();
+       delete(this->key_listener);
 }
 
 bool ui_viewmgr::activate()
index 519b83147aa63bf336fb64a22d86990e6a90ecea..f5460065f661548694aaca43a24b7b0fb4faf8be 100644 (file)
@@ -40,9 +40,10 @@ private:
        bool create_conformant(Evas_Object *win);
        bool create_base_layout(Evas_Object *conform);
        bool set_indicator(ui_view_indicator indicator);
-       virtual void set_key_listener();
 
 protected:
+       ui_viewmgr(const char *pkg, ui_key_listener *key_listener);
+
        Evas_Object *get_base()
        {
                return this->layout;
index ef4327fb5f899184842b8fd3256103eb31b1f552..2b3d10f0bfd528fdb218d2a470004ba5464e7d2c 100644 (file)
@@ -144,7 +144,7 @@ protected:
        }
 
        /// Return a controller of this view.
-       const ui_controller_interface* get_controller()
+       ui_controller_interface* get_controller()
        {
                return this->controller;
        }