diff options
author | Tobias Christiansen <tobi@tobyase.de> | 2021-05-30 21:57:13 +0200 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-06-06 01:46:06 +0430 |
commit | c51dbb43720bee5ce555131a7f8728599634e869 (patch) | |
tree | c0410a8239672c60caeb3cbafae63421916ced60 /Userland | |
parent | ce7c8e215f7e730d4534d4cd32a7ccbb6179127d (diff) | |
download | serenity-c51dbb43720bee5ce555131a7f8728599634e869.zip |
LibWeb: Expose size calculation of BlockFormattingContext
This is a hack for the FlexFormattingContext
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp | 25 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h | 6 |
2 files changed, 20 insertions, 11 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 53fa115123..f262a121a3 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -296,19 +296,11 @@ static float compute_auto_height_for_block_level_element(const Box& box) return bottom.value_or(0) - top.value_or(0); } -void BlockFormattingContext::compute_height(Box& box) +float BlockFormattingContext::compute_theoretical_height(const Box& box) { auto& computed_values = box.computed_values(); auto& containing_block = *box.containing_block(); - // First, resolve the top/bottom parts of the surrounding box model. - box.box_model().margin.top = computed_values.margin().top.resolved_or_zero(box, containing_block.width()).to_px(box); - box.box_model().margin.bottom = computed_values.margin().bottom.resolved_or_zero(box, containing_block.width()).to_px(box); - box.box_model().border.top = computed_values.border_top().width; - box.box_model().border.bottom = computed_values.border_bottom().width; - box.box_model().padding.top = computed_values.padding().top.resolved_or_zero(box, containing_block.width()).to_px(box); - box.box_model().padding.bottom = computed_values.padding().bottom.resolved_or_zero(box, containing_block.width()).to_px(box); - // Then work out what the height is, based on box type and CSS properties. float height = 0; if (is<ReplacedBox>(box)) { @@ -330,7 +322,22 @@ void BlockFormattingContext::compute_height(Box& box) if (!specified_min_height.is_auto() && !(computed_values.min_height().is_percentage() && !containing_block.computed_values().height().is_absolute())) height = max(height, specified_min_height.to_px(box)); + return height; +} + +void BlockFormattingContext::compute_height(Box& box) +{ + auto& computed_values = box.computed_values(); + auto& containing_block = *box.containing_block(); + // First, resolve the top/bottom parts of the surrounding box model. + box.box_model().margin.top = computed_values.margin().top.resolved_or_zero(box, containing_block.width()).to_px(box); + box.box_model().margin.bottom = computed_values.margin().bottom.resolved_or_zero(box, containing_block.width()).to_px(box); + box.box_model().border.top = computed_values.border_top().width; + box.box_model().border.bottom = computed_values.border_bottom().width; + box.box_model().padding.top = computed_values.padding().top.resolved_or_zero(box, containing_block.width()).to_px(box); + box.box_model().padding.bottom = computed_values.padding().bottom.resolved_or_zero(box, containing_block.width()).to_px(box); + auto height = compute_theoretical_height(box); box.set_height(height); } diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h index fbbdd65543..02d45a6dc9 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h @@ -24,9 +24,11 @@ public: const Vector<Box*>& left_floating_boxes() const { return m_left_floating_boxes; } const Vector<Box*>& right_floating_boxes() const { return m_right_floating_boxes; } -protected: + static float compute_theoretical_height(const Box&); void compute_width(Box&); - void compute_height(Box&); + +protected: + static void compute_height(Box&); void compute_position(Box&); private: |