diff options
author | Andreas Kling <kling@serenityos.org> | 2020-08-07 20:30:27 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-07 20:30:59 +0200 |
commit | 498845ea2f356bd9e66225fa457436d348913025 (patch) | |
tree | 7669cf0ff5e14828fca0d94d7db97554d22fc644 /Libraries | |
parent | 0bbced444b86ef9eab4cccf34c75849fa38f3022 (diff) | |
download | serenity-498845ea2f356bd9e66225fa457436d348913025.zip |
LibWeb: Handle CSS "ex" lengths (relative to font x-height)
These are pretty rare, but they do come up in some places and it's not
hard to support. The Gfx::Font information is approximate (and bad)
but we can fix that separately.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibWeb/CSS/Length.cpp | 4 | ||||
-rw-r--r-- | Libraries/LibWeb/CSS/Length.h | 3 | ||||
-rw-r--r-- | Libraries/LibWeb/CSS/Parser/CSSParser.cpp | 3 |
3 files changed, 9 insertions, 1 deletions
diff --git a/Libraries/LibWeb/CSS/Length.cpp b/Libraries/LibWeb/CSS/Length.cpp index ff5e27e02a..2df30f1a38 100644 --- a/Libraries/LibWeb/CSS/Length.cpp +++ b/Libraries/LibWeb/CSS/Length.cpp @@ -33,6 +33,8 @@ namespace Web::CSS { float Length::relative_length_to_px(const LayoutNode& layout_node) const { switch (m_type) { + case Type::Ex: + return m_value * layout_node.specified_style().font().x_height(); case Type::Em: return m_value * layout_node.font_size(); case Type::Rem: @@ -49,6 +51,8 @@ const char* Length::unit_name() const return "px"; case Type::Pt: return "pt"; + case Type::Ex: + return "ex"; case Type::Em: return "em"; case Type::Rem: diff --git a/Libraries/LibWeb/CSS/Length.h b/Libraries/LibWeb/CSS/Length.h index a0f632777f..38efb16b4d 100644 --- a/Libraries/LibWeb/CSS/Length.h +++ b/Libraries/LibWeb/CSS/Length.h @@ -39,6 +39,7 @@ public: Auto, Px, Pt, + Ex, Em, Rem, }; @@ -84,7 +85,7 @@ public: 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 || m_type == Type::Pt; } - bool is_relative() const { return m_type == Type::Em || m_type == Type::Rem; } + bool is_relative() const { return m_type == Type::Ex || m_type == Type::Em || m_type == Type::Rem; } float raw_value() const { return m_value; } ALWAYS_INLINE float to_px(const LayoutNode& layout_node) const diff --git a/Libraries/LibWeb/CSS/Parser/CSSParser.cpp b/Libraries/LibWeb/CSS/Parser/CSSParser.cpp index efab4480d8..162eca30d2 100644 --- a/Libraries/LibWeb/CSS/Parser/CSSParser.cpp +++ b/Libraries/LibWeb/CSS/Parser/CSSParser.cpp @@ -284,6 +284,9 @@ static CSS::Length parse_length(const CSS::ParsingContext& context, const String } else if (view.to_string().to_lowercase().ends_with("em")) { type = CSS::Length::Type::Em; value = try_parse_float(view.substring_view(0, view.length() - 2)); + } else if (view.to_string().to_lowercase().ends_with("ex")) { + type = CSS::Length::Type::Ex; + value = try_parse_float(view.substring_view(0, view.length() - 2)); } else if (view == "0") { type = CSS::Length::Type::Px; value = 0; |