1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 03:58:12 +00:00

LibWeb: Rename Layout::Box::size() to content_size()

This property represents the CSS content size, so let's reduce ambiguity
by using the spec terminology.

We also bring a bunch of related functions along for the ride.
This commit is contained in:
Andreas Kling 2022-02-06 00:49:09 +01:00
parent dbe5af3c6f
commit 0608de8c12
17 changed files with 140 additions and 140 deletions

View file

@ -260,14 +260,14 @@ int Window::inner_width() const
{
if (!associated_document().layout_node())
return 0;
return associated_document().layout_node()->width();
return associated_document().layout_node()->content_width();
}
int Window::inner_height() const
{
if (!associated_document().layout_node())
return 0;
return associated_document().layout_node()->height();
return associated_document().layout_node()->content_height();
}
Page* Window::page()

View file

@ -168,8 +168,8 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
builder.appendff("at ({},{}) size {}x{}",
box.absolute_x(),
box.absolute_y(),
box.width(),
box.height());
box.content_width(),
box.content_height());
if (box.is_positioned())
builder.appendff(" {}positioned{}", positioned_color_on, color_off);
@ -204,7 +204,7 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
box.box_model().margin.left,
box.box_model().border.left,
box.box_model().padding.left,
box.width(),
box.content_width(),
box.box_model().padding.right,
box.box_model().border.right,
box.box_model().margin.right);
@ -214,7 +214,7 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
box.box_model().margin.top,
box.box_model().border.top,
box.box_model().padding.top,
box.height(),
box.content_height(),
box.box_model().padding.bottom,
box.box_model().border.bottom,
box.box_model().margin.bottom);

View file

