Unverified Commit cac8fa5d authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Re-land 'Adding physicalDepth to MediaQueryData & TestWindow' (#38546)

parent c2e2f093
...@@ -74,6 +74,7 @@ enum Orientation { ...@@ -74,6 +74,7 @@ enum Orientation {
/// widgets that reduce those properties by the same amount. /// widgets that reduce those properties by the same amount.
/// The [removePadding], [removeViewPadding], and [removeViewInsets] methods are /// The [removePadding], [removeViewPadding], and [removeViewInsets] methods are
/// useful for this. /// useful for this.
///
/// See also: /// See also:
/// ///
/// * [Scaffold], [SafeArea], [CupertinoTabScaffold], and /// * [Scaffold], [SafeArea], [CupertinoTabScaffold], and
...@@ -93,6 +94,7 @@ class MediaQueryData { ...@@ -93,6 +94,7 @@ class MediaQueryData {
this.padding = EdgeInsets.zero, this.padding = EdgeInsets.zero,
this.viewInsets = EdgeInsets.zero, this.viewInsets = EdgeInsets.zero,
this.viewPadding = EdgeInsets.zero, this.viewPadding = EdgeInsets.zero,
this.physicalDepth = double.maxFinite,
this.alwaysUse24HourFormat = false, this.alwaysUse24HourFormat = false,
this.accessibleNavigation = false, this.accessibleNavigation = false,
this.invertColors = false, this.invertColors = false,
...@@ -114,6 +116,7 @@ class MediaQueryData { ...@@ -114,6 +116,7 @@ class MediaQueryData {
padding = EdgeInsets.fromWindowPadding(window.padding, window.devicePixelRatio), padding = EdgeInsets.fromWindowPadding(window.padding, window.devicePixelRatio),
viewPadding = EdgeInsets.fromWindowPadding(window.viewPadding, window.devicePixelRatio), viewPadding = EdgeInsets.fromWindowPadding(window.viewPadding, window.devicePixelRatio),
viewInsets = EdgeInsets.fromWindowPadding(window.viewInsets, window.devicePixelRatio), viewInsets = EdgeInsets.fromWindowPadding(window.viewInsets, window.devicePixelRatio),
physicalDepth = window.physicalDepth,
accessibleNavigation = window.accessibilityFeatures.accessibleNavigation, accessibleNavigation = window.accessibilityFeatures.accessibleNavigation,
invertColors = window.accessibilityFeatures.invertColors, invertColors = window.accessibilityFeatures.invertColors,
disableAnimations = window.accessibilityFeatures.disableAnimations, disableAnimations = window.accessibilityFeatures.disableAnimations,
...@@ -210,6 +213,19 @@ class MediaQueryData { ...@@ -210,6 +213,19 @@ class MediaQueryData {
/// property and how it relates to [padding] and [viewInsets]. /// property and how it relates to [padding] and [viewInsets].
final EdgeInsets viewPadding; final EdgeInsets viewPadding;
/// The physical depth is the maximum elevation that the Window allows.
///
/// Physical layers drawn at or above this elevation will have their elevation
/// clamped to this value. This can happen if the physical layer itself has
/// an elevation larger than the available depth, or if some ancestor of the
/// layer causes it to have a cumulative elevation that is larger than the
/// available depth.
///
/// The default value is [double.maxFinite], which is used for platforms that
/// do not specify a maximum elevation. This property is currently only
/// expected to be set to a non-default value on Fuchsia.
final double physicalDepth;
/// Whether to use 24-hour format when formatting time. /// Whether to use 24-hour format when formatting time.
/// ///
/// The behavior of this flag is different across platforms: /// The behavior of this flag is different across platforms:
...@@ -259,7 +275,8 @@ class MediaQueryData { ...@@ -259,7 +275,8 @@ class MediaQueryData {
/// * [Window.AccessibilityFeatures], where the setting originates. /// * [Window.AccessibilityFeatures], where the setting originates.
final bool boldText; final bool boldText;
/// The orientation of the media (e.g., whether the device is in landscape or portrait mode). /// The orientation of the media (e.g., whether the device is in landscape or
/// portrait mode).
Orientation get orientation { Orientation get orientation {
return size.width > size.height ? Orientation.landscape : Orientation.portrait; return size.width > size.height ? Orientation.landscape : Orientation.portrait;
} }
...@@ -274,6 +291,7 @@ class MediaQueryData { ...@@ -274,6 +291,7 @@ class MediaQueryData {
EdgeInsets padding, EdgeInsets padding,
EdgeInsets viewPadding, EdgeInsets viewPadding,
EdgeInsets viewInsets, EdgeInsets viewInsets,
double physicalDepth,
bool alwaysUse24HourFormat, bool alwaysUse24HourFormat,
bool disableAnimations, bool disableAnimations,
bool invertColors, bool invertColors,
...@@ -288,6 +306,7 @@ class MediaQueryData { ...@@ -288,6 +306,7 @@ class MediaQueryData {
padding: padding ?? this.padding, padding: padding ?? this.padding,
viewPadding: viewPadding ?? this.viewPadding, viewPadding: viewPadding ?? this.viewPadding,
viewInsets: viewInsets ?? this.viewInsets, viewInsets: viewInsets ?? this.viewInsets,
physicalDepth: physicalDepth ?? this.physicalDepth,
alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat, alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat,
invertColors: invertColors ?? this.invertColors, invertColors: invertColors ?? this.invertColors,
disableAnimations: disableAnimations ?? this.disableAnimations, disableAnimations: disableAnimations ?? this.disableAnimations,
...@@ -305,7 +324,7 @@ class MediaQueryData { ...@@ -305,7 +324,7 @@ class MediaQueryData {
/// ///
/// See also: /// See also:
/// ///
/// * [new MediaQuery.removePadding], which uses this method to remove padding /// * [MediaQuery.removePadding], which uses this method to remove [padding]
/// from the ambient [MediaQuery]. /// from the ambient [MediaQuery].
/// * [SafeArea], which both removes the padding from the [MediaQuery] and /// * [SafeArea], which both removes the padding from the [MediaQuery] and
/// adds a [Padding] widget. /// adds a [Padding] widget.
...@@ -354,8 +373,8 @@ class MediaQueryData { ...@@ -354,8 +373,8 @@ class MediaQueryData {
/// ///
/// See also: /// See also:
/// ///
/// * [new MediaQuery.removeViewInsets], which uses this method to remove /// * [MediaQuery.removeViewInsets], which uses this method to remove
/// padding from the ambient [MediaQuery]. /// [viewInsets] from the ambient [MediaQuery].
/// * [removePadding], the same thing but for [padding]. /// * [removePadding], the same thing but for [padding].
/// * [removeViewPadding], the same thing but for [viewPadding]. /// * [removeViewPadding], the same thing but for [viewPadding].
MediaQueryData removeViewInsets({ MediaQueryData removeViewInsets({
...@@ -401,8 +420,8 @@ class MediaQueryData { ...@@ -401,8 +420,8 @@ class MediaQueryData {
/// ///
/// See also: /// See also:
/// ///
/// * [new MediaQuery.removeViewPadding], which uses this method to remove /// * [MediaQuery.removeViewPadding], which uses this method to remove
/// padding from the ambient [MediaQuery]. /// [viewPadding] from the ambient [MediaQuery].
/// * [removePadding], the same thing but for [padding]. /// * [removePadding], the same thing but for [padding].
/// * [removeViewInsets], the same thing but for [viewInsets]. /// * [removeViewInsets], the same thing but for [viewInsets].
MediaQueryData removeViewPadding({ MediaQueryData removeViewPadding({
...@@ -451,6 +470,7 @@ class MediaQueryData { ...@@ -451,6 +470,7 @@ class MediaQueryData {
&& typedOther.padding == padding && typedOther.padding == padding
&& typedOther.viewPadding == viewPadding && typedOther.viewPadding == viewPadding
&& typedOther.viewInsets == viewInsets && typedOther.viewInsets == viewInsets
&& typedOther.physicalDepth == physicalDepth
&& typedOther.alwaysUse24HourFormat == alwaysUse24HourFormat && typedOther.alwaysUse24HourFormat == alwaysUse24HourFormat
&& typedOther.disableAnimations == disableAnimations && typedOther.disableAnimations == disableAnimations
&& typedOther.invertColors == invertColors && typedOther.invertColors == invertColors
...@@ -468,6 +488,7 @@ class MediaQueryData { ...@@ -468,6 +488,7 @@ class MediaQueryData {
padding, padding,
viewPadding, viewPadding,
viewInsets, viewInsets,
physicalDepth,
alwaysUse24HourFormat, alwaysUse24HourFormat,
disableAnimations, disableAnimations,
invertColors, invertColors,
...@@ -486,6 +507,7 @@ class MediaQueryData { ...@@ -486,6 +507,7 @@ class MediaQueryData {
'padding: $padding, ' 'padding: $padding, '
'viewPadding: $viewPadding, ' 'viewPadding: $viewPadding, '
'viewInsets: $viewInsets, ' 'viewInsets: $viewInsets, '
'physicalDepth: $physicalDepth, '
'alwaysUse24HourFormat: $alwaysUse24HourFormat, ' 'alwaysUse24HourFormat: $alwaysUse24HourFormat, '
'accessibleNavigation: $accessibleNavigation, ' 'accessibleNavigation: $accessibleNavigation, '
'disableAnimations: $disableAnimations, ' 'disableAnimations: $disableAnimations, '
...@@ -529,8 +551,8 @@ class MediaQuery extends InheritedWidget { ...@@ -529,8 +551,8 @@ class MediaQuery extends InheritedWidget {
assert(data != null), assert(data != null),
super(key: key, child: child); super(key: key, child: child);
/// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery] from /// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery]
/// the given context, but removes the specified paddings. /// from the given context, but removes the specified padding.
/// ///
/// This should be inserted into the widget tree when the [MediaQuery] padding /// This should be inserted into the widget tree when the [MediaQuery] padding
/// is consumed by a widget in such a way that the padding is no longer /// is consumed by a widget in such a way that the padding is no longer
...@@ -550,9 +572,11 @@ class MediaQuery extends InheritedWidget { ...@@ -550,9 +572,11 @@ class MediaQuery extends InheritedWidget {
/// ///
/// * [SafeArea], which both removes the padding from the [MediaQuery] and /// * [SafeArea], which both removes the padding from the [MediaQuery] and
/// adds a [Padding] widget. /// adds a [Padding] widget.
/// * [MediaQueryData.padding], the affected property of the [MediaQueryData]. /// * [MediaQueryData.padding], the affected property of the
/// * [new removeViewInsets], the same thing but for removing view insets. /// [MediaQueryData].
/// * [new removeViewPadding], the same thing but for removing view insets. /// * [removeViewInsets], the same thing but for [MediaQueryData.viewInsets].
/// * [removeViewPadding], the same thing but for
/// [MediaQueryData.viewPadding].
factory MediaQuery.removePadding({ factory MediaQuery.removePadding({
Key key, Key key,
@required BuildContext context, @required BuildContext context,
...@@ -574,8 +598,8 @@ class MediaQuery extends InheritedWidget { ...@@ -574,8 +598,8 @@ class MediaQuery extends InheritedWidget {
); );
} }
/// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery] from /// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery]
/// the given context, but removes the specified view insets. /// from the given context, but removes the specified view insets.
/// ///
/// This should be inserted into the widget tree when the [MediaQuery] view /// This should be inserted into the widget tree when the [MediaQuery] view
/// insets are consumed by a widget in such a way that the view insets are no /// insets are consumed by a widget in such a way that the view insets are no
...@@ -593,9 +617,11 @@ class MediaQuery extends InheritedWidget { ...@@ -593,9 +617,11 @@ class MediaQuery extends InheritedWidget {
/// ///
/// See also: /// See also:
/// ///
/// * [MediaQueryData.viewInsets], the affected property of the [MediaQueryData]. /// * [MediaQueryData.viewInsets], the affected property of the
/// * [new removePadding], the same thing but for removing paddings. /// [MediaQueryData].
/// * [new removeViewPadding], the same thing but for removing view insets. /// * [removePadding], the same thing but for [MediaQueryData.padding].
/// * [removeViewPadding], the same thing but for
/// [MediaQueryData.viewPadding].
factory MediaQuery.removeViewInsets({ factory MediaQuery.removeViewInsets({
Key key, Key key,
@required BuildContext context, @required BuildContext context,
...@@ -617,8 +643,8 @@ class MediaQuery extends InheritedWidget { ...@@ -617,8 +643,8 @@ class MediaQuery extends InheritedWidget {
); );
} }
/// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery] from /// Creates a new [MediaQuery] that inherits from the ambient [MediaQuery]
/// the given context, but removes the specified view padding. /// from the given context, but removes the specified view padding.
/// ///
/// This should be inserted into the widget tree when the [MediaQuery] view /// This should be inserted into the widget tree when the [MediaQuery] view
/// padding is consumed by a widget in such a way that the view padding is no /// padding is consumed by a widget in such a way that the view padding is no
...@@ -638,8 +664,8 @@ class MediaQuery extends InheritedWidget { ...@@ -638,8 +664,8 @@ class MediaQuery extends InheritedWidget {
/// ///
/// * [MediaQueryData.viewPadding], the affected property of the /// * [MediaQueryData.viewPadding], the affected property of the
/// [MediaQueryData]. /// [MediaQueryData].
/// * [new removePadding], the same thing but for removing paddings. /// * [removePadding], the same thing but for [MediaQueryData.padding].
/// * [new removeViewInsets], the same thing but for removing view insets. /// * [removeViewInsets], the same thing but for [MediaQueryData.viewInsets].
factory MediaQuery.removeViewPadding({ factory MediaQuery.removeViewPadding({
Key key, Key key,
@required BuildContext context, @required BuildContext context,
...@@ -671,8 +697,8 @@ class MediaQuery extends InheritedWidget { ...@@ -671,8 +697,8 @@ class MediaQuery extends InheritedWidget {
/// context. /// context.
/// ///
/// You can use this function to query the size an orientation of the screen. /// You can use this function to query the size an orientation of the screen.
/// When that information changes, your widget will be scheduled to be rebuilt, /// When that information changes, your widget will be scheduled to be
/// keeping your widget up-to-date. /// rebuilt, keeping your widget up-to-date.
/// ///
/// Typical usage is as follows: /// Typical usage is as follows:
/// ///
......
...@@ -47,6 +47,7 @@ void main() { ...@@ -47,6 +47,7 @@ void main() {
expect(data.disableAnimations, false); expect(data.disableAnimations, false);
expect(data.boldText, false); expect(data.boldText, false);
expect(data.platformBrightness, Brightness.light); expect(data.platformBrightness, Brightness.light);
expect(data.physicalDepth, equals(WidgetsBinding.instance.window.physicalDepth));
}); });
testWidgets('MediaQueryData.copyWith defaults to source', (WidgetTester tester) async { testWidgets('MediaQueryData.copyWith defaults to source', (WidgetTester tester) async {
...@@ -58,6 +59,7 @@ void main() { ...@@ -58,6 +59,7 @@ void main() {
expect(copied.padding, data.padding); expect(copied.padding, data.padding);
expect(copied.viewPadding, data.viewPadding); expect(copied.viewPadding, data.viewPadding);
expect(copied.viewInsets, data.viewInsets); expect(copied.viewInsets, data.viewInsets);
expect(copied.physicalDepth, data.physicalDepth);
expect(copied.alwaysUse24HourFormat, data.alwaysUse24HourFormat); expect(copied.alwaysUse24HourFormat, data.alwaysUse24HourFormat);
expect(copied.accessibleNavigation, data.accessibleNavigation); expect(copied.accessibleNavigation, data.accessibleNavigation);
expect(copied.invertColors, data.invertColors); expect(copied.invertColors, data.invertColors);
...@@ -75,6 +77,7 @@ void main() { ...@@ -75,6 +77,7 @@ void main() {
padding: const EdgeInsets.all(9.10938), padding: const EdgeInsets.all(9.10938),
viewPadding: const EdgeInsets.all(11.24031), viewPadding: const EdgeInsets.all(11.24031),
viewInsets: const EdgeInsets.all(1.67262), viewInsets: const EdgeInsets.all(1.67262),
physicalDepth: 120.0,
alwaysUse24HourFormat: true, alwaysUse24HourFormat: true,
accessibleNavigation: true, accessibleNavigation: true,
invertColors: true, invertColors: true,
...@@ -88,6 +91,7 @@ void main() { ...@@ -88,6 +91,7 @@ void main() {
expect(copied.padding, const EdgeInsets.all(9.10938)); expect(copied.padding, const EdgeInsets.all(9.10938));
expect(copied.viewPadding, const EdgeInsets.all(11.24031)); expect(copied.viewPadding, const EdgeInsets.all(11.24031));
expect(copied.viewInsets, const EdgeInsets.all(1.67262)); expect(copied.viewInsets, const EdgeInsets.all(1.67262));
expect(copied.physicalDepth, 120.0);
expect(copied.alwaysUse24HourFormat, true); expect(copied.alwaysUse24HourFormat, true);
expect(copied.accessibleNavigation, true); expect(copied.accessibleNavigation, true);
expect(copied.invertColors, true); expect(copied.invertColors, true);
......
This diff is collapsed.
...@@ -43,6 +43,20 @@ void main() { ...@@ -43,6 +43,20 @@ void main() {
); );
}); });
testWidgets('TestWindow can fake physical depth', (WidgetTester tester) async {
verifyThatTestWindowCanFakeProperty<double>(
tester: tester,
realValue: ui.window.physicalDepth,
fakeValue: 120.0,
propertyRetriever: () {
return WidgetsBinding.instance.window.physicalDepth;
},
propertyFaker: (TestWidgetsFlutterBinding binding, double fakeValue) {
binding.window.physicalDepthTestValue = fakeValue;
},
);
});
testWidgets('TestWindow can fake view insets', (WidgetTester tester) async { testWidgets('TestWindow can fake view insets', (WidgetTester tester) async {
verifyThatTestWindowCanFakeProperty<WindowPadding>( verifyThatTestWindowCanFakeProperty<WindowPadding>(
tester: tester, tester: tester,
......
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