Skip to content

Commit

Permalink
Remove physicalGeometry (#138103)
Browse files Browse the repository at this point in the history
Looks like this was proactively added in flutter/engine#20496, but never wired up to anything on any platform. It is also unused in framework and customer code; we never exposed this on e.g. MediaQuery.

Related engine PR: flutter/engine#47825
  • Loading branch information
goderbauer committed Nov 8, 2023
1 parent 3215c49 commit 1ef6e99
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 127 deletions.
80 changes: 4 additions & 76 deletions packages/flutter_test/lib/src/window.dart
Expand Up @@ -745,91 +745,29 @@ class TestFlutterView implements FlutterView {
platformDispatcher.onMetricsChanged?.call();
}

/// The physical geometry to use for this test.
///
/// Defaults to the value provided by [FlutterView.physicalGeometry]. This
/// can only be set in a test environment to emulate different view
/// configurations. A standard [FlutterView] is not mutable from the framework.
///
/// This property and [physicalSize] are dependent on one another. If both
/// properties are set through their test setters, the final result will be
/// that [physicalGeometry] determines the location and [physicalSize]
/// determines the size of the [physicalGeometry] [Rect]. If only
/// [physicalSize] is set, the final result is that the default value of
/// [physicalGeometry] determines the location and [physicalSize] determines
/// the size of the [physicalGeometry] [Rect]. If only [physicalGeometry]
/// is set, it will determine both the location and size of the
/// [physicalGeometry] [Rect].
///
/// See also:
///
/// * [FlutterView.physicalGeometry] for the standard implementation
/// * [resetPhysicalGeometry] to reset this value specifically
/// * [reset] to reset all test values for this view
@override
Rect get physicalGeometry {
Rect value = _physicalGeometry ?? _view.physicalGeometry;
if (_physicalSize != null) {
value = value.topLeft & _physicalSize!;
}
return value;
}
Rect? _physicalGeometry;
set physicalGeometry(Rect value) {
_physicalGeometry = value;
platformDispatcher.onMetricsChanged?.call();
}

/// Resets [physicalGeometry] to the default value for this view.
///
/// This will also reset [physicalSize] as the values are dependent
/// on one another.
void resetPhysicalGeometry() {
_physicalGeometry = null;
_physicalSize = null;
platformDispatcher.onMetricsChanged?.call();
}

/// The physical size to use for this test.
///
/// Defaults to the value provided by [FlutterView.physicalSize]. This
/// can only be set in a test environment to emulate different view
/// configurations. A standard [FlutterView] is not mutable from the framework.
///
/// This property and [physicalGeometry] are dependent on one another. If both
/// properties are set through their test setters, the final result will be
/// that [physicalGeometry] determines the location and [physicalSize]
/// determines the size of the [physicalGeometry] [Rect]. If only
/// [physicalSize] is set, the final result is that the default value of
/// [physicalGeometry] determines the location and [physicalSize] determines
/// the size of the [physicalGeometry] [Rect]. If only [physicalGeometry]
/// is set, it will determine both the location and size of the
/// [physicalGeometry] [Rect].
///
/// See also:
///
/// * [FlutterView.physicalSize] for the standard implementation
/// * [resetPhysicalSize] to reset this value specifically
/// * [reset] to reset all test values for this view
@override
Size get physicalSize {
// This has to be able to default to `_view.physicalSize` as web_ui handles
// `physicalSize` and `physicalGeometry` differently than dart:ui, where
// the values are both based off of `physicalGeometry`.
return _physicalSize ?? _physicalGeometry?.size ?? _view.physicalSize;
}
Size get physicalSize => _physicalSize ?? _view.physicalSize;
Size? _physicalSize;
set physicalSize(Size value) {
_physicalSize = value;
platformDispatcher.onMetricsChanged?.call();
}

/// Resets [physicalSize] to the default value for this view.
///
/// This will also reset [physicalGeometry] as the values are dependent
/// on one another.
void resetPhysicalSize() {
resetPhysicalGeometry();
_physicalSize = null;
platformDispatcher.onMetricsChanged?.call();
}

/// The system gesture insets to use for this test.
Expand Down Expand Up @@ -952,7 +890,6 @@ class TestFlutterView implements FlutterView {
/// * [resetDevicePixelRatio] to reset [devicePixelRatio] specifically
/// * [resetDisplayFeatures] to reset [displayFeatures] specifically
/// * [resetPadding] to reset [padding] specifically
/// * [resetPhysicalGeometry] to reset [physicalGeometry] specifically
/// * [resetPhysicalSize] to reset [physicalSize] specifically
/// * [resetSystemGestureInsets] to reset [systemGestureInsets] specifically
/// * [resetViewInsets] to reset [viewInsets] specifically
Expand All @@ -962,8 +899,7 @@ class TestFlutterView implements FlutterView {
resetDevicePixelRatio();
resetDisplayFeatures();
resetPadding();
resetPhysicalGeometry();
// Skipping resetPhysicalSize because resetPhysicalGeometry resets both values.
resetPhysicalSize();
resetSystemGestureInsets();
resetViewInsets();
resetViewPadding();
Expand Down Expand Up @@ -1879,14 +1815,6 @@ class TestWindow implements SingletonFlutterWindow {
@override
FrameData get frameData => platformDispatcher.frameData;

@Deprecated(
'Use WidgetTester.platformDispatcher.physicalGeometry instead. '
'Deprecated to prepare for the upcoming multi-window support. '
'This feature was deprecated after v3.9.0-0.1.pre.'
)
@override
Rect get physicalGeometry => _view.physicalGeometry;

@Deprecated(
'Use WidgetTester.platformDispatcher.systemFontFamily instead. '
'Deprecated to prepare for the upcoming multi-window support. '
Expand Down
51 changes: 0 additions & 51 deletions packages/flutter_test/test/view_test.dart
Expand Up @@ -112,39 +112,6 @@ void main() {
);
});

testWidgets('can fake physicalGeometry', (WidgetTester tester) async {
verifyPropertyFaked<Rect>(
tester: tester,
realValue: trueImplicitView().physicalGeometry,
fakeValue: const Rect.fromLTWH(0, 0, 550, 850),
propertyRetriever: () => boundImplicitView().physicalGeometry,
propertyFaker: (_, Rect fakeValue) {
tester.view.physicalGeometry = fakeValue;
},
);
});

testWidgets('can reset physicalGeometry', (WidgetTester tester) async {
verifyPropertyReset<Rect>(
tester: tester,
fakeValue: const Rect.fromLTWH(0, 0, 35, 475),
propertyRetriever: () => boundImplicitView().physicalGeometry,
propertyResetter: () {
tester.view.resetPhysicalGeometry();
},
propertyFaker: (Rect fakeValue) {
tester.view.physicalGeometry = fakeValue;
},
);
});

testWidgets('updating physicalGeometry also updates physicalSize', (WidgetTester tester) async {
const Rect testGeometry = Rect.fromLTWH(0, 0, 450, 575);
tester.view.physicalGeometry = testGeometry;

expect(tester.view.physicalSize, testGeometry.size);
});

testWidgets('can fake physicalSize', (WidgetTester tester) async {
verifyPropertyFaked<Size>(
tester: tester,
Expand All @@ -171,17 +138,6 @@ void main() {
);
});

testWidgets('updating physicalSize also updates physicalGeometry', (WidgetTester tester) async {
const Rect testGeometry = Rect.fromLTWH(0, 0, 450, 575);
const Size testSize = Size(50, 50);
const Rect expectedGeometry = Rect.fromLTWH(0, 0, 50, 50);

tester.view.physicalGeometry = testGeometry;
tester.view.physicalSize = testSize;

expect(tester.view.physicalGeometry, expectedGeometry);
});

testWidgets('can fake systemGestureInsets', (WidgetTester tester) async {
verifyPropertyFaked<ViewPadding>(
tester: tester,
Expand Down Expand Up @@ -272,7 +228,6 @@ void main() {
tester.view.devicePixelRatio = 7;
tester.view.displayFeatures = <DisplayFeature>[const DisplayFeature(bounds: Rect.fromLTWH(0, 0, 20, 300), type: DisplayFeatureType.unknown, state: DisplayFeatureState.unknown)];
tester.view.padding = FakeViewPadding.zero;
tester.view.physicalGeometry = const Rect.fromLTWH(0, 0, 505, 805);
tester.view.systemGestureInsets = FakeViewPadding.zero;
tester.view.viewInsets = FakeViewPadding.zero;
tester.view.viewPadding = FakeViewPadding.zero;
Expand Down Expand Up @@ -356,9 +311,6 @@ class _FlutterViewSnapshotMatcher extends Matcher {
paddingMatcher.describeMismatch(actual.padding, mismatchDescription, matchState, verbose);
}

if (actual.physicalGeometry != expected.physicalGeometry) {
mismatchDescription.add('actual.physicalGeometry (${actual.physicalGeometry}) did not match expected.physicalGeometry (${expected.physicalGeometry})');
}
if (actual.physicalSize != expected.physicalSize) {
mismatchDescription.add('actual.physicalSize (${actual.physicalSize}) did not match expected.physicalSize (${expected.physicalSize})');
}
Expand Down Expand Up @@ -397,7 +349,6 @@ class _FlutterViewSnapshotMatcher extends Matcher {
actual.displayFeatures.equals(expected.displayFeatures) &&
actual.gestureSettings == expected.gestureSettings &&
matchesViewPadding(expected.padding).matches(actual.padding, matchState) &&
actual.physicalGeometry == expected.physicalGeometry &&
actual.physicalSize == expected.physicalSize &&
matchesViewPadding(expected.systemGestureInsets).matches(actual.padding, matchState) &&
actual.viewId == expected.viewId &&
Expand All @@ -412,7 +363,6 @@ class FlutterViewSnapshot {
displayFeatures = <DisplayFeature>[...view.displayFeatures],
gestureSettings = view.gestureSettings,
padding = view.padding,
physicalGeometry = view.physicalGeometry,
physicalSize = view.physicalSize,
systemGestureInsets = view.systemGestureInsets,
viewId = view.viewId,
Expand All @@ -423,7 +373,6 @@ class FlutterViewSnapshot {
final List<DisplayFeature> displayFeatures;
final GestureSettings gestureSettings;
final ViewPadding padding;
final Rect physicalGeometry;
final Size physicalSize;
final ViewPadding systemGestureInsets;
final Object viewId;
Expand Down

0 comments on commit 1ef6e99

Please sign in to comment.