summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-11-25 20:08:52 +0100
committerAndreas Kling <kling@serenityos.org>2020-11-25 21:26:58 +0100
commitb1e75437c98f3164a01790f9fa47b1a2870a810b (patch)
tree1e4ab33afb26ce66a734b5de4157383f896db0fd
parent2f491e7769eff773d728ff53a40c8681a35cf4c0 (diff)
downloadserenity-b1e75437c98f3164a01790f9fa47b1a2870a810b.zip
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.
-rw-r--r--Libraries/LibWeb/DOM/Document.cpp2
-rw-r--r--Libraries/LibWeb/Layout/BlockFormattingContext.cpp6
-rw-r--r--Libraries/LibWeb/Layout/BlockFormattingContext.h2
-rw-r--r--Libraries/LibWeb/Layout/FormattingContext.cpp11
-rw-r--r--Libraries/LibWeb/Layout/FormattingContext.h8
-rw-r--r--Libraries/LibWeb/Layout/InlineFormattingContext.cpp7
-rw-r--r--Libraries/LibWeb/Layout/InlineFormattingContext.h2
-rw-r--r--Libraries/LibWeb/Layout/TableFormattingContext.cpp4
-rw-r--r--Libraries/LibWeb/Layout/TableFormattingContext.h2
9 files changed, 25 insertions, 19 deletions
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 2cc6af2768..efd8d90b75 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -352,7 +352,7 @@ void Document::layout()
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);
m_layout_root->set_needs_display();
diff --git a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
index 5f1483e043..bac2769a0a 100644
--- a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
+++ b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
@@ -37,8 +37,8 @@
namespace Web::Layout {
-BlockFormattingContext::BlockFormattingContext(Box& context_box)
- : FormattingContext(context_box)
+BlockFormattingContext::BlockFormattingContext(Box& context_box, FormattingContext* parent)
+ : FormattingContext(context_box, parent)
{
}
@@ -393,7 +393,7 @@ void BlockFormattingContext::compute_height(Box& box)
void BlockFormattingContext::layout_inline_children(LayoutMode layout_mode)
{
- InlineFormattingContext context(context_box());
+ InlineFormattingContext context(context_box(), this);
context.run(layout_mode);
}
diff --git a/Libraries/LibWeb/Layout/BlockFormattingContext.h b/Libraries/LibWeb/Layout/BlockFormattingContext.h
index 6b58129899..dbbbbe5caf 100644
--- a/Libraries/LibWeb/Layout/BlockFormattingContext.h
+++ b/Libraries/LibWeb/Layout/BlockFormattingContext.h
@@ -33,7 +33,7 @@ namespace Web::Layout {
class BlockFormattingContext : public FormattingContext {
public:
- explicit BlockFormattingContext(Box& containing_block);
+ explicit BlockFormattingContext(Box&, FormattingContext* parent);
~BlockFormattingContext();
virtual void run(LayoutMode) override;
diff --git a/Libraries/LibWeb/Layout/FormattingContext.cpp b/Libraries/LibWeb/Layout/FormattingContext.cpp
index 05059e90b7..670191f41f 100644
--- a/Libraries/LibWeb/Layout/FormattingContext.cpp
+++ b/Libraries/LibWeb/Layout/FormattingContext.cpp
@@ -32,8 +32,9 @@
namespace Web::Layout {
-FormattingContext::FormattingContext(Box& context_box)
- : m_context_box(context_box)
+FormattingContext::FormattingContext(Box& context_box, FormattingContext* parent)
+ : m_parent(parent)
+ , m_context_box(context_box)
{
}
@@ -44,13 +45,13 @@ FormattingContext::~FormattingContext()
void FormattingContext::layout_inside(Box& box, LayoutMode layout_mode)
{
if (box.is_table()) {
- TableFormattingContext context(box);
+ TableFormattingContext context(box, this);
context.run(layout_mode);
} else if (box.children_are_inline()) {
- InlineFormattingContext context(box);
+ InlineFormattingContext context(box, this);
context.run(layout_mode);
} else {
- BlockFormattingContext context(box);
+ BlockFormattingContext context(box, this);
context.run(layout_mode);
}
}
diff --git a/Libraries/LibWeb/Layout/FormattingContext.h b/Libraries/LibWeb/Layout/FormattingContext.h
index 8885fb3ba2..c8f7487dc2 100644
--- a/Libraries/LibWeb/Layout/FormattingContext.h
+++ b/Libraries/LibWeb/Layout/FormattingContext.h
@@ -37,11 +37,14 @@ public:
Box& context_box() { 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:
- FormattingContext(Box&);
+ FormattingContext(Box&, FormattingContext* parent = nullptr);
virtual ~FormattingContext();
- static void layout_inside(Box&, LayoutMode);
+ void layout_inside(Box&, LayoutMode);
struct ShrinkToFitResult {
float preferred_width { 0 };
@@ -50,6 +53,7 @@ protected:
ShrinkToFitResult calculate_shrink_to_fit_widths(Box&);
+ FormattingContext* m_parent { nullptr };
Box& m_context_box;
};
diff --git a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
index 55219cbb1d..d06f82aec6 100644
--- a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
+++ b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp
@@ -28,6 +28,7 @@
#include <LibWeb/DOM/Node.h>
#include <LibWeb/Dump.h>
#include <LibWeb/Layout/BlockBox.h>
+#include <LibWeb/Layout/BlockFormattingContext.h>
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Layout/InlineFormattingContext.h>
#include <LibWeb/Layout/InlineNode.h>
@@ -35,8 +36,8 @@
namespace Web::Layout {
-InlineFormattingContext::InlineFormattingContext(Box& containing_block)
- : FormattingContext(containing_block)
+InlineFormattingContext::InlineFormattingContext(Box& containing_block, FormattingContext* parent)
+ : 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));
}
- FormattingContext::layout_inside(inline_block, layout_mode);
+ layout_inside(inline_block, layout_mode);
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.
diff --git a/Libraries/LibWeb/Layout/InlineFormattingContext.h b/Libraries/LibWeb/Layout/InlineFormattingContext.h
index 8c23a7f256..2cc6c5f88f 100644
--- a/Libraries/LibWeb/Layout/InlineFormattingContext.h
+++ b/Libraries/LibWeb/Layout/InlineFormattingContext.h
@@ -33,7 +33,7 @@ namespace Web::Layout {
class InlineFormattingContext final : public FormattingContext {
public:
- InlineFormattingContext(Box& containing_block);
+ InlineFormattingContext(Box& containing_block, FormattingContext* parent);
~InlineFormattingContext();
virtual void run(LayoutMode) override;
diff --git a/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Libraries/LibWeb/Layout/TableFormattingContext.cpp
index 71f85eb0ad..b448ad5bf6 100644
--- a/Libraries/LibWeb/Layout/TableFormattingContext.cpp
+++ b/Libraries/LibWeb/Layout/TableFormattingContext.cpp
@@ -38,8 +38,8 @@
namespace Web::Layout {
-TableFormattingContext::TableFormattingContext(Box& context_box)
- : BlockFormattingContext(context_box)
+TableFormattingContext::TableFormattingContext(Box& context_box, FormattingContext* parent)
+ : BlockFormattingContext(context_box, parent)
{
}
diff --git a/Libraries/LibWeb/Layout/TableFormattingContext.h b/Libraries/LibWeb/Layout/TableFormattingContext.h
index f5a5cda164..5419b437a9 100644
--- a/Libraries/LibWeb/Layout/TableFormattingContext.h
+++ b/Libraries/LibWeb/Layout/TableFormattingContext.h
@@ -33,7 +33,7 @@ namespace Web::Layout {
class TableFormattingContext final : public BlockFormattingContext {
public:
- explicit TableFormattingContext(Box& containing_block);
+ explicit TableFormattingContext(Box&, FormattingContext* parent);
~TableFormattingContext();
virtual void run(LayoutMode) override;