@ -61,7 +61,7 @@ void InProcessWebView::set_preferred_color_scheme(CSS::PreferredColorScheme colo
void InProcessWebView::page_did_layout()
{
VERIFY(layout_root());
set_content_size(layout_root()->size().to_type<int>());
set_content_size(layout_root()->content_size().to_type<int>());
}
void InProcessWebView::page_did_change_title(const String& title)
@ -177,13 +177,13 @@ void InProcessWebView::layout_and_sync_size()
bool had_horizontal_scrollbar = horizontal_scrollbar().is_visible();
page().top_level_browsing_context().set_size(available_size());
set_content_size(layout_root()->size().to_type<int>());
set_content_size(layout_root()->content_size().to_type<int>());
// NOTE: If layout caused us to gain or lose scrollbars, we have to lay out again
// since the scrollbars now take up some of the available space.
if (had_vertical_scrollbar != vertical_scrollbar().is_visible() || had_horizontal_scrollbar != horizontal_scrollbar().is_visible()) {
page().top_level_browsing_context().set_size(available_size());
set_content_size(layout_root()->size().to_type<int>());
set_content_size(layout_root()->content_size().to_type<int>());
}
page().top_level_browsing_context().set_viewport_scroll_offset({ horizontal_scrollbar().value(), vertical_scrollbar().value() });

View file

@ -121,7 +121,7 @@ void BlockFormattingContext::compute_width(Box& box)
}
auto& computed_values = box.computed_values();
float width_of_containing_block = box.containing_block()->width();
float width_of_containing_block = box.containing_block()->content_width();
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
auto zero_value = CSS::Length::make_px(0);
@ -231,7 +231,7 @@ void BlockFormattingContext::compute_width(Box& box)
}
}
box.set_width(used_width.to_px(box));
box.set_content_width(used_width.to_px(box));
box.box_model().margin.left = margin_left.to_px(box);
box.box_model().margin.right = margin_right.to_px(box);
box.box_model().border.left = computed_values.border_left().width;
@ -244,7 +244,7 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box)
{
// 10.3.5 Floating, non-replaced elements
auto& computed_values = box.computed_values();
float width_of_containing_block = box.containing_block()->width();
float width_of_containing_block = box.containing_block()->content_width();
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
auto zero_value = CSS::Length::make_px(0);
@ -278,7 +278,7 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box)
}
float final_width = width.resolved_or_zero(box).to_px(box);
box.set_width(final_width);
box.set_content_width(final_width);
box.box_model().margin.left = margin_left.to_px(box);
box.box_model().margin.right = margin_right.to_px(box);
box.box_model().border.left = computed_values.border_left().width;
@ -289,14 +289,14 @@ void BlockFormattingContext::compute_width_for_floating_box(Box& box)
void BlockFormattingContext::compute_width_for_block_level_replaced_element_in_normal_flow(ReplacedBox& box)
{
box.set_width(compute_width_for_replaced_element(box));
box.set_content_width(compute_width_for_replaced_element(box));
}
float BlockFormattingContext::compute_theoretical_height(Box const& box)
{
auto& computed_values = box.computed_values();
auto& containing_block = *box.containing_block();
auto containing_block_height = CSS::Length::make_px(containing_block.height());
auto containing_block_height = CSS::Length::make_px(containing_block.content_height());
auto is_absolute = [](CSS::LengthPercentage const& length_percentage) {
return length_percentage.is_length() && length_percentage.length().is_absolute();
@ -330,7 +330,7 @@ void BlockFormattingContext::compute_height(Box& box)
{
auto& computed_values = box.computed_values();
auto& containing_block = *box.containing_block();
auto width_of_containing_block_as_length = CSS::Length::make_px(containing_block.width());
auto width_of_containing_block_as_length = CSS::Length::make_px(containing_block.content_width());
// First, resolve the top/bottom parts of the surrounding box model.
@ -344,7 +344,7 @@ void BlockFormattingContext::compute_height(Box& box)
box.box_model().padding.bottom = computed_values.padding().bottom.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box).to_px(box);
auto height = compute_theoretical_height(box);
box.set_height(height);
box.set_content_height(height);
}
void BlockFormattingContext::compute_position(Box& box)
@ -354,7 +354,7 @@ void BlockFormattingContext::compute_position(Box& box)
auto& box_model = box.box_model();
auto& computed_values = box.computed_values();
float width_of_containing_block = box.containing_block()->width();
float width_of_containing_block = box.containing_block()->content_width();
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
auto specified_left = computed_values.offset().left.resolved(box, width_of_containing_block_as_length).resolved_or_zero(box);
@ -424,14 +424,14 @@ void BlockFormattingContext::layout_block_level_children(BlockContainer& block_c
if (is<ListItemBox>(child_box))
verify_cast<ListItemBox>(child_box).layout_marker();
content_height = max(content_height, child_box.effective_offset().y() + child_box.height() + child_box.box_model().margin_box().bottom);
content_width = max(content_width, verify_cast<Box>(child_box).width());
content_height = max(content_height, child_box.effective_offset().y() + child_box.content_height() + child_box.box_model().margin_box().bottom);
content_width = max(content_width, child_box.content_width());
return IterationDecision::Continue;
});
if (layout_mode != LayoutMode::Default) {
if (block_container.computed_values().width().is_length() && block_container.computed_values().width().length().is_undefined_or_auto())
block_container.set_width(content_width);
block_container.set_content_width(content_width);
}
}
@ -439,7 +439,7 @@ void BlockFormattingContext::compute_vertical_box_model_metrics(Box& child_box,
{
auto& box_model = child_box.box_model();
auto const& computed_values = child_box.computed_values();
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width());
box_model.margin.top = computed_values.margin().top.resolved(child_box, width_of_containing_block).resolved_or_zero(containing_block).to_px(child_box);
box_model.margin.bottom = computed_values.margin().bottom.resolved(child_box, width_of_containing_block).resolved_or_zero(containing_block).to_px(child_box);
@ -474,7 +474,7 @@ void BlockFormattingContext::place_block_level_element_in_normal_flow_vertically
if (relevant_sibling) {
y += relevant_sibling->effective_offset().y()
+ relevant_sibling->height()
+ relevant_sibling->content_height()
+ relevant_sibling->box_model().border_box().bottom;
// Collapse top margin with bottom margin of preceding siblings if needed
@ -519,7 +519,7 @@ void BlockFormattingContext::place_block_level_element_in_normal_flow_horizontal
float x = 0;
if (containing_block.computed_values().text_align() == CSS::TextAlign::LibwebCenter) {
x = (containing_block.width() / 2) - child_box.width() / 2;
x = (containing_block.content_width() / 2) - child_box.content_width() / 2;
} else {
x = box_model.margin_box().left + box_model.offset.left;
}
@ -534,8 +534,8 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m
auto& icb = verify_cast<Layout::InitialContainingBlock>(root());
icb.build_stacking_context_tree();
icb.set_width(viewport_rect.width());
icb.set_height(viewport_rect.height());
icb.set_content_width(viewport_rect.width());
icb.set_content_height(viewport_rect.height());
VERIFY(!icb.children_are_inline());
layout_block_level_children(root(), layout_mode);
@ -589,7 +589,7 @@ void BlockFormattingContext::layout_floating_child(Box& box, BlockContainer cons
if (side == FloatSide::Left)
x = box.box_model().margin_box().left;
else
x = containing_block.width() - box.box_model().margin_box().right - box.width();
x = containing_block.content_width() - box.box_model().margin_box().right - box.content_width();
side_data.y_offset = 0;
} else {
auto& previous_box = side_data.boxes.last();
@ -604,21 +604,21 @@ void BlockFormattingContext::layout_floating_child(Box& box, BlockContainer cons
if (side == FloatSide::Left) {
auto previous_right_border_edge = previous_box.effective_offset().x()
+ previous_box.width()
+ previous_box.content_width()
+ previous_box.box_model().padding.right
+ previous_box.box_model().border.right
+ margin_collapsed_with_previous;
wanted_x = previous_right_border_edge + box.box_model().border.left + box.box_model().padding.left;
fits_on_line = (wanted_x + box.width() + box.box_model().padding.right + box.box_model().border.right + box.box_model().margin.right) <= containing_block.width();
fits_on_line = (wanted_x + box.content_width() + box.box_model().padding.right + box.box_model().border.right + box.box_model().margin.right) <= containing_block.content_width();
} else {
auto previous_left_border_edge = previous_box.effective_offset().x()
- previous_box.width()
- previous_box.content_width()
- previous_box.box_model().padding.left
- previous_box.box_model().border.left
- margin_collapsed_with_previous;
wanted_x = previous_left_border_edge - box.box_model().border.right - box.box_model().padding.right - box.width();
wanted_x = previous_left_border_edge - box.box_model().border.right - box.box_model().padding.right - box.content_width();
fits_on_line = (wanted_x - box.box_model().padding.left - box.box_model().border.left - box.box_model().margin.left) >= 0;
}

View file

@ -39,9 +39,9 @@ void Box::paint(PaintContext& context, PaintPhase phase)
auto margin_box = box_model().margin_box();
Gfx::FloatRect margin_rect;
margin_rect.set_x(absolute_x() - margin_box.left);
margin_rect.set_width(width() + margin_box.left + margin_box.right);
margin_rect.set_width(content_width() + margin_box.left + margin_box.right);
margin_rect.set_y(absolute_y() - margin_box.top);
margin_rect.set_height(height() + margin_box.top + margin_box.bottom);
margin_rect.set_height(content_height() + margin_box.top + margin_box.bottom);
context.painter().draw_rect(enclosing_int_rect(margin_rect), Color::Yellow);
context.painter().draw_rect(enclosing_int_rect(padded_rect()), Color::Cyan);
@ -180,11 +180,11 @@ void Box::set_offset(const Gfx::FloatPoint& offset)
did_set_rect();
}
void Box::set_size(const Gfx::FloatSize& size)
void Box::set_content_size(Gfx::FloatSize const& size)
{
if (m_size == size)
if (m_content_size == size)
return;
m_size = size;
m_content_size = size;
did_set_rect();
}
@ -197,7 +197,7 @@ Gfx::FloatPoint Box::effective_offset() const
const Gfx::FloatRect Box::absolute_rect() const
{
Gfx::FloatRect rect { effective_offset(), size() };
Gfx::FloatRect rect { effective_offset(), content_size() };
for (auto* block = containing_block(); block; block = block->containing_block()) {
rect.translate_by(block->effective_offset());
}

View file

@ -28,23 +28,23 @@ public:
void set_offset(const Gfx::FloatPoint& offset);
void set_offset(float x, float y) { set_offset({ x, y }); }
const Gfx::FloatSize& size() const { return m_size; }
void set_size(const Gfx::FloatSize&);
void set_size(float width, float height) { set_size({ width, height }); }
Gfx::FloatSize const& content_size() const { return m_content_size; }
void set_content_size(Gfx::FloatSize const&);
void set_content_size(float width, float height) { set_content_size({ width, height }); }
void set_width(float width) { set_size(width, height()); }
void set_height(float height) { set_size(width(), height); }
float width() const { return m_size.width(); }
float height() const { return m_size.height(); }
void set_content_width(float width) { set_content_size(width, content_height()); }
void set_content_height(float height) { set_content_size(content_width(), height); }
float content_width() const { return m_content_size.width(); }
float content_height() const { return m_content_size.height(); }
Gfx::FloatRect padded_rect() const
{
auto absolute_rect = this->absolute_rect();
Gfx::FloatRect rect;
rect.set_x(absolute_rect.x() - box_model().padding.left);
rect.set_width(width() + box_model().padding.left + box_model().padding.right);
rect.set_width(content_width() + box_model().padding.left + box_model().padding.right);
rect.set_y(absolute_rect.y() - box_model().padding.top);
rect.set_height(height() + box_model().padding.top + box_model().padding.bottom);
rect.set_height(content_height() + box_model().padding.top + box_model().padding.bottom);
return rect;
}
@ -62,30 +62,30 @@ public:
float margin_box_width() const
{
auto margin_box = box_model().margin_box();
return width() + margin_box.left + margin_box.right;
return content_width() + margin_box.left + margin_box.right;
}
float margin_box_height() const
{
auto margin_box = box_model().margin_box();
return height() + margin_box.top + margin_box.bottom;
return content_height() + margin_box.top + margin_box.bottom;
}
float border_box_width() const
{
auto border_box = box_model().border_box();
return width() + border_box.left + border_box.right;
return content_width() + border_box.left + border_box.right;
}
float border_box_height() const
{
auto border_box = box_model().border_box();
return height() + border_box.top + border_box.bottom;
return content_height() + border_box.top + border_box.bottom;
}
Gfx::FloatRect content_box_as_relative_rect() const
{
return { m_offset, m_size };
return { m_offset, m_content_size };
}
Gfx::FloatRect border_box_as_relative_rect() const
@ -195,7 +195,7 @@ private:
virtual bool is_box() const final { return true; }
Gfx::FloatPoint m_offset;
Gfx::FloatSize m_size;
Gfx::FloatSize m_content_size;
// Some boxes hang off of line box fragments. (inline-block, inline-table, replaced, etc)
WeakPtr<LineBoxFragment> m_containing_line_box_fragment;

View file

@ -19,7 +19,7 @@ namespace Web::Layout {
static float get_pixel_size(Box const& box, CSS::LengthPercentage const& length_percentage)
{
auto inner_main_size = CSS::Length::make_px(box.containing_block()->width());
auto inner_main_size = CSS::Length::make_px(box.containing_block()->content_width());
return length_percentage.resolved(box, inner_main_size)
.resolved(CSS::Length::make_px(0), box)
.to_px(box);
@ -114,7 +114,7 @@ void FlexFormattingContext::run(Box& run_box, LayoutMode)
void FlexFormattingContext::populate_specified_margins(FlexItem& item, CSS::FlexDirection flex_direction) const
{
auto width_of_containing_block = item.box.containing_block()->width();
auto width_of_containing_block = item.box.containing_block()->content_width();
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
// FIXME: This should also take reverse-ness into account
if (flex_direction == CSS::FlexDirection::Row || flex_direction == CSS::FlexDirection::RowReverse) {
@ -140,19 +140,19 @@ void FlexFormattingContext::generate_anonymous_flex_items()
// This is particularly important since we take references to the items stored in flex_items
// later, whose addresses won't be stable if we added or removed any items.
if (!flex_container().has_definite_width()) {
flex_container().set_width(flex_container().containing_block()->width());
flex_container().set_content_width(flex_container().containing_block()->content_width());
} else {
auto container_width = flex_container().containing_block()->width();
auto container_width = flex_container().containing_block()->content_width();
auto width = flex_container().computed_values().width().resolved(flex_container(), CSS::Length::make_px(container_width)).resolved_or_zero(flex_container()).to_px(flex_container());
flex_container().set_width(width);
flex_container().set_content_width(width);
}
if (!flex_container().has_definite_height()) {
flex_container().set_height(flex_container().containing_block()->height());
flex_container().set_content_height(flex_container().containing_block()->content_height());
} else {
auto container_height = flex_container().containing_block()->height();
auto container_height = flex_container().containing_block()->content_height();
auto height = flex_container().computed_values().height().resolved(flex_container(), CSS::Length::make_px(container_height)).resolved_or_zero(flex_container()).to_px(flex_container());
flex_container().set_height(height);
flex_container().set_content_height(height);
}
flex_container().for_each_child_of_type<Box>([&](Box& child_box) {
@ -190,12 +190,12 @@ bool FlexFormattingContext::has_definite_main_size(Box const& box) const
float FlexFormattingContext::specified_main_size(Box const& box) const
{
return is_row_layout() ? box.width() : box.height();
return is_row_layout() ? box.content_width() : box.content_height();
}
float FlexFormattingContext::specified_cross_size(Box const& box) const
{
return is_row_layout() ? box.height() : box.width();
return is_row_layout() ? box.content_height() : box.content_width();
}
bool FlexFormattingContext::has_main_min_size(Box const& box) const
@ -285,7 +285,7 @@ float FlexFormattingContext::specified_cross_max_size(Box const& box) const
float FlexFormattingContext::calculated_main_size(Box const& box) const
{
return is_row_layout() ? box.width() : box.height();
return is_row_layout() ? box.content_width() : box.content_height();
}
bool FlexFormattingContext::is_cross_auto(Box const& box) const
@ -312,17 +312,17 @@ bool FlexFormattingContext::is_main_axis_margin_second_auto(Box const& box) cons
void FlexFormattingContext::set_main_size(Box& box, float size)
{
if (is_row_layout())
box.set_width(size);
box.set_content_width(size);
else
box.set_height(size);
box.set_content_height(size);
}
void FlexFormattingContext::set_cross_size(Box& box, float size)
{
if (is_row_layout())
box.set_height(size);
box.set_content_height(size);
else
box.set_width(size);
box.set_content_width(size);
}
void FlexFormattingContext::set_offset(Box& box, float main_offset, float cross_offset)
@ -372,12 +372,12 @@ FlexFormattingContext::AvailableSpace FlexFormattingContext::determine_available
auto containing_block_effective_main_size = [&](Box const& box) {
if (is_row_layout()) {
if (box.containing_block()->has_definite_width())
return box.containing_block()->width();
return box.containing_block()->content_width();
main_size_is_infinite = true;
return NumericLimits<float>::max();
} else {
if (box.containing_block()->has_definite_height())
return box.containing_block()->height();
return box.containing_block()->content_height();
main_size_is_infinite = true;
return NumericLimits<float>::max();
}
@ -459,15 +459,15 @@ float FlexFormattingContext::layout_for_maximum_main_size(Box& box)
if (is_row_layout()) {
ifc.run(box, LayoutMode::OnlyRequiredLineBreaks);
return box.width();
return box.content_width();
} else {
ifc.run(box, LayoutMode::AllPossibleLineBreaks);
return box.height();
return box.content_height();
}
}
if (is_row_layout()) {
(void)layout_inside(box, LayoutMode::OnlyRequiredLineBreaks);
return box.width();
return box.content_width();
} else {
return BlockFormattingContext::compute_theoretical_height(box);
}
@ -808,14 +808,14 @@ float FlexFormattingContext::determine_hypothetical_cross_size_of_item(Box& box)
InlineFormattingContext ifc(block_container, bfc);
ifc.run(box, LayoutMode::OnlyRequiredLineBreaks);
return is_row_layout() ? box.height() : box.width();
return is_row_layout() ? box.content_height() : box.content_width();
}
if (is_row_layout())
return BlockFormattingContext::compute_theoretical_height(box);
BlockFormattingContext context(verify_cast<BlockContainer>(box), this);
context.compute_width(box);
return box.width();
return box.content_width();
}
// https://www.w3.org/TR/css-flexbox-1/#algo-cross-line

View file

@ -154,8 +154,8 @@ static Gfx::FloatSize solve_replaced_size_constraint(float w, float h, const Rep
// 10.4 Minimum and maximum widths: 'min-width' and 'max-width'
auto& containing_block = *box.containing_block();
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
auto height_of_containing_block = CSS::Length::make_px(containing_block.height());
auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width());
auto height_of_containing_block = CSS::Length::make_px(containing_block.content_height());
auto specified_min_width = box.computed_values().min_width().resolved(box, width_of_containing_block).resolved_or_zero(box).to_px(box);
auto specified_max_width = box.computed_values().max_width().resolved(box, width_of_containing_block).resolved(CSS::Length::make_px(w), box).to_px(box);
@ -217,7 +217,7 @@ float FormattingContext::compute_auto_height_for_block_level_element(Box const&
return IterationDecision::Continue;
float child_box_top = child_box.effective_offset().y() - child_box.box_model().margin_box().top;
float child_box_bottom = child_box.effective_offset().y() + child_box.height() + child_box.box_model().margin_box().bottom;
float child_box_bottom = child_box.effective_offset().y() + child_box.content_height() + child_box.box_model().margin_box().bottom;
if (!top.has_value() || child_box_top < top.value())
top = child_box_top;
@ -235,7 +235,7 @@ float FormattingContext::compute_auto_height_for_block_level_element(Box const&
if (!child_box.is_floating())
return IterationDecision::Continue;
float child_box_bottom = child_box.effective_offset().y() + child_box.height();
float child_box_bottom = child_box.effective_offset().y() + child_box.content_height();
if (!bottom.has_value() || child_box_bottom > bottom.value())
bottom = child_box_bottom;
@ -251,7 +251,7 @@ float FormattingContext::compute_auto_height_for_block_level_element(Box const&
float FormattingContext::tentative_width_for_replaced_element(ReplacedBox const& box, CSS::Length const& computed_width)
{
auto& containing_block = *box.containing_block();
auto height_of_containing_block = CSS::Length::make_px(containing_block.height());
auto height_of_containing_block = CSS::Length::make_px(containing_block.content_height());
auto computed_height = box.computed_values().height().resolved(box, height_of_containing_block).resolved_or_auto(box);
float used_width = computed_width.to_px(box);
@ -312,7 +312,7 @@ float FormattingContext::compute_width_for_replaced_element(const ReplacedBox& b
auto zero_value = CSS::Length::make_px(0);
auto& containing_block = *box.containing_block();
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width());
auto margin_left = box.computed_values().margin().left.resolved(box, width_of_containing_block).resolved_or_zero(box);
auto margin_right = box.computed_values().margin().right.resolved(box, width_of_containing_block).resolved_or_zero(box);
@ -354,7 +354,7 @@ float FormattingContext::compute_width_for_replaced_element(const ReplacedBox& b
float FormattingContext::tentative_height_for_replaced_element(ReplacedBox const& box, CSS::Length const& computed_height)
{
auto& containing_block = *box.containing_block();
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width());
auto computed_width = box.computed_values().width().resolved(box, width_of_containing_block).resolved_or_auto(box);
// If 'height' and 'width' both have computed values of 'auto' and the element also has
@ -387,8 +387,8 @@ float FormattingContext::compute_height_for_replaced_element(const ReplacedBox&
// 'inline-block' replaced elements in normal flow and floating replaced elements
auto& containing_block = *box.containing_block();
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
auto height_of_containing_block = CSS::Length::make_px(containing_block.height());
auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width());
auto height_of_containing_block = CSS::Length::make_px(containing_block.content_height());
auto specified_width = box.computed_values().width().resolved(box, width_of_containing_block).resolved_or_auto(box);
auto specified_height = box.computed_values().height().resolved(box, height_of_containing_block).resolved_or_auto(box);
@ -406,7 +406,7 @@ float FormattingContext::compute_height_for_replaced_element(const ReplacedBox&
void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_element(Box& box)
{
auto& containing_block = *box.containing_block();
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width());
auto& computed_values = box.computed_values();
auto zero_value = CSS::Length::make_px(0);
@ -426,15 +426,15 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele
auto width = a_width;
auto solve_for_left = [&] {
return CSS::Length(containing_block.width() - margin_left.to_px(box) - border_left - padding_left.to_px(box) - width.to_px(box) - padding_right.to_px(box) - border_right - margin_right.to_px(box) - right.to_px(box), CSS::Length::Type::Px);
return CSS::Length(containing_block.content_width() - margin_left.to_px(box) - border_left - padding_left.to_px(box) - width.to_px(box) - padding_right.to_px(box) - border_right - margin_right.to_px(box) - right.to_px(box), CSS::Length::Type::Px);
};
auto solve_for_width = [&] {
return CSS::Length(containing_block.width() - left.to_px(box) - margin_left.to_px(box) - border_left - padding_left.to_px(box) - padding_right.to_px(box) - border_right - margin_right.to_px(box) - right.to_px(box), CSS::Length::Type::Px);
return CSS::Length(containing_block.content_width() - left.to_px(box) - margin_left.to_px(box) - border_left - padding_left.to_px(box) - padding_right.to_px(box) - border_right - margin_right.to_px(box) - right.to_px(box), CSS::Length::Type::Px);
};
auto solve_for_right = [&] {
return CSS::Length(containing_block.width() - left.to_px(box) - margin_left.to_px(box) - border_left - padding_left.to_px(box) - width.to_px(box) - padding_right.to_px(box) - border_right - margin_right.to_px(box), CSS::Length::Type::Px);
return CSS::Length(containing_block.content_width() - left.to_px(box) - margin_left.to_px(box) - border_left - padding_left.to_px(box) - width.to_px(box) - padding_right.to_px(box) - border_right - margin_right.to_px(box), CSS::Length::Type::Px);
};
// If all three of 'left', 'width', and 'right' are 'auto':
@ -534,7 +534,7 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele
}
}
box.set_width(used_width.to_px(box));
box.set_content_width(used_width.to_px(box));
box.box_model().margin.left = margin_left.to_px(box);
box.box_model().margin.right = margin_right.to_px(box);
@ -549,15 +549,15 @@ void FormattingContext::compute_width_for_absolutely_positioned_replaced_element
// 10.3.8 Absolutely positioned, replaced elements
// The used value of 'width' is determined as for inline replaced elements.
box.prepare_for_replaced_layout();
box.set_width(compute_width_for_replaced_element(box));
box.set_content_width(compute_width_for_replaced_element(box));
}
void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_element(Box& box)
{
auto& computed_values = box.computed_values();
auto& containing_block = *box.containing_block();
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
auto height_of_containing_block = CSS::Length::make_px(containing_block.height());
auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width());
auto height_of_containing_block = CSS::Length::make_px(containing_block.content_height());
CSS::Length specified_top = computed_values.offset().top.resolved(box, height_of_containing_block).resolved_or_auto(box);
CSS::Length specified_bottom = computed_values.offset().bottom.resolved(box, height_of_containing_block).resolved_or_auto(box);
@ -585,7 +585,7 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
const auto& border = box.box_model().border;
specified_height = CSS::Length(compute_auto_height_for_block_level_element(box), CSS::Length::Type::Px);
box.box_model().offset.bottom = containing_block.height() - specified_height.to_px(box) - specified_top.to_px(box) - margin.top - padding.top - border.top - margin.bottom - padding.bottom - border.bottom;
box.box_model().offset.bottom = containing_block.content_height() - specified_height.to_px(box) - specified_top.to_px(box) - margin.top - padding.top - border.top - margin.bottom - padding.bottom - border.bottom;
}
else if (specified_height.is_auto() && !specified_top.is_auto() && !specified_bottom.is_auto()) {
@ -593,7 +593,7 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
const auto& padding = box.box_model().padding;
const auto& border = box.box_model().border;
specified_height = CSS::Length(containing_block.height() - specified_top.to_px(box) - margin.top - padding.top - border.top - specified_bottom.to_px(box) - margin.bottom - padding.bottom - border.bottom, CSS::Length::Type::Px);
specified_height = CSS::Length(containing_block.content_height() - specified_top.to_px(box) - margin.top - padding.top - border.top - specified_bottom.to_px(box) - margin.bottom - padding.bottom - border.bottom, CSS::Length::Type::Px);
}
if (!specified_height.is_auto()) {
@ -602,15 +602,15 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
used_height = min(used_height, specified_max_height.to_px(box));
if (!specified_min_height.is_auto())
used_height = max(used_height, specified_min_height.to_px(box));
box.set_height(used_height);
box.set_content_height(used_height);
}
}
void FormattingContext::layout_absolutely_positioned_element(Box& box)
{
auto& containing_block = *box.containing_block();
auto width_of_containing_block = CSS::Length::make_px(containing_block.width());
auto height_of_containing_block = CSS::Length::make_px(containing_block.height());
auto width_of_containing_block = CSS::Length::make_px(containing_block.content_width());
auto height_of_containing_block = CSS::Length::make_px(containing_block.content_height());
auto& box_model = box.box_model();
auto specified_width = box.computed_values().width().resolved(box, width_of_containing_block).resolved_or_auto(box);
@ -655,7 +655,7 @@ void FormattingContext::layout_absolutely_positioned_element(Box& box)
float x_offset = 0
- box_model.offset.right
- box_model.border_box().right;
used_offset.set_x(containing_block.width() + x_offset - box.width() - box_model.margin.right);
used_offset.set_x(containing_block.content_width() + x_offset - box.content_width() - box_model.margin.right);
} else {
float x_offset = box_model.margin_box().left;
used_offset.set_x(x_offset);
@ -669,7 +669,7 @@ void FormattingContext::layout_absolutely_positioned_element(Box& box)
float y_offset = 0
- box_model.offset.bottom
- box_model.border_box().bottom;
used_offset.set_y(containing_block.height() + y_offset - box.height() - box_model.margin.bottom);
used_offset.set_y(containing_block.content_height() + y_offset - box.content_height() - box_model.margin.bottom);
} else {
float y_offset = box_model.margin_box().top;
used_offset.set_y(y_offset);
@ -682,7 +682,7 @@ void FormattingContext::compute_height_for_absolutely_positioned_replaced_elemen
{
// 10.6.5 Absolutely positioned, replaced elements
// The used value of 'height' is determined as for inline replaced elements.
box.set_height(compute_height_for_replaced_element(box));
box.set_content_height(compute_height_for_replaced_element(box));
}
}

View file

@ -68,7 +68,7 @@ void FrameBox::did_set_rect()
ReplacedBox::did_set_rect();
VERIFY(dom_node().nested_browsing_context());
dom_node().nested_browsing_context()->set_size(size().to_type<int>());
dom_node().nested_browsing_context()->set_size(content_size().to_type<int>());
}
}

View file

@ -65,8 +65,8 @@ void ImageBox::prepare_for_replaced_layout()
}
if (!has_intrinsic_width() && !has_intrinsic_height()) {
set_width(16);
set_height(16);
set_content_width(16);
set_content_height(16);
}
}

View file

@ -55,7 +55,7 @@ InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::avai
}
}
info.right = containing_block().width();
info.right = containing_block().content_width();
for (ssize_t i = bfc.right_side_floats().boxes.size() - 1; i >= 0; --i) {
auto const& floating_box = bfc.right_side_floats().boxes.at(i);
@ -97,18 +97,18 @@ void InlineFormattingContext::run(Box&, LayoutMode layout_mode)
}
if (layout_mode != LayoutMode::Default) {
containing_block().set_width(max_line_width);
containing_block().set_content_width(max_line_width);
}
containing_block().set_height(content_height);
containing_block().set_content_height(content_height);
}
void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_mode)
{
if (is<ReplacedBox>(box)) {
auto& replaced = verify_cast<ReplacedBox>(box);
replaced.set_width(compute_width_for_replaced_element(replaced));
replaced.set_height(compute_height_for_replaced_element(replaced));
replaced.set_content_width(compute_width_for_replaced_element(replaced));
replaced.set_content_height(compute_height_for_replaced_element(replaced));
return;
}
@ -117,7 +117,7 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_
if (inline_block.computed_values().width().is_length() && inline_block.computed_values().width().length().is_undefined_or_auto()) {
auto result = calculate_shrink_to_fit_widths(inline_block);
auto width_of_containing_block = CSS::Length::make_px(containing_block().width());
auto width_of_containing_block = CSS::Length::make_px(containing_block().content_width());
auto margin_left = inline_block.computed_values().margin().left.resolved(box, width_of_containing_block).resolved_or_zero(inline_block).to_px(inline_block);
auto border_left_width = inline_block.computed_values().border_left().width;
@ -127,7 +127,7 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_
auto border_right_width = inline_block.computed_values().border_right().width;
auto padding_right = inline_block.computed_values().padding().right.resolved(box, width_of_containing_block).resolved_or_zero(inline_block).to_px(inline_block);
auto available_width = containing_block().width()
auto available_width = containing_block().content_width()
- margin_left
- border_left_width
- padding_left
@ -136,18 +136,18 @@ void InlineFormattingContext::dimension_box_on_line(Box& box, LayoutMode layout_
- margin_right;
auto width = min(max(result.preferred_minimum_width, available_width), result.preferred_width);
inline_block.set_width(width);
inline_block.set_content_width(width);
} else {
auto container_width = CSS::Length::make_px(containing_block().width());
inline_block.set_width(inline_block.computed_values().width().resolved(box, container_width).resolved_or_zero(inline_block).to_px(inline_block));
auto container_width = CSS::Length::make_px(containing_block().content_width());
inline_block.set_content_width(inline_block.computed_values().width().resolved(box, container_width).resolved_or_zero(inline_block).to_px(inline_block));
}
(void)layout_inside(inline_block, layout_mode);
if (inline_block.computed_values().height().is_length() && inline_block.computed_values().height().length().is_undefined_or_auto()) {
// FIXME: (10.6.6) If 'height' is 'auto', the height depends on the element's descendants per 10.6.7.
} else {
auto container_height = CSS::Length::make_px(containing_block().height());
inline_block.set_height(inline_block.computed_values().height().resolved(box, container_height).resolved_or_zero(inline_block).to_px(inline_block));
auto container_height = CSS::Length::make_px(containing_block().content_height());
inline_block.set_content_height(inline_block.computed_values().height().resolved(box, container_height).resolved_or_zero(inline_block).to_px(inline_block));
}
return;
}
@ -182,7 +182,7 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode)
case InlineLevelIterator::Item::Type::Element: {
auto& box = verify_cast<Layout::Box>(*item.node);
dimension_box_on_line(box, layout_mode);
line_builder.break_if_needed(layout_mode, box.width(), item.should_force_break);
line_builder.break_if_needed(layout_mode, box.content_width(), item.should_force_break);
line_builder.append_box(box);
break;
}

View file

@ -102,7 +102,7 @@ Optional<InlineLevelIterator::Item> InlineLevelIterator::next(float available_wi
.node = &box,
.offset_in_node = 0,
.length_in_node = 0,
.width = box.width(),
.width = box.content_width(),
};
}

