mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
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:
parent
0dd585ba7b
commit
091a1ff527
2 changed files with 85 additions and 1 deletions
|
@ -100,12 +100,24 @@ CSSPixels Length::relative_length_to_px(CSSPixelRect const& viewport_rect, FontM
|
||||||
case Type::Rlh:
|
case Type::Rlh:
|
||||||
return m_value * root_font_metrics.line_height;
|
return m_value * root_font_metrics.line_height;
|
||||||
case Type::Vw:
|
case Type::Vw:
|
||||||
|
case Type::Svw:
|
||||||
|
case Type::Lvw:
|
||||||
|
case Type::Dvw:
|
||||||
return viewport_rect.width() * (m_value / 100);
|
return viewport_rect.width() * (m_value / 100);
|
||||||
case Type::Vh:
|
case Type::Vh:
|
||||||
|
case Type::Svh:
|
||||||
|
case Type::Lvh:
|
||||||
|
case Type::Dvh:
|
||||||
return viewport_rect.height() * (m_value / 100);
|
return viewport_rect.height() * (m_value / 100);
|
||||||
case Type::Vmin:
|
case Type::Vmin:
|
||||||
|
case Type::Svmin:
|
||||||
|
case Type::Lvmin:
|
||||||
|
case Type::Dvmin:
|
||||||
return min(viewport_rect.width(), viewport_rect.height()) * (m_value / 100);
|
return min(viewport_rect.width(), viewport_rect.height()) * (m_value / 100);
|
||||||
case Type::Vmax:
|
case Type::Vmax:
|
||||||
|
case Type::Svmax:
|
||||||
|
case Type::Lvmax:
|
||||||
|
case Type::Dvmax:
|
||||||
return max(viewport_rect.width(), viewport_rect.height()) * (m_value / 100);
|
return max(viewport_rect.width(), viewport_rect.height()) * (m_value / 100);
|
||||||
default:
|
default:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
|
@ -174,12 +186,36 @@ char const* Length::unit_name() const
|
||||||
return "rlh";
|
return "rlh";
|
||||||
case Type::Vw:
|
case Type::Vw:
|
||||||
return "vw";
|
return "vw";
|
||||||
|
case Type::Svw:
|
||||||
|
return "svw";
|
||||||
|
case Type::Lvw:
|
||||||
|
return "lvw";
|
||||||
|
case Type::Dvw:
|
||||||
|
return "dvw";
|
||||||
case Type::Vh:
|
case Type::Vh:
|
||||||
return "vh";
|
return "vh";
|
||||||
|
case Type::Svh:
|
||||||
|
return "svh";
|
||||||
|
case Type::Lvh:
|
||||||
|
return "lvh";
|
||||||
|
case Type::Dvh:
|
||||||
|
return "dvh";
|
||||||
case Type::Vmin:
|
case Type::Vmin:
|
||||||
return "vmin";
|
return "vmin";
|
||||||
|
case Type::Svmin:
|
||||||
|
return "svmin";
|
||||||
|
case Type::Lvmin:
|
||||||
|
return "lvmin";
|
||||||
|
case Type::Dvmin:
|
||||||
|
return "dvmin";
|
||||||
case Type::Vmax:
|
case Type::Vmax:
|
||||||
return "vmax";
|
return "vmax";
|
||||||
|
case Type::Svmax:
|
||||||
|
return "svmax";
|
||||||
|
case Type::Lvmax:
|
||||||
|
return "lvmax";
|
||||||
|
case Type::Dvmax:
|
||||||
|
return "dvmax";
|
||||||
case Type::Cm:
|
case Type::Cm:
|
||||||
return "cm";
|
return "cm";
|
||||||
case Type::Mm:
|
case Type::Mm:
|
||||||
|
@ -228,12 +264,36 @@ Optional<Length::Type> Length::unit_from_name(StringView name)
|
||||||
return Length::Type::Rlh;
|
return Length::Type::Rlh;
|
||||||
} else if (name.equals_ignoring_ascii_case("vw"sv)) {
|
} else if (name.equals_ignoring_ascii_case("vw"sv)) {
|
||||||
return Length::Type::Vw;
|
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)) {
|
} else if (name.equals_ignoring_ascii_case("vh"sv)) {
|
||||||
return Length::Type::Vh;
|
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)) {
|
} else if (name.equals_ignoring_ascii_case("vmin"sv)) {
|
||||||
return Length::Type::Vmin;
|
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)) {
|
} else if (name.equals_ignoring_ascii_case("vmax"sv)) {
|
||||||
return Length::Type::Vmax;
|
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)) {
|
} else if (name.equals_ignoring_ascii_case("cm"sv)) {
|
||||||
return Length::Type::Cm;
|
return Length::Type::Cm;
|
||||||
} else if (name.equals_ignoring_ascii_case("mm"sv)) {
|
} else if (name.equals_ignoring_ascii_case("mm"sv)) {
|
||||||
|
|
|
@ -33,9 +33,21 @@ public:
|
||||||
|
|
||||||
// Viewport-relative
|
// Viewport-relative
|
||||||
Vw,
|
Vw,
|
||||||
|
Svw,
|
||||||
|
Lvw,
|
||||||
|
Dvw,
|
||||||
Vh,
|
Vh,
|
||||||
|
Svh,
|
||||||
|
Lvh,
|
||||||
|
Dvh,
|
||||||
Vmin,
|
Vmin,
|
||||||
|
Svmin,
|
||||||
|
Lvmin,
|
||||||
|
Dvmin,
|
||||||
Vmax,
|
Vmax,
|
||||||
|
Svmax,
|
||||||
|
Lvmax,
|
||||||
|
Dvmax,
|
||||||
|
|
||||||
// Absolute
|
// Absolute
|
||||||
Cm,
|
Cm,
|
||||||
|
@ -105,9 +117,21 @@ public:
|
||||||
bool is_viewport_relative() const
|
bool is_viewport_relative() const
|
||||||
{
|
{
|
||||||
return m_type == Type::Vw
|
return m_type == Type::Vw
|
||||||
|
|| m_type == Type::Svw
|
||||||
|
|| m_type == Type::Lvw
|
||||||
|
|| m_type == Type::Dvw
|
||||||
|| m_type == Type::Vh
|
|| m_type == Type::Vh
|
||||||
|
|| m_type == Type::Svh
|
||||||
|
|| m_type == Type::Lvh
|
||||||
|
|| m_type == Type::Dvh
|
||||||
|| m_type == Type::Vmin
|
|| 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
|
bool is_relative() const
|
||||||
|
|
Loading…
Add table
Reference in a new issue