mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This re-lands #20496 and #21780 after fixing the semantics-enabling code that was causing the post-submit web_smoke_test to fail. Below is the description from the original PR: This is a PR for converting the dart:ui code in the engine to use a multi-window API. The goal here is to convert from the window singleton to an API that has the concept of multiple windows. Also, I'm matching up the new PlatformDispatcher class to talk directly to the PlatformConfiguration class in the engine. I'm not attempting to actually enable creating multiple windows here, just migrate to an API that has a concept of multiple windows. The multi-window API in this PR currently only ever creates one window. The design doc for this change is here. The major changes in this PR: Move the platfom-specific attributes out of Window, and into the new PlatformDispatcher class that holds all of the platform state, so that the platform code need only update the configuration on this class. Create FlutterView, FlutterWindow, and SingletonFlutterWindow classes to separate out the concepts of a view (of which there may be multiple in a window), a window (of which there may be multiple on a screen, and they host views), and a window where there is only ever expected to be one (this hosts the entire API of the former Window class, and will eventually be the type of the window singleton). Next step after this PR lands: Remove the Window class entirely (it is replaced by SingletonFlutterWindow). Some minor changes in the Framework are needed to switch to using SingletonFlutterWindow directly first. The Window class still exists in this PR, but will be removed as soon as the framework is converted to point to the SingletonFlutterWindow class instead. They share the same API, just have different names (Window is currently a subclass of SingletonFlutterWindow). The intention is that the Window name will be freed up to use as a widget class name in the framework for managing windows. The singleton called window will remain, and keep the same API it has now.
198 lines
5.0 KiB
Dart
198 lines
5.0 KiB
Dart
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// TODO(dnfield): Remove unused_import ignores when https://github.com/dart-lang/sdk/issues/35164 is resolved.
|
|
|
|
// @dart = 2.10
|
|
|
|
part of dart.ui;
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _updateWindowMetrics(
|
|
Object id,
|
|
double devicePixelRatio,
|
|
double width,
|
|
double height,
|
|
double viewPaddingTop,
|
|
double viewPaddingRight,
|
|
double viewPaddingBottom,
|
|
double viewPaddingLeft,
|
|
double viewInsetTop,
|
|
double viewInsetRight,
|
|
double viewInsetBottom,
|
|
double viewInsetLeft,
|
|
double systemGestureInsetTop,
|
|
double systemGestureInsetRight,
|
|
double systemGestureInsetBottom,
|
|
double systemGestureInsetLeft,
|
|
) {
|
|
PlatformDispatcher.instance._updateWindowMetrics(
|
|
id,
|
|
devicePixelRatio,
|
|
width,
|
|
height,
|
|
viewPaddingTop,
|
|
viewPaddingRight,
|
|
viewPaddingBottom,
|
|
viewPaddingLeft,
|
|
viewInsetTop,
|
|
viewInsetRight,
|
|
viewInsetBottom,
|
|
viewInsetLeft,
|
|
systemGestureInsetTop,
|
|
systemGestureInsetRight,
|
|
systemGestureInsetBottom,
|
|
systemGestureInsetLeft,
|
|
);
|
|
}
|
|
|
|
typedef _LocaleClosure = String Function();
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
_LocaleClosure? _getLocaleClosure() => PlatformDispatcher.instance._localeClosure;
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _updateLocales(List<String> locales) {
|
|
PlatformDispatcher.instance._updateLocales(locales);
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _updateUserSettingsData(String jsonData) {
|
|
PlatformDispatcher.instance._updateUserSettingsData(jsonData);
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _updateLifecycleState(String state) {
|
|
PlatformDispatcher.instance._updateLifecycleState(state);
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _updateSemanticsEnabled(bool enabled) {
|
|
PlatformDispatcher.instance._updateSemanticsEnabled(enabled);
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _updateAccessibilityFeatures(int values) {
|
|
PlatformDispatcher.instance._updateAccessibilityFeatures(values);
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _dispatchPlatformMessage(String name, ByteData? data, int responseId) {
|
|
PlatformDispatcher.instance._dispatchPlatformMessage(name, data, responseId);
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _dispatchPointerDataPacket(ByteData packet) {
|
|
PlatformDispatcher.instance._dispatchPointerDataPacket(packet);
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _dispatchSemanticsAction(int id, int action, ByteData? args) {
|
|
PlatformDispatcher.instance._dispatchSemanticsAction(id, action, args);
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _beginFrame(int microseconds) {
|
|
PlatformDispatcher.instance._beginFrame(microseconds);
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _reportTimings(List<int> timings) {
|
|
PlatformDispatcher.instance._reportTimings(timings);
|
|
}
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _drawFrame() {
|
|
PlatformDispatcher.instance._drawFrame();
|
|
}
|
|
|
|
// ignore: always_declare_return_types, prefer_generic_function_type_aliases
|
|
typedef _ListStringArgFunction(List<String> args);
|
|
|
|
@pragma('vm:entry-point')
|
|
// ignore: unused_element
|
|
void _runMainZoned(Function startMainIsolateFunction,
|
|
Function userMainFunction,
|
|
List<String> args) {
|
|
startMainIsolateFunction(() {
|
|
runZonedGuarded<void>(() {
|
|
if (userMainFunction is _ListStringArgFunction) {
|
|
(userMainFunction as dynamic)(args);
|
|
} else {
|
|
userMainFunction();
|
|
}
|
|
}, (Object error, StackTrace stackTrace) {
|
|
_reportUnhandledException(error.toString(), stackTrace.toString());
|
|
});
|
|
}, null);
|
|
}
|
|
|
|
void _reportUnhandledException(String error, String stackTrace) native 'PlatformConfiguration_reportUnhandledException';
|
|
|
|
/// Invokes [callback] inside the given [zone].
|
|
void _invoke(void Function()? callback, Zone zone) {
|
|
if (callback == null) {
|
|
return;
|
|
}
|
|
|
|
assert(zone != null); // ignore: unnecessary_null_comparison
|
|
|
|
if (identical(zone, Zone.current)) {
|
|
callback();
|
|
} else {
|
|
zone.runGuarded(callback);
|
|
}
|
|
}
|
|
|
|
/// Invokes [callback] inside the given [zone] passing it [arg].
|
|
void _invoke1<A>(void Function(A a)? callback, Zone zone, A arg) {
|
|
if (callback == null) {
|
|
return;
|
|
}
|
|
|
|
assert(zone != null); // ignore: unnecessary_null_comparison
|
|
|
|
if (identical(zone, Zone.current)) {
|
|
callback(arg);
|
|
} else {
|
|
zone.runUnaryGuarded<A>(callback, arg);
|
|
}
|
|
}
|
|
|
|
/// Invokes [callback] inside the given [zone] passing it [arg1], [arg2], and [arg3].
|
|
void _invoke3<A1, A2, A3>(
|
|
void Function(A1 a1, A2 a2, A3 a3)? callback,
|
|
Zone zone,
|
|
A1 arg1,
|
|
A2 arg2,
|
|
A3 arg3,
|
|
) {
|
|
if (callback == null) {
|
|
return;
|
|
}
|
|
|
|
assert(zone != null); // ignore: unnecessary_null_comparison
|
|
|
|
if (identical(zone, Zone.current)) {
|
|
callback(arg1, arg2, arg3);
|
|
} else {
|
|
zone.runGuarded(() {
|
|
callback(arg1, arg2, arg3);
|
|
});
|
|
}
|
|
}
|