View file

@ -41,8 +41,8 @@ void LineBuilder::begin_new_line(bool increment_y)
void LineBuilder::append_box(Box& box)
{
m_context.containing_block().ensure_last_line_box().add_fragment(box, 0, 0, box.width(), box.height());
m_max_height_on_current_line = max(m_max_height_on_current_line, box.height());
m_context.containing_block().ensure_last_line_box().add_fragment(box, 0, 0, box.content_width(), box.content_height());
m_max_height_on_current_line = max(m_max_height_on_current_line, box.content_height());
}
void LineBuilder::append_text_chunk(TextNode& text_node, size_t offset_in_node, size_t length_in_node, float width, float height)
@ -78,7 +78,7 @@ void LineBuilder::update_last_line()
auto text_align = m_context.containing_block().computed_values().text_align();
float x_offset = m_context.available_space_for_line(m_current_y).left;
float excess_horizontal_space = m_context.containing_block().width() - line_box.width();
float excess_horizontal_space = m_context.containing_block().content_width() - line_box.width();
switch (text_align) {
case CSS::TextAlign::Center:
@ -115,7 +115,7 @@ void LineBuilder::update_last_line()
for (auto& fragment : line_box.fragments()) {
float fragment_baseline;
if (fragment.layout_node().is_box()) {
fragment_baseline = static_cast<Box const&>(fragment.layout_node()).height();
fragment_baseline = static_cast<Box const&>(fragment.layout_node()).content_height();
} else {
float font_baseline = fragment.layout_node().font().baseline();
fragment_baseline = (max_height / 2.0f) + (font_baseline / 2.0f);

View file

@ -39,10 +39,10 @@ void ListItemBox::layout_marker()
append_child(*m_marker);
}
m_marker->set_offset(-(m_marker->width() + 4), 0);
m_marker->set_offset(-(m_marker->content_width() + 4), 0);
if (m_marker->height() > height())
set_height(m_marker->height());
if (m_marker->content_height() > content_height())
set_content_height(m_marker->content_height());
}
}

