Skip to content

Commit c4826ea

Browse files
committed
LibWeb: Rename Layout::BlockBox => BlockContainer
There's a subtle difference here. A "block box" in the spec is a block-level box, while a "block container" is a box whose children are either all inline-level boxes in an IFC, or all block-level boxes participating in a BFC. Notably, an "inline-block" box is a "block container" but not a "block box" since it is itself inline-level.
1 parent 5408913 commit c4826ea

38 files changed

+95
-94
lines changed

Userland/Applications/Browser/Tab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <LibGUI/Window.h>
3131
#include <LibJS/Interpreter.h>
3232
#include <LibWeb/HTML/SyntaxHighlighter/SyntaxHighlighter.h>
33-
#include <LibWeb/Layout/BlockBox.h>
33+
#include <LibWeb/Layout/BlockContainer.h>
3434
#include <LibWeb/Layout/InitialContainingBlock.h>
3535
#include <LibWeb/Loader/ResourceLoader.h>
3636
#include <LibWeb/OutOfProcessWebView.h>

Userland/Libraries/LibWeb/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ set(SOURCES
183183
HTML/WebSocket.cpp
184184
HighResolutionTime/Performance.cpp
185185
InProcessWebView.cpp
186-
Layout/BlockBox.cpp
186+
Layout/BlockContainer.cpp
187187
Layout/BlockFormattingContext.cpp
188188
Layout/Box.cpp
189189
Layout/BoxModelMetrics.cpp

Userland/Libraries/LibWeb/CSS/StyleProperties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <LibGfx/FontDatabase.h>
1111
#include <LibWeb/CSS/StyleProperties.h>
1212
#include <LibWeb/FontCache.h>
13-
#include <LibWeb/Layout/BlockBox.h>
13+
#include <LibWeb/Layout/BlockContainer.h>
1414
#include <LibWeb/Layout/Node.h>
1515

1616
namespace Web::CSS {

Userland/Libraries/LibWeb/DOM/Element.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <LibWeb/Geometry/DOMRect.h>
2323
#include <LibWeb/HTML/EventLoop/EventLoop.h>
2424
#include <LibWeb/HTML/Parser/HTMLParser.h>
25-
#include <LibWeb/Layout/BlockBox.h>
25+
#include <LibWeb/Layout/BlockContainer.h>
2626
#include <LibWeb/Layout/InlineNode.h>
2727
#include <LibWeb/Layout/ListItemBox.h>
2828
#include <LibWeb/Layout/TableBox.h>
@@ -133,12 +133,12 @@ RefPtr<Layout::Node> Element::create_layout_node()
133133

134134
if (display.is_table_column() || display.is_table_column_group() || display.is_table_caption()) {
135135
// FIXME: This is just an incorrect placeholder until we improve table layout support.
136-
return adopt_ref(*new Layout::BlockBox(document(), this, move(style)));
136+
return adopt_ref(*new Layout::BlockContainer(document(), this, move(style)));
137137
}
138138

139139
if (display.is_inline_outside()) {
140140
if (display.is_flow_root_inside()) {
141-
auto block = adopt_ref(*new Layout::BlockBox(document(), this, move(style)));
141+
auto block = adopt_ref(*new Layout::BlockContainer(document(), this, move(style)));
142142
block->set_inline(true);
143143
return block;
144144
}
@@ -149,7 +149,7 @@ RefPtr<Layout::Node> Element::create_layout_node()
149149
}
150150

151151
if (display.is_flow_inside() || display.is_flow_root_inside() || display.is_flex_inside())
152-
return adopt_ref(*new Layout::BlockBox(document(), this, move(style)));
152+
return adopt_ref(*new Layout::BlockContainer(document(), this, move(style)));
153153

154154
TODO();
155155
}

Userland/Libraries/LibWeb/DOM/ShadowRoot.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <LibWeb/DOM/Event.h>
99
#include <LibWeb/DOM/ShadowRoot.h>
1010
#include <LibWeb/DOMParsing/InnerHTML.h>
11-
#include <LibWeb/Layout/BlockBox.h>
11+
#include <LibWeb/Layout/BlockContainer.h>
1212

1313
namespace Web::DOM {
1414

@@ -32,7 +32,7 @@ EventTarget* ShadowRoot::get_parent(const Event& event)
3232

3333
RefPtr<Layout::Node> ShadowRoot::create_layout_node()
3434
{
35-
return adopt_ref(*new Layout::BlockBox(document(), this, CSS::ComputedValues {}));
35+
return adopt_ref(*new Layout::BlockContainer(document(), this, CSS::ComputedValues {}));
3636
}
3737

3838
// https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml

Userland/Libraries/LibWeb/Dump.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <LibWeb/DOM/Text.h>
2222
#include <LibWeb/Dump.h>
2323
#include <LibWeb/HTML/HTMLTemplateElement.h>
24-
#include <LibWeb/Layout/BlockBox.h>
24+
#include <LibWeb/Layout/BlockContainer.h>
2525
#include <LibWeb/Layout/Node.h>
2626
#include <LibWeb/Layout/SVGBox.h>
2727
#include <LibWeb/Layout/TextNode.h>
@@ -206,8 +206,8 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
206206
builder.append("\n");
207207
}
208208

209-
if (is<Layout::BlockBox>(layout_node) && static_cast<Layout::BlockBox const&>(layout_node).children_are_inline()) {
210-
auto& block = static_cast<Layout::BlockBox const&>(layout_node);
209+
if (is<Layout::BlockContainer>(layout_node) && static_cast<Layout::BlockContainer const&>(layout_node).children_are_inline()) {
210+
auto& block = static_cast<Layout::BlockContainer const&>(layout_node);
211211
for (size_t line_box_index = 0; line_box_index < block.line_boxes().size(); ++line_box_index) {
212212
auto& line_box = block.line_boxes()[line_box_index];
213213
for (size_t i = 0; i < indent; ++i)

Userland/Libraries/LibWeb/Forward.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class SVGSVGElement;
219219
namespace Web::Layout {
220220
enum class LayoutMode;
221221
enum class PaintPhase;
222-
class BlockBox;
222+
class BlockContainer;
223223
class BlockFormattingContext;
224224
class Box;
225225
class ButtonBox;

Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <LibWeb/HTML/EventNames.h>
1212
#include <LibWeb/HTML/HTMLFormElement.h>
1313
#include <LibWeb/HTML/HTMLInputElement.h>
14-
#include <LibWeb/Layout/BlockBox.h>
14+
#include <LibWeb/Layout/BlockContainer.h>
1515
#include <LibWeb/Layout/ButtonBox.h>
1616
#include <LibWeb/Layout/CheckBox.h>
1717
#include <LibWeb/Layout/RadioButton.h>
@@ -60,7 +60,7 @@ RefPtr<Layout::Node> HTMLInputElement::create_layout_node()
6060
return adopt_ref(*new Layout::RadioButton(document(), *this, move(style)));
6161

6262
create_shadow_tree_if_needed();
63-
auto layout_node = adopt_ref(*new Layout::BlockBox(document(), this, move(style)));
63+
auto layout_node = adopt_ref(*new Layout::BlockContainer(document(), this, move(style)));
6464
layout_node->set_inline(true);
6565
return layout_node;
6666
}

Userland/Libraries/LibWeb/Layout/BlockBox.cpp renamed to Userland/Libraries/LibWeb/Layout/BlockContainer.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
/*
2-
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
2+
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
33
*
44
* SPDX-License-Identifier: BSD-2-Clause
55
*/
66

77
#include <LibGfx/Painter.h>
88
#include <LibWeb/Dump.h>
9-
#include <LibWeb/Layout/BlockBox.h>
9+
#include <LibWeb/Layout/BlockContainer.h>
1010
#include <LibWeb/Layout/InitialContainingBlock.h>
1111
#include <LibWeb/Layout/InlineFormattingContext.h>
1212
#include <LibWeb/Layout/ReplacedBox.h>
1313
#include <LibWeb/Layout/TextNode.h>
1414

1515
namespace Web::Layout {
1616

17-
BlockBox::BlockBox(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
17+
BlockContainer::BlockContainer(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
1818
: Box(document, node, move(style))
1919
{
2020
}
2121

22-
BlockBox::BlockBox(DOM::Document& document, DOM::Node* node, CSS::ComputedValues computed_values)
22+
BlockContainer::BlockContainer(DOM::Document& document, DOM::Node* node, CSS::ComputedValues computed_values)
2323
: Box(document, node, move(computed_values))
2424
{
2525
}
2626

27-
BlockBox::~BlockBox()
27+
BlockContainer::~BlockContainer()
2828
{
2929
}
3030

31-
bool BlockBox::should_clip_overflow() const
31+
bool BlockContainer::should_clip_overflow() const
3232
{
3333
return computed_values().overflow_x() != CSS::Overflow::Visible && computed_values().overflow_y() != CSS::Overflow::Visible;
3434
}
3535

36-
void BlockBox::paint(PaintContext& context, PaintPhase phase)
36+
void BlockContainer::paint(PaintContext& context, PaintPhase phase)
3737
{
3838
if (!is_visible())
3939
return;
@@ -79,7 +79,7 @@ void BlockBox::paint(PaintContext& context, PaintPhase phase)
7979
}
8080
}
8181

82-
HitTestResult BlockBox::hit_test(const Gfx::IntPoint& position, HitTestType type) const
82+
HitTestResult BlockContainer::hit_test(const Gfx::IntPoint& position, HitTestType type) const
8383
{
8484
if (!children_are_inline())
8585
return Box::hit_test(position, type);
@@ -90,8 +90,8 @@ HitTestResult BlockBox::hit_test(const Gfx::IntPoint& position, HitTestType type
9090
if (is<Box>(fragment.layout_node()) && verify_cast<Box>(fragment.layout_node()).stacking_context())
9191
continue;
9292
if (enclosing_int_rect(fragment.absolute_rect()).contains(position)) {
93-
if (is<BlockBox>(fragment.layout_node()))
94-
return verify_cast<BlockBox>(fragment.layout_node()).hit_test(position, type);
93+
if (is<BlockContainer>(fragment.layout_node()))
94+
return verify_cast<BlockContainer>(fragment.layout_node()).hit_test(position, type);
9595
return { fragment.layout_node(), fragment.text_index_at(position.x()) };
9696
}
9797
if (fragment.absolute_rect().top() <= position.y())
@@ -104,7 +104,7 @@ HitTestResult BlockBox::hit_test(const Gfx::IntPoint& position, HitTestType type
104104
return { absolute_rect().contains(position.x(), position.y()) ? this : nullptr };
105105
}
106106

107-
void BlockBox::split_into_lines(InlineFormattingContext& context, LayoutMode layout_mode)
107+
void BlockContainer::split_into_lines(InlineFormattingContext& context, LayoutMode layout_mode)
108108
{
109109
auto& containing_block = context.containing_block();
110110
auto* line_box = &containing_block.ensure_last_line_box();
@@ -121,13 +121,13 @@ void BlockBox::split_into_lines(InlineFormattingContext& context, LayoutMode lay
121121
line_box->add_fragment(*this, 0, 0, border_box_width(), height());
122122
}
123123

124-
bool BlockBox::is_scrollable() const
124+
bool BlockContainer::is_scrollable() const
125125
{
126126
// FIXME: Support horizontal scroll as well (overflow-x)
127127
return computed_values().overflow_y() == CSS::Overflow::Scroll;
128128
}
129129

130-
void BlockBox::set_scroll_offset(const Gfx::FloatPoint& offset)
130+
void BlockContainer::set_scroll_offset(const Gfx::FloatPoint& offset)
131131
{
132132
// FIXME: If there is horizontal and vertical scroll ignore only part of the new offset
133133
if (offset.y() < 0 || m_scroll_offset == offset)
@@ -136,7 +136,7 @@ void BlockBox::set_scroll_offset(const Gfx::FloatPoint& offset)
136136
set_needs_display();
137137
}
138138

139-
bool BlockBox::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned int, unsigned int, int wheel_delta)
139+
bool BlockContainer::handle_mousewheel(Badge<EventHandler>, const Gfx::IntPoint&, unsigned int, unsigned int, int wheel_delta)
140140
{
141141
if (!is_scrollable())
142142
return false;

Userland/Libraries/LibWeb/Layout/BlockBox.h renamed to Userland/Libraries/LibWeb/Layout/BlockContainer.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
2+
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
33
*
44
* SPDX-License-Identifier: BSD-2-Clause
55
*/
@@ -11,20 +11,21 @@
1111

1212
namespace Web::Layout {
1313

14-
class BlockBox : public Box {
14+
// https://drafts.csswg.org/css-display/#block-container
15+
class BlockContainer : public Box {
1516
public:
16-
BlockBox(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
17-
BlockBox(DOM::Document&, DOM::Node*, CSS::ComputedValues);
18-
virtual ~BlockBox() override;
17+
BlockContainer(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
18+
BlockContainer(DOM::Document&, DOM::Node*, CSS::ComputedValues);
19+
virtual ~BlockContainer() override;
1920

2021
virtual void paint(PaintContext&, PaintPhase) override;
2122

2223
virtual HitTestResult hit_test(const Gfx::IntPoint&, HitTestType) const override;
2324

24-
BlockBox* previous_sibling() { return verify_cast<BlockBox>(Node::previous_sibling()); }
25-
const BlockBox* previous_sibling() const { return verify_cast<BlockBox>(Node::previous_sibling()); }
26-
BlockBox* next_sibling() { return verify_cast<BlockBox>(Node::next_sibling()); }
27-
const BlockBox* next_sibling() const { return verify_cast<BlockBox>(Node::next_sibling()); }
25+
BlockContainer* previous_sibling() { return verify_cast<BlockContainer>(Node::previous_sibling()); }
26+
const BlockContainer* previous_sibling() const { return verify_cast<BlockContainer>(Node::previous_sibling()); }
27+
BlockContainer* next_sibling() { return verify_cast<BlockContainer>(Node::next_sibling()); }
28+
const BlockContainer* next_sibling() const { return verify_cast<BlockContainer>(Node::next_sibling()); }
2829

2930
template<typename Callback>
3031
void for_each_fragment(Callback);
@@ -48,10 +49,10 @@ class BlockBox : public Box {
4849
};
4950

5051
template<>
51-
inline bool Node::fast_is<BlockBox>() const { return is_block_box(); }
52+
inline bool Node::fast_is<BlockContainer>() const { return is_block_box(); }
5253

5354
template<typename Callback>
54-
void BlockBox::for_each_fragment(Callback callback)
55+
void BlockContainer::for_each_fragment(Callback callback)
5556
{
5657
for (auto& line_box : line_boxes()) {
5758
for (auto& fragment : line_box.fragments()) {
@@ -62,7 +63,7 @@ void BlockBox::for_each_fragment(Callback callback)
6263
}
6364

6465
template<typename Callback>
65-
void BlockBox::for_each_fragment(Callback callback) const
66+
void BlockContainer::for_each_fragment(Callback callback) const
6667
{
6768
for (auto& line_box : line_boxes()) {
6869
for (auto& fragment : line_box.fragments()) {

0 commit comments

Comments
 (0)