diff options
author | Andreas Kling <kling@serenityos.org> | 2022-07-16 23:30:32 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-07-17 14:11:36 +0200 |
commit | 52862c72d00e50ae51197e18917b1950643b5f08 (patch) | |
tree | db3c71b6de5714ea8341ef9064dcbf5491040fa9 /Userland/Libraries | |
parent | 0d8f9019c8d464bddddc627becb2f809e21b12d7 (diff) | |
download | serenity-52862c72d00e50ae51197e18917b1950643b5f08.zip |
LibWeb: Rename FormattingState to LayoutState
This seems a bit more descriptive (and also a bit shorter).
Diffstat (limited to 'Userland/Libraries')
24 files changed, 94 insertions, 94 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 28da303ba3..6beb42d3e8 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -257,7 +257,6 @@ set(SOURCES Layout/CheckBox.cpp Layout/FlexFormattingContext.cpp Layout/FormattingContext.cpp - Layout/FormattingState.cpp Layout/FrameBox.cpp Layout/ImageBox.cpp Layout/InitialContainingBlock.cpp @@ -267,6 +266,7 @@ set(SOURCES Layout/Label.cpp Layout/LabelableNode.cpp Layout/LayoutPosition.cpp + Layout/LayoutState.cpp Layout/LineBox.cpp Layout/LineBoxFragment.cpp Layout/LineBuilder.cpp diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index fb7f3beec9..488899715e 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -614,7 +614,7 @@ void Document::update_layout() m_layout_root = static_ptr_cast<Layout::InitialContainingBlock>(tree_builder.build(*this)); } - Layout::FormattingState formatting_state; + Layout::LayoutState formatting_state; formatting_state.nodes.resize(layout_node_count()); Layout::BlockFormattingContext root_formatting_context(formatting_state, *m_layout_root, nullptr); diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 40a24448bc..6309c66de0 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -371,7 +371,7 @@ class ButtonBox; class CheckBox; class FlexFormattingContext; class FormattingContext; -struct FormattingState; +struct LayoutState; class InitialContainingBlock; class InlineFormattingContext; class Label; diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 3a789ff3e6..184e266dce 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -19,7 +19,7 @@ namespace Web::Layout { -BlockFormattingContext::BlockFormattingContext(FormattingState& state, BlockContainer const& root, FormattingContext* parent) +BlockFormattingContext::BlockFormattingContext(LayoutState& state, BlockContainer const& root, FormattingContext* parent) : FormattingContext(Type::Block, state, root, parent) { } @@ -308,7 +308,7 @@ void BlockFormattingContext::compute_width_for_block_level_replaced_element_in_n m_state.get_mutable(box).content_width = compute_width_for_replaced_element(m_state, box); } -float BlockFormattingContext::compute_theoretical_height(FormattingState const& state, Box const& box) +float BlockFormattingContext::compute_theoretical_height(LayoutState const& state, Box const& box) { auto const& computed_values = box.computed_values(); auto const& containing_block = *box.containing_block(); @@ -342,7 +342,7 @@ float BlockFormattingContext::compute_theoretical_height(FormattingState const& return height; } -void BlockFormattingContext::compute_height(Box const& box, FormattingState& state) +void BlockFormattingContext::compute_height(Box const& box, LayoutState& state) { auto const& computed_values = box.computed_values(); auto width_of_containing_block_as_length = CSS::Length::make_px(containing_block_width_for(box, state)); @@ -609,7 +609,7 @@ void BlockFormattingContext::place_block_level_element_in_normal_flow_horizontal box_state.offset = Gfx::FloatPoint { x, box_state.offset.y() }; } -static void measure_scrollable_overflow(FormattingState const& state, Box const& box, float& bottom_edge, float& right_edge) +static void measure_scrollable_overflow(LayoutState const& state, Box const& box, float& bottom_edge, float& right_edge) { auto const& child_state = state.get(box); auto child_rect = absolute_content_rect(box, state); @@ -644,7 +644,7 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m measure_scrollable_overflow(m_state, icb, bottom_edge, right_edge); if (bottom_edge >= viewport_rect.height() || right_edge >= viewport_rect.width()) { - // FIXME: Move overflow data to FormattingState! + // FIXME: Move overflow data to LayoutState! auto& overflow_data = icb_state.ensure_overflow_data(); overflow_data.scrollable_overflow_rect = viewport_rect.to_type<float>(); // NOTE: The edges are *within* the rectangle, so we add 1 to get the width and height. diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h index d91dc51211..5111635142 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h @@ -18,7 +18,7 @@ class LineBuilder; // https://www.w3.org/TR/css-display/#block-formatting-context class BlockFormattingContext : public FormattingContext { public: - explicit BlockFormattingContext(FormattingState&, BlockContainer const&, FormattingContext* parent); + explicit BlockFormattingContext(LayoutState&, BlockContainer const&, FormattingContext* parent); ~BlockFormattingContext(); virtual void run(Box const&, LayoutMode) override; @@ -29,7 +29,7 @@ public: auto const& left_side_floats() const { return m_left_floats; } auto const& right_side_floats() const { return m_right_floats; } - static float compute_theoretical_height(FormattingState const&, Box const&); + static float compute_theoretical_height(LayoutState const&, Box const&); void compute_width(Box const&, LayoutMode = LayoutMode::Normal); // https://www.w3.org/TR/css-display/#block-formatting-context-root @@ -37,7 +37,7 @@ public: virtual void parent_context_did_dimension_child_root_box() override; - static void compute_height(Box const&, FormattingState&); + static void compute_height(Box const&, LayoutState&); void add_absolutely_positioned_box(Box const& box) { m_absolutely_positioned_boxes.append(box); } diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index e08a22d4a8..d159d75eac 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -27,7 +27,7 @@ template<typename T> return ::max(min, ::min(value, max)); } -static float get_pixel_size(FormattingState const& state, Box const& box, Optional<CSS::LengthPercentage> const& length_percentage) +static float get_pixel_size(LayoutState const& state, Box const& box, Optional<CSS::LengthPercentage> const& length_percentage) { if (!length_percentage.has_value()) return 0; @@ -35,7 +35,7 @@ static float get_pixel_size(FormattingState const& state, Box const& box, Option return length_percentage->resolved(box, inner_main_size).to_px(box); } -FlexFormattingContext::FlexFormattingContext(FormattingState& state, Box const& flex_container, FormattingContext* parent) +FlexFormattingContext::FlexFormattingContext(LayoutState& state, Box const& flex_container, FormattingContext* parent) : FormattingContext(Type::Flex, state, flex_container, parent) , m_flex_container_state(m_state.get_mutable(flex_container)) , m_flex_direction(flex_container.computed_values().flex_direction()) @@ -526,7 +526,7 @@ float FlexFormattingContext::calculate_indefinite_main_size(FlexItem const& item // then layout with that and see what height comes out of it. float fit_content_cross_size = calculate_fit_content_width(item.box, m_available_space->cross); - FormattingState throwaway_state(&m_state); + LayoutState throwaway_state(&m_state); auto& box_state = throwaway_state.get_mutable(item.box); // Item has definite cross size, layout with that as the used cross size. @@ -619,7 +619,7 @@ void FlexFormattingContext::determine_flex_base_size_and_hypothetical_main_size( return specified_main_size_of_child_box(child_box); // NOTE: To avoid repeated layout work, we keep a cache of flex item main sizes on the - // root FormattingState object. It's available through a full layout cycle. + // root LayoutState object. It's available through a full layout cycle. // FIXME: Make sure this cache isn't overly permissive.. auto& size_cache = m_state.m_root.flex_item_size_cache; auto it = size_cache.find(&flex_item.box); @@ -976,7 +976,7 @@ void FlexFormattingContext::determine_hypothetical_cross_size_of_item(FlexItem& if (has_definite_main_size(item.box)) { // For indefinite cross sizes, we perform a throwaway layout and then measure it. - FormattingState throwaway_state(&m_state); + LayoutState throwaway_state(&m_state); auto& box_state = throwaway_state.get_mutable(item.box); // Item has definite main size, layout with that as the used main size. diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h index 46021e522e..591af78e1d 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h @@ -13,7 +13,7 @@ namespace Web::Layout { class FlexFormattingContext final : public FormattingContext { public: - FlexFormattingContext(FormattingState&, Box const& flex_container, FormattingContext* parent); + FlexFormattingContext(LayoutState&, Box const& flex_container, FormattingContext* parent); ~FlexFormattingContext(); virtual bool inhibits_floating() const override { return true; } @@ -155,7 +155,7 @@ private: CSS::FlexBasisData used_flex_basis_for_item(FlexItem const&) const; - FormattingState::NodeState& m_flex_container_state; + LayoutState::NodeState& m_flex_container_state; Vector<FlexLine> m_flex_lines; Vector<FlexItem> m_flex_items; diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index c598fd1ef0..d207e17557 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -18,7 +18,7 @@ namespace Web::Layout { -FormattingContext::FormattingContext(Type type, FormattingState& state, Box const& context_box, FormattingContext* parent) +FormattingContext::FormattingContext(Type type, LayoutState& state, Box const& context_box, FormattingContext* parent) : m_type(type) , m_parent(parent) , m_context_box(context_box) @@ -85,7 +85,7 @@ bool FormattingContext::creates_block_formatting_context(Box const& box) return false; } -OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_context_if_needed(FormattingState& state, Box const& child_box) +OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_context_if_needed(LayoutState& state, Box const& child_box) { if (child_box.is_replaced_box() && !child_box.can_have_children()) { // NOTE: This is a bit strange. @@ -94,7 +94,7 @@ OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_conte // without having separate code to handle replaced elements. // FIXME: Find a better abstraction for this. struct ReplacedFormattingContext : public FormattingContext { - ReplacedFormattingContext(FormattingState& state, Box const& box) + ReplacedFormattingContext(LayoutState& state, Box const& box) : FormattingContext(Type::Block, state, box) { } @@ -131,7 +131,7 @@ OwnPtr<FormattingContext> FormattingContext::create_independent_formatting_conte // FIXME: Remove this once it's no longer needed. It currently swallows problem with standalone // table-related boxes that don't get fixed up by CSS anonymous table box generation. struct DummyFormattingContext : public FormattingContext { - DummyFormattingContext(FormattingState& state, Box const& box) + DummyFormattingContext(LayoutState& state, Box const& box) : FormattingContext(Type::Block, state, box) { } @@ -181,7 +181,7 @@ FormattingContext::ShrinkToFitResult FormattingContext::calculate_shrink_to_fit_ }; } -static Gfx::FloatSize solve_replaced_size_constraint(FormattingState const& state, float w, float h, ReplacedBox const& box) +static Gfx::FloatSize solve_replaced_size_constraint(LayoutState const& state, float w, float h, ReplacedBox const& box) { // 10.4 Minimum and maximum widths: 'min-width' and 'max-width' @@ -223,7 +223,7 @@ static Gfx::FloatSize solve_replaced_size_constraint(FormattingState const& stat return { w, h }; } -float FormattingContext::compute_auto_height_for_block_level_element(FormattingState const& state, Box const& box) +float FormattingContext::compute_auto_height_for_block_level_element(LayoutState const& state, Box const& box) { if (creates_block_formatting_context(box)) return compute_auto_height_for_block_formatting_context_root(state, verify_cast<BlockContainer>(box)); @@ -272,7 +272,7 @@ float FormattingContext::compute_auto_height_for_block_level_element(FormattingS } // https://www.w3.org/TR/CSS22/visudet.html#root-height -float FormattingContext::compute_auto_height_for_block_formatting_context_root(FormattingState const& state, BlockContainer const& root) +float FormattingContext::compute_auto_height_for_block_formatting_context_root(LayoutState const& state, BlockContainer const& root) { // 10.6.7 'Auto' heights for block formatting context roots Optional<float> top; @@ -335,7 +335,7 @@ float FormattingContext::compute_auto_height_for_block_formatting_context_root(F } // 10.3.2 Inline, replaced elements, https://www.w3.org/TR/CSS22/visudet.html#inline-replaced-width -float FormattingContext::tentative_width_for_replaced_element(FormattingState const& state, ReplacedBox const& box, CSS::LengthPercentage const& computed_width) +float FormattingContext::tentative_width_for_replaced_element(LayoutState const& state, ReplacedBox const& box, CSS::LengthPercentage const& computed_width) { auto const& containing_block = *box.containing_block(); auto height_of_containing_block = CSS::Length::make_px(state.get(containing_block).content_height); @@ -392,7 +392,7 @@ void FormattingContext::compute_height_for_absolutely_positioned_element(Box con compute_height_for_absolutely_positioned_non_replaced_element(box); } -float FormattingContext::compute_width_for_replaced_element(FormattingState const& state, ReplacedBox const& box) +float FormattingContext::compute_width_for_replaced_element(LayoutState const& state, ReplacedBox const& box) { // 10.3.4 Block-level, replaced elements in normal flow... // 10.3.2 Inline, replaced elements @@ -437,7 +437,7 @@ float FormattingContext::compute_width_for_replaced_element(FormattingState cons // 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, 'inline-block' replaced elements in normal flow and floating replaced elements // https://www.w3.org/TR/CSS22/visudet.html#inline-replaced-height -float FormattingContext::tentative_height_for_replaced_element(FormattingState const& state, ReplacedBox const& box, CSS::LengthPercentage const& computed_height) +float FormattingContext::tentative_height_for_replaced_element(LayoutState const& state, ReplacedBox const& box, CSS::LengthPercentage const& computed_height) { auto computed_width = box.computed_values().width(); @@ -465,7 +465,7 @@ float FormattingContext::tentative_height_for_replaced_element(FormattingState c return computed_height.resolved(box, CSS::Length::make_px(containing_block_height_for(box, state))).to_px(box); } -float FormattingContext::compute_height_for_replaced_element(FormattingState const& state, ReplacedBox const& box) +float FormattingContext::compute_height_for_replaced_element(LayoutState const& state, ReplacedBox const& box) { // 10.6.2 Inline replaced elements, block-level replaced elements in normal flow, // 'inline-block' replaced elements in normal flow and floating replaced elements @@ -845,7 +845,7 @@ float FormattingContext::calculate_fit_content_height(Layout::Box const& box, Op return calculate_fit_content_size(calculate_min_content_height(box), calculate_max_content_height(box), available_space); } -float FormattingContext::calculate_auto_height(FormattingState const& state, Box const& box) +float FormattingContext::calculate_auto_height(LayoutState const& state, Box const& box) { if (is<ReplacedBox>(box)) { return compute_height_for_replaced_element(state, verify_cast<ReplacedBox>(box)); @@ -861,11 +861,11 @@ float FormattingContext::calculate_min_content_width(Layout::Box const& box) con auto& root_state = m_state.m_root; - auto& cache = *root_state.intrinsic_sizes.ensure(&box, [] { return adopt_own(*new FormattingState::IntrinsicSizes); }); + auto& cache = *root_state.intrinsic_sizes.ensure(&box, [] { return adopt_own(*new LayoutState::IntrinsicSizes); }); if (cache.min_content_width.has_value()) return *cache.min_content_width; - FormattingState throwaway_state(&m_state); + LayoutState throwaway_state(&m_state); auto const& containing_block = *box.containing_block(); auto& containing_block_state = throwaway_state.get_mutable(containing_block); containing_block_state.content_width = 0; @@ -901,11 +901,11 @@ float FormattingContext::calculate_max_content_width(Layout::Box const& box) con auto& root_state = m_state.m_root; - auto& cache = *root_state.intrinsic_sizes.ensure(&box, [] { return adopt_own(*new FormattingState::IntrinsicSizes); }); + auto& cache = *root_state.intrinsic_sizes.ensure(&box, [] { return adopt_own(*new LayoutState::IntrinsicSizes); }); if (cache.max_content_width.has_value()) return *cache.max_content_width; - FormattingState throwaway_state(&m_state); + LayoutState throwaway_state(&m_state); auto const& containing_block = *box.containing_block(); auto& containing_block_state = throwaway_state.get_mutable(containing_block); containing_block_state.content_width = INFINITY; @@ -941,11 +941,11 @@ float FormattingContext::calculate_min_content_height(Layout::Box const& box) co auto& root_state = m_state.m_root; - auto& cache = *root_state.intrinsic_sizes.ensure(&box, [] { return adopt_own(*new FormattingState::IntrinsicSizes); }); + auto& cache = *root_state.intrinsic_sizes.ensure(&box, [] { return adopt_own(*new LayoutState::IntrinsicSizes); }); if (cache.min_content_height.has_value()) return *cache.min_content_height; - FormattingState throwaway_state(&m_state); + LayoutState throwaway_state(&m_state); auto const& containing_block = *box.containing_block(); auto& containing_block_state = throwaway_state.get_mutable(containing_block); containing_block_state.content_height = 0; @@ -981,11 +981,11 @@ float FormattingContext::calculate_max_content_height(Layout::Box const& box) co auto& root_state = m_state.m_root; - auto& cache = *root_state.intrinsic_sizes.ensure(&box, [] { return adopt_own(*new FormattingState::IntrinsicSizes); }); + auto& cache = *root_state.intrinsic_sizes.ensure(&box, [] { return adopt_own(*new LayoutState::IntrinsicSizes); }); if (cache.max_content_height.has_value()) return *cache.max_content_height; - FormattingState throwaway_state(&m_state); + LayoutState throwaway_state(&m_state); auto const& containing_block = *box.containing_block(); auto& containing_block_state = throwaway_state.get_mutable(containing_block); containing_block_state.content_height = INFINITY; @@ -1014,7 +1014,7 @@ float FormattingContext::calculate_max_content_height(Layout::Box const& box) co return *cache.max_content_height; } -float FormattingContext::containing_block_width_for(Box const& box, FormattingState const& state) +float FormattingContext::containing_block_width_for(Box const& box, LayoutState const& state) { auto& containing_block_state = state.get(*box.containing_block()); auto& box_state = state.get(box); @@ -1030,7 +1030,7 @@ float FormattingContext::containing_block_width_for(Box const& box, FormattingSt VERIFY_NOT_REACHED(); } -float FormattingContext::containing_block_height_for(Box const& box, FormattingState const& state) +float FormattingContext::containing_block_height_for(Box const& box, LayoutState const& state) { auto& containing_block_state = state.get(*box.containing_block()); auto& box_state = state.get(box); diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.h b/Userland/Libraries/LibWeb/Layout/FormattingContext.h index 6e7eee9019..4ddf022fd1 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.h @@ -8,7 +8,7 @@ #include <AK/OwnPtr.h> #include <LibWeb/Forward.h> -#include <LibWeb/Layout/FormattingState.h> +#include <LibWeb/Layout/LayoutState.h> namespace Web::Layout { @@ -38,10 +38,10 @@ public: static bool creates_block_formatting_context(Box const&); - static float compute_width_for_replaced_element(FormattingState const&, ReplacedBox const&); - static float compute_height_for_replaced_element(FormattingState const&, ReplacedBox const&); + static float compute_width_for_replaced_element(LayoutState const&, ReplacedBox const&); + static float compute_height_for_replaced_element(LayoutState const&, ReplacedBox const&); - OwnPtr<FormattingContext> create_independent_formatting_context_if_needed(FormattingState&, Box const& child_box); + OwnPtr<FormattingContext> create_independent_formatting_context_if_needed(LayoutState&, Box const& child_box); virtual void parent_context_did_dimension_child_root_box() { } @@ -58,13 +58,13 @@ public: float containing_block_width_for(Box const& box) const { return containing_block_width_for(box, m_state); } float containing_block_height_for(Box const& box) const { return containing_block_height_for(box, m_state); } - static float containing_block_width_for(Box const&, FormattingState const&); - static float containing_block_height_for(Box const&, FormattingState const&); + static float containing_block_width_for(Box const&, LayoutState const&); + static float containing_block_height_for(Box const&, LayoutState const&); virtual void run_intrinsic_size_determination(Box const&); protected: - FormattingContext(Type, FormattingState&, Box const&, FormattingContext* parent = nullptr); + FormattingContext(Type, LayoutState&, Box const&, FormattingContext* parent = nullptr); float calculate_fit_content_size(float min_content_size, float max_content_size, Optional<float> available_space) const; @@ -81,11 +81,11 @@ protected: float preferred_minimum_width { 0 }; }; - static float tentative_width_for_replaced_element(FormattingState const&, ReplacedBox const&, CSS::LengthPercentage const& computed_width); - static float tentative_height_for_replaced_element(FormattingState const&, ReplacedBox const&, CSS::LengthPercentage const& computed_height); - static float compute_auto_height_for_block_formatting_context_root(FormattingState const&, BlockContainer const&); - static float compute_auto_height_for_block_level_element(FormattingState const&, Box const&); - static float calculate_auto_height(FormattingState const& state, Box const& box); + static float tentative_width_for_replaced_element(LayoutState const&, ReplacedBox const&, CSS::LengthPercentage const& computed_width); + static float tentative_height_for_replaced_element(LayoutState const&, ReplacedBox const&, CSS::LengthPercentage const& computed_height); + static float compute_auto_height_for_block_formatting_context_root(LayoutState const&, BlockContainer const&); + static float compute_auto_height_for_block_level_element(LayoutState const&, Box const&); + static float calculate_auto_height(LayoutState const& state, Box const& box); ShrinkToFitResult calculate_shrink_to_fit_widths(Box const&); @@ -102,7 +102,7 @@ protected: FormattingContext* m_parent { nullptr }; Box const& m_context_box; - FormattingState& m_state; + LayoutState& m_state; }; } diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 57a3a73c48..716c1e6c25 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -20,7 +20,7 @@ namespace Web::Layout { constexpr float text_justification_threshold = 0.1; -InlineFormattingContext::InlineFormattingContext(FormattingState& state, BlockContainer const& containing_block, BlockFormattingContext& parent) +InlineFormattingContext::InlineFormattingContext(LayoutState& state, BlockContainer const& containing_block, BlockFormattingContext& parent) : FormattingContext(Type::Inline, state, containing_block, &parent) , m_containing_block_state(state.get(containing_block)) { diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h index 84fff2a2fa..307abed880 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h @@ -15,7 +15,7 @@ namespace Web::Layout { class InlineFormattingContext final : public FormattingContext { public: - InlineFormattingContext(FormattingState&, BlockContainer const& containing_block, BlockFormattingContext& parent); + InlineFormattingContext(LayoutState&, BlockContainer const& containing_block, BlockFormattingContext& parent); ~InlineFormattingContext(); BlockFormattingContext& parent(); @@ -36,7 +36,7 @@ private: void generate_line_boxes(LayoutMode); void apply_justification_to_fragments(CSS::TextJustify, LineBox&, bool is_last_line); - FormattingState::NodeState const& m_containing_block_state; + LayoutState::NodeState const& m_containing_block_state; float m_effective_containing_block_width { 0 }; }; diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp index b913ffe1eb..e430c9e7c9 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.cpp @@ -13,7 +13,7 @@ namespace Web::Layout { -InlineLevelIterator::InlineLevelIterator(Layout::InlineFormattingContext& inline_formatting_context, Layout::FormattingState& formatting_state, Layout::BlockContainer const& container, LayoutMode layout_mode) +InlineLevelIterator::InlineLevelIterator(Layout::InlineFormattingContext& inline_formatting_context, Layout::LayoutState& formatting_state, Layout::BlockContainer const& container, LayoutMode layout_mode) : m_inline_formatting_context(inline_formatting_context) , m_formatting_state(formatting_state) , m_container(container) diff --git a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h index 7d26ebada4..5aa0fad680 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h +++ b/Userland/Libraries/LibWeb/Layout/InlineLevelIterator.h @@ -48,7 +48,7 @@ public: } }; - InlineLevelIterator(Layout::InlineFormattingContext&, FormattingState&, Layout::BlockContainer const&, LayoutMode); + InlineLevelIterator(Layout::InlineFormattingContext&, LayoutState&, Layout::BlockContainer const&, LayoutMode); Optional<Item> next(float available_width); @@ -66,9 +66,9 @@ private: Layout::Node const* next_inline_node_in_pre_order(Layout::Node const& current, Layout::Node const* stay_within); Layout::InlineFormattingContext& m_inline_formatting_context; - Layout::FormattingState& m_formatting_state; + Layout::LayoutState& m_formatting_state; Layout::BlockContainer const& m_container; - Layout::FormattingState::NodeState const& m_container_state; + Layout::LayoutState::NodeState const& m_container_state; Layout::Node const* m_current_node { nullptr }; Layout::Node const* m_next_node { nullptr }; LayoutMode const m_layout_mode; diff --git a/Userland/Libraries/LibWeb/Layout/FormattingState.cpp b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp index eedce21856..29ceae0b14 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingState.cpp +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp @@ -5,12 +5,12 @@ */ #include <LibWeb/Layout/BlockContainer.h> -#include <LibWeb/Layout/FormattingState.h> +#include <LibWeb/Layout/LayoutState.h> #include <LibWeb/Layout/TextNode.h> namespace Web::Layout { -FormattingState::NodeState& FormattingState::get_mutable(NodeWithStyleAndBoxModelMetrics const& box) +LayoutState::NodeState& LayoutState::get_mutable(NodeWithStyleAndBoxModelMetrics const& box) { auto serial_id = box.serial_id(); if (nodes[serial_id]) @@ -30,7 +30,7 @@ FormattingState::NodeState& FormattingState::get_mutable(NodeWithStyleAndBoxMode return *nodes[serial_id]; } -FormattingState::NodeState const& FormattingState::get(NodeWithStyleAndBoxModelMetrics const& box) const +LayoutState::NodeState const& LayoutState::get(NodeWithStyleAndBoxModelMetrics const& box) const { auto serial_id = box.serial_id(); if (nodes[serial_id]) @@ -40,14 +40,14 @@ FormattingState::NodeState const& FormattingState::get(NodeWithStyleAndBoxModelM if (ancestor->nodes[serial_id]) return *ancestor->nodes[serial_id]; } - const_cast<FormattingState*>(this)->nodes[serial_id] = adopt_own(*new NodeState); - const_cast<FormattingState*>(this)->nodes[serial_id]->node = const_cast<NodeWithStyleAndBoxModelMetrics*>(&box); + const_cast<LayoutState*>(this)->nodes[serial_id] = adopt_own(*new NodeState); + const_cast<LayoutState*>(this)->nodes[serial_id]->node = const_cast<NodeWithStyleAndBoxModelMetrics*>(&box); return *nodes[serial_id]; } -void FormattingState::commit() +void LayoutState::commit() { - // Only the top-level FormattingState should ever be committed. + // Only the top-level LayoutState should ever be committed. VERIFY(!m_parent); HashTable<Layout::TextNode*> text_nodes; @@ -91,7 +91,7 @@ void FormattingState::commit() text_node->set_paintable(text_node->create_paintable()); } -Gfx::FloatRect margin_box_rect(Box const& box, FormattingState const& state) +Gfx::FloatRect margin_box_rect(Box const& box, LayoutState const& state) { auto const& box_state = state.get(box); auto rect = Gfx::FloatRect { box_state.offset, { box_state.content_width, box_state.content_height } }; @@ -102,7 +102,7 @@ Gfx::FloatRect margin_box_rect(Box const& box, FormattingState const& state) return rect; } -Gfx::FloatRect margin_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, FormattingState const& state) +Gfx::FloatRect margin_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const& state) { auto rect = margin_box_rect(box, state); for (auto const* current = box.parent(); current; current = current->parent()) { @@ -116,7 +116,7 @@ Gfx::FloatRect margin_box_rect_in_ancestor_coordinate_space(Box const& box, Box return rect; } -Gfx::FloatRect absolute_content_rect(Box const& box, FormattingState const& state) +Gfx::FloatRect absolute_content_rect(Box const& box, LayoutState const& state) { auto const& box_state = state.get(box); Gfx::FloatRect rect { box_state.offset, { box_state.content_width, box_state.content_height } }; diff --git a/Userland/Libraries/LibWeb/Layout/FormattingState.h b/Userland/Libraries/LibWeb/Layout/LayoutState.h index e7e98b59d7..2fb82f5c75 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingState.h +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.h @@ -20,22 +20,22 @@ enum class SizeConstraint { MaxContent, }; -struct FormattingState { - FormattingState() +struct LayoutState { + LayoutState() : m_root(*this) { } - explicit FormattingState(FormattingState const* parent) + explicit LayoutState(LayoutState const* parent) : m_parent(parent) , m_root(find_root()) { nodes.resize(m_root.nodes.size()); } - FormattingState const& find_root() const + LayoutState const& find_root() const { - FormattingState const* root = this; + LayoutState const* root = this; for (auto* state = m_parent; state; state = state->m_parent) root = state; return *root; @@ -124,12 +124,12 @@ struct FormattingState { HashMap<Box const*, float> mutable flex_item_size_cache; - FormattingState const* m_parent { nullptr }; - FormattingState const& m_root; + LayoutState const* m_parent { nullptr }; + LayoutState const& m_root; }; -Gfx::FloatRect absolute_content_rect(Box const&, FormattingState const&); -Gfx::FloatRect margin_box_rect(Box const&, FormattingState const&); -Gfx::FloatRect margin_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, FormattingState const&); +Gfx::FloatRect absolute_content_rect(Box const&, LayoutState const&); +Gfx::FloatRect margin_box_rect(Box const&, LayoutState const&); +Gfx::FloatRect margin_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const&); } diff --git a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp index 6945417dc3..17c83f96f4 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.cpp @@ -5,8 +5,8 @@ */ #include <AK/Utf8View.h> -#include <LibWeb/Layout/FormattingState.h> #include <LibWeb/Layout/InitialContainingBlock.h> +#include <LibWeb/Layout/LayoutState.h> #include <LibWeb/Layout/LineBoxFragment.h> #include <LibWeb/Layout/TextNode.h> #include <ctype.h> diff --git a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.h b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.h index 2a34112309..cdbc5ad0bb 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBoxFragment.h +++ b/Userland/Libraries/LibWeb/Layout/LineBoxFragment.h @@ -67,9 +67,9 @@ public: Gfx::FloatRect selection_rect(Gfx::Font const&) const; - float height_of_inline_level_box(FormattingState const&) const; - float top_of_inline_level_box(FormattingState const&) const; - float bottom_of_inline_level_box(FormattingState const&) const; + float height_of_inline_level_box(LayoutState const&) const; + float top_of_inline_level_box(LayoutState const&) const; + float bottom_of_inline_level_box(LayoutState const&) const; private: Node const& m_layout_node; diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp index 333daeb938..dfbc906e84 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -9,7 +9,7 @@ namespace Web::Layout { -LineBuilder::LineBuilder(InlineFormattingContext& context, FormattingState& formatting_state, LayoutMode layout_mode) +LineBuilder::LineBuilder(InlineFormattingContext& context, LayoutState& formatting_state, LayoutMode layout_mode) : m_context(context) , m_formatting_state(formatting_state) , m_containing_block_state(formatting_state.get_mutable(context.containing_block())) @@ -76,7 +76,7 @@ bool LineBuilder::should_break(float next_item_width) return (current_line_width + next_item_width) > m_available_width_for_current_line; } -static float box_baseline(FormattingState const& state, Box const& box) +static float box_baseline(LayoutState const& state, Box const& box) { auto const& box_state = state.get(box); diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.h b/Userland/Libraries/LibWeb/Layout/LineBuilder.h index 8efdbc2e42..3a98666e58 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.h +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.h @@ -15,7 +15,7 @@ class LineBuilder { AK_MAKE_NONMOVABLE(LineBuilder); public: - LineBuilder(InlineFormattingContext&, FormattingState&, LayoutMode); + LineBuilder(InlineFormattingContext&, LayoutState&, LayoutMode); ~LineBuilder(); void break_line(); @@ -50,8 +50,8 @@ private: LineBox& ensure_last_line_box(); InlineFormattingContext& m_context; - FormattingState& m_formatting_state; - FormattingState::NodeState& m_containing_block_state; + LayoutState& m_formatting_state; + LayoutState::NodeState& m_containing_block_state; LayoutMode m_layout_mode {}; float m_available_width_for_current_line { 0 }; float m_current_y { 0 }; diff --git a/Userland/Libraries/LibWeb/Layout/Node.h b/Userland/Libraries/LibWeb/Layout/Node.h index 02b947d5a8..38d6b3f12d 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.h +++ b/Userland/Libraries/LibWeb/Layout/Node.h @@ -25,7 +25,7 @@ enum class LayoutMode { Normal, // Intrinsic size determination. - // Boxes honor min-content and max-content constraints (set via FormattingState::NodeState::{width,height}_constraint) + // Boxes honor min-content and max-content constraints (set via LayoutState::NodeState::{width,height}_constraint) // by considering their containing block to be 0-sized or infinitely large in the relevant axis. IntrinsicSizeDetermination, }; diff --git a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp index 9010f11f77..a951ba1bbc 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.cpp @@ -13,7 +13,7 @@ namespace Web::Layout { -SVGFormattingContext::SVGFormattingContext(FormattingState& state, Box const& box, FormattingContext* parent) +SVGFormattingContext::SVGFormattingContext(LayoutState& state, Box const& box, FormattingContext* parent) : FormattingContext(Type::SVG, state, box, parent) { } diff --git a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.h b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.h index 53c943c784..6d343b5f95 100644 --- a/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/SVGFormattingContext.h @@ -13,7 +13,7 @@ namespace Web::Layout { class SVGFormattingContext : public FormattingContext { public: - explicit SVGFormattingContext(FormattingState&, Box const&, FormattingContext* parent); + explicit SVGFormattingContext(LayoutState&, Box const&, FormattingContext* parent); ~SVGFormattingContext(); virtual void run(Box const&, LayoutMode) override; diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp index 38088dd7e3..e87fa03cae 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp @@ -16,7 +16,7 @@ namespace Web::Layout { -TableFormattingContext::TableFormattingContext(FormattingState& state, BlockContainer const& block_container, FormattingContext* parent) +TableFormattingContext::TableFormattingContext(LayoutState& state, BlockContainer const& block_container, FormattingContext* parent) : BlockFormattingContext(state, block_container, parent) { } diff --git a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h index e95d115c6f..170fd14969 100644 --- a/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/TableFormattingContext.h @@ -20,7 +20,7 @@ struct ColumnWidth { class TableFormattingContext final : public BlockFormattingContext { public: - explicit TableFormattingContext(FormattingState&, BlockContainer const&, FormattingContext* parent); + explicit TableFormattingContext(LayoutState&, BlockContainer const&, FormattingContext* parent); ~TableFormattingContext(); virtual void run(Box const&, LayoutMode) override; |