-
Notifications
You must be signed in to change notification settings - Fork 6k
Remove single view assumptions from window.dart
#38453
Changes from 16 commits
5f9cbb0
1f5376a
def8a49
ee1d3a3
59a1b34
559ab5c
3ef5f40
368ec15
570cc18
109c396
b08531d
d8425c2
6a8fd2e
4c659b1
48832da
9504d93
bdb74d2
4453c99
5103c3a
184e658
864a0ee
0ae4700
56e558c
278f724
ce6db62
23be98b
40922b5
75d1cbe
e8df09f
0209cf6
ec25975
8199e72
b3164c8
d42d9ec
5c2e0a9
12d4871
15ebe59
1f71e01
6d531ba
3a70482
2a4f807
9f4ac26
b2b410e
4bbd09d
82defe4
8fa153b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -222,9 +222,10 @@ 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( | ||
| view: _views[id], | ||
| window: _views[id], | ||
| devicePixelRatio: devicePixelRatio, | ||
| geometry: Rect.fromLTWH(0.0, 0.0, width, height), | ||
|
|
@@ -1290,6 +1291,10 @@ class PlatformConfiguration { | |
| class ViewConfiguration { | ||
| /// A const constructor for an immutable [ViewConfiguration]. | ||
| const ViewConfiguration({ | ||
| this.view, | ||
| @Deprecated(''' | ||
|
goderbauer marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ultimately, it's up to you, but I would probably do the rename (with deprecation) in a separate PR that's dedicated to just that. That may make it easier to land these two changes and potentially roll back if there are issues.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a good idea. I'd like to address all the feedback and get an LGTM before I cherry-pick the commits from this PR into another one. |
||
| Renaming window to view since `FlutterWindow` has been removed from dart::ui. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, you're right 👍
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion the explanation is unnecessary here. Just tell the user how to change it. If you really want to explain it, add a link to the design doc, or to this PR with an expanded paragraph of description.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reopening as I don't think the second part was addressed:
|
||
| ''') | ||
| this.window, | ||
| this.devicePixelRatio = 1.0, | ||
| this.geometry = Rect.zero, | ||
|
|
@@ -1304,6 +1309,7 @@ class ViewConfiguration { | |
|
|
||
| /// Copy this configuration with some fields replaced. | ||
| ViewConfiguration copyWith({ | ||
| FlutterView? view, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deprecate the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| FlutterView? window, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy with should do something with the window property instead of silently ignoring it. |
||
| double? devicePixelRatio, | ||
| Rect? geometry, | ||
|
|
@@ -1316,6 +1322,7 @@ class ViewConfiguration { | |
| List<DisplayFeature>? displayFeatures, | ||
| }) { | ||
| return ViewConfiguration( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably assert that at least one of window, view is null
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added 7d2ad3e. |
||
| view: view ?? this.view, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need to deal with the window here in addition to the view for backwards compatibility reasons: window: window ?? this.window,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll get an error that the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This snippet would guarantee that both assert(window != null || view != null);
return ViewConfiguration(
view: view ?? window ?? _view,
);
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is also what I would go for.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @dkwingsmt 👍
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 8199e72 has the changes requested. |
||
| window: window ?? this.window, | ||
| devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, | ||
| geometry: geometry ?? this.geometry, | ||
|
|
@@ -1333,7 +1340,11 @@ class ViewConfiguration { | |
| /// relative to. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not directly related to your PR, but this doc comment doesn't make much sense: "[The] view into which the view is placed"?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, the comment below: What is the "top level view itself"?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about this 75d1cbe? |
||
| /// | ||
| /// If null, then this configuration represents a top level view itself. | ||
| @Deprecated(''' | ||
| Renaming window to view since `FlutterWindow` has been removed from dart::ui. | ||
| ''') | ||
| final FlutterView? window; | ||
| final FlutterView? view; | ||
|
a-wallen marked this conversation as resolved.
Outdated
|
||
|
|
||
| /// The pixel density of the output surface. | ||
| final double devicePixelRatio; | ||
|
|
@@ -1427,7 +1438,7 @@ class ViewConfiguration { | |
|
|
||
| @override | ||
| String toString() { | ||
| return '$runtimeType[window: $window, geometry: $geometry]'; | ||
| return '$runtimeType[view: $view, geometry: $geometry]'; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1666,7 +1677,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, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 [FlutterWindow] 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]. | ||
|
a-wallen marked this conversation as resolved.
Outdated
|
||
| /// | ||
| /// ## Insets and Padding | ||
| /// | ||
|
|
@@ -51,18 +51,22 @@ 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: | ||
| /// | ||
| /// * [FlutterWindow], 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move the private field below the getter. Our style is to have the following order: getter, private field, setter. The setter may be optional, though.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure thing. Is that documented somewhere?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually couldn't find this in the style guide, but it is something we try to follow. We should add it.
dkwingsmt marked this conversation as resolved.
Outdated
|
||
| Object get viewId => _viewId; | ||
|
a-wallen marked this conversation as resolved.
Outdated
|
||
|
|
||
| /// 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 +285,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 +300,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 { | ||
|
dkwingsmt marked this conversation as resolved.
|
||
| SingletonFlutterWindow._(super.windowId, super.platformDispatcher) | ||
| : super._(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,10 @@ class PlatformConfiguration { | |
|
|
||
| class ViewConfiguration { | ||
| const ViewConfiguration({ | ||
| this.view, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The web side should be treated the same as |
||
| @Deprecated(''' | ||
| Renaming window to view as the class `FlutterWindow` has been deprecated. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: keep these consistent with the other file? |
||
| ''') | ||
| this.window, | ||
| this.devicePixelRatio = 1.0, | ||
| this.geometry = Rect.zero, | ||
|
|
@@ -203,7 +207,8 @@ class ViewConfiguration { | |
| }); | ||
|
|
||
| ViewConfiguration copyWith({ | ||
| FlutterWindow? window, | ||
| FlutterView? view, | ||
| FlutterView? window, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deprecate window param?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| double? devicePixelRatio, | ||
| Rect? geometry, | ||
| bool? visible, | ||
|
|
@@ -215,6 +220,7 @@ class ViewConfiguration { | |
| List<DisplayFeature>? displayFeatures, | ||
| }) { | ||
| return ViewConfiguration( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert here that at most of view, window is not-null. |
||
| view: view ?? this.view, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assert that only one is provided and add window: window ?? this.window,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved. See #38453 (comment). |
||
| window: window ?? this.window, | ||
| devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, | ||
| geometry: geometry ?? this.geometry, | ||
|
|
@@ -228,7 +234,11 @@ class ViewConfiguration { | |
| ); | ||
| } | ||
|
|
||
| final FlutterWindow? window; | ||
| @Deprecated(''' | ||
| Renaming window to view as the class `FlutterWindow` has been deprecated. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keep these consistent. |
||
| ''') | ||
| final FlutterView? window; | ||
| final FlutterView? view; | ||
| final double devicePixelRatio; | ||
| final Rect geometry; | ||
| final bool visible; | ||
|
|
@@ -241,7 +251,7 @@ class ViewConfiguration { | |
|
|
||
| @override | ||
| String toString() { | ||
| return '$runtimeType[window: $window, geometry: $geometry]'; | ||
| return '$runtimeType[view: $view, geometry: $geometry]'; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -138,9 +138,10 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { | |||||||||
|
|
||||||||||
| /// The current list of windows, | ||||||||||
|
a-wallen marked this conversation as resolved.
Outdated
|
||||||||||
| @override | ||||||||||
| Iterable<ui.FlutterView> get views => _windows.values; | ||||||||||
| Map<Object, ui.FlutterWindow> get windows => _windows; | ||||||||||
| final Map<Object, ui.FlutterWindow> _windows = <Object, ui.FlutterWindow>{}; | ||||||||||
| Iterable<ui.FlutterView> get views => _views.values; | ||||||||||
| final Map<Object, ui.FlutterView> _views = <Object, ui.FlutterView>{}; | ||||||||||
| ui.FlutterView? getViewById(Object id) => _views[id]; | ||||||||||
| void addView(Object id, ui.FlutterView view) => _views[id] = view; | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is all private, you could just replace all of this with something like:
Suggested change
... and then elsewhere operate directly with that map. |
||||||||||
|
|
||||||||||
| /// A map of opaque platform window identifiers to window configurations. | ||||||||||
| /// | ||||||||||
|
|
@@ -481,7 +482,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 | ||||||||||
|
a-wallen marked this conversation as resolved.
Outdated
|
||||||||||
| // supported. | ||||||||||
| (_windows[0]! as EngineFlutterWindow) | ||||||||||
| (_views[0]! as EngineFlutterWindow) | ||||||||||
| .browserHistory | ||||||||||
| .exit() | ||||||||||
| .then((_) { | ||||||||||
|
|
@@ -571,7 +572,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 +1161,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. | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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.windows[_windowId] = this; | ||
| engineDispatcher.windowConfigurations[_windowId] = const ui.ViewConfiguration(); | ||
| engineDispatcher.addView(_viewId, this); | ||
| engineDispatcher.windowConfigurations[_viewId] = const ui.ViewConfiguration(); | ||
| if (_isUrlStrategySet) { | ||
| _browserHistory = createHistoryForExistingState(_customUrlStrategy); | ||
| } | ||
|
|
@@ -58,7 +58,10 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow { | |
| }); | ||
| } | ||
|
|
||
| final Object _windowId; | ||
| final Object _viewId; | ||
|
|
||
| @override | ||
| Object get viewId => _viewId; | ||
|
a-wallen marked this conversation as resolved.
Outdated
|
||
|
|
||
| @override | ||
| final ui.PlatformDispatcher platformDispatcher; | ||
|
|
@@ -202,8 +205,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(); | ||
| } | ||
|
|
||
|
|
@@ -340,11 +343,14 @@ class EngineSingletonFlutterWindow extends EngineFlutterWindow { | |
| } | ||
|
|
||
| /// A type of [FlutterView] that can be hosted inside of a [FlutterWindow]. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update the comment since FlutterWindow doesn't exist anymore. The name of the class "EngineFlutterWindowView" also seems odd with the "Window" in there. Not sure what this is used for, but is this still needed? |
||
| 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; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.