1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 09:18:11 +00:00

LibWeb: Move min-width and max-width into LayoutStyle

This commit is contained in:
Andreas Kling 2020-06-24 16:03:25 +02:00
parent ecacab8618
commit ec466c0385
3 changed files with 20 additions and 13 deletions

View file

@ -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);

View file

@ -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, {}));
}
}

View file

@ -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; }
};
}