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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 //////////////////////////////////////////////////////////////////////////////// | 46 //////////////////////////////////////////////////////////////////////////////// |
47 // PlatformWindowAndroid, public: | 47 // PlatformWindowAndroid, public: |
48 | 48 |
49 // static | 49 // static |
50 bool PlatformWindowAndroid::Register(JNIEnv* env) { | 50 bool PlatformWindowAndroid::Register(JNIEnv* env) { |
51 return RegisterNativesImpl(env); | 51 return RegisterNativesImpl(env); |
52 } | 52 } |
53 | 53 |
| 54 // static |
| 55 void PlatformWindowAndroid::createForActivity( |
| 56 JNIEnv* env, |
| 57 jobject activity, |
| 58 jlong nativePlatformWindowAndroid, |
| 59 jlong nativeImeController) { |
| 60 Java_PlatformWindowAndroid_createForActivity( |
| 61 env, |
| 62 activity, |
| 63 nativePlatformWindowAndroid, |
| 64 nativeImeController); |
| 65 } |
| 66 |
54 PlatformWindowAndroid::PlatformWindowAndroid(PlatformWindowDelegate* delegate) | 67 PlatformWindowAndroid::PlatformWindowAndroid(PlatformWindowDelegate* delegate) |
55 : delegate_(delegate), | 68 : delegate_(delegate), |
56 window_(NULL), | 69 window_(NULL), |
57 id_generator_(0), | 70 id_generator_(0), |
58 weak_factory_(this) { | 71 weak_factory_(this) { |
59 } | 72 } |
60 | 73 |
61 PlatformWindowAndroid::~PlatformWindowAndroid() { | 74 PlatformWindowAndroid::~PlatformWindowAndroid() { |
62 if (window_) | 75 if (window_) |
63 ReleaseWindow(); | 76 ReleaseWindow(); |
64 if (!java_platform_window_android_.is_empty()) { | 77 if (!java_platform_window_android_.is_empty()) { |
65 JNIEnv* env = base::android::AttachCurrentThread(); | 78 JNIEnv* env = base::android::AttachCurrentThread(); |
66 Java_PlatformWindowAndroid_detach( | 79 Java_PlatformWindowAndroid_detach( |
67 env, java_platform_window_android_.get(env).obj()); | 80 env, java_platform_window_android_.get(env).obj()); |
68 } | 81 } |
69 } | 82 } |
70 | 83 |
71 void PlatformWindowAndroid::Destroy(JNIEnv* env, jobject obj) { | 84 void PlatformWindowAndroid::Destroy(JNIEnv* env, jobject obj) { |
72 delegate_->OnClosed(); | 85 delegate_->OnClosed(); |
73 } | 86 } |
74 | 87 |
| 88 void PlatformWindowAndroid::JavaPlatformWindowCreated( |
| 89 JNIEnv* env, jobject obj) { |
| 90 java_platform_window_android_ = JavaObjectWeakGlobalRef(env, obj); |
| 91 } |
| 92 |
75 void PlatformWindowAndroid::SurfaceCreated(JNIEnv* env, | 93 void PlatformWindowAndroid::SurfaceCreated(JNIEnv* env, |
76 jobject obj, | 94 jobject obj, |
77 jobject jsurface, | 95 jobject jsurface, |
78 float device_pixel_ratio) { | 96 float device_pixel_ratio) { |
79 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); | 97 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); |
80 // Note: This ensures that any local references used by | 98 // Note: This ensures that any local references used by |
81 // ANativeWindow_fromSurface are released immediately. This is needed as a | 99 // ANativeWindow_fromSurface are released immediately. This is needed as a |
82 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 100 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
83 { | 101 { |
84 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 102 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 163 |
146 void PlatformWindowAndroid::ReleaseWindow() { | 164 void PlatformWindowAndroid::ReleaseWindow() { |
147 ANativeWindow_release(window_); | 165 ANativeWindow_release(window_); |
148 window_ = NULL; | 166 window_ = NULL; |
149 } | 167 } |
150 | 168 |
151 //////////////////////////////////////////////////////////////////////////////// | 169 //////////////////////////////////////////////////////////////////////////////// |
152 // PlatformWindowAndroid, PlatformWindow implementation: | 170 // PlatformWindowAndroid, PlatformWindow implementation: |
153 | 171 |
154 void PlatformWindowAndroid::Show() { | 172 void PlatformWindowAndroid::Show() { |
155 if (!java_platform_window_android_.is_empty()) | 173 CHECK(!java_platform_window_android_.is_empty()); |
156 return; | |
157 JNIEnv* env = base::android::AttachCurrentThread(); | |
158 java_platform_window_android_ = JavaObjectWeakGlobalRef( | |
159 env, Java_PlatformWindowAndroid_createForActivity( | |
160 env, base::android::GetApplicationContext(), | |
161 reinterpret_cast<jlong>(this), | |
162 reinterpret_cast<jlong>(&platform_ime_controller_)).obj()); | |
163 } | 174 } |
164 | 175 |
165 void PlatformWindowAndroid::Hide() { | 176 void PlatformWindowAndroid::Hide() { |
166 // Nothing to do. View is always visible. | 177 // Nothing to do. View is always visible. |
167 } | 178 } |
168 | 179 |
169 void PlatformWindowAndroid::Close() { | 180 void PlatformWindowAndroid::Close() { |
170 delegate_->OnCloseRequest(); | 181 delegate_->OnCloseRequest(); |
171 } | 182 } |
172 | 183 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 227 |
217 void PlatformWindowAndroid::ConfineCursorToBounds(const gfx::Rect& bounds) { | 228 void PlatformWindowAndroid::ConfineCursorToBounds(const gfx::Rect& bounds) { |
218 NOTIMPLEMENTED(); | 229 NOTIMPLEMENTED(); |
219 } | 230 } |
220 | 231 |
221 PlatformImeController* PlatformWindowAndroid::GetPlatformImeController() { | 232 PlatformImeController* PlatformWindowAndroid::GetPlatformImeController() { |
222 return &platform_ime_controller_; | 233 return &platform_ime_controller_; |
223 } | 234 } |
224 | 235 |
225 } // namespace ui | 236 } // namespace ui |
OLD | NEW |