+ hw key handler infra code. 84/59884/1
authorHermet Park <hermet@hermet.pe.kr>
Fri, 19 Feb 2016 06:55:07 +0000 (15:55 +0900)
committerHermet Park <hermet@hermet.pe.kr>
Fri, 19 Feb 2016 06:55:07 +0000 (15:55 +0900)
Change-Id: Ibcd68ac5a35ed4f30cb9edad6b3bd0825c097608

CMakeLists.txt
src/efl/mobile/mobile_key_handler.cpp [new file with mode: 0644]
src/efl/mobile/mobile_key_handler.h [new file with mode: 0644]
src/efl/ui_key_handler.cpp [new file with mode: 0644]
src/efl/ui_key_handler.h [new file with mode: 0644]
src/efl/ui_viewmgr.cpp
src/efl/ui_viewmgr.h
src/interface/ui_viewmgr_base.h

index b790692..818aad6 100644 (file)
@@ -3,13 +3,15 @@ PROJECT(ui-viewmgr)
 SET(PACKAGE org.tizen.ui-viewmgr)
 
 SET(SRCS
-       src/efl/ui_controller.cpp
-       src/efl/ui_view.cpp
-       src/efl/ui_viewmgr.cpp
        src/interface/ui_controller_base.cpp
        src/interface/ui_view_base.cpp
        src/interface/ui_viewmgr_base.cpp
+       src/efl/ui_controller.cpp
+       src/efl/ui_view.cpp
+       src/efl/ui_viewmgr.cpp
+       src/efl/ui_key_handler.cpp
        src/efl/mobile/ui_basic_view.cpp
+       src/efl/mobile/mobile_key_handler.cpp
        src/main.cpp
    )
 
diff --git a/src/efl/mobile/mobile_key_handler.cpp b/src/efl/mobile/mobile_key_handler.cpp
new file mode 100644 (file)
index 0000000..9a3a1ba
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * 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 "../efl_viewmgr.h"
+#include "mobile_key_handler.h"
+
+using namespace efl;
+
+static const char *KEY_BACK = "XF86Back";
+static const char *KEY_MENU = "XF86Menu";
+
+enum mobile_key_event_type
+{
+       UI_KEY_EVENT_BACK = 0,
+       UI_KEY_EVENT_MENU
+};
+
+mobile_key_handler::mobile_key_handler(ui_viewmgr *viewmgr)
+               : ui_key_handler(viewmgr)
+{
+}
+
+static void event_proc(mobile_key_handler *key_handler, Evas_Event_Key_Down *ev)
+{
+   mobile_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 mobile_key_handler::term()
+{
+       evas_object_del(this->key_grabber);
+       return true;
+}
+
+bool mobile_key_handler::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;
+       }
+
+       Evas_Object *key_grab_rect = evas_object_rectangle_add(e);
+       if (!key_grab_rect)
+       {
+               LOGE("Failed to create a key grabber rectangle");
+               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);
+                               mobile_key_handler *key_handler = static_cast<mobile_key_handler *>(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;
+}
diff --git a/src/efl/mobile/mobile_key_handler.h b/src/efl/mobile/mobile_key_handler.h
new file mode 100644 (file)
index 0000000..f30db1d
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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 MOBILE_KEY_HANDLER
+#define MOBILE_KEY_HANDLER
+
+#include <Elementary.h>
+#include "../ui_key_handler.h"
+
+namespace efl
+{
+class ui_viewmgr;
+
+class mobile_key_handler : public ui_key_handler
+{
+public:
+       mobile_key_handler(ui_viewmgr *viewmgr);
+
+       bool init();
+       bool term();
+
+       ui_viewmgr *get_viewmgr() { return this->viewmgr; }
+};
+
+}
+
+#endif /* MOBILE_KEY_HANDLER */
diff --git a/src/efl/ui_key_handler.cpp b/src/efl/ui_key_handler.cpp
new file mode 100644 (file)
index 0000000..797ea47
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * 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_viewmgr.h"
+#include "ui_key_handler.h"
+
+using namespace efl;
+
+static const char *KEY_BACK = "XF86Back";
+
+enum ui_key_event_type
+{
+       UI_KEY_EVENT_BACK = 0,
+};
+
+ui_key_handler::ui_key_handler(ui_viewmgr *viewmgr)
+               : viewmgr(viewmgr), key_grabber(NULL)
+{
+
+}
+
+static void event_proc(ui_key_handler *key_handler, 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;
+   }
+}
+
+bool ui_key_handler::term()
+{
+       evas_object_del(this->key_grabber);
+       return true;
+}
+
+bool ui_key_handler::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;
+       }
+
+       Evas_Object *key_grab_rect = evas_object_rectangle_add(e);
+       if (!key_grab_rect)
+       {
+               LOGE("Failed to create a key grabber rectangle");
+               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_handler *key_handler = static_cast<ui_key_handler *>(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;
+       }
+
+       this->key_grabber = key_grab_rect;
+
+       return true;
+}
diff --git a/src/efl/ui_key_handler.h b/src/efl/ui_key_handler.h
new file mode 100644 (file)
index 0000000..112cd94
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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_KEY_HANDLER
+#define UI_KEY_HANDLER
+
+#include <Elementary.h>
+#include "../interface/ui_viewmgr.h"
+
+namespace efl
+{
+class ui_viewmgr;
+
+class ui_key_handler
+{
+protected:
+       ui_viewmgr *viewmgr;
+       Evas_Object *key_grabber;
+
+public:
+       ui_key_handler(ui_viewmgr *viewmgr);
+       virtual ~ui_key_handler() {}
+
+       virtual bool init();
+       virtual bool term();
+
+       ui_viewmgr *get_viewmgr() { return this->viewmgr; }
+};
+
+}
+
+#endif /* UI_KEY_HANDLER */
index 16598d9..87ed7d7 100644 (file)
@@ -79,7 +79,7 @@ bool ui_viewmgr::create_base_layout(Evas_Object *conform)
 }
 
 ui_viewmgr::ui_viewmgr(const char *pkg)
