[Tizen] Support HW key event 01/159001/5
authorSanghyup Lee <sh53.lee@samsung.com>
Mon, 6 Nov 2017 08:51:00 +0000 (17:51 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Thu, 9 Nov 2017 00:46:06 +0000 (09:46 +0900)
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 <sh53.lee@samsung.com>
atom/browser/native_window_efl.cc
atom/browser/native_window_efl.h
efl/build/system.gyp
electron.gyp
packaging/electron-efl.spec
wrt/wrt_support/apps_repo/extensions_settings/src/was_key_event_handler.js
wrt/wrt_support/apps_repo/installer/assets/js/was_key_event_handler.js
wrt/wrt_support/apps_repo/webgl/assets/js/was_key_event_handler.js
wrt/wrt_support/extensions_settings/src/was_key_event_handler.js
wrt/wrt_support/sample/installer/assets/js/was_key_event_handler.js
wrt/wrt_support/sample/launcher/assets/js/was_key_event_handler.js

index 7b76bfb..cff4769 100644 (file)
 #include "ui/gfx/geometry/size.h"
 #include "ui/gfx/image/image.h"
 
+#if defined(OS_TIZEN)
+#include <efl_extension.h>
+
+#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<NativeWindow*>(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<NativeWindow*>(data);
+  content::RenderFrameHost* rfh = thiz->web_contents()->GetMainFrame();
+  if (rfh) {
+    rfh->ExecuteJavaScriptWithUserGestureForTests(
+        base::UTF8ToUTF16(kMenuKeyEventScript));
+  }
+}
+#endif
+
 }
index 773fd0b..cfb2c7c 100644 (file)
@@ -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_;
 
index 35d3ec6..b244657 100644 (file)
         ],
       },
     }, # icu
+    {
+      'target_name': 'efl-extension',
+      'type': 'none',
+      'direct_dependent_settings': {
+        'cflags': [
+          '<!@(<(pkg-config) --cflags efl-extension)',
+        ],
+      },
+      'link_settings': {
+        'ldflags': [
+          '<!@(<(pkg-config) --libs-only-L --libs-only-other efl-extension)',
+        ],
+        'libraries': [
+          '<!@(<(pkg-config) --libs-only-l efl-extension)',
+        ],
+      },
+    }, # efl-extension
   ],
 }
index 9829911..4e52801 100644 (file)
             ['is_tizen==1', {
               'dependencies': [
                 '<(DEPTH)/efl/build/system.gyp:elementary',
+                '<(DEPTH)/efl/build/system.gyp:efl-extension',
                 '<(DEPTH)/efl/build/system.gyp:evas',
                 '<(DEPTH)/efl/build/system.gyp:icu',
                 'electron_shell_copy',
index 67048f0..4643729 100755 (executable)
@@ -19,6 +19,7 @@ BuildRequires: python-accel-aarch64-cross-aarch64
 BuildRequires: pkgconfig(chromium-efl)
 BuildRequires: pkgconfig(dbus-glib-1)
 BuildRequires: pkgconfig(ecore-evas)
+BuildRequires: pkgconfig(efl-extension)
 BuildRequires: pkgconfig(elementary)
 BuildRequires: pkgconfig(evas)
 BuildRequires: pkgconfig(expat)
index 48c127f..db97d3e 100644 (file)
             launcher.close();
         }
     })
+    window.addEventListener('tizenhwkey', function(e) {
+        if (e.keyName === "back") {
+            e.preventDefault();
+            e.stopPropagation();
+            var launcher = require('electron').remote.getCurrentWindow();
+            launcher.close();
+        }
+    })
 })()
\ No newline at end of file
index 48c127f..db97d3e 100644 (file)
             launcher.close();
         }
     })
+    window.addEventListener('tizenhwkey', function(e) {
+        if (e.keyName === "back") {
+            e.preventDefault();
+            e.stopPropagation();
+            var launcher = require('electron').remote.getCurrentWindow();
+            launcher.close();
+        }
+    })
 })()
\ No newline at end of file
index 83d5d6c..352521a 100644 (file)
             launcher.reload();
         }
     })
+    window.addEventListener('tizenhwkey', function(e) {
+        if (e.keyName === "back") {
+            e.preventDefault();
+            e.stopPropagation();
+            var launcher = require('electron').remote.getCurrentWindow();
+            launcher.close();
+        }
+    })
 })()
\ No newline at end of file
index 47bbf1d..d506863 100644 (file)
             launcher.close();
         }
     })
+    window.addEventListener('tizenhwkey', function(e) {
+        if (e.keyName === "back") {
+            e.preventDefault();
+            e.stopPropagation();
+            var launcher = require('electron').remote.getCurrentWindow();
+            launcher.close();
+        }
+    })
 })()
index 47bbf1d..d506863 100644 (file)
             launcher.close();
         }
     })
+    window.addEventListener('tizenhwkey', function(e) {
+        if (e.keyName === "back") {
+            e.preventDefault();
+            e.stopPropagation();
+            var launcher = require('electron').remote.getCurrentWindow();
+            launcher.close();
+        }
+    })
 })()
index 80f45d6..e7a2464 100644 (file)
             launcher.reload();
         }
     })
+    window.addEventListener('tizenhwkey', function(e) {
+        if (e.keyName === "back") {
+            e.preventDefault();
+            e.stopPropagation();
+            var launcher = require('electron').remote.getCurrentWindow();
+            launcher.close();
+        }
+    })
 })()