diff --git a/engine/src/flutter/lib/ui/fixtures/ui_test.dart b/engine/src/flutter/lib/ui/fixtures/ui_test.dart index 80bdb2ac92..2393ec4431 100644 --- a/engine/src/flutter/lib/ui/fixtures/ui_test.dart +++ b/engine/src/flutter/lib/ui/fixtures/ui_test.dart @@ -622,8 +622,6 @@ void hooksTests() async { [], // display features states ); - expectEquals(window.viewConfiguration.gestureSettings, - GestureSettings(physicalTouchSlop: 11.0)); expectEquals(window.gestureSettings, GestureSettings(physicalTouchSlop: 11.0)); @@ -652,8 +650,6 @@ void hooksTests() async { [], // display features states ); - expectEquals(window.viewConfiguration.gestureSettings, - GestureSettings(physicalTouchSlop: null)); expectEquals(window.gestureSettings, GestureSettings(physicalTouchSlop: null)); @@ -682,8 +678,6 @@ void hooksTests() async { [], // display features states ); - expectEquals(window.viewConfiguration.gestureSettings, - GestureSettings(physicalTouchSlop: 22.0)); expectEquals(window.gestureSettings, GestureSettings(physicalTouchSlop: 22.0)); }); diff --git a/engine/src/flutter/lib/ui/platform_dispatcher.dart b/engine/src/flutter/lib/ui/platform_dispatcher.dart index 90112aad40..f047b7bff8 100644 --- a/engine/src/flutter/lib/ui/platform_dispatcher.dart +++ b/engine/src/flutter/lib/ui/platform_dispatcher.dart @@ -135,12 +135,7 @@ class PlatformDispatcher { static PlatformDispatcher get instance => _instance; static final PlatformDispatcher _instance = PlatformDispatcher._(); - /// The current platform configuration. - /// - /// If values in this configuration change, [onPlatformConfigurationChanged] - /// will be called. - PlatformConfiguration get configuration => _configuration; - PlatformConfiguration _configuration = const PlatformConfiguration(); + _PlatformConfiguration _configuration = const _PlatformConfiguration(); /// Called when the platform configuration changes. /// @@ -162,7 +157,7 @@ class PlatformDispatcher { final Map _views = {}; // A map of opaque platform view identifiers to view configurations. - final Map _viewConfigurations = {}; + final Map _viewConfigurations = {}; /// The [FlutterView] provided by the engine if the platform is unable to /// create windows, or, for backwards compatibility. @@ -245,8 +240,8 @@ class PlatformDispatcher { List displayFeaturesType, List displayFeaturesState, ) { - final ViewConfiguration previousConfiguration = - _viewConfigurations[id] ?? const ViewConfiguration(); + final _ViewConfiguration previousConfiguration = + _viewConfigurations[id] ?? const _ViewConfiguration(); if (!_views.containsKey(id)) { _views[id] = FlutterView._(id, this); } @@ -748,7 +743,7 @@ class PlatformDispatcher { external static void _scheduleFrame(); /// Additional accessibility features that may be enabled by the platform. - AccessibilityFeatures get accessibilityFeatures => configuration.accessibilityFeatures; + AccessibilityFeatures get accessibilityFeatures => _configuration.accessibilityFeatures; /// A callback that is invoked when the value of [accessibilityFeatures] /// changes. @@ -766,7 +761,7 @@ class PlatformDispatcher { // Called from the engine, via hooks.dart void _updateAccessibilityFeatures(int values) { final AccessibilityFeatures newFeatures = AccessibilityFeatures._(values); - final PlatformConfiguration previousConfiguration = configuration; + final _PlatformConfiguration previousConfiguration = _configuration; if (newFeatures == previousConfiguration.accessibilityFeatures) { return; } @@ -826,7 +821,7 @@ class PlatformDispatcher { /// /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to /// observe when this value changes. - List get locales => configuration.locales; + List get locales => _configuration.locales; /// Performs the platform-native locale resolution. /// @@ -881,7 +876,7 @@ class PlatformDispatcher { void _updateLocales(List locales) { const int stringsPerLocale = 4; final int numLocales = locales.length ~/ stringsPerLocale; - final PlatformConfiguration previousConfiguration = configuration; + final _PlatformConfiguration previousConfiguration = _configuration; final List newLocales = []; bool localesDiffer = numLocales != previousConfiguration.locales.length; for (int localeIndex = 0; localeIndex < numLocales; localeIndex++) { @@ -939,7 +934,7 @@ class PlatformDispatcher { /// format. /// /// This option is used by [showTimePicker]. - bool get alwaysUse24HourFormat => configuration.alwaysUse24HourFormat; + bool get alwaysUse24HourFormat => _configuration.alwaysUse24HourFormat; /// The system-reported text scale. /// @@ -953,7 +948,7 @@ class PlatformDispatcher { /// /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to /// observe when this value changes. - double get textScaleFactor => configuration.textScaleFactor; + double get textScaleFactor => _configuration.textScaleFactor; /// A callback that is invoked whenever [textScaleFactor] changes value. /// @@ -993,7 +988,7 @@ class PlatformDispatcher { /// The setting indicating the current brightness mode of the host platform. /// If the platform has no preference, [platformBrightness] defaults to /// [Brightness.light]. - Brightness get platformBrightness => configuration.platformBrightness; + Brightness get platformBrightness => _configuration.platformBrightness; /// A callback that is invoked whenever [platformBrightness] changes value. /// @@ -1013,7 +1008,7 @@ class PlatformDispatcher { } /// The setting indicating the current system font of the host platform. - String? get systemFontFamily => configuration.systemFontFamily; + String? get systemFontFamily => _configuration.systemFontFamily; /// A callback that is invoked whenever [systemFontFamily] changes value. /// @@ -1055,7 +1050,7 @@ class PlatformDispatcher { final Brightness platformBrightness = data['platformBrightness']! as String == 'dark' ? Brightness.dark : Brightness.light; final String? systemFontFamily = data['systemFontFamily'] as String?; - final PlatformConfiguration previousConfiguration = configuration; + final _PlatformConfiguration previousConfiguration = _configuration; final bool platformBrightnessChanged = previousConfiguration.platformBrightness != platformBrightness; final bool textScaleFactorChanged = previousConfiguration.textScaleFactor != textScaleFactor; final bool alwaysUse24HourFormatChanged = @@ -1088,7 +1083,7 @@ class PlatformDispatcher { /// /// The [onSemanticsEnabledChanged] callback is called whenever this value /// changes. - bool get semanticsEnabled => configuration.semanticsEnabled; + bool get semanticsEnabled => _configuration.semanticsEnabled; /// A callback that is invoked when the value of [semanticsEnabled] changes. /// @@ -1104,7 +1099,7 @@ class PlatformDispatcher { // Called from the engine, via hooks.dart void _updateSemanticsEnabled(bool enabled) { - final PlatformConfiguration previousConfiguration = configuration; + final _PlatformConfiguration previousConfiguration = _configuration; if (previousConfiguration.semanticsEnabled == enabled) { return; } @@ -1247,9 +1242,8 @@ class PlatformDispatcher { /// Configuration of the platform. /// /// Immutable class (but can't use @immutable in dart:ui) -class PlatformConfiguration { - /// Const constructor for [PlatformConfiguration]. - const PlatformConfiguration({ +class _PlatformConfiguration { + const _PlatformConfiguration({ this.accessibilityFeatures = const AccessibilityFeatures._(0), this.alwaysUse24HourFormat = false, this.semanticsEnabled = false, @@ -1260,8 +1254,7 @@ class PlatformConfiguration { this.systemFontFamily, }); - /// Copy a [PlatformConfiguration] with some fields replaced. - PlatformConfiguration copyWith({ + _PlatformConfiguration copyWith({ AccessibilityFeatures? accessibilityFeatures, bool? alwaysUse24HourFormat, bool? semanticsEnabled, @@ -1271,7 +1264,7 @@ class PlatformConfiguration { String? defaultRouteName, String? systemFontFamily, }) { - return PlatformConfiguration( + return _PlatformConfiguration( accessibilityFeatures: accessibilityFeatures ?? this.accessibilityFeatures, alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat, semanticsEnabled: semanticsEnabled ?? this.semanticsEnabled, @@ -1314,20 +1307,9 @@ class PlatformConfiguration { } /// An immutable view configuration. -class ViewConfiguration { - /// A const constructor for an immutable [ViewConfiguration]. - /// - /// When constructing a view configuration, supply either the [view] or the - /// [window] property, but not both since the [view] and [window] property - /// are backed by the same instance variable. - const ViewConfiguration({ - FlutterView? view, - @Deprecated(''' - Use the `view` property instead. - This change is related to adding multi-view support in Flutter. - This feature was deprecated after 3.7.0-1.2.pre. - ''') - FlutterView? window, +class _ViewConfiguration { + const _ViewConfiguration({ + this.view, this.devicePixelRatio = 1.0, this.geometry = Rect.zero, this.visible = false, @@ -1337,18 +1319,11 @@ class ViewConfiguration { this.padding = ViewPadding.zero, this.gestureSettings = const GestureSettings(), this.displayFeatures = const [], - }) : assert(window == null || view == null), - _view = view ?? window; + }); /// Copy this configuration with some fields replaced. - ViewConfiguration copyWith({ + _ViewConfiguration copyWith({ FlutterView? view, - @Deprecated(''' - Use the `view` property instead. - This change is related to adding multi-view support in Flutter. - This feature was deprecated after 3.7.0-1.2.pre. - ''') - FlutterView? window, double? devicePixelRatio, Rect? geometry, bool? visible, @@ -1359,9 +1334,8 @@ class ViewConfiguration { GestureSettings? gestureSettings, List? displayFeatures, }) { - assert(view == null || window == null); - return ViewConfiguration( - view: view ?? window ?? _view, + return _ViewConfiguration( + view: view ?? this.view, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, geometry: geometry ?? this.geometry, visible: visible ?? this.visible, @@ -1374,22 +1348,7 @@ class ViewConfiguration { ); } - /// The top level view for which this [ViewConfiguration]'s properties apply to. - /// - /// If this property is null, this [ViewConfiguration] is a top level view. - @Deprecated(''' - Use the `view` property instead. - This change is related to adding multi-view support in Flutter. - This feature was deprecated after 3.7.0-1.2.pre. - ''') - FlutterView? get window => _view; - - /// The top level view for which this [ViewConfiguration]'s properties apply to. - /// - /// If this property is null, this [ViewConfiguration] is a top level view. - FlutterView? get view => _view; - - final FlutterView? _view; + final FlutterView? view; /// The pixel density of the output surface. final double devicePixelRatio; @@ -1449,7 +1408,6 @@ class ViewConfiguration { /// touch slop constant. final GestureSettings gestureSettings; - /// {@template dart.ui.ViewConfiguration.displayFeatures} /// Areas of the display that are obstructed by hardware features. /// /// This list is populated only on Android. If the device has no display @@ -1466,7 +1424,6 @@ class ViewConfiguration { /// Folding [DisplayFeature]s like the [DisplayFeatureType.hinge] and /// [DisplayFeatureType.fold] also have a [DisplayFeature.state] which can be /// used to determine the posture the device is in. - /// {@endtemplate} final List displayFeatures; @override diff --git a/engine/src/flutter/lib/ui/window.dart b/engine/src/flutter/lib/ui/window.dart index d5abb49723..a47ccd6bfd 100644 --- a/engine/src/flutter/lib/ui/window.dart +++ b/engine/src/flutter/lib/ui/window.dart @@ -62,7 +62,7 @@ class FlutterView { final PlatformDispatcher platformDispatcher; /// The configuration of this view. - ViewConfiguration get viewConfiguration { + _ViewConfiguration get _viewConfiguration { assert(platformDispatcher._viewConfigurations.containsKey(viewId)); return platformDispatcher._viewConfigurations[viewId]!; } @@ -92,7 +92,7 @@ class FlutterView { /// /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to /// observe when this value changes. - double get devicePixelRatio => viewConfiguration.devicePixelRatio; + double get devicePixelRatio => _viewConfiguration.devicePixelRatio; /// The dimensions and location of the rectangle into which the scene rendered /// in this view will be drawn on the screen, in physical pixels. @@ -111,7 +111,7 @@ class FlutterView { /// /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to /// observe when this value changes. - Rect get physicalGeometry => viewConfiguration.geometry; + Rect get physicalGeometry => _viewConfiguration.geometry; /// The dimensions of the rectangle into which the scene rendered in this view /// will be drawn on the screen, in physical pixels. @@ -134,7 +134,7 @@ class FlutterView { /// its size. /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to /// observe when this value changes. - Size get physicalSize => viewConfiguration.geometry.size; + Size get physicalSize => _viewConfiguration.geometry.size; /// The number of physical pixels on each side of the display rectangle into /// which the view can render, but over which the operating system will likely @@ -153,7 +153,7 @@ class FlutterView { /// * [MediaQuery.of], a simpler mechanism for the same. /// * [Scaffold], which automatically applies the view insets in material /// design applications. - ViewPadding get viewInsets => viewConfiguration.viewInsets; + ViewPadding get viewInsets => _viewConfiguration.viewInsets; /// The number of physical pixels on each side of the display rectangle into /// which the view can render, but which may be partially obscured by system @@ -179,7 +179,7 @@ class FlutterView { /// * [MediaQuery.of], a simpler mechanism for the same. /// * [Scaffold], which automatically applies the padding in material design /// applications. - ViewPadding get viewPadding => viewConfiguration.viewPadding; + ViewPadding get viewPadding => _viewConfiguration.viewPadding; /// The number of physical pixels on each side of the display rectangle into /// which the view can render, but where the operating system will consume @@ -196,7 +196,7 @@ class FlutterView { /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to /// observe when this value changes. /// * [MediaQuery.of], a simpler mechanism for the same. - ViewPadding get systemGestureInsets => viewConfiguration.systemGestureInsets; + ViewPadding get systemGestureInsets => _viewConfiguration.systemGestureInsets; /// The number of physical pixels on each side of the display rectangle into /// which the view can render, but which may be partially obscured by system @@ -224,16 +224,31 @@ class FlutterView { /// * [MediaQuery.of], a simpler mechanism for the same. /// * [Scaffold], which automatically applies the padding in material design /// applications. - ViewPadding get padding => viewConfiguration.padding; + ViewPadding get padding => _viewConfiguration.padding; /// Additional configuration for touch gestures performed on this view. /// /// For example, the touch slop defined in physical pixels may be provided /// by the gesture settings and should be preferred over the framework /// touch slop constant. - GestureSettings get gestureSettings => viewConfiguration.gestureSettings; + GestureSettings get gestureSettings => _viewConfiguration.gestureSettings; - /// {@macro dart.ui.ViewConfiguration.displayFeatures} + /// Areas of the display that are obstructed by hardware features. + /// + /// This list is populated only on Android. If the device has no display + /// features, this list is empty. + /// + /// The coordinate space in which the [DisplayFeature.bounds] are defined spans + /// across the screens currently in use. This means that the space between the screens + /// is virtually part of the Flutter view space, with the [DisplayFeature.bounds] + /// of the display feature as an obstructed area. The [DisplayFeature.type] can + /// be used to determine if this display feature obstructs the screen or not. + /// For example, [DisplayFeatureType.hinge] and [DisplayFeatureType.cutout] both + /// obstruct the display, while [DisplayFeatureType.fold] is a crease in the display. + /// + /// Folding [DisplayFeature]s like the [DisplayFeatureType.hinge] and + /// [DisplayFeatureType.fold] also have a [DisplayFeature.state] which can be + /// used to determine the posture the device is in. /// /// When this changes, [PlatformDispatcher.onMetricsChanged] is called. /// @@ -242,7 +257,7 @@ class FlutterView { /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to /// observe when this value changes. /// * [MediaQuery.of], a simpler mechanism to access this data. - List get displayFeatures => viewConfiguration.displayFeatures; + List get displayFeatures => _viewConfiguration.displayFeatures; /// Updates the view's rendering on the GPU with the newly provided [Scene]. /// @@ -921,8 +936,9 @@ class FrameData { /// Platform specific configuration for gesture behavior, such as touch slop. /// -/// These settings are provided via [ViewConfiguration] to each window, and should -/// be favored for configuring gesture behavior over the framework constants. +/// These settings are provided via [FlutterView.gestureSettings] to each +/// view, and should be favored for configuring gesture behavior over the +/// framework constants. /// /// A `null` field indicates that the platform or view does not have a preference /// and the fallback constants should be used instead. diff --git a/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart b/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart index 4163612364..7af13e3095 100644 --- a/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart +++ b/engine/src/flutter/lib/web_ui/lib/platform_dispatcher.dart @@ -26,7 +26,6 @@ class RootIsolateToken { abstract class PlatformDispatcher { static PlatformDispatcher get instance => engine.EnginePlatformDispatcher.instance; - PlatformConfiguration get configuration; VoidCallback? get onPlatformConfigurationChanged; set onPlatformConfigurationChanged(VoidCallback? callback); @@ -96,7 +95,7 @@ abstract class PlatformDispatcher { Locale get locale; - List get locales => configuration.locales; + List get locales; Locale? computePlatformResolvedLocale(List supportedLocales); @@ -105,9 +104,9 @@ abstract class PlatformDispatcher { String get initialLifecycleState => 'AppLifecycleState.resumed'; - bool get alwaysUse24HourFormat => configuration.alwaysUse24HourFormat; + bool get alwaysUse24HourFormat; - double get textScaleFactor => configuration.textScaleFactor; + double get textScaleFactor; bool get nativeSpellCheckServiceDefined => false; @@ -116,17 +115,17 @@ abstract class PlatformDispatcher { VoidCallback? get onTextScaleFactorChanged; set onTextScaleFactorChanged(VoidCallback? callback); - Brightness get platformBrightness => configuration.platformBrightness; + Brightness get platformBrightness; VoidCallback? get onPlatformBrightnessChanged; set onPlatformBrightnessChanged(VoidCallback? callback); - String? get systemFontFamily => configuration.systemFontFamily; + String? get systemFontFamily; VoidCallback? get onSystemFontFamilyChanged; set onSystemFontFamilyChanged(VoidCallback? callback); - bool get semanticsEnabled => configuration.semanticsEnabled; + bool get semanticsEnabled; VoidCallback? get onSemanticsEnabledChanged; set onSemanticsEnabledChanged(VoidCallback? callback); @@ -145,128 +144,6 @@ abstract class PlatformDispatcher { set onFrameDataChanged(VoidCallback? callback) {} } -class PlatformConfiguration { - const PlatformConfiguration({ - this.accessibilityFeatures = const engine.EngineAccessibilityFeatures(0), - this.alwaysUse24HourFormat = false, - this.semanticsEnabled = false, - this.platformBrightness = Brightness.light, - this.textScaleFactor = 1.0, - this.locales = const [], - this.defaultRouteName = '/', - this.systemFontFamily, - }); - - PlatformConfiguration copyWith({ - AccessibilityFeatures? accessibilityFeatures, - bool? alwaysUse24HourFormat, - bool? semanticsEnabled, - Brightness? platformBrightness, - double? textScaleFactor, - List? locales, - String? defaultRouteName, - String? systemFontFamily, - }) { - return PlatformConfiguration( - accessibilityFeatures: accessibilityFeatures ?? this.accessibilityFeatures, - alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat, - semanticsEnabled: semanticsEnabled ?? this.semanticsEnabled, - platformBrightness: platformBrightness ?? this.platformBrightness, - textScaleFactor: textScaleFactor ?? this.textScaleFactor, - locales: locales ?? this.locales, - defaultRouteName: defaultRouteName ?? this.defaultRouteName, - systemFontFamily: systemFontFamily ?? this.systemFontFamily, - ); - } - - final AccessibilityFeatures accessibilityFeatures; - final bool alwaysUse24HourFormat; - final bool semanticsEnabled; - final Brightness platformBrightness; - final double textScaleFactor; - final List locales; - final String defaultRouteName; - final String? systemFontFamily; -} - -class ViewConfiguration { - const ViewConfiguration({ - FlutterView? view, - @Deprecated(''' - Use the `view` property instead. - This change is related to adding multi-view support in Flutter. - This feature was deprecated after 3.7.0-1.2.pre. - ''') - FlutterView? window, - this.devicePixelRatio = 1.0, - this.geometry = Rect.zero, - this.visible = false, - this.viewInsets = ViewPadding.zero, - this.viewPadding = ViewPadding.zero, - this.systemGestureInsets = ViewPadding.zero, - this.padding = ViewPadding.zero, - this.gestureSettings = const GestureSettings(), - this.displayFeatures = const [], - }) : assert(window == null || view == null), - _view = view ?? window; - - ViewConfiguration copyWith({ - FlutterView? view, - @Deprecated(''' - Use the `view` property instead. - This change is related to adding multi-view support in Flutter. - This feature was deprecated after 3.7.0-1.2.pre. - ''') - FlutterView? window, - double? devicePixelRatio, - Rect? geometry, - bool? visible, - ViewPadding? viewInsets, - ViewPadding? viewPadding, - ViewPadding? systemGestureInsets, - ViewPadding? padding, - GestureSettings? gestureSettings, - List? displayFeatures, - }) { - assert(view == null || window == null); - return ViewConfiguration( - view: view ?? window ?? _view, - devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, - geometry: geometry ?? this.geometry, - visible: visible ?? this.visible, - viewInsets: viewInsets ?? this.viewInsets, - viewPadding: viewPadding ?? this.viewPadding, - systemGestureInsets: systemGestureInsets ?? this.systemGestureInsets, - padding: padding ?? this.padding, - gestureSettings: gestureSettings ?? this.gestureSettings, - displayFeatures: displayFeatures ?? this.displayFeatures, - ); - } - - @Deprecated(''' - Use the `view` property instead. - This change is related to adding multi-view support in Flutter. - This feature was deprecated after 3.7.0-1.2.pre. - ''') - FlutterView? get window => _view; - FlutterView? get view => _view; - final FlutterView? _view; - final double devicePixelRatio; - final Rect geometry; - final bool visible; - final ViewPadding viewInsets; - final ViewPadding viewPadding; - final ViewPadding systemGestureInsets; - final ViewPadding padding; - final GestureSettings gestureSettings; - final List displayFeatures; - - @override - String toString() { - return '$runtimeType[view: $view, geometry: $geometry]'; - } -} - enum FramePhase { vsyncStart, buildStart, diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 1c8c384bbb..41ae4c1cd6 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -91,9 +91,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { static EnginePlatformDispatcher get instance => _instance; static final EnginePlatformDispatcher _instance = EnginePlatformDispatcher(); - /// The current platform configuration. - @override - ui.PlatformConfiguration configuration = ui.PlatformConfiguration( + PlatformConfiguration configuration = PlatformConfiguration( locales: parseBrowserLanguages(), textScaleFactor: findBrowserTextScaleFactor(), accessibilityFeatures: computeAccessibilityFeatures(), @@ -144,9 +142,9 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { /// /// This should be considered a protected member, only to be used by /// [PlatformDispatcher] subclasses. - Map get windowConfigurations => _windowConfigurations; - final Map _windowConfigurations = - {}; + Map get windowConfigurations => _windowConfigurations; + final Map _windowConfigurations = + {}; /// The [FlutterView] provided by the engine if the platform is unable to /// create windows, or, for backwards compatibility. @@ -1320,3 +1318,104 @@ double findBrowserTextScaleFactor() { final num fontSize = parseFontSize(domDocument.documentElement!) ?? _defaultRootFontSize; return fontSize / _defaultRootFontSize; } + +class ViewConfiguration { + const ViewConfiguration({ + this.view, + this.devicePixelRatio = 1.0, + this.geometry = ui.Rect.zero, + this.visible = false, + this.viewInsets = ui.ViewPadding.zero as ViewPadding, + this.viewPadding = ui.ViewPadding.zero as ViewPadding, + this.systemGestureInsets = ui.ViewPadding.zero as ViewPadding, + this.padding = ui.ViewPadding.zero as ViewPadding, + this.gestureSettings = const ui.GestureSettings(), + this.displayFeatures = const [], + }); + + ViewConfiguration copyWith({ + ui.FlutterView? view, + double? devicePixelRatio, + ui.Rect? geometry, + bool? visible, + ViewPadding? viewInsets, + ViewPadding? viewPadding, + ViewPadding? systemGestureInsets, + ViewPadding? padding, + ui.GestureSettings? gestureSettings, + List? displayFeatures, + }) { + return ViewConfiguration( + view: view ?? this.view, + devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, + geometry: geometry ?? this.geometry, + visible: visible ?? this.visible, + viewInsets: viewInsets ?? this.viewInsets, + viewPadding: viewPadding ?? this.viewPadding, + systemGestureInsets: systemGestureInsets ?? this.systemGestureInsets, + padding: padding ?? this.padding, + gestureSettings: gestureSettings ?? this.gestureSettings, + displayFeatures: displayFeatures ?? this.displayFeatures, + ); + } + + final ui.FlutterView? view; + final double devicePixelRatio; + final ui.Rect geometry; + final bool visible; + final ViewPadding viewInsets; + final ViewPadding viewPadding; + final ViewPadding systemGestureInsets; + final ViewPadding padding; + final ui.GestureSettings gestureSettings; + final List displayFeatures; + + @override + String toString() { + return '$runtimeType[view: $view, geometry: $geometry]'; + } +} + +class PlatformConfiguration { + const PlatformConfiguration({ + this.accessibilityFeatures = const EngineAccessibilityFeatures(0), + this.alwaysUse24HourFormat = false, + this.semanticsEnabled = false, + this.platformBrightness = ui.Brightness.light, + this.textScaleFactor = 1.0, + this.locales = const [], + this.defaultRouteName = '/', + this.systemFontFamily, + }); + + PlatformConfiguration copyWith({ + ui.AccessibilityFeatures? accessibilityFeatures, + bool? alwaysUse24HourFormat, + bool? semanticsEnabled, + ui.Brightness? platformBrightness, + double? textScaleFactor, + List? locales, + String? defaultRouteName, + String? systemFontFamily, + }) { + return PlatformConfiguration( + accessibilityFeatures: accessibilityFeatures ?? this.accessibilityFeatures, + alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat, + semanticsEnabled: semanticsEnabled ?? this.semanticsEnabled, + platformBrightness: platformBrightness ?? this.platformBrightness, + textScaleFactor: textScaleFactor ?? this.textScaleFactor, + locales: locales ?? this.locales, + defaultRouteName: defaultRouteName ?? this.defaultRouteName, + systemFontFamily: systemFontFamily ?? this.systemFontFamily, + ); + } + + final ui.AccessibilityFeatures accessibilityFeatures; + final bool alwaysUse24HourFormat; + final bool semanticsEnabled; + final ui.Brightness platformBrightness; + final double textScaleFactor; + final List locales; + final String defaultRouteName; + final String? systemFontFamily; +} diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart index d3d659ccb4..62f89313f3 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/semantics/semantics.dart @@ -1579,7 +1579,7 @@ class EngineSemanticsOwner { final EngineAccessibilityFeatures original = EnginePlatformDispatcher.instance.configuration.accessibilityFeatures as EngineAccessibilityFeatures; - final ui.PlatformConfiguration newConfiguration = + final PlatformConfiguration newConfiguration = EnginePlatformDispatcher.instance.configuration.copyWith( accessibilityFeatures: original.copyWith(accessibleNavigation: value)); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart index 9e1fd13f7c..11af5ef1bb 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/window.dart @@ -50,7 +50,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { final EnginePlatformDispatcher engineDispatcher = platformDispatcher as EnginePlatformDispatcher; engineDispatcher.viewData[viewId] = this; - engineDispatcher.windowConfigurations[viewId] = const ui.ViewConfiguration(); + engineDispatcher.windowConfigurations[viewId] = const ViewConfiguration(); if (_isUrlStrategySet) { _browserHistory = createHistoryForExistingState(_customUrlStrategy); } @@ -202,15 +202,32 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { }); } - @override - ui.ViewConfiguration get viewConfiguration { + ViewConfiguration get _viewConfiguration { final EnginePlatformDispatcher engineDispatcher = platformDispatcher as EnginePlatformDispatcher; assert(engineDispatcher.windowConfigurations.containsKey(viewId)); return engineDispatcher.windowConfigurations[viewId] ?? - const ui.ViewConfiguration(); + const ViewConfiguration(); } + @override + ui.Rect get physicalGeometry => _viewConfiguration.geometry; + + @override + ViewPadding get viewPadding => _viewConfiguration.viewPadding; + + @override + ViewPadding get systemGestureInsets => _viewConfiguration.systemGestureInsets; + + @override + ViewPadding get padding => _viewConfiguration.padding; + + @override + ui.GestureSettings get gestureSettings => _viewConfiguration.gestureSettings; + + @override + List get displayFeatures => _viewConfiguration.displayFeatures; + late DimensionsProvider _dimensionsProvider; void configureDimensionsProvider(DimensionsProvider dimensionsProvider) { _dimensionsProvider = dimensionsProvider; diff --git a/engine/src/flutter/lib/web_ui/lib/window.dart b/engine/src/flutter/lib/web_ui/lib/window.dart index a75f1b3083..8493ec1888 100644 --- a/engine/src/flutter/lib/web_ui/lib/window.dart +++ b/engine/src/flutter/lib/web_ui/lib/window.dart @@ -6,17 +6,16 @@ part of ui; abstract class FlutterView { PlatformDispatcher get platformDispatcher; - ViewConfiguration get viewConfiguration; Object get viewId; - double get devicePixelRatio => viewConfiguration.devicePixelRatio; - Rect get physicalGeometry => viewConfiguration.geometry; - Size get physicalSize => viewConfiguration.geometry.size; - ViewPadding get viewInsets => viewConfiguration.viewInsets; - ViewPadding get viewPadding => viewConfiguration.viewPadding; - ViewPadding get systemGestureInsets => viewConfiguration.systemGestureInsets; - ViewPadding get padding => viewConfiguration.padding; - GestureSettings get gestureSettings => viewConfiguration.gestureSettings; - List get displayFeatures => viewConfiguration.displayFeatures; + double get devicePixelRatio; + Rect get physicalGeometry; + Size get physicalSize; + ViewPadding get viewInsets; + ViewPadding get viewPadding; + ViewPadding get systemGestureInsets; + ViewPadding get padding; + GestureSettings get gestureSettings; + List get displayFeatures; void render(Scene scene) => platformDispatcher.render(scene, this); void updateSemantics(SemanticsUpdate update) => platformDispatcher.updateSemantics(update); } diff --git a/engine/src/flutter/lib/web_ui/test/engine/platform_dispatcher_test.dart b/engine/src/flutter/lib/web_ui/test/engine/platform_dispatcher_test.dart index dd6b928a30..1b19330b38 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/platform_dispatcher_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/platform_dispatcher_test.dart @@ -10,8 +10,6 @@ import 'package:test/test.dart'; import 'package:ui/src/engine.dart'; import 'package:ui/ui.dart' as ui; -import '../matchers.dart'; - void main() { internalBootstrapBrowserTest(() => testMain); } @@ -175,42 +173,6 @@ void testMain() { expect(ui.PlatformDispatcher.instance.textScaleFactor, findBrowserTextScaleFactor()); }); }); - - test('A ViewConfiguration asserts that both window and view are not provided', () { - expect(() { - // ignore: deprecated_member_use - final EngineFlutterWindow window = EngineFlutterWindow(0, ui.PlatformDispatcher.instance); - ui.ViewConfiguration( - window: window, - view: window, - ); - }, throwsAssertionError); - }); - - test("A ViewConfiguration's view and window are backed with the same property", () { - final ui.FlutterView window = EngineFlutterWindow(0, ui.PlatformDispatcher.instance); - final ui.ViewConfiguration viewConfiguration = ui.ViewConfiguration(view: window); - // ignore: deprecated_member_use - expect(viewConfiguration.view, window); - // ignore: deprecated_member_use - expect(viewConfiguration.window, viewConfiguration.view); - }); - - test('Initialize a ViewConfiguration with a window', () { - final ui.FlutterView window = EngineFlutterWindow(0, ui.PlatformDispatcher.instance); - // ignore: deprecated_member_use - final ui.ViewConfiguration configuration = ui.ViewConfiguration(window: window); - // ignore: deprecated_member_use - expect(window, configuration.window); - }); - - test("copyWith() on a ViewConfiguration asserts that both a window aren't provided", () { - final ui.FlutterView window = EngineFlutterWindow(0, ui.PlatformDispatcher.instance); - // ignore: deprecated_member_use - expect(() { - ui.ViewConfiguration(view: window).copyWith(view: window, window: window); - }, throwsAssertionError); - }); } class MockHighContrastSupport implements HighContrastSupport { diff --git a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart index 63f70a6a06..6e2bda120f 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/semantics/semantics_test.dart @@ -250,7 +250,7 @@ void _testEngineSemanticsOwner() { expect(semantics().semanticsEnabled, isFalse); expect( EnginePlatformDispatcher - .instance.configuration.accessibilityFeatures.accessibleNavigation, + .instance.accessibilityFeatures.accessibleNavigation, isFalse); final DomElement placeholder = @@ -266,7 +266,7 @@ void _testEngineSemanticsOwner() { expect(semantics().semanticsEnabled, isTrue); expect( EnginePlatformDispatcher - .instance.configuration.accessibilityFeatures.accessibleNavigation, + .instance.accessibilityFeatures.accessibleNavigation, isTrue); // The placeholder should be removed diff --git a/engine/src/flutter/testing/dart/BUILD.gn b/engine/src/flutter/testing/dart/BUILD.gn index 7ee975b6d3..1c372c5ed9 100644 --- a/engine/src/flutter/testing/dart/BUILD.gn +++ b/engine/src/flutter/testing/dart/BUILD.gn @@ -37,7 +37,6 @@ tests = [ "paragraph_test.dart", "path_test.dart", "picture_test.dart", - "platform_dispatcher_test.dart", "platform_view_test.dart", "plugin_utilities_test.dart", "semantics_test.dart", diff --git a/engine/src/flutter/testing/dart/platform_dispatcher_test.dart b/engine/src/flutter/testing/dart/platform_dispatcher_test.dart deleted file mode 100644 index dc19fba3fe..0000000000 --- a/engine/src/flutter/testing/dart/platform_dispatcher_test.dart +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2022 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:ui'; - -import 'package:litetest/litetest.dart'; - -void main() { - test('A ViewConfiguration asserts that both window and view are not provided', () { - expectAssertion(() { - return ViewConfiguration( - // ignore: deprecated_member_use - window: PlatformDispatcher.instance.views.first, - view: PlatformDispatcher.instance.views.first, - ); - }); - }); - - test("A ViewConfiguration's view and window are backed with the same property", () { - final FlutterView view = PlatformDispatcher.instance.views.first; - final ViewConfiguration viewConfiguration = ViewConfiguration(view: view); - // ignore: deprecated_member_use - expect(viewConfiguration.window, view); - // ignore: deprecated_member_use - expect(viewConfiguration.window, viewConfiguration.view); - }); - - test('Initialize a ViewConfiguration with a window', () { - final FlutterView view = PlatformDispatcher.instance.views.first; - // ignore: deprecated_member_use - ViewConfiguration(window: view); - }); - - test("copyWith() on a ViewConfiguration asserts that both a window aren't provided", () { - final FlutterView view = PlatformDispatcher.instance.views.first; - expectAssertion(() { - // ignore: deprecated_member_use - return ViewConfiguration(view: view)..copyWith(view: view, window: view); - }); - }); -}