LibWeb: Add *lots* of viewport-based Length units

`sfoo` `lfoo` and `dfoo` are, for our purposes, identical to `foo`,
because we don't have dynamic GUI elements that cover the page content.
This commit is contained in:
Sam Atkins 2023-04-28 17:46:49 +01:00 committed by Andreas Kling
parent 0dd585ba7b
commit 091a1ff527
Notes: sideshowbarker 2024-07-16 20:50:31 +09:00
2 changed files with 85 additions and 1 deletions

View File

@ -100,12 +100,24 @@ CSSPixels Length::relative_length_to_px(CSSPixelRect const& viewport_rect, FontM
case Type::Rlh:
return m_value * root_font_metrics.line_height;
case Type::Vw:
case Type::Svw:
case Type::Lvw:
case Type::Dvw:
return viewport_rect.width() * (m_value / 100);
case Type::Vh:
case Type::Svh:
case Type::Lvh:
case Type::Dvh:
return viewport_rect.height() * (m_value / 100);
case Type::Vmin:
case Type::Svmin:
case Type::Lvmin:
case Type::Dvmin:
return min(viewport_rect.width(), viewport_rect.height()) * (m_value / 100);
case Type::Vmax:
case Type::Svmax:
case Type::Lvmax:
case Type::Dvmax:
return max(viewport_rect.width(), viewport_rect.height()) * (m_value / 100);
default:
VERIFY_NOT_REACHED();
@ -174,12 +186,36 @@ char const* Length::unit_name() const
return "rlh";
case Type::Vw:
return "vw";
case Type::Svw:
return "svw";
case Type::Lvw:
return "lvw";
case Type::Dvw:
return "dvw";
case Type::Vh:
return "vh";
case Type::Svh:
return "svh";
case Type::Lvh:
return "lvh";
case Type::Dvh:
return "dvh";
case Type::Vmin:
return "vmin";
case Type::Svmin:
return "svmin";
case Type::Lvmin:
return "lvmin";
case Type::Dvmin:
return "dvmin";
case Type::Vmax:
return "vmax";
case Type::Svmax:
return "svmax";
case Type::Lvmax:
return "lvmax";
case Type::Dvmax:
return "dvmax";
case Type::Cm:
return "cm";
case Type::Mm:
@ -228,12 +264,36 @@ Optional<Length::Type> Length::unit_from_name(StringView name)
return Length::Type::Rlh;
} else if (name.equals_ignoring_ascii_case("vw"sv)) {
return Length::Type::Vw;
} else if (name.equals_ignoring_ascii_case("svw"sv)) {
return Length::Type::Svw;
} else if (name.equals_ignoring_ascii_case("lvw"sv)) {
return Length::Type::Lvw;
} else if (name.equals_ignoring_ascii_case("dvw"sv)) {
return Length::Type::Dvw;
} else if (name.equals_ignoring_ascii_case("vh"sv)) {
return Length::Type::Vh;
} else if (name.equals_ignoring_ascii_case("svh"sv)) {
return Length::Type::Svh;
} else if (name.equals_ignoring_ascii_case("lvh"sv)) {
return Length::Type::Lvh;
} else if (name.equals_ignoring_ascii_case("dvh"sv)) {
return Length::Type::Dvh;
} else if (name.equals_ignoring_ascii_case("vmin"sv)) {
return Length::Type::Vmin;
} else if (name.equals_ignoring_ascii_case("svmin"sv)) {
return Length::Type::Svmin;
} else if (name.equals_ignoring_ascii_case("lvmin"sv)) {
return Length::Type::Lvmin;
} else if (name.equals_ignoring_ascii_case("dvmin"sv)) {
return Length::Type::Dvmin;
} else if (name.equals_ignoring_ascii_case("vmax"sv)) {
return Length::Type::Vmax;
} else if (name.equals_ignoring_ascii_case("svmax"sv)) {
return Length::Type::Svmax;
} else if (name.equals_ignoring_ascii_case("lvmax"sv)) {
return Length::Type::Lvmax;
} else if (name.equals_ignoring_ascii_case("dvmax"sv)) {
return Length::Type::Dvmax;
} else if (name.equals_ignoring_ascii_case("cm"sv)) {
return Length::Type::Cm;
} else if (name.equals_ignoring_ascii_case("mm"sv)) {

View File

@ -33,9 +33,21 @@ public:
// Viewport-relative
Vw,
Svw,
Lvw,
Dvw,
Vh,
Svh,
Lvh,
Dvh,
Vmin,
Svmin,
Lvmin,
Dvmin,
Vmax,
Svmax,
Lvmax,
Dvmax,
// Absolute
Cm,
@ -105,9 +117,21 @@ public:
bool is_viewport_relative() const
{
return m_type == Type::Vw
|| m_type == Type::Svw
|| m_type == Type::Lvw
|| m_type == Type::Dvw
|| m_type == Type::Vh
|| m_type == Type::Svh
|| m_type == Type::Lvh
|| m_type == Type::Dvh
|| m_type == Type::Vmin
|| m_type == Type::Vmax;
|| m_type == Type::Svmin
|| m_type == Type::Lvmin
|| m_type == Type::Dvmin
|| m_type == Type::Vmax
|| m_type == Type::Svmax
|| m_type == Type::Lvmax
|| m_type == Type::Dvmax;
}
bool is_relative() const