mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:17:35 +00:00
LibWeb: Add BlockFormattingContext::root()
The CSS spec uses the name "block formatting context root" when talking about a box that establishes a BFC. So let's call it BFC::root() in our code as well, instead of the less specific BFC::context_box().
This commit is contained in:
parent
bce3bf9f1e
commit
5408913b22
2 changed files with 17 additions and 12 deletions
|
@ -17,8 +17,8 @@
|
||||||
|
|
||||||
namespace Web::Layout {
|
namespace Web::Layout {
|
||||||
|
|
||||||
BlockFormattingContext::BlockFormattingContext(Box& context_box, FormattingContext* parent)
|
BlockFormattingContext::BlockFormattingContext(Box& root, FormattingContext* parent)
|
||||||
: FormattingContext(context_box, parent)
|
: FormattingContext(root, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ BlockFormattingContext::~BlockFormattingContext()
|
||||||
|
|
||||||
bool BlockFormattingContext::is_initial() const
|
bool BlockFormattingContext::is_initial() const
|
||||||
{
|
{
|
||||||
return is<InitialContainingBlock>(context_box());
|
return is<InitialContainingBlock>(root());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockFormattingContext::run(Box& box, LayoutMode layout_mode)
|
void BlockFormattingContext::run(Box& box, LayoutMode layout_mode)
|
||||||
|
@ -564,14 +564,14 @@ void BlockFormattingContext::place_block_level_non_replaced_element_in_normal_fl
|
||||||
|
|
||||||
void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_mode)
|
void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
auto viewport_rect = context_box().browsing_context().viewport_rect();
|
auto viewport_rect = root().browsing_context().viewport_rect();
|
||||||
|
|
||||||
auto& icb = verify_cast<Layout::InitialContainingBlock>(context_box());
|
auto& icb = verify_cast<Layout::InitialContainingBlock>(root());
|
||||||
icb.build_stacking_context_tree();
|
icb.build_stacking_context_tree();
|
||||||
|
|
||||||
icb.set_width(viewport_rect.width());
|
icb.set_width(viewport_rect.width());
|
||||||
|
|
||||||
layout_block_level_children(context_box(), layout_mode);
|
layout_block_level_children(root(), layout_mode);
|
||||||
|
|
||||||
VERIFY(!icb.children_are_inline());
|
VERIFY(!icb.children_are_inline());
|
||||||
|
|
||||||
|
@ -614,15 +614,15 @@ void BlockFormattingContext::layout_floating_child(Box& box, Box& containing_blo
|
||||||
// Then we float it to the left or right.
|
// Then we float it to the left or right.
|
||||||
float x = box.effective_offset().x();
|
float x = box.effective_offset().x();
|
||||||
|
|
||||||
auto box_in_context_rect = rect_in_coordinate_space(box, context_box());
|
auto box_in_root_rect = rect_in_coordinate_space(box, root());
|
||||||
float y_in_context_box = box_in_context_rect.y();
|
float y_in_root = box_in_root_rect.y();
|
||||||
|
|
||||||
// Next, float to the left and/or right
|
// Next, float to the left and/or right
|
||||||
if (box.computed_values().float_() == CSS::Float::Left) {
|
if (box.computed_values().float_() == CSS::Float::Left) {
|
||||||
if (!m_left_floating_boxes.is_empty()) {
|
if (!m_left_floating_boxes.is_empty()) {
|
||||||
auto& previous_floating_box = *m_left_floating_boxes.last();
|
auto& previous_floating_box = *m_left_floating_boxes.last();
|
||||||
auto previous_rect = rect_in_coordinate_space(previous_floating_box, context_box());
|
auto previous_rect = rect_in_coordinate_space(previous_floating_box, root());
|
||||||
if (previous_rect.contains_vertically(y_in_context_box)) {
|
if (previous_rect.contains_vertically(y_in_root)) {
|
||||||
// This box touches another already floating box. Stack to the right.
|
// This box touches another already floating box. Stack to the right.
|
||||||
x = previous_floating_box.margin_box_as_relative_rect().x() + previous_floating_box.margin_box_as_relative_rect().width() + box.box_model().margin_box().left;
|
x = previous_floating_box.margin_box_as_relative_rect().x() + previous_floating_box.margin_box_as_relative_rect().width() + box.box_model().margin_box().left;
|
||||||
} else {
|
} else {
|
||||||
|
@ -639,8 +639,8 @@ void BlockFormattingContext::layout_floating_child(Box& box, Box& containing_blo
|
||||||
} else if (box.computed_values().float_() == CSS::Float::Right) {
|
} else if (box.computed_values().float_() == CSS::Float::Right) {
|
||||||
if (!m_right_floating_boxes.is_empty()) {
|
if (!m_right_floating_boxes.is_empty()) {
|
||||||
auto& previous_floating_box = *m_right_floating_boxes.last();
|
auto& previous_floating_box = *m_right_floating_boxes.last();
|
||||||
auto previous_rect = rect_in_coordinate_space(previous_floating_box, context_box());
|
auto previous_rect = rect_in_coordinate_space(previous_floating_box, root());
|
||||||
if (previous_rect.contains_vertically(y_in_context_box)) {
|
if (previous_rect.contains_vertically(y_in_root)) {
|
||||||
// This box touches another already floating box. Stack to the left.
|
// This box touches another already floating box. Stack to the left.
|
||||||
x = previous_floating_box.margin_box_as_relative_rect().x() - box.box_model().margin_box().right - box.width();
|
x = previous_floating_box.margin_box_as_relative_rect().x() - box.box_model().margin_box().right - box.width();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
namespace Web::Layout {
|
namespace Web::Layout {
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-display/#block-formatting-context
|
||||||
class BlockFormattingContext : public FormattingContext {
|
class BlockFormattingContext : public FormattingContext {
|
||||||
public:
|
public:
|
||||||
explicit BlockFormattingContext(Box&, FormattingContext* parent);
|
explicit BlockFormattingContext(Box&, FormattingContext* parent);
|
||||||
|
@ -27,6 +28,10 @@ public:
|
||||||
static float compute_theoretical_height(const Box&);
|
static float compute_theoretical_height(const Box&);
|
||||||
void compute_width(Box&);
|
void compute_width(Box&);
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-display/#block-formatting-context-root
|
||||||
|
Box& root() { return context_box(); }
|
||||||
|
Box const& root() const { return context_box(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void compute_height(Box&);
|
static void compute_height(Box&);
|
||||||
void compute_position(Box&);
|
void compute_position(Box&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue