Skip to content

Commit

Permalink
Remove references to BindingBase.window (#122119)
Browse files Browse the repository at this point in the history
Remove references to BindingBase.window
  • Loading branch information
goderbauer authored Mar 9, 2023
1 parent f4551e6 commit c7681f0
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 96 deletions.
4 changes: 2 additions & 2 deletions dev/benchmarks/test_apps/stocks/test/icon_color_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void main() {
expect(find.text('Account Balance'), findsNothing);

// drag the drawer out
final Offset left = Offset(0.0, (WidgetsBinding.instance.window.physicalSize / WidgetsBinding.instance.window.devicePixelRatio).height / 2.0);
final Offset right = Offset((WidgetsBinding.instance.window.physicalSize / WidgetsBinding.instance.window.devicePixelRatio).width, left.dy);
final Offset left = Offset(0.0, (tester.view.physicalSize / tester.view.devicePixelRatio).height / 2.0);
final Offset right = Offset((tester.view.physicalSize / tester.view.devicePixelRatio).width, left.dy);
final TestGesture gesture = await tester.startGesture(left);
await tester.pump();
await gesture.moveTo(right);
Expand Down
7 changes: 6 additions & 1 deletion packages/flutter/test/cupertino/route_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,7 @@ void main() {
];
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test shouldn't call this.
Expand All @@ -1728,6 +1729,7 @@ void main() {

await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test shouldn't call this.
Expand Down Expand Up @@ -1756,6 +1758,7 @@ void main() {
];
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test shouldn't call this.
Expand All @@ -1777,6 +1780,7 @@ void main() {

await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test shouldn't call this.
Expand Down Expand Up @@ -2213,12 +2217,13 @@ class TransitionDetector extends DefaultTransitionDelegate<void> {

Widget buildNavigator({
required List<Page<dynamic>> pages,
required FlutterView view,
PopPageCallback? onPopPage,
GlobalKey<NavigatorState>? key,
TransitionDelegate<dynamic>? transitionDelegate,
}) {
return MediaQuery(
data: MediaQueryData.fromView(WidgetsBinding.instance.window),
data: MediaQueryData.fromView(view),
child: Localizations(
locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@ void main() {
expect(events.length, 1);
expect(events[0], isA<PointerDownEvent>());
expect(events[0].timeStamp, currentTestFrameTime() + kSamplingOffset);
expect(events[0].position, Offset(7.5 / GestureBinding.instance.window.devicePixelRatio, 0.0));
expect(events[0].position, Offset(7.5 / tester.view.devicePixelRatio, 0.0));

// Now the system time is epoch + 20ms
requestFrame();
await tester.pump(const Duration(milliseconds: 10));
expect(events.length, 2);
expect(events[1].timeStamp, currentTestFrameTime() + kSamplingOffset);
expect(events[1], isA<PointerMoveEvent>());
expect(events[1].position, Offset(22.5 / GestureBinding.instance.window.devicePixelRatio, 0.0));
expect(events[1].delta, Offset(15.0 / GestureBinding.instance.window.devicePixelRatio, 0.0));
expect(events[1].position, Offset(22.5 / tester.view.devicePixelRatio, 0.0));
expect(events[1].delta, Offset(15.0 / tester.view.devicePixelRatio, 0.0));

// Now the system time is epoch + 30ms
requestFrame();
await tester.pump(const Duration(milliseconds: 10));
expect(events.length, 4);
expect(events[2].timeStamp, currentTestFrameTime() + kSamplingOffset);
expect(events[2], isA<PointerMoveEvent>());
expect(events[2].position, Offset(37.5 / GestureBinding.instance.window.devicePixelRatio, 0.0));
expect(events[2].delta, Offset(15.0 / GestureBinding.instance.window.devicePixelRatio, 0.0));
expect(events[2].position, Offset(37.5 / tester.view.devicePixelRatio, 0.0));
expect(events[2].delta, Offset(15.0 / tester.view.devicePixelRatio, 0.0));
expect(events[3].timeStamp, currentTestFrameTime() + kSamplingOffset);
expect(events[3], isA<PointerUpEvent>());
});
Expand Down
32 changes: 17 additions & 15 deletions packages/flutter/test/gestures/gesture_binding_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ void main() {
expect(events[1], isA<PointerCancelEvent>());
});

const double devicePixelRatio = 2.5;

test('Can expand add and hover pointers', () {
const ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
Expand All @@ -173,7 +175,7 @@ void main() {
],
);

final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();

expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
Expand All @@ -189,7 +191,7 @@ void main() {
ui.PointerData(change: ui.PointerChange.add, device: 24),
],
);
List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();

expect(events.length, 1);
expect(events[0], isA<PointerAddedEvent>());
Expand All @@ -205,7 +207,7 @@ void main() {
ui.PointerData(signalKind: ui.PointerSignalKind.scroll, device: 24, scrollDeltaY: double.negativeInfinity, scrollDeltaX: 10),
],
);
events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 0);

// Send packet with a valid scroll event.
Expand All @@ -215,7 +217,7 @@ void main() {
],
);
// Make sure PointerEventConverter can expand when device pixel ratio is valid.
events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();
expect(events.length, 1);
expect(events[0], isA<PointerScrollEvent>());

Expand All @@ -232,15 +234,15 @@ void main() {
],
);

final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();

expect(events.length, 2);
expect(events[0], isA<PointerAddedEvent>());
expect(events[1], isA<PointerScrollEvent>());
});

