diff options
author | Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> | 2022-12-04 19:51:29 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-12-05 17:47:48 +0100 |
commit | ba64d0462ca2ea1a621cb181489cfa197c2946da (patch) | |
tree | 85d9c8d50736cdbd8391fc6adff6eafec335bcf7 /Userland | |
parent | 2f38f8c84ae448169986fd4a3dc1b3496c380ecc (diff) | |
download | serenity-ba64d0462ca2ea1a621cb181489cfa197c2946da.zip |
LibWeb: Move box_baseline from LineBuilder.cpp to LayoutState.cpp
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/LayoutState.cpp | 26 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/LayoutState.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/LineBuilder.cpp | 26 |
3 files changed, 27 insertions, 26 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp index 19131d5dcb..994957ae82 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.cpp +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.cpp @@ -97,6 +97,32 @@ void LayoutState::commit() text_node->set_paintable(text_node->create_paintable()); } +float box_baseline(LayoutState const& state, Box const& box) +{ + auto const& box_state = state.get(box); + + auto const& vertical_align = box.computed_values().vertical_align(); + if (vertical_align.has<CSS::VerticalAlign>()) { + switch (vertical_align.get<CSS::VerticalAlign>()) { + case CSS::VerticalAlign::Top: + return box_state.border_box_top(); + case CSS::VerticalAlign::Bottom: + return box_state.content_height() + box_state.border_box_bottom(); + default: + break; + } + } + + if (!box_state.line_boxes.is_empty()) + return box_state.border_box_top() + box_state.offset.y() + box_state.line_boxes.last().baseline(); + if (box.has_children() && !box.children_are_inline()) { + auto const* child_box = box.last_child_of_type<Box>(); + VERIFY(child_box); + return box_baseline(state, *child_box); + } + return box_state.border_box_height(); +} + Gfx::FloatRect margin_box_rect(Box const& box, LayoutState const& state) { auto const& box_state = state.get(box); diff --git a/Userland/Libraries/LibWeb/Layout/LayoutState.h b/Userland/Libraries/LibWeb/Layout/LayoutState.h index ec1071e390..e7c7515d09 100644 --- a/Userland/Libraries/LibWeb/Layout/LayoutState.h +++ b/Userland/Libraries/LibWeb/Layout/LayoutState.h @@ -184,5 +184,6 @@ Gfx::FloatRect border_box_rect(Box const&, LayoutState const&); Gfx::FloatRect border_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const&); Gfx::FloatRect content_box_rect(Box const&, LayoutState const&); Gfx::FloatRect content_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const&); +float box_baseline(LayoutState const& state, Box const& box); } diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp index a12208f782..92890a3bff 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -141,32 +141,6 @@ 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(LayoutState const& state, Box const& box) -{ - auto const& box_state = state.get(box); - - auto const& vertical_align = box.computed_values().vertical_align(); - if (vertical_align.has<CSS::VerticalAlign>()) { - switch (vertical_align.get<CSS::VerticalAlign>()) { - case CSS::VerticalAlign::Top: - return box_state.border_box_top(); - case CSS::VerticalAlign::Bottom: - return box_state.content_height() + box_state.border_box_bottom(); - default: - break; - } - } - - if (!box_state.line_boxes.is_empty()) - return box_state.border_box_top() + box_state.offset.y() + box_state.line_boxes.last().baseline(); - if (box.has_children() && !box.children_are_inline()) { - auto const* child_box = box.last_child_of_type<Box>(); - VERIFY(child_box); - return box_baseline(state, *child_box); - } - return box_state.border_box_height(); -} - void LineBuilder::update_last_line() { m_last_line_needs_update = false; |