forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwindow_android.h
227 lines (173 loc) · 7.39 KB
/
window_android.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_ANDROID_WINDOW_ANDROID_H_
#define UI_ANDROID_WINDOW_ANDROID_H_
#include <jni.h>
#include <memory>
#include <string>
#include "base/android/jni_weak_ref.h"
#include "base/android/scoped_java_ref.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "third_party/blink/public/common/page/content_to_visible_time_reporter.h"
#include "ui/android/progress_bar_config.h"
#include "ui/android/ui_android_export.h"
#include "ui/android/view_android.h"
#include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/overlay_transform.h"
namespace display {
class Display;
class DisplayAndroidManager;
} // namespace display
namespace ui {
extern UI_ANDROID_EXPORT const float kDefaultMouseWheelTickMultiplier;
class ModalDialogManagerBridge;
class WindowAndroidCompositor;
class WindowAndroidObserver;
// Android implementation of the activity window.
// WindowAndroid is also the root of a ViewAndroid tree.
class UI_ANDROID_EXPORT WindowAndroid : public ViewAndroid {
public:
// Intended for unittests only.
class ScopedWindowAndroidForTesting {
public:
ScopedWindowAndroidForTesting(WindowAndroid* window);
~ScopedWindowAndroidForTesting();
WindowAndroid* get() { return window_; }
void SetModalDialogManager(
base::android::ScopedJavaLocalRef<jobject> modal_dialog_manager);
private:
raw_ptr<WindowAndroid> window_;
};
struct AdaptiveRefreshRateInfo {
bool supports_adaptive_refresh_rate = false;
// Fields below are valid only if `supports_adaptive_refresh_rate` is true.
float suggested_frame_rate_normal = 0.f;
float suggested_frame_rate_high = 0.f;
std::vector<float> supported_frame_rates;
AdaptiveRefreshRateInfo();
AdaptiveRefreshRateInfo(const AdaptiveRefreshRateInfo& other);
~AdaptiveRefreshRateInfo();
AdaptiveRefreshRateInfo& operator=(const AdaptiveRefreshRateInfo& other);
};
static WindowAndroid* FromJavaWindowAndroid(
const base::android::JavaParamRef<jobject>& jwindow_android);
WindowAndroid(JNIEnv* env,
jobject obj,
int display_id,
float scroll_factor,
bool window_is_wide_color_gamut);
WindowAndroid(const WindowAndroid&) = delete;
WindowAndroid& operator=(const WindowAndroid&) = delete;
~WindowAndroid() override;
void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
void AttachCompositor(WindowAndroidCompositor* compositor);
void DetachCompositor();
void AddObserver(WindowAndroidObserver* observer);
void RemoveObserver(WindowAndroidObserver* observer);
WindowAndroidCompositor* GetCompositor() { return compositor_; }
float GetRefreshRate();
gfx::OverlayTransform GetOverlayTransform();
std::vector<float> GetSupportedRefreshRates();
AdaptiveRefreshRateInfo adaptive_refresh_rate_info() const {
return adaptive_refresh_rate_info_;
}
void SetPreferredRefreshRate(float refresh_rate);
void SetNeedsAnimate();
void Animate(base::TimeTicks begin_frame_time);
void OnVisibilityChanged(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
bool visible);
void OnActivityStopped(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
void OnActivityStarted(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
void SetVSyncPaused(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
bool paused);
void OnUpdateRefreshRate(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
float refresh_rate);
void OnSupportedRefreshRatesUpdated(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
const base::android::JavaParamRef<jfloatArray>& supported_refresh_rates);
void OnAdaptiveRefreshRateInfoChanged(
JNIEnv* env,
jboolean supports_adaptive_refresh_rate,
jfloat suggested_frame_rate_normal,
jfloat suggested_frame_rate_high,
const base::android::JavaParamRef<jfloatArray>& supported_frame_rates);
void OnOverlayTransformUpdated(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
void SendUnfoldLatencyBeginTimestamp(JNIEnv* env, jlong begin_time);
void OnWindowPointerLockRelease(JNIEnv* env);
void ShowToast(const std::string text);
// Return whether the specified Android permission is granted.
bool HasPermission(const std::string& permission);
// Return whether the specified Android permission can be requested by Chrome.
bool CanRequestPermission(const std::string& permission);
void set_progress_bar_config_for_testing(ProgressBarConfig config) {
progress_bar_config_for_testing_ = config;
}
ProgressBarConfig GetProgressBarConfig();
ModalDialogManagerBridge* GetModalDialogManagerBridge();
// Intended for native browser tests.
void SetModalDialogManagerForTesting(
base::android::ScopedJavaLocalRef<jobject> java_modal_dialog_manager);
float mouse_wheel_scroll_factor() const { return mouse_wheel_scroll_factor_; }
static std::unique_ptr<ScopedWindowAndroidForTesting> CreateForTesting();
// This should return the same Display as Screen::GetDisplayNearestWindow
// except the color space depends on the status of this particular window
// rather than the display itself.
// See comment on WindowAndroid.getWindowIsWideColorGamut for details.
display::Display GetDisplayWithWindowColorSpace();
void SetWideColorEnabled(bool enabled);
bool RequestPointerLock(ViewAndroid& view_android);
bool HasPointerLock(ViewAndroid& view_android);
void ReleasePointerLock(ViewAndroid& view_android);
class TestHooks {
public:
virtual ~TestHooks() = default;
virtual std::vector<float> GetSupportedRates() = 0;
virtual void SetPreferredRate(float refresh_rate) = 0;
};
void SetTestHooks(TestHooks* hooks);
class ScopedSelectionHandles {
public:
ScopedSelectionHandles(WindowAndroid* window);
~ScopedSelectionHandles();
private:
raw_ptr<WindowAndroid> window_;
};
private:
class WindowBeginFrameSource;
class ScopedOnBeginFrame;
friend class DisplayAndroidManager;
friend class WindowBeginFrameSource;
void Force60HzRefreshRateIfNeeded();
// ViewAndroid overrides.
WindowAndroid* GetWindowAndroid() const override;
// The ID of the display that this window belongs to.
int display_id() const { return display_id_; }
base::android::ScopedJavaGlobalRef<jobject> java_window_;
const int display_id_;
const bool window_is_wide_color_gamut_;
raw_ptr<WindowAndroidCompositor> compositor_;
std::optional<ProgressBarConfig> progress_bar_config_for_testing_;
base::ObserverList<WindowAndroidObserver>::Unchecked observer_list_;
blink::ContentToVisibleTimeReporter content_to_visible_time_recorder_;
float mouse_wheel_scroll_factor_;
bool vsync_paused_ = false;
raw_ptr<TestHooks> test_hooks_ = nullptr;
int selection_handles_active_count_ = 0;
raw_ptr<ViewAndroid> pointer_locking_view_ = nullptr;
AdaptiveRefreshRateInfo adaptive_refresh_rate_info_;
};
} // namespace ui
#endif // UI_ANDROID_WINDOW_ANDROID_H_