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 "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 #include "ui/events/keycodes/keyboard_code_conversion_android.h" |
14 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
15 | 16 |
16 namespace native_viewport { | 17 namespace native_viewport { |
17 namespace { | 18 namespace { |
18 | 19 |
19 ui::EventType MotionEventActionToEventType(jint action) { | 20 ui::EventType MotionEventActionToEventType(jint action) { |
20 switch (action) { | 21 switch (action) { |
21 case AMOTION_EVENT_ACTION_DOWN: | 22 case AMOTION_EVENT_ACTION_DOWN: |
22 return ui::ET_TOUCH_PRESSED; | 23 return ui::ET_TOUCH_PRESSED; |
23 case AMOTION_EVENT_ACTION_UP: | 24 case AMOTION_EVENT_ACTION_UP: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 id_generator_.GetGeneratedID(pointer_id), | 109 id_generator_.GetGeneratedID(pointer_id), |
109 base::TimeDelta::FromMilliseconds(time_ms)); | 110 base::TimeDelta::FromMilliseconds(time_ms)); |
110 // TODO(beng): handle multiple touch-points. | 111 // TODO(beng): handle multiple touch-points. |
111 delegate_->OnEvent(&event); | 112 delegate_->OnEvent(&event); |
112 if (action == ui::ET_TOUCH_RELEASED || action == ui::ET_TOUCH_CANCELLED) | 113 if (action == ui::ET_TOUCH_RELEASED || action == ui::ET_TOUCH_CANCELLED) |
113 id_generator_.ReleaseNumber(pointer_id); | 114 id_generator_.ReleaseNumber(pointer_id); |
114 | 115 |
115 return true; | 116 return true; |
116 } | 117 } |
117 | 118 |
| 119 bool PlatformViewportAndroid::KeyEvent(JNIEnv* env, |
| 120 jobject obj, |
| 121 bool pressed, |
| 122 jint key_code, |
| 123 jint unicode_character) { |
| 124 ui::KeyEvent event(pressed ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, |
| 125 ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); |
| 126 event.set_platform_keycode(key_code); |
| 127 delegate_->OnEvent(&event); |
| 128 if (pressed && unicode_character) { |
| 129 ui::KeyEvent char_event(unicode_character, |
| 130 ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); |
| 131 char_event.set_platform_keycode(key_code); |
| 132 delegate_->OnEvent(&char_event); |
| 133 } |
| 134 return true; |
| 135 } |
| 136 |
118 //////////////////////////////////////////////////////////////////////////////// | 137 //////////////////////////////////////////////////////////////////////////////// |
119 // PlatformViewportAndroid, PlatformViewport implementation: | 138 // PlatformViewportAndroid, PlatformViewport implementation: |
120 | 139 |
121 void PlatformViewportAndroid::Init(const gfx::Rect& bounds) { | 140 void PlatformViewportAndroid::Init(const gfx::Rect& bounds) { |
122 JNIEnv* env = base::android::AttachCurrentThread(); | 141 JNIEnv* env = base::android::AttachCurrentThread(); |
123 Java_PlatformViewportAndroid_createForActivity( | 142 Java_PlatformViewportAndroid_createForActivity( |
124 env, | 143 env, |
125 base::android::GetApplicationContext(), | 144 base::android::GetApplicationContext(), |
126 reinterpret_cast<jlong>(this)); | 145 reinterpret_cast<jlong>(this)); |
127 } | 146 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 //////////////////////////////////////////////////////////////////////////////// | 187 //////////////////////////////////////////////////////////////////////////////// |
169 // PlatformViewport, public: | 188 // PlatformViewport, public: |
170 | 189 |
171 // static | 190 // static |
172 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { | 191 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { |
173 return scoped_ptr<PlatformViewport>( | 192 return scoped_ptr<PlatformViewport>( |
174 new PlatformViewportAndroid(delegate)).Pass(); | 193 new PlatformViewportAndroid(delegate)).Pass(); |
175 } | 194 } |
176 | 195 |
177 } // namespace native_viewport | 196 } // namespace native_viewport |
OLD | NEW |