From 5f9cbb08e0f086a7ed2f357654aea40405f4fa23 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 14:40:54 -0800 Subject: [PATCH 01/46] Refactor `window.dart` --- lib/ui/window.dart | 54 +++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 6450fad95c413..78674a27b70a4 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -6,7 +6,7 @@ part of dart.ui; /// A view into which a Flutter [Scene] is drawn. /// /// Each [FlutterView] has its own layer tree that is rendered into an area -/// inside of a [FlutterWindow] whenever [render] is called with a [Scene]. +/// inside of a [SingletonFlutterWindow] whenever [render] is called with a [Scene]. /// /// ## Insets and Padding /// @@ -54,15 +54,23 @@ part of dart.ui; /// /// See also: /// -/// * [FlutterWindow], a special case of a [FlutterView] that is represented on +/// * [FlutterView], a special case of a [FlutterView] that is represented on /// the platform as a separate window which can host other [FlutterView]s. -abstract class FlutterView { +class FlutterView { + FlutterView._(this._viewId, this.platformDispatcher); + + /// The opaque ID for this view. + final Object _viewId; + /// The platform dispatcher that this view is registered with, and gets its /// information from. - PlatformDispatcher get platformDispatcher; + final PlatformDispatcher platformDispatcher; /// The configuration of this view. - ViewConfiguration get viewConfiguration; + ViewConfiguration get viewConfiguration { + assert(platformDispatcher._viewConfigurations.containsKey(_viewId)); + return platformDispatcher._viewConfigurations[_viewId]!; + } /// The number of device pixels for each logical pixel for the screen this /// view is displayed on. @@ -281,39 +289,7 @@ abstract class FlutterView { external static void _updateSemantics(SemanticsUpdate update); } -/// A top-level platform window displaying a Flutter layer tree drawn from a -/// [Scene]. -/// -/// The current list of all Flutter views for the application is available from -/// `WidgetsBinding.instance.platformDispatcher.views`. Only views that are of type -/// [FlutterWindow] are top level platform windows. -/// -/// There is also a [PlatformDispatcher.instance] singleton object in `dart:ui` -/// if `WidgetsBinding` is unavailable, but we strongly advise avoiding a static -/// reference to it. See the documentation for [PlatformDispatcher.instance] for -/// more details about why it should be avoided. -/// -/// See also: -/// -/// * [PlatformDispatcher], which manages the current list of [FlutterView] (and -/// thus [FlutterWindow]) instances. -class FlutterWindow extends FlutterView { - FlutterWindow._(this._windowId, this.platformDispatcher); - - /// The opaque ID for this view. - final Object _windowId; - - @override - final PlatformDispatcher platformDispatcher; - - @override - ViewConfiguration get viewConfiguration { - assert(platformDispatcher._viewConfigurations.containsKey(_windowId)); - return platformDispatcher._viewConfigurations[_windowId]!; - } -} - -/// A [FlutterWindow] that includes access to setting callbacks and retrieving +/// A [FlutterView] that includes access to setting callbacks and retrieving /// properties that reside on the [PlatformDispatcher]. /// /// It is the type of the global [window] singleton used by applications that @@ -328,7 +304,7 @@ class FlutterWindow extends FlutterView { /// `WidgetsBinding.instance.platformDispatcher` over a static reference to /// [window], or [PlatformDispatcher.instance]. See the documentation for /// [PlatformDispatcher.instance] for more details about this recommendation. -class SingletonFlutterWindow extends FlutterWindow { +class SingletonFlutterWindow extends FlutterView { SingletonFlutterWindow._(super.windowId, super.platformDispatcher) : super._(); From 1f5376ad3547ddd5b6aac5d1339057191ad9c156 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 14:41:34 -0800 Subject: [PATCH 02/46] Remove single window assumption from platform dispatcher --- lib/ui/platform_dispatcher.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index f348a4f8db00e..519e9bb29871a 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -222,7 +222,7 @@ class PlatformDispatcher { final ViewConfiguration previousConfiguration = _viewConfigurations[id] ?? const ViewConfiguration(); if (!_views.containsKey(id)) { - _views[id] = FlutterWindow._(id, this); + _views[id] = FlutterView._(id, this); } _viewConfigurations[id] = previousConfiguration.copyWith( window: _views[id], From def8a4927d1f89d77296ce82120cc0637f6ea337 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 14:47:20 -0800 Subject: [PATCH 03/46] Expose viewId --- lib/ui/window.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 78674a27b70a4..9e9f3d1adcafa 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -61,6 +61,7 @@ class FlutterView { /// The opaque ID for this view. final Object _viewId; + Object get viewId => _viewId; /// The platform dispatcher that this view is registered with, and gets its /// information from. From ee1d3a3b21487d4796679a80400718d27a5aecb1 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:02 -0800 Subject: [PATCH 04/46] Remove FlutterWindow from web_ui --- lib/web_ui/lib/window.dart | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/web_ui/lib/window.dart b/lib/web_ui/lib/window.dart index ee4e0e35ec897..99e236a203614 100644 --- a/lib/web_ui/lib/window.dart +++ b/lib/web_ui/lib/window.dart @@ -7,6 +7,7 @@ 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; @@ -19,15 +20,7 @@ abstract class FlutterView { void updateSemantics(SemanticsUpdate update) => platformDispatcher.updateSemantics(update); } -abstract class FlutterWindow extends FlutterView { - @override - PlatformDispatcher get platformDispatcher; - - @override - ViewConfiguration get viewConfiguration; -} - -abstract class SingletonFlutterWindow extends FlutterWindow { +abstract class SingletonFlutterWindow extends FlutterView { VoidCallback? get onMetricsChanged => platformDispatcher.onMetricsChanged; set onMetricsChanged(VoidCallback? callback) { platformDispatcher.onMetricsChanged = callback; From 59a1b347f220720e464c854d19508f1eda77bb94 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Thu, 22 Dec 2022 07:55:31 -1000 Subject: [PATCH 05/46] Refactor EngineFlutterWindow to inherit from FlutterView --- lib/web_ui/lib/platform_dispatcher.dart | 10 +++++----- lib/web_ui/lib/src/engine/platform_dispatcher.dart | 10 ++++------ lib/web_ui/lib/src/engine/window.dart | 10 ++++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index 82d991915d8ff..6109e09c0c526 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -31,7 +31,7 @@ abstract class PlatformDispatcher { VoidCallback? get onPlatformConfigurationChanged; set onPlatformConfigurationChanged(VoidCallback? callback); - Iterable get views; + Map get views; VoidCallback? get onMetricsChanged; set onMetricsChanged(VoidCallback? callback); @@ -190,7 +190,7 @@ class PlatformConfiguration { class ViewConfiguration { const ViewConfiguration({ - this.window, + this.view, this.devicePixelRatio = 1.0, this.geometry = Rect.zero, this.visible = false, @@ -203,7 +203,7 @@ class ViewConfiguration { }); ViewConfiguration copyWith({ - FlutterWindow? window, + FlutterView? view, double? devicePixelRatio, Rect? geometry, bool? visible, @@ -215,7 +215,7 @@ class ViewConfiguration { List? displayFeatures, }) { return ViewConfiguration( - window: window ?? this.window, + view: view ?? this.view, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, geometry: geometry ?? this.geometry, visible: visible ?? this.visible, @@ -228,7 +228,7 @@ class ViewConfiguration { ); } - final FlutterWindow? window; + final FlutterView? view; final double devicePixelRatio; final Rect geometry; final bool visible; diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 480b367a2be3c..c3e02f5ace7e9 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -138,9 +138,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { /// The current list of windows, @override - Iterable get views => _windows.values; - Map get windows => _windows; - final Map _windows = {}; + final Map views = {}; /// A map of opaque platform window identifiers to window configurations. /// @@ -481,7 +479,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { // TODO(gspencergoog): As multi-window support expands, the pop call // will need to include the window ID. Right now only one window is // supported. - (_windows[0]! as EngineFlutterWindow) + (views[0]! as EngineFlutterWindow) .browserHistory .exit() .then((_) { @@ -571,7 +569,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { // TODO(gspencergoog): As multi-window support expands, the navigation call // will need to include the window ID. Right now only one window is // supported. - (_windows[0]! as EngineFlutterWindow) + (views[0]! as EngineFlutterWindow) .handleNavigationMessage(data) .then((bool handled) { if (handled) { @@ -1160,7 +1158,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { @override String get defaultRouteName { return _defaultRouteName ??= - (_windows[0]! as EngineFlutterWindow).browserHistory.currentPath; + (views[0]! as EngineFlutterWindow).browserHistory.currentPath; } /// Lazily initialized when the `defaultRouteName` getter is invoked. diff --git a/lib/web_ui/lib/src/engine/window.dart b/lib/web_ui/lib/src/engine/window.dart index 5538055f589f7..cf23eac77295c 100644 --- a/lib/web_ui/lib/src/engine/window.dart +++ b/lib/web_ui/lib/src/engine/window.dart @@ -46,7 +46,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { EngineFlutterWindow(this._windowId, this.platformDispatcher) { final EnginePlatformDispatcher engineDispatcher = platformDispatcher as EnginePlatformDispatcher; - engineDispatcher.windows[_windowId] = this; + engineDispatcher.views[_windowId] = this; engineDispatcher.windowConfigurations[_windowId] = const ui.ViewConfiguration(); if (_isUrlStrategySet) { _browserHistory = createHistoryForExistingState(_customUrlStrategy); @@ -60,6 +60,9 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { final Object _windowId; + @override + Object get viewId => _windowId; + @override final ui.PlatformDispatcher platformDispatcher; @@ -340,11 +343,14 @@ class EngineSingletonFlutterWindow extends EngineFlutterWindow { } /// A type of [FlutterView] that can be hosted inside of a [FlutterWindow]. -class EngineFlutterWindowView extends ui.FlutterWindow { +class EngineFlutterWindowView extends ui.FlutterView { EngineFlutterWindowView._(this._viewId, this.platformDispatcher); final Object _viewId; + @override + Object get viewId => _viewId; + @override final ui.PlatformDispatcher platformDispatcher; From 559ab5cbb247548310aa45ab1e59cbfdbbf6538d Mon Sep 17 00:00:00 2001 From: a-wallen Date: Thu, 22 Dec 2022 08:03:13 -1000 Subject: [PATCH 06/46] Rename window property --- lib/ui/platform_dispatcher.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 519e9bb29871a..72de5815fbbdc 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -225,7 +225,7 @@ class PlatformDispatcher { _views[id] = FlutterView._(id, this); } _viewConfigurations[id] = previousConfiguration.copyWith( - window: _views[id], + view: _views[id], devicePixelRatio: devicePixelRatio, geometry: Rect.fromLTWH(0.0, 0.0, width, height), viewPadding: WindowPadding._( @@ -1290,7 +1290,7 @@ class PlatformConfiguration { class ViewConfiguration { /// A const constructor for an immutable [ViewConfiguration]. const ViewConfiguration({ - this.window, + this.view, this.devicePixelRatio = 1.0, this.geometry = Rect.zero, this.visible = false, @@ -1304,7 +1304,7 @@ class ViewConfiguration { /// Copy this configuration with some fields replaced. ViewConfiguration copyWith({ - FlutterView? window, + FlutterView? view, double? devicePixelRatio, Rect? geometry, bool? visible, @@ -1316,7 +1316,7 @@ class ViewConfiguration { List? displayFeatures, }) { return ViewConfiguration( - window: window ?? this.window, + view: view ?? this.view, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, geometry: geometry ?? this.geometry, visible: visible ?? this.visible, @@ -1333,7 +1333,7 @@ class ViewConfiguration { /// relative to. /// /// If null, then this configuration represents a top level view itself. - final FlutterView? window; + final FlutterView? view; /// The pixel density of the output surface. final double devicePixelRatio; From 3ef5f40da139c93a74e862e87faab92383d81caa Mon Sep 17 00:00:00 2001 From: a-wallen Date: Thu, 22 Dec 2022 10:25:59 -1000 Subject: [PATCH 07/46] Undo Iterable -> Map conversion --- lib/web_ui/lib/platform_dispatcher.dart | 2 +- .../lib/src/engine/platform_dispatcher.dart | 11 ++++++----- lib/web_ui/lib/src/engine/window.dart | 15 +++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index 6109e09c0c526..28ec462d97a11 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -31,7 +31,7 @@ abstract class PlatformDispatcher { VoidCallback? get onPlatformConfigurationChanged; set onPlatformConfigurationChanged(VoidCallback? callback); - Map get views; + Iterable get views; VoidCallback? get onMetricsChanged; set onMetricsChanged(VoidCallback? callback); diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index c3e02f5ace7e9..ebe12a7c0d375 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -138,8 +138,9 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { /// The current list of windows, @override - final Map views = {}; - + Iterable get views => _windows.values; + Map get windows => _windows; + final Map _windows = {}; /// A map of opaque platform window identifiers to window configurations. /// /// This should be considered a protected member, only to be used by @@ -479,7 +480,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { // TODO(gspencergoog): As multi-window support expands, the pop call // will need to include the window ID. Right now only one window is // supported. - (views[0]! as EngineFlutterWindow) + (windows[0]! as EngineFlutterWindow) .browserHistory .exit() .then((_) { @@ -569,7 +570,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { // TODO(gspencergoog): As multi-window support expands, the navigation call // will need to include the window ID. Right now only one window is // supported. - (views[0]! as EngineFlutterWindow) + (windows[0]! as EngineFlutterWindow) .handleNavigationMessage(data) .then((bool handled) { if (handled) { @@ -1158,7 +1159,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { @override String get defaultRouteName { return _defaultRouteName ??= - (views[0]! as EngineFlutterWindow).browserHistory.currentPath; + (windows[0]! as EngineFlutterWindow).browserHistory.currentPath; } /// Lazily initialized when the `defaultRouteName` getter is invoked. diff --git a/lib/web_ui/lib/src/engine/window.dart b/lib/web_ui/lib/src/engine/window.dart index cf23eac77295c..ab26d60a6da6d 100644 --- a/lib/web_ui/lib/src/engine/window.dart +++ b/lib/web_ui/lib/src/engine/window.dart @@ -43,11 +43,11 @@ set customUrlStrategy(UrlStrategy? strategy) { /// The Web implementation of [ui.SingletonFlutterWindow]. class EngineFlutterWindow extends ui.SingletonFlutterWindow { - EngineFlutterWindow(this._windowId, this.platformDispatcher) { + EngineFlutterWindow(this._viewId, this.platformDispatcher) { final EnginePlatformDispatcher engineDispatcher = platformDispatcher as EnginePlatformDispatcher; - engineDispatcher.views[_windowId] = this; - engineDispatcher.windowConfigurations[_windowId] = const ui.ViewConfiguration(); + engineDispatcher.windows[_viewId] = this; + engineDispatcher.windowConfigurations[_viewId] = const ui.ViewConfiguration(); if (_isUrlStrategySet) { _browserHistory = createHistoryForExistingState(_customUrlStrategy); } @@ -58,10 +58,9 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { }); } - final Object _windowId; - + final Object _viewId; @override - Object get viewId => _windowId; + Object get viewId => _viewId; @override final ui.PlatformDispatcher platformDispatcher; @@ -205,8 +204,8 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { ui.ViewConfiguration get viewConfiguration { final EnginePlatformDispatcher engineDispatcher = platformDispatcher as EnginePlatformDispatcher; - assert(engineDispatcher.windowConfigurations.containsKey(_windowId)); - return engineDispatcher.windowConfigurations[_windowId] ?? + assert(engineDispatcher.windowConfigurations.containsKey(_viewId)); + return engineDispatcher.windowConfigurations[_viewId] ?? const ui.ViewConfiguration(); } From 368ec15830e56638750010523d1a2ec569f95677 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Thu, 22 Dec 2022 10:32:30 -1000 Subject: [PATCH 08/46] Add window and deprecate it so that the change isn't breaking --- lib/ui/platform_dispatcher.dart | 10 ++++++++++ lib/web_ui/lib/platform_dispatcher.dart | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 72de5815fbbdc..8519f760e347e 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1291,6 +1291,10 @@ class ViewConfiguration { /// A const constructor for an immutable [ViewConfiguration]. const ViewConfiguration({ this.view, + @Deprecated(''' + Renaming window to view as the class `FlutterWindow` has been deprecated. + ''') + this.window, this.devicePixelRatio = 1.0, this.geometry = Rect.zero, this.visible = false, @@ -1305,6 +1309,7 @@ class ViewConfiguration { /// Copy this configuration with some fields replaced. ViewConfiguration copyWith({ FlutterView? view, + FlutterView? window, double? devicePixelRatio, Rect? geometry, bool? visible, @@ -1317,6 +1322,7 @@ class ViewConfiguration { }) { return ViewConfiguration( view: view ?? this.view, + window: window ?? this.window, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, geometry: geometry ?? this.geometry, visible: visible ?? this.visible, @@ -1333,6 +1339,10 @@ class ViewConfiguration { /// relative to. /// /// If null, then this configuration represents a top level view itself. + @Deprecated(''' + Renaming window to view as the class `FlutterWindow` has been deprecated. + ''') + final FlutterView? window; final FlutterView? view; /// The pixel density of the output surface. diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index 28ec462d97a11..b39da9192159f 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -191,6 +191,10 @@ class PlatformConfiguration { class ViewConfiguration { const ViewConfiguration({ this.view, + @Deprecated(''' + Renaming window to view as the class `FlutterWindow` has been deprecated. + ''') + this.window, this.devicePixelRatio = 1.0, this.geometry = Rect.zero, this.visible = false, @@ -228,6 +232,10 @@ class ViewConfiguration { ); } + @Deprecated(''' + Renaming window to view as the class `FlutterWindow` has been deprecated. + ''') + final FlutterView? window; final FlutterView? view; final double devicePixelRatio; final Rect geometry; From 570cc186c37371f2c1ae4ee09c53ce5fba6bd185 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Thu, 22 Dec 2022 10:39:57 -1000 Subject: [PATCH 09/46] Name resolution --- lib/ui/platform_dispatcher.dart | 6 +++--- lib/web_ui/lib/platform_dispatcher.dart | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 8519f760e347e..6f6bbff3265cd 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1349,7 +1349,7 @@ class ViewConfiguration { final double devicePixelRatio; /// The geometry requested for the view on the screen or within its parent - /// window, in logical pixels. + /// view, in logical pixels. final Rect geometry; /// Whether or not the view is currently visible on the screen. @@ -1437,7 +1437,7 @@ class ViewConfiguration { @override String toString() { - return '$runtimeType[window: $window, geometry: $geometry]'; + return '$runtimeType[view: $view, geometry: $geometry]'; } } @@ -1676,7 +1676,7 @@ enum AppLifecycleState { /// On Android, this corresponds to an app or the Flutter host view running /// in the foreground inactive state. Apps transition to this state when /// another activity is focused, such as a split-screen app, a phone call, - /// a picture-in-picture app, a system dialog, or another window. + /// a picture-in-picture app, a system dialog, or another view. /// /// Apps in this state should assume that they may be [paused] at any time. inactive, diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index b39da9192159f..6051abcbd4f32 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -249,7 +249,7 @@ class ViewConfiguration { @override String toString() { - return '$runtimeType[window: $window, geometry: $geometry]'; + return '$runtimeType[view: $view, geometry: $geometry]'; } } From 109c396d5437da0f9960f02d026cf9cc951a68f2 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Thu, 22 Dec 2022 11:33:14 -1000 Subject: [PATCH 10/46] Revisions --- lib/ui/platform_dispatcher.dart | 3 ++- lib/web_ui/lib/platform_dispatcher.dart | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 6f6bbff3265cd..65b62f6c1d56c 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -226,6 +226,7 @@ class PlatformDispatcher { } _viewConfigurations[id] = previousConfiguration.copyWith( view: _views[id], + window: _views[id], devicePixelRatio: devicePixelRatio, geometry: Rect.fromLTWH(0.0, 0.0, width, height), viewPadding: WindowPadding._( @@ -1349,7 +1350,7 @@ class ViewConfiguration { final double devicePixelRatio; /// The geometry requested for the view on the screen or within its parent - /// view, in logical pixels. + /// window, in logical pixels. final Rect geometry; /// Whether or not the view is currently visible on the screen. diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index 6051abcbd4f32..1b35ec423acd1 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -208,6 +208,7 @@ class ViewConfiguration { ViewConfiguration copyWith({ FlutterView? view, + FlutterView? window, double? devicePixelRatio, Rect? geometry, bool? visible, @@ -220,6 +221,7 @@ class ViewConfiguration { }) { return ViewConfiguration( view: view ?? this.view, + window: window ?? this.window, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, geometry: geometry ?? this.geometry, visible: visible ?? this.visible, From b08531d2ee3ab4c8a98a0069f0e5b09b1d1e63e4 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Thu, 22 Dec 2022 11:43:06 -1000 Subject: [PATCH 11/46] Doc changes --- lib/ui/window.dart | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 9e9f3d1adcafa..63b28dd42148e 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -5,8 +5,8 @@ part of dart.ui; /// A view into which a Flutter [Scene] is drawn. /// -/// Each [FlutterView] has its own layer tree that is rendered into an area -/// inside of a [SingletonFlutterWindow] whenever [render] is called with a [Scene]. +/// Each [FlutterView] has its own layer tree that is shown whenever [render] +/// is called on it with a [Scene]. /// /// ## Insets and Padding /// @@ -51,11 +51,6 @@ part of dart.ui; /// the [viewPadding] anyway, so there is no need to account for /// that in the [padding], which is always safe to use for such /// calculations. -/// -/// See also: -/// -/// * [FlutterView], a special case of a [FlutterView] that is represented on -/// the platform as a separate window which can host other [FlutterView]s. class FlutterView { FlutterView._(this._viewId, this.platformDispatcher); From d8425c2991b15305510b60a67845b147b8bb3b00 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Tue, 3 Jan 2023 07:08:55 -1000 Subject: [PATCH 12/46] Refactor deprecation message --- lib/ui/platform_dispatcher.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 65b62f6c1d56c..6065d7b62813b 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1293,7 +1293,7 @@ class ViewConfiguration { const ViewConfiguration({ this.view, @Deprecated(''' - Renaming window to view as the class `FlutterWindow` has been deprecated. + Renaming window to view since `FlutterWindow` has been removed from dart::ui. ''') this.window, this.devicePixelRatio = 1.0, @@ -1341,7 +1341,7 @@ class ViewConfiguration { /// /// If null, then this configuration represents a top level view itself. @Deprecated(''' - Renaming window to view as the class `FlutterWindow` has been deprecated. + Renaming window to view since `FlutterWindow` has been removed from dart::ui. ''') final FlutterView? window; final FlutterView? view; From 6a8fd2ed50b2ba1f790535731dc52f0030e3ea8f Mon Sep 17 00:00:00 2001 From: a-wallen Date: Tue, 3 Jan 2023 07:12:20 -1000 Subject: [PATCH 13/46] Newline --- lib/web_ui/lib/src/engine/window.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/web_ui/lib/src/engine/window.dart b/lib/web_ui/lib/src/engine/window.dart index ab26d60a6da6d..30263244aac97 100644 --- a/lib/web_ui/lib/src/engine/window.dart +++ b/lib/web_ui/lib/src/engine/window.dart @@ -59,6 +59,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { } final Object _viewId; + @override Object get viewId => _viewId; From 4c659b168814ca672aa6d5f81bf2151b3a5265eb Mon Sep 17 00:00:00 2001 From: a-wallen Date: Tue, 3 Jan 2023 07:26:17 -1000 Subject: [PATCH 14/46] Expose getViewById, hide map interface --- lib/web_ui/lib/src/engine/platform_dispatcher.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index ebe12a7c0d375..8ac5ec606b2eb 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -138,9 +138,10 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { /// The current list of windows, @override - Iterable get views => _windows.values; - Map get windows => _windows; - final Map _windows = {}; + Iterable get views => _views.values; + final Map _views = {}; + ui.FlutterView? getViewById(Object id) => _views[id]; + /// A map of opaque platform window identifiers to window configurations. /// /// This should be considered a protected member, only to be used by From 48832da069f513a79c0529dfea69843cd207d1ee Mon Sep 17 00:00:00 2001 From: a-wallen Date: Tue, 3 Jan 2023 08:09:15 -1000 Subject: [PATCH 15/46] Fix compilaiton errors --- lib/web_ui/lib/src/engine/platform_dispatcher.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 8ac5ec606b2eb..205fc72d7f7b8 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -481,7 +481,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { // TODO(gspencergoog): As multi-window support expands, the pop call // will need to include the window ID. Right now only one window is // supported. - (windows[0]! as EngineFlutterWindow) + (_views[0]! as EngineFlutterWindow) .browserHistory .exit() .then((_) { @@ -571,7 +571,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { // TODO(gspencergoog): As multi-window support expands, the navigation call // will need to include the window ID. Right now only one window is // supported. - (windows[0]! as EngineFlutterWindow) + (_views[0]! as EngineFlutterWindow) .handleNavigationMessage(data) .then((bool handled) { if (handled) { @@ -1160,7 +1160,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { @override String get defaultRouteName { return _defaultRouteName ??= - (windows[0]! as EngineFlutterWindow).browserHistory.currentPath; + (_views[0]! as EngineFlutterWindow).browserHistory.currentPath; } /// Lazily initialized when the `defaultRouteName` getter is invoked. From 9504d9333a9178b07ed32b897e278d3771a18b8f Mon Sep 17 00:00:00 2001 From: a-wallen Date: Tue, 3 Jan 2023 08:14:22 -1000 Subject: [PATCH 16/46] Introduce addView API --- lib/web_ui/lib/src/engine/platform_dispatcher.dart | 1 + lib/web_ui/lib/src/engine/window.dart | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 205fc72d7f7b8..968fc1022f731 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -141,6 +141,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { Iterable get views => _views.values; final Map _views = {}; ui.FlutterView? getViewById(Object id) => _views[id]; + void addView(Object id, ui.FlutterView view) => _views[id] = view; /// A map of opaque platform window identifiers to window configurations. /// diff --git a/lib/web_ui/lib/src/engine/window.dart b/lib/web_ui/lib/src/engine/window.dart index 30263244aac97..e42098a32d376 100644 --- a/lib/web_ui/lib/src/engine/window.dart +++ b/lib/web_ui/lib/src/engine/window.dart @@ -46,7 +46,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { EngineFlutterWindow(this._viewId, this.platformDispatcher) { final EnginePlatformDispatcher engineDispatcher = platformDispatcher as EnginePlatformDispatcher; - engineDispatcher.windows[_viewId] = this; + engineDispatcher.addView(_viewId, this); engineDispatcher.windowConfigurations[_viewId] = const ui.ViewConfiguration(); if (_isUrlStrategySet) { _browserHistory = createHistoryForExistingState(_customUrlStrategy); From bdb74d2d243399f7aa39ee1b8a1a980158b945f0 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Tue, 3 Jan 2023 09:11:39 -1000 Subject: [PATCH 17/46] Change deprecation message --- lib/ui/platform_dispatcher.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 6065d7b62813b..c22a0c6c1a59b 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1293,7 +1293,7 @@ class ViewConfiguration { const ViewConfiguration({ this.view, @Deprecated(''' - Renaming window to view since `FlutterWindow` has been removed from dart::ui. + Use the `view` property instead. ''') this.window, this.devicePixelRatio = 1.0, @@ -1341,7 +1341,7 @@ class ViewConfiguration { /// /// If null, then this configuration represents a top level view itself. @Deprecated(''' - Renaming window to view since `FlutterWindow` has been removed from dart::ui. + Use the `view` property instead. ''') final FlutterView? window; final FlutterView? view; From 4453c992620a99a60abd6450fab8cdae7e6c0dab Mon Sep 17 00:00:00 2001 From: Alex Wallen Date: Tue, 3 Jan 2023 09:39:53 -1000 Subject: [PATCH 18/46] Update lib/ui/window.dart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com> --- lib/ui/window.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 63b28dd42148e..3f44c62c67d18 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -5,8 +5,8 @@ part of dart.ui; /// A view into which a Flutter [Scene] is drawn. /// -/// Each [FlutterView] has its own layer tree that is shown whenever [render] -/// is called on it with a [Scene]. +/// Each [FlutterView] has its own layer tree that is rendered +/// whenever [render] is called on it with a [Scene]. /// /// ## Insets and Padding /// From 5103c3ad87e965404ccd5bd20899e4e9c409c9ac Mon Sep 17 00:00:00 2001 From: a-wallen Date: Tue, 3 Jan 2023 10:06:50 -1000 Subject: [PATCH 19/46] Take greg's todos --- lib/web_ui/lib/src/engine/platform_dispatcher.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 968fc1022f731..4c223975c2d6c 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -479,7 +479,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { final MethodCall decoded = codec.decodeMethodCall(data); switch (decoded.method) { case 'SystemNavigator.pop': - // TODO(gspencergoog): As multi-window support expands, the pop call + // TODO(a-wallen): As multi-window support expands, the pop call // will need to include the window ID. Right now only one window is // supported. (_views[0]! as EngineFlutterWindow) @@ -569,7 +569,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { return; case 'flutter/navigation': - // TODO(gspencergoog): As multi-window support expands, the navigation call + // TODO(a-wallen): As multi-window support expands, the navigation call // will need to include the window ID. Right now only one window is // supported. (_views[0]! as EngineFlutterWindow) From 184e658712664fef0ae69e86830a5600ea676ad8 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Tue, 3 Jan 2023 10:15:29 -1000 Subject: [PATCH 20/46] Add mutual exclusion assertion --- lib/ui/platform_dispatcher.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index c22a0c6c1a59b..c1f29e072b1d6 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1305,7 +1305,7 @@ class ViewConfiguration { this.padding = WindowPadding.zero, this.gestureSettings = const GestureSettings(), this.displayFeatures = const [], - }); + }) : assert(!(window != null && view != null)); /// Copy this configuration with some fields replaced. ViewConfiguration copyWith({ From 864a0eef37d7757762eece132a2d10e22ec7599f Mon Sep 17 00:00:00 2001 From: a-wallen Date: Tue, 3 Jan 2023 10:16:21 -1000 Subject: [PATCH 21/46] Fix trailing whitespace lint --- lib/ui/window.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 3f44c62c67d18..7ad162bbbc58b 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -5,7 +5,7 @@ part of dart.ui; /// A view into which a Flutter [Scene] is drawn. /// -/// Each [FlutterView] has its own layer tree that is rendered +/// Each [FlutterView] has its own layer tree that is rendered /// whenever [render] is called on it with a [Scene]. /// /// ## Insets and Padding From 0ae470091a4250a732859b35ece7af2361eb8b6c Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 22/46] Use only one property to store backing view --- lib/ui/platform_dispatcher.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index c1f29e072b1d6..c03719c99ba45 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1291,11 +1291,11 @@ class PlatformConfiguration { class ViewConfiguration { /// A const constructor for an immutable [ViewConfiguration]. const ViewConfiguration({ - this.view, + FlutterView? view, @Deprecated(''' Use the `view` property instead. ''') - this.window, + FlutterView? window, this.devicePixelRatio = 1.0, this.geometry = Rect.zero, this.visible = false, @@ -1305,7 +1305,8 @@ class ViewConfiguration { this.padding = WindowPadding.zero, this.gestureSettings = const GestureSettings(), this.displayFeatures = const [], - }) : assert(!(window != null && view != null)); + }) : assert(!(window != null && view != null)), + _view = view ?? window; /// Copy this configuration with some fields replaced. ViewConfiguration copyWith({ @@ -1323,7 +1324,6 @@ class ViewConfiguration { }) { return ViewConfiguration( view: view ?? this.view, - window: window ?? this.window, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, geometry: geometry ?? this.geometry, visible: visible ?? this.visible, @@ -1343,8 +1343,10 @@ class ViewConfiguration { @Deprecated(''' Use the `view` property instead. ''') - final FlutterView? window; - final FlutterView? view; + FlutterView? get window => _view; + FlutterView? get view => _view; + + final FlutterView? _view; /// The pixel density of the output surface. final double devicePixelRatio; From 56e558cca6d26765dac6ac5bf815074f04d30bca Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 23/46] Add doc comment to view --- lib/ui/platform_dispatcher.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index c03719c99ba45..bb45cc108a8f3 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1344,6 +1344,11 @@ class ViewConfiguration { Use the `view` property instead. ''') FlutterView? get window => _view; + + /// The top level view into which the view is placed and its geometry is + /// relative to. + /// + /// If null, then this configuration represents a top level view itself. FlutterView? get view => _view; final FlutterView? _view; From 278f7249916621f6611e8da715e76511eae39178 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 24/46] Document view and window parameters in the constructor of ViewConfiguration --- lib/ui/platform_dispatcher.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index bb45cc108a8f3..b0a3406a56f70 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1290,6 +1290,10 @@ 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(''' From ce6db6287229dc338146fc0d3743956701088700 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 25/46] Sync web api --- lib/web_ui/lib/platform_dispatcher.dart | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index 1b35ec423acd1..e9af309d889ed 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -190,11 +190,11 @@ class PlatformConfiguration { class ViewConfiguration { const ViewConfiguration({ - this.view, + FlutterView? view, @Deprecated(''' - Renaming window to view as the class `FlutterWindow` has been deprecated. + Use the `view` property instead. ''') - this.window, + FlutterView? window, this.devicePixelRatio = 1.0, this.geometry = Rect.zero, this.visible = false, @@ -204,7 +204,8 @@ class ViewConfiguration { this.padding = WindowPadding.zero, this.gestureSettings = const GestureSettings(), this.displayFeatures = const [], - }); + }) : assert(!(window != null && view != null)), + _view = view ?? window; ViewConfiguration copyWith({ FlutterView? view, @@ -221,7 +222,6 @@ class ViewConfiguration { }) { return ViewConfiguration( view: view ?? this.view, - window: window ?? this.window, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, geometry: geometry ?? this.geometry, visible: visible ?? this.visible, @@ -237,8 +237,9 @@ class ViewConfiguration { @Deprecated(''' Renaming window to view as the class `FlutterWindow` has been deprecated. ''') - final FlutterView? window; - final FlutterView? view; + FlutterView? get window => _view; + FlutterView? get view => _view; + final FlutterView? _view; final double devicePixelRatio; final Rect geometry; final bool visible; From 23be98b9c5f2eee6ceb810a7f6f9a67ea3383555 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 26/46] Refactor assertion --- lib/ui/platform_dispatcher.dart | 2 +- lib/web_ui/lib/platform_dispatcher.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index b0a3406a56f70..0fd65b8c4426f 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1309,7 +1309,7 @@ class ViewConfiguration { this.padding = WindowPadding.zero, this.gestureSettings = const GestureSettings(), this.displayFeatures = const [], - }) : assert(!(window != null && view != null)), + }) : assert(window == null || view == null), _view = view ?? window; /// Copy this configuration with some fields replaced. diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index e9af309d889ed..74b01224c8acf 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -204,7 +204,7 @@ class ViewConfiguration { this.padding = WindowPadding.zero, this.gestureSettings = const GestureSettings(), this.displayFeatures = const [], - }) : assert(!(window != null && view != null)), + }) : assert(window == null || view == null), _view = view ?? window; ViewConfiguration copyWith({ From 40922b5c8b5b029fe619801b8435d1aa37b8d926 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 27/46] Improve deprecation message --- lib/ui/platform_dispatcher.dart | 6 +++++- lib/web_ui/lib/platform_dispatcher.dart | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 0fd65b8c4426f..e2841e51aa7d2 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1298,6 +1298,8 @@ class 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, @@ -1345,7 +1347,9 @@ class ViewConfiguration { /// /// If null, then this configuration represents a top level view itself. @Deprecated(''' - Use the `view` property instead. + 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; diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index 74b01224c8acf..d6809cf8e6157 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -193,6 +193,8 @@ class 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, @@ -235,7 +237,9 @@ class ViewConfiguration { } @Deprecated(''' - Renaming window to view as the class `FlutterWindow` has been 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; From 75d1cbe7771e687410113c9d64626f2c30b7523a Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 28/46] Improve window documentation --- lib/ui/platform_dispatcher.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index e2841e51aa7d2..9c65369b76350 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1342,10 +1342,9 @@ class ViewConfiguration { ); } - /// The top level view into which the view is placed and its geometry is - /// relative to. + /// The top level view for which this [ViewConfiguration]'s properties apply to. /// - /// If null, then this configuration represents a top level view itself. + /// 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. @@ -1353,10 +1352,9 @@ class ViewConfiguration { ''') FlutterView? get window => _view; - /// The top level view into which the view is placed and its geometry is - /// relative to. + /// The top level view for which this [ViewConfiguration]'s properties apply to. /// - /// If null, then this configuration represents a top level view itself. + /// If this property is null, this [ViewConfiguration] is a top level view. FlutterView? get view => _view; final FlutterView? _view; From e8df09fe6b0aec9bad6f1449f20c638b46bd75c0 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 29/46] Assert one of window/view is null in copyWith ViewConfiguration --- lib/ui/platform_dispatcher.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 9c65369b76350..1bf06e7179865 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -226,7 +226,6 @@ class PlatformDispatcher { } _viewConfigurations[id] = previousConfiguration.copyWith( view: _views[id], - window: _views[id], devicePixelRatio: devicePixelRatio, geometry: Rect.fromLTWH(0.0, 0.0, width, height), viewPadding: WindowPadding._( @@ -1328,6 +1327,7 @@ class ViewConfiguration { GestureSettings? gestureSettings, List? displayFeatures, }) { + assert(view == null || window == null); return ViewConfiguration( view: view ?? this.view, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, From 0209cf65823a92f3b6187b8f84b089bc7626e59b Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 30/46] Remove EngineFlutterWindowView --- lib/web_ui/lib/src/engine/window.dart | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/lib/web_ui/lib/src/engine/window.dart b/lib/web_ui/lib/src/engine/window.dart index e42098a32d376..1bd48eba36ca3 100644 --- a/lib/web_ui/lib/src/engine/window.dart +++ b/lib/web_ui/lib/src/engine/window.dart @@ -342,28 +342,6 @@ class EngineSingletonFlutterWindow extends EngineFlutterWindow { double? _debugDevicePixelRatio; } -/// A type of [FlutterView] that can be hosted inside of a [FlutterWindow]. -class EngineFlutterWindowView extends ui.FlutterView { - EngineFlutterWindowView._(this._viewId, this.platformDispatcher); - - final Object _viewId; - - @override - Object get viewId => _viewId; - - @override - final ui.PlatformDispatcher platformDispatcher; - - @override - ui.ViewConfiguration get viewConfiguration { - final EnginePlatformDispatcher engineDispatcher = - platformDispatcher as EnginePlatformDispatcher; - assert(engineDispatcher.windowConfigurations.containsKey(_viewId)); - return engineDispatcher.windowConfigurations[_viewId] ?? - const ui.ViewConfiguration(); - } -} - /// The window singleton. /// /// `dart:ui` window delegates to this value. However, this value has a wider From ec2597533dcd8b7bbfb5216887c915094af841a5 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 31/46] Make dartdoc happy --- lib/ui/platform_dispatcher.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index 1bf06e7179865..ab4541ee6bf9a 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1290,8 +1290,8 @@ class PlatformConfiguration { 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 + /// 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, From 8199e721121231d2e4871a0576628d729209e843 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 32/46] Refactor copyWith() --- lib/ui/platform_dispatcher.dart | 2 +- lib/web_ui/lib/platform_dispatcher.dart | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index ab4541ee6bf9a..acc8e8923f2e4 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1329,7 +1329,7 @@ class ViewConfiguration { }) { assert(view == null || window == null); return ViewConfiguration( - view: view ?? this.view, + view: view ?? window ?? _view, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, geometry: geometry ?? this.geometry, visible: visible ?? this.visible, diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index d6809cf8e6157..b863c6710f00a 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -222,8 +222,9 @@ class ViewConfiguration { GestureSettings? gestureSettings, List? displayFeatures, }) { + assert(view == null || window == null); return ViewConfiguration( - view: view ?? this.view, + view: view ?? window ?? _view, devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, geometry: geometry ?? this.geometry, visible: visible ?? this.visible, From b3164c8fb90460acf18550c66b18bee449b1ca93 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 33/46] Change to internal map implementation --- lib/web_ui/lib/src/engine/platform_dispatcher.dart | 12 +++++------- lib/web_ui/lib/src/engine/window.dart | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 4c223975c2d6c..16c910f9c36cb 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -138,10 +138,8 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { /// The current list of windows, @override - Iterable get views => _views.values; - final Map _views = {}; - ui.FlutterView? getViewById(Object id) => _views[id]; - void addView(Object id, ui.FlutterView view) => _views[id] = view; + Iterable get views => viewData.values; + final Map viewData = {}; /// A map of opaque platform window identifiers to window configurations. /// @@ -482,7 +480,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { // TODO(a-wallen): As multi-window support expands, the pop call // will need to include the window ID. Right now only one window is // supported. - (_views[0]! as EngineFlutterWindow) + (viewData[0]! as EngineFlutterWindow) .browserHistory .exit() .then((_) { @@ -572,7 +570,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { // TODO(a-wallen): As multi-window support expands, the navigation call // will need to include the window ID. Right now only one window is // supported. - (_views[0]! as EngineFlutterWindow) + (viewData[0]! as EngineFlutterWindow) .handleNavigationMessage(data) .then((bool handled) { if (handled) { @@ -1161,7 +1159,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { @override String get defaultRouteName { return _defaultRouteName ??= - (_views[0]! as EngineFlutterWindow).browserHistory.currentPath; + (viewData[0]! as EngineFlutterWindow).browserHistory.currentPath; } /// Lazily initialized when the `defaultRouteName` getter is invoked. diff --git a/lib/web_ui/lib/src/engine/window.dart b/lib/web_ui/lib/src/engine/window.dart index 1bd48eba36ca3..5256007612179 100644 --- a/lib/web_ui/lib/src/engine/window.dart +++ b/lib/web_ui/lib/src/engine/window.dart @@ -46,7 +46,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { EngineFlutterWindow(this._viewId, this.platformDispatcher) { final EnginePlatformDispatcher engineDispatcher = platformDispatcher as EnginePlatformDispatcher; - engineDispatcher.addView(_viewId, this); + engineDispatcher.viewData[_viewId] = this; engineDispatcher.windowConfigurations[_viewId] = const ui.ViewConfiguration(); if (_isUrlStrategySet) { _browserHistory = createHistoryForExistingState(_customUrlStrategy); From d42d9ec09dc413d2a11f62ad83f262ebbad77394 Mon Sep 17 00:00:00 2001 From: Alex Wallen Date: Wed, 4 Jan 2023 07:46:12 -1000 Subject: [PATCH 34/46] final private refactor Co-authored-by: Michael Goderbauer --- lib/ui/window.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 7ad162bbbc58b..5e008ca28ad19 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -55,8 +55,7 @@ class FlutterView { FlutterView._(this._viewId, this.platformDispatcher); /// The opaque ID for this view. - final Object _viewId; - Object get viewId => _viewId; + final Object viewId; /// The platform dispatcher that this view is registered with, and gets its /// information from. From 5c2e0a9d2a7250ab23e45dccd573c684fbf0791c Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 35/46] Deprecate window parameter in copyWith --- lib/ui/platform_dispatcher.dart | 5 +++++ lib/ui/window.dart | 6 +++--- lib/web_ui/lib/platform_dispatcher.dart | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ui/platform_dispatcher.dart b/lib/ui/platform_dispatcher.dart index acc8e8923f2e4..b3b4de7369012 100644 --- a/lib/ui/platform_dispatcher.dart +++ b/lib/ui/platform_dispatcher.dart @@ -1316,6 +1316,11 @@ class ViewConfiguration { /// Copy this configuration with some fields replaced. 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, diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 5e008ca28ad19..b823dd34ea215 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -52,7 +52,7 @@ part of dart.ui; /// that in the [padding], which is always safe to use for such /// calculations. class FlutterView { - FlutterView._(this._viewId, this.platformDispatcher); + FlutterView._(this.viewId, this.platformDispatcher); /// The opaque ID for this view. final Object viewId; @@ -63,8 +63,8 @@ class FlutterView { /// The configuration of this view. ViewConfiguration get viewConfiguration { - assert(platformDispatcher._viewConfigurations.containsKey(_viewId)); - return platformDispatcher._viewConfigurations[_viewId]!; + assert(platformDispatcher._viewConfigurations.containsKey(viewId)); + return platformDispatcher._viewConfigurations[viewId]!; } /// The number of device pixels for each logical pixel for the screen this diff --git a/lib/web_ui/lib/platform_dispatcher.dart b/lib/web_ui/lib/platform_dispatcher.dart index b863c6710f00a..5d569d985264c 100644 --- a/lib/web_ui/lib/platform_dispatcher.dart +++ b/lib/web_ui/lib/platform_dispatcher.dart @@ -211,6 +211,11 @@ class ViewConfiguration { 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, From 12d4871a2810500f05841007a7d9862f6bfe769a Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 36/46] Repl Window w/ View --- testing/scenario_app/lib/src/scenario.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/scenario_app/lib/src/scenario.dart b/testing/scenario_app/lib/src/scenario.dart index 6e66c862280e9..68c5d6506fa55 100644 --- a/testing/scenario_app/lib/src/scenario.dart +++ b/testing/scenario_app/lib/src/scenario.dart @@ -7,7 +7,7 @@ import 'dart:ui'; /// A scenario to run for testing. abstract class Scenario { - /// Creates a new scenario using a specific FlutterWindow instance. + /// Creates a new scenario using a specific FlutterView instance. Scenario(this.dispatcher); /// The window used by this scenario. May be mocked. From 15ebe5919beb84be839523985f6c405099387d3e Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 37/46] Add tests for viewConfiguration --- .../test/engine/platform_dispatcher_test.dart | 30 ++++++++++++++++ testing/dart/BUILD.gn | 1 + testing/dart/platform_dispatcher_test.dart | 36 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 testing/dart/platform_dispatcher_test.dart diff --git a/lib/web_ui/test/engine/platform_dispatcher_test.dart b/lib/web_ui/test/engine/platform_dispatcher_test.dart index 2568f27181e36..65c92d201e2fd 100644 --- a/lib/web_ui/test/engine/platform_dispatcher_test.dart +++ b/lib/web_ui/test/engine/platform_dispatcher_test.dart @@ -11,6 +11,8 @@ 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); } @@ -160,6 +162,34 @@ void testMain() { expect(ui.PlatformDispatcher.instance.textScaleFactor, findBrowserTextScaleFactor()); }); }); + + test('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.window, window); + // ignore: deprecated_member_use + expect(viewConfiguration.window, viewConfiguration.view); + }); + + test('Calling copyWith on a ViewConfiguration with both a window and view throws an error', () { + 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/testing/dart/BUILD.gn b/testing/dart/BUILD.gn index 1c372c5ed9ea1..7ee975b6d384e 100644 --- a/testing/dart/BUILD.gn +++ b/testing/dart/BUILD.gn @@ -37,6 +37,7 @@ 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/testing/dart/platform_dispatcher_test.dart b/testing/dart/platform_dispatcher_test.dart new file mode 100644 index 0000000000000..b21841c919fe8 --- /dev/null +++ b/testing/dart/platform_dispatcher_test.dart @@ -0,0 +1,36 @@ +// 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('ViewConfiguration asserts that both window and view are not provided', () async { + 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", () async { + 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('Calling copyWith on a ViewConfiguration with both a window and view throws an error', () async { + final FlutterView view = PlatformDispatcher.instance.views.first; + expectAssertion(() { + // ignore: deprecated_member_use + return ViewConfiguration(view: view)..copyWith(view: view, window: view); + }); + }); +} From 1f71e01b1f68900807275e736fe06a88eae3cdbf Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 38/46] Make test descriptions better --- lib/web_ui/test/engine/platform_dispatcher_test.dart | 4 ++-- testing/dart/platform_dispatcher_test.dart | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/web_ui/test/engine/platform_dispatcher_test.dart b/lib/web_ui/test/engine/platform_dispatcher_test.dart index 65c92d201e2fd..6cd004915b966 100644 --- a/lib/web_ui/test/engine/platform_dispatcher_test.dart +++ b/lib/web_ui/test/engine/platform_dispatcher_test.dart @@ -163,7 +163,7 @@ void testMain() { }); }); - test('ViewConfiguration asserts that both window and view are not provided', () { + 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); @@ -183,7 +183,7 @@ void testMain() { expect(viewConfiguration.window, viewConfiguration.view); }); - test('Calling copyWith on a ViewConfiguration with both a window and view throws an error', () { + 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(() { diff --git a/testing/dart/platform_dispatcher_test.dart b/testing/dart/platform_dispatcher_test.dart index b21841c919fe8..ae7f406de9842 100644 --- a/testing/dart/platform_dispatcher_test.dart +++ b/testing/dart/platform_dispatcher_test.dart @@ -7,7 +7,7 @@ import 'dart:ui'; import 'package:litetest/litetest.dart'; void main() { - test('ViewConfiguration asserts that both window and view are not provided', () async { + test('A ViewConfiguration asserts that both window and view are not provided', () { expectAssertion(() { return ViewConfiguration( // ignore: deprecated_member_use @@ -17,7 +17,7 @@ void main() { }); }); - test("A ViewConfiguration's view and window are backed with the same property", () async { + 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 @@ -26,7 +26,7 @@ void main() { expect(viewConfiguration.window, viewConfiguration.view); }); - test('Calling copyWith on a ViewConfiguration with both a window and view throws an error', () async { + 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 From 6d531ba35e27e11034e5ed3ee44d283dae81b3e0 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 39/46] Add ViewConfiguration initialization with window tests --- lib/web_ui/test/engine/platform_dispatcher_test.dart | 6 ++++++ testing/dart/platform_dispatcher_test.dart | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/web_ui/test/engine/platform_dispatcher_test.dart b/lib/web_ui/test/engine/platform_dispatcher_test.dart index 6cd004915b966..fb7e3d7c09c0f 100644 --- a/lib/web_ui/test/engine/platform_dispatcher_test.dart +++ b/lib/web_ui/test/engine/platform_dispatcher_test.dart @@ -183,6 +183,12 @@ void testMain() { 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 + ui.ViewConfiguration(window: 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 diff --git a/testing/dart/platform_dispatcher_test.dart b/testing/dart/platform_dispatcher_test.dart index ae7f406de9842..dc19fba3fe57f 100644 --- a/testing/dart/platform_dispatcher_test.dart +++ b/testing/dart/platform_dispatcher_test.dart @@ -26,6 +26,12 @@ void main() { 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(() { From 3a704826a504af812a1c9d873dc9738ce15a1d21 Mon Sep 17 00:00:00 2001 From: Alex Wallen Date: Thu, 5 Jan 2023 07:39:56 -1000 Subject: [PATCH 40/46] Update lib/web_ui/lib/src/engine/window.dart Co-authored-by: David Iglesias --- lib/web_ui/lib/src/engine/window.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/web_ui/lib/src/engine/window.dart b/lib/web_ui/lib/src/engine/window.dart index 5256007612179..19b0e84c1c2b0 100644 --- a/lib/web_ui/lib/src/engine/window.dart +++ b/lib/web_ui/lib/src/engine/window.dart @@ -58,10 +58,8 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { }); } - final Object _viewId; - @override - Object get viewId => _viewId; + final Object viewId; @override final ui.PlatformDispatcher platformDispatcher; From 2a4f807a8d92e9a88b1da4b321327e156553d237 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 41/46] Refactor TODO message --- lib/web_ui/lib/src/engine/platform_dispatcher.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 16c910f9c36cb..f7ae7b0d76438 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -478,7 +478,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { switch (decoded.method) { case 'SystemNavigator.pop': // TODO(a-wallen): As multi-window support expands, the pop call - // will need to include the window ID. Right now only one window is + // will need to include the view ID. Right now only one view is // supported. (viewData[0]! as EngineFlutterWindow) .browserHistory @@ -568,7 +568,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { case 'flutter/navigation': // TODO(a-wallen): As multi-window support expands, the navigation call - // will need to include the window ID. Right now only one window is + // will need to include the view ID. Right now only one view is // supported. (viewData[0]! as EngineFlutterWindow) .handleNavigationMessage(data) From 9f4ac26c017f60b881c30ca3ac580ef18b6abd8a Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 42/46] Add expectation :) --- lib/web_ui/test/engine/platform_dispatcher_test.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/web_ui/test/engine/platform_dispatcher_test.dart b/lib/web_ui/test/engine/platform_dispatcher_test.dart index fb7e3d7c09c0f..b19f2c40bb64e 100644 --- a/lib/web_ui/test/engine/platform_dispatcher_test.dart +++ b/lib/web_ui/test/engine/platform_dispatcher_test.dart @@ -186,7 +186,9 @@ void testMain() { test('Initialize a ViewConfiguration with a window', () { final ui.FlutterView window = EngineFlutterWindow(0, ui.PlatformDispatcher.instance); // ignore: deprecated_member_use - ui.ViewConfiguration(window: window); + 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", () { From b2b410ee9a0cc534dee70c3033d37a8a49271a08 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 43/46] Fix viewId in window.dart --- lib/web_ui/lib/src/engine/window.dart | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/web_ui/lib/src/engine/window.dart b/lib/web_ui/lib/src/engine/window.dart index 19b0e84c1c2b0..57081a97afe78 100644 --- a/lib/web_ui/lib/src/engine/window.dart +++ b/lib/web_ui/lib/src/engine/window.dart @@ -43,11 +43,11 @@ set customUrlStrategy(UrlStrategy? strategy) { /// The Web implementation of [ui.SingletonFlutterWindow]. class EngineFlutterWindow extends ui.SingletonFlutterWindow { - EngineFlutterWindow(this._viewId, this.platformDispatcher) { + EngineFlutterWindow(this.viewId, this.platformDispatcher) { final EnginePlatformDispatcher engineDispatcher = platformDispatcher as EnginePlatformDispatcher; - engineDispatcher.viewData[_viewId] = this; - engineDispatcher.windowConfigurations[_viewId] = const ui.ViewConfiguration(); + engineDispatcher.viewData[viewId] = this; + engineDispatcher.windowConfigurations[viewId] = const ui.ViewConfiguration(); if (_isUrlStrategySet) { _browserHistory = createHistoryForExistingState(_customUrlStrategy); } @@ -203,8 +203,8 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { ui.ViewConfiguration get viewConfiguration { final EnginePlatformDispatcher engineDispatcher = platformDispatcher as EnginePlatformDispatcher; - assert(engineDispatcher.windowConfigurations.containsKey(_viewId)); - return engineDispatcher.windowConfigurations[_viewId] ?? + assert(engineDispatcher.windowConfigurations.containsKey(viewId)); + return engineDispatcher.windowConfigurations[viewId] ?? const ui.ViewConfiguration(); } From 4bbd09dc686f52b9442ddf37e631384e6dacda75 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 44/46] Remove double deprecation access --- lib/web_ui/test/engine/platform_dispatcher_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web_ui/test/engine/platform_dispatcher_test.dart b/lib/web_ui/test/engine/platform_dispatcher_test.dart index b19f2c40bb64e..e304394e7e30a 100644 --- a/lib/web_ui/test/engine/platform_dispatcher_test.dart +++ b/lib/web_ui/test/engine/platform_dispatcher_test.dart @@ -178,7 +178,7 @@ void testMain() { final ui.FlutterView window = EngineFlutterWindow(0, ui.PlatformDispatcher.instance); final ui.ViewConfiguration viewConfiguration = ui.ViewConfiguration(view: window); // ignore: deprecated_member_use - expect(viewConfiguration.window, window); + expect(viewConfiguration.view, window); // ignore: deprecated_member_use expect(viewConfiguration.window, viewConfiguration.view); }); From 82defe477934235352257868ab34096ff13335b5 Mon Sep 17 00:00:00 2001 From: Alex Wallen Date: Thu, 5 Jan 2023 08:11:51 -1000 Subject: [PATCH 45/46] punctuation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com> --- lib/web_ui/lib/src/engine/platform_dispatcher.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index f7ae7b0d76438..6207694cb48bc 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -136,7 +136,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { _onPlatformConfigurationChanged, _onPlatformConfigurationChangedZone); } - /// The current list of windows, + /// The current list of windows. @override Iterable get views => viewData.values; final Map viewData = {}; From 8fa153bb72ad174e862c2f92ef886a74788213e3 Mon Sep 17 00:00:00 2001 From: a-wallen Date: Wed, 21 Dec 2022 17:58:49 -0800 Subject: [PATCH 46/46] Add kSingletonWindowID const --- lib/web_ui/lib/src/engine/platform_dispatcher.dart | 6 +++--- lib/web_ui/lib/src/engine/window.dart | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/web_ui/lib/src/engine/platform_dispatcher.dart b/lib/web_ui/lib/src/engine/platform_dispatcher.dart index 6207694cb48bc..b34226fd4ee3e 100644 --- a/lib/web_ui/lib/src/engine/platform_dispatcher.dart +++ b/lib/web_ui/lib/src/engine/platform_dispatcher.dart @@ -480,7 +480,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { // TODO(a-wallen): As multi-window support expands, the pop call // will need to include the view ID. Right now only one view is // supported. - (viewData[0]! as EngineFlutterWindow) + (viewData[kSingletonViewId]! as EngineFlutterWindow) .browserHistory .exit() .then((_) { @@ -570,7 +570,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { // TODO(a-wallen): As multi-window support expands, the navigation call // will need to include the view ID. Right now only one view is // supported. - (viewData[0]! as EngineFlutterWindow) + (viewData[kSingletonViewId]! as EngineFlutterWindow) .handleNavigationMessage(data) .then((bool handled) { if (handled) { @@ -1159,7 +1159,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { @override String get defaultRouteName { return _defaultRouteName ??= - (viewData[0]! as EngineFlutterWindow).browserHistory.currentPath; + (viewData[kSingletonViewId]! as EngineFlutterWindow).browserHistory.currentPath; } /// Lazily initialized when the `defaultRouteName` getter is invoked. diff --git a/lib/web_ui/lib/src/engine/window.dart b/lib/web_ui/lib/src/engine/window.dart index 57081a97afe78..1d8e2d13bcef9 100644 --- a/lib/web_ui/lib/src/engine/window.dart +++ b/lib/web_ui/lib/src/engine/window.dart @@ -27,6 +27,9 @@ typedef _HandleMessageCallBack = Future Function(); /// When set to true, all platform messages will be printed to the console. const bool debugPrintPlatformMessages = false; +/// The view ID for a singleton flutter window. +const int kSingletonViewId = 0; + /// Whether [_customUrlStrategy] has been set or not. /// /// It is valid to set [_customUrlStrategy] to null, so we can't use a null @@ -346,7 +349,7 @@ class EngineSingletonFlutterWindow extends EngineFlutterWindow { /// API surface, providing Web-specific functionality that the standard /// `dart:ui` version does not. final EngineSingletonFlutterWindow window = - EngineSingletonFlutterWindow(0, EnginePlatformDispatcher.instance); + EngineSingletonFlutterWindow(kSingletonViewId, EnginePlatformDispatcher.instance); /// The Web implementation of [ui.WindowPadding]. class WindowPadding implements ui.WindowPadding {