mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:07:44 +00:00
LibWeb: Store y offset of current block container in BFC member
This change should make it possible to access y offset of current block container in BFC without explicitly passing it using method parameters.
This commit is contained in:
parent
84e8d5f418
commit
0cd63f851e
2 changed files with 13 additions and 8 deletions
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/TemporaryChange.h>
|
||||||
#include <LibWeb/CSS/Length.h>
|
#include <LibWeb/CSS/Length.h>
|
||||||
#include <LibWeb/DOM/Node.h>
|
#include <LibWeb/DOM/Node.h>
|
||||||
#include <LibWeb/Dump.h>
|
#include <LibWeb/Dump.h>
|
||||||
|
@ -450,7 +451,7 @@ CSSPixels BlockFormattingContext::compute_auto_height_for_block_level_element(Bo
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContainer const& block_container, LayoutMode layout_mode, CSSPixels& bottom_of_lowest_margin_box, AvailableSpace const& available_space, CSSPixels& current_y)
|
void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContainer const& block_container, LayoutMode layout_mode, CSSPixels& bottom_of_lowest_margin_box, AvailableSpace const& available_space)
|
||||||
{
|
{
|
||||||
auto& box_state = m_state.get_mutable(box);
|
auto& box_state = m_state.get_mutable(box);
|
||||||
|
|
||||||
|
@ -463,9 +464,11 @@ void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContain
|
||||||
if (is<ListItemMarkerBox>(box))
|
if (is<ListItemMarkerBox>(box))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
auto const y = m_y_offset_of_current_block_container.value();
|
||||||
|
|
||||||
if (box.is_floating()) {
|
if (box.is_floating()) {
|
||||||
auto margin_top = !m_margin_state.has_block_container_waiting_for_final_y_position() ? m_margin_state.current_collapsed_margin() : 0;
|
auto margin_top = !m_margin_state.has_block_container_waiting_for_final_y_position() ? m_margin_state.current_collapsed_margin() : 0;
|
||||||
layout_floating_box(box, block_container, layout_mode, available_space, margin_top + current_y);
|
layout_floating_box(box, block_container, layout_mode, available_space, margin_top + y);
|
||||||
bottom_of_lowest_margin_box = max(bottom_of_lowest_margin_box, box_state.offset.y() + box_state.content_height() + box_state.margin_box_bottom());
|
bottom_of_lowest_margin_box = max(bottom_of_lowest_margin_box, box_state.offset.y() + box_state.content_height() + box_state.margin_box_bottom());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -489,7 +492,7 @@ void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContain
|
||||||
margin_top = 0;
|
margin_top = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
place_block_level_element_in_normal_flow_vertically(box, current_y + margin_top);
|
place_block_level_element_in_normal_flow_vertically(box, y + margin_top);
|
||||||
place_block_level_element_in_normal_flow_horizontally(box, available_space);
|
place_block_level_element_in_normal_flow_horizontally(box, available_space);
|
||||||
|
|
||||||
OwnPtr<FormattingContext> independent_formatting_context;
|
OwnPtr<FormattingContext> independent_formatting_context;
|
||||||
|
@ -510,7 +513,7 @@ void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContain
|
||||||
} else if (!m_margin_state.has_block_container_waiting_for_final_y_position()) {
|
} else if (!m_margin_state.has_block_container_waiting_for_final_y_position()) {
|
||||||
// margin-top of block container can be updated during children layout hence it's final y position yet to be determined
|
// margin-top of block container can be updated during children layout hence it's final y position yet to be determined
|
||||||
m_margin_state.register_block_container_y_position_update_callback([&](CSSPixels margin_top) {
|
m_margin_state.register_block_container_y_position_update_callback([&](CSSPixels margin_top) {
|
||||||
place_block_level_element_in_normal_flow_vertically(box, margin_top + current_y + box_state.border_box_top());
|
place_block_level_element_in_normal_flow_vertically(box, margin_top + y + box_state.border_box_top());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,7 +528,7 @@ void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContain
|
||||||
if (!m_margin_state.box_last_in_flow_child_margin_bottom_collapsed) {
|
if (!m_margin_state.box_last_in_flow_child_margin_bottom_collapsed) {
|
||||||
m_margin_state.reset();
|
m_margin_state.reset();
|
||||||
}
|
}
|
||||||
current_y = box_state.offset.y() + box_state.content_height() + box_state.border_box_bottom();
|
m_y_offset_of_current_block_container = box_state.offset.y() + box_state.content_height() + box_state.border_box_bottom();
|
||||||
}
|
}
|
||||||
m_margin_state.box_last_in_flow_child_margin_bottom_collapsed = false;
|
m_margin_state.box_last_in_flow_child_margin_bottom_collapsed = false;
|
||||||
|
|
||||||
|
@ -549,10 +552,10 @@ void BlockFormattingContext::layout_block_level_children(BlockContainer const& b
|
||||||
VERIFY(!block_container.children_are_inline());
|
VERIFY(!block_container.children_are_inline());
|
||||||
|
|
||||||
CSSPixels bottom_of_lowest_margin_box = 0;
|
CSSPixels bottom_of_lowest_margin_box = 0;
|
||||||
CSSPixels current_y = 0;
|
|
||||||
|
|
||||||
|
TemporaryChange<Optional<CSSPixels>> change { m_y_offset_of_current_block_container, CSSPixels(0) };
|
||||||
block_container.for_each_child_of_type<Box>([&](Box& box) {
|
block_container.for_each_child_of_type<Box>([&](Box& box) {
|
||||||
layout_block_level_box(box, block_container, layout_mode, bottom_of_lowest_margin_box, available_space, current_y);
|
layout_block_level_box(box, block_container, layout_mode, bottom_of_lowest_margin_box, available_space);
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
|
|
||||||
void layout_floating_box(Box const& child, BlockContainer const& containing_block, LayoutMode, AvailableSpace const&, CSSPixels y, LineBuilder* = nullptr);
|
void layout_floating_box(Box const& child, BlockContainer const& containing_block, LayoutMode, AvailableSpace const&, CSSPixels y, LineBuilder* = nullptr);
|
||||||
|
|
||||||
void layout_block_level_box(Box const&, BlockContainer const&, LayoutMode, CSSPixels& bottom_of_lowest_margin_box, AvailableSpace const&, CSSPixels& current_y);
|
void layout_block_level_box(Box const&, BlockContainer const&, LayoutMode, CSSPixels& bottom_of_lowest_margin_box, AvailableSpace const&);
|
||||||
|
|
||||||
virtual bool can_determine_size_of_child() const override { return true; }
|
virtual bool can_determine_size_of_child() const override { return true; }
|
||||||
virtual void determine_width_of_child(Box const&, AvailableSpace const&) override;
|
virtual void determine_width_of_child(Box const&, AvailableSpace const&) override;
|
||||||
|
@ -150,6 +150,8 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Optional<CSSPixels> m_y_offset_of_current_block_container;
|
||||||
|
|
||||||
BlockMarginState m_margin_state;
|
BlockMarginState m_margin_state;
|
||||||
|
|
||||||
FloatSideData m_left_floats;
|
FloatSideData m_left_floats;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue