Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / android / window_android.cc
blob9a47689295afe6df8ef074eb64a5ce72946640b9
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
3 // found in the LICENSE file.
5 #include "ui/android/window_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_weak_ref.h"
10 #include "base/android/scoped_java_ref.h"
11 #include "jni/WindowAndroid_jni.h"
12 #include "ui/android/window_android_compositor.h"
13 #include "ui/android/window_android_observer.h"
15 namespace ui {
17 using base::android::AttachCurrentThread;
18 using base::android::ScopedJavaLocalRef;
20 WindowAndroid::WindowAndroid(JNIEnv* env, jobject obj) : compositor_(NULL) {
21 java_window_.Reset(env, obj);
24 void WindowAndroid::Destroy(JNIEnv* env, jobject obj) {
25 delete this;
28 ScopedJavaLocalRef<jobject> WindowAndroid::GetJavaObject() {
29 return base::android::ScopedJavaLocalRef<jobject>(java_window_);
32 bool WindowAndroid::RegisterWindowAndroid(JNIEnv* env) {
33 return RegisterNativesImpl(env);
36 WindowAndroid::~WindowAndroid() {
37 DCHECK(!compositor_);
40 void WindowAndroid::OnCompositingDidCommit() {
41 FOR_EACH_OBSERVER(WindowAndroidObserver,
42 observer_list_,
43 OnCompositingDidCommit());
46 void WindowAndroid::OnVisibilityChanged(bool visible) {
47 FOR_EACH_OBSERVER(WindowAndroidObserver, observer_list_,
48 OnRootWindowVisibilityChanged(visible));
51 void WindowAndroid::AddObserver(WindowAndroidObserver* observer) {
52 if (!observer_list_.HasObserver(observer))
53 observer_list_.AddObserver(observer);
56 void WindowAndroid::RemoveObserver(WindowAndroidObserver* observer) {
57 observer_list_.RemoveObserver(observer);
60 void WindowAndroid::AttachCompositor(WindowAndroidCompositor* compositor) {
61 if (compositor_ && compositor != compositor_)
62 DetachCompositor();
64 compositor_ = compositor;
65 FOR_EACH_OBSERVER(WindowAndroidObserver,
66 observer_list_,
67 OnAttachCompositor());
70 void WindowAndroid::DetachCompositor() {
71 compositor_ = NULL;
72 FOR_EACH_OBSERVER(WindowAndroidObserver,
73 observer_list_,
74 OnDetachCompositor());
75 observer_list_.Clear();
78 void WindowAndroid::RequestVSyncUpdate() {
79 JNIEnv* env = AttachCurrentThread();
80 Java_WindowAndroid_requestVSyncUpdate(env, GetJavaObject().obj());
83 void WindowAndroid::SetNeedsAnimate() {
84 if (compositor_)
85 compositor_->SetNeedsAnimate();
88 void WindowAndroid::Animate(base::TimeTicks begin_frame_time) {
89 FOR_EACH_OBSERVER(
90 WindowAndroidObserver, observer_list_, OnAnimate(begin_frame_time));
93 void WindowAndroid::OnVSync(JNIEnv* env,
94 jobject obj,
95 jlong time_micros,
96 jlong period_micros) {
97 base::TimeTicks frame_time(base::TimeTicks::FromInternalValue(time_micros));
98 base::TimeDelta vsync_period(
99 base::TimeDelta::FromMicroseconds(period_micros));
100 FOR_EACH_OBSERVER(
101 WindowAndroidObserver,
102 observer_list_,
103 OnVSync(frame_time, vsync_period));
104 if (compositor_)
105 compositor_->OnVSync(frame_time, vsync_period);
108 void WindowAndroid::OnActivityResumed(JNIEnv* env, jobject obj) {
109 FOR_EACH_OBSERVER(WindowAndroidObserver, observer_list_, OnActivityResumed());
112 void WindowAndroid::OnActivityPaused(JNIEnv* env, jobject obj) {
113 FOR_EACH_OBSERVER(WindowAndroidObserver, observer_list_, OnActivityPaused());
116 // ----------------------------------------------------------------------------
117 // Native JNI methods
118 // ----------------------------------------------------------------------------
120 jlong Init(JNIEnv* env, jobject obj) {
121 WindowAndroid* window = new WindowAndroid(env, obj);
122 return reinterpret_cast<intptr_t>(window);
125 } // namespace ui