mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:47:45 +00:00
LibWeb: Use the new to_px() helpers in CSS, SVG and layout code
There should be no behavior change from this, only slightly less verbosity. :^)
This commit is contained in:
parent
cdf0d3e905
commit
ca1fa5f748
14 changed files with 141 additions and 149 deletions
|
@ -646,14 +646,14 @@ void BlockFormattingContext::resolve_vertical_box_model_metrics(Box const& box,
|
|||
{
|
||||
auto& box_state = state.get_mutable(box);
|
||||
auto const& computed_values = box.computed_values();
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block_width_for(box, state));
|
||||
auto width_of_containing_block = containing_block_width_for(box, state);
|
||||
|
||||
box_state.margin_top = computed_values.margin().top().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.margin_bottom = computed_values.margin().bottom().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.margin_top = computed_values.margin().top().to_px(box, width_of_containing_block);
|
||||
box_state.margin_bottom = computed_values.margin().bottom().to_px(box, width_of_containing_block);
|
||||
box_state.border_top = computed_values.border_top().width;
|
||||
box_state.border_bottom = computed_values.border_bottom().width;
|
||||
box_state.padding_top = computed_values.padding().top().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.padding_bottom = computed_values.padding().bottom().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.padding_top = computed_values.padding().top().to_px(box, width_of_containing_block);
|
||||
box_state.padding_bottom = computed_values.padding().bottom().to_px(box, width_of_containing_block);
|
||||
}
|
||||
|
||||
CSSPixels BlockFormattingContext::BlockMarginState::current_collapsed_margin() const
|
||||
|
|
|
@ -39,31 +39,31 @@ static CSS::Size to_css_size(CSS::LengthPercentage const& length_percentage)
|
|||
|
||||
CSSPixels FlexFormattingContext::get_pixel_width(Box const& box, CSS::Size const& size) const
|
||||
{
|
||||
auto containing_block_width = CSS::Length::make_px(containing_block_width_for(box));
|
||||
auto containing_block_width = containing_block_width_for(box);
|
||||
if (box.computed_values().box_sizing() == CSS::BoxSizing::BorderBox) {
|
||||
auto border_left = box.computed_values().border_left().width;
|
||||
auto border_right = box.computed_values().border_right().width;
|
||||
auto padding_left = box.computed_values().padding().left().resolved(box, containing_block_width).to_px(box);
|
||||
auto padding_right = box.computed_values().padding().right().resolved(box, containing_block_width).to_px(box);
|
||||
return size.resolved(box, containing_block_width).to_px(box) - border_left - border_right - padding_left - padding_right;
|
||||
auto padding_left = box.computed_values().padding().left().to_px(box, containing_block_width);
|
||||
auto padding_right = box.computed_values().padding().right().to_px(box, containing_block_width);
|
||||
return size.to_px(box, containing_block_width) - border_left - border_right - padding_left - padding_right;
|
||||
}
|
||||
|
||||
return size.resolved(box, containing_block_width).to_px(box);
|
||||
return size.to_px(box, containing_block_width);
|
||||
}
|
||||
|
||||
CSSPixels FlexFormattingContext::get_pixel_height(Box const& box, CSS::Size const& size) const
|
||||
{
|
||||
auto containing_block_height = CSS::Length::make_px(containing_block_height_for(box));
|
||||
auto containing_block_height = containing_block_height_for(box);
|
||||
if (box.computed_values().box_sizing() == CSS::BoxSizing::BorderBox) {
|
||||
auto containing_block_width = CSS::Length::make_px(containing_block_width_for(box));
|
||||
auto containing_block_width = containing_block_width_for(box);
|
||||
auto border_top = box.computed_values().border_top().width;
|
||||
auto border_bottom = box.computed_values().border_bottom().width;
|
||||
auto padding_top = box.computed_values().padding().top().resolved(box, containing_block_width).to_px(box);
|
||||
auto padding_bottom = box.computed_values().padding().bottom().resolved(box, containing_block_width).to_px(box);
|
||||
return size.resolved(box, containing_block_height).to_px(box) - border_top - border_bottom - padding_top - padding_bottom;
|
||||
auto padding_top = box.computed_values().padding().top().to_px(box, containing_block_width);
|
||||
auto padding_bottom = box.computed_values().padding().bottom().to_px(box, containing_block_width);
|
||||
return size.to_px(box, containing_block_height) - border_top - border_bottom - padding_top - padding_bottom;
|
||||
}
|
||||
|
||||
return size.resolved(box, containing_block_height).to_px(box);
|
||||
return size.to_px(box, containing_block_height);
|
||||
}
|
||||
|
||||
FlexFormattingContext::FlexFormattingContext(LayoutState& state, Box const& flex_container, FormattingContext* parent)
|
||||
|
@ -245,7 +245,6 @@ void FlexFormattingContext::parent_context_did_dimension_child_root_box()
|
|||
void FlexFormattingContext::populate_specified_margins(FlexItem& item, CSS::FlexDirection flex_direction) const
|
||||
{
|
||||
auto width_of_containing_block = m_state.get(*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) {
|
||||
item.borders.main_before = item.box->computed_values().border_left().width;
|
||||
|
@ -253,15 +252,15 @@ void FlexFormattingContext::populate_specified_margins(FlexItem& item, CSS::Flex
|
|||
item.borders.cross_before = item.box->computed_values().border_top().width;
|
||||
item.borders.cross_after = item.box->computed_values().border_bottom().width;
|
||||
|
||||
item.padding.main_before = item.box->computed_values().padding().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.padding.main_after = item.box->computed_values().padding().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.padding.cross_before = item.box->computed_values().padding().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.padding.cross_after = item.box->computed_values().padding().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.padding.main_before = item.box->computed_values().padding().left().to_px(item.box, width_of_containing_block);
|
||||
item.padding.main_after = item.box->computed_values().padding().right().to_px(item.box, width_of_containing_block);
|
||||
item.padding.cross_before = item.box->computed_values().padding().top().to_px(item.box, width_of_containing_block);
|
||||
item.padding.cross_after = item.box->computed_values().padding().bottom().to_px(item.box, width_of_containing_block);
|
||||
|
||||
item.margins.main_before = item.box->computed_values().margin().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.margins.main_after = item.box->computed_values().margin().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.margins.cross_before = item.box->computed_values().margin().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.margins.cross_after = item.box->computed_values().margin().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.margins.main_before = item.box->computed_values().margin().left().to_px(item.box, width_of_containing_block);
|
||||
item.margins.main_after = item.box->computed_values().margin().right().to_px(item.box, width_of_containing_block);
|
||||
item.margins.cross_before = item.box->computed_values().margin().top().to_px(item.box, width_of_containing_block);
|
||||
item.margins.cross_after = item.box->computed_values().margin().bottom().to_px(item.box, width_of_containing_block);
|
||||
|
||||
item.margins.main_before_is_auto = item.box->computed_values().margin().left().is_auto();
|
||||
item.margins.main_after_is_auto = item.box->computed_values().margin().right().is_auto();
|
||||
|
@ -273,15 +272,15 @@ void FlexFormattingContext::populate_specified_margins(FlexItem& item, CSS::Flex
|
|||
item.borders.cross_before = item.box->computed_values().border_left().width;
|
||||
item.borders.cross_after = item.box->computed_values().border_right().width;
|
||||
|
||||
item.padding.main_before = item.box->computed_values().padding().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.padding.main_after = item.box->computed_values().padding().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.padding.cross_before = item.box->computed_values().padding().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.padding.cross_after = item.box->computed_values().padding().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.padding.main_before = item.box->computed_values().padding().top().to_px(item.box, width_of_containing_block);
|
||||
item.padding.main_after = item.box->computed_values().padding().bottom().to_px(item.box, width_of_containing_block);
|
||||
item.padding.cross_before = item.box->computed_values().padding().left().to_px(item.box, width_of_containing_block);
|
||||
item.padding.cross_after = item.box->computed_values().padding().right().to_px(item.box, width_of_containing_block);
|
||||
|
||||
item.margins.main_before = item.box->computed_values().margin().top().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.margins.main_after = item.box->computed_values().margin().bottom().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.margins.cross_before = item.box->computed_values().margin().left().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.margins.cross_after = item.box->computed_values().margin().right().resolved(item.box, width_of_containing_block_as_length).to_px(item.box);
|
||||
item.margins.main_before = item.box->computed_values().margin().top().to_px(item.box, width_of_containing_block);
|
||||
item.margins.main_after = item.box->computed_values().margin().bottom().to_px(item.box, width_of_containing_block);
|
||||
item.margins.cross_before = item.box->computed_values().margin().left().to_px(item.box, width_of_containing_block);
|
||||
item.margins.cross_after = item.box->computed_values().margin().right().to_px(item.box, width_of_containing_block);
|
||||
|
||||
item.margins.main_before_is_auto = item.box->computed_values().margin().top().is_auto();
|
||||
item.margins.main_after_is_auto = item.box->computed_values().margin().bottom().is_auto();
|
||||
|
@ -1436,7 +1435,7 @@ void FlexFormattingContext::determine_flex_container_used_cross_size()
|
|||
}
|
||||
} else {
|
||||
// Otherwise, resolve the indefinite size at this point.
|
||||
cross_size = cross_size_value.resolved(flex_container(), CSS::Length::make_px(inner_cross_size(*flex_container().containing_block()))).to_px(flex_container());
|
||||
cross_size = cross_size_value.to_px(flex_container(), inner_cross_size(*flex_container().containing_block()));
|
||||
}
|
||||
}
|
||||
auto const& computed_min_size = this->computed_cross_min_size(flex_container());
|
||||
|
@ -1531,15 +1530,15 @@ void FlexFormattingContext::copy_dimensions_from_flex_items_to_boxes()
|
|||
auto const& box = item.box;
|
||||
auto& box_state = m_state.get_mutable(box);
|
||||
|
||||
box_state.padding_left = box->computed_values().padding().left().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
|
||||
box_state.padding_right = box->computed_values().padding().right().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
|
||||
box_state.padding_top = box->computed_values().padding().top().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
|
||||
box_state.padding_bottom = box->computed_values().padding().bottom().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
|
||||
box_state.padding_left = box->computed_values().padding().left().to_px(box, m_flex_container_state.content_width());
|
||||
box_state.padding_right = box->computed_values().padding().right().to_px(box, m_flex_container_state.content_width());
|
||||
box_state.padding_top = box->computed_values().padding().top().to_px(box, m_flex_container_state.content_width());
|
||||
box_state.padding_bottom = box->computed_values().padding().bottom().to_px(box, m_flex_container_state.content_width());
|
||||
|
||||
box_state.margin_left = box->computed_values().margin().left().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
|
||||
box_state.margin_right = box->computed_values().margin().right().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
|
||||
box_state.margin_top = box->computed_values().margin().top().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
|
||||
box_state.margin_bottom = box->computed_values().margin().bottom().resolved(box, CSS::Length::make_px(m_flex_container_state.content_width())).to_px(box);
|
||||
box_state.margin_left = box->computed_values().margin().left().to_px(box, m_flex_container_state.content_width());
|
||||
box_state.margin_right = box->computed_values().margin().right().to_px(box, m_flex_container_state.content_width());
|
||||
box_state.margin_top = box->computed_values().margin().top().to_px(box, m_flex_container_state.content_width());
|
||||
box_state.margin_bottom = box->computed_values().margin().bottom().to_px(box, m_flex_container_state.content_width());
|
||||
|
||||
box_state.border_left = box->computed_values().border_left().width;
|
||||
box_state.border_right = box->computed_values().border_right().width;
|
||||
|
@ -2157,14 +2156,14 @@ CSSPixels FlexFormattingContext::main_gap() const
|
|||
{
|
||||
auto const& computed_values = flex_container().computed_values();
|
||||
auto gap = is_row_layout() ? computed_values.column_gap() : computed_values.row_gap();
|
||||
return gap.resolved(flex_container(), CSS::Length::make_px(inner_main_size(flex_container()))).to_px(flex_container());
|
||||
return gap.to_px(flex_container(), inner_main_size(flex_container()));
|
||||
}
|
||||
|
||||
CSSPixels FlexFormattingContext::cross_gap() const
|
||||
{
|
||||
auto const& computed_values = flex_container().computed_values();
|
||||
auto gap = is_row_layout() ? computed_values.row_gap() : computed_values.column_gap();
|
||||
return gap.resolved(flex_container(), CSS::Length::make_px(inner_cross_size(flex_container()))).to_px(flex_container());
|
||||
return gap.to_px(flex_container(), inner_cross_size(flex_container()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -264,13 +264,13 @@ static CSSPixelSize solve_replaced_size_constraint(LayoutState const& state, CSS
|
|||
|
||||
auto const& containing_block = *box.containing_block();
|
||||
auto const& containing_block_state = state.get(containing_block);
|
||||
auto width_of_containing_block = CSS::Length::make_px(containing_block_state.content_width());
|
||||
auto height_of_containing_block = CSS::Length::make_px(containing_block_state.content_height());
|
||||
auto width_of_containing_block = containing_block_state.content_width();
|
||||
auto height_of_containing_block = containing_block_state.content_height();
|
||||
|
||||
CSSPixels specified_min_width = box.computed_values().min_width().is_auto() ? 0 : box.computed_values().min_width().resolved(box, width_of_containing_block).to_px(box);
|
||||
CSSPixels specified_max_width = box.computed_values().max_width().is_none() ? w : box.computed_values().max_width().resolved(box, width_of_containing_block).to_px(box);
|
||||
CSSPixels specified_min_height = box.computed_values().min_height().is_auto() ? 0 : box.computed_values().min_height().resolved(box, height_of_containing_block).to_px(box);
|
||||
CSSPixels specified_max_height = box.computed_values().max_height().is_none() ? h : box.computed_values().max_height().resolved(box, height_of_containing_block).to_px(box);
|
||||
CSSPixels specified_min_width = box.computed_values().min_width().is_auto() ? 0 : box.computed_values().min_width().to_px(box, width_of_containing_block);
|
||||
CSSPixels specified_max_width = box.computed_values().max_width().is_none() ? w : box.computed_values().max_width().to_px(box, width_of_containing_block);
|
||||
CSSPixels specified_min_height = box.computed_values().min_height().is_auto() ? 0 : box.computed_values().min_height().to_px(box, height_of_containing_block);
|
||||
CSSPixels specified_max_height = box.computed_values().max_height().is_none() ? h : box.computed_values().max_height().to_px(box, height_of_containing_block);
|
||||
|
||||
auto min_width = min(specified_min_width, specified_max_width);
|
||||
auto max_width = max(specified_min_width, specified_max_width);
|
||||
|
@ -369,7 +369,7 @@ CSSPixels FormattingContext::tentative_width_for_replaced_element(LayoutState co
|
|||
auto height_of_containing_block = CSS::Length::make_px(containing_block_height_for(box, state));
|
||||
auto computed_height = should_treat_height_as_auto(box, available_space) ? CSS::Size::make_auto() : box.computed_values().height();
|
||||
|
||||
CSSPixels used_width = computed_width.resolved(box, CSS::Length::make_px(available_space.width.to_px())).to_px(box);
|
||||
CSSPixels used_width = computed_width.to_px(box, available_space.width.to_px());
|
||||
|
||||
// If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic width,
|
||||
// then that intrinsic width is the used value of 'width'.
|
||||
|
@ -426,7 +426,8 @@ CSSPixels FormattingContext::compute_width_for_replaced_element(LayoutState cons
|
|||
// 10.3.2 Inline, replaced elements
|
||||
|
||||
auto zero_value = CSS::Length::make_px(0);
|
||||
auto width_of_containing_block_as_length = CSS::Length::make_px(available_space.width.to_px());
|
||||
auto width_of_containing_block = available_space.width.to_px();
|
||||
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
|
||||
|
||||
auto margin_left = box.computed_values().margin().left().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
auto margin_right = box.computed_values().margin().right().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
|
@ -446,7 +447,7 @@ CSSPixels FormattingContext::compute_width_for_replaced_element(LayoutState cons
|
|||
// but this time using the computed value of 'max-width' as the computed value for 'width'.
|
||||
auto computed_max_width = box.computed_values().max_width();
|
||||
if (!computed_max_width.is_none()) {
|
||||
if (used_width > computed_max_width.resolved(box, width_of_containing_block_as_length).to_px(box)) {
|
||||
if (used_width > computed_max_width.to_px(box, width_of_containing_block)) {
|
||||
used_width = tentative_width_for_replaced_element(state, box, computed_max_width, available_space);
|
||||
}
|
||||
}
|
||||
|
@ -455,7 +456,7 @@ CSSPixels FormattingContext::compute_width_for_replaced_element(LayoutState cons
|
|||
// but this time using the value of 'min-width' as the computed value for 'width'.
|
||||
auto computed_min_width = box.computed_values().min_width();
|
||||
if (!computed_min_width.is_auto()) {
|
||||
if (used_width < computed_min_width.resolved(box, width_of_containing_block_as_length).to_px(box)) {
|
||||
if (used_width < computed_min_width.to_px(box, width_of_containing_block)) {
|
||||
used_width = tentative_width_for_replaced_element(state, box, computed_min_width, available_space);
|
||||
}
|
||||
}
|
||||
|
@ -488,7 +489,7 @@ CSSPixels FormattingContext::tentative_height_for_replaced_element(LayoutState c
|
|||
if (computed_height.is_auto())
|
||||
return 150;
|
||||
|
||||
return computed_height.resolved(box, CSS::Length::make_px(available_space.height.to_px())).to_px(box);
|
||||
return computed_height.to_px(box, available_space.height.to_px());
|
||||
}
|
||||
|
||||
CSSPixels FormattingContext::compute_height_for_replaced_element(LayoutState const& state, ReplacedBox const& box, AvailableSpace const& available_space)
|
||||
|
@ -523,8 +524,8 @@ void FormattingContext::compute_width_for_absolutely_positioned_non_replaced_ele
|
|||
auto margin_right = CSS::Length::make_auto();
|
||||
auto const border_left = computed_values.border_left().width;
|
||||
auto const border_right = computed_values.border_right().width;
|
||||
auto const padding_left = computed_values.padding().left().resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
auto const padding_right = computed_values.padding().right().resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
auto const padding_left = computed_values.padding().left().to_px(box, width_of_containing_block);
|
||||
auto const padding_right = computed_values.padding().right().to_px(box, width_of_containing_block);
|
||||
|
||||
auto try_compute_width = [&](auto const& a_width) {
|
||||
margin_left = computed_values.margin().left().resolved(box, width_of_containing_block_as_length).resolved(box);
|
||||
|
@ -690,15 +691,15 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
|
|||
};
|
||||
auto solve_for = [&](CSS::Length length, ClampToZero clamp_to_zero = ClampToZero::No) {
|
||||
auto unclamped_value = height_of_containing_block
|
||||
- top.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- margin_top.resolved(box, width_of_containing_block_as_length).to_px(box)
|
||||
- top.to_px(box, height_of_containing_block)
|
||||
- margin_top.to_px(box, width_of_containing_block)
|
||||
- box.computed_values().border_top().width
|
||||
- box.computed_values().padding().top().resolved(box, width_of_containing_block_as_length).to_px(box)
|
||||
- height.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- box.computed_values().padding().bottom().resolved(box, width_of_containing_block_as_length).to_px(box)
|
||||
- box.computed_values().padding().top().to_px(box, width_of_containing_block)
|
||||
- height.to_px(box, height_of_containing_block)
|
||||
- box.computed_values().padding().bottom().to_px(box, width_of_containing_block)
|
||||
- box.computed_values().border_bottom().width
|
||||
- margin_bottom.resolved(box, width_of_containing_block_as_length).to_px(box)
|
||||
- bottom.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- margin_bottom.to_px(box, width_of_containing_block)
|
||||
- bottom.to_px(box, height_of_containing_block)
|
||||
+ length.to_px(box);
|
||||
if (clamp_to_zero == ClampToZero::Yes)
|
||||
return CSS::Length::make_px(max(CSSPixels(0), unclamped_value));
|
||||
|
@ -726,7 +727,7 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
|
|||
};
|
||||
|
||||
auto solve_for_margin_top_and_margin_bottom = [&] {
|
||||
auto remainder = solve_for(CSS::Length::make_px(margin_top.resolved(box, width_of_containing_block_as_length).to_px(box) + margin_bottom.resolved(box, width_of_containing_block_as_length).to_px(box))).to_px(box);
|
||||
auto remainder = solve_for(CSS::Length::make_px(margin_top.to_px(box, width_of_containing_block) + margin_bottom.to_px(box, width_of_containing_block))).to_px(box);
|
||||
margin_top = CSS::Length::make_px(remainder / 2);
|
||||
margin_bottom = CSS::Length::make_px(remainder / 2);
|
||||
};
|
||||
|
@ -840,7 +841,7 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
|
|||
}
|
||||
}
|
||||
|
||||
auto used_height = height.resolved(box, height_of_containing_block_as_length).to_px(box);
|
||||
auto used_height = height.to_px(box, height_of_containing_block);
|
||||
auto const& computed_min_height = box.computed_values().min_height();
|
||||
auto const& computed_max_height = box.computed_values().max_height();
|
||||
|
||||
|
@ -853,12 +854,12 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
|
|||
// the final used values for vertical margin/border/padding.
|
||||
|
||||
auto& box_state = m_state.get_mutable(box);
|
||||
box_state.margin_top = margin_top.resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
box_state.margin_bottom = margin_bottom.resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
box_state.margin_top = margin_top.to_px(box, width_of_containing_block);
|
||||
box_state.margin_bottom = margin_bottom.to_px(box, width_of_containing_block);
|
||||
box_state.border_top = box.computed_values().border_top().width;
|
||||
box_state.border_bottom = box.computed_values().border_bottom().width;
|
||||
box_state.padding_top = box.computed_values().padding().top().resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
box_state.padding_bottom = box.computed_values().padding().bottom().resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
box_state.padding_top = box.computed_values().padding().top().to_px(box, width_of_containing_block);
|
||||
box_state.padding_bottom = box.computed_values().padding().bottom().to_px(box, width_of_containing_block);
|
||||
|
||||
// And here is where we assign the box's content height.
|
||||
box_state.set_content_height(used_height);
|
||||
|
@ -947,10 +948,10 @@ void FormattingContext::layout_absolutely_positioned_element(Box const& box, Ava
|
|||
|
||||
compute_height_for_absolutely_positioned_element(box, available_space, BeforeOrAfterInsideLayout::After);
|
||||
|
||||
box_state.margin_left = box.computed_values().margin().left().resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
box_state.margin_top = box.computed_values().margin().top().resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
box_state.margin_right = box.computed_values().margin().right().resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
box_state.margin_bottom = box.computed_values().margin().bottom().resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
box_state.margin_left = box.computed_values().margin().left().to_px(box, width_of_containing_block);
|
||||
box_state.margin_top = box.computed_values().margin().top().to_px(box, width_of_containing_block);
|
||||
box_state.margin_right = box.computed_values().margin().right().to_px(box, width_of_containing_block);
|
||||
box_state.margin_bottom = box.computed_values().margin().bottom().to_px(box, width_of_containing_block);
|
||||
|
||||
box_state.border_left = box.computed_values().border_left().width;
|
||||
box_state.border_right = box.computed_values().border_right().width;
|
||||
|
@ -962,10 +963,10 @@ void FormattingContext::layout_absolutely_positioned_element(Box const& box, Ava
|
|||
auto const& computed_top = box.computed_values().inset().top();
|
||||
auto const& computed_bottom = box.computed_values().inset().bottom();
|
||||
|
||||
box_state.inset_left = computed_left.resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
box_state.inset_top = computed_top.resolved(box, height_of_containing_block_as_length).to_px(box);
|
||||
box_state.inset_right = computed_right.resolved(box, width_of_containing_block_as_length).to_px(box);
|
||||
box_state.inset_bottom = computed_bottom.resolved(box, height_of_containing_block_as_length).to_px(box);
|
||||
box_state.inset_left = computed_left.to_px(box, width_of_containing_block);
|
||||
box_state.inset_top = computed_top.to_px(box, height_of_containing_block);
|
||||
box_state.inset_right = computed_right.to_px(box, width_of_containing_block);
|
||||
box_state.inset_bottom = computed_bottom.to_px(box, height_of_containing_block);
|
||||
|
||||
if (computed_left.is_auto() && box.computed_values().width().is_auto() && computed_right.is_auto()) {
|
||||
if (box.computed_values().margin().left().is_auto())
|
||||
|
@ -1297,7 +1298,7 @@ CSS::Length FormattingContext::calculate_inner_width(Layout::Box const& box, Ava
|
|||
auto const padding_left = computed_values.padding().left().resolved(box, width_of_containing_block_as_length_for_resolve);
|
||||
auto const padding_right = computed_values.padding().right().resolved(box, width_of_containing_block_as_length_for_resolve);
|
||||
|
||||
auto inner_width = width.resolved(box, width_of_containing_block_as_length_for_resolve).to_px(box)
|
||||
auto inner_width = width.to_px(box, width_of_containing_block)
|
||||
- computed_values.border_left().width
|
||||
- padding_left.to_px(box)
|
||||
- computed_values.border_right().width
|
||||
|
@ -1323,7 +1324,7 @@ CSS::Length FormattingContext::calculate_inner_height(Layout::Box const& box, Av
|
|||
auto const padding_top = computed_values.padding().top().resolved(box, width_of_containing_block);
|
||||
auto const padding_bottom = computed_values.padding().bottom().resolved(box, width_of_containing_block);
|
||||
|
||||
auto inner_height = height.resolved(box, height_of_containing_block_as_length_for_resolve).to_px(box)
|
||||
auto inner_height = height.to_px(box, height_of_containing_block)
|
||||
- computed_values.border_top().width
|
||||
- padding_top.to_px(box)
|
||||
- computed_values.border_bottom().width
|
||||
|
|
|
@ -613,14 +613,14 @@ void GridFormattingContext::initialize_grid_tracks(AvailableSpace const& availab
|
|||
// line.
|
||||
if (!grid_container().computed_values().column_gap().is_auto()) {
|
||||
for (int column_index = 1; column_index < (m_occupation_grid.column_count() * 2) - 1; column_index += 2) {
|
||||
auto column_gap_width = grid_container().computed_values().column_gap().resolved(grid_container(), CSS::Length::make_px(available_space.width.to_px()));
|
||||
m_grid_columns.insert(column_index, TemporaryTrack(column_gap_width.to_px(grid_container()), true));
|
||||
auto column_gap_width = grid_container().computed_values().column_gap().to_px(grid_container(), available_space.width.to_px());
|
||||
m_grid_columns.insert(column_index, TemporaryTrack(column_gap_width, true));
|
||||
}
|
||||
}
|
||||
if (!grid_container().computed_values().row_gap().is_auto()) {
|
||||
for (int row_index = 1; row_index < (m_occupation_grid.row_count() * 2) - 1; row_index += 2) {
|
||||
auto column_gap_height = grid_container().computed_values().row_gap().resolved(grid_container(), CSS::Length::make_px(available_space.height.to_px()));
|
||||
m_grid_rows.insert(row_index, TemporaryTrack(column_gap_height.to_px(grid_container()), true));
|
||||
auto column_gap_height = grid_container().computed_values().row_gap().to_px(grid_container(), available_space.height.to_px());
|
||||
m_grid_rows.insert(row_index, TemporaryTrack(column_gap_height, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,25 +91,25 @@ void InlineFormattingContext::run(Box const&, LayoutMode layout_mode, AvailableS
|
|||
|
||||
void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode layout_mode)
|
||||
{
|
||||
auto width_of_containing_block = CSS::Length::make_px(m_available_space->width.to_px());
|
||||
auto width_of_containing_block = m_available_space->width.to_px();
|
||||
auto& box_state = m_state.get_mutable(box);
|
||||
auto const& computed_values = box.computed_values();
|
||||
|
||||
box_state.margin_left = computed_values.margin().left().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.margin_left = computed_values.margin().left().to_px(box, width_of_containing_block);
|
||||
box_state.border_left = computed_values.border_left().width;
|
||||
box_state.padding_left = computed_values.padding().left().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.padding_left = computed_values.padding().left().to_px(box, width_of_containing_block);
|
||||
|
||||
box_state.margin_right = computed_values.margin().right().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.margin_right = computed_values.margin().right().to_px(box, width_of_containing_block);
|
||||
box_state.border_right = computed_values.border_right().width;
|
||||
box_state.padding_right = computed_values.padding().right().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.padding_right = computed_values.padding().right().to_px(box, width_of_containing_block);
|
||||
|
||||
box_state.margin_top = computed_values.margin().top().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.margin_top = computed_values.margin().top().to_px(box, width_of_containing_block);
|
||||
box_state.border_top = computed_values.border_top().width;
|
||||
box_state.padding_top = computed_values.padding().top().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.padding_top = computed_values.padding().top().to_px(box, width_of_containing_block);
|
||||
|
||||
box_state.padding_bottom = computed_values.padding().bottom().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.padding_bottom = computed_values.padding().bottom().to_px(box, width_of_containing_block);
|
||||
box_state.border_bottom = computed_values.border_bottom().width;
|
||||
box_state.margin_bottom = computed_values.margin().bottom().resolved(box, width_of_containing_block).to_px(box);
|
||||
box_state.margin_bottom = computed_values.margin().bottom().to_px(box, width_of_containing_block);
|
||||
|
||||
if (is<ReplacedBox>(box)) {
|
||||
auto& replaced = verify_cast<ReplacedBox>(box);
|
||||
|
@ -155,7 +155,7 @@ void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode l
|
|||
CSSPixels width = unconstrained_width;
|
||||
auto computed_max_width = box.computed_values().max_width();
|
||||
if (!computed_max_width.is_none()) {
|
||||
auto max_width = computed_max_width.resolved(box, width_of_containing_block).to_px(box);
|
||||
auto max_width = computed_max_width.to_px(box, width_of_containing_block);
|
||||
width = min(width, max_width);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,9 +34,9 @@ void InlineLevelIterator::enter_node_with_box_model_metrics(Layout::NodeWithStyl
|
|||
auto& used_values = m_layout_state.get_mutable(node);
|
||||
auto const& computed_values = node.computed_values();
|
||||
|
||||
used_values.margin_left = computed_values.margin().left().resolved(node, CSS::Length::make_px(m_container_state.content_width())).to_px(node);
|
||||
used_values.margin_left = computed_values.margin().left().to_px(node, m_container_state.content_width());
|
||||
used_values.border_left = computed_values.border_left().width;
|
||||
used_values.padding_left = computed_values.padding().left().resolved(node, CSS::Length::make_px(m_container_state.content_width())).to_px(node);
|
||||
used_values.padding_left = computed_values.padding().left().to_px(node, m_container_state.content_width());
|
||||
|
||||
m_extra_leading_metrics->margin += used_values.margin_left;
|
||||
m_extra_leading_metrics->border += used_values.border_left;
|
||||
|
@ -54,9 +54,9 @@ void InlineLevelIterator::exit_node_with_box_model_metrics()
|
|||
auto& used_values = m_layout_state.get_mutable(node);
|
||||
auto const& computed_values = node->computed_values();
|
||||
|
||||
used_values.margin_right = computed_values.margin().right().resolved(node, CSS::Length::make_px(m_container_state.content_width())).to_px(node);
|
||||
used_values.margin_right = computed_values.margin().right().to_px(node, m_container_state.content_width());
|
||||
used_values.border_right = computed_values.border_right().width;
|
||||
used_values.padding_right = computed_values.padding().right().resolved(node, CSS::Length::make_px(m_container_state.content_width())).to_px(node);
|
||||
used_values.padding_right = computed_values.padding().right().to_px(node, m_container_state.content_width());
|
||||
|
||||
m_extra_trailing_metrics->margin += used_values.margin_right;
|
||||
m_extra_trailing_metrics->border += used_values.border_right;
|
||||
|
|
|
@ -57,8 +57,8 @@ void SVGSVGBox::prepare_for_replaced_layout()
|
|||
if (dom_node.has_attribute(HTML::AttributeNames::width) && dom_node.has_attribute(HTML::AttributeNames::height)) {
|
||||
CSSPixelRect rect;
|
||||
// FIXME: Allow for relative lengths here
|
||||
rect.set_width(computed_values().width().resolved(*this, CSS::Length::make_px(0)).to_px(*this));
|
||||
rect.set_height(computed_values().height().resolved(*this, CSS::Length::make_px(0)).to_px(*this));
|
||||
rect.set_width(computed_values().width().to_px(*this, 0));
|
||||
rect.set_height(computed_values().height().to_px(*this, 0));
|
||||
add_to_united_rect(rect);
|
||||
return IterationDecision::Continue;
|
||||
}
|
||||
|
|
|
@ -107,10 +107,9 @@ void TableFormattingContext::compute_table_measures()
|
|||
|
||||
for (auto& cell : m_cells) {
|
||||
auto width_of_containing_block = m_state.get(*table_wrapper().containing_block()).content_width();
|
||||
auto width_of_containing_block_as_length = CSS::Length::make_px(width_of_containing_block);
|
||||
auto& computed_values = cell.box->computed_values();
|
||||
CSSPixels padding_left = computed_values.padding().left().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
|
||||
CSSPixels padding_right = computed_values.padding().right().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
|
||||
CSSPixels padding_left = computed_values.padding().left().to_px(cell.box, width_of_containing_block);
|
||||
CSSPixels padding_right = computed_values.padding().right().to_px(cell.box, width_of_containing_block);
|
||||
|
||||
auto is_left_most_cell = cell.column_index == 0;
|
||||
auto is_right_most_cell = cell.column_index == m_columns.size() - 1;
|
||||
|
@ -118,18 +117,18 @@ void TableFormattingContext::compute_table_measures()
|
|||
CSSPixels border_left = should_hide_borders && !is_left_most_cell ? 0 : computed_values.border_left().width;
|
||||
CSSPixels border_right = should_hide_borders && !is_right_most_cell ? 0 : computed_values.border_right().width;
|
||||
|
||||
CSSPixels width = computed_values.width().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
|
||||
CSSPixels width = computed_values.width().to_px(cell.box, width_of_containing_block);
|
||||
auto cell_intrinsic_offsets = padding_left + padding_right + border_left + border_right;
|
||||
auto min_content_width = calculate_min_content_width(cell.box);
|
||||
auto max_content_width = calculate_max_content_width(cell.box);
|
||||
|
||||
CSSPixels min_width = min_content_width;
|
||||
if (!computed_values.min_width().is_auto())
|
||||
min_width = max(min_width, computed_values.min_width().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box));
|
||||
min_width = max(min_width, computed_values.min_width().to_px(cell.box, width_of_containing_block));
|
||||
|
||||
CSSPixels max_width = computed_values.width().is_auto() ? max_content_width.value() : width;
|
||||
if (!computed_values.max_width().is_none())
|
||||
max_width = min(max_width, computed_values.max_width().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box));
|
||||
max_width = min(max_width, computed_values.max_width().to_px(cell.box, width_of_containing_block));
|
||||
|
||||
auto computed_width = computed_values.width();
|
||||
if (computed_width.is_percentage()) {
|
||||
|
@ -235,7 +234,7 @@ void TableFormattingContext::compute_table_width()
|
|||
// The used min-width of a table is the greater of the resolved min-width, CAPMIN, and GRIDMIN.
|
||||
auto used_min_width = grid_min;
|
||||
if (!computed_values.min_width().is_auto()) {
|
||||
used_min_width = max(used_min_width, computed_values.min_width().resolved(table_box(), CSS::Length::make_px(width_of_table_wrapper_containing_block)).to_px(table_box()));
|
||||
used_min_width = max(used_min_width, computed_values.min_width().to_px(table_box(), width_of_table_wrapper_containing_block));
|
||||
}
|
||||
|
||||
CSSPixels used_width;
|
||||
|
@ -247,10 +246,10 @@ void TableFormattingContext::compute_table_width()
|
|||
// If the table-root’s width property has a computed value (resolving to
|
||||
// resolved-table-width) other than auto, the used width is the greater
|
||||
// of resolved-table-width, and the used min-width of the table.
|
||||
CSSPixels resolved_table_width = computed_values.width().resolved(table_box(), CSS::Length::make_px(width_of_table_wrapper_containing_block)).to_px(table_box());
|
||||
CSSPixels resolved_table_width = computed_values.width().to_px(table_box(), width_of_table_wrapper_containing_block);
|
||||
used_width = max(resolved_table_width, used_min_width);
|
||||
if (!computed_values.max_width().is_none())
|
||||
used_width = min(used_width, computed_values.max_width().resolved(table_box(), CSS::Length::make_px(width_of_table_wrapper_containing_block)).to_px(table_box()));
|
||||
used_width = min(used_width, computed_values.max_width().to_px(table_box(), width_of_table_wrapper_containing_block));
|
||||
}
|
||||
|
||||
// The assignable table width is the used width of the table minus the total horizontal border spacing (if any).
|
||||
|
@ -407,8 +406,7 @@ void TableFormattingContext::compute_table_height(LayoutMode layout_mode)
|
|||
auto row_computed_height = row.box->computed_values().height();
|
||||
if (row_computed_height.is_length()) {
|
||||
auto height_of_containing_block = m_state.get(*row.box->containing_block()).content_height();
|
||||
auto height_of_containing_block_as_length = CSS::Length::make_px(height_of_containing_block);
|
||||
auto row_used_height = row_computed_height.resolved(row.box, height_of_containing_block_as_length).to_px(row.box);
|
||||
auto row_used_height = row_computed_height.to_px(row.box, height_of_containing_block);
|
||||
row.base_height = max(row.base_height, row_used_height);
|
||||
}
|
||||
}
|
||||
|
@ -427,10 +425,10 @@ void TableFormattingContext::compute_table_height(LayoutMode layout_mode)
|
|||
auto height_of_containing_block = m_state.get(*cell.box->containing_block()).content_height();
|
||||
auto height_of_containing_block_as_length = CSS::Length::make_px(height_of_containing_block);
|
||||
|
||||
cell_state.padding_top = cell.box->computed_values().padding().top().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
|
||||
cell_state.padding_bottom = cell.box->computed_values().padding().bottom().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
|
||||
cell_state.padding_left = cell.box->computed_values().padding().left().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
|
||||
cell_state.padding_right = cell.box->computed_values().padding().right().resolved(cell.box, width_of_containing_block_as_length).to_px(cell.box);
|
||||
cell_state.padding_top = cell.box->computed_values().padding().top().to_px(cell.box, width_of_containing_block);
|
||||
cell_state.padding_bottom = cell.box->computed_values().padding().bottom().to_px(cell.box, width_of_containing_block);
|
||||
cell_state.padding_left = cell.box->computed_values().padding().left().to_px(cell.box, width_of_containing_block);
|
||||
cell_state.padding_right = cell.box->computed_values().padding().right().to_px(cell.box, width_of_containing_block);
|
||||
|
||||
auto is_top_most_cell = cell.row_index == 0;
|
||||
auto is_left_most_cell = cell.column_index == 0;
|
||||
|
@ -445,7 +443,7 @@ void TableFormattingContext::compute_table_height(LayoutMode layout_mode)
|
|||
|
||||
auto cell_computed_height = cell.box->computed_values().height();
|
||||
if (cell_computed_height.is_length()) {
|
||||
auto cell_used_height = cell_computed_height.resolved(cell.box, height_of_containing_block_as_length).to_px(cell.box);
|
||||
auto cell_used_height = cell_computed_height.to_px(cell.box, height_of_containing_block);
|
||||
cell_state.set_content_height(cell_used_height - cell_state.border_box_top() - cell_state.border_box_bottom());
|
||||
|
||||
row.base_height = max(row.base_height, cell_used_height);
|
||||
|
@ -476,7 +474,7 @@ void TableFormattingContext::compute_table_height(LayoutMode layout_mode)
|
|||
// table grid, and will eventually be distributed to the height of the rows if their collective minimum height
|
||||
// ends up smaller than this number.
|
||||
CSSPixels height_of_table_containing_block = m_state.get(*table_wrapper().containing_block()).content_height();
|
||||
auto specified_table_height = table_box().computed_values().height().resolved(table_box(), CSS::Length::make_px(height_of_table_containing_block)).to_px(table_box());
|
||||
auto specified_table_height = table_box().computed_values().height().to_px(table_box(), height_of_table_containing_block);
|
||||
if (m_table_height < specified_table_height) {
|
||||
m_table_height = specified_table_height;
|
||||
}
|
||||
|
@ -499,7 +497,7 @@ void TableFormattingContext::compute_table_height(LayoutMode layout_mode)
|
|||
for (auto& row : m_rows) {
|
||||
auto row_computed_height = row.box->computed_values().height();
|
||||
if (row_computed_height.is_percentage()) {
|
||||
auto row_used_height = row_computed_height.resolved(row.box, CSS::Length::make_px(m_table_height)).to_px(row.box);
|
||||
auto row_used_height = row_computed_height.to_px(row.box, m_table_height);
|
||||
row.reference_height = max(row.reference_height, row_used_height);
|
||||
} else {
|
||||
continue;
|
||||
|
@ -516,11 +514,9 @@ void TableFormattingContext::compute_table_height(LayoutMode layout_mode)
|
|||
for (size_t i = 0; i < cell.column_span; ++i)
|
||||
span_width += m_columns[cell.column_index + i].used_width;
|
||||
|
||||
auto height_of_containing_block_as_length = CSS::Length::make_px(m_table_height);
|
||||
|
||||
auto cell_computed_height = cell.box->computed_values().height();
|
||||
if (cell_computed_height.is_percentage()) {
|
||||
auto cell_used_height = cell_computed_height.resolved(cell.box, height_of_containing_block_as_length).to_px(cell.box);
|
||||
auto cell_used_height = cell_computed_height.to_px(cell.box, m_table_height);
|
||||
cell_state.set_content_height(cell_used_height - cell_state.border_box_top() - cell_state.border_box_bottom());
|
||||
|
||||
row.reference_height = max(row.reference_height, cell_used_height);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue