From: Sanghyup Lee Date: Mon, 6 Nov 2017 08:51:00 +0000 (+0900) Subject: [Tizen] Support HW key event X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=86bfa9bac31bd43deea6c465b997003a24a109d3;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git [Tizen] Support HW key event Send tizenhwkey custom event from HW back/More keys. And close default apps with HW back key. Change-Id: I625372d11f35fd48ff847320082ca8bdc3c0637f Signed-off-by: Sanghyup Lee --- diff --git a/atom/browser/native_window_efl.cc b/atom/browser/native_window_efl.cc index 7b76bfb..cff4769 100644 --- a/atom/browser/native_window_efl.cc +++ b/atom/browser/native_window_efl.cc @@ -14,6 +14,14 @@ #include "ui/gfx/geometry/size.h" #include "ui/gfx/image/image.h" +#if defined(OS_TIZEN) +#include + +#include "base/strings/utf_string_conversions.h" +#include "content/public/browser/navigation_controller.h" +#include "content/public/browser/render_frame_host.h" +#endif + namespace atom { namespace { @@ -21,6 +29,28 @@ namespace { const int kDefaultWindowWidthDip = 800; const int kDefaultWindowHeightDip = 600; +#if defined(OS_TIZEN) +const char* kBackKeyEventScript = + "(function(){" + "var __event = document.createEvent(\"CustomEvent\");\n" + "__event.initCustomEvent(\"tizenhwkey\", true, true, null);\n" + "__event.keyName = \"back\";\n" + "document.dispatchEvent(__event);\n" + "\n" + "for (var i=0; i < window.frames.length; i++)\n" + "{ window.frames[i].document.dispatchEvent(__event); }" + "})()"; +const char* kMenuKeyEventScript = + "(function(){" + "var __event = document.createEvent(\"CustomEvent\");\n" + "__event.initCustomEvent(\"tizenhwkey\", true, true, null);\n" + "__event.keyName = \"menu\";\n" + "document.dispatchEvent(__event);\n" + "\n" + "for (var i=0; i < window.frames.length; i++)\n" + "{ window.frames[i].document.dispatchEvent(__event); }" + "})()"; +#endif } NativeWindowEfl::NativeWindowEfl( @@ -51,6 +81,20 @@ NativeWindowEfl::NativeWindowEfl( elm_box_pack_end(box, web_view_); web_contents()->Focus(); + +#if defined(OS_TIZEN) + eext_object_event_callback_add(web_view_, EEXT_CALLBACK_BACK, + &HWBackKeyCallback, this); + eext_object_event_callback_add(web_view_, EEXT_CALLBACK_MORE, + &HWMoreKeyCallback, this); +#endif +} + +NativeWindowEfl::~NativeWindowEfl() { + eext_object_event_callback_del(web_view_, EEXT_CALLBACK_BACK, + &HWBackKeyCallback); + eext_object_event_callback_del(web_view_, EEXT_CALLBACK_MORE, + &HWBackKeyCallback); } void NativeWindowEfl::Close() { @@ -325,4 +369,28 @@ NativeWindow* NativeWindow::Create( return new NativeWindowEfl(web_contents, options, parent); } +#if defined(OS_TIZEN) +// static +void NativeWindowEfl::HWBackKeyCallback(void* data, Evas_Object*, void*) { + NativeWindow* thiz = static_cast(data); + // TODO: We need to consider to clear selection or exit fullscreen + // before send JS custom event. + content::RenderFrameHost* rfh = thiz->web_contents()->GetMainFrame(); + if (rfh) { + rfh->ExecuteJavaScriptWithUserGestureForTests( + base::UTF8ToUTF16(kBackKeyEventScript)); + } +} + +// static +void NativeWindowEfl::HWMoreKeyCallback(void* data, Evas_Object*, void*) { + NativeWindow* thiz = static_cast(data); + content::RenderFrameHost* rfh = thiz->web_contents()->GetMainFrame(); + if (rfh) { + rfh->ExecuteJavaScriptWithUserGestureForTests( + base::UTF8ToUTF16(kMenuKeyEventScript)); + } +} +#endif + } diff --git a/atom/browser/native_window_efl.h b/atom/browser/native_window_efl.h index 773fd0b..cfb2c7c 100644 --- a/atom/browser/native_window_efl.h +++ b/atom/browser/native_window_efl.h @@ -94,10 +94,15 @@ class NativeWindowEfl : public NativeWindow { // Converts between content bounds and window bounds. virtual gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) override; virtual gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) override; - ~NativeWindowEfl() override {}; + ~NativeWindowEfl() override; static void OnWindowDeleteRequest(void* data, Evas_Object*, void*); +#if defined(OS_TIZEN) + static void HWBackKeyCallback(void*, Evas_Object*, void*); + static void HWMoreKeyCallback(void*, Evas_Object*, void*); +#endif + Evas_Object* window_; Evas_Object* web_view_; diff --git a/efl/build/system.gyp b/efl/build/system.gyp index 35d3ec6..b244657 100644 --- a/efl/build/system.gyp +++ b/efl/build/system.gyp @@ -113,5 +113,22 @@ ], }, }, # icu + { + 'target_name': 'efl-extension', + 'type': 'none', + 'direct_dependent_settings': { + 'cflags': [ + '