diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-10-24 17:16:08 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-12-10 12:03:19 +0000 |
commit | 56422e37e0456497b3dd06768c8b76371ca84541 (patch) | |
tree | 694eb7560ff360a435b06efa4aa4d748d25ea789 /Userland/Libraries/LibWeb | |
parent | 8a5c50f59d96306a656786b2414d8276900bf3ef (diff) | |
download | serenity-56422e37e0456497b3dd06768c8b76371ca84541.zip |
LibWeb: Allow creating Lengths from CSSPixels
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Length.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/Length.h | 3 |
2 files changed, 14 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Length.cpp b/Userland/Libraries/LibWeb/CSS/Length.cpp index 071ffbe478..7e6de34abf 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.cpp +++ b/Userland/Libraries/LibWeb/CSS/Length.cpp @@ -15,6 +15,7 @@ #include <LibWeb/DOM/Document.h> #include <LibWeb/HTML/BrowsingContext.h> #include <LibWeb/HTML/HTMLHtmlElement.h> +#include <LibWeb/PixelUnits.h> namespace Web::CSS { @@ -28,6 +29,11 @@ Length::Length(float value, Type type) , m_value(value) { } +Length::Length(CSSPixels value, Type type) + : m_type(type) + , m_value(value.value()) +{ +} Length::~Length() = default; Length Length::make_auto() @@ -40,6 +46,11 @@ Length Length::make_px(float value) return Length(value, Type::Px); } +Length Length::make_px(CSSPixels value) +{ + return Length(value.value(), Type::Px); +} + Length Length::make_calculated(NonnullRefPtr<CalculatedStyleValue> calculated_style_value) { Length length { 0, Type::Calculated }; diff --git a/Userland/Libraries/LibWeb/CSS/Length.h b/Userland/Libraries/LibWeb/CSS/Length.h index f168559515..bc4687e7f7 100644 --- a/Userland/Libraries/LibWeb/CSS/Length.h +++ b/Userland/Libraries/LibWeb/CSS/Length.h @@ -9,6 +9,7 @@ #include <AK/DeprecatedString.h> #include <LibGfx/Forward.h> #include <LibWeb/Forward.h> +#include <LibWeb/PixelUnits.h> namespace Web::CSS { @@ -40,10 +41,12 @@ public: // this file already. To break the cyclic dependency, we must move all method definitions out. Length(int value, Type type); Length(float value, Type type); + Length(CSSPixels value, Type type); ~Length(); static Length make_auto(); static Length make_px(float value); + static Length make_px(CSSPixels value); static Length make_calculated(NonnullRefPtr<CalculatedStyleValue>); Length percentage_of(Percentage const&) const; |