Implement rotary event
authorJongHeon Choi <j-h.choi@samsung.com>
Wed, 30 Mar 2016 07:21:11 +0000 (16:21 +0900)
committerJongHeon Choi <j-h.choi@samsung.com>
Tue, 12 Apr 2016 06:18:02 +0000 (15:18 +0900)
packaging/crosswalk-tizen.spec
runtime/browser/web_application.cc [changed mode: 0755->0644]
runtime/browser/web_application.h
runtime/browser/web_view.cc [changed mode: 0755->0644]
runtime/browser/web_view.h [changed mode: 0755->0644]
runtime/browser/web_view_impl.cc
runtime/browser/web_view_impl.h
runtime/runtime.gyp

index c3f64c0a2be0d261597ef8a03a5552f450644a65..03491d56bb51c015d0d2e85c37a8aa427b14c9b3 100755 (executable)
@@ -56,7 +56,8 @@ cp %{SOURCE1001} .
 
 %build
 export GYP_GENERATORS='ninja'
-GYP_OPTIONS="--depth=."
+GYP_OPTIONS="--depth=.
+-Dprofile=%{profile}"
 
 # BuildType: Debug / Release
 %if 0%{?tizen_build_devel_mode}
old mode 100755 (executable)
new mode 100644 (file)
index e9b211d..5bb635b
@@ -654,6 +654,30 @@ void WebApplication::OnLowMemory() {
   ewk_context_notify_low_memory(ewk_context_);
 }
 
+#ifdef PROFILE_WEARABLE
+void WebApplication::OnRotaryEvent(WebView* /*view*/,
+                                   RotaryEventType type) {
+  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 = \""
+    << (type == RotaryEventType::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());
+}
+#endif  // PROFILE_WEARABLE
+
 bool WebApplication::OnContextMenuDisabled(WebView* /*view*/) {
   return !(app_data_->setting_info() != NULL
                ? app_data_->setting_info()->context_menu_enabled()
index 36caeaac8aa00ea250547dac433051087992953e..0eea5becd6470b710985ac233d2dcbb261f30770 100644 (file)
@@ -89,6 +89,10 @@ class WebApplication : public WebView::EventListener {
   virtual void OnUsermediaPermissionRequest(
       WebView* view, const std::string& url,
       std::function<void(bool)> result_handler);
+#ifdef PROFILE_WEARABLE
+  virtual void OnRotaryEvent(WebView* view,
+      RotaryEventType type);
+#endif  // PROFILE_WEARABLE
 
  private:
   bool Initialize();
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 52ae9ef..00ba003
@@ -29,6 +29,11 @@ class Ewk_Context;
 namespace runtime {
 class WebViewImpl;
 
+enum class RotaryEventType {
+  CLOCKWISE,  // Rotary is rotated clockwise direction
+  COUNTER_CLOCKWISE  // Rotary is rotated counter clockwise direction
+};
+
 class WebView {
  public:
   class EventListener {
@@ -87,6 +92,11 @@ class WebView {
         WebView* /*view*/,
         const std::string& /*url*/,
         std::function<void(bool)> /*result_handler*/) {}
+#ifdef PROFILE_WEARABLE
+    virtual void OnRotaryEvent(
+        WebView* /*view*/,
+        RotaryEventType /*type*/) {}
+#endif  // PROFILE_WEARABLE
   };
 
   WebView(NativeWindow* window, Ewk_Context* context);
index 0914733c4b1f16a0a549b57e2ac56ce95bedc84c..6c7629f3cd24656f3cd4b4d7427e2f8d100983af 100644 (file)
@@ -199,6 +199,9 @@ void WebViewImpl::Initialize() {
   InitCertificateAllowCallback();
   InitPopupWaitCallback();
   InitUsermediaCallback();
+#ifdef PROFILE_WEARABLE
+  InitRotaryEventCallback();
+#endif  // PROFILE_WEARABLE
 
   Ewk_Settings* settings = ewk_view_settings_get(ewk_view_);
   ewk_settings_scripts_can_open_windows_set(settings, EINA_TRUE);
@@ -825,6 +828,30 @@ void WebViewImpl::InitUsermediaCallback() {
   ewk_view_user_media_permission_callback_set(ewk_view_, callback, this);
 }
 
+#ifdef PROFILE_WEARABLE
+void WebViewImpl::InitRotaryEventCallback() {
+  auto rotary_callback = [](void* user_data,
+                         Evas_Object*,
+                         Eext_Rotary_Event_Info* event_info) -> Eina_Bool {
+    WebViewImpl* self = static_cast<WebViewImpl*>(user_data);
+    Eext_Rotary_Event_Info* rotary = event_info;
+
+    RotaryEventType type;
+    if (rotary->direction == EEXT_ROTARY_DIRECTION_CLOCKWISE)
+      type = RotaryEventType::CLOCKWISE;
+    else
+      type = RotaryEventType::COUNTER_CLOCKWISE;
+
+    self->listener_->OnRotaryEvent(self->view_, type);
+    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);
+}
+#endif  // PROFILE_WEARABLE
+
 std::string WebViewImpl::GetUrl() {
   return std::string(ewk_view_url_get(ewk_view_));
 }
index 8b93f56472c87d366053e7d1f42c5474db348114..c3d0551f7c9a786eb04ce6467a6cb57a1733247c 100644 (file)
@@ -75,6 +75,9 @@ class WebViewImpl {
   void InitCertificateAllowCallback();
   void InitPopupWaitCallback();
   void InitUsermediaCallback();
+#ifdef PROFILE_WEARABLE
+  void InitRotaryEventCallback();
+#endif  // PROFILE_WEARABLE
 
   NativeWindow* window_;
   Ewk_Context* context_;
index 77e8d7c314b0c99d73d04c9cd689dc1700169831..12606e97b8351646fb615dcb012d3e863e6f4299 100755 (executable)
           'launchpad',
         ],
       },
+      'conditions': [
+        ['profile == "wearable"', {
+          'defines': ['PROFILE_WEARABLE'],
+        }],
+      ],
     }, # end of target 'xwalk_runtime'
     {
       'target_name': 'xwalk_injected_bundle',