Chromium Code Reviews| 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/MotionEvent_jni.h" | |
|
qsr
2015/03/24 08:20:22
I'm completely missing why you need this. You do n
sky
2015/03/24 13:18:21
Ya, sorry, an early version had me calling into th
| |
| 11 #include "jni/PlatformViewportAndroid_jni.h" | 12 #include "jni/PlatformViewportAndroid_jni.h" |
| 12 #include "mojo/converters/geometry/geometry_type_converters.h" | 13 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 13 #include "mojo/converters/input_events/input_events_type_converters.h" | 14 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 14 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 15 #include "ui/events/keycodes/keyboard_code_conversion_android.h" | 16 #include "ui/events/keycodes/keyboard_code_conversion_android.h" |
| 16 #include "ui/gfx/point.h" | 17 #include "ui/gfx/point.h" |
| 17 | 18 |
| 18 namespace native_viewport { | 19 namespace native_viewport { |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 ui::EventType MotionEventActionToEventType(jint action) { | 22 mojo::EventType MotionEventActionToEventType(jint action) { |
| 22 switch (action) { | 23 switch (action) { |
| 23 case AMOTION_EVENT_ACTION_DOWN: | 24 case AMOTION_EVENT_ACTION_DOWN: |
| 24 return ui::ET_TOUCH_PRESSED; | 25 case AMOTION_EVENT_ACTION_POINTER_DOWN: |
| 26 return mojo::EVENT_TYPE_POINTER_DOWN; | |
| 25 case AMOTION_EVENT_ACTION_UP: | 27 case AMOTION_EVENT_ACTION_UP: |
| 26 return ui::ET_TOUCH_RELEASED; | 28 case AMOTION_EVENT_ACTION_POINTER_UP: |
| 29 return mojo::EVENT_TYPE_POINTER_UP; | |
| 27 case AMOTION_EVENT_ACTION_MOVE: | 30 case AMOTION_EVENT_ACTION_MOVE: |
| 28 return ui::ET_TOUCH_MOVED; | 31 return mojo::EVENT_TYPE_POINTER_MOVE; |
| 29 case AMOTION_EVENT_ACTION_CANCEL: | 32 case AMOTION_EVENT_ACTION_CANCEL: |
| 30 return ui::ET_TOUCH_CANCELLED; | 33 return mojo::EVENT_TYPE_POINTER_CANCEL; |
| 31 // case AMOTION_EVENT_ACTION_OUTSIDE: | 34 case AMOTION_EVENT_ACTION_OUTSIDE: |
| 32 // case AMOTION_EVENT_ACTION_POINTER_DOWN: | 35 case AMOTION_EVENT_ACTION_HOVER_MOVE: |
| 33 // case AMOTION_EVENT_ACTION_POINTER_UP: | 36 case AMOTION_EVENT_ACTION_SCROLL: |
| 34 // case AMOTION_EVENT_ACTION_HOVER_MOVE: | 37 case AMOTION_EVENT_ACTION_HOVER_ENTER: |
| 35 // case AMOTION_EVENT_ACTION_SCROLL: | 38 case AMOTION_EVENT_ACTION_HOVER_EXIT: |
| 36 // case AMOTION_EVENT_ACTION_HOVER_ENTER: | |
| 37 // case AMOTION_EVENT_ACTION_HOVER_EXIT: | |
| 38 default: | 39 default: |
| 39 NOTIMPLEMENTED() << "Unimplemented motion action: " << action; | 40 NOTIMPLEMENTED() << "Unimplemented motion action: " << action; |
| 40 } | 41 } |
| 41 return ui::ET_UNKNOWN; | 42 return mojo::EVENT_TYPE_UNKNOWN; |
| 42 } | 43 } |
| 43 | 44 |
| 44 } | 45 } // namespace |
| 45 | 46 |
| 46 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
| 47 // PlatformViewportAndroid, public: | 48 // PlatformViewportAndroid, public: |
| 48 | 49 |
| 49 // static | 50 // static |
| 50 bool PlatformViewportAndroid::Register(JNIEnv* env) { | 51 bool PlatformViewportAndroid::Register(JNIEnv* env) { |
| 51 return RegisterNativesImpl(env); | 52 return RegisterNativesImpl(env) && JNI_MotionEvent::RegisterNativesImpl(env); |
| 52 } | 53 } |
| 53 | 54 |
| 54 PlatformViewportAndroid::PlatformViewportAndroid(Delegate* delegate) | 55 PlatformViewportAndroid::PlatformViewportAndroid(Delegate* delegate) |
| 55 : delegate_(delegate), | 56 : delegate_(delegate), |
| 56 window_(NULL), | 57 window_(NULL), |
| 57 id_generator_(0), | 58 id_generator_(0), |
| 58 weak_factory_(this) { | 59 weak_factory_(this) { |
| 59 } | 60 } |
| 60 | 61 |
| 61 PlatformViewportAndroid::~PlatformViewportAndroid() { | 62 PlatformViewportAndroid::~PlatformViewportAndroid() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 jint height, | 94 jint height, |
| 94 jfloat density) { | 95 jfloat density) { |
| 95 metrics_ = mojo::ViewportMetrics::New(); | 96 metrics_ = mojo::ViewportMetrics::New(); |
| 96 metrics_->size = mojo::Size::New(); | 97 metrics_->size = mojo::Size::New(); |
| 97 metrics_->size->width = static_cast<int>(width); | 98 metrics_->size->width = static_cast<int>(width); |
| 98 metrics_->size->height = static_cast<int>(height); | 99 metrics_->size->height = static_cast<int>(height); |
| 99 metrics_->device_pixel_ratio = density; | 100 metrics_->device_pixel_ratio = density; |
| 100 delegate_->OnMetricsChanged(metrics_.Clone()); | 101 delegate_->OnMetricsChanged(metrics_.Clone()); |
| 101 } | 102 } |
| 102 | 103 |
| 103 bool PlatformViewportAndroid::TouchEvent(JNIEnv* env, jobject obj, | 104 bool PlatformViewportAndroid::TouchEvent(JNIEnv* env, |
| 105 jobject obj, | |
| 106 jobject motion_event, | |
| 107 jlong time_ms, | |
| 108 jint masked_action, | |
| 104 jint pointer_id, | 109 jint pointer_id, |
| 105 jint action_and_index, | 110 jfloat x, |
| 106 jfloat x, jfloat y, | 111 jfloat y, |
| 107 jlong time_ms) { | 112 jfloat pressure, |
| 108 gfx::Point location(static_cast<int>(x), static_cast<int>(y)); | 113 jfloat touch_major, |
| 109 jint action = action_and_index & AMOTION_EVENT_ACTION_MASK; | 114 jfloat touch_minor, |
| 110 ui::TouchEvent event(MotionEventActionToEventType(action), location, | 115 jfloat orientation, |
| 111 id_generator_.GetGeneratedID(pointer_id), | 116 jfloat h_wheel, |
| 112 base::TimeDelta::FromMilliseconds(time_ms)); | 117 jfloat v_wheel) { |
| 113 // TODO(sky): handle multiple touch-points. | 118 mojo::EventPtr event(mojo::Event::New()); |
| 114 delegate_->OnEvent(mojo::Event::From(static_cast<ui::Event&>(event))); | 119 event->action = MotionEventActionToEventType(masked_action); |
| 115 if (event.type() == ui::ET_TOUCH_RELEASED || | 120 if (event->action == mojo::EVENT_TYPE_UNKNOWN) |
| 116 event.type() == ui::ET_TOUCH_CANCELLED) | 121 return false; |
| 117 id_generator_.ReleaseNumber(pointer_id); | 122 |
| 123 event->pointer_data = mojo::PointerData::New(); | |
| 124 event->pointer_data->pointer_id = pointer_id; | |
| 125 event->pointer_data->x = x; | |
| 126 event->pointer_data->y = y; | |
| 127 event->pointer_data->pressure = pressure; | |
| 128 event->pointer_data->radius_major = touch_major; | |
| 129 event->pointer_data->radius_minor = touch_minor; | |
| 130 event->pointer_data->orientation = orientation; | |
| 131 event->pointer_data->horizontal_wheel = h_wheel; | |
| 132 event->pointer_data->vertical_wheel = v_wheel; | |
| 133 delegate_->OnEvent(event.Pass()); | |
| 118 | 134 |
| 119 return true; | 135 return true; |
| 120 } | 136 } |
| 121 | 137 |
| 122 bool PlatformViewportAndroid::KeyEvent(JNIEnv* env, | 138 bool PlatformViewportAndroid::KeyEvent(JNIEnv* env, |
| 123 jobject obj, | 139 jobject obj, |
| 124 bool pressed, | 140 bool pressed, |
| 125 jint key_code, | 141 jint key_code, |
| 126 jint unicode_character) { | 142 jint unicode_character) { |
| 127 ui::KeyEvent event(pressed ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, | 143 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 //////////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////////// |
| 183 // PlatformViewport, public: | 199 // PlatformViewport, public: |
| 184 | 200 |
| 185 // static | 201 // static |
| 186 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { | 202 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { |
| 187 return scoped_ptr<PlatformViewport>( | 203 return scoped_ptr<PlatformViewport>( |
| 188 new PlatformViewportAndroid(delegate)).Pass(); | 204 new PlatformViewportAndroid(delegate)).Pass(); |
| 189 } | 205 } |
| 190 | 206 |
| 191 } // namespace native_viewport | 207 } // namespace native_viewport |
| OLD | NEW |