-               : ui_viewmgr_base()
+               : ui_viewmgr_base(), key_handler(NULL)
 {
        if (!pkg)
        {
@@ -132,10 +132,19 @@ ui_viewmgr::ui_viewmgr(const char *pkg)
        elm_win_indicator_opacity_set(this->win, ELM_WIN_INDICATOR_OPAQUE);
 
        elm_win_autodel_set(this->win, EINA_TRUE);
+
+       this->set_key_handler();
 }
 
 ui_viewmgr::~ui_viewmgr()
 {
+       this->key_handler->term();
+}
+
+void ui_viewmgr::set_key_handler()
+{
+       this->key_handler = new ui_key_handler(this);
+       this->key_handler->init();
 }
 
 bool ui_viewmgr::activate()
index 5da92e8..ba40d36 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <Elementary.h>
 #include "../interface/ui_viewmgr.h"
+#include "ui_key_handler.h"
 
 namespace efl
 {
@@ -33,11 +34,13 @@ private:
        Evas_Object *win;
        Evas_Object *conform;
        Evas_Object *layout;
+       ui_key_handler *key_handler;   //HW Key Handler such as "BACK" key...
        ui_view_indicator indicator;
 
        bool create_conformant(Evas_Object *win);
        bool create_base_layout(Evas_Object *conform);
        bool set_indicator(ui_view_indicator indicator);
+       virtual void set_key_handler();
 
 protected:
        Evas_Object *get_base()
index 52c6513..9191c70 100644 (file)
@@ -40,7 +40,7 @@ class ui_viewmgr_base
        friend class ui_view_base;
 
 private:
-       list<ui_view_base*> view_list;     //view list.
+       list<ui_view_base*> view_list;      //view list.
        bool event_block;   //event block on view transition. This value should be configurable by system.
        bool activated;     //activated status of this viewmgr.
        bool soft_back_key;  //If system doesn't support HW back key, then this value is true.
@@ -183,9 +183,6 @@ protected:
                return NULL;
        }
 
-       //FIXME: Doc.
-       ui_view_base *get_last_view();
-
        /**
         *  @brief Return a stack index number of the given view.
         *         You could use this function to query the given view stack order.
@@ -210,6 +207,9 @@ public:
        ///Destructor. Delete all contained views.
        virtual ~ui_viewmgr_base();
 
+       //FIXME: Doc.
+       ui_view_base *get_last_view();
+
        /**
         *  @brief Return the number of views which this viewmgr has.
         *