Implement rotary event 24/64124/1 accepted/tizen/common/20160414.143643 accepted/tizen/wearable/20160330.102350 submit/tizen_common/20160413.090423 submit/tizen_wearable/20160330.072955
authorJongHeon Choi <j-h.choi@samsung.com>
Wed, 30 Mar 2016 07:18:57 +0000 (16:18 +0900)
committerJongHeon Choi <j-h.choi@samsung.com>
Wed, 30 Mar 2016 07:19:28 +0000 (16:19 +0900)
Change-Id: I1ff85a6bf6397773ee0711778a37241a87bb0ad4

runtime/browser/web_application.cc
runtime/browser/web_application.h
runtime/browser/web_view.cc
runtime/browser/web_view.h
runtime/browser/web_view_impl.cc
runtime/browser/web_view_impl.h

index e9b211d4016603a824315239bddf223e99179323..a295efdd60d565cc1334c65cbdc86626b389cd74 100755 (executable)
@@ -25,6 +25,7 @@
 #include <memory>
 #include <sstream>
 #include <vector>
+#include <efl_extension.h>
 
 #include "common/application_data.h"
 #include "common/app_db.h"
@@ -654,6 +655,28 @@ void WebApplication::OnLowMemory() {
   ewk_context_notify_low_memory(ewk_context_);
 }
 
+void WebApplication::OnRotaryEvent(WebView* /*view*/,
+                                   Eext_Rotary_Event_Info* info) {
+  LOGGER(DEBUG) << "OnRotaryEvent";
+  std::stringstream script;
+  script
+    << "(function(){"
+    << "var __event = document.createEvent(\"CustomEvent\");\n"
+    << "var __detail = {};\n"
+    << "__event.initCustomEvent(\"rotarydetent\", true, true, __detail);\n"
+    << "__event.detail.direction = \""
+    << (info->direction == EEXT_ROTARY_DIRECTION_CLOCKWISE ? "CW" : "CCW")
+    << "\";\n"
+    << "document.dispatchEvent(__event);\n"
+    << "\n"
+    << "for (var i=0; i < window.frames.length; i++)\n"
+    << "{ window.frames[i].document.dispatchEvent(__event); }"
+    << "})()";
+  std::string kRotaryEventScript = script.str();
+  if (view_stack_.size() > 0 && view_stack_.front() != NULL)
+    view_stack_.front()->EvalJavascript(kRotaryEventScript.c_str());
+}
+
 bool WebApplication::OnContextMenuDisabled(WebView* /*view*/) {
   return !(app_data_->setting_info() != NULL
                ? app_data_->setting_info()->context_menu_enabled()
index 36caeaac8aa00ea250547dac433051087992953e..b640ffd4f5a98bf7f892778adc2e9fc57beb2452 100644 (file)
@@ -21,6 +21,7 @@
 #include <list>
 #include <memory>
 #include <string>
+#include <efl_extension.h>
 
 #include "runtime/browser/web_view.h"
 
@@ -89,6 +90,8 @@ class WebApplication : public WebView::EventListener {
   virtual void OnUsermediaPermissionRequest(
       WebView* view, const std::string& url,
       std::function<void(bool)> result_handler);
+  virtual void OnRotaryEvent(WebView* view,
+      Eext_Rotary_Event_Info* info);
 
  private:
   bool Initialize();
index 7fa79d59b2b989642f94f3e31af04e6baf34ed63..8564ac30790d411ba167372c7fb4d64b940038bc 100755 (executable)
@@ -19,6 +19,7 @@
 #include <ewk_chromium.h>
 #include <functional>
 #include <sstream>
+#include <efl_extension.h>
 
 #include "runtime/browser/native_window.h"
 #include "runtime/browser/web_view_impl.h"
index 52ae9efe5a024af46a1e69784f1cdd4ed9ffbf9a..5020138aba903d151e0166d088a555cb357f0652 100755 (executable)
@@ -21,6 +21,7 @@
 #include <ewk_chromium.h>
 #include <functional>
 #include <string>
+#include <efl_extension.h>
 
 #include "runtime/browser/native_window.h"
 
@@ -87,6 +88,9 @@ class WebView {
         WebView* /*view*/,
         const std::string& /*url*/,
         std::function<void(bool)> /*result_handler*/) {}
+    virtual void OnRotaryEvent(
+        WebView* /*view*/,
+        Eext_Rotary_Event_Info* info) {}
   };
 
   WebView(NativeWindow* window, Ewk_Context* context);
index 0914733c4b1f16a0a549b57e2ac56ce95bedc84c..7e905a6cff0ba1b6cc3c3d90e0822d7246a2b4b2 100644 (file)
@@ -199,6 +199,7 @@ void WebViewImpl::Initialize() {
   InitCertificateAllowCallback();
   InitPopupWaitCallback();
   InitUsermediaCallback();
+  InitRotaryEventCallback();
 
   Ewk_Settings* settings = ewk_view_settings_get(ewk_view_);
   ewk_settings_scripts_can_open_windows_set(settings, EINA_TRUE);
@@ -825,6 +826,21 @@ void WebViewImpl::InitUsermediaCallback() {
   ewk_view_user_media_permission_callback_set(ewk_view_, callback, this);
 }
 
+void WebViewImpl::InitRotaryEventCallback() {
+  auto rotary_callback = [](void* user_data,
+                         Evas_Object* /*obj*/,
+                         Eext_Rotary_Event_Info* event_info) -> Eina_Bool {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+    Eext_Rotary_Event_Info* rotary = event_info;
+    self->listener_->OnRotaryEvent(self->view_, rotary);
+    return EINA_TRUE;
+  };
+
+  // add callback to handle rotary event
+  eext_rotary_object_event_callback_add(ewk_view_, rotary_callback, this);
+  eext_rotary_object_event_activated_set(ewk_view_, EINA_TRUE);
+}
+
 std::string WebViewImpl::GetUrl() {
   return std::string(ewk_view_url_get(ewk_view_));
 }
index 8b93f56472c87d366053e7d1f42c5474db348114..c4c0d0dafcacc510c909dbd12c16840ff80e6ec9 100644 (file)
@@ -75,6 +75,7 @@ class WebViewImpl {
   void InitCertificateAllowCallback();
   void InitPopupWaitCallback();
   void InitUsermediaCallback();
+  void InitRotaryEventCallback();
 
   NativeWindow* window_;
   Ewk_Context* context_;