Selaa lähdekoodia

LibWeb: Use CSS text-indent property on input type="submit" elements

Bastiaan van der Plaat 2 vuotta sitten
vanhempi
commit
148d74b103
1 muutettua tiedostoa jossa 14 lisäystä ja 2 poistoa
  1. 14 2
      Userland/Libraries/LibWeb/Painting/ButtonPaintable.cpp

+ 14 - 2
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<HTML::HTMLInputElement>(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<int>());
+        painter.draw_text(
             text_rect.to_type<int>(),
             static_cast<HTML::HTMLInputElement const&>(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();
     }
 }