-
Notifications
You must be signed in to change notification settings - Fork 6k
Remove single view assumptions from window.dart
#38453
Changes from 33 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,10 +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( | ||
window: _views[id], | ||
view: _views[id], | ||
devicePixelRatio: devicePixelRatio, | ||
geometry: Rect.fromLTWH(0.0, 0.0, width, height), | ||
viewPadding: WindowPadding._( | ||
|
@@ -1289,8 +1289,18 @@ 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({ | ||
this.window, | ||
FlutterView? view, | ||
@Deprecated(''' | ||
goderbauer marked this conversation as resolved.
Show resolved
Hide resolved
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. 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. |
||
Use the `view` property instead. | ||
This change is related to adding multi-view support in Flutter. | ||
This feature was deprecated after 3.7.0-1.2.pre. | ||
''') | ||
FlutterView? window, | ||
this.devicePixelRatio = 1.0, | ||
this.geometry = Rect.zero, | ||
this.visible = false, | ||
|
@@ -1300,10 +1310,12 @@ class ViewConfiguration { | |
this.padding = WindowPadding.zero, | ||
this.gestureSettings = const GestureSettings(), | ||
this.displayFeatures = const <DisplayFeature>[], | ||
}); | ||
}) : assert(window == null || view == null), | ||
_view = view ?? window; | ||
|
||
/// Copy this configuration with some fields replaced. | ||
ViewConfiguration copyWith({ | ||
FlutterView? view, | ||
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 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, | ||
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, | ||
|
@@ -1315,8 +1327,9 @@ class ViewConfiguration { | |
GestureSettings? gestureSettings, | ||
List<DisplayFeature>? displayFeatures, | ||
}) { | ||
assert(view == null || window == null); | ||
return ViewConfiguration( | ||
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 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. |
||
window: window ?? this.window, | ||
view: view ?? window ?? _view, | ||
devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, | ||
geometry: geometry ?? this.geometry, | ||
visible: visible ?? this.visible, | ||
|
@@ -1329,11 +1342,22 @@ 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 this property is null, this [ViewConfiguration] is a top level view. | ||
@Deprecated(''' | ||
Use the `view` property instead. | ||
This change is related to adding multi-view support in Flutter. | ||
This feature was deprecated after 3.7.0-1.2.pre. | ||
''') | ||
FlutterView? get window => _view; | ||
|
||
/// The top level view for which this [ViewConfiguration]'s properties apply to. | ||
/// | ||
/// If null, then this configuration represents a top level view itself. | ||
final FlutterView? window; | ||
/// If this property is null, this [ViewConfiguration] is a top level view. | ||
FlutterView? get view => _view; | ||
dkwingsmt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
final FlutterView? _view; | ||
|
||
/// The pixel density of the output surface. | ||
final double devicePixelRatio; | ||
|
@@ -1427,7 +1451,7 @@ class ViewConfiguration { | |
|
||
@override | ||
String toString() { | ||
return '$runtimeType[window: $window, geometry: $geometry]'; | ||
return '$runtimeType[view: $view, geometry: $geometry]'; | ||
} | ||
} | ||
|
||
|
@@ -1666,7 +1690,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 rendered | ||
/// whenever [render] is called on it with a [Scene]. | ||
/// | ||
/// ## 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; | ||
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. 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? 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.
Show resolved
Hide resolved
|
||
Object get viewId => _viewId; | ||
a-wallen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// 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.
Show resolved
Hide resolved
|
||
SingletonFlutterWindow._(super.windowId, super.platformDispatcher) | ||
: super._(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,7 +190,13 @@ class PlatformConfiguration { | |
|
||
class ViewConfiguration { | ||
const ViewConfiguration({ | ||
this.window, | ||
FlutterView? view, | ||
@Deprecated(''' | ||
Use the `view` property instead. | ||
This change is related to adding multi-view support in Flutter. | ||
This feature was deprecated after 3.7.0-1.2.pre. | ||
''') | ||
FlutterView? window, | ||
this.devicePixelRatio = 1.0, | ||
this.geometry = Rect.zero, | ||
this.visible = false, | ||
|
@@ -200,10 +206,12 @@ class ViewConfiguration { | |
this.padding = WindowPadding.zero, | ||
this.gestureSettings = const GestureSettings(), | ||
this.displayFeatures = const <DisplayFeature>[], | ||
}); | ||
}) : assert(window == null || view == null), | ||
_view = view ?? window; | ||
|
||
ViewConfiguration copyWith({ | ||
FlutterWindow? window, | ||
FlutterView? view, | ||
FlutterView? window, | ||
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? 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, | ||
|
@@ -214,8 +222,9 @@ class ViewConfiguration { | |
GestureSettings? gestureSettings, | ||
List<DisplayFeature>? displayFeatures, | ||
}) { | ||
assert(view == null || window == null); | ||
return ViewConfiguration( | ||
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. |
||
window: window ?? this.window, | ||
view: view ?? window ?? _view, | ||
devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio, | ||
geometry: geometry ?? this.geometry, | ||
visible: visible ?? this.visible, | ||
|
@@ -228,7 +237,14 @@ class ViewConfiguration { | |
); | ||
} | ||
|
||
final FlutterWindow? window; | ||
@Deprecated(''' | ||
Use the `view` property instead. | ||
This change is related to adding multi-view support in Flutter. | ||
This feature was deprecated after 3.7.0-1.2.pre. | ||
''') | ||
FlutterView? get window => _view; | ||
FlutterView? get view => _view; | ||
final FlutterView? _view; | ||
final double devicePixelRatio; | ||
final Rect geometry; | ||
final bool visible; | ||
|
@@ -241,7 +257,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,8 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { | |||||
|
||||||
/// The current list of windows, | ||||||
a-wallen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
@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 => viewData.values; | ||||||
final Map<Object, ui.FlutterView> viewData = <Object, ui.FlutterView>{}; | ||||||
ditman marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
/// A map of opaque platform window identifiers to window configurations. | ||||||
/// | ||||||
|
@@ -478,10 +477,10 @@ 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 | ||||||
a-wallen marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// supported. | ||||||
(_windows[0]! as EngineFlutterWindow) | ||||||
(viewData[0]! as EngineFlutterWindow) | ||||||
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 code looks like it's trying to access the "first" element in a list, but that's not what's happening. engine/lib/web_ui/lib/src/engine/window.dart Lines 366 to 367 in bb40152
I suggest we make that explicit through a constant (e.g. (I know this existed before your PR, but I wanted to recommend it since you are working on this part of the code anyway). 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. |
||||||
.browserHistory | ||||||
.exit() | ||||||
.then((_) { | ||||||
|
@@ -568,10 +567,10 @@ 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. | ||||||
(_windows[0]! as EngineFlutterWindow) | ||||||
(viewData[0]! as EngineFlutterWindow) | ||||||
.handleNavigationMessage(data) | ||||||
.then((bool handled) { | ||||||
if (handled) { | ||||||
|
@@ -1160,7 +1159,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher { | |||||
@override | ||||||
String get defaultRouteName { | ||||||
return _defaultRouteName ??= | ||||||
(_windows[0]! as EngineFlutterWindow).browserHistory.currentPath; | ||||||
(viewData[0]! as EngineFlutterWindow).browserHistory.currentPath; | ||||||
} | ||||||
|
||||||
/// Lazily initialized when the `defaultRouteName` getter is invoked. | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.