View file

@ -57,13 +57,13 @@ ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType
}
if (m_text.is_null()) {
set_width(image_width + 4);
set_content_width(image_width + 4);
} else {
auto text_width = font().width(m_text);
set_width(image_width + text_width);
set_content_width(image_width + text_width);
}
set_height(max(image_height, line_height()));
set_content_height(max(image_height, line_height()));
}
ListItemMarkerBox::~ListItemMarkerBox()

View file

@ -32,7 +32,7 @@ void SVGFormattingContext::run(Box& box, LayoutMode)
if (is<SVGPathBox>(descendant)) {
auto& path_box = static_cast<SVGPathBox&>(descendant);
auto& path = path_box.dom_node().get_path();
path_box.set_size(path.bounding_box().size());
path_box.set_content_size(path.bounding_box().size());
total_bounding_box = total_bounding_box.united(path.bounding_box());
}
@ -40,7 +40,7 @@ void SVGFormattingContext::run(Box& box, LayoutMode)
return IterationDecision::Continue;
});
box.set_size(total_bounding_box.size());
box.set_content_size(total_bounding_box.size());
}
}

View file

@ -48,24 +48,24 @@ void TableFormattingContext::run(Box& box, LayoutMode)
row_group_box.template for_each_child_of_type<TableRowBox>([&](auto& row) {
row.set_offset(0, content_height);
layout_row(row, column_widths);
content_width = max(content_width, row.width());
content_height += row.height();
content_width = max(content_width, row.content_width());
content_height += row.content_height();
});
if (row_group_box.computed_values().width().is_length() && row_group_box.computed_values().width().length().is_auto())
row_group_box.set_width(content_width);
row_group_box.set_height(content_height);
row_group_box.set_content_width(content_width);
row_group_box.set_content_height(content_height);
row_group_box.set_offset(0, total_content_height);
total_content_height += content_height;
total_content_width = max(total_content_width, row_group_box.width());
total_content_width = max(total_content_width, row_group_box.content_width());
});
if (box.computed_values().width().is_length() && box.computed_values().width().length().is_auto())
box.set_width(total_content_width);
box.set_content_width(total_content_width);
// FIXME: This is a total hack, we should respect the 'height' property.
box.set_height(total_content_height);
box.set_content_height(total_content_height);
}
void TableFormattingContext::calculate_column_widths(Box& row, Vector<float>& column_widths)
@ -80,7 +80,7 @@ void TableFormattingContext::calculate_column_widths(Box& row, Vector<float>& co
} else {
(void)layout_inside(cell, LayoutMode::Default);
}
column_widths[column_index] = max(column_widths[column_index], cell.width());
column_widths[column_index] = max(column_widths[column_index], cell.content_width());
column_index += cell.colspan();
});
}
@ -106,16 +106,16 @@ void TableFormattingContext::layout_row(Box& row, Vector<float>& column_widths)
size_t cell_colspan = cell.colspan();
for (size_t i = 0; i < cell_colspan; ++i)
content_width += column_widths[column_index++];
tallest_cell_height = max(tallest_cell_height, cell.height());
tallest_cell_height = max(tallest_cell_height, cell.content_height());
});
if (use_auto_layout) {
row.set_width(content_width);
row.set_content_width(content_width);
} else {
row.set_width(table->width());
row.set_content_width(table->content_width());
}
row.set_height(tallest_cell_height);
row.set_content_height(tallest_cell_height);
}
}