Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@mdebbar
Copy link
Contributor

@mdebbar mdebbar commented Oct 30, 2023

  • Move default style values from FlutterViewEmbedder to StyleManager.
  • Move DOM tag names from FlutterViewEmbedder to DomManager.
  • Deduplicate style sheet creation code and put it in StyleManager.

Part of Part of flutter/flutter#134443

@mdebbar mdebbar requested a review from ditman October 30, 2023 22:02
@github-actions github-actions bot added the platform-web Code specifically for the web engine label Oct 30, 2023
Copy link
Member

@ditman ditman left a 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!

Copy link
Member

@ditman ditman left a 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}) {
Copy link
Member

@ditman ditman Nov 9, 2023

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)

Copy link
Contributor Author

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.

Copy link
Member

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();
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, makes sense!

Comment on lines -23 to +89
$cssSelectorPrefix flt-scene-host {
$cssSelectorPrefix ${DomManager.sceneHostTagName} {
Copy link
Member

Choose a reason for hiding this comment

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

Fantastic!

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 9, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 9, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Nov 9, 2023

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.

Copy link
Member

@ditman ditman left a 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;
Copy link
Member

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:

Suggested change
final num cssFontSize = fontSize?.floor() ?? StyleManager.defaultFontSize;
final int cssFontSize = fontSize?.floor() ?? StyleManager.defaultFontSize;

Copy link
Contributor Author

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';
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
static const double defaultFontSize = 14;
static const int defaultFontSize = 14;

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 10, 2023
@auto-submit auto-submit bot merged commit 5e3fdec into flutter:main Nov 10, 2023
@mdebbar mdebbar deleted the style_manager branch November 10, 2023 16:11
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 10, 2023
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants