1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:18:11 +00:00

LibHTML: A tiny bit of work towards block layout.

This commit is contained in:
Andreas Kling 2019-07-26 08:05:14 +02:00
parent fc9a1a1328
commit e423bb4901
2 changed files with 21 additions and 1 deletions

View file

@ -24,6 +24,7 @@ public:
bool is_initial() const { return type() == Type::Initial; }
virtual String to_string() const = 0;
virtual Length to_length() const { return {}; }
protected:
explicit StyleValue(Type);
@ -60,7 +61,10 @@ public:
}
virtual ~LengthStyleValue() override {}
String to_string() const override { return m_length.to_string(); }
virtual String to_string() const override { return m_length.to_string(); }
virtual Length to_length() const override { return m_length; }
const Length& length() const { return m_length; }
private:
explicit LengthStyleValue(const Length& length)

View file

@ -50,6 +50,22 @@ void LayoutBlock::compute_width()
dbg() << " Left: " << margin_left->to_string() << "+" << border_left->to_string() << "+" << padding_left->to_string();
dbg() << "Right: " << margin_right->to_string() << "+" << border_right->to_string() << "+" << padding_right->to_string();
int total_px = 0;
for (auto& value : { margin_left, border_left, padding_left, width, padding_right, border_right, margin_right }) {
total_px += value->to_length().to_px();
}
dbg() << "Total: " << total_px;
// 10.3.3 Block-level, non-replaced elements in normal flow
// If 'width' is not 'auto' and 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' (plus any of 'margin-left' or 'margin-right' that are not 'auto') is larger than the width of the containing block, then any 'auto' values for 'margin-left' or 'margin-right' are, for the following rules, treated as zero.
if (width->to_length().is_auto() && total_px > containing_block()->rect().width()) {
if (margin_left->to_length().is_auto())
margin_left = zero_value;
if (margin_right->to_length().is_auto())
margin_right = zero_value;
}
}
void LayoutBlock::compute_height()