Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: ui/platform_window/android/platform_window_android.cc

Issue 1455793005: Adding a way to associate Android Activities with PlatformWindowAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@auraclank_upstream_native_widget
Patch Set: Making the new property "owned" property. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/platform_window/android/platform_window_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/context_utils.h" 10 #include "base/android/context_utils.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } // namespace 45 } // namespace
46 46
47 //////////////////////////////////////////////////////////////////////////////// 47 ////////////////////////////////////////////////////////////////////////////////
48 // PlatformWindowAndroid, public: 48 // PlatformWindowAndroid, public:
49 49
50 // static 50 // static
51 bool PlatformWindowAndroid::Register(JNIEnv* env) { 51 bool PlatformWindowAndroid::Register(JNIEnv* env) {
52 return RegisterNativesImpl(env); 52 return RegisterNativesImpl(env);
53 } 53 }
54 54
55 //static
56 PlatformWindowAndroid* PlatformWindowAndroid::From(
57 PlatformWindow* platform_window) {
58 return static_cast<PlatformWindowAndroid*>(platform_window);
59 }
60
55 PlatformWindowAndroid::PlatformWindowAndroid(PlatformWindowDelegate* delegate) 61 PlatformWindowAndroid::PlatformWindowAndroid(PlatformWindowDelegate* delegate)
56 : delegate_(delegate), 62 : delegate_(delegate),
57 window_(NULL), 63 window_(NULL),
58 id_generator_(0), 64 id_generator_(0),
59 weak_factory_(this) { 65 weak_factory_(this) {
60 } 66 }
61 67
62 PlatformWindowAndroid::~PlatformWindowAndroid() { 68 PlatformWindowAndroid::~PlatformWindowAndroid() {
63 if (window_) 69 if (window_)
64 ReleaseWindow(); 70 ReleaseWindow();
65 JNIEnv* env = base::android::AttachCurrentThread(); 71 JNIEnv* env = base::android::AttachCurrentThread();
66 ScopedJavaLocalRef<jobject> scoped_obj = 72 ScopedJavaLocalRef<jobject> scoped_obj =
67 java_platform_window_android_.get(env); 73 java_platform_window_android_.get(env);
68 if (!scoped_obj.is_null()) { 74 if (!scoped_obj.is_null()) {
69 Java_PlatformWindowAndroid_detach(env, scoped_obj.obj()); 75 Java_PlatformWindowAndroid_detach(env, scoped_obj.obj());
70 } 76 }
71 } 77 }
72 78
79 void PlatformWindowAndroid::AttachToActivity(
80 JNIEnv* env,
81 const base::android::JavaRef<jobject>& activity) {
82 DCHECK(!IsAttachedToActivity());
83 DCHECK(!activity.is_null());
84 base::android::ScopedJavaLocalRef<jobject> jpwa =
85 Java_PlatformWindowAndroid_createForActivity(
86 env,
87 activity.obj(),
88 reinterpret_cast<jlong>(this),
89 reinterpret_cast<jlong>(&platform_ime_controller_));
90 java_platform_window_android_ = JavaObjectWeakGlobalRef(env, jpwa.obj());
91 }
92
93 bool PlatformWindowAndroid::IsAttachedToActivity() const {
94 JNIEnv* env = base::android::AttachCurrentThread();
95 return !java_platform_window_android_.get(env).is_null();
96 }
97
73 void PlatformWindowAndroid::Destroy(JNIEnv* env, jobject obj) { 98 void PlatformWindowAndroid::Destroy(JNIEnv* env, jobject obj) {
74 delegate_->OnClosed(); 99 delegate_->OnClosed();
75 } 100 }
76 101
77 void PlatformWindowAndroid::SurfaceCreated(JNIEnv* env, 102 void PlatformWindowAndroid::SurfaceCreated(JNIEnv* env,
78 jobject obj, 103 jobject obj,
79 jobject jsurface, 104 jobject jsurface,
80 float device_pixel_ratio) { 105 float device_pixel_ratio) {
81 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); 106 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface);
82 // Note: This ensures that any local references used by 107 // Note: This ensures that any local references used by
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 172
148 void PlatformWindowAndroid::ReleaseWindow() { 173 void PlatformWindowAndroid::ReleaseWindow() {
149 ANativeWindow_release(window_); 174 ANativeWindow_release(window_);
150 window_ = NULL; 175 window_ = NULL;
151 } 176 }
152 177
153 //////////////////////////////////////////////////////////////////////////////// 178 ////////////////////////////////////////////////////////////////////////////////
154 // PlatformWindowAndroid, PlatformWindow implementation: 179 // PlatformWindowAndroid, PlatformWindow implementation:
155 180
156 void PlatformWindowAndroid::Show() { 181 void PlatformWindowAndroid::Show() {
157 if (!java_platform_window_android_.is_empty()) 182 DCHECK(IsAttachedToActivity());
158 return;
159 JNIEnv* env = base::android::AttachCurrentThread();
160 java_platform_window_android_ = JavaObjectWeakGlobalRef(
161 env, Java_PlatformWindowAndroid_createForActivity(
162 env, base::android::GetApplicationContext(),
163 reinterpret_cast<jlong>(this),
164 reinterpret_cast<jlong>(&platform_ime_controller_)).obj());
165 } 183 }
166 184
167 void PlatformWindowAndroid::Hide() { 185 void PlatformWindowAndroid::Hide() {
168 // Nothing to do. View is always visible. 186 // Nothing to do. View is always visible.
169 } 187 }
170 188
171 void PlatformWindowAndroid::Close() { 189 void PlatformWindowAndroid::Close() {
172 delegate_->OnCloseRequest(); 190 delegate_->OnCloseRequest();
173 } 191 }
174 192
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 236
219 void PlatformWindowAndroid::ConfineCursorToBounds(const gfx::Rect& bounds) { 237 void PlatformWindowAndroid::ConfineCursorToBounds(const gfx::Rect& bounds) {
220 NOTIMPLEMENTED(); 238 NOTIMPLEMENTED();
221 } 239 }
222 240
223 PlatformImeController* PlatformWindowAndroid::GetPlatformImeController() { 241 PlatformImeController* PlatformWindowAndroid::GetPlatformImeController() {
224 return &platform_ime_controller_; 242 return &platform_ime_controller_;
225 } 243 }
226 244
227 } // namespace ui 245 } // namespace ui
OLDNEW
« no previous file with comments | « ui/platform_window/android/platform_window_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698