-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Move styling from FlutterViewEmbedder to StyleManager #47489
Conversation
ditman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comment to unify the global_styles.dart and the StyleManager into one big single, interrelated blob, but consider all my comments as severity "nitpick" at most!
ditman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have much left to say here! A couple of minor questions about some small implementation details, but other than that: 🚀
| return fontWeightIndexToCss(fontWeightIndex: fontWeight.index); | ||
| } | ||
|
|
||
| String fontWeightIndexToCss({int fontWeightIndex = 3}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is fontWeightIndexToCss still needed outside of the FontWeightExtension? Should the implementation of this method be the actual implementation of toCssString() there? Or could this method be made a private method on the FontWeightExtension?
Also, can this reimplemented as:
case 3:
return 'normal';
case 6:
return 'bold';
default:
return '${(fontWeightIndex + 1) * 100}';(This might be in a super-critical part of the code so we might not want to do math on it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is being used in text_editing.dart where the framework sends us the font weight index in a platform message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this happen in many places? Shouldn't we convert the platform message to a proper ui.FontWeight with something like: ui.FontWeight.values[index]?
| // Font family. | ||
| result.write(canonicalizeFontFamily(fontFamily)); | ||
|
|
||
| return result.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a StringBuffer in this method looks weird to me, why not:
return '$cssFontStyle $cssFontWeight $cssFontSize ${canonicalizeFontFamily(fontFamily)}';
So there's no need to instantiate a string buffer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, makes sense!
| $cssSelectorPrefix flt-scene-host { | ||
| $cssSelectorPrefix ${DomManager.sceneHostTagName} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic!
|
auto label is removed for flutter/engine/47489, due to - The status or check suite Linux mac_unopt has failed. Please fix the issues identified (or deflake) before re-applying this label. |
ditman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Still leaving my approval, but for fontSize I think we should prefer int to num (or double?)
| final StringBuffer result = StringBuffer(); | ||
| final String cssFontStyle = fontStyle?.toCssString() ?? StyleManager.defaultFontStyle; | ||
| final String cssFontWeight = fontWeight?.toCssString() ?? StyleManager.defaultFontWeight; | ||
| final num cssFontSize = fontSize?.floor() ?? StyleManager.defaultFontSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It probably doesn't matter much, but:
| final num cssFontSize = fontSize?.floor() ?? StyleManager.defaultFontSize; | |
| final int cssFontSize = fontSize?.floor() ?? StyleManager.defaultFontSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I did it slightly differently though because the rest of the code expects font size to be a double.
final int cssFontSize = (fontSize ?? StyleManager.defaultFontSize).floor();(and kept StyleManager.defaultFontSize a double).
| result.write(canonicalizeFontFamily(fontFamily)); | ||
|
|
||
| return result.toString(); | ||
| return '$cssFontStyle $cssFontWeight ${cssFontSize}px $cssFontFamily'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏
| class StyleManager { | ||
| static const String defaultFontStyle = 'normal'; | ||
| static const String defaultFontWeight = 'normal'; | ||
| static const double defaultFontSize = 14; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| static const double defaultFontSize = 14; | |
| static const int defaultFontSize = 14; |
…138237) flutter/engine@a5eab0d...77349dc 2023-11-10 [email protected] [Android] Bump robolectric version to support unit testing on Android 34 (flutter/engine#47768) 2023-11-10 [email protected] Roll Skia from ae6df7264c6e to 5df579e87784 (1 revision) (flutter/engine#47910) 2023-11-10 [email protected] [web] Move styling from FlutterViewEmbedder to StyleManager (flutter/engine#47489) 2023-11-10 [email protected] Roll Skia from e23e328584a1 to ae6df7264c6e (1 revision) (flutter/engine#47907) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
FlutterViewEmbeddertoStyleManager.FlutterViewEmbeddertoDomManager.StyleManager.Part of Part of flutter/flutter#134443