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 "mojo/services/native_viewport/android/mojo_viewport.h" | 5 #include "mojo/services/native_viewport/android/mojo_viewport.h" |
6 | 6 |
| 7 #include <android/input.h> |
7 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
| 9 |
8 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
10 #include "base/location.h" | 12 #include "base/location.h" |
11 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
12 #include "jni/MojoViewport_jni.h" | 14 #include "jni/MojoViewport_jni.h" |
13 | 15 |
14 namespace mojo { | 16 namespace mojo { |
15 namespace services { | 17 namespace services { |
16 | 18 |
| 19 ui::EventType MotionEventActionToEventType(jint action) { |
| 20 switch (action) { |
| 21 case AMOTION_EVENT_ACTION_DOWN: |
| 22 return ui::ET_TOUCH_PRESSED; |
| 23 case AMOTION_EVENT_ACTION_MOVE: |
| 24 return ui::ET_TOUCH_MOVED; |
| 25 case AMOTION_EVENT_ACTION_UP: |
| 26 return ui::ET_TOUCH_RELEASED; |
| 27 default: |
| 28 NOTREACHED(); |
| 29 } |
| 30 return ui::ET_UNKNOWN; |
| 31 } |
| 32 |
17 MojoViewportInit::MojoViewportInit() { | 33 MojoViewportInit::MojoViewportInit() { |
18 } | 34 } |
19 | 35 |
20 MojoViewportInit::~MojoViewportInit() { | 36 MojoViewportInit::~MojoViewportInit() { |
21 } | 37 } |
22 | 38 |
23 static jint Init(JNIEnv* env, jclass obj, jint jinit) { | 39 static jint Init(JNIEnv* env, jclass obj, jint jinit) { |
24 MojoViewportInit* init = reinterpret_cast<MojoViewportInit*>(jinit); | 40 MojoViewportInit* init = reinterpret_cast<MojoViewportInit*>(jinit); |
25 MojoViewport* viewport = new MojoViewport(init); | 41 MojoViewport* viewport = new MojoViewport(init); |
26 return reinterpret_cast<jint>(viewport); | 42 return reinterpret_cast<jint>(viewport); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 79 } |
64 | 80 |
65 void MojoViewport::SurfaceSetSize( | 81 void MojoViewport::SurfaceSetSize( |
66 JNIEnv* env, jobject obj, jint width, jint height) { | 82 JNIEnv* env, jobject obj, jint width, jint height) { |
67 ui_runner_->PostTask(FROM_HERE, base::Bind( | 83 ui_runner_->PostTask(FROM_HERE, base::Bind( |
68 &NativeViewportAndroid::OnResized, | 84 &NativeViewportAndroid::OnResized, |
69 native_viewport_, | 85 native_viewport_, |
70 gfx::Size(width, height))); | 86 gfx::Size(width, height))); |
71 } | 87 } |
72 | 88 |
| 89 bool MojoViewport::TouchEvent(JNIEnv* env, jobject obj, |
| 90 jint pointer_id, |
| 91 jint action, |
| 92 jfloat x, jfloat y, |
| 93 jlong time_ms) { |
| 94 ui_runner_->PostTask(FROM_HERE, base::Bind( |
| 95 &NativeViewportAndroid::OnTouchEvent, |
| 96 native_viewport_, |
| 97 pointer_id, |
| 98 MotionEventActionToEventType(action), |
| 99 x, y, |
| 100 time_ms)); |
| 101 // TODO(beng): This type needs to live on the main thread so we can respond to |
| 102 // this question truthfully. |
| 103 return true; |
| 104 } |
| 105 |
73 bool MojoViewport::Register(JNIEnv* env) { | 106 bool MojoViewport::Register(JNIEnv* env) { |
74 return RegisterNativesImpl(env); | 107 return RegisterNativesImpl(env); |
75 } | 108 } |
76 | 109 |
77 } // namespace services | 110 } // namespace services |
78 } // namespace mojo | 111 } // namespace mojo |
OLD | NEW |