test('Should synthesize kPrimaryButton for touch when no button is set', () {
final Offset location = const Offset(10.0, 10.0) * GestureBinding.instance.window.devicePixelRatio;
final Offset location = const Offset(10.0, 10.0) * devicePixelRatio;
final ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
ui.PointerData(change: ui.PointerChange.add, physicalX: location.dx, physicalY: location.dy),
Expand All @@ -251,7 +253,7 @@ void main() {
],
);

final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();

expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
Expand All @@ -267,7 +269,7 @@ void main() {
});

test('Should not synthesize kPrimaryButton for touch when a button is set', () {
final Offset location = const Offset(10.0, 10.0) * GestureBinding.instance.window.devicePixelRatio;
final Offset location = const Offset(10.0, 10.0) * devicePixelRatio;
final ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
ui.PointerData(change: ui.PointerChange.add, physicalX: location.dx, physicalY: location.dy),
Expand All @@ -278,7 +280,7 @@ void main() {
],
);

final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();

expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
Expand All @@ -294,7 +296,7 @@ void main() {
});

test('Should synthesize kPrimaryButton for stylus when no button is set', () {
final Offset location = const Offset(10.0, 10.0) * GestureBinding.instance.window.devicePixelRatio;
final Offset location = const Offset(10.0, 10.0) * devicePixelRatio;
for (final PointerDeviceKind kind in <PointerDeviceKind>[
PointerDeviceKind.stylus,
PointerDeviceKind.invertedStylus,
Expand All @@ -310,7 +312,7 @@ void main() {
],
);

final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();

expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
Expand All @@ -327,7 +329,7 @@ void main() {
});

test('Should synthesize kPrimaryButton for unknown devices when no button is set', () {
final Offset location = const Offset(10.0, 10.0) * GestureBinding.instance.window.devicePixelRatio;
final Offset location = const Offset(10.0, 10.0) * devicePixelRatio;
const PointerDeviceKind kind = PointerDeviceKind.unknown;
final ui.PointerDataPacket packet = ui.PointerDataPacket(
data: <ui.PointerData>[
Expand All @@ -339,7 +341,7 @@ void main() {
],
);

final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();

expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
Expand All @@ -355,7 +357,7 @@ void main() {
});

test('Should not synthesize kPrimaryButton for mouse', () {
final Offset location = const Offset(10.0, 10.0) * GestureBinding.instance.window.devicePixelRatio;
final Offset location = const Offset(10.0, 10.0) * devicePixelRatio;
for (final PointerDeviceKind kind in <PointerDeviceKind>[
PointerDeviceKind.mouse,
]) {
Expand All @@ -369,7 +371,7 @@ void main() {
],
);

final List<PointerEvent> events = PointerEventConverter.expand(packet.data, GestureBinding.instance.window.devicePixelRatio).toList();
final List<PointerEvent> events = PointerEventConverter.expand(packet.data, devicePixelRatio).toList();

expect(events.length, 5);
expect(events[0], isA<PointerAddedEvent>());
Expand Down
7 changes: 6 additions & 1 deletion packages/flutter/test/material/page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ void main() {
];
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test should never execute this.
Expand All @@ -1060,6 +1061,7 @@ void main() {

await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test should never execute this.
Expand All @@ -1085,6 +1087,7 @@ void main() {
];
await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test should never execute this.
Expand All @@ -1106,6 +1109,7 @@ void main() {

await tester.pumpWidget(
buildNavigator(
view: tester.view,
pages: myPages,
onPopPage: (Route<dynamic> route, dynamic result) {
assert(false); // The test should never execute this.
Expand Down Expand Up @@ -1214,11 +1218,12 @@ class TransitionDetector extends DefaultTransitionDelegate<void> {
Widget buildNavigator({
required List<Page<dynamic>> pages,
required PopPageCallback onPopPage,
required ui.FlutterView view,
GlobalKey<NavigatorState>? key,
TransitionDelegate<dynamic>? transitionDelegate,
}) {
return MediaQuery(
data: MediaQueryData.fromView(WidgetsBinding.instance.window),
data: MediaQueryData.fromView(view),
child: Localizations(
locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[
Expand Down
10 changes: 5 additions & 5 deletions packages/flutter/test/painting/paint_image_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void main() {

test('debugInvertOversizedImages', () async {
debugInvertOversizedImages = true;
expect(PaintingBinding.instance.window.devicePixelRatio != 1.0, true);
expect(PaintingBinding.instance.platformDispatcher.views.any((ui. FlutterView view) => view.devicePixelRatio > 1.0), isTrue);
final FlutterExceptionHandler? oldFlutterError = FlutterError.onError;

final List<String> messages = <String>[];
Expand Down Expand Up @@ -180,7 +180,7 @@ void main() {
expect(imageSizeInfo, isNotNull);
expect(imageSizeInfo.source, 'test.png');
expect(imageSizeInfo.imageSize, const Size(300, 300));
expect(imageSizeInfo.displaySize, const Size(200, 100) * PaintingBinding.instance.window.devicePixelRatio);
expect(imageSizeInfo.displaySize, const Size(200, 100) * tester.view.devicePixelRatio);

// Make sure that we don't report an identical image size info if we
// redraw in the next frame.
Expand Down Expand Up @@ -219,7 +219,7 @@ void main() {
expect(imageSizeInfo, isNotNull);
expect(imageSizeInfo.source, 'test.png');
expect(imageSizeInfo.imageSize, const Size(300, 300));
expect(imageSizeInfo.displaySize, const Size(200, 100) * PaintingBinding.instance.window.devicePixelRatio);
expect(imageSizeInfo.displaySize, const Size(200, 100) * tester.view.devicePixelRatio);

// Make sure that we don't report an identical image size info if we
// redraw in the next frame.
Expand All @@ -237,7 +237,7 @@ void main() {
expect(imageSizeInfo, isNotNull);
expect(imageSizeInfo.source, 'test.png');
expect(imageSizeInfo.imageSize, const Size(300, 300));
expect(imageSizeInfo.displaySize, const Size(200, 150) * PaintingBinding.instance.window.devicePixelRatio);
expect(imageSizeInfo.displaySize, const Size(200, 150) * tester.view.devicePixelRatio);

debugOnPaintImage = null;
});
Expand All @@ -261,7 +261,7 @@ void main() {
expect(imageSizeInfo, isNotNull);
expect(imageSizeInfo.source, '<Unknown Image(300×200)>');
expect(imageSizeInfo.imageSize, const Size(300, 200));
expect(imageSizeInfo.displaySize, const Size(200, 100) * PaintingBinding.instance.window.devicePixelRatio);
expect(imageSizeInfo.displaySize, const Size(200, 100) * tester.view.devicePixelRatio);

debugOnPaintImage = null;
});
Expand Down
5 changes: 3 additions & 2 deletions packages/flutter/test/rendering/independent_layout_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void main() {
expect(offscreen.child.hasSize, isFalse);
expect(offscreen.painted, isFalse);
// Attach the offscreen to a custom render view and owner
final RenderView renderView = RenderView(configuration: testConfiguration, window: RendererBinding.instance.window);
final RenderView renderView = RenderView(configuration: testConfiguration, window: RendererBinding.instance.platformDispatcher.views.single);
final PipelineOwner pipelineOwner = PipelineOwner();
renderView.attach(pipelineOwner);
renderView.child = offscreen.root;
Expand All @@ -66,6 +66,7 @@ void main() {
pipelineOwner.flushPaint();
expect(offscreen.painted, isTrue);
});

test('offscreen layout does not affect onscreen', () {
final TestLayout onscreen = TestLayout();
final TestLayout offscreen = TestLayout();
Expand All @@ -74,7 +75,7 @@ void main() {
expect(offscreen.child.hasSize, isFalse);
expect(offscreen.painted, isFalse);
// Attach the offscreen to a custom render view and owner
final RenderView renderView = RenderView(configuration: testConfiguration, window: RendererBinding.instance.window);
final RenderView renderView = RenderView(configuration: testConfiguration, window: RendererBinding.instance.platformDispatcher.views.single);
final PipelineOwner pipelineOwner = PipelineOwner();
renderView.attach(pipelineOwner);
renderView.child = offscreen.root;
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/test/rendering/layers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void main() {
test('switching layer link of an attached leader layer should not crash', () {
final LayerLink link = LayerLink();
final LeaderLayer leaderLayer = LeaderLayer(link: link);
final RenderView view = RenderView(configuration: const ViewConfiguration(), window: RendererBinding.instance.window);
final RenderView view = RenderView(configuration: const ViewConfiguration(), window: RendererBinding.instance.platformDispatcher.views.single);
leaderLayer.attach(view);
final LayerLink link2 = LayerLink();
leaderLayer.link = link2;
Expand All @@ -182,7 +182,7 @@ void main() {
final LayerLink link = LayerLink();
final LeaderLayer leaderLayer1 = LeaderLayer(link: link);
final LeaderLayer leaderLayer2 = LeaderLayer(link: link);
final RenderView view = RenderView(configuration: const ViewConfiguration(), window: RendererBinding.instance.window);
final RenderView view = RenderView(configuration: const ViewConfiguration(), window: RendererBinding.instance.platformDispatcher.views.single);
leaderLayer1.attach(view);
leaderLayer2.attach(view);
leaderLayer2.detach();
Expand Down
Loading

0 comments on commit c7681f0

Please sign in to comment.