1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:27:34 +00:00

LibWeb: Rename Layout::InitialContainingBlock to Layout::Viewport

The name "initial containing block" was wrong for this, as it doesn't
correspond to the HTML element, and that's specifically what it's
supposed to do! :^)
This commit is contained in:
Andreas Kling 2023-02-25 11:04:29 +01:00
parent 60f699338d
commit 7e76a51cb0
66 changed files with 121 additions and 128 deletions

View file

@ -12,7 +12,6 @@
#include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Layout/BlockFormattingContext.h>
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/InlineFormattingContext.h>
#include <LibWeb/Layout/LineBuilder.h>
#include <LibWeb/Layout/ListItemBox.h>
@ -20,6 +19,7 @@
#include <LibWeb/Layout/ReplacedBox.h>
#include <LibWeb/Layout/TableBox.h>
#include <LibWeb/Layout/TableWrapper.h>
#include <LibWeb/Layout/Viewport.h>
namespace Web::Layout {
@ -38,11 +38,6 @@ BlockFormattingContext::~BlockFormattingContext()
}
}
bool BlockFormattingContext::is_initial() const
{
return is<InitialContainingBlock>(root());
}
CSSPixels BlockFormattingContext::automatic_content_height() const
{
return compute_auto_height_for_block_formatting_context_root(root());
@ -50,8 +45,8 @@ CSSPixels BlockFormattingContext::automatic_content_height() const
void BlockFormattingContext::run(Box const&, LayoutMode layout_mode, AvailableSpace const& available_space)
{
if (is_initial()) {
layout_initial_containing_block(layout_mode, available_space);
if (is<Viewport>(root())) {
layout_viewport(layout_mode, available_space);
return;
}
@ -696,12 +691,12 @@ static void measure_scrollable_overflow(LayoutState const& state, Box const& box
});
}
void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_mode, AvailableSpace const& available_space)
void BlockFormattingContext::layout_viewport(LayoutMode layout_mode, AvailableSpace const& available_space)
{
auto viewport_rect = root().browsing_context().viewport_rect();
auto& icb = verify_cast<Layout::InitialContainingBlock>(root());
auto& icb_state = m_state.get_mutable(icb);
auto& viewport = verify_cast<Layout::Viewport>(root());
auto& viewport_state = m_state.get_mutable(viewport);
if (root().children_are_inline())
layout_inline_children(root(), layout_mode, available_space);
@ -710,11 +705,11 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m
CSSPixels bottom_edge = 0;
CSSPixels right_edge = 0;
measure_scrollable_overflow(m_state, icb, bottom_edge, right_edge);
measure_scrollable_overflow(m_state, viewport, bottom_edge, right_edge);
if (bottom_edge >= viewport_rect.height() || right_edge >= viewport_rect.width()) {
// FIXME: Move overflow data to LayoutState!
auto& overflow_data = icb_state.ensure_overflow_data();
auto& overflow_data = viewport_state.ensure_overflow_data();
overflow_data.scrollable_overflow_rect = viewport_rect;
// NOTE: The edges are *within* the rectangle, so we add 1 to get the width and height.
overflow_data.scrollable_overflow_rect.set_size(right_edge + 1, bottom_edge + 1);

View file

@ -24,8 +24,6 @@ public:
virtual void run(Box const&, LayoutMode, AvailableSpace const&) override;
virtual CSSPixels automatic_content_height() const override;
bool is_initial() const;
auto const& left_side_floats() const { return m_left_floats; }
auto const& right_side_floats() const { return m_right_floats; }
@ -61,7 +59,7 @@ private:
CSSPixels compute_width_for_table_wrapper(Box const&, AvailableSpace const&);
void layout_initial_containing_block(LayoutMode, AvailableSpace const&);
void layout_viewport(LayoutMode, AvailableSpace const&);
void layout_block_level_children(BlockContainer const&, LayoutMode, AvailableSpace const&);
void layout_inline_children(BlockContainer const&, LayoutMode, AvailableSpace const&);

View file

@ -13,9 +13,9 @@
#include <LibWeb/Layout/BlockFormattingContext.h>
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Layout/FlexFormattingContext.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/ReplacedBox.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Layout/Viewport.h>
namespace Web::Layout {

View file

@ -10,13 +10,13 @@
#include <LibWeb/Layout/FlexFormattingContext.h>
#include <LibWeb/Layout/FormattingContext.h>
#include <LibWeb/Layout/GridFormattingContext.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/ReplacedBox.h>
#include <LibWeb/Layout/SVGFormattingContext.h>
#include <LibWeb/Layout/SVGSVGBox.h>
#include <LibWeb/Layout/TableBox.h>
#include <LibWeb/Layout/TableCellBox.h>
#include <LibWeb/Layout/TableFormattingContext.h>
#include <LibWeb/Layout/Viewport.h>
namespace Web::Layout {

View file

@ -7,7 +7,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/Layout/FrameBox.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Painting/NestedBrowsingContextPaintable.h>
namespace Web::Layout {

View file

@ -7,10 +7,10 @@
#include <LibGUI/Event.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/Label.h>
#include <LibWeb/Layout/LabelableNode.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Painting/LabelablePaintable.h>
namespace Web::Layout {

View file

@ -26,7 +26,7 @@ LayoutState::UsedValues& LayoutState::get_mutable(NodeWithStyleAndBoxModelMetric
}
}
auto const* containing_block_used_values = box.is_initial_containing_block_box() ? nullptr : &get(*box.containing_block());
auto const* containing_block_used_values = box.is_viewport() ? nullptr : &get(*box.containing_block());
used_values_per_layout_node[serial_id] = adopt_own(*new UsedValues);
used_values_per_layout_node[serial_id]->set_node(const_cast<NodeWithStyleAndBoxModelMetrics&>(box), containing_block_used_values);
@ -44,7 +44,7 @@ LayoutState::UsedValues const& LayoutState::get(NodeWithStyleAndBoxModelMetrics
return *ancestor->used_values_per_layout_node[serial_id];
}
auto const* containing_block_used_values = box.is_initial_containing_block_box() ? nullptr : &get(*box.containing_block());
auto const* containing_block_used_values = box.is_viewport() ? nullptr : &get(*box.containing_block());
const_cast<LayoutState*>(this)->used_values_per_layout_node[serial_id] = adopt_own(*new UsedValues);
const_cast<LayoutState*>(this)->used_values_per_layout_node[serial_id]->set_node(const_cast<NodeWithStyleAndBoxModelMetrics&>(box), containing_block_used_values);

View file

@ -6,10 +6,10 @@
#include <AK/Utf8View.h>
#include <LibWeb/DOM/Range.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/LayoutState.h>
#include <LibWeb/Layout/LineBoxFragment.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Layout/Viewport.h>
#include <ctype.h>
namespace Web::Layout {

View file

@ -11,10 +11,10 @@
#include <LibWeb/HTML/HTMLHtmlElement.h>
#include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Layout/FormattingContext.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Layout/TableBox.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Platform/FontPlugin.h>
namespace Web::Layout {
@ -62,7 +62,7 @@ bool Node::can_contain_boxes_with_position_absolute() const
if (computed_values().position() != CSS::Position::Static)
return true;
if (is<InitialContainingBlock>(*this))
if (is<Viewport>(*this))
return true;
// https://w3c.github.io/csswg-drafts/css-transforms-1/#propdef-transform
@ -163,13 +163,13 @@ HTML::BrowsingContext& Node::browsing_context()
return *m_browsing_context;
}
InitialContainingBlock const& Node::root() const
Viewport const& Node::root() const
{
VERIFY(document().layout_node());
return *document().layout_node();
}
InitialContainingBlock& Node::root()
Viewport& Node::root()
{
VERIFY(document().layout_node());
return *document().layout_node();

View file

@ -62,8 +62,8 @@ public:
HTML::BrowsingContext const& browsing_context() const;
HTML::BrowsingContext& browsing_context();
InitialContainingBlock const& root() const;
InitialContainingBlock& root();
Viewport const& root() const;
Viewport& root();
bool is_root_element() const;
@ -86,7 +86,7 @@ public:
virtual bool is_block_container() const { return false; }
virtual bool is_break_node() const { return false; }
virtual bool is_text_node() const { return false; }
virtual bool is_initial_containing_block_box() const { return false; }
virtual bool is_viewport() const { return false; }
virtual bool is_svg_box() const { return false; }
virtual bool is_svg_geometry_box() const { return false; }
virtual bool is_label() const { return false; }

View file

@ -16,7 +16,6 @@
#include <LibWeb/Dump.h>
#include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/HTML/HTMLProgressElement.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/ListItemBox.h>
#include <LibWeb/Layout/ListItemMarkerBox.h>
#include <LibWeb/Layout/Node.h>
@ -27,6 +26,7 @@
#include <LibWeb/Layout/TableWrapper.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Layout/TreeBuilder.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/SVG/SVGForeignObjectElement.h>
namespace Web::Layout {
@ -219,7 +219,7 @@ ErrorOr<void> TreeBuilder::create_layout_tree(DOM::Node& dom_node, TreeBuilder::
} else if (is<DOM::Document>(dom_node)) {
style = style_computer.create_document_style();
display = style->display();
layout_node = document.heap().allocate_without_realm<Layout::InitialContainingBlock>(static_cast<DOM::Document&>(dom_node), *style);
layout_node = document.heap().allocate_without_realm<Layout::Viewport>(static_cast<DOM::Document&>(dom_node), *style);
} else if (is<DOM::Text>(dom_node)) {
layout_node = document.heap().allocate_without_realm<Layout::TextNode>(document, static_cast<DOM::Text&>(dom_node));
display = CSS::Display(CSS::Display::Outside::Inline, CSS::Display::Inside::Flow);

View file

@ -1,37 +1,37 @@
/*
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/DOM/Range.h>
#include <LibWeb/Dump.h>
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Painting/StackingContext.h>
namespace Web::Layout {
InitialContainingBlock::InitialContainingBlock(DOM::Document& document, NonnullRefPtr<CSS::StyleProperties> style)
Viewport::Viewport(DOM::Document& document, NonnullRefPtr<CSS::StyleProperties> style)
: BlockContainer(document, &document, move(style))
{
}
InitialContainingBlock::~InitialContainingBlock() = default;
Viewport::~Viewport() = default;
JS::GCPtr<Selection::Selection> InitialContainingBlock::selection() const
JS::GCPtr<Selection::Selection> Viewport::selection() const
{
return const_cast<DOM::Document&>(document()).get_selection();
}
void InitialContainingBlock::build_stacking_context_tree_if_needed()
void Viewport::build_stacking_context_tree_if_needed()
{
if (paint_box()->stacking_context())
return;
build_stacking_context_tree();
}
void InitialContainingBlock::build_stacking_context_tree()
void Viewport::build_stacking_context_tree()
{
const_cast<Painting::PaintableWithLines*>(paint_box())->set_stacking_context(make<Painting::StackingContext>(*this, nullptr));
@ -52,7 +52,7 @@ void InitialContainingBlock::build_stacking_context_tree()
const_cast<Painting::PaintableWithLines*>(paint_box())->stacking_context()->sort();
}
void InitialContainingBlock::paint_all_phases(PaintContext& context)
void Viewport::paint_all_phases(PaintContext& context)
{
build_stacking_context_tree_if_needed();
context.painter().fill_rect(context.enclosing_device_rect(paint_box()->absolute_rect()).to_type<int>(), document().background_color(context.palette()));
@ -60,7 +60,7 @@ void InitialContainingBlock::paint_all_phases(PaintContext& context)
paint_box()->stacking_context()->paint(context);
}
void InitialContainingBlock::recompute_selection_states()
void Viewport::recompute_selection_states()
{
// 1. Start by resetting the selection state of all layout nodes to None.
for_each_in_inclusive_subtree([&](auto& layout_node) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -12,12 +12,12 @@
namespace Web::Layout {
class InitialContainingBlock final : public BlockContainer {
JS_CELL(InitialContainingBlock, BlockContainer);
class Viewport final : public BlockContainer {
JS_CELL(Viewport, BlockContainer);
public:
explicit InitialContainingBlock(DOM::Document&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~InitialContainingBlock() override;
explicit Viewport(DOM::Document&, NonnullRefPtr<CSS::StyleProperties>);
virtual ~Viewport() override;
const DOM::Document& dom_node() const { return static_cast<const DOM::Document&>(*Node::dom_node()); }
@ -30,10 +30,10 @@ public:
private:
void build_stacking_context_tree();
virtual bool is_initial_containing_block_box() const override { return true; }
virtual bool is_viewport() const override { return true; }
};
template<>
inline bool Node::fast_is<InitialContainingBlock>() const { return is_initial_containing_block_box(); }
inline bool Node::fast_is<Viewport>() const { return is_viewport(); }
}