From 148d74b1032645ce299180aadcbe7dc7762cf44a Mon Sep 17 00:00:00 2001 From: Bastiaan van der Plaat Date: Mon, 31 Jul 2023 12:31:09 +0200 Subject: [PATCH] LibWeb: Use CSS text-indent property on input type="submit" elements --- .../LibWeb/Painting/ButtonPaintable.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/ButtonPaintable.cpp b/Userland/Libraries/LibWeb/Painting/ButtonPaintable.cpp index c0e58aad25..1653fbe7e4 100644 --- a/Userland/Libraries/LibWeb/Painting/ButtonPaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/ButtonPaintable.cpp @@ -43,17 +43,29 @@ void ButtonPaintable::paint(PaintContext& context, PaintPhase phase) const auto const& dom_node = layout_box().dom_node(); if (is(dom_node) && phase == PaintPhase::Foreground) { - auto text_rect = context.enclosing_device_rect(absolute_rect()); + auto button_rect = context.enclosing_device_rect(absolute_rect()); + auto text_rect = button_rect; + + // Apply CSS text-indent property to text rect + auto text_indent = computed_values().text_indent().to_px(layout_box(), CSSPixels()); + text_rect.translate_by(text_indent.to_int(), 0); + + // Apply button pressed state offset if (being_pressed()) { auto offset = context.rounded_device_pixels(1); text_rect.translate_by(offset, offset); } - context.painter().draw_text( + + // Paint button text clipped to button rect + auto& painter = context.painter(); + painter.add_clip_rect(button_rect.to_type()); + painter.draw_text( text_rect.to_type(), static_cast(dom_node).value(), FontCache::the().scaled_font(layout_box().font(), context.device_pixels_per_css_pixel()), Gfx::TextAlignment::Center, computed_values().color()); + painter.clear_clip_rect(); } }