mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 17:37:35 +00:00
LibWeb: Handle CSS "ch" length unit (mostly)
This isn't 100% spec complaint, as it should use glyph_height() depending on what the value of the writing-mode is, but we haven't implemented it yet, so I think it'll be good enough for now. This can be tested in https://wpt.live/css/css-values/ch-unit-008.html Other css-unit tests fail as: - 001 shows an issue related to a renderer (looks to me like you can't pass a width and height property to a span -- adding `display: block` to it passes the test), - 002-004 and 009-012 use mentioned writing-mode, - 016-017 loads custom fonts, which we also don't support (yet).
This commit is contained in:
parent
a230524c46
commit
ffa7da0ca5
3 changed files with 9 additions and 0 deletions
|
@ -21,6 +21,9 @@ float Length::relative_length_to_px(const Layout::Node& layout_node) const
|
||||||
return m_value * layout_node.font().x_height();
|
return m_value * layout_node.font().x_height();
|
||||||
case Type::Em:
|
case Type::Em:
|
||||||
return m_value * layout_node.font_size();
|
return m_value * layout_node.font_size();
|
||||||
|
case Type::Ch:
|
||||||
|
// FIXME: Use layout_node.font().glyph_height() when writing-mode is not horizontal-tb (it has to be implemented first)
|
||||||
|
return m_value * (layout_node.font().glyph_width('0') + layout_node.font().glyph_spacing());
|
||||||
case Type::Rem:
|
case Type::Rem:
|
||||||
return m_value * layout_node.document().document_element()->layout_node()->font_size();
|
return m_value * layout_node.document().document_element()->layout_node()->font_size();
|
||||||
case Type::Vw:
|
case Type::Vw:
|
||||||
|
@ -180,6 +183,8 @@ const char* Length::unit_name() const
|
||||||
return "ex";
|
return "ex";
|
||||||
case Type::Em:
|
case Type::Em:
|
||||||
return "em";
|
return "em";
|
||||||
|
case Type::Ch:
|
||||||
|
return "ch";
|
||||||
case Type::Rem:
|
case Type::Rem:
|
||||||
return "rem";
|
return "rem";
|
||||||
case Type::Auto:
|
case Type::Auto:
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
Pc,
|
Pc,
|
||||||
Ex,
|
Ex,
|
||||||
Em,
|
Em,
|
||||||
|
Ch,
|
||||||
Rem,
|
Rem,
|
||||||
Vh,
|
Vh,
|
||||||
Vw,
|
Vw,
|
||||||
|
@ -93,6 +94,7 @@ public:
|
||||||
{
|
{
|
||||||
return m_type == Type::Ex
|
return m_type == Type::Ex
|
||||||
|| m_type == Type::Em
|
|| m_type == Type::Em
|
||||||
|
|| m_type == Type::Ch
|
||||||
|| m_type == Type::Rem
|
|| m_type == Type::Rem
|
||||||
|| m_type == Type::Vh
|
|| m_type == Type::Vh
|
||||||
|| m_type == Type::Vw
|
|| m_type == Type::Vw
|
||||||
|
|
|
@ -1466,6 +1466,8 @@ Optional<Length> Parser::parse_length(ParsingContext const& context, StyleCompon
|
||||||
type = Length::Type::Em;
|
type = Length::Type::Em;
|
||||||
} else if (unit_string.equals_ignoring_case("ex")) {
|
} else if (unit_string.equals_ignoring_case("ex")) {
|
||||||
type = Length::Type::Ex;
|
type = Length::Type::Ex;
|
||||||
|
} else if (unit_string.equals_ignoring_case("ch")) {
|
||||||
|
type = Length::Type::Ch;
|
||||||
} else if (unit_string.equals_ignoring_case("vw")) {
|
} else if (unit_string.equals_ignoring_case("vw")) {
|
||||||
type = Length::Type::Vw;
|
type = Length::Type::Vw;
|
||||||
} else if (unit_string.equals_ignoring_case("vh")) {
|
} else if (unit_string.equals_ignoring_case("vh")) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue