From: Hermet Park Date: Tue, 23 Feb 2016 15:34:36 +0000 (+0900) Subject: implement hw key events propagation. X-Git-Tag: submit/tizen/20160617.075742~126 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=618b8e5e6bdd958076c04d7944243c8df7a94c20;p=platform%2Fcore%2Fuifw%2Fui-viewmgr.git implement hw key events propagation. now viewmgr support back/menu keys. Change-Id: I579f8e9fbcbae647da83a8375c4d8c39a85a8828 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index efecc3b..26c7143 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) diff --git a/src/efl/example/main.cpp b/src/efl/example/main.cpp index 4b38950..edcfdf7 100644 --- a/src/efl/example/main.cpp +++ b/src/efl/example/main.cpp @@ -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); diff --git a/src/efl/example/page1.h b/src/efl/example/page1.h index 0951a61..3c8bd06 100644 --- a/src/efl/example/page1.h +++ b/src/efl/example/page1.h @@ -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) diff --git a/src/efl/example/page2.h b/src/efl/example/page2.h index 0f2a2d3..d36c313 100644 --- a/src/efl/example/page2.h +++ b/src/efl/example/page2.h @@ -14,7 +14,7 @@ * limitations under the License. * */ -class page2: public ui_controller +class page2: public ui_basic_controller { private: appdata_s *ad; diff --git a/src/efl/example/page3.h b/src/efl/example/page3.h index dc5621b..f2a29eb 100644 --- a/src/efl/example/page3.h +++ b/src/efl/example/page3.h @@ -14,7 +14,7 @@ * limitations under the License. * */ -class page3: public ui_controller +class page3: public ui_basic_controller { private: appdata_s *ad; diff --git a/src/efl/example/page4.h b/src/efl/example/page4.h index 6c22cf5..168202d 100644 --- a/src/efl/example/page4.h +++ b/src/efl/example/page4.h @@ -14,7 +14,7 @@ * limitations under the License. * */ -class page4: public ui_controller +class page4: public ui_basic_controller { private: appdata_s *ad; diff --git a/src/efl/example/page5.h b/src/efl/example/page5.h index 202ce7b..ca8c4f5 100644 --- a/src/efl/example/page5.h +++ b/src/efl/example/page5.h @@ -14,7 +14,7 @@ * limitations under the License. * */ -class page5: public ui_controller +class page5: public ui_basic_controller { private: appdata_s *ad; diff --git a/src/efl/example/page6.h b/src/efl/example/page6.h index aa15024..2b11ed6 100644 --- a/src/efl/example/page6.h +++ b/src/efl/example/page6.h @@ -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 index 0000000..9f53896 --- /dev/null +++ b/src/efl/mobile/ui_basic_controller.cpp @@ -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 index 0000000..a980e95 --- /dev/null +++ b/src/efl/mobile/ui_basic_controller.h @@ -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 */ diff --git a/src/efl/mobile/ui_basic_key_listener.cpp b/src/efl/mobile/ui_basic_key_listener.cpp index 993aca4..cff8b70 100644 --- a/src/efl/mobile/ui_basic_key_listener.cpp +++ b/src/efl/mobile/ui_basic_key_listener.cpp @@ -19,12 +19,10 @@ 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(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(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(event_info); - ui_basic_key_listener *key_handler = static_cast(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/ui_basic_key_listener.h b/src/efl/mobile/ui_basic_key_listener.h index 203ebb5..2563d55 100644 --- a/src/efl/mobile/ui_basic_key_listener.h +++ b/src/efl/mobile/ui_basic_key_listener.h @@ -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); }; } diff --git a/src/efl/mobile/ui_basic_view.cpp b/src/efl/mobile/ui_basic_view.cpp index 83886f9..f1c2c13 100644 --- a/src/efl/mobile/ui_basic_view.cpp +++ b/src/efl/mobile/ui_basic_view.cpp @@ -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(this->get_controller()))->menu(); +} diff --git a/src/efl/mobile/ui_basic_view.h b/src/efl/mobile/ui_basic_view.h index 8e37f2a..eff4044 100644 --- a/src/efl/mobile/ui_basic_view.h +++ b/src/efl/mobile/ui_basic_view.h @@ -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 index 0000000..a2fc32c --- /dev/null +++ b/src/efl/mobile/ui_basic_viewmgr.cpp @@ -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 index 0000000..f0aa8d1 --- /dev/null +++ b/src/efl/mobile/ui_basic_viewmgr.h @@ -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 +#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 */ diff --git a/src/efl/mobile/ui_viewmanager.h b/src/efl/mobile/ui_viewmanager.h index a2a23b5..6910ade 100644 --- a/src/efl/mobile/ui_viewmanager.h +++ b/src/efl/mobile/ui_viewmanager.h @@ -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" diff --git a/src/efl/ui_controller.h b/src/efl/ui_controller.h index 485b3c0..1878e64 100644 --- a/src/efl/ui_controller.h +++ b/src/efl/ui_controller.h @@ -34,6 +34,8 @@ public: virtual void pause() {} virtual void resume() {} virtual void destroy() {} + + virtual bool back() { return true; } }; } diff --git a/src/efl/ui_key_listener.cpp b/src/efl/ui_key_listener.cpp index 5b12bef..6a6144c 100644 --- a/src/efl/ui_key_listener.cpp +++ b/src/efl/ui_key_listener.cpp @@ -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(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(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(event_info); - ui_key_listener *key_handler = static_cast(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(event_info); + ui_key_listener *key_listener = static_cast(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; diff --git a/src/efl/ui_key_listener.h b/src/efl/ui_key_listener.h index 7921b57..62ee0f5 100644 --- a/src/efl/ui_key_listener.h +++ b/src/efl/ui_key_listener.h @@ -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; } }; diff --git a/src/efl/ui_view.cpp b/src/efl/ui_view.cpp index d4a4ec1..ae35ceb 100644 --- a/src/efl/ui_view.cpp +++ b/src/efl/ui_view.cpp @@ -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(this->get_controller())->back()) + { + return; + } + } + dynamic_cast(this->get_viewmgr())->pop_view(); +} diff --git a/src/efl/ui_view.h b/src/efl/ui_view.h index 09171aa..87ce588 100644 --- a/src/efl/ui_view.h +++ b/src/efl/ui_view.h @@ -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: diff --git a/src/efl/ui_viewmgr.cpp b/src/efl/ui_viewmgr.cpp index f944b96..62b163c 100644 --- a/src/efl/ui_viewmgr.cpp +++ b/src/efl/ui_viewmgr.cpp @@ -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() diff --git a/src/efl/ui_viewmgr.h b/src/efl/ui_viewmgr.h index 519b831..f546006 100644 --- a/src/efl/ui_viewmgr.h +++ b/src/efl/ui_viewmgr.h @@ -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; diff --git a/src/interface/ui_view_interface.h b/src/interface/ui_view_interface.h index ef4327f..2b3d10f 100644 --- a/src/interface/ui_view_interface.h +++ b/src/interface/ui_view_interface.h @@ -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; }