2020-11-22 13:38:18 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2020-2024, Andreas Kling <andreas@ladybird.org>
|
2020-11-22 13:38:18 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-11-22 13:38:18 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibWeb/CSS/Length.h>
|
|
|
|
|
#include <LibWeb/DOM/Node.h>
|
|
|
|
|
#include <LibWeb/Dump.h>
|
2021-10-06 20:02:41 +02:00
|
|
|
#include <LibWeb/Layout/BlockContainer.h>
|
2020-11-25 20:08:52 +01:00
|
|
|
#include <LibWeb/Layout/BlockFormattingContext.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/Box.h>
|
2020-11-22 13:38:18 +01:00
|
|
|
#include <LibWeb/Layout/InlineFormattingContext.h>
|
2022-01-17 15:07:19 +01:00
|
|
|
#include <LibWeb/Layout/InlineLevelIterator.h>
|
2022-01-19 11:59:44 +01:00
|
|
|
#include <LibWeb/Layout/LineBuilder.h>
|
2020-11-22 13:38:18 +01:00
|
|
|
|
|
|
|
|
namespace Web::Layout {
|
|
|
|
|
|
2024-03-15 19:25:00 +01:00
|
|
|
InlineFormattingContext::InlineFormattingContext(
|
|
|
|
|
LayoutState& state,
|
2024-09-11 01:03:02 +02:00
|
|
|
LayoutMode layout_mode,
|
2024-03-15 19:25:00 +01:00
|
|
|
BlockContainer const& containing_block,
|
|
|
|
|
LayoutState::UsedValues& containing_block_used_values,
|
|
|
|
|
BlockFormattingContext& parent)
|
2024-09-11 01:03:02 +02:00
|
|
|
: FormattingContext(Type::Inline, layout_mode, state, containing_block, &parent)
|
2024-03-15 19:25:00 +01:00
|
|
|
, m_containing_block_used_values(containing_block_used_values)
|
2020-11-22 13:38:18 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 13:21:51 -06:00
|
|
|
InlineFormattingContext::~InlineFormattingContext() = default;
|
2020-11-22 13:38:18 +01:00
|
|
|
|
2022-01-23 15:22:18 +01:00
|
|
|
BlockFormattingContext& InlineFormattingContext::parent()
|
2020-12-05 20:10:39 +01:00
|
|
|
{
|
2022-01-23 15:22:18 +01:00
|
|
|
return static_cast<BlockFormattingContext&>(*FormattingContext::parent());
|
|
|
|
|
}
|
2021-09-23 16:58:57 +02:00
|
|
|
|
2022-01-23 15:22:18 +01:00
|
|
|
BlockFormattingContext const& InlineFormattingContext::parent() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<BlockFormattingContext const&>(*FormattingContext::parent());
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-29 11:32:59 +00:00
|
|
|
CSSPixels InlineFormattingContext::leftmost_inline_offset_at(CSSPixels y) const
|
2022-01-23 15:22:18 +01:00
|
|
|
{
|
2022-01-24 02:03:29 +01:00
|
|
|
// NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC.
|
2024-03-15 19:25:00 +01:00
|
|
|
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(m_containing_block_used_values, parent().root());
|
2022-11-03 17:48:46 +00:00
|
|
|
CSSPixels y_in_root = box_in_root_rect.y() + y;
|
2023-06-13 13:37:15 +00:00
|
|
|
auto space_and_containing_margin = parent().space_used_and_containing_margin_for_floats(y_in_root);
|
2025-07-28 00:01:37 +02:00
|
|
|
|
|
|
|
|
// If there's no float box to take into account, we start at the left edge of the containing block.
|
|
|
|
|
if (!space_and_containing_margin.matching_left_float_box)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
// If the left edge of the containing block is to the right of the rightmost left-side float, start placing inline
|
|
|
|
|
// content at the left edge of the containing block.
|
2023-06-13 13:37:15 +00:00
|
|
|
auto left_side_floats_limit_to_right = space_and_containing_margin.left_total_containing_margin + space_and_containing_margin.left_used_space;
|
2025-07-28 00:01:37 +02:00
|
|
|
if (box_in_root_rect.x() >= left_side_floats_limit_to_right)
|
2023-05-16 09:46:45 +02:00
|
|
|
return 0;
|
2025-07-28 00:01:37 +02:00
|
|
|
|
2023-05-16 09:46:45 +02:00
|
|
|
// The left edge of the containing block is to the left of the rightmost left-side float.
|
|
|
|
|
// We adjust the inline content insertion point by the overlap between the containing block and the float.
|
2025-07-28 00:01:37 +02:00
|
|
|
return left_side_floats_limit_to_right - box_in_root_rect.x();
|
2022-03-18 14:44:36 +01:00
|
|
|
}
|
|
|
|
|
|
2023-08-12 18:30:18 +02:00
|
|
|
AvailableSize InlineFormattingContext::available_space_for_line(CSSPixels y) const
|
2022-03-18 14:44:36 +01:00
|
|
|
{
|
2025-04-01 13:21:16 +02:00
|
|
|
if (!m_available_space->width.is_definite())
|
2023-08-12 18:30:18 +02:00
|
|
|
return m_available_space->width;
|
2025-04-01 13:21:16 +02:00
|
|
|
|
|
|
|
|
auto intrusions = parent().intrusion_by_floats_into_box(m_containing_block_used_values, y);
|
|
|
|
|
return AvailableSize::make_definite(m_available_space->width.to_px_or_zero() - intrusions.left - intrusions.right);
|
2020-12-05 20:10:39 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:46:10 +00:00
|
|
|
CSSPixels InlineFormattingContext::automatic_content_width() const
|
2022-09-27 15:29:17 +02:00
|
|
|
{
|
|
|
|
|
return m_automatic_content_width;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 17:46:10 +00:00
|
|
|
CSSPixels InlineFormattingContext::automatic_content_height() const
|
2022-09-24 13:39:43 +02:00
|
|
|
{
|
2022-09-27 15:29:17 +02:00
|
|
|
return m_automatic_content_height;
|
2022-09-24 13:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-11 01:03:02 +02:00
|
|
|
void InlineFormattingContext::run(AvailableSpace const& available_space)
|
2020-11-22 13:38:18 +01:00
|
|
|
{
|
2026-01-08 19:25:36 +01:00
|
|
|
FORMATTING_CONTEXT_TRACE();
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(containing_block().children_are_inline());
|
2022-09-27 15:29:17 +02:00
|
|
|
m_available_space = available_space;
|
2024-09-11 01:03:02 +02:00
|
|
|
generate_line_boxes();
|
2022-09-27 15:29:17 +02:00
|
|
|
|
2022-11-03 17:48:46 +00:00
|
|
|
CSSPixels content_height = 0;
|
2022-09-27 15:29:17 +02:00
|
|
|
|
2025-03-27 14:59:49 +00:00
|
|
|
for (auto& line_box : m_containing_block_used_values.line_boxes)
|
2022-09-27 15:29:17 +02:00
|
|
|
content_height += line_box.height();
|
|
|
|
|
|
2023-05-03 17:14:15 +02:00
|
|
|
// NOTE: We ask the parent BFC to calculate the automatic content width of this IFC.
|
|
|
|
|
// This ensures that any floated boxes are taken into account.
|
|
|
|
|
m_automatic_content_width = parent().greatest_child_width(containing_block());
|
2022-09-27 15:29:17 +02:00
|
|
|
m_automatic_content_height = content_height;
|
2020-11-22 13:38:18 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-20 15:51:24 +01:00
|
|
|
void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode layout_mode)
|
2020-11-22 13:38:18 +01:00
|
|
|
{
|
2023-07-06 14:38:46 +02:00
|
|
|
auto width_of_containing_block = m_available_space->width.to_px_or_zero();
|
2022-02-21 17:42:09 +01:00
|
|
|
auto& box_state = m_state.get_mutable(box);
|
2022-02-20 15:51:24 +01:00
|
|
|
auto const& computed_values = box.computed_values();
|
2022-02-14 15:49:46 +01:00
|
|
|
|
2025-09-01 12:51:52 +01:00
|
|
|
box_state.margin_left = computed_values.margin().left().to_px_or_zero(box, width_of_containing_block);
|
2022-02-20 15:51:24 +01:00
|
|
|
box_state.border_left = computed_values.border_left().width;
|
2025-09-01 12:51:52 +01:00
|
|
|
box_state.padding_left = computed_values.padding().left().to_px_or_zero(box, width_of_containing_block);
|
2022-03-20 13:27:47 +01:00
|
|
|
|
2025-09-01 12:51:52 +01:00
|
|
|
box_state.margin_right = computed_values.margin().right().to_px_or_zero(box, width_of_containing_block);
|
2022-02-20 15:51:24 +01:00
|
|
|
box_state.border_right = computed_values.border_right().width;
|
2025-09-01 12:51:52 +01:00
|
|
|
box_state.padding_right = computed_values.padding().right().to_px_or_zero(box, width_of_containing_block);
|
2022-03-20 13:27:47 +01:00
|
|
|
|
2025-09-01 12:51:52 +01:00
|
|
|
box_state.margin_top = computed_values.margin().top().to_px_or_zero(box, width_of_containing_block);
|
2022-03-20 13:27:47 +01:00
|
|
|
box_state.border_top = computed_values.border_top().width;
|
2025-09-01 12:51:52 +01:00
|
|
|
box_state.padding_top = computed_values.padding().top().to_px_or_zero(box, width_of_containing_block);
|
2022-03-20 13:27:47 +01:00
|
|
|
|
2025-09-01 12:51:52 +01:00
|
|
|
box_state.padding_bottom = computed_values.padding().bottom().to_px_or_zero(box, width_of_containing_block);
|
2022-03-20 13:27:47 +01:00
|
|
|
box_state.border_bottom = computed_values.border_bottom().width;
|
2025-09-01 12:51:52 +01:00
|
|
|
box_state.margin_bottom = computed_values.margin().bottom().to_px_or_zero(box, width_of_containing_block);
|
2022-02-14 15:49:46 +01:00
|
|
|
|
2025-08-04 15:55:19 +02:00
|
|
|
if (box_is_sized_as_replaced_element(box, *m_available_space)) {
|
2023-06-08 16:47:50 +01:00
|
|
|
box_state.set_content_width(compute_width_for_replaced_element(box, *m_available_space));
|
|
|
|
|
box_state.set_content_height(compute_height_for_replaced_element(box, *m_available_space));
|
2024-03-23 19:04:38 +01:00
|
|
|
auto independent_formatting_context = layout_inside(box, layout_mode, box_state.available_inner_space_or_constraints_from(*m_available_space));
|
|
|
|
|
if (independent_formatting_context)
|
|
|
|
|
independent_formatting_context->parent_context_did_dimension_child_root_box();
|
2020-11-22 13:38:18 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 20:29:31 +02:00
|
|
|
// Any box that has simple flow inside should have generated line box fragments already.
|
2023-04-13 13:37:19 +02:00
|
|
|
if (box.display().is_flow_inside()) {
|
|
|
|
|
dbgln("FIXME: InlineFormattingContext::dimension_box_on_line got unexpected box in inline context:");
|
|
|
|
|
dump_tree(box);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-10-06 20:29:31 +02:00
|
|
|
|
|
|
|
|
auto const& width_value = box.computed_values().width();
|
2022-11-03 17:48:46 +00:00
|
|
|
CSSPixels unconstrained_width = 0;
|
2022-11-28 16:40:15 +01:00
|
|
|
if (should_treat_width_as_auto(box, *m_available_space)) {
|
2022-10-06 20:29:31 +02:00
|
|
|
auto result = calculate_shrink_to_fit_widths(box);
|
|
|
|
|
|
2023-08-12 18:30:18 +02:00
|
|
|
if (m_available_space->width.is_definite()) {
|
|
|
|
|
auto available_width = m_available_space->width.to_px_or_zero()
|
|
|
|
|
- box_state.margin_left
|
|
|
|
|
- box_state.border_left
|
|
|
|
|
- box_state.padding_left
|
|
|
|
|
- box_state.padding_right
|
|
|
|
|
- box_state.border_right
|
|
|
|
|
- box_state.margin_right;
|
2022-10-06 20:29:31 +02:00
|
|
|
|
2023-08-12 18:30:18 +02:00
|
|
|
unconstrained_width = min(max(result.preferred_minimum_width, available_width), result.preferred_width);
|
2023-10-16 19:28:29 +02:00
|
|
|
} else if (m_available_space->width.is_min_content()) {
|
|
|
|
|
unconstrained_width = result.preferred_minimum_width;
|
2023-08-12 18:30:18 +02:00
|
|
|
} else {
|
|
|
|
|
unconstrained_width = result.preferred_width;
|
|
|
|
|
}
|
2022-10-06 20:29:31 +02:00
|
|
|
} else {
|
|
|
|
|
if (width_value.contains_percentage() && !m_available_space->width.is_definite()) {
|
|
|
|
|
// NOTE: We can't resolve percentages yet. We'll have to wait until after inner layout.
|
2020-11-22 13:38:18 +01:00
|
|
|
} else {
|
2023-01-07 13:38:46 +01:00
|
|
|
auto inner_width = calculate_inner_width(box, m_available_space->width, width_value);
|
2024-01-07 05:24:09 +01:00
|
|
|
unconstrained_width = inner_width;
|
2020-11-22 13:38:18 +01:00
|
|
|
}
|
2022-10-06 20:29:31 +02:00
|
|
|
}
|
2022-10-15 13:54:42 +02:00
|
|
|
|
2022-11-03 17:48:46 +00:00
|
|
|
CSSPixels width = unconstrained_width;
|
2023-06-16 13:46:55 +02:00
|
|
|
if (!should_treat_max_width_as_none(box, m_available_space->width)) {
|
2024-01-07 05:24:09 +01:00
|
|
|
auto max_width = calculate_inner_width(box, m_available_space->width, box.computed_values().max_width());
|
2022-10-15 13:54:42 +02:00
|
|
|
width = min(width, max_width);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto computed_min_width = box.computed_values().min_width();
|
|
|
|
|
if (!computed_min_width.is_auto()) {
|
2024-01-07 05:24:09 +01:00
|
|
|
auto min_width = calculate_inner_width(box, m_available_space->width, computed_min_width);
|
2022-10-15 13:54:42 +02:00
|
|
|
width = max(width, min_width);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-04 20:32:50 +00:00
|
|
|
box_state.set_content_width(width);
|
2022-10-15 13:54:42 +02:00
|
|
|
|
2024-09-27 17:49:02 +02:00
|
|
|
parent().resolve_used_height_if_not_treated_as_auto(box, AvailableSpace(AvailableSize::make_definite(width), AvailableSize::make_indefinite()));
|
|
|
|
|
|
LibWeb: Let parent formatting context determine size of flex containers
Until now, we had implemented flex container sizing by awkwardly doing
exactly what the spec said (basically having FFC size the container)
despite that not really making sense in the big picture. (Parent
formatting contexts should be responsible for sizing and placing their
children)
This patch moves us away from the Flexbox spec text a little bit, by
removing the logic for sizing the flex container in FFC, and instead
making sure that all formatting contexts can set both width and height
of flex container children.
This required changes in BFC and IFC, but it's actually quite simple!
Width was already not a problem, and it turns out height isn't either,
since the automatic height of a flex container is max-content.
With this in mind, we can simply determine the height of flex containers
before transferring control to FFC, and everything flows nicely.
With this change, we can remove all the virtuals and FFC logic for
negotiating container size with the parent formatting context.
We also don't need the "available space for flex container" stuff
anymore either, so that's gone as well.
There are some minor diffs in layout test results from this, but the
new results actually match other browsers more closely, so that's fine.
This should make flex layout, and indeed layout in general, easier to
understand, since this was the main weird special case outside of
BFC/IFC where a formatting context delegates work to its parent instead
of the other way around. :^)
2024-01-10 14:52:21 +01:00
|
|
|
// NOTE: Flex containers with `auto` height are treated as `max-content`, so we can compute their height early.
|
2024-10-24 16:52:11 +02:00
|
|
|
if (box.display().is_flex_inside())
|
2024-09-27 17:49:02 +02:00
|
|
|
parent().resolve_used_height_if_treated_as_auto(box, AvailableSpace(AvailableSize::make_definite(width), AvailableSize::make_indefinite()));
|
LibWeb: Let parent formatting context determine size of flex containers
Until now, we had implemented flex container sizing by awkwardly doing
exactly what the spec said (basically having FFC size the container)
despite that not really making sense in the big picture. (Parent
formatting contexts should be responsible for sizing and placing their
children)
This patch moves us away from the Flexbox spec text a little bit, by
removing the logic for sizing the flex container in FFC, and instead
making sure that all formatting contexts can set both width and height
of flex container children.
This required changes in BFC and IFC, but it's actually quite simple!
Width was already not a problem, and it turns out height isn't either,
since the automatic height of a flex container is max-content.
With this in mind, we can simply determine the height of flex containers
before transferring control to FFC, and everything flows nicely.
With this change, we can remove all the virtuals and FFC logic for
negotiating container size with the parent formatting context.
We also don't need the "available space for flex container" stuff
anymore either, so that's gone as well.
There are some minor diffs in layout test results from this, but the
new results actually match other browsers more closely, so that's fine.
This should make flex layout, and indeed layout in general, easier to
understand, since this was the main weird special case outside of
BFC/IFC where a formatting context delegates work to its parent instead
of the other way around. :^)
2024-01-10 14:52:21 +01:00
|
|
|
|
2022-10-06 20:29:31 +02:00
|
|
|
auto independent_formatting_context = layout_inside(box, layout_mode, box_state.available_inner_space_or_constraints_from(*m_available_space));
|
|
|
|
|
|
2023-07-15 22:50:38 +02:00
|
|
|
if (should_treat_height_as_auto(box, *m_available_space)) {
|
2022-10-06 20:29:31 +02:00
|
|
|
// FIXME: (10.6.6) If 'height' is 'auto', the height depends on the element's descendants per 10.6.7.
|
2024-11-21 17:32:02 +01:00
|
|
|
parent().resolve_used_height_if_treated_as_auto(box, *m_available_space);
|
2022-10-06 20:29:31 +02:00
|
|
|
} else {
|
2024-11-21 17:32:02 +01:00
|
|
|
parent().resolve_used_height_if_not_treated_as_auto(box, *m_available_space);
|
2020-11-22 13:38:18 +01:00
|
|
|
}
|
|
|
|
|
|
2022-10-06 20:29:31 +02:00
|
|
|
if (independent_formatting_context)
|
|
|
|
|
independent_formatting_context->parent_context_did_dimension_child_root_box();
|
2020-11-22 13:38:18 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-09 20:56:59 +02:00
|
|
|
void InlineFormattingContext::apply_justification_to_fragments(CSS::TextJustify text_justify, LineBox& line_box, bool is_last_line)
|
2022-03-12 17:01:06 +00:00
|
|
|
{
|
2022-03-12 19:32:03 +00:00
|
|
|
switch (text_justify) {
|
|
|
|
|
case CSS::TextJustify::None:
|
|
|
|
|
return;
|
|
|
|
|
// FIXME: These two cases currently fall back to auto, handle them as well.
|
|
|
|
|
case CSS::TextJustify::InterCharacter:
|
|
|
|
|
case CSS::TextJustify::InterWord:
|
|
|
|
|
case CSS::TextJustify::Auto:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-10 15:49:17 +02:00
|
|
|
// https://www.w3.org/TR/css-text-3/#text-align-property
|
|
|
|
|
// Unless otherwise specified by text-align-last, the last line before a forced break or the end of the block is start-aligned.
|
|
|
|
|
// FIXME: Support text-align-last.
|
|
|
|
|
if (is_last_line || line_box.m_has_forced_break)
|
2022-03-12 17:01:06 +00:00
|
|
|
return;
|
|
|
|
|
|
2024-10-29 11:32:59 +00:00
|
|
|
CSSPixels excess_horizontal_space = line_box.original_available_width().to_px_or_zero() - line_box.inline_length();
|
2022-11-03 17:48:46 +00:00
|
|
|
CSSPixels excess_horizontal_space_including_whitespace = excess_horizontal_space;
|
2022-03-12 17:01:06 +00:00
|
|
|
size_t whitespace_count = 0;
|
|
|
|
|
for (auto& fragment : line_box.fragments()) {
|
|
|
|
|
if (fragment.is_justifiable_whitespace()) {
|
|
|
|
|
++whitespace_count;
|
2024-10-29 11:32:59 +00:00
|
|
|
excess_horizontal_space_including_whitespace += fragment.inline_length();
|
2022-03-12 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-12 21:37:35 +03:00
|
|
|
CSSPixels justified_space_width = whitespace_count > 0 ? (excess_horizontal_space_including_whitespace / whitespace_count) : 0;
|
2022-03-12 17:01:06 +00:00
|
|
|
|
|
|
|
|
// This is the amount that each fragment will be offset by. If a whitespace
|
|
|
|
|
// fragment is shorter than the justified space width, it increases to push
|
|
|
|
|
// subsequent fragments, and decreases to pull them back otherwise.
|
2022-11-03 17:48:46 +00:00
|
|
|
CSSPixels running_diff = 0;
|
2022-03-12 17:01:06 +00:00
|
|
|
for (size_t i = 0; i < line_box.fragments().size(); ++i) {
|
|
|
|
|
auto& fragment = line_box.fragments()[i];
|
2024-10-29 11:32:59 +00:00
|
|
|
fragment.set_inline_offset(fragment.inline_offset() + running_diff);
|
2022-03-12 17:01:06 +00:00
|
|
|
|
|
|
|
|
if (fragment.is_justifiable_whitespace()
|
2024-10-29 11:32:59 +00:00
|
|
|
&& fragment.inline_length() != justified_space_width) {
|
|
|
|
|
running_diff += justified_space_width - fragment.inline_length();
|
|
|
|
|
fragment.set_inline_length(justified_space_width);
|
2022-03-12 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 22:35:07 +01:00
|
|
|
// https://drafts.csswg.org/css-overflow-4/#text-overflow
|
|
|
|
|
void InlineFormattingContext::apply_text_overflow_ellipsis(Vector<LineBox>& line_boxes)
|
|
|
|
|
{
|
|
|
|
|
// This property specifies rendering when inline content overflows its line box edge in the inline progression
|
|
|
|
|
// direction of its block container element ("the block") that has overflow other than visible.
|
|
|
|
|
|
|
|
|
|
// NB: When inline children are wrapped in anonymous blocks (e.g. due to floats), we look past the anonymous
|
|
|
|
|
// wrapper to the actual element that has text-overflow and overflow set.
|
|
|
|
|
GC::Ref<Box const> block = containing_block();
|
|
|
|
|
if (block->is_anonymous())
|
|
|
|
|
block = *block->non_anonymous_containing_block();
|
|
|
|
|
|
|
|
|
|
// FIXME: Support the <string>, fade, and fade() values, as well as the two-value syntax.
|
|
|
|
|
auto const& block_values = block->computed_values();
|
|
|
|
|
if (block_values.text_overflow() != CSS::TextOverflow::Ellipsis)
|
|
|
|
|
return;
|
|
|
|
|
if (block_values.overflow_x() == CSS::Overflow::Visible)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Render an ellipsis character (U+2026) to represent clipped inline content.
|
|
|
|
|
constexpr u32 ellipsis_codepoint = 0x2026;
|
|
|
|
|
|
|
|
|
|
for (auto& line_box : line_boxes) {
|
|
|
|
|
// NB: Use the line box's original available width rather than the IFC's available space, since the line's
|
|
|
|
|
// usable width may be reduced by float intrusions.
|
|
|
|
|
if (!line_box.original_available_width().is_definite())
|
|
|
|
|
continue;
|
|
|
|
|
auto available_width = line_box.original_available_width().to_px_or_zero();
|
|
|
|
|
if (line_box.inline_length() <= available_width)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
auto& fragments = line_box.fragments();
|
|
|
|
|
if (fragments.is_empty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// For the ellipsis and string values, implementations must hide characters and atomic inline-level elements at
|
|
|
|
|
// the applicable edge(s) of the line as necessary to fit the ellipsis/string, and place the ellipsis/string
|
|
|
|
|
// immediately adjacent to the applicable edge(s) of the remaining inline content.
|
|
|
|
|
bool line_has_visible_content = false;
|
|
|
|
|
for (size_t i = 0; i < fragments.size(); i++) {
|
|
|
|
|
auto& fragment = fragments[i];
|
|
|
|
|
auto fragment_start = fragment.inline_offset();
|
|
|
|
|
auto fragment_end = fragment_start + fragment.inline_length();
|
|
|
|
|
|
|
|
|
|
if (fragment_end <= available_width) {
|
|
|
|
|
line_has_visible_content = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NB: We skip non-text fragments (atomic inlines) for now. Hiding them entirely to make room for the
|
|
|
|
|
// ellipsis is not yet implemented.
|
|
|
|
|
if (!fragment.glyph_run())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
auto& font = fragment.glyph_run()->font();
|
|
|
|
|
auto ellipsis_width = font.glyph_width(ellipsis_codepoint);
|
|
|
|
|
auto available_in_fragment = (available_width - fragment_start).to_float();
|
|
|
|
|
auto max_text_width = available_in_fragment - ellipsis_width;
|
|
|
|
|
|
|
|
|
|
auto& glyphs = fragment.glyph_run()->glyphs();
|
|
|
|
|
size_t keep_count = 0;
|
|
|
|
|
float last_kept_end = 0.f;
|
|
|
|
|
float y_position = 0.f;
|
|
|
|
|
|
|
|
|
|
// https://drafts.csswg.org/css-overflow-4/#auto-ellipsis
|
|
|
|
|
// The first character or atomic inline-level element on a line must be clipped rather than ellipsed.
|
|
|
|
|
for (auto const& glyph : glyphs) {
|
|
|
|
|
auto glyph_end = glyph.position.x() + glyph.glyph_width;
|
|
|
|
|
if (glyph_end > max_text_width && (keep_count > 0 || line_has_visible_content))
|
|
|
|
|
break;
|
|
|
|
|
keep_count++;
|
|
|
|
|
last_kept_end = glyph_end;
|
|
|
|
|
y_position = glyph.position.y();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (keep_count < glyphs.size())
|
|
|
|
|
glyphs.remove(keep_count, glyphs.size() - keep_count);
|
|
|
|
|
|
|
|
|
|
glyphs.append(Gfx::DrawGlyph {
|
|
|
|
|
.position = { last_kept_end, y_position },
|
|
|
|
|
.length_in_code_units = AK::UnicodeUtils::code_unit_length_for_code_point(ellipsis_codepoint),
|
|
|
|
|
.glyph_width = ellipsis_width,
|
|
|
|
|
.glyph_id = font.glyph_id_for_code_point(ellipsis_codepoint),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fragment.set_inline_length(CSSPixels::nearest_value_for(last_kept_end + ellipsis_width));
|
|
|
|
|
|
2026-03-31 19:00:25 +01:00
|
|
|
for (size_t j = i + 1; j < fragments.size(); ++j)
|
|
|
|
|
fragments[j].set_fully_truncated(true);
|
2026-03-23 22:35:07 +01:00
|
|
|
|
|
|
|
|
line_box.m_inline_length = available_width;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-11 01:03:02 +02:00
|
|
|
void InlineFormattingContext::generate_line_boxes()
|
2022-01-17 15:07:19 +01:00
|
|
|
{
|
2024-03-15 19:25:00 +01:00
|
|
|
auto& line_boxes = m_containing_block_used_values.line_boxes;
|
2022-02-20 15:51:24 +01:00
|
|
|
line_boxes.clear_with_capacity();
|
2022-01-17 15:07:19 +01:00
|
|
|
|
2024-08-18 17:58:05 +01:00
|
|
|
auto direction = m_context_box->computed_values().direction();
|
2024-10-29 11:32:59 +00:00
|
|
|
auto writing_mode = m_context_box->computed_values().writing_mode();
|
2024-08-18 17:58:05 +01:00
|
|
|
|
2024-09-11 01:03:02 +02:00
|
|
|
InlineLevelIterator iterator(*this, m_state, containing_block(), m_containing_block_used_values, m_layout_mode);
|
2024-10-29 11:32:59 +00:00
|
|
|
LineBuilder line_builder(*this, m_state, m_containing_block_used_values, direction, writing_mode);
|
2022-01-17 15:07:19 +01:00
|
|
|
|
2024-01-20 20:15:09 +01:00
|
|
|
// NOTE: When we ignore collapsible whitespace chunks at the start of a line,
|
2026-02-07 21:37:47 +01:00
|
|
|
// we have to remember how much start margin, border and padding that chunk had
|
|
|
|
|
// in the inline axis, so that we can add it to the first non-whitespace chunk.
|
2024-01-20 20:15:09 +01:00
|
|
|
CSSPixels leading_margin_from_collapsible_whitespace = 0;
|
2026-02-07 21:37:47 +01:00
|
|
|
CSSPixels leading_border_from_collapsible_whitespace = 0;
|
|
|
|
|
CSSPixels leading_padding_from_collapsible_whitespace = 0;
|
2024-01-20 20:15:09 +01:00
|
|
|
|
2024-09-21 19:46:37 +02:00
|
|
|
Vector<Box const*> absolute_boxes;
|
|
|
|
|
|
2022-01-17 15:07:19 +01:00
|
|
|
for (;;) {
|
2023-08-17 05:38:52 +00:00
|
|
|
auto item_opt = iterator.next();
|
2022-01-17 15:07:19 +01:00
|
|
|
if (!item_opt.has_value())
|
|
|
|
|
break;
|
|
|
|
|
auto& item = item_opt.value();
|
|
|
|
|
|
2022-01-21 14:15:10 +01:00
|
|
|
// Ignore collapsible whitespace chunks at the start of line, and if the last fragment already ends in whitespace.
|
2023-08-19 03:36:53 +00:00
|
|
|
if (item.is_collapsible_whitespace && (line_boxes.is_empty() || line_boxes.last().is_empty_or_ends_in_whitespace())) {
|
2025-05-22 00:31:24 +12:00
|
|
|
if (item.node->computed_values().text_wrap_mode() == CSS::TextWrapMode::Wrap) {
|
2023-08-19 03:36:53 +00:00
|
|
|
auto next_width = iterator.next_non_whitespace_sequence_width();
|
|
|
|
|
if (next_width > 0)
|
|
|
|
|
line_builder.break_if_needed(next_width);
|
|
|
|
|
}
|
2024-01-20 20:15:09 +01:00
|
|
|
leading_margin_from_collapsible_whitespace += item.margin_start;
|
2026-02-07 21:37:47 +01:00
|
|
|
leading_border_from_collapsible_whitespace += item.border_start;
|
|
|
|
|
leading_padding_from_collapsible_whitespace += item.padding_start;
|
2022-01-21 14:15:10 +01:00
|
|
|
continue;
|
2023-08-19 03:36:53 +00:00
|
|
|
}
|
2022-01-21 14:15:10 +01:00
|
|
|
|
2024-01-20 20:15:09 +01:00
|
|
|
item.margin_start += leading_margin_from_collapsible_whitespace;
|
|
|
|
|
leading_margin_from_collapsible_whitespace = 0;
|
2026-02-07 21:37:47 +01:00
|
|
|
item.border_start += leading_border_from_collapsible_whitespace;
|
|
|
|
|
leading_border_from_collapsible_whitespace = 0;
|
|
|
|
|
item.padding_start += leading_padding_from_collapsible_whitespace;
|
|
|
|
|
leading_padding_from_collapsible_whitespace = 0;
|
2024-01-20 20:15:09 +01:00
|
|
|
|
2022-01-19 11:59:44 +01:00
|
|
|
switch (item.type) {
|
2023-07-19 23:44:40 +00:00
|
|
|
case InlineLevelIterator::Item::Type::ForcedBreak: {
|
2023-06-10 15:49:17 +02:00
|
|
|
line_builder.break_line(LineBuilder::ForcedBreak::Yes);
|
2023-07-19 23:44:40 +00:00
|
|
|
if (item.node) {
|
2023-07-29 04:05:45 +00:00
|
|
|
auto introduce_clearance = parent().clear_floating_boxes(*item.node, *this);
|
2025-03-27 11:34:20 +00:00
|
|
|
if (introduce_clearance == BlockFormattingContext::DidIntroduceClearance::Yes) {
|
2025-04-01 11:01:15 +02:00
|
|
|
line_builder.did_introduce_clearance(vertical_float_clearance());
|
2023-07-19 23:44:40 +00:00
|
|
|
parent().reset_margin_state();
|
2025-03-27 11:34:20 +00:00
|
|
|
}
|
2023-07-19 23:44:40 +00:00
|
|
|
}
|
2022-01-19 11:59:44 +01:00
|
|
|
break;
|
2023-07-19 23:44:40 +00:00
|
|
|
}
|
2022-01-19 11:59:44 +01:00
|
|
|
case InlineLevelIterator::Item::Type::Element: {
|
2025-01-21 09:12:05 -05:00
|
|
|
auto& box = as<Layout::Box>(*item.node);
|
2024-11-11 15:54:21 +01:00
|
|
|
compute_inset(box, content_box_rect(m_containing_block_used_values).size());
|
2025-05-22 00:31:24 +12:00
|
|
|
if (containing_block().computed_values().text_wrap_mode() == CSS::TextWrapMode::Wrap) {
|
2023-12-10 10:09:38 +01:00
|
|
|
auto minimum_space_needed_on_line = item.border_box_width();
|
|
|
|
|
if (item.margin_start < 0)
|
|
|
|
|
minimum_space_needed_on_line += item.margin_start;
|
|
|
|
|
if (item.margin_end < 0)
|
|
|
|
|
minimum_space_needed_on_line += item.margin_end;
|
|
|
|
|
line_builder.break_if_needed(minimum_space_needed_on_line);
|
2023-09-16 11:18:05 +02:00
|
|
|
}
|
2022-03-09 18:46:07 +01:00
|
|
|
line_builder.append_box(box, item.border_start + item.padding_start, item.padding_end + item.border_end, item.margin_start, item.margin_end);
|
2022-01-19 11:59:44 +01:00
|
|
|
break;
|
2022-01-17 15:07:19 +01:00
|
|
|
}
|
2022-03-07 22:27:09 +01:00
|
|
|
case InlineLevelIterator::Item::Type::AbsolutelyPositionedElement:
|
2025-08-25 07:22:57 +01:00
|
|
|
if (auto const* box = as_if<Box>(*item.node)) {
|
2024-09-21 19:46:37 +02:00
|
|
|
// Calculation of static position for absolute boxes is delayed until trailing whitespaces are removed.
|
2025-08-25 07:22:57 +01:00
|
|
|
absolute_boxes.append(box);
|
2024-09-10 19:02:03 +02:00
|
|
|
}
|
2022-03-07 22:27:09 +01:00
|
|
|
break;
|
|
|
|
|
|
2022-03-22 19:18:05 +01:00
|
|
|
case InlineLevelIterator::Item::Type::FloatingElement:
|
2025-08-25 07:22:57 +01:00
|
|
|
if (auto* box = as_if<Box>(*item.node)) {
|
2025-03-26 19:26:20 +00:00
|
|
|
(void)parent().clear_floating_boxes(*item.node, *this);
|
|
|
|
|
// Even if this introduces clearance, we do NOT reset the margin state, because that is clearance
|
|
|
|
|
// between floats and does not contribute to the height of the Inline Formatting Context.
|
2025-08-25 07:22:57 +01:00
|
|
|
parent().layout_floating_box(*box, containing_block(), *m_available_space, 0, &line_builder);
|
2023-07-29 04:05:45 +00:00
|
|
|
}
|
2022-03-22 19:18:05 +01:00
|
|
|
break;
|
|
|
|
|
|
2022-01-19 11:59:44 +01:00
|
|
|
case InlineLevelIterator::Item::Type::Text: {
|
2025-01-21 09:12:05 -05:00
|
|
|
auto& text_node = as<Layout::TextNode>(*item.node);
|
2022-04-03 21:05:09 +02:00
|
|
|
|
2025-05-22 00:31:24 +12:00
|
|
|
if (text_node.computed_values().text_wrap_mode() == CSS::TextWrapMode::Wrap) {
|
2023-08-19 03:36:53 +00:00
|
|
|
bool is_whitespace = false;
|
|
|
|
|
CSSPixels next_width = 0;
|
2022-03-29 13:35:21 +02:00
|
|
|
// If we're in a whitespace-collapsing context, we can simply check the flag.
|
2023-08-19 03:36:53 +00:00
|
|
|
if (item.is_collapsible_whitespace) {
|
|
|
|
|
is_whitespace = true;
|
|
|
|
|
next_width = iterator.next_non_whitespace_sequence_width();
|
|
|
|
|
} else {
|
|
|
|
|
// In whitespace-preserving contexts (white-space: pre*), we have to check manually.
|
2025-07-25 09:34:41 -04:00
|
|
|
auto view = text_node.text_for_rendering().substring_view(item.offset_in_node, item.length_in_node);
|
|
|
|
|
is_whitespace = view.is_ascii_whitespace();
|
2023-08-19 03:36:53 +00:00
|
|
|
if (is_whitespace)
|
|
|
|
|
next_width = iterator.next_non_whitespace_sequence_width();
|
|
|
|
|
}
|
2022-03-29 13:35:21 +02:00
|
|
|
|
2026-01-29 13:19:40 +01:00
|
|
|
// If whitespace caused us to break, don't put it on the next line.
|
|
|
|
|
if (is_whitespace && next_width > 0 && line_builder.break_if_needed(item.border_box_width() + next_width)) {
|
|
|
|
|
// Record that the previous line has trailing whitespace for text selection.
|
|
|
|
|
line_builder.set_trailing_whitespace_on_previous_line();
|
2022-03-29 13:35:21 +02:00
|
|
|
break;
|
2026-01-29 13:19:40 +01:00
|
|
|
}
|
2026-01-20 09:23:51 +00:00
|
|
|
|
2026-03-25 17:03:03 +00:00
|
|
|
// https://drafts.csswg.org/css2/#floats
|
|
|
|
|
// If a shortened line box is too small to contain any content, then the line box is shifted downward
|
|
|
|
|
// (and its width recomputed) until either some content fits or there are no more floats present.
|
|
|
|
|
if (!is_whitespace && (item.can_break_before || line_boxes.last().is_empty()))
|
2026-01-20 09:23:51 +00:00
|
|
|
line_builder.break_if_needed(item.border_box_width());
|
2022-03-26 18:50:43 +01:00
|
|
|
}
|
2022-01-19 11:59:44 +01:00
|
|
|
line_builder.append_text_chunk(
|
2022-01-17 15:07:19 +01:00
|
|
|
text_node,
|
|
|
|
|
item.offset_in_node,
|
|
|
|
|
item.length_in_node,
|
2022-02-14 15:52:29 +01:00
|
|
|
item.border_start + item.padding_start,
|
|
|
|
|
item.padding_end + item.border_end,
|
2022-03-09 18:46:07 +01:00
|
|
|
item.margin_start,
|
|
|
|
|
item.margin_end,
|
2022-01-17 15:07:19 +01:00
|
|
|
item.width,
|
2024-01-12 15:34:13 +01:00
|
|
|
text_node.computed_values().line_height(),
|
2024-03-24 16:51:04 +01:00
|
|
|
move(item.glyph_run));
|
2022-01-19 11:59:44 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2022-01-17 15:07:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-27 11:34:20 +00:00
|
|
|
for (auto& line_box : line_boxes)
|
2022-01-17 15:07:19 +01:00
|
|
|
line_box.trim_trailing_whitespace();
|
|
|
|
|
|
2026-03-23 22:35:07 +01:00
|
|
|
apply_text_overflow_ellipsis(line_boxes);
|
|
|
|
|
|
2022-01-22 10:32:49 +01:00
|
|
|
line_builder.remove_last_line_if_empty();
|
2022-03-12 17:01:06 +00:00
|
|
|
|
|
|
|
|
auto const& containing_block = this->containing_block();
|
|
|
|
|
auto text_align = containing_block.computed_values().text_align();
|
2022-03-12 19:32:03 +00:00
|
|
|
auto text_justify = containing_block.computed_values().text_justify();
|
2022-03-12 17:01:06 +00:00
|
|
|
if (text_align == CSS::TextAlign::Justify) {
|
|
|
|
|
for (size_t i = 0; i < line_boxes.size(); i++) {
|
|
|
|
|
auto& line_box = line_boxes[i];
|
|
|
|
|
auto is_last_line = i == line_boxes.size() - 1;
|
2022-07-09 20:56:59 +02:00
|
|
|
apply_justification_to_fragments(text_justify, line_box, is_last_line);
|
2022-03-12 17:01:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-09-21 19:46:37 +02:00
|
|
|
|
2025-03-06 18:10:38 +05:00
|
|
|
for (auto& line_box : line_boxes) {
|
|
|
|
|
for (auto& fragment : line_box.fragments()) {
|
|
|
|
|
if (fragment.layout_node().is_inline_block()) {
|
|
|
|
|
auto& box = as<Box>(fragment.layout_node());
|
|
|
|
|
auto& box_state = m_state.get_mutable(box);
|
|
|
|
|
box_state.set_content_offset(fragment.offset());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-28 00:03:09 +02:00
|
|
|
line_builder.update_last_line();
|
|
|
|
|
|
2026-02-27 10:40:27 +01:00
|
|
|
if (m_layout_mode == LayoutMode::Normal) {
|
|
|
|
|
for (auto* box : absolute_boxes) {
|
|
|
|
|
auto& box_state = m_state.get_mutable(*box);
|
|
|
|
|
box_state.set_static_position_rect(calculate_static_position_rect(*box));
|
|
|
|
|
}
|
2024-09-21 19:46:37 +02:00
|
|
|
}
|
2022-01-17 15:07:19 +01:00
|
|
|
}
|
|
|
|
|
|
2024-10-29 11:32:59 +00:00
|
|
|
bool InlineFormattingContext::any_floats_intrude_at_block_offset(CSSPixels block_offset) const
|
2022-09-11 22:39:01 +02:00
|
|
|
{
|
2024-03-15 19:25:00 +01:00
|
|
|
auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(m_containing_block_used_values, parent().root());
|
2024-10-29 11:32:59 +00:00
|
|
|
// FIXME: Respect inline direction.
|
|
|
|
|
CSSPixels y_in_root = box_in_root_rect.y() + block_offset;
|
2023-06-13 13:37:15 +00:00
|
|
|
auto space_and_containing_margin = parent().space_used_and_containing_margin_for_floats(y_in_root);
|
|
|
|
|
return space_and_containing_margin.left_used_space > 0 || space_and_containing_margin.right_used_space > 0;
|
2022-09-11 22:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-29 11:32:59 +00:00
|
|
|
bool InlineFormattingContext::can_fit_new_line_at_block_offset(CSSPixels block_offset) const
|
2022-09-16 14:21:52 +02:00
|
|
|
{
|
2024-10-29 11:32:59 +00:00
|
|
|
// FIXME: Respect inline direction.
|
|
|
|
|
|
|
|
|
|
auto top_intrusions = parent().intrusion_by_floats_into_box(m_containing_block_used_values, block_offset);
|
|
|
|
|
auto bottom_intrusions = parent().intrusion_by_floats_into_box(m_containing_block_used_values, block_offset + containing_block().computed_values().line_height() - 1);
|
2023-05-16 09:46:45 +02:00
|
|
|
|
|
|
|
|
auto left_edge = [](auto& space) -> CSSPixels {
|
|
|
|
|
return space.left;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto right_edge = [this](auto& space) -> CSSPixels {
|
2023-08-12 18:30:18 +02:00
|
|
|
return m_available_space->width.to_px_or_zero() - space.right;
|
2023-05-16 09:46:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto top_left_edge = left_edge(top_intrusions);
|
|
|
|
|
auto top_right_edge = right_edge(top_intrusions);
|
|
|
|
|
auto bottom_left_edge = left_edge(bottom_intrusions);
|
|
|
|
|
auto bottom_right_edge = right_edge(bottom_intrusions);
|
2022-09-16 14:21:52 +02:00
|
|
|
|
|
|
|
|
if (top_left_edge > bottom_right_edge)
|
|
|
|
|
return false;
|
|
|
|
|
if (bottom_left_edge > top_right_edge)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-29 04:05:45 +00:00
|
|
|
CSSPixels InlineFormattingContext::vertical_float_clearance() const
|
|
|
|
|
{
|
|
|
|
|
return m_vertical_float_clearance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InlineFormattingContext::set_vertical_float_clearance(CSSPixels vertical_float_clearance)
|
|
|
|
|
{
|
|
|
|
|
m_vertical_float_clearance = vertical_float_clearance;
|
|
|
|
|
}
|
2024-10-05 22:18:53 +02:00
|
|
|
|
|
|
|
|
StaticPositionRect InlineFormattingContext::calculate_static_position_rect(Box const& box) const
|
|
|
|
|
{
|
|
|
|
|
VERIFY(box.parent());
|
|
|
|
|
VERIFY(box.parent()->children_are_inline());
|
2025-08-28 00:03:09 +02:00
|
|
|
|
|
|
|
|
CSSPixelPoint position;
|
2024-10-05 22:18:53 +02:00
|
|
|
if (auto const* sibling = box.previous_sibling()) {
|
2025-09-09 00:35:59 +02:00
|
|
|
// We're calculating the position for an absolutely positioned box with a previous sibling in an IFC.
|
|
|
|
|
// We need to position the box...
|
|
|
|
|
// ...below the last fragment of this sibling, if the display-outside value (before box type transformation) is block.
|
|
|
|
|
// ...at the top right corner of the last fragment of this sibling otherwise.
|
2024-10-05 22:18:53 +02:00
|
|
|
LineBoxFragment const* last_fragment = nullptr;
|
|
|
|
|
auto const& cb_state = m_state.get(*sibling->containing_block());
|
|
|
|
|
for (auto const& line_box : cb_state.line_boxes) {
|
|
|
|
|
for (auto const& fragment : line_box.fragments()) {
|
|
|
|
|
if (&fragment.layout_node() == sibling)
|
|
|
|
|
last_fragment = &fragment;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (last_fragment) {
|
2025-09-09 00:35:59 +02:00
|
|
|
if (box.display_before_box_type_transformation().is_block_outside()) {
|
|
|
|
|
// Display-outside value is block => position below
|
|
|
|
|
position.set_x(0);
|
|
|
|
|
position.set_y(last_fragment->offset().y() + last_fragment->height());
|
|
|
|
|
} else {
|
|
|
|
|
// Display-outside value is not block => position to the right
|
|
|
|
|
position.set_x(last_fragment->offset().x() + last_fragment->width());
|
|
|
|
|
position.set_y(last_fragment->offset().y());
|
|
|
|
|
}
|
2024-10-05 22:18:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-08-28 00:03:09 +02:00
|
|
|
|
|
|
|
|
return { .rect = { position, { 0, 0 } } };
|
2024-10-05 22:18:53 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-22 13:38:18 +01:00
|
|
|
}
|