Explorar o código

LibWeb: Support "pt" length units :^)

Andreas Kling %!s(int64=5) %!d(string=hai) anos
pai
achega
7d3c8d066f

+ 2 - 0
Libraries/LibWeb/CSS/Length.cpp

@@ -47,6 +47,8 @@ const char* Length::unit_name() const
     switch (m_type) {
     case Type::Px:
         return "px";
+    case Type::Pt:
+        return "pt";
     case Type::Em:
         return "em";
     case Type::Rem:

+ 4 - 1
Libraries/LibWeb/CSS/Length.h

@@ -38,6 +38,7 @@ public:
         Percentage,
         Auto,
         Px,
+        Pt,
         Em,
         Rem,
     };
@@ -82,7 +83,7 @@ public:
     bool is_undefined() const { return m_type == Type::Undefined; }
     bool is_percentage() const { return m_type == Type::Percentage; }
     bool is_auto() const { return m_type == Type::Auto; }
-    bool is_absolute() const { return m_type == Type::Px; }
+    bool is_absolute() const { return m_type == Type::Px || m_type == Type::Pt; }
     bool is_relative() const { return m_type == Type::Em || m_type == Type::Rem; }
 
     float raw_value() const { return m_value; }
@@ -95,6 +96,8 @@ public:
             return 0;
         case Type::Px:
             return m_value;
+        case Type::Pt:
+            return m_value * 1.33333333f;
         case Type::Undefined:
         case Type::Percentage:
         default:

+ 3 - 22
Libraries/LibWeb/Parser/CSSParser.cpp

@@ -264,28 +264,6 @@ static Optional<float> try_parse_float(const StringView& string)
     return is_negative ? -value : value;
 }
 
-static Optional<float> parse_number(const CSS::ParsingContext& context, const StringView& view)
-{
-    if (view.ends_with('%'))
-        return parse_number(context, view.substring_view(0, view.length() - 1));
-
-    // FIXME: Maybe we should have "ends_with_ignoring_case()" ?
-    if (view.to_string().to_lowercase().ends_with("px"))
-        return parse_number(context, view.substring_view(0, view.length() - 2));
-    if (view.to_string().to_lowercase().ends_with("rem"))
-        return parse_number(context, view.substring_view(0, view.length() - 3));
-    if (view.to_string().to_lowercase().ends_with("em"))
-        return parse_number(context, view.substring_view(0, view.length() - 2));
-    if (view == "0")
-        return 0;
-
-    // NOTE: We don't allow things like "width: 100" in standards mode.
-    if (!context.in_quirks_mode())
-        return {};
-
-    return try_parse_float(view);
-}
-
 static Length parse_length(const CSS::ParsingContext& context, const StringView& view, bool& is_bad_length)
 {
     Length::Type type = Length::Type::Undefined;
@@ -297,6 +275,9 @@ static Length parse_length(const CSS::ParsingContext& context, const StringView&
     } else if (view.to_string().to_lowercase().ends_with("px")) {
         type = Length::Type::Px;
         value = try_parse_float(view.substring_view(0, view.length() - 2));
+    } else if (view.to_string().to_lowercase().ends_with("pt")) {
+        type = Length::Type::Pt;
+        value = try_parse_float(view.substring_view(0, view.length() - 2));
     } else if (view.to_string().to_lowercase().ends_with("rem")) {
         type = Length::Type::Rem;
         value = try_parse_float(view.substring_view(0, view.length() - 3));