瀏覽代碼

LibWeb: Add list-style-type: decimal-leading-zero support

This doesn't exactly do what you would think from its name: It surely
adds an extra leading zero to the front of a number, but only if the
number is less than 10. CSS is weird sometimes.
Tobias Christiansen 4 年之前
父節點
當前提交
0983cd9243

+ 1 - 0
Userland/Libraries/LibWeb/CSS/Identifiers.json

@@ -77,6 +77,7 @@
   "crosshair",
   "dashed",
   "decimal",
+  "decimal-leading-zero",
   "default",
   "disc",
   "dotted",

+ 2 - 0
Userland/Libraries/LibWeb/CSS/StyleProperties.cpp

@@ -576,6 +576,8 @@ Optional<CSS::ListStyleType> StyleProperties::list_style_type() const
         return CSS::ListStyleType::Square;
     case CSS::ValueID::Decimal:
         return CSS::ListStyleType::Decimal;
+    case CSS::ValueID::DecimalLeadingZero:
+        return CSS::ListStyleType::DecimalLeadingZero;
     default:
         return {};
     }

+ 1 - 0
Userland/Libraries/LibWeb/CSS/StyleValue.h

@@ -159,6 +159,7 @@ enum class ListStyleType {
     Circle,
     Square,
     Decimal,
+    DecimalLeadingZero,
 };
 
 enum class Overflow : u8 {

+ 7 - 0
Userland/Libraries/LibWeb/Layout/ListItemMarkerBox.cpp

@@ -52,6 +52,13 @@ void ListItemMarkerBox::paint(PaintContext& context, PaintPhase phase)
     case CSS::ListStyleType::Disc:
         context.painter().fill_ellipse(marker_rect, color);
         break;
+    case CSS::ListStyleType::DecimalLeadingZero:
+        // This is weird, but in accordance to spec.
+        context.painter().draw_text(
+            enclosing,
+            m_index < 10 ? String::formatted("0{}.", m_index) : String::formatted("{}.", m_index),
+            Gfx::TextAlignment::Center);
+        break;
     case CSS::ListStyleType::None:
         return;