From d6f0dd850546bed2ae7d1f04dd80c7f94c456f2d Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Wed, 30 Mar 2016 16:21:11 +0900 Subject: [PATCH] Implement rotary event --- packaging/crosswalk-tizen.spec | 3 ++- runtime/browser/web_application.cc | 24 ++++++++++++++++++++++++ runtime/browser/web_application.h | 4 ++++ runtime/browser/web_view.cc | 0 runtime/browser/web_view.h | 10 ++++++++++ runtime/browser/web_view_impl.cc | 27 +++++++++++++++++++++++++++ runtime/browser/web_view_impl.h | 3 +++ runtime/runtime.gyp | 5 +++++ 8 files changed, 75 insertions(+), 1 deletion(-) mode change 100755 => 100644 runtime/browser/web_application.cc mode change 100755 => 100644 runtime/browser/web_view.cc mode change 100755 => 100644 runtime/browser/web_view.h diff --git a/packaging/crosswalk-tizen.spec b/packaging/crosswalk-tizen.spec index c3f64c0..03491d5 100755 --- a/packaging/crosswalk-tizen.spec +++ b/packaging/crosswalk-tizen.spec @@ -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} diff --git a/runtime/browser/web_application.cc b/runtime/browser/web_application.cc old mode 100755 new mode 100644 index e9b211d..5bb635b --- a/runtime/browser/web_application.cc +++ b/runtime/browser/web_application.cc @@ -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() diff --git a/runtime/browser/web_application.h b/runtime/browser/web_application.h index 36caeaa..0eea5be 100644 --- a/runtime/browser/web_application.h +++ b/runtime/browser/web_application.h @@ -89,6 +89,10 @@ class WebApplication : public WebView::EventListener { virtual void OnUsermediaPermissionRequest( WebView* view, const std::string& url, std::function result_handler); +#ifdef PROFILE_WEARABLE + virtual void OnRotaryEvent(WebView* view, + RotaryEventType type); +#endif // PROFILE_WEARABLE private: bool Initialize(); diff --git a/runtime/browser/web_view.cc b/runtime/browser/web_view.cc old mode 100755 new mode 100644 diff --git a/runtime/browser/web_view.h b/runtime/browser/web_view.h old mode 100755 new mode 100644 index 52ae9ef..00ba003 --- a/runtime/browser/web_view.h +++ b/runtime/browser/web_view.h @@ -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 /*result_handler*/) {} +#ifdef PROFILE_WEARABLE + virtual void OnRotaryEvent( + WebView* /*view*/, + RotaryEventType /*type*/) {} +#endif // PROFILE_WEARABLE }; WebView(NativeWindow* window, Ewk_Context* context); diff --git a/runtime/browser/web_view_impl.cc b/runtime/browser/web_view_impl.cc index 0914733..6c7629f 100644 --- a/runtime/browser/web_view_impl.cc +++ b/runtime/browser/web_view_impl.cc @@ -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(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_)); } diff --git a/runtime/browser/web_view_impl.h b/runtime/browser/web_view_impl.h index 8b93f56..c3d0551 100644 --- a/runtime/browser/web_view_impl.h +++ b/runtime/browser/web_view_impl.h @@ -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_; diff --git a/runtime/runtime.gyp b/runtime/runtime.gyp index 77e8d7c..12606e9 100755 --- a/runtime/runtime.gyp +++ b/runtime/runtime.gyp @@ -56,6 +56,11 @@ 'launchpad', ], }, + 'conditions': [ + ['profile == "wearable"', { + 'defines': ['PROFILE_WEARABLE'], + }], + ], }, # end of target 'xwalk_runtime' { 'target_name': 'xwalk_injected_bundle', -- 2.7.4