mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibWeb: Make IFC aware that its parent is always a BFC
This simplifies some code and allows us to use tighter types for the parent context everywhere.
This commit is contained in:
parent
83a6e698a0
commit
00bd17034d
5 changed files with 21 additions and 11 deletions
|
@ -384,7 +384,7 @@ void BlockFormattingContext::compute_position(Box& box)
|
||||||
|
|
||||||
void BlockFormattingContext::layout_inline_children(BlockContainer& block_container, LayoutMode layout_mode)
|
void BlockFormattingContext::layout_inline_children(BlockContainer& block_container, LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
InlineFormattingContext context(block_container, this);
|
InlineFormattingContext context(block_container, *this);
|
||||||
context.run(block_container, layout_mode);
|
context.run(block_container, layout_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -455,7 +455,7 @@ float FlexFormattingContext::layout_for_maximum_main_size(Box& box)
|
||||||
auto& block_container = verify_cast<BlockContainer>(box);
|
auto& block_container = verify_cast<BlockContainer>(box);
|
||||||
BlockFormattingContext bfc(block_container, this);
|
BlockFormattingContext bfc(block_container, this);
|
||||||
bfc.run(box, LayoutMode::Default);
|
bfc.run(box, LayoutMode::Default);
|
||||||
InlineFormattingContext ifc(block_container, &bfc);
|
InlineFormattingContext ifc(block_container, bfc);
|
||||||
|
|
||||||
if (is_row_layout()) {
|
if (is_row_layout()) {
|
||||||
ifc.run(box, LayoutMode::OnlyRequiredLineBreaks);
|
ifc.run(box, LayoutMode::OnlyRequiredLineBreaks);
|
||||||
|
@ -805,7 +805,7 @@ float FlexFormattingContext::determine_hypothetical_cross_size_of_item(Box& box)
|
||||||
auto& block_container = verify_cast<BlockContainer>(box);
|
auto& block_container = verify_cast<BlockContainer>(box);
|
||||||
BlockFormattingContext bfc(block_container, this);
|
BlockFormattingContext bfc(block_container, this);
|
||||||
bfc.run(box, LayoutMode::Default);
|
bfc.run(box, LayoutMode::Default);
|
||||||
InlineFormattingContext ifc(block_container, &bfc);
|
InlineFormattingContext ifc(block_container, bfc);
|
||||||
ifc.run(box, LayoutMode::OnlyRequiredLineBreaks);
|
ifc.run(box, LayoutMode::OnlyRequiredLineBreaks);
|
||||||
|
|
||||||
return is_row_layout() ? box.height() : box.width();
|
return is_row_layout() ? box.height() : box.width();
|
||||||
|
|
|
@ -95,7 +95,7 @@ OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_conte
|
||||||
|
|
||||||
VERIFY(is_block_formatting_context());
|
VERIFY(is_block_formatting_context());
|
||||||
if (child_box.children_are_inline())
|
if (child_box.children_are_inline())
|
||||||
return make<InlineFormattingContext>(verify_cast<BlockContainer>(child_box), this);
|
return make<InlineFormattingContext>(verify_cast<BlockContainer>(child_box), static_cast<BlockFormattingContext&>(*this));
|
||||||
|
|
||||||
// The child box is a block container that doesn't create its own BFC.
|
// The child box is a block container that doesn't create its own BFC.
|
||||||
// It will be formatted by this BFC.
|
// It will be formatted by this BFC.
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
|
|
||||||
namespace Web::Layout {
|
namespace Web::Layout {
|
||||||
|
|
||||||
InlineFormattingContext::InlineFormattingContext(BlockContainer& containing_block, FormattingContext* parent)
|
InlineFormattingContext::InlineFormattingContext(BlockContainer& containing_block, BlockFormattingContext& parent)
|
||||||
: FormattingContext(Type::Inline, containing_block, parent)
|
: FormattingContext(Type::Inline, containing_block, &parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,14 +26,21 @@ InlineFormattingContext::~InlineFormattingContext()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BlockFormattingContext& InlineFormattingContext::parent()
|
||||||
|
{
|
||||||
|
return static_cast<BlockFormattingContext&>(*FormattingContext::parent());
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockFormattingContext const& InlineFormattingContext::parent() const
|
||||||
|
{
|
||||||
|
return static_cast<BlockFormattingContext const&>(*FormattingContext::parent());
|
||||||
|
}
|
||||||
|
|
||||||
InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::available_space_for_line(float y) const
|
InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::available_space_for_line(float y) const
|
||||||
{
|
{
|
||||||
if (!parent()->is_block_formatting_context())
|
|
||||||
return { 0, context_box().width() };
|
|
||||||
|
|
||||||
AvailableSpaceForLineInfo info;
|
AvailableSpaceForLineInfo info;
|
||||||
|
|
||||||
auto const& bfc = static_cast<BlockFormattingContext const&>(*parent());
|
auto const& bfc = parent();
|
||||||
|
|
||||||
for (ssize_t i = bfc.left_side_floats().boxes.size() - 1; i >= 0; --i) {
|
for (ssize_t i = bfc.left_side_floats().boxes.size() - 1; i >= 0; --i) {
|
||||||
auto const& floating_box = bfc.left_side_floats().boxes.at(i);
|
auto const& floating_box = bfc.left_side_floats().boxes.at(i);
|
||||||
|
|
|
@ -15,9 +15,12 @@ namespace Web::Layout {
|
||||||
|
|
||||||
class InlineFormattingContext final : public FormattingContext {
|
class InlineFormattingContext final : public FormattingContext {
|
||||||
public:
|
public:
|
||||||
InlineFormattingContext(BlockContainer& containing_block, FormattingContext* parent);
|
InlineFormattingContext(BlockContainer& containing_block, BlockFormattingContext& parent);
|
||||||
~InlineFormattingContext();
|
~InlineFormattingContext();
|
||||||
|
|
||||||
|
BlockFormattingContext& parent();
|
||||||
|
BlockFormattingContext const& parent() const;
|
||||||
|
|
||||||
BlockContainer& containing_block() { return static_cast<BlockContainer&>(context_box()); }
|
BlockContainer& containing_block() { return static_cast<BlockContainer&>(context_box()); }
|
||||||
BlockContainer const& containing_block() const { return static_cast<BlockContainer const&>(context_box()); }
|
BlockContainer const& containing_block() const { return static_cast<BlockContainer const&>(context_box()); }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue