summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-24 16:03:25 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-24 16:49:51 +0200
commitec466c0385c76213579a9418e32182e316f20cc6 (patch)
treed2a73462920fcd1f0310aecfe249e4cb81d5e187 /Libraries/LibWeb
parentecacab8618761f4cb539480a4e19861670dc2679 (diff)
downloadserenity-ec466c0385c76213579a9418e32182e316f20cc6.zip
LibWeb: Move min-width and max-width into LayoutStyle
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r--Libraries/LibWeb/Layout/LayoutBlock.cpp25
-rw-r--r--Libraries/LibWeb/Layout/LayoutNode.cpp2
-rw-r--r--Libraries/LibWeb/Layout/LayoutStyle.h6
3 files changed, 20 insertions, 13 deletions
diff --git a/Libraries/LibWeb/Layout/LayoutBlock.cpp b/Libraries/LibWeb/Layout/LayoutBlock.cpp
index 75bac253ab..c66fe3d356 100644
--- a/Libraries/LibWeb/Layout/LayoutBlock.cpp
+++ b/Libraries/LibWeb/Layout/LayoutBlock.cpp
@@ -392,7 +392,7 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
// 2. The tentative used width is greater than 'max-width', the rules above are applied again,
// but this time using the computed value of 'max-width' as the computed value for 'width'.
- auto specified_max_width = specified_style.length_or_fallback(CSS::PropertyID::MaxWidth, Length::make_auto(), containing_block.width());
+ auto specified_max_width = style().max_width().resolved_or_auto(*this, containing_block.width());
if (!specified_max_width.is_auto()) {
if (used_width.to_px(*this) > specified_max_width.to_px(*this)) {
used_width = try_compute_width(specified_max_width);
@@ -401,7 +401,7 @@ void LayoutBlock::compute_width_for_absolutely_positioned_block()
// 3. If the resulting width is smaller than 'min-width', the rules above are applied again,
// but this time using the value of 'min-width' as the computed value for 'width'.
- auto specified_min_width = specified_style.length_or_fallback(CSS::PropertyID::MinWidth, Length::make_auto(), containing_block.width());
+ auto specified_min_width = style().min_width().resolved_or_auto(*this, containing_block.width());
if (!specified_min_width.is_auto()) {
if (used_width.to_px(*this) < specified_min_width.to_px(*this)) {
used_width = try_compute_width(specified_min_width);
@@ -423,8 +423,7 @@ void LayoutBlock::compute_width()
if (is_absolutely_positioned())
return compute_width_for_absolutely_positioned_block();
- auto& style = this->specified_style();
- auto auto_value = Length::make_auto();
+ auto& specified_style = this->specified_style();
auto zero_value = Length::make_px(0);
Length margin_left = Length::make_auto();
@@ -442,12 +441,12 @@ void LayoutBlock::compute_width()
dbg() << " Left: " << margin_left << "+" << border_left << "+" << padding_left;
dbg() << "Right: " << margin_right << "+" << border_right << "+" << padding_right;
#endif
- margin_left = style.length_or_fallback(CSS::PropertyID::MarginLeft, zero_value, containing_block.width());
- margin_right = style.length_or_fallback(CSS::PropertyID::MarginRight, zero_value, containing_block.width());
- border_left = style.length_or_fallback(CSS::PropertyID::BorderLeftWidth, zero_value);
- border_right = style.length_or_fallback(CSS::PropertyID::BorderRightWidth, zero_value);
- padding_left = style.length_or_fallback(CSS::PropertyID::PaddingLeft, zero_value, containing_block.width());
- padding_right = style.length_or_fallback(CSS::PropertyID::PaddingRight, zero_value, containing_block.width());
+ margin_left = specified_style.length_or_fallback(CSS::PropertyID::MarginLeft, zero_value, containing_block.width());
+ margin_right = specified_style.length_or_fallback(CSS::PropertyID::MarginRight, zero_value, containing_block.width());
+ border_left = specified_style.length_or_fallback(CSS::PropertyID::BorderLeftWidth, zero_value);
+ border_right = specified_style.length_or_fallback(CSS::PropertyID::BorderRightWidth, zero_value);
+ padding_left = specified_style.length_or_fallback(CSS::PropertyID::PaddingLeft, zero_value, containing_block.width());
+ padding_right = specified_style.length_or_fallback(CSS::PropertyID::PaddingRight, zero_value, containing_block.width());
float total_px = 0;
for (auto& value : { margin_left, border_left, padding_left, width, padding_right, border_right, margin_right }) {
@@ -525,14 +524,14 @@ void LayoutBlock::compute_width()
return width;
};
- auto specified_width = style.length_or_fallback(CSS::PropertyID::Width, auto_value, containing_block.width());
+ auto specified_width = style().width().resolved_or_auto(*this, containing_block.width());
// 1. The tentative used width is calculated (without 'min-width' and 'max-width')
auto used_width = try_compute_width(specified_width);
// 2. The tentative used width is greater than 'max-width', the rules above are applied again,
// but this time using the computed value of 'max-width' as the computed value for 'width'.
- auto specified_max_width = style.length_or_fallback(CSS::PropertyID::MaxWidth, auto_value, containing_block.width());
+ auto specified_max_width = style().max_width().resolved_or_auto(*this, containing_block.width());
if (!specified_max_width.is_auto()) {
if (used_width.to_px(*this) > specified_max_width.to_px(*this)) {
used_width = try_compute_width(specified_max_width);
@@ -541,7 +540,7 @@ void LayoutBlock::compute_width()
// 3. If the resulting width is smaller than 'min-width', the rules above are applied again,
// but this time using the value of 'min-width' as the computed value for 'width'.
- auto specified_min_width = style.length_or_fallback(CSS::PropertyID::MinWidth, auto_value, containing_block.width());
+ auto specified_min_width = style().min_width().resolved_or_auto(*this, containing_block.width());
if (!specified_min_width.is_auto()) {
if (used_width.to_px(*this) < specified_min_width.to_px(*this)) {
used_width = try_compute_width(specified_min_width);
diff --git a/Libraries/LibWeb/Layout/LayoutNode.cpp b/Libraries/LibWeb/Layout/LayoutNode.cpp
index 372adec70e..21dbe49891 100644
--- a/Libraries/LibWeb/Layout/LayoutNode.cpp
+++ b/Libraries/LibWeb/Layout/LayoutNode.cpp
@@ -227,6 +227,8 @@ void LayoutNodeWithStyle::apply_style(const StyleProperties& specified_style)
style.set_text_align(specified_style.text_align());
style.set_z_index(specified_style.z_index());
style.set_width(specified_style.length_or_fallback(CSS::PropertyID::Width, {}));
+ style.set_min_width(specified_style.length_or_fallback(CSS::PropertyID::MinWidth, {}));
+ style.set_max_width(specified_style.length_or_fallback(CSS::PropertyID::MaxWidth, {}));
}
}
diff --git a/Libraries/LibWeb/Layout/LayoutStyle.h b/Libraries/LibWeb/Layout/LayoutStyle.h
index 73d6ba9f65..41a0b44ad7 100644
--- a/Libraries/LibWeb/Layout/LayoutStyle.h
+++ b/Libraries/LibWeb/Layout/LayoutStyle.h
@@ -37,12 +37,16 @@ public:
CSS::TextAlign text_align() const { return m_text_align; }
CSS::Position position() const { return m_position; }
const Length& width() const { return m_width; }
+ const Length& min_width() const { return m_min_width; }
+ const Length& max_width() const { return m_max_width; }
protected:
Optional<int> m_z_index;
CSS::TextAlign m_text_align;
CSS::Position m_position;
Length m_width;
+ Length m_min_width;
+ Length m_max_width;
};
class ImmutableLayoutStyle final : public LayoutStyle {
@@ -54,6 +58,8 @@ public:
void set_text_align(CSS::TextAlign text_align) { m_text_align = text_align; }
void set_position(CSS::Position position) { m_position = position; }
void set_width(const Length& width) { m_width = width; }
+ void set_min_width(const Length& width) { m_min_width = width; }
+ void set_max_width(const Length& width) { m_max_width = width; }
};
}