Unverified Commit bbc01616 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Remove references to `Window`, and switch usages to `PlatformDispatcher` or...

Remove references to `Window`, and switch usages to `PlatformDispatcher` or `SingletonFlutterWindow` (#69617)

* Remove references to dart:ui.Window, and point usages to PlatformDispatcher or SingletonFlutterWindow, as appropriate

* remove new test platform dispatchers

* Amend documentation
parent 3b7718c2
...@@ -217,15 +217,16 @@ abstract class SceneBuilderRecorder extends Recorder { ...@@ -217,15 +217,16 @@ abstract class SceneBuilderRecorder extends Recorder {
Profile get profile => _profile; Profile get profile => _profile;
Profile _profile; Profile _profile;
/// Called from [Window.onBeginFrame]. /// Called from [dart:ui.PlatformDispatcher.onBeginFrame].
@mustCallSuper @mustCallSuper
void onBeginFrame() {} void onBeginFrame() {}
/// Called on every frame. /// Called on every frame.
/// ///
/// An implementation should exercise the [sceneBuilder] to build a frame. /// An implementation should exercise the [sceneBuilder] to build a frame.
/// However, it must not call [SceneBuilder.build] or [Window.render]. /// However, it must not call [SceneBuilder.build] or
/// Instead the benchmark harness will call them and time them appropriately. /// [dart:ui.FlutterView.render]. Instead the benchmark harness will call them
/// and time them appropriately.
void onDrawFrame(SceneBuilder sceneBuilder); void onDrawFrame(SceneBuilder sceneBuilder);
@override @override
......
...@@ -41,8 +41,9 @@ Future<void> main() async { ...@@ -41,8 +41,9 @@ Future<void> main() async {
await SchedulerBinding.instance.endOfFrame; await SchedulerBinding.instance.endOfFrame;
// We are waiting for the GPU to rasterize a frame here. This makes this flaky, // We are waiting for the GPU to rasterize a frame here. This makes this
// we can rely on a more deterministic such as `Window.onReportTimings` once // flaky, we can rely on a more deterministic source such as
// PlatformDispatcher.onReportTimings once
// https://github.com/flutter/flutter/issues/26154 is addressed. // https://github.com/flutter/flutter/issues/26154 is addressed.
await Future<void>.delayed(const Duration(milliseconds: 50)); await Future<void>.delayed(const Duration(milliseconds: 50));
debugPrint('==== MEMORY BENCHMARK ==== READY ===='); debugPrint('==== MEMORY BENCHMARK ==== READY ====');
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'dart:convert' show json; import 'dart:convert' show json;
import 'dart:developer' as developer; import 'dart:developer' as developer;
import 'dart:io' show exit; import 'dart:io' show exit;
import 'dart:ui' as ui show Window, window, Brightness; import 'dart:ui' as ui show SingletonFlutterWindow, Brightness, PlatformDispatcher, window;
// Before adding any more dart:ui imports, please read the README. // Before adding any more dart:ui imports, please read the README.
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
...@@ -68,23 +68,57 @@ abstract class BindingBase { ...@@ -68,23 +68,57 @@ abstract class BindingBase {
static bool _debugInitialized = false; static bool _debugInitialized = false;
static bool _debugServiceExtensionsRegistered = false; static bool _debugServiceExtensionsRegistered = false;
/// The window to which this binding is bound. /// The main window to which this binding is bound.
/// ///
/// A number of additional bindings are defined as extensions of [BindingBase], /// A number of additional bindings are defined as extensions of
/// e.g., [ServicesBinding], [RendererBinding], and [WidgetsBinding]. Each of /// [BindingBase], e.g., [ServicesBinding], [RendererBinding], and
/// these bindings define behaviors that interact with a [ui.Window], e.g., /// [WidgetsBinding]. Each of these bindings define behaviors that interact
/// [ServicesBinding] registers a [ui.Window.onPlatformMessage] handler, and /// with a [ui.SingletonFlutterWindow].
/// [RendererBinding] registers [ui.Window.onMetricsChanged], ///
/// [ui.Window.onTextScaleFactorChanged], [ui.Window.onSemanticsEnabledChanged], /// Each of these other bindings could individually access a
/// and [ui.Window.onSemanticsAction] handlers. /// [ui.SingletonFlutterWindow] statically, but that would preclude the
/// /// ability to test its behaviors with a fake window for verification
/// Each of these other bindings could individually access a [Window] statically, /// purposes. Therefore, [BindingBase] exposes this
/// but that would preclude the ability to test these behaviors with a fake /// [ui.SingletonFlutterWindow] for use by other bindings. A subclass of
/// window for verification purposes. Therefore, [BindingBase] exposes this /// [BindingBase], such as [TestWidgetsFlutterBinding], can override this
/// [Window] for use by other bindings. A subclass of [BindingBase], such as /// accessor to return a different [ui.SingletonFlutterWindow] implementation,
/// such as a [TestWindow].
///
/// The `window` is a singleton meant for use by applications that only have a
/// single main window. In addition to the properties of [ui.FlutterWindow],
/// `window` provides access to platform-specific properties and callbacks
/// available on the [platformDispatcher].
///
/// For applications designed for more than one main window, prefer using the
/// [platformDispatcher] to access available views via
/// [ui.PlatformDispatcher.views].
///
/// However, multiple window support is not yet implemented, so currently this
/// provides access to the one and only window.
// TODO(gspencergoog): remove the preceding note once multi-window support is
// active.
ui.SingletonFlutterWindow get window => ui.window;
/// The [ui.PlatformDispatcher] to which this binding is bound.
///
/// A number of additional bindings are defined as extensions of
/// [BindingBase], e.g., [ServicesBinding], [RendererBinding], and
/// [WidgetsBinding]. Each of these bindings define behaviors that interact
/// with a [ui.PlatformDispatcher], e.g., [ServicesBinding] registers a
/// [ui.PlatformDispatcher.onPlatformMessage] handler, and [RendererBinding]
/// registers [ui.PlatformDispatcher.onMetricsChanged],
/// [ui.PlatformDispatcher.onTextScaleFactorChanged],
/// [ui.PlatformDispatcher.onSemanticsEnabledChanged], and
/// [ui.PlatformDispatcher.onSemanticsAction] handlers.
///
/// Each of these other bindings could individually access a
/// [ui.PlatformDispatcher] statically, but that would preclude the ability to
/// test these behaviors with a fake platform dispatcher for verification
/// purposes. Therefore, [BindingBase] exposes this [ui.PlatformDispatcher]
/// for use by other bindings. A subclass of [BindingBase], such as
/// [TestWidgetsFlutterBinding], can override this accessor to return a /// [TestWidgetsFlutterBinding], can override this accessor to return a
/// different [Window] implementation, such as a [TestWindow]. /// different [ui.PlatformDispatcher] implementation.
ui.Window get window => ui.window; ui.PlatformDispatcher get platformDispatcher => ui.PlatformDispatcher.instance;
/// The initialization method. Subclasses override this method to hook into /// The initialization method. Subclasses override this method to hook into
/// the platform and otherwise configure their services. Subclasses must call /// the platform and otherwise configure their services. Subclasses must call
...@@ -202,12 +236,12 @@ abstract class BindingBase { ...@@ -202,12 +236,12 @@ abstract class BindingBase {
} }
_postExtensionStateChangedEvent( _postExtensionStateChangedEvent(
brightnessOverrideExtensionName, brightnessOverrideExtensionName,
(debugBrightnessOverride ?? window.platformBrightness).toString(), (debugBrightnessOverride ?? platformDispatcher.platformBrightness).toString(),
); );
await reassembleApplication(); await reassembleApplication();
} }
return <String, dynamic>{ return <String, dynamic>{
'value': (debugBrightnessOverride ?? window.platformBrightness).toString(), 'value': (debugBrightnessOverride ?? platformDispatcher.platformBrightness).toString(),
}; };
}, },
); );
......
...@@ -102,7 +102,7 @@ String debugFormatDouble(double? value) { ...@@ -102,7 +102,7 @@ String debugFormatDouble(double? value) {
} }
/// A setting that can be used to override the platform [Brightness] exposed /// A setting that can be used to override the platform [Brightness] exposed
/// from [BindingBase.window]. /// from [BindingBase.platformDispatcher].
/// ///
/// See also: /// See also:
/// ///
......
...@@ -158,7 +158,7 @@ const Duration _samplingInterval = Duration(microseconds: 16667); ...@@ -158,7 +158,7 @@ const Duration _samplingInterval = Duration(microseconds: 16667);
/// ### [PointerDownEvent] /// ### [PointerDownEvent]
/// ///
/// When a [PointerDownEvent] is received by the [GestureBinding] (from /// When a [PointerDownEvent] is received by the [GestureBinding] (from
/// [Window.onPointerDataPacket], as interpreted by the /// [dart:ui.PlatformDispatcher.onPointerDataPacket], as interpreted by the
/// [PointerEventConverter]), a [hitTest] is performed to determine which /// [PointerEventConverter]), a [hitTest] is performed to determine which
/// [HitTestTarget] nodes are affected. (Other bindings are expected to /// [HitTestTarget] nodes are affected. (Other bindings are expected to
/// implement [hitTest] to defer to [HitTestable] objects. For example, the /// implement [hitTest] to defer to [HitTestable] objects. For example, the
...@@ -198,7 +198,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H ...@@ -198,7 +198,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
void initInstances() { void initInstances() {
super.initInstances(); super.initInstances();
_instance = this; _instance = this;
window.onPointerDataPacket = _handlePointerDataPacket; platformDispatcher.onPointerDataPacket = _handlePointerDataPacket;
} }
@override @override
......
...@@ -30,8 +30,8 @@ int _synthesiseDownButtons(int buttons, PointerDeviceKind kind) { ...@@ -30,8 +30,8 @@ int _synthesiseDownButtons(int buttons, PointerDeviceKind kind) {
/// Converts from engine pointer data to framework pointer events. /// Converts from engine pointer data to framework pointer events.
/// ///
/// This takes [PointerDataPacket] objects, as received from the engine via /// This takes [PointerDataPacket] objects, as received from the engine via
/// [dart:ui.Window.onPointerDataPacket], and converts them to [PointerEvent] /// [dart:ui.PlatformDispatcher.onPointerDataPacket], and converts them to
/// objects. /// [PointerEvent] objects.
class PointerEventConverter { class PointerEventConverter {
// This class is not meant to be instantiated or extended; this constructor // This class is not meant to be instantiated or extended; this constructor
// prevents instantiation and extension. // prevents instantiation and extension.
...@@ -42,7 +42,7 @@ class PointerEventConverter { ...@@ -42,7 +42,7 @@ class PointerEventConverter {
/// pointer events. /// pointer events.
/// ///
/// The `devicePixelRatio` argument (usually given the value from /// The `devicePixelRatio` argument (usually given the value from
/// [dart:ui.Window.devicePixelRatio]) is used to convert the incoming data /// [dart:ui.FlutterView.devicePixelRatio]) is used to convert the incoming data
/// from physical coordinates to logical pixels. See the discussion at /// from physical coordinates to logical pixels. See the discussion at
/// [PointerEvent] for more details on the [PointerEvent] coordinate space. /// [PointerEvent] for more details on the [PointerEvent] coordinate space.
static Iterable<PointerEvent> expand(Iterable<ui.PointerData> data, double devicePixelRatio) sync* { static Iterable<PointerEvent> expand(Iterable<ui.PointerData> data, double devicePixelRatio) sync* {
......
...@@ -229,7 +229,8 @@ bool isSingleButton(int buttons) => buttons != 0 && (smallestButton(buttons) == ...@@ -229,7 +229,8 @@ bool isSingleButton(int buttons) => buttons != 0 && (smallestButton(buttons) ==
/// ///
/// See also: /// See also:
/// ///
/// * [Window.devicePixelRatio], which defines the device's current resolution. /// * [dart:ui.FlutterView.devicePixelRatio], which defines the device's
/// current resolution.
/// * [Listener], a widget that calls callbacks in response to common pointer /// * [Listener], a widget that calls callbacks in response to common pointer
/// events. /// events.
@immutable @immutable
......
...@@ -71,7 +71,7 @@ enum ThemeMode { ...@@ -71,7 +71,7 @@ enum ThemeMode {
/// If a [Navigator] is created, at least one of these options must handle the /// If a [Navigator] is created, at least one of these options must handle the
/// `/` route, since it is used when an invalid [initialRoute] is specified on /// `/` route, since it is used when an invalid [initialRoute] is specified on
/// startup (e.g. by another application launching this one with an intent on /// startup (e.g. by another application launching this one with an intent on
/// Android; see [Window.defaultRouteName]). /// Android; see [dart:ui.PlatformDispatcher.defaultRouteName]).
/// ///
/// This widget also configures the observer of the top-level [Navigator] (if /// This widget also configures the observer of the top-level [Navigator] (if
/// any) to perform [Hero] animations. /// any) to perform [Hero] animations.
......
...@@ -33,7 +33,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture ...@@ -33,7 +33,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
onSemanticsOwnerCreated: _handleSemanticsOwnerCreated, onSemanticsOwnerCreated: _handleSemanticsOwnerCreated,
onSemanticsOwnerDisposed: _handleSemanticsOwnerDisposed, onSemanticsOwnerDisposed: _handleSemanticsOwnerDisposed,
); );
window platformDispatcher
..onMetricsChanged = handleMetricsChanged ..onMetricsChanged = handleMetricsChanged
..onTextScaleFactorChanged = handleTextScaleFactorChanged ..onTextScaleFactorChanged = handleTextScaleFactorChanged
..onPlatformBrightnessChanged = handlePlatformBrightnessChanged ..onPlatformBrightnessChanged = handlePlatformBrightnessChanged
...@@ -187,7 +187,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture ...@@ -187,7 +187,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
/// Called when the system metrics change. /// Called when the system metrics change.
/// ///
/// See [Window.onMetricsChanged]. /// See [dart:ui.PlatformDispatcher.onMetricsChanged].
@protected @protected
void handleMetricsChanged() { void handleMetricsChanged() {
assert(renderView != null); assert(renderView != null);
...@@ -197,7 +197,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture ...@@ -197,7 +197,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
/// Called when the platform text scale factor changes. /// Called when the platform text scale factor changes.
/// ///
/// See [Window.onTextScaleFactorChanged]. /// See [dart:ui.PlatformDispatcher.onTextScaleFactorChanged].
@protected @protected
void handleTextScaleFactorChanged() { } void handleTextScaleFactorChanged() { }
...@@ -233,7 +233,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture ...@@ -233,7 +233,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
/// ``` /// ```
/// {@end-tool} /// {@end-tool}
/// ///
/// See [Window.onPlatformBrightnessChanged]. /// See [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged].
@protected @protected
void handlePlatformBrightnessChanged() { } void handlePlatformBrightnessChanged() { }
...@@ -280,7 +280,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture ...@@ -280,7 +280,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
} }
void _handleSemanticsEnabledChanged() { void _handleSemanticsEnabledChanged() {
setSemanticsEnabled(window.semanticsEnabled); setSemanticsEnabled(platformDispatcher.semanticsEnabled);
} }
/// Whether the render tree associated with this binding should produce a tree /// Whether the render tree associated with this binding should produce a tree
...@@ -414,9 +414,9 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture ...@@ -414,9 +414,9 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
/// completed this frame. /// completed this frame.
/// ///
/// After [handleBeginFrame], [handleDrawFrame], which is registered with /// After [handleBeginFrame], [handleDrawFrame], which is registered with
/// [Window.onDrawFrame], is called, which invokes all the persistent frame /// [dart:ui.PlatformDispatcher.onDrawFrame], is called, which invokes all the
/// callbacks, of which the most notable is this method, [drawFrame], which /// persistent frame callbacks, of which the most notable is this method,
/// proceeds as follows: /// [drawFrame], which proceeds as follows:
/// ///
/// 3. The layout phase: All the dirty [RenderObject]s in the system are laid /// 3. The layout phase: All the dirty [RenderObject]s in the system are laid
/// out (see [RenderObject.performLayout]). See [RenderObject.markNeedsLayout] /// out (see [RenderObject.performLayout]). See [RenderObject.markNeedsLayout]
......
...@@ -86,7 +86,7 @@ class AnnotationResult<T> { ...@@ -86,7 +86,7 @@ class AnnotationResult<T> {
/// To composite the tree, create a [SceneBuilder] object, pass it to the /// To composite the tree, create a [SceneBuilder] object, pass it to the
/// root [Layer] object's [addToScene] method, and then call /// root [Layer] object's [addToScene] method, and then call
/// [SceneBuilder.build] to obtain a [Scene]. A [Scene] can then be painted /// [SceneBuilder.build] to obtain a [Scene]. A [Scene] can then be painted
/// using [Window.render]. /// using [dart:ui.FlutterView.render].
/// ///
/// See also: /// See also:
/// ///
...@@ -1179,9 +1179,9 @@ class OffsetLayer extends ContainerLayer { ...@@ -1179,9 +1179,9 @@ class OffsetLayer extends ContainerLayer {
/// ///
/// The [pixelRatio] describes the scale between the logical pixels and the /// The [pixelRatio] describes the scale between the logical pixels and the
/// size of the output image. It is independent of the /// size of the output image. It is independent of the
/// [Window.devicePixelRatio] for the device, so specifying 1.0 (the default) /// [dart:ui.FlutterView.devicePixelRatio] for the device, so specifying 1.0
/// will give you a 1:1 mapping between logical pixels and the output pixels /// (the default) will give you a 1:1 mapping between logical pixels and the
/// in the image. /// output pixels in the image.
/// ///
/// See also: /// See also:
/// ///
......
...@@ -2914,9 +2914,9 @@ class RenderRepaintBoundary extends RenderProxyBox { ...@@ -2914,9 +2914,9 @@ class RenderRepaintBoundary extends RenderProxyBox {
/// ///
/// The [pixelRatio] describes the scale between the logical pixels and the /// The [pixelRatio] describes the scale between the logical pixels and the
/// size of the output image. It is independent of the /// size of the output image. It is independent of the
/// [Window.devicePixelRatio] for the device, so specifying 1.0 (the default) /// [dart:ui.FlutterView.devicePixelRatio] for the device, so specifying 1.0
/// will give you a 1:1 mapping between logical pixels and the output pixels /// (the default) will give you a 1:1 mapping between logical pixels and the
/// in the image. /// output pixels in the image.
/// ///
/// {@tool snippet} /// {@tool snippet}
/// ///
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'dart:developer'; import 'dart:developer';
import 'dart:io' show Platform; import 'dart:io' show Platform;
import 'dart:ui' as ui show Scene, SceneBuilder, Window; import 'dart:ui' as ui show Scene, SceneBuilder, FlutterView;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
...@@ -57,7 +57,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox> ...@@ -57,7 +57,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
RenderView({ RenderView({
RenderBox? child, RenderBox? child,
required ViewConfiguration configuration, required ViewConfiguration configuration,
required ui.Window window, required ui.FlutterView window,
}) : assert(configuration != null), }) : assert(configuration != null),
_configuration = configuration, _configuration = configuration,
_window = window { _window = window {
...@@ -85,7 +85,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox> ...@@ -85,7 +85,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
markNeedsLayout(); markNeedsLayout();
} }
final ui.Window _window; final ui.FlutterView _window;
/// Whether Flutter should automatically compute the desired system UI. /// Whether Flutter should automatically compute the desired system UI.
/// ///
...@@ -334,7 +334,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox> ...@@ -334,7 +334,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
properties.add(DiagnosticsProperty<Size>('window size', _window.physicalSize, tooltip: 'in physical pixels')); properties.add(DiagnosticsProperty<Size>('window size', _window.physicalSize, tooltip: 'in physical pixels'));
properties.add(DoubleProperty('device pixel ratio', _window.devicePixelRatio, tooltip: 'physical pixels per logical pixel')); properties.add(DoubleProperty('device pixel ratio', _window.devicePixelRatio, tooltip: 'physical pixels per logical pixel'));
properties.add(DiagnosticsProperty<ViewConfiguration>('configuration', configuration, tooltip: 'in logical pixels')); properties.add(DiagnosticsProperty<ViewConfiguration>('configuration', configuration, tooltip: 'in logical pixels'));
if (_window.semanticsEnabled) if (_window.platformDispatcher.semanticsEnabled)
properties.add(DiagnosticsNode.message('semantics enabled')); properties.add(DiagnosticsNode.message('semantics enabled'));
} }
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:collection'; import 'dart:collection';
import 'dart:developer' show Flow, Timeline; import 'dart:developer' show Flow, Timeline;
import 'dart:ui' show AppLifecycleState, FramePhase, FrameTiming, TimingsCallback; import 'dart:ui' show AppLifecycleState, FramePhase, FrameTiming, TimingsCallback, PlatformDispatcher;
import 'package:collection/collection.dart' show PriorityQueue, HeapPriorityQueue; import 'package:collection/collection.dart' show PriorityQueue, HeapPriorityQueue;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -179,18 +179,18 @@ enum SchedulerPhase { ...@@ -179,18 +179,18 @@ enum SchedulerPhase {
/// Scheduler for running the following: /// Scheduler for running the following:
/// ///
/// * _Transient callbacks_, triggered by the system's [Window.onBeginFrame] /// * _Transient callbacks_, triggered by the system's
/// callback, for synchronizing the application's behavior to the system's /// [dart:ui.PlatformDispatcher.onBeginFrame] callback, for synchronizing the
/// display. For example, [Ticker]s and [AnimationController]s trigger from /// application's behavior to the system's display. For example, [Ticker]s and
/// these. /// [AnimationController]s trigger from these.
/// ///
/// * _Persistent callbacks_, triggered by the system's [Window.onDrawFrame] /// * _Persistent callbacks_, triggered by the system's
/// callback, for updating the system's display after transient callbacks have /// [dart:ui.PlatformDispatcher.onDrawFrame] callback, for updating the
/// executed. For example, the rendering layer uses this to drive its /// system's display after transient callbacks have executed. For example, the
/// rendering pipeline. /// rendering layer uses this to drive its rendering pipeline.
/// ///
/// * _Post-frame callbacks_, which are run after persistent callbacks, just /// * _Post-frame callbacks_, which are run after persistent callbacks, just
/// before returning from the [Window.onDrawFrame] callback. /// before returning from the [dart:ui.PlatformDispatcher.onDrawFrame] callback.
/// ///
/// * Non-rendering tasks, to be run between frames. These are given a /// * Non-rendering tasks, to be run between frames. These are given a
/// priority and are executed in priority order according to a /// priority and are executed in priority order according to a
...@@ -238,20 +238,20 @@ mixin SchedulerBinding on BindingBase { ...@@ -238,20 +238,20 @@ mixin SchedulerBinding on BindingBase {
/// feel more sluggish. /// feel more sluggish.
/// ///
/// Using [addTimingsCallback] is preferred over using /// Using [addTimingsCallback] is preferred over using
/// [Window.onReportTimings] directly because the /// [dart:ui.PlatformDispatcher.onReportTimings] directly because the
/// [Window.onReportTimings] API only allows one callback, which /// [dart:ui.PlatformDispatcher.onReportTimings] API only allows one callback,
/// prevents multiple libraries from registering listeners /// which prevents multiple libraries from registering listeners
/// simultaneously, while this API allows multiple callbacks to be /// simultaneously, while this API allows multiple callbacks to be registered
/// registered independently. /// independently.
/// ///
/// This API is implemented in terms of [Window.onReportTimings]. In /// This API is implemented in terms of
/// release builds, when no libraries have registered with this API, /// [dart:ui.PlatformDispatcher.onReportTimings]. In release builds, when no
/// the [Window.onReportTimings] callback is not set, which disables /// libraries have registered with this API, the
/// the performance tracking and reduces the runtime overhead to /// [dart:ui.PlatformDispatcher.onReportTimings] callback is not set, which
/// approximately zero. The performance overhead of the performance /// disables the performance tracking and reduces the runtime overhead to
/// tracking when one or more callbacks are registered (i.e. when it /// approximately zero. The performance overhead of the performance tracking
/// is enabled) is very approximately 0.01% CPU usage per second /// when one or more callbacks are registered (i.e. when it is enabled) is
/// (measured on an iPhone 6s). /// very approximately 0.01% CPU usage per second (measured on an iPhone 6s).
/// ///
/// In debug and profile builds, the [SchedulerBinding] itself /// In debug and profile builds, the [SchedulerBinding] itself
/// registers a timings callback to update the [Timeline]. /// registers a timings callback to update the [Timeline].
...@@ -265,10 +265,10 @@ mixin SchedulerBinding on BindingBase { ...@@ -265,10 +265,10 @@ mixin SchedulerBinding on BindingBase {
void addTimingsCallback(TimingsCallback callback) { void addTimingsCallback(TimingsCallback callback) {
_timingsCallbacks.add(callback); _timingsCallbacks.add(callback);
if (_timingsCallbacks.length == 1) { if (_timingsCallbacks.length == 1) {
assert(window.onReportTimings == null); assert(platformDispatcher.onReportTimings == null);
window.onReportTimings = _executeTimingsCallbacks; platformDispatcher.onReportTimings = _executeTimingsCallbacks;
} }
assert(window.onReportTimings == _executeTimingsCallbacks); assert(platformDispatcher.onReportTimings == _executeTimingsCallbacks);
} }
/// Removes a callback that was earlier added by [addTimingsCallback]. /// Removes a callback that was earlier added by [addTimingsCallback].
...@@ -276,7 +276,7 @@ mixin SchedulerBinding on BindingBase { ...@@ -276,7 +276,7 @@ mixin SchedulerBinding on BindingBase {
assert(_timingsCallbacks.contains(callback)); assert(_timingsCallbacks.contains(callback));
_timingsCallbacks.remove(callback); _timingsCallbacks.remove(callback);
if (_timingsCallbacks.isEmpty) { if (_timingsCallbacks.isEmpty) {
window.onReportTimings = null; platformDispatcher.onReportTimings = null;
} }
} }
...@@ -720,12 +720,12 @@ mixin SchedulerBinding on BindingBase { ...@@ -720,12 +720,12 @@ mixin SchedulerBinding on BindingBase {
scheduleFrame(); scheduleFrame();
} }
/// Ensures callbacks for `window.onBeginFrame` and `window.onDrawFrame` /// Ensures callbacks for [PlatformDispatcher.onBeginFrame] and
/// are registered. /// [PlatformDispatcher.onDrawFrame] are registered.
@protected @protected
void ensureFrameCallbacksRegistered() { void ensureFrameCallbacksRegistered() {
window.onBeginFrame ??= _handleBeginFrame; platformDispatcher.onBeginFrame ??= _handleBeginFrame;
window.onDrawFrame ??= _handleDrawFrame; platformDispatcher.onDrawFrame ??= _handleDrawFrame;
} }
/// Schedules a new frame using [scheduleFrame] if this object is not /// Schedules a new frame using [scheduleFrame] if this object is not
...@@ -755,7 +755,7 @@ mixin SchedulerBinding on BindingBase { ...@@ -755,7 +755,7 @@ mixin SchedulerBinding on BindingBase {
} }
/// If necessary, schedules a new frame by calling /// If necessary, schedules a new frame by calling
/// [Window.scheduleFrame]. /// [dart:ui.PlatformDispatcher.scheduleFrame].
/// ///
/// After this is called, the engine will (eventually) call /// After this is called, the engine will (eventually) call
/// [handleBeginFrame]. (This call might be delayed, e.g. if the device's /// [handleBeginFrame]. (This call might be delayed, e.g. if the device's
...@@ -790,11 +790,12 @@ mixin SchedulerBinding on BindingBase { ...@@ -790,11 +790,12 @@ mixin SchedulerBinding on BindingBase {
return true; return true;
}()); }());
ensureFrameCallbacksRegistered(); ensureFrameCallbacksRegistered();
window.scheduleFrame(); platformDispatcher.scheduleFrame();
_hasScheduledFrame = true; _hasScheduledFrame = true;
} }
/// Schedules a new frame by calling [Window.scheduleFrame]. /// Schedules a new frame by calling
/// [dart:ui.PlatformDispatcher.scheduleFrame].
/// ///
/// After this is called, the engine will call [handleBeginFrame], even if /// After this is called, the engine will call [handleBeginFrame], even if
/// frames would normally not be scheduled by [scheduleFrame] (e.g. even if /// frames would normally not be scheduled by [scheduleFrame] (e.g. even if
...@@ -826,7 +827,7 @@ mixin SchedulerBinding on BindingBase { ...@@ -826,7 +827,7 @@ mixin SchedulerBinding on BindingBase {
debugPrintStack(label: 'scheduleForcedFrame() called. Current phase is $schedulerPhase.'); debugPrintStack(label: 'scheduleForcedFrame() called. Current phase is $schedulerPhase.');
return true; return true;
}()); }());
window.scheduleFrame(); platformDispatcher.scheduleFrame();
_hasScheduledFrame = true; _hasScheduledFrame = true;
} }
...@@ -934,8 +935,9 @@ mixin SchedulerBinding on BindingBase { ...@@ -934,8 +935,9 @@ mixin SchedulerBinding on BindingBase {
} }
Duration? _currentFrameTimeStamp; Duration? _currentFrameTimeStamp;
/// The raw time stamp as provided by the engine to [Window.onBeginFrame] /// The raw time stamp as provided by the engine to
/// for the frame currently being processed. /// [dart:ui.PlatformDispatcher.onBeginFrame] for the frame currently being
/// processed.
/// ///
/// Unlike [currentFrameTimeStamp], this time stamp is neither adjusted to /// Unlike [currentFrameTimeStamp], this time stamp is neither adjusted to
/// offset when the epoch started nor scaled to reflect the [timeDilation] in /// offset when the epoch started nor scaled to reflect the [timeDilation] in
......
...@@ -21,15 +21,15 @@ mixin SemanticsBinding on BindingBase { ...@@ -21,15 +21,15 @@ mixin SemanticsBinding on BindingBase {
void initInstances() { void initInstances() {
super.initInstances(); super.initInstances();
_instance = this; _instance = this;
_accessibilityFeatures = window.accessibilityFeatures; _accessibilityFeatures = platformDispatcher.accessibilityFeatures;
} }
/// Called when the platform accessibility features change. /// Called when the platform accessibility features change.
/// ///
/// See [Window.onAccessibilityFeaturesChanged]. /// See [dart:ui.PlatformDispatcher.onAccessibilityFeaturesChanged].
@protected @protected
void handleAccessibilityFeaturesChanged() { void handleAccessibilityFeaturesChanged() {
_accessibilityFeatures = window.accessibilityFeatures; _accessibilityFeatures = platformDispatcher.accessibilityFeatures;
} }
/// Creates an empty semantics update builder. /// Creates an empty semantics update builder.
......
...@@ -2611,7 +2611,7 @@ class SemanticsOwner extends ChangeNotifier { ...@@ -2611,7 +2611,7 @@ class SemanticsOwner extends ChangeNotifier {
super.dispose(); super.dispose();
} }
/// Update the semantics using [Window.updateSemantics]. /// Update the semantics using [dart:ui.PlatformDispatcher.updateSemantics].
void sendSemanticsUpdate() { void sendSemanticsUpdate() {
if (_dirtyNodes.isEmpty) if (_dirtyNodes.isEmpty)
return; return;
...@@ -2658,7 +2658,7 @@ class SemanticsOwner extends ChangeNotifier { ...@@ -2658,7 +2658,7 @@ class SemanticsOwner extends ChangeNotifier {
final CustomSemanticsAction action = CustomSemanticsAction.getAction(actionId)!; final CustomSemanticsAction action = CustomSemanticsAction.getAction(actionId)!;
builder.updateCustomAction(id: actionId, label: action.label, hint: action.hint, overrideId: action.action?.index ?? -1); builder.updateCustomAction(id: actionId, label: action.label, hint: action.hint, overrideId: action.action?.index ?? -1);
} }
SemanticsBinding.instance!.window.updateSemantics(builder.build()); SemanticsBinding.instance!.platformDispatcher.updateSemantics(builder.build());
notifyListeners(); notifyListeners();
} }
......
...@@ -22,7 +22,7 @@ abstract class BinaryMessenger { ...@@ -22,7 +22,7 @@ abstract class BinaryMessenger {
/// Calls the handler registered for the given channel. /// Calls the handler registered for the given channel.
/// ///
/// Typically called by [ServicesBinding] to handle platform messages received /// Typically called by [ServicesBinding] to handle platform messages received
/// from [Window.onPlatformMessage]. /// from [dart:ui.PlatformDispatcher.onPlatformMessage].
/// ///
/// To register a handler for a given message channel, see [setMessageHandler]. /// To register a handler for a given message channel, see [setMessageHandler].
Future<void> handlePlatformMessage(String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback); Future<void> handlePlatformMessage(String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback);
......
...@@ -28,7 +28,7 @@ mixin ServicesBinding on BindingBase, SchedulerBinding { ...@@ -28,7 +28,7 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
_instance = this; _instance = this;
_defaultBinaryMessenger = createBinaryMessenger(); _defaultBinaryMessenger = createBinaryMessenger();
_restorationManager = createRestorationManager(); _restorationManager = createRestorationManager();
window.onPlatformMessage = defaultBinaryMessenger.handlePlatformMessage; platformDispatcher.onPlatformMessage = defaultBinaryMessenger.handlePlatformMessage;
initLicenses(); initLicenses();
SystemChannels.system.setMessageHandler((dynamic message) => handleSystemMessage(message as Object)); SystemChannels.system.setMessageHandler((dynamic message) => handleSystemMessage(message as Object));
SystemChannels.lifecycle.setMessageHandler(_handleLifecycleMessage); SystemChannels.lifecycle.setMessageHandler(_handleLifecycleMessage);
...@@ -166,14 +166,14 @@ mixin ServicesBinding on BindingBase, SchedulerBinding { ...@@ -166,14 +166,14 @@ mixin ServicesBinding on BindingBase, SchedulerBinding {
// App life cycle // App life cycle
/// Initializes the [lifecycleState] with the [Window.initialLifecycleState] /// Initializes the [lifecycleState] with the
/// from the window. /// [dart:ui.SingletonFlutterWindow.initialLifecycleState].
/// ///
/// Once the [lifecycleState] is populated through any means (including this /// Once the [lifecycleState] is populated through any means (including this
/// method), this method will do nothing. This is because the /// method), this method will do nothing. This is because the
/// [Window.initialLifecycleState] may already be stale and it no longer makes /// [dart:ui.SingletonFlutterWindow.initialLifecycleState] may already be
/// sense to use the initial state at dart vm startup as the current state /// stale and it no longer makes sense to use the initial state at dart vm
/// anymore. /// startup as the current state anymore.
/// ///
/// The latest state should be obtained by subscribing to /// The latest state should be obtained by subscribing to
/// [WidgetsBindingObserver.didChangeAppLifecycleState]. /// [WidgetsBindingObserver.didChangeAppLifecycleState].
...@@ -249,13 +249,14 @@ class _DefaultBinaryMessenger extends BinaryMessenger { ...@@ -249,13 +249,14 @@ class _DefaultBinaryMessenger extends BinaryMessenger {
Future<ByteData?> _sendPlatformMessage(String channel, ByteData? message) { Future<ByteData?> _sendPlatformMessage(String channel, ByteData? message) {
final Completer<ByteData?> completer = Completer<ByteData?>(); final Completer<ByteData?> completer = Completer<ByteData?>();
// ui.window is accessed directly instead of using ServicesBinding.instance.window // ui.PlatformDispatcher.instance is accessed directly instead of using
// because this method might be invoked before any binding is initialized. // ServicesBinding.instance.platformDispatcher because this method might be
// This issue was reported in #27541. It is not ideal to statically access // invoked before any binding is initialized. This issue was reported in
// ui.window because the Window may be dependency injected elsewhere with // #27541. It is not ideal to statically access
// a different instance. However, static access at this location seems to be // ui.PlatformDispatcher.instance because the PlatformDispatcher may be
// the least bad option. // dependency injected elsewhere with a different instance. However, static
ui.window.sendPlatformMessage(channel, message, (ByteData? reply) { // access at this location seems to be the least bad option.
ui.PlatformDispatcher.instance.sendPlatformMessage(channel, message, (ByteData? reply) {
try { try {
completer.complete(reply); completer.complete(reply);
} catch (exception, stack) { } catch (exception, stack) {
......
...@@ -42,7 +42,7 @@ class BinaryMessages { ...@@ -42,7 +42,7 @@ class BinaryMessages {
/// Calls the handler registered for the given channel. /// Calls the handler registered for the given channel.
/// ///
/// Typically called by [ServicesBinding] to handle platform messages received /// Typically called by [ServicesBinding] to handle platform messages received
/// from [Window.onPlatformMessage]. /// from [dart:ui.PlatformDispatcher.onPlatformMessage].
/// ///
/// To register a handler for a given message channel, see [setMessageHandler]. /// To register a handler for a given message channel, see [setMessageHandler].
@Deprecated( @Deprecated(
......
...@@ -433,8 +433,8 @@ class WidgetsApp extends StatefulWidget { ...@@ -433,8 +433,8 @@ class WidgetsApp extends StatefulWidget {
/// This object will be used by the underlying [Router]. /// This object will be used by the underlying [Router].
/// ///
/// If this is not provided, the widgets app will create a /// If this is not provided, the widgets app will create a
/// [PlatformRouteInformationProvider] with initial route name equals to /// [PlatformRouteInformationProvider] with initial route name equal to the
/// the [Window.defaultRouteName] by default. /// [dart:ui.PlatformDispatcher.defaultRouteName] by default.
/// ///
/// See also: /// See also:
/// ///
...@@ -525,8 +525,8 @@ class WidgetsApp extends StatefulWidget { ...@@ -525,8 +525,8 @@ class WidgetsApp extends StatefulWidget {
/// {@template flutter.widgets.widgetsApp.initialRoute} /// {@template flutter.widgets.widgetsApp.initialRoute}
/// The name of the first route to show, if a [Navigator] is built. /// The name of the first route to show, if a [Navigator] is built.
/// ///
/// Defaults to [Window.defaultRouteName], which may be overridden by the code /// Defaults to [dart:ui.PlatformDispatcher.defaultRouteName], which may be
/// that launched the application. /// overridden by the code that launched the application.
/// ///
/// If the route name starts with a slash, then it is treated as a "deep link", /// If the route name starts with a slash, then it is treated as a "deep link",
/// and before this route is pushed, the routes leading to this one are pushed /// and before this route is pushed, the routes leading to this one are pushed
...@@ -1113,15 +1113,15 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver { ...@@ -1113,15 +1113,15 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
// If window.defaultRouteName isn't '/', we should assume it was set // If window.defaultRouteName isn't '/', we should assume it was set
// intentionally via `setInitialRoute`, and should override whatever is in // intentionally via `setInitialRoute`, and should override whatever is in
// [widget.initialRoute]. // [widget.initialRoute].
String get _initialRouteName => WidgetsBinding.instance!.window.defaultRouteName != Navigator.defaultRouteName String get _initialRouteName => WidgetsBinding.instance!.platformDispatcher.defaultRouteName != Navigator.defaultRouteName
? WidgetsBinding.instance!.window.defaultRouteName ? WidgetsBinding.instance!.platformDispatcher.defaultRouteName
: widget.initialRoute ?? WidgetsBinding.instance!.window.defaultRouteName; : widget.initialRoute ?? WidgetsBinding.instance!.platformDispatcher.defaultRouteName;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_updateRouting(); _updateRouting();
_locale = _resolveLocales(WidgetsBinding.instance!.window.locales, widget.supportedLocales); _locale = _resolveLocales(WidgetsBinding.instance!.platformDispatcher.locales, widget.supportedLocales);
WidgetsBinding.instance!.addObserver(this); WidgetsBinding.instance!.addObserver(this);
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:developer' as developer; import 'dart:developer' as developer;
import 'dart:ui' show AppLifecycleState, Locale, AccessibilityFeatures, FrameTiming, TimingsCallback; import 'dart:ui' show AppLifecycleState, Locale, AccessibilityFeatures, FrameTiming, TimingsCallback, PlatformDispatcher;
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
...@@ -124,7 +124,8 @@ abstract class WidgetsBindingObserver { ...@@ -124,7 +124,8 @@ abstract class WidgetsBindingObserver {
/// Called when the application's dimensions change. For example, /// Called when the application's dimensions change. For example,
/// when a phone is rotated. /// when a phone is rotated.
/// ///
/// This method exposes notifications from [Window.onMetricsChanged]. /// This method exposes notifications from
/// [dart:ui.PlatformDispatcher.onMetricsChanged].
/// ///
/// {@tool snippet} /// {@tool snippet}
/// ///
...@@ -185,7 +186,8 @@ abstract class WidgetsBindingObserver { ...@@ -185,7 +186,8 @@ abstract class WidgetsBindingObserver {
/// preferences, and it should affect all of the text sizes in the /// preferences, and it should affect all of the text sizes in the
/// application. /// application.
/// ///
/// This method exposes notifications from [Window.onTextScaleFactorChanged]. /// This method exposes notifications from
/// [dart:ui.PlatformDispatcher.onTextScaleFactorChanged].
/// ///
/// {@tool snippet} /// {@tool snippet}
/// ///
...@@ -233,14 +235,16 @@ abstract class WidgetsBindingObserver { ...@@ -233,14 +235,16 @@ abstract class WidgetsBindingObserver {
/// Called when the platform brightness changes. /// Called when the platform brightness changes.
/// ///
/// This method exposes notifications from [Window.onPlatformBrightnessChanged]. /// This method exposes notifications from
/// [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged].
void didChangePlatformBrightness() { } void didChangePlatformBrightness() { }
/// Called when the system tells the app that the user's locale has /// Called when the system tells the app that the user's locale has
/// changed. For example, if the user changes the system language /// changed. For example, if the user changes the system language
/// settings. /// settings.
/// ///
/// This method exposes notifications from [Window.onLocaleChanged]. /// This method exposes notifications from
/// [dart:ui.PlatformDispatcher.onLocaleChanged].
void didChangeLocales(List<Locale>? locale) { } void didChangeLocales(List<Locale>? locale) { }
/// Called when the system puts the app in the background or returns /// Called when the system puts the app in the background or returns
...@@ -261,7 +265,8 @@ abstract class WidgetsBindingObserver { ...@@ -261,7 +265,8 @@ abstract class WidgetsBindingObserver {
/// Called when the system changes the set of currently active accessibility /// Called when the system changes the set of currently active accessibility
/// features. /// features.
/// ///
/// This method exposes notifications from [Window.onAccessibilityFeaturesChanged]. /// This method exposes notifications from
/// [dart:ui.PlatformDispatcher.onAccessibilityFeaturesChanged].
void didChangeAccessibilityFeatures() { } void didChangeAccessibilityFeatures() { }
} }
...@@ -282,8 +287,8 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB ...@@ -282,8 +287,8 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
// properly setup the [defaultBinaryMessenger] instance. // properly setup the [defaultBinaryMessenger] instance.
_buildOwner = BuildOwner(); _buildOwner = BuildOwner();
buildOwner!.onBuildScheduled = _handleBuildScheduled; buildOwner!.onBuildScheduled = _handleBuildScheduled;
window.onLocaleChanged = handleLocaleChanged; platformDispatcher.onLocaleChanged = handleLocaleChanged;
window.onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged; platformDispatcher.onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged;
SystemChannels.navigation.setMethodCallHandler(_handleNavigationInvocation); SystemChannels.navigation.setMethodCallHandler(_handleNavigationInvocation);
FlutterErrorDetails.propertiesTransformers.add(transformDebugCreator); FlutterErrorDetails.propertiesTransformers.add(transformDebugCreator);
} }
...@@ -577,19 +582,19 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB ...@@ -577,19 +582,19 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
/// ///
/// Calls [dispatchLocalesChanged] to notify the binding observers. /// Calls [dispatchLocalesChanged] to notify the binding observers.
/// ///
/// See [Window.onLocaleChanged]. /// See [dart:ui.PlatformDispatcher.onLocaleChanged].
@protected @protected
@mustCallSuper @mustCallSuper
void handleLocaleChanged() { void handleLocaleChanged() {
dispatchLocalesChanged(window.locales); dispatchLocalesChanged(platformDispatcher.locales);
} }
/// Notify all the observers that the locale has changed (using /// Notify all the observers that the locale has changed (using
/// [WidgetsBindingObserver.didChangeLocales]), giving them the /// [WidgetsBindingObserver.didChangeLocales]), giving them the
/// `locales` argument. /// `locales` argument.
/// ///
/// This is called by [handleLocaleChanged] when the [Window.onLocaleChanged] /// This is called by [handleLocaleChanged] when the
/// notification is received. /// [PlatformDispatcher.onLocaleChanged] notification is received.
@protected @protected
@mustCallSuper @mustCallSuper
void dispatchLocalesChanged(List<Locale>? locales) { void dispatchLocalesChanged(List<Locale>? locales) {
...@@ -602,7 +607,7 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB ...@@ -602,7 +607,7 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
/// giving them the `features` argument. /// giving them the `features` argument.
/// ///
/// This is called by [handleAccessibilityFeaturesChanged] when the /// This is called by [handleAccessibilityFeaturesChanged] when the
/// [Window.onAccessibilityFeaturesChanged] notification is received. /// [PlatformDispatcher.onAccessibilityFeaturesChanged] notification is received.
@protected @protected
@mustCallSuper @mustCallSuper
void dispatchAccessibilityFeaturesChanged() { void dispatchAccessibilityFeaturesChanged() {
...@@ -806,11 +811,11 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB ...@@ -806,11 +811,11 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
/// Each frame consists of the following phases: /// Each frame consists of the following phases:
/// ///
/// 1. The animation phase: The [handleBeginFrame] method, which is registered /// 1. The animation phase: The [handleBeginFrame] method, which is registered
/// with [Window.onBeginFrame], invokes all the transient frame callbacks /// with [PlatformDispatcher.onBeginFrame], invokes all the transient frame
/// registered with [scheduleFrameCallback], in /// callbacks registered with [scheduleFrameCallback], in registration order.
/// registration order. This includes all the [Ticker] instances that are /// This includes all the [Ticker] instances that are driving
/// driving [AnimationController] objects, which means all of the active /// [AnimationController] objects, which means all of the active [Animation]
/// [Animation] objects tick at this point. /// objects tick at this point.
/// ///
/// 2. Microtasks: After [handleBeginFrame] returns, any microtasks that got /// 2. Microtasks: After [handleBeginFrame] returns, any microtasks that got
/// scheduled by transient frame callbacks get to run. This typically includes /// scheduled by transient frame callbacks get to run. This typically includes
...@@ -818,9 +823,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB ...@@ -818,9 +823,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
/// completed this frame. /// completed this frame.
/// ///
/// After [handleBeginFrame], [handleDrawFrame], which is registered with /// After [handleBeginFrame], [handleDrawFrame], which is registered with
/// [Window.onDrawFrame], is called, which invokes all the persistent frame /// [PlatformDispatcher.onDrawFrame], is called, which invokes all the
/// callbacks, of which the most notable is this method, [drawFrame], which /// persistent frame callbacks, of which the most notable is this method,
/// proceeds as follows: /// [drawFrame], which proceeds as follows:
/// ///
/// 3. The build phase: All the dirty [Element]s in the widget tree are /// 3. The build phase: All the dirty [Element]s in the widget tree are
/// rebuilt (see [State.build]). See [State.setState] for further details on /// rebuilt (see [State.build]). See [State.setState] for further details on
...@@ -883,9 +888,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB ...@@ -883,9 +888,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
firstFrameCallback = null; firstFrameCallback = null;
_firstFrameCompleter.complete(); _firstFrameCompleter.complete();
}; };
// Callback is only invoked when [Window.render] is called. When // Callback is only invoked when FlutterView.render is called. When
// [sendFramesToEngine] is set to false during the frame, it will not // sendFramesToEngine is set to false during the frame, it will not be
// be called and we need to remove the callback (see below). // called and we need to remove the callback (see below).
SchedulerBinding.instance!.addTimingsCallback(firstFrameCallback!); SchedulerBinding.instance!.addTimingsCallback(firstFrameCallback!);
} }
...@@ -1011,7 +1016,7 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB ...@@ -1011,7 +1016,7 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB
/// method again with the matched locale of the first call omitted from /// method again with the matched locale of the first call omitted from
/// `supportedLocales`. /// `supportedLocales`.
Locale? computePlatformResolvedLocale(List<Locale> supportedLocales) { Locale? computePlatformResolvedLocale(List<Locale> supportedLocales) {
return window.computePlatformResolvedLocale(supportedLocales); return platformDispatcher.computePlatformResolvedLocale(supportedLocales);
} }
} }
......
...@@ -86,7 +86,7 @@ class MediaQueryData { ...@@ -86,7 +86,7 @@ class MediaQueryData {
/// Creates data for a media query with explicit values. /// Creates data for a media query with explicit values.
/// ///
/// Consider using [MediaQueryData.fromWindow] to create data based on a /// Consider using [MediaQueryData.fromWindow] to create data based on a
/// [Window]. /// [dart:ui.PlatformDispatcher].
const MediaQueryData({ const MediaQueryData({
this.size = Size.zero, this.size = Size.zero,
this.devicePixelRatio = 1.0, this.devicePixelRatio = 1.0,
...@@ -124,8 +124,9 @@ class MediaQueryData { ...@@ -124,8 +124,9 @@ class MediaQueryData {
/// If you use this, you should ensure that you also register for /// If you use this, you should ensure that you also register for
/// notifications so that you can update your [MediaQueryData] when the /// notifications so that you can update your [MediaQueryData] when the
/// window's metrics change. For example, see /// window's metrics change. For example, see
/// [WidgetsBindingObserver.didChangeMetrics] or [Window.onMetricsChanged]. /// [WidgetsBindingObserver.didChangeMetrics] or
MediaQueryData.fromWindow(ui.Window window) /// [dart:ui.PlatformDispatcher.onMetricsChanged].
MediaQueryData.fromWindow(ui.SingletonFlutterWindow window)
: size = window.physicalSize / window.devicePixelRatio, : size = window.physicalSize / window.devicePixelRatio,
devicePixelRatio = window.devicePixelRatio, devicePixelRatio = window.devicePixelRatio,
textScaleFactor = window.textScaleFactor, textScaleFactor = window.textScaleFactor,
...@@ -308,7 +309,7 @@ class MediaQueryData { ...@@ -308,7 +309,7 @@ class MediaQueryData {
/// ///
/// See also: /// See also:
/// ///
/// * [Window.accessibilityFeatures], where the setting originates. /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting originates.
final bool accessibleNavigation; final bool accessibleNavigation;
/// Whether the device is inverting the colors of the platform. /// Whether the device is inverting the colors of the platform.
...@@ -317,7 +318,8 @@ class MediaQueryData { ...@@ -317,7 +318,8 @@ class MediaQueryData {
/// ///
/// See also: /// See also:
/// ///
/// * [Window.accessibilityFeatures], where the setting originates. /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting
/// originates.
final bool invertColors; final bool invertColors;
/// Whether the user requested a high contrast between foreground and background /// Whether the user requested a high contrast between foreground and background
...@@ -332,7 +334,8 @@ class MediaQueryData { ...@@ -332,7 +334,8 @@ class MediaQueryData {
/// ///
/// See also: /// See also:
/// ///
/// * [Window.accessibilityFeatures], where the setting originates. /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting
/// originates.
final bool disableAnimations; final bool disableAnimations;
/// Whether the platform is requesting that text be drawn with a bold font /// Whether the platform is requesting that text be drawn with a bold font
...@@ -340,7 +343,8 @@ class MediaQueryData { ...@@ -340,7 +343,8 @@ class MediaQueryData {
/// ///
/// See also: /// See also:
/// ///
/// * [Window.accessibilityFeatures], where the setting originates. /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting
/// originates.
final bool boldText; final bool boldText;
/// Describes the navigation mode requested by the platform. /// Describes the navigation mode requested by the platform.
......
...@@ -1563,7 +1563,7 @@ class Navigator extends StatefulWidget { ...@@ -1563,7 +1563,7 @@ class Navigator extends StatefulWidget {
/// ///
/// See also: /// See also:
/// ///
/// * [dart:ui.Window.defaultRouteName], which reflects the route that the /// * [dart:ui.PlatformDispatcher.defaultRouteName], which reflects the route that the
/// application was started with. /// application was started with.
static const String defaultRouteName = '/'; static const String defaultRouteName = '/';
......
...@@ -31,7 +31,7 @@ import 'media_query.dart'; ...@@ -31,7 +31,7 @@ import 'media_query.dart';
/// intrusions. /// intrusions.
/// * [Padding], for insetting widgets in general. /// * [Padding], for insetting widgets in general.
/// * [MediaQuery], from which the window padding is obtained. /// * [MediaQuery], from which the window padding is obtained.
/// * [dart:ui.Window.padding], which reports the padding from the operating /// * [dart:ui.FlutterView.padding], which reports the padding from the operating
/// system. /// system.
class SafeArea extends StatelessWidget { class SafeArea extends StatelessWidget {
/// Creates a widget that avoids operating system interfaces. /// Creates a widget that avoids operating system interfaces.
...@@ -147,7 +147,7 @@ class SafeArea extends StatelessWidget { ...@@ -147,7 +147,7 @@ class SafeArea extends StatelessWidget {
/// * [SafeArea], for insetting widgets to avoid operating system intrusions. /// * [SafeArea], for insetting widgets to avoid operating system intrusions.
/// * [SliverPadding], for insetting slivers in general. /// * [SliverPadding], for insetting slivers in general.
/// * [MediaQuery], from which the window padding is obtained. /// * [MediaQuery], from which the window padding is obtained.
/// * [dart:ui.Window.padding], which reports the padding from the operating /// * [dart:ui.FlutterView.padding], which reports the padding from the operating
/// system. /// system.
class SliverSafeArea extends StatelessWidget { class SliverSafeArea extends StatelessWidget {
/// Creates a sliver that avoids operating system interfaces. /// Creates a sliver that avoids operating system interfaces.
......
...@@ -87,7 +87,10 @@ class TestBindingBase implements BindingBase { ...@@ -87,7 +87,10 @@ class TestBindingBase implements BindingBase {
void unlocked() {} void unlocked() {}
@override @override
ui.Window get window => throw UnimplementedError(); ui.SingletonFlutterWindow get window => throw UnimplementedError();
@override
ui.PlatformDispatcher get platformDispatcher => throw UnimplementedError();
} }
class TestPaintingBinding extends TestBindingBase with SchedulerBinding, ServicesBinding, PaintingBinding { class TestPaintingBinding extends TestBindingBase with SchedulerBinding, ServicesBinding, PaintingBinding {
......
...@@ -71,7 +71,10 @@ class TestBindingBase implements BindingBase { ...@@ -71,7 +71,10 @@ class TestBindingBase implements BindingBase {
void unlocked() {} void unlocked() {}
@override @override
ui.Window get window => TestWindow(window: ui.window); ui.SingletonFlutterWindow get window => TestWindow(window: ui.window);
@override
ui.PlatformDispatcher get platformDispatcher => TestWindow(window: ui.window).platformDispatcher;
} }
class TestPaintingBinding extends TestBindingBase with SchedulerBinding, ServicesBinding, PaintingBinding {} class TestPaintingBinding extends TestBindingBase with SchedulerBinding, ServicesBinding, PaintingBinding {}
...@@ -19,14 +19,14 @@ void main() { ...@@ -19,14 +19,14 @@ void main() {
// Simulates the engine completing a frame render to trigger the // Simulates the engine completing a frame render to trigger the
// appropriate callback setting [WidgetBinding.firstFrameRasterized]. // appropriate callback setting [WidgetBinding.firstFrameRasterized].
binding.window.onReportTimings!(<FrameTiming>[]); binding.platformDispatcher.onReportTimings!(<FrameTiming>[]);
expect(binding.firstFrameRasterized, isFalse); expect(binding.firstFrameRasterized, isFalse);
binding.allowFirstFrame(); binding.allowFirstFrame();
fakeAsync.flushTimers(); fakeAsync.flushTimers();
// Simulates the engine again. // Simulates the engine again.
binding.window.onReportTimings!(<FrameTiming>[]); binding.platformDispatcher.onReportTimings!(<FrameTiming>[]);
expect(binding.firstFrameRasterized, isTrue); expect(binding.firstFrameRasterized, isTrue);
}); });
}); });
......
...@@ -98,7 +98,8 @@ class TestSemantics { ...@@ -98,7 +98,8 @@ class TestSemantics {
/// set to the appropriate values for direct children of the root node. /// set to the appropriate values for direct children of the root node.
/// ///
/// The [transform] is set to a 3.0 scale (to account for the /// The [transform] is set to a 3.0 scale (to account for the
/// [Window.devicePixelRatio] being 3.0 on the test pseudo-device). /// [dart:ui.FlutterView.devicePixelRatio] being 3.0 on the test
/// pseudo-device).
/// ///
/// The [rect] field is required and has no default. The /// The [rect] field is required and has no default. The
/// [TestSemantics.fullScreen] property may be useful as a value; it describes /// [TestSemantics.fullScreen] property may be useful as a value; it describes
......
...@@ -31,7 +31,7 @@ EnumIndex<OffsetType> _offsetTypeIndex = EnumIndex<OffsetType>(OffsetType.values ...@@ -31,7 +31,7 @@ EnumIndex<OffsetType> _offsetTypeIndex = EnumIndex<OffsetType>(OffsetType.values
/// identified by [finder]. /// identified by [finder].
/// ///
/// The requested offset is returned in logical pixels, which can be translated /// The requested offset is returned in logical pixels, which can be translated
/// to device pixels via [Window.devicePixelRatio]. /// to device pixels via [dart:ui.FlutterView.devicePixelRatio].
class GetOffset extends CommandWithTarget { class GetOffset extends CommandWithTarget {
/// The `finder` looks for an element to get its rect. /// The `finder` looks for an element to get its rect.
GetOffset(SerializableFinder finder, this.offsetType, { Duration? timeout }) : super(finder, timeout: timeout); GetOffset(SerializableFinder finder, this.offsetType, { Duration? timeout }) : super(finder, timeout: timeout);
...@@ -56,7 +56,7 @@ class GetOffset extends CommandWithTarget { ...@@ -56,7 +56,7 @@ class GetOffset extends CommandWithTarget {
/// The result of the [GetOffset] command. /// The result of the [GetOffset] command.
/// ///
/// The offset is provided in logical pixels, which can be translated /// The offset is provided in logical pixels, which can be translated
/// to device pixels via [Window.devicePixelRatio]. /// to device pixels via [dart:ui.FlutterView.devicePixelRatio].
class GetOffsetResult extends Result { class GetOffsetResult extends Result {
/// Creates a result with the offset defined by [dx] and [dy]. /// Creates a result with the offset defined by [dx] and [dy].
const GetOffsetResult({ this.dx = 0.0, this.dy = 0.0}); const GetOffsetResult({ this.dx = 0.0, this.dy = 0.0});
...@@ -64,13 +64,13 @@ class GetOffsetResult extends Result { ...@@ -64,13 +64,13 @@ class GetOffsetResult extends Result {
/// The x component of the offset in logical pixels. /// The x component of the offset in logical pixels.
/// ///
/// The value can be translated to device pixels via /// The value can be translated to device pixels via
/// [Window.devicePixelRatio]. /// [dart:ui.FlutterView.devicePixelRatio].
final double dx; final double dx;
/// The y component of the offset in logical pixels. /// The y component of the offset in logical pixels.
/// ///
/// The value can be translated to device pixels via /// The value can be translated to device pixels via
/// [Window.devicePixelRatio]. /// [dart:ui.FlutterView.devicePixelRatio].
final double dy; final double dy;
/// Deserializes the result from JSON. /// Deserializes the result from JSON.
......
...@@ -227,7 +227,8 @@ abstract class FlutterDriver { ...@@ -227,7 +227,8 @@ abstract class FlutterDriver {
await sendCommand(WaitForCondition(const NoTransientCallbacks(), timeout: timeout)); await sendCommand(WaitForCondition(const NoTransientCallbacks(), timeout: timeout));
} }
/// Waits until the next [Window.onReportTimings] is called. /// Waits until the next [dart:ui.PlatformDispatcher.onReportTimings] is
/// called.
/// ///
/// Use this method to wait for the first frame to be rasterized during the /// Use this method to wait for the first frame to be rasterized during the
/// app launch. /// app launch.
...@@ -246,7 +247,7 @@ abstract class FlutterDriver { ...@@ -246,7 +247,7 @@ abstract class FlutterDriver {
/// Returns the point at the top left of the widget identified by `finder`. /// Returns the point at the top left of the widget identified by `finder`.
/// ///
/// The offset is expressed in logical pixels and can be translated to /// The offset is expressed in logical pixels and can be translated to
/// device pixels via [Window.devicePixelRatio]. /// device pixels via [dart:ui.FlutterView.devicePixelRatio].
Future<DriverOffset> getTopLeft(SerializableFinder finder, { Duration timeout }) async { Future<DriverOffset> getTopLeft(SerializableFinder finder, { Duration timeout }) async {
return _getOffset(finder, OffsetType.topLeft, timeout: timeout); return _getOffset(finder, OffsetType.topLeft, timeout: timeout);
} }
...@@ -254,7 +255,7 @@ abstract class FlutterDriver { ...@@ -254,7 +255,7 @@ abstract class FlutterDriver {
/// Returns the point at the top right of the widget identified by `finder`. /// Returns the point at the top right of the widget identified by `finder`.
/// ///
/// The offset is expressed in logical pixels and can be translated to /// The offset is expressed in logical pixels and can be translated to
/// device pixels via [Window.devicePixelRatio]. /// device pixels via [dart:ui.FlutterView.devicePixelRatio].
Future<DriverOffset> getTopRight(SerializableFinder finder, { Duration timeout }) async { Future<DriverOffset> getTopRight(SerializableFinder finder, { Duration timeout }) async {
return _getOffset(finder, OffsetType.topRight, timeout: timeout); return _getOffset(finder, OffsetType.topRight, timeout: timeout);
} }
...@@ -262,7 +263,7 @@ abstract class FlutterDriver { ...@@ -262,7 +263,7 @@ abstract class FlutterDriver {
/// Returns the point at the bottom left of the widget identified by `finder`. /// Returns the point at the bottom left of the widget identified by `finder`.
/// ///
/// The offset is expressed in logical pixels and can be translated to /// The offset is expressed in logical pixels and can be translated to
/// device pixels via [Window.devicePixelRatio]. /// device pixels via [dart:ui.FlutterView.devicePixelRatio].
Future<DriverOffset> getBottomLeft(SerializableFinder finder, { Duration timeout }) async { Future<DriverOffset> getBottomLeft(SerializableFinder finder, { Duration timeout }) async {
return _getOffset(finder, OffsetType.bottomLeft, timeout: timeout); return _getOffset(finder, OffsetType.bottomLeft, timeout: timeout);
} }
...@@ -270,7 +271,7 @@ abstract class FlutterDriver { ...@@ -270,7 +271,7 @@ abstract class FlutterDriver {
/// Returns the point at the bottom right of the widget identified by `finder`. /// Returns the point at the bottom right of the widget identified by `finder`.
/// ///
/// The offset is expressed in logical pixels and can be translated to /// The offset is expressed in logical pixels and can be translated to
/// device pixels via [Window.devicePixelRatio]. /// device pixels via [dart:ui.FlutterView.devicePixelRatio].
Future<DriverOffset> getBottomRight(SerializableFinder finder, { Duration timeout }) async { Future<DriverOffset> getBottomRight(SerializableFinder finder, { Duration timeout }) async {
return _getOffset(finder, OffsetType.bottomRight, timeout: timeout); return _getOffset(finder, OffsetType.bottomRight, timeout: timeout);
} }
...@@ -278,7 +279,7 @@ abstract class FlutterDriver { ...@@ -278,7 +279,7 @@ abstract class FlutterDriver {
/// Returns the point at the center of the widget identified by `finder`. /// Returns the point at the center of the widget identified by `finder`.
/// ///
/// The offset is expressed in logical pixels and can be translated to /// The offset is expressed in logical pixels and can be translated to
/// device pixels via [Window.devicePixelRatio]. /// device pixels via [dart:ui.FlutterView.devicePixelRatio].
Future<DriverOffset> getCenter(SerializableFinder finder, { Duration timeout }) async { Future<DriverOffset> getCenter(SerializableFinder finder, { Duration timeout }) async {
return _getOffset(finder, OffsetType.center, timeout: timeout); return _getOffset(finder, OffsetType.center, timeout: timeout);
} }
......
...@@ -88,7 +88,7 @@ RenderObject _findRepaintBoundary(Element element) { ...@@ -88,7 +88,7 @@ RenderObject _findRepaintBoundary(Element element) {
return renderObject; return renderObject;
} }
void _renderElement(ui.Window window, RenderObject renderObject) { void _renderElement(ui.FlutterView window, RenderObject renderObject) {
assert(renderObject.debugLayer != null); assert(renderObject.debugLayer != null);
final Layer layer = renderObject.debugLayer!; final Layer layer = renderObject.debugLayer!;
final ui.SceneBuilder sceneBuilder = ui.SceneBuilder(); final ui.SceneBuilder sceneBuilder = ui.SceneBuilder();
......
...@@ -311,7 +311,7 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline { ...@@ -311,7 +311,7 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline {
// Given a pixel buffer based on the physical window size, can we actually // Given a pixel buffer based on the physical window size, can we actually
// get all the data from this node? allow a small delta overlap before // get all the data from this node? allow a small delta overlap before
// culling the node. // culling the node.
bool _isNodeOffScreen(Rect paintBounds, ui.Window window) { bool _isNodeOffScreen(Rect paintBounds, ui.FlutterView window) {
return paintBounds.top < -50.0 return paintBounds.top < -50.0
|| paintBounds.left < -50.0 || paintBounds.left < -50.0
|| paintBounds.bottom > (window.physicalSize.height * window.devicePixelRatio) + 50.0 || paintBounds.bottom > (window.physicalSize.height * window.devicePixelRatio) + 50.0
......
...@@ -1038,9 +1038,9 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -1038,9 +1038,9 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
@override @override
void ensureFrameCallbacksRegistered() { void ensureFrameCallbacksRegistered() {
// Leave Window alone, do nothing. // Leave PlatformDispatcher alone, do nothing.
assert(window.onDrawFrame == null); assert(platformDispatcher.onDrawFrame == null);
assert(window.onBeginFrame == null); assert(platformDispatcher.onBeginFrame == null);
} }
@override @override
...@@ -1326,7 +1326,7 @@ enum LiveTestWidgetsFlutterBindingFramePolicy { ...@@ -1326,7 +1326,7 @@ enum LiveTestWidgetsFlutterBindingFramePolicy {
/// pipeline directly. It tells the binding to entirely ignore requests for a /// pipeline directly. It tells the binding to entirely ignore requests for a
/// frame to be scheduled, while still allowing frames that are pumped /// frame to be scheduled, while still allowing frames that are pumped
/// directly to run (either by using [WidgetTester.pumpBenchmark] or invoking /// directly to run (either by using [WidgetTester.pumpBenchmark] or invoking
/// [Window.onBeginFrame] and [Window.onDrawFrame]). /// [PlatformDispatcher.onBeginFrame] and [PlatformDispatcher.onDrawFrame]).
/// ///
/// This allows all frame requests from the engine to be serviced, and allows /// This allows all frame requests from the engine to be serviced, and allows
/// all frame requests that are artificially triggered to be serviced, but /// all frame requests that are artificially triggered to be serviced, but
...@@ -1684,17 +1684,17 @@ class TestViewConfiguration extends ViewConfiguration { ...@@ -1684,17 +1684,17 @@ class TestViewConfiguration extends ViewConfiguration {
/// If a [window] instance is not provided it defaults to [ui.window]. /// If a [window] instance is not provided it defaults to [ui.window].
factory TestViewConfiguration({ factory TestViewConfiguration({
Size size = _kDefaultTestViewportSize, Size size = _kDefaultTestViewportSize,
ui.Window? window, ui.FlutterView? window,
}) { }) {
return TestViewConfiguration._(size, window ?? ui.window); return TestViewConfiguration._(size, window ?? ui.window);
} }
TestViewConfiguration._(Size size, ui.Window window) TestViewConfiguration._(Size size, ui.FlutterView window)
: _paintMatrix = _getMatrix(size, window.devicePixelRatio, window), : _paintMatrix = _getMatrix(size, window.devicePixelRatio, window),
_hitTestMatrix = _getMatrix(size, 1.0, window), _hitTestMatrix = _getMatrix(size, 1.0, window),
super(size: size); super(size: size);
static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.Window window) { static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.FlutterView window) {
final double inverseRatio = devicePixelRatio / window.devicePixelRatio; final double inverseRatio = devicePixelRatio / window.devicePixelRatio;
final double actualWidth = window.physicalSize.width * inverseRatio; final double actualWidth = window.physicalSize.width * inverseRatio;
final double actualHeight = window.physicalSize.height * inverseRatio; final double actualHeight = window.physicalSize.height * inverseRatio;
...@@ -1756,7 +1756,7 @@ class _LiveTestRenderView extends RenderView { ...@@ -1756,7 +1756,7 @@ class _LiveTestRenderView extends RenderView {
_LiveTestRenderView({ _LiveTestRenderView({
required ViewConfiguration configuration, required ViewConfiguration configuration,
required this.onNeedPaint, required this.onNeedPaint,
required ui.Window window, required ui.FlutterView window,
}) : super(configuration: configuration, window: window); }) : super(configuration: configuration, window: window);
@override @override
......
...@@ -3,16 +3,17 @@ ...@@ -3,16 +3,17 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:typed_data' show ByteData; import 'dart:typed_data' show ByteData;
import 'dart:ui' hide window; import 'dart:ui' as ui hide window;
/// [Window] that wraps another [Window] and allows faking of some properties /// [SingletonFlutterWindow] that wraps another [SingletonFlutterWindow] and
/// for testing purposes. /// allows faking of some properties for testing purposes.
/// ///
/// Tests for certain widgets, e.g., [MaterialApp], might require faking certain /// Tests for certain widgets, e.g., [MaterialApp], might require faking certain
/// properties of a [Window]. [TestWindow] facilitates the faking of these /// properties of a [SingletonFlutterWindow]. [TestWindow] facilitates the
/// properties by overriding the properties of a real [Window] with desired fake /// faking of these properties by overriding the properties of a real
/// values. The binding used within tests, [TestWidgetsFlutterBinding], contains /// [SingletonFlutterWindow] with desired fake values. The binding used within
/// a [TestWindow] that is used by all tests. /// tests, [TestWidgetsFlutterBinding], contains a [TestWindow] that is used by
/// all tests.
/// ///
/// ## Sample Code /// ## Sample Code
/// ///
...@@ -36,21 +37,22 @@ import 'dart:ui' hide window; ...@@ -36,21 +37,22 @@ import 'dart:ui' hide window;
/// therefore any fake values defined in one test will not persist /// therefore any fake values defined in one test will not persist
/// to the next. /// to the next.
/// ///
/// If a test needs to override a real [Window] property and then later /// If a test needs to override a real [SingletonFlutterWindow] property and
/// return to using the real [Window] property, [TestWindow] provides /// then later return to using the real [SingletonFlutterWindow] property,
/// methods to clear each individual test value, e.g., [clearLocaleTestValue()]. /// [TestWindow] provides methods to clear each individual test value, e.g.,
/// [clearLocaleTestValue()].
/// ///
/// To clear all fake test values in a [TestWindow], consider using /// To clear all fake test values in a [TestWindow], consider using
/// [clearAllTestValues()]. /// [clearAllTestValues()].
class TestWindow implements Window { class TestWindow implements ui.SingletonFlutterWindow {
/// Constructs a [TestWindow] that defers all behavior to the given [Window] /// Constructs a [TestWindow] that defers all behavior to the given
/// unless explicitly overridden for test purposes. /// [dart:ui.SingletonFlutterWindow] unless explicitly overridden for test purposes.
TestWindow({ TestWindow({
required Window window, required ui.SingletonFlutterWindow window,
}) : _window = window; }) : _window = window;
/// The [Window] that is wrapped by this [TestWindow]. /// The [dart:ui.SingletonFlutterWindow] that is wrapped by this [TestWindow].
final Window _window; final ui.SingletonFlutterWindow _window;
@override @override
double get devicePixelRatio => _devicePixelRatio ?? _window.devicePixelRatio; double get devicePixelRatio => _devicePixelRatio ?? _window.devicePixelRatio;
...@@ -69,11 +71,11 @@ class TestWindow implements Window { ...@@ -69,11 +71,11 @@ class TestWindow implements Window {
} }
@override @override
Size get physicalSize => _physicalSizeTestValue ?? _window.physicalSize; ui.Size get physicalSize => _physicalSizeTestValue ?? _window.physicalSize;
Size? _physicalSizeTestValue; ui.Size? _physicalSizeTestValue;
/// Hides the real physical size and reports the given [physicalSizeTestValue] /// Hides the real physical size and reports the given [physicalSizeTestValue]
/// instead. /// instead.
set physicalSizeTestValue (Size physicalSizeTestValue) { set physicalSizeTestValue (ui.Size physicalSizeTestValue) {
_physicalSizeTestValue = physicalSizeTestValue; _physicalSizeTestValue = physicalSizeTestValue;
onMetricsChanged?.call(); onMetricsChanged?.call();
} }
...@@ -85,11 +87,11 @@ class TestWindow implements Window { ...@@ -85,11 +87,11 @@ class TestWindow implements Window {
} }
@override @override
WindowPadding get viewInsets => _viewInsetsTestValue ?? _window.viewInsets; ui.WindowPadding get viewInsets => _viewInsetsTestValue ?? _window.viewInsets;
WindowPadding? _viewInsetsTestValue; ui.WindowPadding? _viewInsetsTestValue;
/// Hides the real view insets and reports the given [viewInsetsTestValue] /// Hides the real view insets and reports the given [viewInsetsTestValue]
/// instead. /// instead.
set viewInsetsTestValue(WindowPadding viewInsetsTestValue) { set viewInsetsTestValue(ui.WindowPadding viewInsetsTestValue) {
_viewInsetsTestValue = viewInsetsTestValue; _viewInsetsTestValue = viewInsetsTestValue;
onMetricsChanged?.call(); onMetricsChanged?.call();
} }
...@@ -101,11 +103,11 @@ class TestWindow implements Window { ...@@ -101,11 +103,11 @@ class TestWindow implements Window {
} }
@override @override
WindowPadding get viewPadding => _viewPaddingTestValue ?? _window.padding; ui.WindowPadding get viewPadding => _viewPaddingTestValue ?? _window.padding;
WindowPadding? _viewPaddingTestValue; ui.WindowPadding? _viewPaddingTestValue;
/// Hides the real view padding and reports the given [paddingTestValue] /// Hides the real view padding and reports the given [paddingTestValue]
/// instead. /// instead.
set viewPaddingTestValue(WindowPadding viewPaddingTestValue) { set viewPaddingTestValue(ui.WindowPadding viewPaddingTestValue) {
_viewPaddingTestValue = viewPaddingTestValue; _viewPaddingTestValue = viewPaddingTestValue;
onMetricsChanged?.call(); onMetricsChanged?.call();
} }
...@@ -117,10 +119,10 @@ class TestWindow implements Window { ...@@ -117,10 +119,10 @@ class TestWindow implements Window {
} }
@override @override
WindowPadding get padding => _paddingTestValue ?? _window.padding; ui.WindowPadding get padding => _paddingTestValue ?? _window.padding;
WindowPadding? _paddingTestValue; ui.WindowPadding? _paddingTestValue;
/// Hides the real padding and reports the given [paddingTestValue] instead. /// Hides the real padding and reports the given [paddingTestValue] instead.
set paddingTestValue(WindowPadding paddingTestValue) { set paddingTestValue(ui.WindowPadding paddingTestValue) {
_paddingTestValue = paddingTestValue; _paddingTestValue = paddingTestValue;
onMetricsChanged?.call(); onMetricsChanged?.call();
} }
...@@ -131,10 +133,10 @@ class TestWindow implements Window { ...@@ -131,10 +133,10 @@ class TestWindow implements Window {
} }
@override @override
WindowPadding get systemGestureInsets => _systemGestureInsetsTestValue ?? _window.systemGestureInsets; ui.WindowPadding get systemGestureInsets => _systemGestureInsetsTestValue ?? _window.systemGestureInsets;
WindowPadding? _systemGestureInsetsTestValue; ui.WindowPadding? _systemGestureInsetsTestValue;
/// Hides the real system gesture insets and reports the given [systemGestureInsetsTestValue] instead. /// Hides the real system gesture insets and reports the given [systemGestureInsetsTestValue] instead.
set systemGestureInsetsTestValue(WindowPadding systemGestureInsetsTestValue) { set systemGestureInsetsTestValue(ui.WindowPadding systemGestureInsetsTestValue) {
_systemGestureInsetsTestValue = systemGestureInsetsTestValue; _systemGestureInsetsTestValue = systemGestureInsetsTestValue;
onMetricsChanged?.call(); onMetricsChanged?.call();
} }
...@@ -145,17 +147,18 @@ class TestWindow implements Window { ...@@ -145,17 +147,18 @@ class TestWindow implements Window {
} }
@override @override
VoidCallback? get onMetricsChanged => _window.onMetricsChanged; ui.VoidCallback? get onMetricsChanged => platformDispatcher.onMetricsChanged;
@override @override
set onMetricsChanged(VoidCallback? callback) { set onMetricsChanged(ui.VoidCallback? callback) {
_window.onMetricsChanged = callback; platformDispatcher.onMetricsChanged = callback;
} }
@override @override
Locale? get locale => _localeTestValue ?? _window.locale; // ignore: unnecessary_non_null_assertion
Locale? _localeTestValue; ui.Locale get locale => _localeTestValue ?? platformDispatcher.locale!;
ui.Locale? _localeTestValue;
/// Hides the real locale and reports the given [localeTestValue] instead. /// Hides the real locale and reports the given [localeTestValue] instead.
set localeTestValue(Locale localeTestValue) { set localeTestValue(ui.Locale localeTestValue) {
_localeTestValue = localeTestValue; _localeTestValue = localeTestValue;
onLocaleChanged?.call(); onLocaleChanged?.call();
} }
...@@ -166,10 +169,11 @@ class TestWindow implements Window { ...@@ -166,10 +169,11 @@ class TestWindow implements Window {
} }
@override @override
List<Locale>? get locales => _localesTestValue ?? _window.locales; // ignore: unnecessary_non_null_assertion
List<Locale>? _localesTestValue; List<ui.Locale> get locales => _localesTestValue ?? platformDispatcher.locales!;
List<ui.Locale>? _localesTestValue;
/// Hides the real locales and reports the given [localesTestValue] instead. /// Hides the real locales and reports the given [localesTestValue] instead.
set localesTestValue(List<Locale> localesTestValue) { set localesTestValue(List<ui.Locale> localesTestValue) {
_localesTestValue = localesTestValue; _localesTestValue = localesTestValue;
onLocaleChanged?.call(); onLocaleChanged?.call();
} }
...@@ -180,10 +184,10 @@ class TestWindow implements Window { ...@@ -180,10 +184,10 @@ class TestWindow implements Window {
} }
@override @override
VoidCallback? get onLocaleChanged => _window.onLocaleChanged; ui.VoidCallback? get onLocaleChanged => platformDispatcher.onLocaleChanged;
@override @override
set onLocaleChanged(VoidCallback? callback) { set onLocaleChanged(ui.VoidCallback? callback) {
_window.onLocaleChanged = callback; platformDispatcher.onLocaleChanged = callback;
} }
@override @override
...@@ -195,7 +199,7 @@ class TestWindow implements Window { ...@@ -195,7 +199,7 @@ class TestWindow implements Window {
} }
@override @override
double get textScaleFactor => _textScaleFactorTestValue ?? _window.textScaleFactor; double get textScaleFactor => _textScaleFactorTestValue ?? platformDispatcher.textScaleFactor;
double? _textScaleFactorTestValue; double? _textScaleFactorTestValue;
/// Hides the real text scale factor and reports the given /// Hides the real text scale factor and reports the given
/// [textScaleFactorTestValue] instead. /// [textScaleFactorTestValue] instead.
...@@ -211,17 +215,17 @@ class TestWindow implements Window { ...@@ -211,17 +215,17 @@ class TestWindow implements Window {
} }
@override @override
Brightness get platformBrightness => _platformBrightnessTestValue ?? _window.platformBrightness; ui.Brightness get platformBrightness => _platformBrightnessTestValue ?? platformDispatcher.platformBrightness;
Brightness? _platformBrightnessTestValue; ui.Brightness? _platformBrightnessTestValue;
@override @override
VoidCallback? get onPlatformBrightnessChanged => _window.onPlatformBrightnessChanged; ui.VoidCallback? get onPlatformBrightnessChanged => platformDispatcher.onPlatformBrightnessChanged;
@override @override
set onPlatformBrightnessChanged(VoidCallback? callback) { set onPlatformBrightnessChanged(ui.VoidCallback? callback) {
_window.onPlatformBrightnessChanged = callback; platformDispatcher.onPlatformBrightnessChanged = callback;
} }
/// Hides the real text scale factor and reports the given /// Hides the real text scale factor and reports the given
/// [platformBrightnessTestValue] instead. /// [platformBrightnessTestValue] instead.
set platformBrightnessTestValue(Brightness platformBrightnessTestValue) { set platformBrightnessTestValue(ui.Brightness platformBrightnessTestValue) {
_platformBrightnessTestValue = platformBrightnessTestValue; _platformBrightnessTestValue = platformBrightnessTestValue;
onPlatformBrightnessChanged?.call(); onPlatformBrightnessChanged?.call();
} }
...@@ -233,7 +237,7 @@ class TestWindow implements Window { ...@@ -233,7 +237,7 @@ class TestWindow implements Window {
} }
@override @override
bool get alwaysUse24HourFormat => _alwaysUse24HourFormatTestValue ?? _window.alwaysUse24HourFormat; bool get alwaysUse24HourFormat => _alwaysUse24HourFormatTestValue ?? platformDispatcher.alwaysUse24HourFormat;
bool? _alwaysUse24HourFormatTestValue; bool? _alwaysUse24HourFormatTestValue;
/// Hides the real clock format and reports the given /// Hides the real clock format and reports the given
/// [alwaysUse24HourFormatTestValue] instead. /// [alwaysUse24HourFormatTestValue] instead.
...@@ -247,42 +251,42 @@ class TestWindow implements Window { ...@@ -247,42 +251,42 @@ class TestWindow implements Window {
} }
@override @override
VoidCallback? get onTextScaleFactorChanged => _window.onTextScaleFactorChanged; ui.VoidCallback? get onTextScaleFactorChanged => platformDispatcher.onTextScaleFactorChanged;
@override @override
set onTextScaleFactorChanged(VoidCallback? callback) { set onTextScaleFactorChanged(ui.VoidCallback? callback) {
_window.onTextScaleFactorChanged = callback; platformDispatcher.onTextScaleFactorChanged = callback;
} }
@override @override
FrameCallback? get onBeginFrame => _window.onBeginFrame; ui.FrameCallback? get onBeginFrame => platformDispatcher.onBeginFrame;
@override @override
set onBeginFrame(FrameCallback? callback) { set onBeginFrame(ui.FrameCallback? callback) {
_window.onBeginFrame = callback; platformDispatcher.onBeginFrame = callback;
} }
@override @override
VoidCallback? get onDrawFrame => _window.onDrawFrame; ui.VoidCallback? get onDrawFrame => platformDispatcher.onDrawFrame;
@override @override
set onDrawFrame(VoidCallback? callback) { set onDrawFrame(ui.VoidCallback? callback) {
_window.onDrawFrame = callback; platformDispatcher.onDrawFrame = callback;
} }
@override @override
TimingsCallback? get onReportTimings => _window.onReportTimings; ui.TimingsCallback? get onReportTimings => platformDispatcher.onReportTimings;
@override @override
set onReportTimings(TimingsCallback? callback) { set onReportTimings(ui.TimingsCallback? callback) {
_window.onReportTimings = callback; platformDispatcher.onReportTimings = callback;
} }
@override @override
PointerDataPacketCallback? get onPointerDataPacket => _window.onPointerDataPacket; ui.PointerDataPacketCallback? get onPointerDataPacket => platformDispatcher.onPointerDataPacket;
@override @override
set onPointerDataPacket(PointerDataPacketCallback? callback) { set onPointerDataPacket(ui.PointerDataPacketCallback? callback) {
_window.onPointerDataPacket = callback; platformDispatcher.onPointerDataPacket = callback;
} }
@override @override
String get defaultRouteName => _defaultRouteNameTestValue ?? _window.defaultRouteName; String get defaultRouteName => _defaultRouteNameTestValue ?? platformDispatcher.defaultRouteName;
String? _defaultRouteNameTestValue; String? _defaultRouteNameTestValue;
/// Hides the real default route name and reports the given /// Hides the real default route name and reports the given
/// [defaultRouteNameTestValue] instead. /// [defaultRouteNameTestValue] instead.
...@@ -297,16 +301,16 @@ class TestWindow implements Window { ...@@ -297,16 +301,16 @@ class TestWindow implements Window {
@override @override
void scheduleFrame() { void scheduleFrame() {
_window.scheduleFrame(); platformDispatcher.scheduleFrame();
} }
@override @override
void render(Scene scene) { void render(ui.Scene scene) {
_window.render(scene); _window.render(scene);
} }
@override @override
bool get semanticsEnabled => _semanticsEnabledTestValue ?? _window.semanticsEnabled; bool get semanticsEnabled => _semanticsEnabledTestValue ?? platformDispatcher.semanticsEnabled;
bool? _semanticsEnabledTestValue; bool? _semanticsEnabledTestValue;
/// Hides the real semantics enabled and reports the given /// Hides the real semantics enabled and reports the given
/// [semanticsEnabledTestValue] instead. /// [semanticsEnabledTestValue] instead.
...@@ -322,25 +326,25 @@ class TestWindow implements Window { ...@@ -322,25 +326,25 @@ class TestWindow implements Window {
} }
@override @override
VoidCallback? get onSemanticsEnabledChanged => _window.onSemanticsEnabledChanged; ui.VoidCallback? get onSemanticsEnabledChanged => platformDispatcher.onSemanticsEnabledChanged;
@override @override
set onSemanticsEnabledChanged(VoidCallback? callback) { set onSemanticsEnabledChanged(ui.VoidCallback? callback) {
_window.onSemanticsEnabledChanged = callback; platformDispatcher.onSemanticsEnabledChanged = callback;
} }
@override @override
SemanticsActionCallback? get onSemanticsAction => _window.onSemanticsAction; ui.SemanticsActionCallback? get onSemanticsAction => platformDispatcher.onSemanticsAction;
@override @override
set onSemanticsAction(SemanticsActionCallback? callback) { set onSemanticsAction(ui.SemanticsActionCallback? callback) {
_window.onSemanticsAction = callback; platformDispatcher.onSemanticsAction = callback;
} }
@override @override
AccessibilityFeatures get accessibilityFeatures => _accessibilityFeaturesTestValue ?? _window.accessibilityFeatures; ui.AccessibilityFeatures get accessibilityFeatures => _accessibilityFeaturesTestValue ?? platformDispatcher.accessibilityFeatures;
AccessibilityFeatures? _accessibilityFeaturesTestValue; ui.AccessibilityFeatures? _accessibilityFeaturesTestValue;
/// Hides the real accessibility features and reports the given /// Hides the real accessibility features and reports the given
/// [accessibilityFeaturesTestValue] instead. /// [accessibilityFeaturesTestValue] instead.
set accessibilityFeaturesTestValue(AccessibilityFeatures accessibilityFeaturesTestValue) { set accessibilityFeaturesTestValue(ui.AccessibilityFeatures accessibilityFeaturesTestValue) {
_accessibilityFeaturesTestValue = accessibilityFeaturesTestValue; _accessibilityFeaturesTestValue = accessibilityFeaturesTestValue;
onAccessibilityFeaturesChanged?.call(); onAccessibilityFeaturesChanged?.call();
} }
...@@ -352,41 +356,44 @@ class TestWindow implements Window { ...@@ -352,41 +356,44 @@ class TestWindow implements Window {
} }
@override @override
VoidCallback? get onAccessibilityFeaturesChanged => _window.onAccessibilityFeaturesChanged; ui.VoidCallback? get onAccessibilityFeaturesChanged => platformDispatcher.onAccessibilityFeaturesChanged;
@override @override
set onAccessibilityFeaturesChanged(VoidCallback? callback) { set onAccessibilityFeaturesChanged(ui.VoidCallback? callback) {
_window.onAccessibilityFeaturesChanged = callback; platformDispatcher.onAccessibilityFeaturesChanged = callback;
} }
@override @override
void updateSemantics(SemanticsUpdate update) { void updateSemantics(ui.SemanticsUpdate update) {
_window.updateSemantics(update); platformDispatcher.updateSemantics(update);
} }
@override @override
void setIsolateDebugName(String name) { void setIsolateDebugName(String name) {
_window.setIsolateDebugName(name); platformDispatcher.setIsolateDebugName(name);
} }
@override @override
void sendPlatformMessage( void sendPlatformMessage(
String name, String name,
ByteData? data, ByteData? data,
PlatformMessageResponseCallback? callback, ui.PlatformMessageResponseCallback? callback,
) { ) {
_window.sendPlatformMessage(name, data, callback); platformDispatcher.sendPlatformMessage(name, data, callback);
} }
@override @override
PlatformMessageCallback? get onPlatformMessage => _window.onPlatformMessage; ui.PlatformMessageCallback? get onPlatformMessage => platformDispatcher.onPlatformMessage;
@override @override
set onPlatformMessage(PlatformMessageCallback? callback) { set onPlatformMessage(ui.PlatformMessageCallback? callback) {
_window.onPlatformMessage = callback; platformDispatcher.onPlatformMessage = callback;
} }
@override
ui.PlatformDispatcher get platformDispatcher => _window.platformDispatcher;
/// Delete any test value properties that have been set on this [TestWindow] /// Delete any test value properties that have been set on this [TestWindow]
/// and return to reporting the real [Window] values for all [Window] /// and return to reporting the real [SingletonFlutterWindow] values for all
/// properties. /// [SingletonFlutterWindow] properties.
/// ///
/// If desired, clearing of properties can be done on an individual basis, /// If desired, clearing of properties can be done on an individual basis,
/// e.g., [clearLocaleTestValue()]. /// e.g., [clearLocaleTestValue()].
......
...@@ -1100,7 +1100,7 @@ void handleSymlinkException(FileSystemException e, { ...@@ -1100,7 +1100,7 @@ void handleSymlinkException(FileSystemException e, {
if (platform.isWindows && (e.osError?.errorCode ?? 0) == 1314) { if (platform.isWindows && (e.osError?.errorCode ?? 0) == 1314) {
final String versionString = RegExp(r'[\d.]+').firstMatch(os.name)?.group(0); final String versionString = RegExp(r'[\d.]+').firstMatch(os.name)?.group(0);
final Version version = Version.parse(versionString); final Version version = Version.parse(versionString);
// Window 10 14972 is the oldest version that allows creating symlinks // Windows 10 14972 is the oldest version that allows creating symlinks
// just by enabling developer mode; before that it requires running the // just by enabling developer mode; before that it requires running the
// terminal as Administrator. // terminal as Administrator.
// https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/ // https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment