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

Commit 9ce10b9

Browse files
Get rid of "outrageous" default text styles for HTML renderer. (#41822)
The CanvasKit renderer doesn't do this, so we should just remove the red text global style.
1 parent a3c45b0 commit 9ce10b9

File tree

6 files changed

+5
-34
lines changed

6 files changed

+5
-34
lines changed

lib/web_ui/lib/src/engine/global_styles.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ void applyGlobalCssRulesToSheet(
1818
assert(styleElement.sheet != null);
1919
final DomCSSStyleSheet sheet = styleElement.sheet! as DomCSSStyleSheet;
2020

21-
// These are intentionally outrageous font parameters to make sure that the
22-
// apps fully specify their text styles.
23-
//
2421
// Fixes #115216 by ensuring that our parameters only affect the flt-scene-host children.
2522
sheet.insertRule('''
2623
$cssSelectorPrefix flt-scene-host {
27-
color: red;
2824
font: $defaultCssFont;
2925
}
3026
''', sheet.cssRules.length);

lib/web_ui/lib/src/engine/text/canvas_paragraph.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import 'paint_service.dart';
1515
import 'paragraph.dart';
1616
import 'word_breaker.dart';
1717

18-
const ui.Color _defaultTextColor = ui.Color(0xFFFF0000);
19-
2018
final String placeholderChar = String.fromCharCode(0xFFFC);
2119

2220
/// A paragraph made up of a flat list of text spans and placeholders.
@@ -491,7 +489,7 @@ class RootStyleNode extends StyleNode {
491489
final EngineParagraphStyle paragraphStyle;
492490

493491
@override
494-
final ui.Color _color = _defaultTextColor;
492+
ui.Color? get _color => null;
495493

496494
@override
497495
ui.TextDecoration? get _decoration => null;

lib/web_ui/lib/src/engine/text/paint_service.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ class TextPaintService {
107107
if (foreground != null) {
108108
paint = foreground as SurfacePaint;
109109
} else {
110-
paint = (ui.Paint()..color = style.color!) as SurfacePaint;
110+
paint = ui.Paint() as SurfacePaint;
111+
if (style.color != null) {
112+
paint.color = style.color!;
113+
}
111114
}
112115

113116
canvas.setCssFont(style.cssFontString, fragment.textDirection!);

lib/web_ui/test/engine/global_styles_test.dart

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,6 @@ void testMain() {
3838
expect(hasFakeRule, isFalse);
3939
});
4040

41-
test('Attaches outrageous text styles to flt-scene-host', () {
42-
final bool hasColorRed = hasCssRule(styleElement,
43-
selector: 'flt-scene-host', declaration: 'color: red');
44-
45-
bool hasFont = false;
46-
if (isSafari) {
47-
// Safari expands the shorthand rules, so we check for all we've set (separately).
48-
hasFont = hasCssRule(styleElement,
49-
selector: 'flt-scene-host',
50-
declaration: 'font-family: monospace') &&
51-
hasCssRule(styleElement,
52-
selector: 'flt-scene-host', declaration: 'font-size: 14px');
53-
} else {
54-
hasFont = hasCssRule(styleElement,
55-
selector: 'flt-scene-host', declaration: 'font: $_kDefaultCssFont');
56-
}
57-
58-
expect(hasColorRed, isTrue,
59-
reason: 'Should make foreground color red within scene host.');
60-
expect(hasFont, isTrue, reason: 'Should pass default css font.');
61-
});
62-
6341
test('Attaches styling to remove password reveal icons on Edge', () {
6442
// Check that style.sheet! contains input::-ms-reveal rule
6543
final bool hidesRevealIcons = hasCssRule(styleElement,

lib/web_ui/test/html/text/canvas_paragraph_builder_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,6 @@ String spanStyle({
514514
num? letterSpacing,
515515
}) {
516516
return <String>[
517-
'color: rgb(255, 0, 0);',
518517
'font-size: ${fontSize}px;',
519518
if (fontWeight != null) 'font-weight: $fontWeight;',
520519
if (fontStyle != null) 'font-style: $fontStyle;',
@@ -529,7 +528,6 @@ String spanStyle({
529528
}
530529

531530
TextStyle styleWithDefaults({
532-
Color color = const Color(0xFFFF0000),
533531
String fontFamily = FlutterViewEmbedder.defaultFontFamily,
534532
double fontSize = FlutterViewEmbedder.defaultFontSize,
535533
FontWeight? fontWeight,
@@ -538,7 +536,6 @@ TextStyle styleWithDefaults({
538536
double? letterSpacing,
539537
}) {
540538
return TextStyle(
541-
color: color,
542539
fontFamily: fontFamily,
543540
fontSize: fontSize,
544541
fontWeight: fontWeight,

lib/web_ui/test/html/text/layout_fragmenter_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:ui/ui.dart';
1010
import '../paragraph/helper.dart';
1111

1212
final EngineTextStyle defaultStyle = EngineTextStyle.only(
13-
color: const Color(0xFFFF0000),
1413
fontFamily: FlutterViewEmbedder.defaultFontFamily,
1514
fontSize: FlutterViewEmbedder.defaultFontSize,
1615
);

0 commit comments

Comments
 (0)