diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-28 15:25:32 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-28 15:25:32 +0200 |
commit | 7d3c8d066ffa05e401b23586b49bf09639ae64b0 (patch) | |
tree | b881eaca54eba22beb6f481242022469c34772ba /Libraries/LibWeb | |
parent | 7fc988b9192642ffa15b845972373d02090fff82 (diff) | |
download | serenity-7d3c8d066ffa05e401b23586b49bf09639ae64b0.zip |
LibWeb: Support "pt" length units :^)
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r-- | Libraries/LibWeb/CSS/Length.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/CSS/Length.h | 5 | ||||
-rw-r--r-- | Libraries/LibWeb/Parser/CSSParser.cpp | 25 |
3 files changed, 9 insertions, 23 deletions
diff --git a/Libraries/LibWeb/CSS/Length.cpp b/Libraries/LibWeb/CSS/Length.cpp index 7ed66c3f14..e71cffda40 100644 --- a/Libraries/LibWeb/CSS/Length.cpp +++ b/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: diff --git a/Libraries/LibWeb/CSS/Length.h b/Libraries/LibWeb/CSS/Length.h index 023c5ae702..61ca914a7c 100644 --- a/Libraries/LibWeb/CSS/Length.h +++ b/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: diff --git a/Libraries/LibWeb/Parser/CSSParser.cpp b/Libraries/LibWeb/Parser/CSSParser.cpp index c044a5e8f5..9bc89980b0 100644 --- a/Libraries/LibWeb/Parser/CSSParser.cpp +++ b/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)); |