OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ui/platform_window/android/platform_window_android.h" | 5 #include "ui/platform_window/android/platform_window_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/PlatformWindowAndroid_jni.h" | 11 #include "jni/PlatformWindowAndroid_jni.h" |
| 12 #include "ui/base/ime/input_method.h" |
12 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
13 #include "ui/events/keycodes/keyboard_code_conversion_android.h" | 14 #include "ui/events/keycodes/keyboard_code_conversion_android.h" |
14 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
15 #include "ui/platform_window/platform_window_delegate.h" | 16 #include "ui/platform_window/platform_window_delegate.h" |
16 | 17 |
17 namespace ui { | 18 namespace ui { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 ui::EventType MotionEventActionToEventType(jint action) { | 22 ui::EventType MotionEventActionToEventType(jint action) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 float device_pixel_ratio) { | 79 float device_pixel_ratio) { |
79 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); | 80 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); |
80 // Note: This ensures that any local references used by | 81 // Note: This ensures that any local references used by |
81 // ANativeWindow_fromSurface are released immediately. This is needed as a | 82 // ANativeWindow_fromSurface are released immediately. This is needed as a |
82 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 83 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
83 { | 84 { |
84 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 85 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
85 window_ = ANativeWindow_fromSurface(env, jsurface); | 86 window_ = ANativeWindow_fromSurface(env, jsurface); |
86 } | 87 } |
87 delegate_->OnAcceleratedWidgetAvailable(window_, device_pixel_ratio); | 88 delegate_->OnAcceleratedWidgetAvailable(window_, device_pixel_ratio); |
| 89 platform_ime_controller_.SetInputMethod(delegate_->GetInputMethod2()); |
88 } | 90 } |
89 | 91 |
90 void PlatformWindowAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) { | 92 void PlatformWindowAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) { |
91 DCHECK(window_); | 93 DCHECK(window_); |
92 ReleaseWindow(); | 94 ReleaseWindow(); |
93 delegate_->OnAcceleratedWidgetAvailable(gfx::kNullAcceleratedWidget, 0.f); | 95 delegate_->OnAcceleratedWidgetAvailable(gfx::kNullAcceleratedWidget, 0.f); |
94 } | 96 } |
95 | 97 |
96 void PlatformWindowAndroid::SurfaceSetSize(JNIEnv* env, | 98 void PlatformWindowAndroid::SurfaceSetSize(JNIEnv* env, |
97 jobject obj, | 99 jobject obj, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 jint key_code, | 133 jint key_code, |
132 jint unicode_character) { | 134 jint unicode_character) { |
133 ui::KeyEvent key_event(pressed ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, | 135 ui::KeyEvent key_event(pressed ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, |
134 ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); | 136 ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); |
135 key_event.set_platform_keycode(key_code); | 137 key_event.set_platform_keycode(key_code); |
136 delegate_->DispatchEvent(&key_event); | 138 delegate_->DispatchEvent(&key_event); |
137 if (pressed && unicode_character) { | 139 if (pressed && unicode_character) { |
138 ui::KeyEvent char_event(unicode_character, | 140 ui::KeyEvent char_event(unicode_character, |
139 ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); | 141 ui::KeyboardCodeFromAndroidKeyCode(key_code), 0); |
140 char_event.set_platform_keycode(key_code); | 142 char_event.set_platform_keycode(key_code); |
| 143 platform_ime_controller_.GetInputMethod()->DispatchKeyEvent(&char_event); |
141 delegate_->DispatchEvent(&char_event); | 144 delegate_->DispatchEvent(&char_event); |
142 } | 145 } |
143 return true; | 146 return true; |
144 } | 147 } |
145 | 148 |
| 149 void PlatformWindowAndroid::FocusChanged(JNIEnv* env, jobject obj, bool gained_f
ocus) { |
| 150 delegate_->OnActivationChanged(gained_focus); |
| 151 } |
| 152 |
146 void PlatformWindowAndroid::ReleaseWindow() { | 153 void PlatformWindowAndroid::ReleaseWindow() { |
147 ANativeWindow_release(window_); | 154 ANativeWindow_release(window_); |
148 window_ = NULL; | 155 window_ = NULL; |
149 } | 156 } |
150 | 157 |
151 //////////////////////////////////////////////////////////////////////////////// | 158 //////////////////////////////////////////////////////////////////////////////// |
152 // PlatformWindowAndroid, PlatformWindow implementation: | 159 // PlatformWindowAndroid, PlatformWindow implementation: |
153 | 160 |
154 void PlatformWindowAndroid::Show() { | 161 void PlatformWindowAndroid::Show() { |
155 if (!java_platform_window_android_.is_empty()) | 162 if (!java_platform_window_android_.is_empty()) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 219 |
213 void PlatformWindowAndroid::ConfineCursorToBounds(const gfx::Rect& bounds) { | 220 void PlatformWindowAndroid::ConfineCursorToBounds(const gfx::Rect& bounds) { |
214 NOTIMPLEMENTED(); | 221 NOTIMPLEMENTED(); |
215 } | 222 } |
216 | 223 |
217 PlatformImeController* PlatformWindowAndroid::GetPlatformImeController() { | 224 PlatformImeController* PlatformWindowAndroid::GetPlatformImeController() { |
218 return &platform_ime_controller_; | 225 return &platform_ime_controller_; |
219 } | 226 } |
220 | 227 |
221 } // namespace ui | 228 } // namespace ui |
OLD | NEW |