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 PlatformWindowAndroid* PlatformWindowAndroid::From( | |
56 PlatformWindow* platform_window) { | |
57 return static_cast<PlatformWindowAndroid*>(platform_window); | |
58 } | |
59 | |
54 PlatformWindowAndroid::PlatformWindowAndroid(PlatformWindowDelegate* delegate) | 60 PlatformWindowAndroid::PlatformWindowAndroid(PlatformWindowDelegate* delegate) |
55 : delegate_(delegate), | 61 : delegate_(delegate), |
56 window_(NULL), | 62 window_(NULL), |
57 id_generator_(0), | 63 id_generator_(0), |
58 weak_factory_(this) { | 64 weak_factory_(this) { |
59 } | 65 } |
60 | 66 |
61 PlatformWindowAndroid::~PlatformWindowAndroid() { | 67 PlatformWindowAndroid::~PlatformWindowAndroid() { |
62 if (window_) | 68 if (window_) |
63 ReleaseWindow(); | 69 ReleaseWindow(); |
64 if (!java_platform_window_android_.is_empty()) { | 70 if (!java_platform_window_android_.is_empty()) { |
65 JNIEnv* env = base::android::AttachCurrentThread(); | 71 JNIEnv* env = base::android::AttachCurrentThread(); |
66 Java_PlatformWindowAndroid_detach( | 72 Java_PlatformWindowAndroid_detach( |
67 env, java_platform_window_android_.get(env).obj()); | 73 env, java_platform_window_android_.get(env).obj()); |
68 } | 74 } |
69 } | 75 } |
70 | 76 |
77 void PlatformWindowAndroid::AttachToActivity(jobject activity) { | |
78 JNIEnv* env = base::android::AttachCurrentThread(); | |
sadrul
2015/12/01 21:29:34
Should this DCHECK(!IsAttachedToActivity())? Or is
mfomitchev
2015/12/01 21:50:50
I'll add the DCHECK for now. If we need to change
| |
79 base::android::ScopedJavaLocalRef<jobject> jpwa = | |
80 Java_PlatformWindowAndroid_createForActivity( | |
81 env, | |
82 activity, | |
83 reinterpret_cast<jlong>(this), | |
84 reinterpret_cast<jlong>(&platform_ime_controller_)); | |
85 java_platform_window_android_ = JavaObjectWeakGlobalRef(env, jpwa.obj()); | |
86 } | |
87 | |
88 bool PlatformWindowAndroid::IsAttachedToActivity() { | |
89 return !java_platform_window_android_.is_empty(); | |
90 } | |
91 | |
71 void PlatformWindowAndroid::Destroy(JNIEnv* env, jobject obj) { | 92 void PlatformWindowAndroid::Destroy(JNIEnv* env, jobject obj) { |
72 delegate_->OnClosed(); | 93 delegate_->OnClosed(); |
73 } | 94 } |
74 | 95 |
75 void PlatformWindowAndroid::SurfaceCreated(JNIEnv* env, | 96 void PlatformWindowAndroid::SurfaceCreated(JNIEnv* env, |
76 jobject obj, | 97 jobject obj, |
77 jobject jsurface, | 98 jobject jsurface, |
78 float device_pixel_ratio) { | 99 float device_pixel_ratio) { |
79 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); | 100 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); |
80 // Note: This ensures that any local references used by | 101 // Note: This ensures that any local references used by |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 | 166 |
146 void PlatformWindowAndroid::ReleaseWindow() { | 167 void PlatformWindowAndroid::ReleaseWindow() { |
147 ANativeWindow_release(window_); | 168 ANativeWindow_release(window_); |
148 window_ = NULL; | 169 window_ = NULL; |
149 } | 170 } |
150 | 171 |
151 //////////////////////////////////////////////////////////////////////////////// | 172 //////////////////////////////////////////////////////////////////////////////// |
152 // PlatformWindowAndroid, PlatformWindow implementation: | 173 // PlatformWindowAndroid, PlatformWindow implementation: |
153 | 174 |
154 void PlatformWindowAndroid::Show() { | 175 void PlatformWindowAndroid::Show() { |
155 if (!java_platform_window_android_.is_empty()) | 176 DCHECK(IsAttachedToActivity()); |
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 } | 177 } |
sadrul
2015/12/01 21:29:34
Should this set visibility on the android SurfaceV
mfomitchev
2015/12/01 21:50:51
Considering we are not doing anything in Hide(), I
| |
164 | 178 |
165 void PlatformWindowAndroid::Hide() { | 179 void PlatformWindowAndroid::Hide() { |
166 // Nothing to do. View is always visible. | 180 // Nothing to do. View is always visible. |
167 } | 181 } |
168 | 182 |
169 void PlatformWindowAndroid::Close() { | 183 void PlatformWindowAndroid::Close() { |
170 delegate_->OnCloseRequest(); | 184 delegate_->OnCloseRequest(); |
171 } | 185 } |
172 | 186 |
173 void PlatformWindowAndroid::SetBounds(const gfx::Rect& bounds) { | 187 void PlatformWindowAndroid::SetBounds(const gfx::Rect& bounds) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 | 230 |
217 void PlatformWindowAndroid::ConfineCursorToBounds(const gfx::Rect& bounds) { | 231 void PlatformWindowAndroid::ConfineCursorToBounds(const gfx::Rect& bounds) { |
218 NOTIMPLEMENTED(); | 232 NOTIMPLEMENTED(); |
219 } | 233 } |
220 | 234 |
221 PlatformImeController* PlatformWindowAndroid::GetPlatformImeController() { | 235 PlatformImeController* PlatformWindowAndroid::GetPlatformImeController() { |
222 return &platform_ime_controller_; | 236 return &platform_ime_controller_; |
223 } | 237 } |
224 | 238 |
225 } // namespace ui | 239 } // namespace ui |
OLD | NEW |