summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-04-28 17:46:49 +0100
committerAndreas Kling <kling@serenityos.org>2023-04-29 16:23:50 +0200
commit091a1ff5279f0ed8fe03f82c0cbd1a0349c90eea (patch)
tree96fd888fc898c15c25ed8299af812a0f276d8958 /Userland/Libraries
parent0dd585ba7bedcbc87db7eaf6d586d43c5ce1fc38 (diff)
downloadserenity-091a1ff5279f0ed8fe03f82c0cbd1a0349c90eea.zip
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.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Length.cpp60
-rw-r--r--Userland/Libraries/LibWeb/CSS/Length.h26
2 files changed, 85 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp
index 7657a2e557..e8b7320932 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Length.cpp
@@ -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)) {
diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h
index ded6735393..bae94c0f31 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.h
+++ b/Userland/Libraries/LibWeb/CSS/Length.h
@@ -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