mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:47:44 +00:00
LibWeb+WebContent: Forbid access to underlying type of CSSPixels
Although DistinctNumeric, which is supposed to abstract the underlying type, was used to represent CSSPixels, we have a whole bunch of places in the layout code that assume CSSPixels::value() returns a floating-point type. This assumption makes it difficult to replace the underlying type in CSSPixels with a non-floating type. To make it easier to transition CSSPixels to fixed-point math, one step we can take is to prevent access to the underlying type using value() and instead use explicit conversions with the to_float(), to_double(), and to_int() methods.
This commit is contained in:
parent
5a54c686a7
commit
147c3b3d97
43 changed files with 340 additions and 220 deletions
|
@ -11,7 +11,7 @@ namespace Web::Layout {
|
|||
|
||||
AvailableSize AvailableSize::make_definite(CSSPixels value)
|
||||
{
|
||||
VERIFY(isfinite(value.value()));
|
||||
VERIFY(isfinite(value.to_double()));
|
||||
return AvailableSize { Type::Definite, value };
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ void BlockFormattingContext::run(Box const&, LayoutMode layout_mode, AvailableSp
|
|||
continue;
|
||||
if (margins_collapse_through(*child_box, m_state))
|
||||
continue;
|
||||
m_state.get_mutable(*child_box).margin_bottom = m_margin_state.current_collapsed_margin().value();
|
||||
m_state.get_mutable(*child_box).margin_bottom = m_margin_state.current_collapsed_margin();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -92,14 +92,14 @@ void BlockFormattingContext::parent_context_did_dimension_child_root_box()
|
|||
// Left-side floats: offset_from_edge is from left edge (0) to left content edge of floating_box.
|
||||
for (auto& floating_box : m_left_floats.all_boxes) {
|
||||
auto& box_state = m_state.get_mutable(floating_box->box);
|
||||
box_state.set_content_x(floating_box->offset_from_edge.value());
|
||||
box_state.set_content_x(floating_box->offset_from_edge);
|
||||
}
|
||||
|
||||
// Right-side floats: offset_from_edge is from right edge (float_containing_block_width) to the left content edge of floating_box.
|
||||
for (auto& floating_box : m_right_floats.all_boxes) {
|
||||
auto float_containing_block_width = containing_block_width_for(floating_box->box);
|
||||
auto& box_state = m_state.get_mutable(floating_box->box);
|
||||
box_state.set_content_x((float_containing_block_width - floating_box->offset_from_edge).value());
|
||||
box_state.set_content_x(float_containing_block_width - floating_box->offset_from_edge);
|
||||
}
|
||||
|
||||
// We can also layout absolutely positioned boxes within this BFC.
|
||||
|
@ -214,12 +214,12 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const&
|
|||
width = CSS::Length::make_px(underflow_px);
|
||||
} else {
|
||||
width = zero_value;
|
||||
margin_right = CSS::Length::make_px(margin_right.to_px(box) + underflow_px.value());
|
||||
margin_right = CSS::Length::make_px(margin_right.to_px(box) + underflow_px);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!margin_left.is_auto() && !margin_right.is_auto()) {
|
||||
margin_right = CSS::Length::make_px(margin_right.to_px(box) + underflow_px.value());
|
||||
margin_right = CSS::Length::make_px(margin_right.to_px(box) + underflow_px);
|
||||
} else if (!margin_left.is_auto() && margin_right.is_auto()) {
|
||||
margin_right = CSS::Length::make_px(underflow_px);
|
||||
} else if (margin_left.is_auto() && !margin_right.is_auto()) {
|
||||
|
@ -542,7 +542,7 @@ CSSPixels BlockFormattingContext::compute_auto_height_for_block_level_element(Bo
|
|||
|
||||
// 1. the bottom edge of the last line box, if the box establishes a inline formatting context with one or more lines
|
||||
if (box.children_are_inline() && !box_state.line_boxes.is_empty())
|
||||
return box_state.line_boxes.last().bottom().value();
|
||||
return box_state.line_boxes.last().bottom();
|
||||
|
||||
// 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin does not collapse with the element's bottom margin
|
||||
// 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin
|
||||
|
@ -569,7 +569,7 @@ CSSPixels BlockFormattingContext::compute_auto_height_for_block_level_element(Bo
|
|||
margin_bottom = 0;
|
||||
}
|
||||
|
||||
return max(0.0f, (child_box_state.offset.y() + child_box_state.content_height() + child_box_state.border_box_bottom() + margin_bottom).value());
|
||||
return max(CSSPixels(0), child_box_state.offset.y() + child_box_state.content_height() + child_box_state.border_box_bottom() + margin_bottom);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -795,7 +795,7 @@ void BlockFormattingContext::place_block_level_element_in_normal_flow_vertically
|
|||
{
|
||||
auto& box_state = m_state.get_mutable(child_box);
|
||||
y += box_state.border_box_top();
|
||||
box_state.set_content_offset(CSSPixelPoint { box_state.offset.x(), y.value() });
|
||||
box_state.set_content_offset(CSSPixelPoint { box_state.offset.x(), y });
|
||||
}
|
||||
|
||||
void BlockFormattingContext::place_block_level_element_in_normal_flow_horizontally(Box const& child_box, AvailableSpace const& available_space)
|
||||
|
@ -819,7 +819,7 @@ void BlockFormattingContext::place_block_level_element_in_normal_flow_horizontal
|
|||
x += box_state.margin_box_left();
|
||||
}
|
||||
|
||||
box_state.set_content_offset({ x.value(), box_state.offset.y() });
|
||||
box_state.set_content_offset({ x, box_state.offset.y() });
|
||||
}
|
||||
|
||||
void BlockFormattingContext::layout_viewport(LayoutMode layout_mode, AvailableSpace const& available_space)
|
||||
|
@ -960,7 +960,7 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
|
|||
|
||||
// NOTE: We don't set the X position here, that happens later, once we know the root block width.
|
||||
// See parent_context_did_dimension_child_root_box() for that logic.
|
||||
box_state.set_content_y(y.value());
|
||||
box_state.set_content_y(y);
|
||||
|
||||
// If the new box was inserted below the bottom of the opposite side,
|
||||
// we reset the other side back to its edge.
|
||||
|
@ -1003,13 +1003,13 @@ void BlockFormattingContext::layout_list_item_marker(ListItemBox const& list_ite
|
|||
CSSPixels default_marker_width = max(4, marker.font().pixel_size_rounded_up() - 4);
|
||||
|
||||
if (marker.text().is_empty()) {
|
||||
marker_state.set_content_width((image_width + default_marker_width).value());
|
||||
marker_state.set_content_width(image_width + default_marker_width);
|
||||
} else {
|
||||
auto text_width = marker.font().width(marker.text());
|
||||
marker_state.set_content_width((image_width + text_width).value());
|
||||
marker_state.set_content_width(image_width + text_width);
|
||||
}
|
||||
|
||||
marker_state.set_content_height(max(image_height, marker.font().pixel_size_rounded_up() + 1).value());
|
||||
marker_state.set_content_height(max(image_height, marker.font().pixel_size_rounded_up() + 1));
|
||||
|
||||
if (marker.list_style_type() == CSS::ListStyleType::DisclosureClosed || marker.list_style_type() == CSS::ListStyleType::DisclosureOpen)
|
||||
marker_state.set_content_width(marker_state.content_height());
|
||||
|
@ -1036,7 +1036,7 @@ BlockFormattingContext::SpaceUsedByFloats BlockFormattingContext::space_used_by_
|
|||
auto const& floating_box_state = m_state.get(floating_box.box);
|
||||
// NOTE: The floating box is *not* in the final horizontal position yet, but the size and vertical position is valid.
|
||||
auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box.box, root());
|
||||
if (rect.contains_vertically(y.value())) {
|
||||
if (rect.contains_vertically(y)) {
|
||||
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
|
||||
for (auto const* containing_block = floating_box.box->containing_block(); containing_block && containing_block != &root(); containing_block = containing_block->containing_block()) {
|
||||
auto const& containing_block_state = m_state.get(*containing_block);
|
||||
|
@ -1055,7 +1055,7 @@ BlockFormattingContext::SpaceUsedByFloats BlockFormattingContext::space_used_by_
|
|||
auto const& floating_box_state = m_state.get(floating_box.box);
|
||||
// NOTE: The floating box is *not* in the final horizontal position yet, but the size and vertical position is valid.
|
||||
auto rect = margin_box_rect_in_ancestor_coordinate_space(floating_box.box, root());
|
||||
if (rect.contains_vertically(y.value())) {
|
||||
if (rect.contains_vertically(y)) {
|
||||
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
|
||||
for (auto const* containing_block = floating_box.box->containing_block(); containing_block && containing_block != &root(); containing_block = containing_block->containing_block()) {
|
||||
auto const& containing_block_state = m_state.get(*containing_block);
|
||||
|
@ -1103,7 +1103,7 @@ CSSPixels BlockFormattingContext::greatest_child_width(Box const& box) const
|
|||
// NOTE: Floats directly affect the automatic size of their containing block, but only indirectly anything above in the tree.
|
||||
if (left_float->box->containing_block() != &box)
|
||||
continue;
|
||||
if (line_box.baseline() >= left_float->top_margin_edge.value() || line_box.baseline() <= left_float->bottom_margin_edge.value()) {
|
||||
if (line_box.baseline() >= left_float->top_margin_edge || line_box.baseline() <= left_float->bottom_margin_edge) {
|
||||
auto const& left_float_state = m_state.get(left_float->box);
|
||||
extra_width_from_left_floats = max(extra_width_from_left_floats, left_float->offset_from_edge + left_float_state.content_width() + left_float_state.margin_box_right());
|
||||
}
|
||||
|
@ -1113,7 +1113,7 @@ CSSPixels BlockFormattingContext::greatest_child_width(Box const& box) const
|
|||
// NOTE: Floats directly affect the automatic size of their containing block, but only indirectly anything above in the tree.
|
||||
if (right_float->box->containing_block() != &box)
|
||||
continue;
|
||||
if (line_box.baseline() >= right_float->top_margin_edge.value() || line_box.baseline() <= right_float->bottom_margin_edge.value()) {
|
||||
if (line_box.baseline() >= right_float->top_margin_edge || line_box.baseline() <= right_float->bottom_margin_edge) {
|
||||
auto const& right_float_state = m_state.get(right_float->box);
|
||||
extra_width_from_right_floats = max(extra_width_from_right_floats, right_float->offset_from_edge + right_float_state.margin_box_left());
|
||||
}
|
||||
|
|
|
@ -1037,7 +1037,7 @@ void FlexFormattingContext::resolve_flexible_lengths_for_line(FlexLine& line)
|
|||
for (auto& item : line.items) {
|
||||
if (item.frozen)
|
||||
continue;
|
||||
item.scaled_flex_shrink_factor = item.flex_factor.value() * item.flex_base_size.value();
|
||||
item.scaled_flex_shrink_factor = item.flex_factor.value() * item.flex_base_size.to_double();
|
||||
}
|
||||
auto sum_of_scaled_flex_shrink_factors_of_all_unfrozen_items_on_line = line.sum_of_scaled_flex_shrink_factor_of_unfrozen_items();
|
||||
for (auto& item : line.items) {
|
||||
|
@ -1123,7 +1123,7 @@ void FlexFormattingContext::resolve_flexible_lengths_for_line(FlexLine& line)
|
|||
|
||||
// AD-HOC: Due to the way we calculate the remaining free space, it can be infinite when sizing
|
||||
// under a max-content constraint. In that case, we can simply set it to zero here.
|
||||
if (!isfinite(line.remaining_free_space.value()))
|
||||
if (!isfinite(line.remaining_free_space.to_double()))
|
||||
line.remaining_free_space = 0;
|
||||
|
||||
// 6. Set each item’s used main size to its target main size.
|
||||
|
@ -1704,7 +1704,7 @@ CSSPixels FlexFormattingContext::calculate_intrinsic_main_size_of_flex_container
|
|||
result /= item.scaled_flex_shrink_factor;
|
||||
}
|
||||
|
||||
item.desired_flex_fraction = result.value();
|
||||
item.desired_flex_fraction = result.to_double();
|
||||
}
|
||||
|
||||
// 2. Place all flex items into lines of infinite length.
|
||||
|
|
|
@ -960,7 +960,7 @@ CSSPixelPoint FormattingContext::calculate_static_position(Box const& box) const
|
|||
}
|
||||
}
|
||||
if (last_fragment) {
|
||||
y = (last_fragment->offset().y() + last_fragment->height()).value();
|
||||
y = last_fragment->offset().y() + last_fragment->height();
|
||||
}
|
||||
} else {
|
||||
// Easy case: no previous sibling, we're at the top of the containing block.
|
||||
|
@ -1179,7 +1179,7 @@ CSSPixels FormattingContext::calculate_min_content_width(Layout::Box const& box)
|
|||
|
||||
cache.min_content_width = context->automatic_content_width();
|
||||
|
||||
if (!isfinite(cache.min_content_width->value())) {
|
||||
if (!isfinite(cache.min_content_width->to_double())) {
|
||||
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
|
||||
dbgln("FIXME: Calculated non-finite min-content width for {}", box.debug_description());
|
||||
cache.min_content_width = 0;
|
||||
|
@ -1217,7 +1217,7 @@ CSSPixels FormattingContext::calculate_max_content_width(Layout::Box const& box)
|
|||
|
||||
cache.max_content_width = context->automatic_content_width();
|
||||
|
||||
if (!isfinite(cache.max_content_width->value())) {
|
||||
if (!isfinite(cache.max_content_width->to_double())) {
|
||||
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
|
||||
dbgln("FIXME: Calculated non-finite max-content width for {}", box.debug_description());
|
||||
cache.max_content_width = 0;
|
||||
|
@ -1271,7 +1271,7 @@ CSSPixels FormattingContext::calculate_min_content_height(Layout::Box const& box
|
|||
context->run(box, LayoutMode::IntrinsicSizing, AvailableSpace(available_width, AvailableSize::make_min_content()));
|
||||
|
||||
auto min_content_height = context->automatic_content_height();
|
||||
if (!isfinite(min_content_height.value())) {
|
||||
if (!isfinite(min_content_height.to_double())) {
|
||||
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
|
||||
dbgln("FIXME: Calculated non-finite min-content height for {}", box.debug_description());
|
||||
min_content_height = 0;
|
||||
|
@ -1327,7 +1327,7 @@ CSSPixels FormattingContext::calculate_max_content_height(Layout::Box const& box
|
|||
|
||||
auto max_content_height = context->automatic_content_height();
|
||||
|
||||
if (!isfinite(max_content_height.value())) {
|
||||
if (!isfinite(max_content_height.to_double())) {
|
||||
// HACK: If layout calculates a non-finite result, something went wrong. Force it to zero and log a little whine.
|
||||
dbgln("FIXME: Calculated non-finite max-content height for {}", box.debug_description());
|
||||
max_content_height = 0;
|
||||
|
|
|
@ -119,7 +119,7 @@ int GridFormattingContext::count_of_repeated_auto_fill_or_fit_tracks(Vector<CSS:
|
|||
sum_of_grid_track_sizes += min(resolve_definite_track_size(track_sizing_function.grid_size(), available_space), resolve_definite_track_size(track_sizing_function.grid_size(), available_space));
|
||||
}
|
||||
}
|
||||
return max(1, static_cast<int>((get_free_space(available_space, GridDimension::Column).to_px() / sum_of_grid_track_sizes).value()));
|
||||
return max(1, static_cast<int>((get_free_space(available_space, GridDimension::Column).to_px() / sum_of_grid_track_sizes).to_double()));
|
||||
|
||||
// For the purpose of finding the number of auto-repeated tracks in a standalone axis, the UA must
|
||||
// floor the track size to a UA-specified value to avoid division by zero. It is suggested that this
|
||||
|
@ -800,7 +800,7 @@ void GridFormattingContext::resolve_intrinsic_track_sizes(AvailableSpace const&
|
|||
// 5. If any track still has an infinite growth limit (because, for example, it had no items placed in
|
||||
// it or it is a flexible track), set its growth limit to its base size.
|
||||
for (auto& track : tracks_and_gaps) {
|
||||
if (!isfinite(track.growth_limit.value())) {
|
||||
if (!isfinite(track.growth_limit.to_double())) {
|
||||
track.growth_limit = track.base_size;
|
||||
}
|
||||
}
|
||||
|
@ -879,7 +879,7 @@ void GridFormattingContext::distribute_extra_space_across_spanned_tracks_growth_
|
|||
// 1. Find the space to distribute:
|
||||
CSSPixels spanned_tracks_sizes_sum = 0;
|
||||
for (auto& track : spanned_tracks) {
|
||||
if (isfinite(track.growth_limit.value())) {
|
||||
if (isfinite(track.growth_limit.to_double())) {
|
||||
spanned_tracks_sizes_sum += track.growth_limit;
|
||||
} else {
|
||||
spanned_tracks_sizes_sum += track.base_size;
|
||||
|
@ -1005,7 +1005,7 @@ void GridFormattingContext::increase_sizes_to_accommodate_spanning_items_crossin
|
|||
return track.max_track_sizing_function.is_intrinsic(available_size);
|
||||
});
|
||||
for (auto& track : spanned_tracks) {
|
||||
if (!isfinite(track.growth_limit.value())) {
|
||||
if (!isfinite(track.growth_limit.to_double())) {
|
||||
// If the affected size is an infinite growth limit, set it to the track’s base size plus the planned increase.
|
||||
track.growth_limit = track.base_size + track.planned_increase;
|
||||
// Mark any tracks whose growth limit changed from infinite to finite in this step as infinitely growable
|
||||
|
@ -1025,7 +1025,7 @@ void GridFormattingContext::increase_sizes_to_accommodate_spanning_items_crossin
|
|||
return track.max_track_sizing_function.is_max_content() || track.max_track_sizing_function.is_auto(available_size);
|
||||
});
|
||||
for (auto& track : spanned_tracks) {
|
||||
if (!isfinite(track.growth_limit.value())) {
|
||||
if (!isfinite(track.growth_limit.to_double())) {
|
||||
// If the affected size is an infinite growth limit, set it to the track’s base size plus the planned increase.
|
||||
track.growth_limit = track.base_size + track.planned_increase;
|
||||
} else {
|
||||
|
@ -1098,7 +1098,7 @@ void GridFormattingContext::maximize_tracks(AvailableSpace const& available_spac
|
|||
while (free_space_px > 0) {
|
||||
auto free_space_to_distribute_per_track = free_space_px / tracks.size();
|
||||
for (auto& track : tracks) {
|
||||
VERIFY(isfinite(track.growth_limit.value()));
|
||||
VERIFY(isfinite(track.growth_limit.to_double()));
|
||||
track.base_size = min(track.growth_limit, track.base_size + free_space_to_distribute_per_track);
|
||||
}
|
||||
if (get_free_space_px() == free_space_px)
|
||||
|
|
|
@ -205,7 +205,7 @@ void InlineFormattingContext::apply_justification_to_fragments(CSS::TextJustify
|
|||
}
|
||||
}
|
||||
|
||||
CSSPixels justified_space_width = whitespace_count > 0 ? (excess_horizontal_space_including_whitespace / static_cast<double>(whitespace_count)) : 0;
|
||||
CSSPixels justified_space_width = whitespace_count > 0 ? (excess_horizontal_space_including_whitespace / whitespace_count) : 0;
|
||||
|
||||
// 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
|
||||
|
|
|
@ -108,10 +108,10 @@ void LayoutState::commit()
|
|||
auto& node = const_cast<NodeWithStyleAndBoxModelMetrics&>(used_values.node());
|
||||
|
||||
// Transfer box model metrics.
|
||||
node.box_model().inset = { used_values.inset_top.value(), used_values.inset_right.value(), used_values.inset_bottom.value(), used_values.inset_left.value() };
|
||||
node.box_model().padding = { used_values.padding_top.value(), used_values.padding_right.value(), used_values.padding_bottom.value(), used_values.padding_left.value() };
|
||||
node.box_model().border = { used_values.border_top.value(), used_values.border_right.value(), used_values.border_bottom.value(), used_values.border_left.value() };
|
||||
node.box_model().margin = { used_values.margin_top.value(), used_values.margin_right.value(), used_values.margin_bottom.value(), used_values.margin_left.value() };
|
||||
node.box_model().inset = { used_values.inset_top, used_values.inset_right, used_values.inset_bottom, used_values.inset_left };
|
||||
node.box_model().padding = { used_values.padding_top, used_values.padding_right, used_values.padding_bottom, used_values.padding_left };
|
||||
node.box_model().border = { used_values.border_top, used_values.border_right, used_values.border_bottom, used_values.border_left };
|
||||
node.box_model().margin = { used_values.margin_top, used_values.margin_right, used_values.margin_bottom, used_values.margin_left };
|
||||
|
||||
node.set_paintable(node.create_paintable());
|
||||
|
||||
|
@ -297,7 +297,7 @@ void LayoutState::UsedValues::set_node(NodeWithStyleAndBoxModelMetrics& node, Us
|
|||
|
||||
void LayoutState::UsedValues::set_content_width(CSSPixels width)
|
||||
{
|
||||
VERIFY(isfinite(width.value()));
|
||||
VERIFY(isfinite(width.to_double()));
|
||||
if (width < 0) {
|
||||
// Negative widths are not allowed in CSS. We have a bug somewhere! Clamp to 0 to avoid doing too much damage.
|
||||
dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Layout calculated a negative width for {}: {}", m_node->debug_description(), width);
|
||||
|
@ -309,7 +309,7 @@ void LayoutState::UsedValues::set_content_width(CSSPixels width)
|
|||
|
||||
void LayoutState::UsedValues::set_content_height(CSSPixels height)
|
||||
{
|
||||
VERIFY(isfinite(height.value()));
|
||||
VERIFY(isfinite(height.to_double()));
|
||||
if (height < 0) {
|
||||
// Negative heights are not allowed in CSS. We have a bug somewhere! Clamp to 0 to avoid doing too much damage.
|
||||
dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Layout calculated a negative height for {}: {}", m_node->debug_description(), height);
|
||||
|
|
|
@ -35,7 +35,7 @@ void LineBox::trim_trailing_whitespace()
|
|||
{
|
||||
while (!m_fragments.is_empty() && m_fragments.last().is_justifiable_whitespace()) {
|
||||
auto fragment = m_fragments.take_last();
|
||||
m_width -= fragment.width().value();
|
||||
m_width -= fragment.width();
|
||||
}
|
||||
|
||||
if (m_fragments.is_empty())
|
||||
|
|
|
@ -136,7 +136,7 @@ CSSPixels LineBuilder::y_for_float_to_be_inserted_here(Box const& box)
|
|||
|
||||
bool LineBuilder::should_break(CSSPixels next_item_width)
|
||||
{
|
||||
if (!isfinite(m_available_width_for_current_line.value()))
|
||||
if (!isfinite(m_available_width_for_current_line.to_double()))
|
||||
return false;
|
||||
|
||||
auto const& line_boxes = m_containing_block_state.line_boxes;
|
||||
|
@ -228,7 +228,7 @@ void LineBuilder::update_last_line()
|
|||
if (length_percentage->is_length())
|
||||
fragment_baseline += length_percentage->length().to_px(fragment.layout_node());
|
||||
else if (length_percentage->is_percentage())
|
||||
fragment_baseline += static_cast<double>(length_percentage->percentage().as_fraction()) * line_height;
|
||||
fragment_baseline += length_percentage->percentage().as_fraction() * line_height.to_double();
|
||||
}
|
||||
|
||||
line_box_baseline = max(line_box_baseline, fragment_baseline);
|
||||
|
@ -282,7 +282,7 @@ void LineBuilder::update_last_line()
|
|||
auto vertical_align_amount = length_percentage->length().to_px(fragment.layout_node());
|
||||
new_fragment_y = y_value_for_alignment(CSS::VerticalAlign::Baseline) - vertical_align_amount;
|
||||
} else if (length_percentage->is_percentage()) {
|
||||
auto vertical_align_amount = static_cast<double>(length_percentage->percentage().as_fraction()) * m_context.containing_block().line_height();
|
||||
auto vertical_align_amount = length_percentage->percentage().as_fraction() * m_context.containing_block().line_height().to_double();
|
||||
new_fragment_y = y_value_for_alignment(CSS::VerticalAlign::Baseline) - vertical_align_amount;
|
||||
}
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ void LineBuilder::update_last_line()
|
|||
if (length_percentage->is_length())
|
||||
bottom_of_inline_box += length_percentage->length().to_px(fragment.layout_node());
|
||||
else if (length_percentage->is_percentage())
|
||||
bottom_of_inline_box += static_cast<double>(length_percentage->percentage().as_fraction()) * m_context.containing_block().line_height();
|
||||
bottom_of_inline_box += length_percentage->percentage().as_fraction() * m_context.containing_block().line_height().to_double();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -298,7 +298,7 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
|
|||
// m_font is used by Length::to_px() when resolving sizes against this layout node.
|
||||
// That's why it has to be set before everything else.
|
||||
m_font = computed_style.computed_font();
|
||||
computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->as_length().length().to_px(*this).value());
|
||||
computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->as_length().length().to_px(*this).to_double());
|
||||
computed_values.set_font_weight(round_to<int>(computed_style.property(CSS::PropertyID::FontWeight)->as_number().number()));
|
||||
m_line_height = computed_style.line_height(*this);
|
||||
|
||||
|
@ -644,9 +644,9 @@ void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
|
|||
auto resolve_border_width = [&]() -> double {
|
||||
auto value = computed_style.property(width_property);
|
||||
if (value->is_calculated())
|
||||
return value->as_calculated().resolve_length(*this)->to_px(*this).value();
|
||||
return value->as_calculated().resolve_length(*this)->to_px(*this).to_double();
|
||||
if (value->is_length())
|
||||
return value->as_length().length().to_px(*this).value();
|
||||
return value->as_length().length().to_px(*this).to_double();
|
||||
if (value->is_identifier()) {
|
||||
// https://www.w3.org/TR/css-backgrounds-3/#valdef-line-width-thin
|
||||
switch (value->to_identifier()) {
|
||||
|
|
|
@ -168,12 +168,12 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
|
|||
}
|
||||
|
||||
auto view_box = maybe_view_box.value();
|
||||
auto scale_width = svg_box_state.has_definite_width() ? svg_box_state.content_width().value() / view_box.width : 1;
|
||||
auto scale_height = svg_box_state.has_definite_height() ? svg_box_state.content_height().value() / view_box.height : 1;
|
||||
auto scale_width = svg_box_state.has_definite_width() ? svg_box_state.content_width() / view_box.width : 1;
|
||||
auto scale_height = svg_box_state.has_definite_height() ? svg_box_state.content_height() / view_box.height : 1;
|
||||
|
||||
// The initial value for preserveAspectRatio is xMidYMid meet.
|
||||
auto preserve_aspect_ratio = svg_svg_element.preserve_aspect_ratio().value_or(SVG::PreserveAspectRatio {});
|
||||
auto viewbox_transform = scale_and_align_viewbox_content(preserve_aspect_ratio, view_box, { scale_width, scale_height }, svg_box_state);
|
||||
auto viewbox_transform = scale_and_align_viewbox_content(preserve_aspect_ratio, view_box, { scale_width.to_double(), scale_height.to_double() }, svg_box_state);
|
||||
path_transform = Gfx::AffineTransform {}.translate(viewbox_transform.offset.to_type<double>().to_type<float>()).scale(viewbox_transform.scale_factor, viewbox_transform.scale_factor).translate({ -view_box.min_x, -view_box.min_y }).multiply(path_transform);
|
||||
viewbox_scale = viewbox_transform.scale_factor;
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ Optional<Gfx::AffineTransform> SVGGeometryBox::layout_transform() const
|
|||
// If the transform (or path) results in a empty box we can't display this.
|
||||
if (original_bounding_box.is_empty())
|
||||
return {};
|
||||
auto scaled_width = paintable_box()->content_width().value();
|
||||
auto scaled_height = paintable_box()->content_height().value();
|
||||
auto scaled_width = paintable_box()->content_width().to_double();
|
||||
auto scaled_height = paintable_box()->content_height().to_double();
|
||||
scaling = min(scaled_width / static_cast<double>(original_bounding_box.width()), scaled_height / static_cast<double>(original_bounding_box.height()));
|
||||
auto scaled_bounding_box = original_bounding_box.scaled(scaling, scaling);
|
||||
paint_offset = (paintable_box()->absolute_rect().location() - svg_box->paintable_box()->absolute_rect().location()).to_type<double>().to_type<float>() - scaled_bounding_box.location();
|
||||
|
|
|
@ -57,7 +57,7 @@ Optional<float> SVGSVGBox::calculate_intrinsic_aspect_ratio() const
|
|||
|
||||
if (width != 0 && height != 0) {
|
||||
// 1. return width / height
|
||||
return width.value() / height.value();
|
||||
return width.to_double() / height.to_double();
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
|
@ -184,8 +184,8 @@ void TableFormattingContext::compute_cell_measures(AvailableSpace const& availab
|
|||
if (!computed_values.min_width().is_auto())
|
||||
min_width = max(min_width, computed_values.min_width().to_px(cell.box, containing_block.content_width()));
|
||||
|
||||
CSSPixels max_height = computed_values.height().is_auto() ? max_content_height.value() : height;
|
||||
CSSPixels max_width = computed_values.width().is_auto() ? max_content_width.value() : width;
|
||||
CSSPixels max_height = computed_values.height().is_auto() ? max_content_height : height;
|
||||
CSSPixels max_width = computed_values.width().is_auto() ? max_content_width : width;
|
||||
if (!computed_values.max_height().is_none())
|
||||
max_height = min(max_height, computed_values.max_height().to_px(cell.box, containing_block.content_height()));
|
||||
if (!computed_values.max_width().is_none())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue