summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/Length.h
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-10-05 15:39:40 +0100
committerAndreas Kling <kling@serenityos.org>2021-10-05 18:51:39 +0200
commitf354fd72f1518b250f7e1de6f1ab8f61da557396 (patch)
tree2dcb0427b630c4fc01d79ed9f7a4016d28f31f95 /Userland/Libraries/LibWeb/CSS/Length.h
parentfd51b02f9d2b400f73887b88ea81099513cded87 (diff)
downloadserenity-f354fd72f1518b250f7e1de6f1ab8f61da557396.zip
LibWeb: Split Length::absolute_length_to_px() out from to_px()
In cases where we know the Length is absolute, we know we don't need to pass in a Layout::Node or FontMetrics etc, and yet we were required to before. Splitting it means jumping through less hoops that we don't have to. :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS/Length.h')
-rw-r--r--Userland/Libraries/LibWeb/CSS/Length.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h
index f328263427..0e05727ba0 100644
--- a/Userland/Libraries/LibWeb/CSS/Length.h
+++ b/Userland/Libraries/LibWeb/CSS/Length.h
@@ -109,13 +109,18 @@ public:
ALWAYS_INLINE float to_px(Gfx::IntRect const& viewport_rect, Gfx::FontMetrics const& font_metrics, float root_font_size) const
{
+ if (is_auto())
+ return 0;
if (is_relative())
return relative_length_to_px(viewport_rect, font_metrics, root_font_size);
+ return absolute_length_to_px();
+ }
+
+ ALWAYS_INLINE float absolute_length_to_px() const
+ {
constexpr float inch_pixels = 96.0f;
constexpr float centimeter_pixels = (inch_pixels / 2.54f);
switch (m_type) {
- case Type::Auto:
- return 0;
case Type::Cm:
return m_value * centimeter_pixels; // 1cm = 96px/2.54
case Type::In:
@@ -130,9 +135,6 @@ public:
return m_value * ((1.0f / 10.0f) * centimeter_pixels); // 1mm = 1/10th of 1cm
case Type::Q:
return m_value * ((1.0f / 40.0f) * centimeter_pixels); // 1Q = 1/40th of 1cm
- case Type::Undefined:
- case Type::Percentage:
- case Type::Calculated:
default:
VERIFY_NOT_REACHED();
}