diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-24 11:24:00 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-24 11:24:00 +0200 |
commit | 90edaabc4b303f444752eddabd632daaeea68af9 (patch) | |
tree | b32fffaec967c81ba18bde8187415ddf2d299250 /Libraries/LibWeb/CSS | |
parent | f742b245b79a029998bae87d71593a4fd510cbc7 (diff) | |
download | serenity-90edaabc4b303f444752eddabd632daaeea68af9.zip |
LibWeb: Add an "undefined" state to Length
A default-constructed Length now gives you an undefined length value,
which can be used to signify the absence of a value.
Diffstat (limited to 'Libraries/LibWeb/CSS')
-rw-r--r-- | Libraries/LibWeb/CSS/Length.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibWeb/CSS/Length.h | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/Libraries/LibWeb/CSS/Length.cpp b/Libraries/LibWeb/CSS/Length.cpp index 0df4001de0..c0db571a8a 100644 --- a/Libraries/LibWeb/CSS/Length.cpp +++ b/Libraries/LibWeb/CSS/Length.cpp @@ -53,6 +53,8 @@ const char* Length::unit_name() const return "rem"; case Type::Auto: return "auto"; + case Type::Undefined: + return "undefined"; } ASSERT_NOT_REACHED(); } diff --git a/Libraries/LibWeb/CSS/Length.h b/Libraries/LibWeb/CSS/Length.h index f531ace3a0..cd1413f550 100644 --- a/Libraries/LibWeb/CSS/Length.h +++ b/Libraries/LibWeb/CSS/Length.h @@ -34,12 +34,14 @@ namespace Web { class Length { public: enum class Type { + Undefined, Auto, Px, Em, Rem, }; + Length() { } Length(int value, Type type) : m_type(type) , m_value(value) @@ -54,6 +56,7 @@ public: static Length make_auto() { return Length(0, Type::Auto); } static Length make_px(float value) { return Length(value, Type::Px); } + bool is_undefined() const { return m_type == Type::Undefined; } bool is_auto() const { return m_type == Type::Auto; } bool is_absolute() const { return m_type == Type::Px; } bool is_relative() const { return m_type == Type::Em || m_type == Type::Rem; } @@ -68,6 +71,7 @@ public: return 0; case Type::Px: return m_value; + case Type::Undefined: default: ASSERT_NOT_REACHED(); } @@ -85,7 +89,7 @@ private: const char* unit_name() const; - Type m_type { Type::Auto }; + Type m_type { Type::Undefined }; float m_value { 0 }; }; |