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
35 changes: 34 additions & 1 deletion lib/ui/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,26 @@ class PlatformDispatcher {
_onPlatformBrightnessChangedZone = Zone.current;
}

/// The setting indicating the current system font of the host platform.
String? get systemFontFamily => configuration.systemFontFamily;

/// A callback that is invoked whenever [systemFontFamily] changes value.
///
/// The framework invokes this callback in the same zone in which the callback
/// was set.
///
/// See also:
///
/// * [WidgetsBindingObserver], for a mechanism at the widgets layer to
/// observe when this callback is invoked.
VoidCallback? get onSystemFontFamilyChanged => _onSystemFontFamilyChanged;
VoidCallback? _onSystemFontFamilyChanged;
Zone _onSystemFontFamilyChangedZone = Zone.root;
set onSystemFontFamilyChanged(VoidCallback? callback) {
_onSystemFontFamilyChanged = callback;
_onSystemFontFamilyChangedZone = Zone.current;
}

// Called from the engine, via hooks.dart
void _updateUserSettingsData(String jsonData) {
final Map<String, Object?> data = json.decode(jsonData) as Map<String, Object?>;
Expand All @@ -880,19 +900,23 @@ class PlatformDispatcher {
}
final Brightness platformBrightness =
data['platformBrightness']! as String == 'dark' ? Brightness.dark : Brightness.light;
final String? systemFontFamily = data['systemFontFamily'] as String?;
final PlatformConfiguration previousConfiguration = configuration;
final bool platformBrightnessChanged =
previousConfiguration.platformBrightness != platformBrightness;
final bool textScaleFactorChanged = previousConfiguration.textScaleFactor != textScaleFactor;
final bool alwaysUse24HourFormatChanged =
previousConfiguration.alwaysUse24HourFormat != alwaysUse24HourFormat;
if (!platformBrightnessChanged && !textScaleFactorChanged && !alwaysUse24HourFormatChanged) {
final bool systemFontFamilyChanged =
previousConfiguration.systemFontFamily != systemFontFamily;
if (!platformBrightnessChanged && !textScaleFactorChanged && !alwaysUse24HourFormatChanged && !systemFontFamilyChanged) {
return;
}
_configuration = previousConfiguration.copyWith(
textScaleFactor: textScaleFactor,
alwaysUse24HourFormat: alwaysUse24HourFormat,
platformBrightness: platformBrightness,
systemFontFamily: systemFontFamily,
);
_invoke(onPlatformConfigurationChanged, _onPlatformConfigurationChangedZone);
if (textScaleFactorChanged) {
Expand All @@ -901,6 +925,9 @@ class PlatformDispatcher {
if (platformBrightnessChanged) {
_invoke(onPlatformBrightnessChanged, _onPlatformBrightnessChangedZone);
}
if (systemFontFamilyChanged) {
_invoke(onSystemFontFamilyChanged, _onSystemFontFamilyChangedZone);
}
}

/// Whether the user has requested that [updateSemantics] be called when the
Expand Down Expand Up @@ -1032,6 +1059,7 @@ class PlatformConfiguration {
this.textScaleFactor = 1.0,
this.locales = const <Locale>[],
this.defaultRouteName,
this.systemFontFamily,
});

/// Copy a [PlatformConfiguration] with some fields replaced.
Expand All @@ -1043,6 +1071,7 @@ class PlatformConfiguration {
double? textScaleFactor,
List<Locale>? locales,
String? defaultRouteName,
String? systemFontFamily,
}) {
return PlatformConfiguration(
accessibilityFeatures: accessibilityFeatures ?? this.accessibilityFeatures,
Expand All @@ -1052,6 +1081,7 @@ class PlatformConfiguration {
textScaleFactor: textScaleFactor ?? this.textScaleFactor,
locales: locales ?? this.locales,
defaultRouteName: defaultRouteName ?? this.defaultRouteName,
systemFontFamily: systemFontFamily ?? this.systemFontFamily,
);
}

Expand Down Expand Up @@ -1080,6 +1110,9 @@ class PlatformConfiguration {
/// The route or path that the embedder requested when the application was
/// launched.
final String? defaultRouteName;

/// The system-reported default font family.
final String? systemFontFamily;
}

/// An immutable view configuration.
Expand Down
21 changes: 21 additions & 0 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,27 @@ class SingletonFlutterWindow extends FlutterWindow {
platformDispatcher.onPlatformBrightnessChanged = callback;
}

/// The setting indicating the system font of the host platform.
///
/// {@macro dart.ui.window.accessorForwardWarning}
String? get systemFontFamily => platformDispatcher.systemFontFamily;

/// A callback that is invoked whenever [systemFontFamily] changes value.
///
/// {@macro dart.ui.window.accessorForwardWarning}
///
/// The framework invokes this callback in the same zone in which the
/// callback was set.
///
/// See also:
///
/// * [WidgetsBindingObserver], for a mechanism at the widgets layer to
/// observe when this callback is invoked.
VoidCallback? get onSystemFontFamilyChanged => platformDispatcher.onSystemFontFamilyChanged;
set onSystemFontFamilyChanged(VoidCallback? callback) {
platformDispatcher.onSystemFontFamilyChanged = callback;
}

/// A callback that is invoked to notify the window that it is an appropriate
/// time to provide a scene using the [SceneBuilder] API and the [render]
/// method.
Expand Down
9 changes: 9 additions & 0 deletions lib/web_ui/lib/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ abstract class PlatformDispatcher {
VoidCallback? get onPlatformBrightnessChanged;
set onPlatformBrightnessChanged(VoidCallback? callback);

String? get systemFontFamily => configuration.systemFontFamily;

VoidCallback? get onSystemFontFamilyChanged;
set onSystemFontFamilyChanged(VoidCallback? callback);

bool get semanticsEnabled => configuration.semanticsEnabled;

VoidCallback? get onSemanticsEnabledChanged;
Expand All @@ -116,6 +121,7 @@ class PlatformConfiguration {
this.textScaleFactor = 1.0,
this.locales = const <Locale>[],
this.defaultRouteName = '/',
this.systemFontFamily,
});

PlatformConfiguration copyWith({
Expand All @@ -126,6 +132,7 @@ class PlatformConfiguration {
double? textScaleFactor,
List<Locale>? locales,
String? defaultRouteName,
String? systemFontFamily,
}) {
return PlatformConfiguration(
accessibilityFeatures: accessibilityFeatures ?? this.accessibilityFeatures,
Expand All @@ -135,6 +142,7 @@ class PlatformConfiguration {
textScaleFactor: textScaleFactor ?? this.textScaleFactor,
locales: locales ?? this.locales,
defaultRouteName: defaultRouteName ?? this.defaultRouteName,
systemFontFamily: systemFontFamily ?? this.systemFontFamily,
);
}

Expand All @@ -145,6 +153,7 @@ class PlatformConfiguration {
final double textScaleFactor;
final List<Locale> locales;
final String defaultRouteName;
final String? systemFontFamily;
}

class ViewConfiguration {
Expand Down
30 changes: 30 additions & 0 deletions lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,10 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
}
}

/// The setting indicating the current system font of the host platform.
@override
String? get systemFontFamily => configuration.systemFontFamily;

/// Reference to css media query that indicates the user theme preference on the web.
final html.MediaQueryList _brightnessMediaQuery =
html.window.matchMedia('(prefers-color-scheme: dark)');
Expand Down Expand Up @@ -940,6 +944,32 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
invoke(_onPlatformBrightnessChanged, _onPlatformBrightnessChangedZone);
}

/// A callback that is invoked whenever [systemFontFamily] changes value.
///
/// The framework invokes this callback in the same zone in which the
/// callback was set.
///
/// See also:
///
/// * [WidgetsBindingObserver], for a mechanism at the widgets layer to
/// observe when this callback is invoked.
@override
ui.VoidCallback? get onSystemFontFamilyChanged =>
_onSystemFontFamilyChanged;
ui.VoidCallback? _onSystemFontFamilyChanged;
Zone? _onSystemFontFamilyChangedZone;
@override
set onSystemFontFamilyChanged(ui.VoidCallback? callback) {
_onSystemFontFamilyChanged = callback;
_onSystemFontFamilyChangedZone = Zone.current;
}

/// Engine code should use this method instead of the callback directly.
/// Otherwise zones won't work properly.
void invokeOnSystemFontFamilyChanged() {
invoke(_onSystemFontFamilyChanged, _onSystemFontFamilyChangedZone);
}

/// Whether the user has requested that [updateSemantics] be called when
/// the semantic contents of window changes.
///
Expand Down
7 changes: 7 additions & 0 deletions lib/web_ui/lib/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ abstract class SingletonFlutterWindow extends FlutterWindow {
platformDispatcher.onPlatformBrightnessChanged = callback;
}

String? get systemFontFamily => platformDispatcher.systemFontFamily;

VoidCallback? get onSystemFontFamilyChanged => platformDispatcher.onSystemFontFamilyChanged;
set onSystemFontFamilyChanged(VoidCallback? callback) {
platformDispatcher.onSystemFontFamilyChanged = callback;
}

FrameCallback? get onBeginFrame => platformDispatcher.onBeginFrame;
set onBeginFrame(FrameCallback? callback) {
platformDispatcher.onBeginFrame = callback;
Expand Down