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 "ui/events/event.h" | 14 #include "ui/events/event.h" |
14 #include "ui/events/keycodes/keyboard_code_conversion_android.h" | 15 #include "ui/events/keycodes/keyboard_code_conversion_android.h" |
15 #include "ui/gfx/point.h" | 16 #include "ui/gfx/point.h" |
16 | 17 |
17 namespace native_viewport { | 18 namespace native_viewport { |
18 namespace { | 19 namespace { |
19 | 20 |
20 ui::EventType MotionEventActionToEventType(jint action) { | 21 ui::EventType MotionEventActionToEventType(jint action) { |
21 switch (action) { | 22 switch (action) { |
22 case AMOTION_EVENT_ACTION_DOWN: | 23 case AMOTION_EVENT_ACTION_DOWN: |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 bool PlatformViewportAndroid::TouchEvent(JNIEnv* env, jobject obj, | 103 bool PlatformViewportAndroid::TouchEvent(JNIEnv* env, jobject obj, |
103 jint pointer_id, | 104 jint pointer_id, |
104 jint action_and_index, | 105 jint action_and_index, |
105 jfloat x, jfloat y, | 106 jfloat x, jfloat y, |
106 jlong time_ms) { | 107 jlong time_ms) { |
107 gfx::Point location(static_cast<int>(x), static_cast<int>(y)); | 108 gfx::Point location(static_cast<int>(x), static_cast<int>(y)); |
108 jint action = action_and_index & AMOTION_EVENT_ACTION_MASK; | 109 jint action = action_and_index & AMOTION_EVENT_ACTION_MASK; |
109 ui::TouchEvent event(MotionEventActionToEventType(action), location, | 110 ui::TouchEvent event(MotionEventActionToEventType(action), location, |
110 id_generator_.GetGeneratedID(pointer_id), | 111 id_generator_.GetGeneratedID(pointer_id), |
111 base::TimeDelta::FromMilliseconds(time_ms)); | 112 base::TimeDelta::FromMilliseconds(time_ms)); |
112 // TODO(beng): handle multiple touch-points. | 113 // TODO(sky): handle multiple touch-points. |
113 delegate_->OnEvent(&event); | 114 delegate_->OnEvent(mojo::Event::From(static_cast<ui::Event&>(event))); |
114 if (event.type() == ui::ET_TOUCH_RELEASED || | 115 if (event.type() == ui::ET_TOUCH_RELEASED || |
115 event.type() == ui::ET_TOUCH_CANCELLED) | 116 event.type() == ui::ET_TOUCH_CANCELLED) |
116 id_generator_.ReleaseNumber(pointer_id); | 117 id_generator_.ReleaseNumber(pointer_id); |
117 | 118 |
118 return true; | 119 return true; |
119 } | 120 } |
120 | 121 |
121 bool PlatformViewportAndroid::KeyEvent(JNIEnv* env, | 122 bool PlatformViewportAndroid::KeyEvent(JNIEnv* env, |
122 jobject obj, | 123 jobject obj, |
123 bool pressed, | 124 bool pressed, |
124 jint key_code, | 125 jint key_code, |
125 jint unicode_character) { | 126 jint unicode_character) { |
126 ui::KeyEvent event(pressed ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, | 127 ui::KeyEvent event(pressed ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, |
127 ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); | 128 ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); |
128 event.set_platform_keycode(key_code); | 129 event.set_platform_keycode(key_code); |
129 delegate_->OnEvent(&event); | 130 delegate_->OnEvent(mojo::Event::From(event)); |
130 if (pressed && unicode_character) { | 131 if (pressed && unicode_character) { |
131 ui::KeyEvent char_event(unicode_character, | 132 ui::KeyEvent char_event(unicode_character, |
132 ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); | 133 ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); |
133 char_event.set_platform_keycode(key_code); | 134 char_event.set_platform_keycode(key_code); |
134 delegate_->OnEvent(&char_event); | 135 delegate_->OnEvent(mojo::Event::From(char_event)); |
135 } | 136 } |
136 return true; | 137 return true; |
137 } | 138 } |
138 | 139 |
139 //////////////////////////////////////////////////////////////////////////////// | 140 //////////////////////////////////////////////////////////////////////////////// |
140 // PlatformViewportAndroid, PlatformViewport implementation: | 141 // PlatformViewportAndroid, PlatformViewport implementation: |
141 | 142 |
142 void PlatformViewportAndroid::Init(const gfx::Rect& bounds) { | 143 void PlatformViewportAndroid::Init(const gfx::Rect& bounds) { |
143 JNIEnv* env = base::android::AttachCurrentThread(); | 144 JNIEnv* env = base::android::AttachCurrentThread(); |
144 Java_PlatformViewportAndroid_createForActivity( | 145 Java_PlatformViewportAndroid_createForActivity( |
(...skipping 18 matching lines...) Expand all Loading... |
163 } | 164 } |
164 | 165 |
165 gfx::Size PlatformViewportAndroid::GetSize() { | 166 gfx::Size PlatformViewportAndroid::GetSize() { |
166 return metrics_->size.To<gfx::Size>(); | 167 return metrics_->size.To<gfx::Size>(); |
167 } | 168 } |
168 | 169 |
169 void PlatformViewportAndroid::SetBounds(const gfx::Rect& bounds) { | 170 void PlatformViewportAndroid::SetBounds(const gfx::Rect& bounds) { |
170 NOTIMPLEMENTED(); | 171 NOTIMPLEMENTED(); |
171 } | 172 } |
172 | 173 |
173 void PlatformViewportAndroid::SetCapture() { | |
174 } | |
175 | |
176 void PlatformViewportAndroid::ReleaseCapture() { | |
177 } | |
178 | |
179 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
180 // PlatformViewportAndroid, private: | 175 // PlatformViewportAndroid, private: |
181 | 176 |
182 void PlatformViewportAndroid::ReleaseWindow() { | 177 void PlatformViewportAndroid::ReleaseWindow() { |
183 ANativeWindow_release(window_); | 178 ANativeWindow_release(window_); |
184 window_ = NULL; | 179 window_ = NULL; |
185 } | 180 } |
186 | 181 |
187 //////////////////////////////////////////////////////////////////////////////// | 182 //////////////////////////////////////////////////////////////////////////////// |
188 // PlatformViewport, public: | 183 // PlatformViewport, public: |
189 | 184 |
190 // static | 185 // static |
191 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { | 186 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { |
192 return scoped_ptr<PlatformViewport>( | 187 return scoped_ptr<PlatformViewport>( |
193 new PlatformViewportAndroid(delegate)).Pass(); | 188 new PlatformViewportAndroid(delegate)).Pass(); |
194 } | 189 } |
195 | 190 |
196 } // namespace native_viewport | 191 } // namespace native_viewport |
OLD | NEW |