Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ class HighContrastSupport {
}
}

class EngineFlutterDisplay extends ui.Display {
EngineFlutterDisplay({
required this.id,
required this.devicePixelRatio,
required this.size,
required this.refreshRate,
});

@override
final int id;
@override
final double devicePixelRatio;
@override
final ui.Size size;
@override
final double refreshRate;
}

/// Platform event dispatcher.
///
/// This is the central entry point for platform messages and configuration
Expand Down Expand Up @@ -135,7 +153,14 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
}

@override
Iterable<ui.Display> get displays => <ui.Display>[];
Iterable<ui.Display> get displays => <ui.Display>[
EngineFlutterDisplay(
id: 0,
size: ui.Size(domWindow.screen?.width ?? 0, domWindow.screen?.height ?? 0),
devicePixelRatio: domWindow.devicePixelRatio,
refreshRate: 60,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be bigger on MacOS/Safari with ProMotion display?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - but there's not a good web API to measure this, so for now it's just getting defaulted to 60.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're interested in improving this, see e.g. https://stackoverflow.com/questions/6131051/is-it-possible-to-find-out-what-is-the-monitor-frame-rate-in-javascript - but I'm not sure how we'd do that without being pretty flaky.

)
];

/// The current list of windows.
@override
Expand Down
25 changes: 1 addition & 24 deletions lib/web_ui/lib/src/engine/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,6 @@ const bool debugPrintPlatformMessages = false;
/// The view ID for the implicit flutter view provided by the platform.
const int kImplicitViewId = 0;

class EngineFlutterDisplay extends ui.Display {
EngineFlutterDisplay({
required this.id,
required this.devicePixelRatio,
required this.size,
required this.refreshRate,
});

@override
final int id;
@override
final double devicePixelRatio;
@override
final ui.Size size;
@override
final double refreshRate;
}

/// The Web implementation of [ui.SingletonFlutterWindow].
class EngineFlutterWindow extends ui.SingletonFlutterWindow {
EngineFlutterWindow(this.viewId, this.platformDispatcher) {
Expand All @@ -66,12 +48,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {

@override
ui.Display get display {
return EngineFlutterDisplay(
id: 0,
size: ui.Size(domWindow.screen?.width ?? 0, domWindow.screen?.height ?? 0),
devicePixelRatio: domWindow.devicePixelRatio,
refreshRate: 60,
);
return ui.PlatformDispatcher.instance.displays.first;
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ void testMain() {
ensureFlutterViewEmbedderInitialized();

group('PlatformDispatcher', () {
test('reports at least one display', () {
expect(ui.PlatformDispatcher.instance.displays.length, greaterThan(0));
});

test('high contrast in accessibilityFeatures has the correct value', () {
final MockHighContrastSupport mockHighContrast =
MockHighContrastSupport();
Expand Down