expose max depth on Window (flutter/engine#10414)

This commit is contained in:
Dan Field
2019-08-02 20:37:24 -07:00
committed by GitHub
parent 06e7030b0f
commit 5a9ac6e780
5 changed files with 53 additions and 21 deletions

View File

@@ -21,6 +21,7 @@ dynamic _decodeJSON(String message) {
void _updateWindowMetrics(double devicePixelRatio,
double width,
double height,
double depth,
double viewPaddingTop,
double viewPaddingRight,
double viewPaddingBottom,
@@ -32,6 +33,7 @@ void _updateWindowMetrics(double devicePixelRatio,
window
.._devicePixelRatio = devicePixelRatio
.._physicalSize = Size(width, height)
.._physicalDepth = depth
.._viewPadding = WindowPadding._(
top: viewPaddingTop,
right: viewPaddingRight,

View File

@@ -618,6 +618,20 @@ class Window {
Size get physicalSize => _physicalSize;
Size _physicalSize = Size.zero;
/// 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 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 on expected
/// to be set to a non-default value on Fuchsia.
double get physicalDepth => _physicalDepth;
double _physicalDepth = double.maxFinite;
/// The number of physical pixels on each side of the display rectangle into
/// which the application can render, but over which the operating system
/// will likely place system UI, such as the keyboard, that fully obscures

View File

@@ -9,7 +9,11 @@
namespace flutter {
static const double kUnsetDepth = -1;
// This is the value of double.maxFinite from dart:core.
// Platforms that do not explicitly set a depth will use this value, which
// avoids the need to special case logic that wants to check the max depth on
// the Dart side.
static const double kUnsetDepth = 1.7976931348623157e+308;
struct ViewportMetrics {
ViewportMetrics();

View File

@@ -185,6 +185,7 @@ void Window::UpdateWindowMetrics(const ViewportMetrics& metrics) {
tonic::ToDart(metrics.device_pixel_ratio),
tonic::ToDart(metrics.physical_width),
tonic::ToDart(metrics.physical_height),
tonic::ToDart(metrics.physical_depth),
tonic::ToDart(metrics.physical_padding_top),
tonic::ToDart(metrics.physical_padding_right),
tonic::ToDart(metrics.physical_padding_bottom),

View File

@@ -43,7 +43,19 @@ void main() {
PlatformMessageCallback originalOnPlatformMessage;
VoidCallback originalOnTextScaleFactorChanged;
double oldDPR;
Size oldSize;
double oldDepth;
WindowPadding oldPadding;
WindowPadding oldInsets;
setUp(() {
oldDPR = window.devicePixelRatio;
oldSize = window.physicalSize;
oldDepth = window.physicalDepth;
oldPadding = window.viewPadding;
oldInsets = window.viewInsets;
originalOnMetricsChanged = window.onMetricsChanged;
originalOnLocaleChanged = window.onLocaleChanged;
originalOnBeginFrame = window.onBeginFrame;
@@ -57,6 +69,20 @@ void main() {
});
tearDown(() {
_updateWindowMetrics(
oldDPR, // DPR
oldSize.width, // width
oldSize.height, // height
oldDepth, // depth
oldPadding.top, // padding top
oldPadding.right, // padding right
oldPadding.bottom, // padding bottom
oldPadding.left, // padding left
oldInsets.top, // inset top
oldInsets.right, // inset right
oldInsets.bottom, // inset bottom
oldInsets.left, // inset left
);
window.onMetricsChanged = originalOnMetricsChanged;
window.onLocaleChanged = originalOnLocaleChanged;
window.onBeginFrame = originalOnBeginFrame;
@@ -89,7 +115,7 @@ void main() {
});
window.onMetricsChanged();
_updateWindowMetrics(0.1234, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
_updateWindowMetrics(0.1234, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
expect(runZone, isNotNull);
expect(runZone, same(innerZone));
expect(devicePixelRatio, equals(0.1234));
@@ -290,15 +316,11 @@ void main() {
test('Window padding/insets/viewPadding', () {
final double oldDPR = window.devicePixelRatio;
final Size oldSize = window.physicalSize;
final WindowPadding oldPadding = window.viewPadding;
final WindowPadding oldInsets = window.viewInsets;
_updateWindowMetrics(
1.0, // DPR
800.0, // width
600.0, // height
100.0, // depth
50.0, // padding top
0.0, // padding right
40.0, // padding bottom
@@ -312,11 +334,13 @@ void main() {
expect(window.viewInsets.bottom, 0.0);
expect(window.viewPadding.bottom, 40.0);
expect(window.padding.bottom, 40.0);
expect(window.physicalDepth, 100.0);
_updateWindowMetrics(
1.0, // DPR
800.0, // width
600.0, // height
100.0, // depth
50.0, // padding top
0.0, // padding right
40.0, // padding bottom
@@ -330,20 +354,7 @@ void main() {
expect(window.viewInsets.bottom, 400.0);
expect(window.viewPadding.bottom, 40.0);
expect(window.padding.bottom, 0.0);
_updateWindowMetrics(
oldDPR, // DPR
oldSize.width, // width
oldSize.height, // height
oldPadding.top, // padding top
oldPadding.right, // padding right
oldPadding.bottom, // padding bottom
oldPadding.left, // padding left
oldInsets.top, // inset top
oldInsets.right, // inset right
oldInsets.bottom, // inset bottom
oldInsets.left, // inset left
);
expect(window.physicalDepth, 100.0);
});
});
}