diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-01 17:17:32 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-01 17:17:32 +0200 |
commit | 33ac0de988c4328c3ed292190cbc38210e5f8c5f (patch) | |
tree | 42eed226e023f491e1cbe5d3435e9f910fb64640 /LibHTML | |
parent | a190f674501a8eb71425d14c067a5dc0842cbbce (diff) | |
download | serenity-33ac0de988c4328c3ed292190cbc38210e5f8c5f.zip |
LibHTML: Add Length and LengthBox classes.
We need a way to represent values that are "auto", so adding a Length class
seems like the easiest way to achieve that.
Diffstat (limited to 'LibHTML')
-rw-r--r-- | LibHTML/CSS/Length.h | 26 | ||||
-rw-r--r-- | LibHTML/CSS/LengthBox.h | 10 | ||||
-rw-r--r-- | LibHTML/Layout/LayoutBlock.cpp | 2 | ||||
-rw-r--r-- | LibHTML/Layout/LayoutStyle.h | 29 |
4 files changed, 49 insertions, 18 deletions
diff --git a/LibHTML/CSS/Length.h b/LibHTML/CSS/Length.h new file mode 100644 index 0000000000..d0483c6fdf --- /dev/null +++ b/LibHTML/CSS/Length.h @@ -0,0 +1,26 @@ +#pragma once + +class Length { +public: + enum class Type { + Auto, + Absolute, + }; + + Length() {} + Length(int value, Type type) + : m_type(type) + , m_value(value) + { + } + ~Length() {} + + bool is_auto() const { return m_type == Type::Auto; } + bool is_absolute() const { return m_type == Type::Absolute; } + + int value() const { return m_value; } + +private: + Type m_type { Type::Auto }; + int m_value { 0 }; +}; diff --git a/LibHTML/CSS/LengthBox.h b/LibHTML/CSS/LengthBox.h new file mode 100644 index 0000000000..46fa6c5cc9 --- /dev/null +++ b/LibHTML/CSS/LengthBox.h @@ -0,0 +1,10 @@ +#pragma once + +#include <LibHTML/CSS/Length.h> + +struct LengthBox { + Length top; + Length right; + Length bottom; + Length left; +}; diff --git a/LibHTML/Layout/LayoutBlock.cpp b/LibHTML/Layout/LayoutBlock.cpp index ffcca02f15..95fc1e5bd7 100644 --- a/LibHTML/Layout/LayoutBlock.cpp +++ b/LibHTML/Layout/LayoutBlock.cpp @@ -21,10 +21,8 @@ void LayoutBlock::layout() void LayoutBlock::compute_width() { - } void LayoutBlock::compute_height() { - } diff --git a/LibHTML/Layout/LayoutStyle.h b/LibHTML/Layout/LayoutStyle.h index 99bb54fec4..ddee1736ad 100644 --- a/LibHTML/Layout/LayoutStyle.h +++ b/LibHTML/Layout/LayoutStyle.h @@ -1,15 +1,9 @@ #pragma once +#include <LibHTML/CSS/LengthBox.h> #include <SharedGraphics/Color.h> #include <SharedGraphics/Size.h> -struct Box { - int top { 0 }; - int right { 0 }; - int bottom { 0 }; - int left { 0 }; -}; - enum FontStyle { Normal, Bold, @@ -23,13 +17,15 @@ public: Color text_color() const { return m_text_color; } Color background_color() const { return m_background_color; } - Box& offset() { return m_offset; } - Box& margin() { return m_margin; } - Box& padding() { return m_padding; } + LengthBox& offset() { return m_offset; } + LengthBox& margin() { return m_margin; } + LengthBox& padding() { return m_padding; } + LengthBox& border() { return m_border; } - const Box& offset() const { return m_offset; } - const Box& margin() const { return m_margin; } - const Box& padding() const { return m_padding; } + const LengthBox& offset() const { return m_offset; } + const LengthBox& margin() const { return m_margin; } + const LengthBox& padding() const { return m_padding; } + const LengthBox& border() const { return m_border; } FontStyle font_style() const { return m_font_style; } @@ -40,9 +36,10 @@ private: Color m_text_color; Color m_background_color; - Box m_offset; - Box m_margin; - Box m_padding; + LengthBox m_offset; + LengthBox m_margin; + LengthBox m_padding; + LengthBox m_border; Size m_size; |