@@ -66,44 +66,48 @@ const String& TextNode::text_for_style(const CSS::StyleProperties& style) const
66
66
return dom_node ().data ();
67
67
}
68
68
69
- void TextNode::paint_fragment (PaintContext& context, const LineBoxFragment& fragment) const
69
+ void TextNode::paint_fragment (PaintContext& context, const LineBoxFragment& fragment, PaintPhase phase ) const
70
70
{
71
71
auto & painter = context.painter ();
72
- painter.set_font (specified_style ().font ());
73
-
74
- auto background_color = specified_style ().property (CSS::PropertyID::BackgroundColor);
75
- if (background_color.has_value () && background_color.value ()->is_color ())
76
- painter.fill_rect (enclosing_int_rect (fragment.absolute_rect ()), background_color.value ()->to_color (document ()));
77
-
78
- auto color = specified_style ().color_or_fallback (CSS::PropertyID::Color, document (), context.palette ().base_text ());
79
- auto text_decoration = specified_style ().string_or_fallback (CSS::PropertyID::TextDecoration, " none" );
80
-
81
- if (document ().inspected_node () == &dom_node ())
82
- context.painter ().draw_rect (enclosing_int_rect (fragment.absolute_rect ()), Color::Magenta);
83
-
84
- bool is_underline = text_decoration == " underline" ;
85
- if (is_underline)
86
- painter.draw_line (enclosing_int_rect (fragment.absolute_rect ()).bottom_left ().translated (0 , 1 ), enclosing_int_rect (fragment.absolute_rect ()).bottom_right ().translated (0 , 1 ), color);
87
-
88
- // FIXME: text-transform should be done already in layout, since uppercase glyphs may be wider than lowercase, etc.
89
- auto text = m_text_for_rendering;
90
- auto text_transform = specified_style ().string_or_fallback (CSS::PropertyID::TextTransform, " none" );
91
- if (text_transform == " uppercase" )
92
- text = m_text_for_rendering.to_uppercase ();
93
- if (text_transform == " lowercase" )
94
- text = m_text_for_rendering.to_lowercase ();
95
-
96
- painter.draw_text (enclosing_int_rect (fragment.absolute_rect ()), text.substring_view (fragment.start (), fragment.length ()), Gfx::TextAlignment::TopLeft, color);
97
-
98
- auto selection_rect = fragment.selection_rect (specified_style ().font ());
99
- if (!selection_rect.is_empty ()) {
100
- painter.fill_rect (enclosing_int_rect (selection_rect), context.palette ().selection ());
101
- Gfx::PainterStateSaver saver (painter);
102
- painter.add_clip_rect (enclosing_int_rect (selection_rect));
103
- painter.draw_text (enclosing_int_rect (fragment.absolute_rect ()), text.substring_view (fragment.start (), fragment.length ()), Gfx::TextAlignment::TopLeft, context.palette ().selection_text ());
72
+
73
+ if (phase == PaintPhase::Background) {
74
+ auto background_color = specified_style ().property (CSS::PropertyID::BackgroundColor);
75
+ if (background_color.has_value () && background_color.value ()->is_color ())
76
+ painter.fill_rect (enclosing_int_rect (fragment.absolute_rect ()), background_color.value ()->to_color (document ()));
104
77
}
105
78
106
- paint_cursor_if_needed (context, fragment);
79
+ if (phase == PaintPhase::Foreground) {
80
+ painter.set_font (specified_style ().font ());
81
+ auto color = specified_style ().color_or_fallback (CSS::PropertyID::Color, document (), context.palette ().base_text ());
82
+ auto text_decoration = specified_style ().string_or_fallback (CSS::PropertyID::TextDecoration, " none" );
83
+
84
+ if (document ().inspected_node () == &dom_node ())
85
+ context.painter ().draw_rect (enclosing_int_rect (fragment.absolute_rect ()), Color::Magenta);
86
+
87
+ bool is_underline = text_decoration == " underline" ;
88
+ if (is_underline)
89
+ painter.draw_line (enclosing_int_rect (fragment.absolute_rect ()).bottom_left ().translated (0 , 1 ), enclosing_int_rect (fragment.absolute_rect ()).bottom_right ().translated (0 , 1 ), color);
90
+
91
+ // FIXME: text-transform should be done already in layout, since uppercase glyphs may be wider than lowercase, etc.
92
+ auto text = m_text_for_rendering;
93
+ auto text_transform = specified_style ().string_or_fallback (CSS::PropertyID::TextTransform, " none" );
94
+ if (text_transform == " uppercase" )
95
+ text = m_text_for_rendering.to_uppercase ();
96
+ if (text_transform == " lowercase" )
97
+ text = m_text_for_rendering.to_lowercase ();
98
+
99
+ painter.draw_text (enclosing_int_rect (fragment.absolute_rect ()), text.substring_view (fragment.start (), fragment.length ()), Gfx::TextAlignment::CenterLeft, color);
100
+
101
+ auto selection_rect = fragment.selection_rect (specified_style ().font ());
102
+ if (!selection_rect.is_empty ()) {
103
+ painter.fill_rect (enclosing_int_rect (selection_rect), context.palette ().selection ());
104
+ Gfx::PainterStateSaver saver (painter);
105
+ painter.add_clip_rect (enclosing_int_rect (selection_rect));
106
+ painter.draw_text (enclosing_int_rect (fragment.absolute_rect ()), text.substring_view (fragment.start (), fragment.length ()), Gfx::TextAlignment::CenterLeft, context.palette ().selection_text ());
107
+ }
108
+
109
+ paint_cursor_if_needed (context, fragment);
110
+ }
107
111
}
108
112
109
113
void TextNode::paint_cursor_if_needed (PaintContext& context, const LineBoxFragment& fragment) const
0 commit comments