| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "services/native_viewport/platform_viewport_android.h" | 5 #include "services/native_viewport/platform_viewport_android.h" |
| 6 | 6 |
| 7 #include <android/input.h> | 7 #include <android/input.h> |
| 8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
| 9 | 9 |
| 10 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 11 #include "jni/PlatformViewportAndroid_jni.h" | 11 #include "jni/PlatformViewportAndroid_jni.h" |
| 12 #include "mojo/converters/geometry/geometry_type_converters.h" | 12 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 13 #include "mojo/converters/input_events/input_events_type_converters.h" | 13 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 14 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
| 15 #include "ui/events/keycodes/keyboard_code_conversion_android.h" | 15 #include "ui/events/keycodes/keyboard_code_conversion_android.h" |
| 16 #include "ui/gfx/point.h" | 16 #include "ui/gfx/point.h" |
| 17 | 17 |
| 18 namespace native_viewport { | 18 namespace native_viewport { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 ui::EventType MotionEventActionToEventType(jint action) { | 21 mojo::EventType MotionEventActionToEventType(jint action) { |
| 22 switch (action) { | 22 switch (action) { |
| 23 case AMOTION_EVENT_ACTION_DOWN: | 23 case AMOTION_EVENT_ACTION_DOWN: |
| 24 return ui::ET_TOUCH_PRESSED; | 24 case AMOTION_EVENT_ACTION_POINTER_DOWN: |
| 25 return mojo::EVENT_TYPE_POINTER_DOWN; |
| 25 case AMOTION_EVENT_ACTION_UP: | 26 case AMOTION_EVENT_ACTION_UP: |
| 26 return ui::ET_TOUCH_RELEASED; | 27 case AMOTION_EVENT_ACTION_POINTER_UP: |
| 28 return mojo::EVENT_TYPE_POINTER_UP; |
| 27 case AMOTION_EVENT_ACTION_MOVE: | 29 case AMOTION_EVENT_ACTION_MOVE: |
| 28 return ui::ET_TOUCH_MOVED; | 30 return mojo::EVENT_TYPE_POINTER_MOVE; |
| 29 case AMOTION_EVENT_ACTION_CANCEL: | 31 case AMOTION_EVENT_ACTION_CANCEL: |
| 30 return ui::ET_TOUCH_CANCELLED; | 32 return mojo::EVENT_TYPE_POINTER_CANCEL; |
| 31 // case AMOTION_EVENT_ACTION_OUTSIDE: | 33 case AMOTION_EVENT_ACTION_OUTSIDE: |
| 32 // case AMOTION_EVENT_ACTION_POINTER_DOWN: | 34 case AMOTION_EVENT_ACTION_HOVER_MOVE: |
| 33 // case AMOTION_EVENT_ACTION_POINTER_UP: | 35 case AMOTION_EVENT_ACTION_SCROLL: |
| 34 // case AMOTION_EVENT_ACTION_HOVER_MOVE: | 36 case AMOTION_EVENT_ACTION_HOVER_ENTER: |
| 35 // case AMOTION_EVENT_ACTION_SCROLL: | 37 case AMOTION_EVENT_ACTION_HOVER_EXIT: |
| 36 // case AMOTION_EVENT_ACTION_HOVER_ENTER: | |
| 37 // case AMOTION_EVENT_ACTION_HOVER_EXIT: | |
| 38 default: | 38 default: |
| 39 NOTIMPLEMENTED() << "Unimplemented motion action: " << action; | 39 NOTIMPLEMENTED() << "Unimplemented motion action: " << action; |
| 40 } | 40 } |
| 41 return ui::ET_UNKNOWN; | 41 return mojo::EVENT_TYPE_UNKNOWN; |
| 42 } | 42 } |
| 43 | 43 |
| 44 } | 44 } // namespace |
| 45 | 45 |
| 46 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
| 47 // PlatformViewportAndroid, public: | 47 // PlatformViewportAndroid, public: |
| 48 | 48 |
| 49 // static | 49 // static |
| 50 bool PlatformViewportAndroid::Register(JNIEnv* env) { | 50 bool PlatformViewportAndroid::Register(JNIEnv* env) { |
| 51 return RegisterNativesImpl(env); | 51 return RegisterNativesImpl(env); |
| 52 } | 52 } |
| 53 | 53 |
| 54 PlatformViewportAndroid::PlatformViewportAndroid(Delegate* delegate) | 54 PlatformViewportAndroid::PlatformViewportAndroid(Delegate* delegate) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 jint height, | 93 jint height, |
| 94 jfloat density) { | 94 jfloat density) { |
| 95 metrics_ = mojo::ViewportMetrics::New(); | 95 metrics_ = mojo::ViewportMetrics::New(); |
| 96 metrics_->size = mojo::Size::New(); | 96 metrics_->size = mojo::Size::New(); |
| 97 metrics_->size->width = static_cast<int>(width); | 97 metrics_->size->width = static_cast<int>(width); |
| 98 metrics_->size->height = static_cast<int>(height); | 98 metrics_->size->height = static_cast<int>(height); |
| 99 metrics_->device_pixel_ratio = density; | 99 metrics_->device_pixel_ratio = density; |
| 100 delegate_->OnMetricsChanged(metrics_.Clone()); | 100 delegate_->OnMetricsChanged(metrics_.Clone()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool PlatformViewportAndroid::TouchEvent(JNIEnv* env, jobject obj, | 103 bool PlatformViewportAndroid::TouchEvent(JNIEnv* env, |
| 104 jobject obj, |
| 105 jlong time_ms, |
| 106 jint masked_action, |
| 104 jint pointer_id, | 107 jint pointer_id, |
| 105 jint action_and_index, | 108 jfloat x, |
| 106 jfloat x, jfloat y, | 109 jfloat y, |
| 107 jlong time_ms) { | 110 jfloat pressure, |
| 108 gfx::Point location(static_cast<int>(x), static_cast<int>(y)); | 111 jfloat touch_major, |
| 109 jint action = action_and_index & AMOTION_EVENT_ACTION_MASK; | 112 jfloat touch_minor, |
| 110 ui::TouchEvent event(MotionEventActionToEventType(action), location, | 113 jfloat orientation, |
| 111 id_generator_.GetGeneratedID(pointer_id), | 114 jfloat h_wheel, |
| 112 base::TimeDelta::FromMilliseconds(time_ms)); | 115 jfloat v_wheel) { |
| 113 // TODO(sky): handle multiple touch-points. | 116 mojo::EventPtr event(mojo::Event::New()); |
| 114 delegate_->OnEvent(mojo::Event::From(static_cast<ui::Event&>(event))); | 117 event->action = MotionEventActionToEventType(masked_action); |
| 115 if (event.type() == ui::ET_TOUCH_RELEASED || | 118 if (event->action == mojo::EVENT_TYPE_UNKNOWN) |
| 116 event.type() == ui::ET_TOUCH_CANCELLED) | 119 return false; |
| 117 id_generator_.ReleaseNumber(pointer_id); | 120 |
| 121 event->pointer_data = mojo::PointerData::New(); |
| 122 event->pointer_data->pointer_id = pointer_id; |
| 123 event->pointer_data->x = x; |
| 124 event->pointer_data->y = y; |
| 125 event->pointer_data->pressure = pressure; |
| 126 event->pointer_data->radius_major = touch_major; |
| 127 event->pointer_data->radius_minor = touch_minor; |
| 128 event->pointer_data->orientation = orientation; |
| 129 event->pointer_data->horizontal_wheel = h_wheel; |
| 130 event->pointer_data->vertical_wheel = v_wheel; |
| 131 delegate_->OnEvent(event.Pass()); |
| 118 | 132 |
| 119 return true; | 133 return true; |
| 120 } | 134 } |
| 121 | 135 |
| 122 bool PlatformViewportAndroid::KeyEvent(JNIEnv* env, | 136 bool PlatformViewportAndroid::KeyEvent(JNIEnv* env, |
| 123 jobject obj, | 137 jobject obj, |
| 124 bool pressed, | 138 bool pressed, |
| 125 jint key_code, | 139 jint key_code, |
| 126 jint unicode_character) { | 140 jint unicode_character) { |
| 127 ui::KeyEvent event(pressed ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, | 141 ui::KeyEvent event(pressed ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 //////////////////////////////////////////////////////////////////////////////// | 196 //////////////////////////////////////////////////////////////////////////////// |
| 183 // PlatformViewport, public: | 197 // PlatformViewport, public: |
| 184 | 198 |
| 185 // static | 199 // static |
| 186 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { | 200 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { |
| 187 return scoped_ptr<PlatformViewport>( | 201 return scoped_ptr<PlatformViewport>( |
| 188 new PlatformViewportAndroid(delegate)).Pass(); | 202 new PlatformViewportAndroid(delegate)).Pass(); |
| 189 } | 203 } |
| 190 | 204 |
| 191 } // namespace native_viewport | 205 } // namespace native_viewport |
| OLD | NEW |