Unverified Commit a599c08c authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Remvoe last few references to window singleton (#122644)

Remove last few references to window singleton
parent 0ba64488
...@@ -288,7 +288,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H ...@@ -288,7 +288,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
// We convert pointer data to logical pixels so that e.g. the touch slop can be // We convert pointer data to logical pixels so that e.g. the touch slop can be
// defined in a device-independent manner. // defined in a device-independent manner.
try { try {
_pendingPointerEvents.addAll(PointerEventConverter.expand(packet.data, window.devicePixelRatio)); _pendingPointerEvents.addAll(PointerEventConverter.expand(packet.data, platformDispatcher.implicitView!.devicePixelRatio));
if (!locked) { if (!locked) {
_flushPointerEventQueue(); _flushPointerEventQueue();
} }
......
...@@ -212,7 +212,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture ...@@ -212,7 +212,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
_debugIsRenderViewInitialized = true; _debugIsRenderViewInitialized = true;
return true; return true;
}()); }());
renderView = RenderView(configuration: createViewConfiguration(), window: window); renderView = RenderView(configuration: createViewConfiguration(), window: platformDispatcher.implicitView!);
renderView.prepareInitialFrame(); renderView.prepareInitialFrame();
} }
bool _debugIsRenderViewInitialized = false; bool _debugIsRenderViewInitialized = false;
...@@ -300,9 +300,10 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture ...@@ -300,9 +300,10 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
/// this to force the display into 800x600 when a test is run on the device /// this to force the display into 800x600 when a test is run on the device
/// using `flutter run`. /// using `flutter run`.
ViewConfiguration createViewConfiguration() { ViewConfiguration createViewConfiguration() {
final double devicePixelRatio = window.devicePixelRatio; final FlutterView view = platformDispatcher.implicitView!;
final double devicePixelRatio = view.devicePixelRatio;
return ViewConfiguration( return ViewConfiguration(
size: window.physicalSize / devicePixelRatio, size: view.physicalSize / devicePixelRatio,
devicePixelRatio: devicePixelRatio, devicePixelRatio: devicePixelRatio,
); );
} }
......
...@@ -140,7 +140,7 @@ void main() { ...@@ -140,7 +140,7 @@ void main() {
expect(events.length, 1); expect(events.length, 1);
expect(events[0], isA<PointerDownEvent>()); expect(events[0], isA<PointerDownEvent>());
expect(events[0].timeStamp, binding.frameTime! + samplingOffset); expect(events[0].timeStamp, binding.frameTime! + samplingOffset);
expect(events[0].position, Offset(0.0 / GestureBinding.instance.window.devicePixelRatio, 0.0)); expect(events[0].position, Offset(0.0 / _devicePixelRatio, 0.0));
// Second frame callback should have been requested. // Second frame callback should have been requested.
callback = binding.postFrameCallback; callback = binding.postFrameCallback;
...@@ -155,8 +155,8 @@ void main() { ...@@ -155,8 +155,8 @@ void main() {
expect(events.length, 2); expect(events.length, 2);
expect(events[1], isA<PointerMoveEvent>()); expect(events[1], isA<PointerMoveEvent>());
expect(events[1].timeStamp, binding.frameTime! + samplingOffset); expect(events[1].timeStamp, binding.frameTime! + samplingOffset);
expect(events[1].position, Offset(10.0 / GestureBinding.instance.window.devicePixelRatio, 0.0)); expect(events[1].position, Offset(10.0 / _devicePixelRatio, 0.0));
expect(events[1].delta, Offset(10.0 / GestureBinding.instance.window.devicePixelRatio, 0.0)); expect(events[1].delta, Offset(10.0 / _devicePixelRatio, 0.0));
// Verify that resampling continues without a frame callback. // Verify that resampling continues without a frame callback.
async.elapse(frameInterval * 1.5); async.elapse(frameInterval * 1.5);
...@@ -183,3 +183,5 @@ void main() { ...@@ -183,3 +183,5 @@ void main() {
GestureBinding.instance.resamplingEnabled = false; GestureBinding.instance.resamplingEnabled = false;
}); });
} }
double get _devicePixelRatio => GestureBinding.instance.platformDispatcher.implicitView!.devicePixelRatio;
...@@ -18,7 +18,6 @@ void main() { ...@@ -18,7 +18,6 @@ void main() {
final List<TestMenu> opened = <TestMenu>[]; final List<TestMenu> opened = <TestMenu>[];
final List<TestMenu> closed = <TestMenu>[]; final List<TestMenu> closed = <TestMenu>[];
final GlobalKey menuItemKey = GlobalKey(); final GlobalKey menuItemKey = GlobalKey();
late Size defaultSize;
void onPressed(TestMenu item) { void onPressed(TestMenu item) {
selected.add(item); selected.add(item);
...@@ -36,11 +35,6 @@ void main() { ...@@ -36,11 +35,6 @@ void main() {
focusedMenu = (primaryFocus?.debugLabel ?? primaryFocus).toString(); focusedMenu = (primaryFocus?.debugLabel ?? primaryFocus).toString();
} }
setUpAll(() {
final MediaQueryData mediaQueryData = MediaQueryData.fromView(TestWidgetsFlutterBinding.instance.window);
defaultSize = mediaQueryData.size;
});
setUp(() { setUp(() {
focusedMenu = null; focusedMenu = null;
selected.clear(); selected.clear();
...@@ -53,7 +47,7 @@ void main() { ...@@ -53,7 +47,7 @@ void main() {
Future<void> changeSurfaceSize(WidgetTester tester, Size size) async { Future<void> changeSurfaceSize(WidgetTester tester, Size size) async {
await tester.binding.setSurfaceSize(size); await tester.binding.setSurfaceSize(size);
addTearDown(() async { addTearDown(() async {
await tester.binding.setSurfaceSize(defaultSize); await tester.binding.setSurfaceSize(null);
}); });
} }
...@@ -1395,7 +1389,7 @@ void main() { ...@@ -1395,7 +1389,7 @@ void main() {
testWidgets('menus close on view size change', (WidgetTester tester) async { testWidgets('menus close on view size change', (WidgetTester tester) async {
final ScrollController scrollController = ScrollController(); final ScrollController scrollController = ScrollController();
final MediaQueryData mediaQueryData = MediaQueryData.fromView(tester.binding.window); final MediaQueryData mediaQueryData = MediaQueryData.fromView(tester.view);
Widget build(Size size) { Widget build(Size size) {
return MaterialApp( return MaterialApp(
......
...@@ -438,10 +438,11 @@ ui.PointerData _pointerData( ...@@ -438,10 +438,11 @@ ui.PointerData _pointerData(
int device = 0, int device = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse, PointerDeviceKind kind = PointerDeviceKind.mouse,
}) { }) {
final double devicePixelRatio = RendererBinding.instance.platformDispatcher.implicitView!.devicePixelRatio;
return ui.PointerData( return ui.PointerData(
change: change, change: change,
physicalX: logicalPosition.dx * RendererBinding.instance.window.devicePixelRatio, physicalX: logicalPosition.dx * devicePixelRatio,
physicalY: logicalPosition.dy * RendererBinding.instance.window.devicePixelRatio, physicalY: logicalPosition.dy * devicePixelRatio,
kind: kind, kind: kind,
device: device, device: device,
); );
......
...@@ -592,10 +592,11 @@ ui.PointerData _pointerData( ...@@ -592,10 +592,11 @@ ui.PointerData _pointerData(
int device = 0, int device = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse, PointerDeviceKind kind = PointerDeviceKind.mouse,
}) { }) {
final double devicePixelRatio = RendererBinding.instance.platformDispatcher.implicitView!.devicePixelRatio;
return ui.PointerData( return ui.PointerData(
change: change, change: change,
physicalX: logicalPosition.dx * RendererBinding.instance.window.devicePixelRatio, physicalX: logicalPosition.dx * devicePixelRatio,
physicalY: logicalPosition.dy * RendererBinding.instance.window.devicePixelRatio, physicalY: logicalPosition.dy * devicePixelRatio,
kind: kind, kind: kind,
device: device, device: device,
); );
......
...@@ -305,12 +305,13 @@ ui.PointerData _pointerData( ...@@ -305,12 +305,13 @@ ui.PointerData _pointerData(
PointerDeviceKind kind = PointerDeviceKind.mouse, PointerDeviceKind kind = PointerDeviceKind.mouse,
int pointer = 0, int pointer = 0,
}) { }) {
final double devicePixelRatio = RendererBinding.instance.platformDispatcher.implicitView!.devicePixelRatio;
return ui.PointerData( return ui.PointerData(
pointerIdentifier: pointer, pointerIdentifier: pointer,
embedderId: pointer, embedderId: pointer,
change: change, change: change,
physicalX: logicalPosition.dx * RendererBinding.instance.window.devicePixelRatio, physicalX: logicalPosition.dx * devicePixelRatio,
physicalY: logicalPosition.dy * RendererBinding.instance.window.devicePixelRatio, physicalY: logicalPosition.dy * devicePixelRatio,
kind: kind, kind: kind,
device: device, device: device,
); );
......
...@@ -1098,7 +1098,7 @@ void main() { ...@@ -1098,7 +1098,7 @@ void main() {
}); });
testWidgets('MediaQueryData.fromWindow is created using window values', (WidgetTester tester) async { testWidgets('MediaQueryData.fromWindow is created using window values', (WidgetTester tester) async {
final MediaQueryData windowData = MediaQueryData.fromWindow(tester.binding.window); final MediaQueryData windowData = MediaQueryData.fromWindow(tester.view);
late MediaQueryData fromWindowData; late MediaQueryData fromWindowData;
await tester.pumpWidget( await tester.pumpWidget(
......
...@@ -206,7 +206,7 @@ void main() { ...@@ -206,7 +206,7 @@ void main() {
const MaterialPage<void> page = MaterialPage<void>(child: Text('page')); const MaterialPage<void> page = MaterialPage<void>(child: Text('page'));
await tester.pumpWidget( await tester.pumpWidget(
MediaQuery( MediaQuery(
data: MediaQueryData.fromView(tester.binding.window), data: MediaQueryData.fromView(tester.view),
child: Directionality( child: Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Navigator( child: Navigator(
...@@ -221,7 +221,7 @@ void main() { ...@@ -221,7 +221,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MediaQuery( MediaQuery(
data: MediaQueryData.fromView(tester.binding.window), data: MediaQueryData.fromView(tester.view),
child: Directionality( child: Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: Navigator( child: Navigator(
...@@ -2810,7 +2810,7 @@ void main() { ...@@ -2810,7 +2810,7 @@ void main() {
await tester.pumpWidget( await tester.pumpWidget(
MediaQuery( MediaQuery(
data: MediaQueryData.fromView(tester.binding.window), data: MediaQueryData.fromView(tester.view),
child: Localizations( child: Localizations(
locale: const Locale('en', 'US'), locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[ delegates: const <LocalizationsDelegate<dynamic>>[
...@@ -2849,7 +2849,7 @@ void main() { ...@@ -2849,7 +2849,7 @@ void main() {
}; };
await tester.pumpWidget( await tester.pumpWidget(
MediaQuery( MediaQuery(
data: MediaQueryData.fromView(tester.binding.window), data: MediaQueryData.fromView(tester.view),
child: Localizations( child: Localizations(
locale: const Locale('en', 'US'), locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[ delegates: const <LocalizationsDelegate<dynamic>>[
......
...@@ -96,7 +96,7 @@ void main() { ...@@ -96,7 +96,7 @@ void main() {
Widget deepChild = Container(); Widget deepChild = Container();
await tester.pumpWidget(MediaQuery( await tester.pumpWidget(MediaQuery(
data: MediaQueryData.fromView(tester.binding.window), data: MediaQueryData.fromView(tester.view),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
StatefulBuilder(builder: (BuildContext context, StateSetter setState) { StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
......
...@@ -34,7 +34,7 @@ Future<void> performTest(WidgetTester tester, bool maintainState) async { ...@@ -34,7 +34,7 @@ Future<void> performTest(WidgetTester tester, bool maintainState) async {
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: MediaQuery( child: MediaQuery(
data: MediaQueryData.fromView(tester.binding.window), data: MediaQueryData.fromView(tester.view),
child: Navigator( child: Navigator(
key: navigatorKey, key: navigatorKey,
onGenerateRoute: (RouteSettings settings) { onGenerateRoute: (RouteSettings settings) {
......
...@@ -301,7 +301,7 @@ void main() { ...@@ -301,7 +301,7 @@ void main() {
child: Directionality( child: Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: MediaQuery( child: MediaQuery(
data: MediaQueryData.fromView(tester.binding.window), data: MediaQueryData.fromView(tester.view),
child: Material( child: Material(
child: Center( child: Center(
child: Slider( child: Slider(
......
...@@ -58,12 +58,13 @@ class MatchesGoldenFile extends AsyncMatcher { ...@@ -58,12 +58,13 @@ class MatchesGoldenFile extends AsyncMatcher {
final Size size = renderObject.paintBounds.size; final Size size = renderObject.paintBounds.size;
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.instance; final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.instance;
final Element e = binding.renderViewElement!; final Element e = binding.renderViewElement!;
final ui.FlutterView view = binding.platformDispatcher.implicitView!;
// Unlike `flutter_tester`, we don't have the ability to render an element // Unlike `flutter_tester`, we don't have the ability to render an element
// to an image directly. Instead, we will use `window.render()` to render // to an image directly. Instead, we will use `window.render()` to render
// only the element being requested, and send a request to the test server // only the element being requested, and send a request to the test server
// requesting it to take a screenshot through the browser's debug interface. // requesting it to take a screenshot through the browser's debug interface.
_renderElement(binding.window, renderObject); _renderElement(view, renderObject);
final String? result = await binding.runAsync<String?>(() async { final String? result = await binding.runAsync<String?>(() async {
if (autoUpdateGoldenFiles) { if (autoUpdateGoldenFiles) {
await webGoldenComparator.update(size.width, size.height, key); await webGoldenComparator.update(size.width, size.height, key);
...@@ -76,7 +77,7 @@ class MatchesGoldenFile extends AsyncMatcher { ...@@ -76,7 +77,7 @@ class MatchesGoldenFile extends AsyncMatcher {
return ex.message; return ex.message;
} }
}, additionalTime: const Duration(seconds: 22)); }, additionalTime: const Duration(seconds: 22));
_renderElement(binding.window, _findRepaintBoundary(e)); _renderElement(view, _findRepaintBoundary(e));
return result; return result;
} }
......
...@@ -485,8 +485,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase ...@@ -485,8 +485,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
@override @override
ViewConfiguration createViewConfiguration() { ViewConfiguration createViewConfiguration() {
final double devicePixelRatio = window.devicePixelRatio; final FlutterView view = platformDispatcher.implicitView!;
final Size size = _surfaceSize ?? window.physicalSize / devicePixelRatio; final double devicePixelRatio = view.devicePixelRatio;
final Size size = _surfaceSize ?? view.physicalSize / devicePixelRatio;
return ViewConfiguration( return ViewConfiguration(
size: size, size: size,
devicePixelRatio: devicePixelRatio, devicePixelRatio: devicePixelRatio,
...@@ -1730,7 +1731,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -1730,7 +1731,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
renderView = _LiveTestRenderView( renderView = _LiveTestRenderView(
configuration: createViewConfiguration(), configuration: createViewConfiguration(),
onNeedPaint: _handleViewNeedsPaint, onNeedPaint: _handleViewNeedsPaint,
window: window, window: platformDispatcher.implicitView!,
); );
renderView.prepareInitialFrame(); renderView.prepareInitialFrame();
} }
...@@ -1921,7 +1922,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { ...@@ -1921,7 +1922,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
ViewConfiguration createViewConfiguration() { ViewConfiguration createViewConfiguration() {
return TestViewConfiguration.fromView( return TestViewConfiguration.fromView(
size: _surfaceSize ?? _kDefaultTestViewportSize, size: _surfaceSize ?? _kDefaultTestViewportSize,
view: window, view: platformDispatcher.implicitView!,
); );
} }
......
...@@ -7,8 +7,9 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -7,8 +7,9 @@ import 'package:flutter_test/flutter_test.dart';
void main() { void main() {
testWidgets('Fails correctly with configured screen size - small', (WidgetTester tester) async { testWidgets('Fails correctly with configured screen size - small', (WidgetTester tester) async {
tester.binding.window.devicePixelRatioTestValue = 1.2; tester.view.devicePixelRatio = 1.2;
tester.binding.window.physicalSizeTestValue = const Size(250, 300); tester.view.physicalSize = const Size(250, 300);
addTearDown(tester.view.reset);
final Widget invalidButton = ElevatedButton( final Widget invalidButton = ElevatedButton(
onPressed: () {}, onPressed: () {},
...@@ -25,8 +26,9 @@ void main() { ...@@ -25,8 +26,9 @@ void main() {
}); });
testWidgets('Fails correctly with configured screen size - large', (WidgetTester tester) async { testWidgets('Fails correctly with configured screen size - large', (WidgetTester tester) async {
tester.binding.window.devicePixelRatioTestValue = 4.2; tester.view.devicePixelRatio = 4.2;
tester.binding.window.physicalSizeTestValue = const Size(2500, 3000); tester.view.physicalSize = const Size(2500, 3000);
addTearDown(tester.view.reset);
final Widget invalidButton = ElevatedButton( final Widget invalidButton = ElevatedButton(
onPressed: () {}, onPressed: () {},
......
...@@ -71,8 +71,8 @@ void main() { ...@@ -71,8 +71,8 @@ void main() {
testWidgets('setSurfaceSize works', (WidgetTester tester) async { testWidgets('setSurfaceSize works', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: Center(child: Text('Test')))); await tester.pumpWidget(const MaterialApp(home: Center(child: Text('Test'))));
final Size windowCenter = tester.binding.window.physicalSize / final Size windowCenter = tester.view.physicalSize /
tester.binding.window.devicePixelRatio / tester.view.devicePixelRatio /
2; 2;
final double windowCenterX = windowCenter.width; final double windowCenterX = windowCenter.width;
final double windowCenterY = windowCenter.height; final double windowCenterY = windowCenter.height;
......
...@@ -34,8 +34,8 @@ void main() { ...@@ -34,8 +34,8 @@ void main() {
), ),
); );
final Size windowCenter = tester.binding.window.physicalSize / final Size windowCenter = tester.view.physicalSize /
tester.binding.window.devicePixelRatio / tester.view.devicePixelRatio /
2; 2;
final double windowCenterX = windowCenter.width; final double windowCenterX = windowCenter.width;
final double windowCenterY = windowCenter.height; final double windowCenterY = windowCenter.height;
......
...@@ -118,11 +118,12 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab ...@@ -118,11 +118,12 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
@override @override
ViewConfiguration createViewConfiguration() { ViewConfiguration createViewConfiguration() {
final double devicePixelRatio = window.devicePixelRatio; final FlutterView view = platformDispatcher.implicitView!;
final Size size = _surfaceSize ?? window.physicalSize / devicePixelRatio; final double devicePixelRatio = view.devicePixelRatio;
final Size size = _surfaceSize ?? view.physicalSize / devicePixelRatio;
return TestViewConfiguration.fromView( return TestViewConfiguration.fromView(
size: size, size: size,
view: window, view: view,
); );
} }
......
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