mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 16:47:42 +00:00
LibWeb: Keep track of the parent of each formatting context
This will allow us to find the containing block formatting context when needed later on.
This commit is contained in:
parent
2f491e7769
commit
b1e75437c9
9 changed files with 25 additions and 19 deletions
|
@ -352,7 +352,7 @@ void Document::layout()
|
||||||
m_layout_root = static_ptr_cast<Layout::InitialContainingBlockBox>(tree_builder.build(*this));
|
m_layout_root = static_ptr_cast<Layout::InitialContainingBlockBox>(tree_builder.build(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
Layout::BlockFormattingContext root_formatting_context(*m_layout_root);
|
Layout::BlockFormattingContext root_formatting_context(*m_layout_root, nullptr);
|
||||||
root_formatting_context.run(Layout::LayoutMode::Default);
|
root_formatting_context.run(Layout::LayoutMode::Default);
|
||||||
|
|
||||||
m_layout_root->set_needs_display();
|
m_layout_root->set_needs_display();
|
||||||
|
|
|
@ -37,8 +37,8 @@
|
||||||
|
|
||||||
namespace Web::Layout {
|
namespace Web::Layout {
|
||||||
|
|
||||||
BlockFormattingContext::BlockFormattingContext(Box& context_box)
|
BlockFormattingContext::BlockFormattingContext(Box& context_box, FormattingContext* parent)
|
||||||
: FormattingContext(context_box)
|
: FormattingContext(context_box, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +393,7 @@ void BlockFormattingContext::compute_height(Box& box)
|
||||||
|
|
||||||
void BlockFormattingContext::layout_inline_children(LayoutMode layout_mode)
|
void BlockFormattingContext::layout_inline_children(LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
InlineFormattingContext context(context_box());
|
InlineFormattingContext context(context_box(), this);
|
||||||
context.run(layout_mode);
|
context.run(layout_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Web::Layout {
|
||||||
|
|
||||||
class BlockFormattingContext : public FormattingContext {
|
class BlockFormattingContext : public FormattingContext {
|
||||||
public:
|
public:
|
||||||
explicit BlockFormattingContext(Box& containing_block);
|
explicit BlockFormattingContext(Box&, FormattingContext* parent);
|
||||||
~BlockFormattingContext();
|
~BlockFormattingContext();
|
||||||
|
|
||||||
virtual void run(LayoutMode) override;
|
virtual void run(LayoutMode) override;
|
||||||
|
|
|
@ -32,8 +32,9 @@
|
||||||
|
|
||||||
namespace Web::Layout {
|
namespace Web::Layout {
|
||||||
|
|
||||||
FormattingContext::FormattingContext(Box& context_box)
|
FormattingContext::FormattingContext(Box& context_box, FormattingContext* parent)
|
||||||
: m_context_box(context_box)
|
: m_parent(parent)
|
||||||
|
, m_context_box(context_box)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,13 +45,13 @@ FormattingContext::~FormattingContext()
|
||||||
void FormattingContext::layout_inside(Box& box, LayoutMode layout_mode)
|
void FormattingContext::layout_inside(Box& box, LayoutMode layout_mode)
|
||||||
{
|
{
|
||||||
if (box.is_table()) {
|
if (box.is_table()) {
|
||||||
TableFormattingContext context(box);
|
TableFormattingContext context(box, this);
|
||||||
context.run(layout_mode);
|
context.run(layout_mode);
|
||||||
} else if (box.children_are_inline()) {
|
} else if (box.children_are_inline()) {
|
||||||
InlineFormattingContext context(box);
|
InlineFormattingContext context(box, this);
|
||||||
context.run(layout_mode);
|
context.run(layout_mode);
|
||||||
} else {
|
} else {
|
||||||
BlockFormattingContext context(box);
|
BlockFormattingContext context(box, this);
|
||||||
context.run(layout_mode);
|
context.run(layout_mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,14 @@ public:
|
||||||
Box& context_box() { return m_context_box; }
|
Box& context_box() { return m_context_box; }
|
||||||
const Box& context_box() const { return m_context_box; }
|
const Box& context_box() const { return m_context_box; }
|
||||||
|
|
||||||
|
FormattingContext* parent() { return m_parent; }
|
||||||
|
const FormattingContext* parent() const { return m_parent; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FormattingContext(Box&);
|
FormattingContext(Box&, FormattingContext* parent = nullptr);
|
||||||
virtual ~FormattingContext();
|
virtual ~FormattingContext();
|
||||||
|
|
||||||
static void layout_inside(Box&, LayoutMode);
|
void layout_inside(Box&, LayoutMode);
|
||||||
|
|
||||||
struct ShrinkToFitResult {
|
struct ShrinkToFitResult {
|
||||||
float preferred_width { 0 };
|
float preferred_width { 0 };
|
||||||
|
@ -50,6 +53,7 @@ protected:
|
||||||
|
|
||||||
ShrinkToFitResult calculate_shrink_to_fit_widths(Box&);
|
ShrinkToFitResult calculate_shrink_to_fit_widths(Box&);
|
||||||
|
|
||||||
|
FormattingContext* m_parent { nullptr };
|
||||||
Box& m_context_box;
|
Box& m_context_box;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <LibWeb/DOM/Node.h>
|
#include <LibWeb/DOM/Node.h>
|
||||||
#include <LibWeb/Dump.h>
|
#include <LibWeb/Dump.h>
|
||||||
#include <LibWeb/Layout/BlockBox.h>
|
#include <LibWeb/Layout/BlockBox.h>
|
||||||
|
#include <LibWeb/Layout/BlockFormattingContext.h>
|
||||||
#include <LibWeb/Layout/Box.h>
|
#include <LibWeb/Layout/Box.h>
|
||||||
#include <LibWeb/Layout/InlineFormattingContext.h>
|
#include <LibWeb/Layout/InlineFormattingContext.h>
|
||||||
#include <LibWeb/Layout/InlineNode.h>
|
#include <LibWeb/Layout/InlineNode.h>
|
||||||
|
@ -35,8 +36,8 @@
|
||||||
|
|
||||||
namespace Web::Layout {
|
namespace Web::Layout {
|
||||||
|
|
||||||
InlineFormattingContext::InlineFormattingContext(Box& containing_block)
|
InlineFormattingContext::InlineFormattingContext(Box& containing_block, FormattingContext* parent)
|
||||||
: FormattingContext(containing_block)
|
: FormattingContext(containing_block, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,7 +179,7 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_
|
||||||
inline_block.set_width(inline_block.style().width().to_px(inline_block));
|
inline_block.set_width(inline_block.style().width().to_px(inline_block));
|
||||||
}
|
}
|
||||||
|
|
||||||
FormattingContext::layout_inside(inline_block, layout_mode);
|
layout_inside(inline_block, layout_mode);
|
||||||
|
|
||||||
if (inline_block.style().height().is_undefined_or_auto()) {
|
if (inline_block.style().height().is_undefined_or_auto()) {
|
||||||
// FIXME: (10.6.6) If 'height' is 'auto', the height depends on the element's descendants per 10.6.7.
|
// FIXME: (10.6.6) If 'height' is 'auto', the height depends on the element's descendants per 10.6.7.
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Web::Layout {
|
||||||
|
|
||||||
class InlineFormattingContext final : public FormattingContext {
|
class InlineFormattingContext final : public FormattingContext {
|
||||||
public:
|
public:
|
||||||
InlineFormattingContext(Box& containing_block);
|
InlineFormattingContext(Box& containing_block, FormattingContext* parent);
|
||||||
~InlineFormattingContext();
|
~InlineFormattingContext();
|
||||||
|
|
||||||
virtual void run(LayoutMode) override;
|
virtual void run(LayoutMode) override;
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
|
|
||||||
namespace Web::Layout {
|
namespace Web::Layout {
|
||||||
|
|
||||||
TableFormattingContext::TableFormattingContext(Box& context_box)
|
TableFormattingContext::TableFormattingContext(Box& context_box, FormattingContext* parent)
|
||||||
: BlockFormattingContext(context_box)
|
: BlockFormattingContext(context_box, parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace Web::Layout {
|
||||||
|
|
||||||
class TableFormattingContext final : public BlockFormattingContext {
|
class TableFormattingContext final : public BlockFormattingContext {
|
||||||
public:
|
public:
|
||||||
explicit TableFormattingContext(Box& containing_block);
|
explicit TableFormattingContext(Box&, FormattingContext* parent);
|
||||||
~TableFormattingContext();
|
~TableFormattingContext();
|
||||||
|
|
||||||
virtual void run(LayoutMode) override;
|
virtual void run(LayoutMode) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue