diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-11-03 17:48:46 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-01-05 17:42:31 +0100 |
commit | 056acb5ebfd906260607100d37d309a03c4f97b8 (patch) | |
tree | 9594f46bc2d1e595a2d9cc3bb006016ae537ddb6 /Userland/Libraries/LibWeb | |
parent | 55ddfa9348d4000c564f35f59d547e13d1090ce5 (diff) | |
download | serenity-056acb5ebfd906260607100d37d309a03c4f97b8.zip |
LibWeb: Convert InlineFormattingContext to new pixel units
Diffstat (limited to 'Userland/Libraries/LibWeb')
3 files changed, 37 insertions, 37 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 59f7ce01db..570c9b932a 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -38,27 +38,27 @@ BlockFormattingContext const& InlineFormattingContext::parent() const return static_cast<BlockFormattingContext const&>(*FormattingContext::parent()); } -float InlineFormattingContext::leftmost_x_offset_at(float y) const +CSSPixels InlineFormattingContext::leftmost_x_offset_at(CSSPixels y) const { // NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC. - auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root(), m_state); - float y_in_root = box_in_root_rect.y() + y; + auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root(), m_state).to_type<CSSPixels>(); + CSSPixels y_in_root = box_in_root_rect.y() + y; auto space = parent().space_used_by_floats(y_in_root); - return space.left.value(); + return space.left; } -float InlineFormattingContext::available_space_for_line(float y) const +CSSPixels InlineFormattingContext::available_space_for_line(CSSPixels y) const { // NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC. auto& root_block = parent().root(); - auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), root_block, m_state); - float y_in_root = box_in_root_rect.y() + y; + auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), root_block, m_state).to_type<CSSPixels>(); + CSSPixels y_in_root = box_in_root_rect.y() + y; auto space = parent().space_used_by_floats(y_in_root); space.left = space.left; space.right = min(m_available_space->width.to_px() - space.right, m_available_space->width.to_px()); - return (space.right - space.left).value(); + return space.right - space.left; } CSSPixels InlineFormattingContext::automatic_content_width() const @@ -77,8 +77,8 @@ void InlineFormattingContext::run(Box const&, LayoutMode layout_mode, AvailableS m_available_space = available_space; generate_line_boxes(layout_mode); - float max_line_width = 0; - float content_height = 0; + CSSPixels max_line_width = 0; + CSSPixels content_height = 0; for (auto& line_box : m_containing_block_state.line_boxes) { max_line_width = max(max_line_width, line_box.width()); @@ -126,7 +126,7 @@ void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode l VERIFY(!box.display().is_flow_inside()); auto const& width_value = box.computed_values().width(); - float unconstrained_width = 0; + CSSPixels unconstrained_width = 0; if (should_treat_width_as_auto(box, *m_available_space)) { auto result = calculate_shrink_to_fit_widths(box); @@ -138,7 +138,7 @@ void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode l - box_state.border_right - box_state.margin_right; - unconstrained_width = min(max(result.preferred_minimum_width, available_width), result.preferred_width).value(); + unconstrained_width = min(max(result.preferred_minimum_width, available_width), result.preferred_width); } else { if (width_value.contains_percentage() && !m_available_space->width.is_definite()) { // NOTE: We can't resolve percentages yet. We'll have to wait until after inner layout. @@ -148,7 +148,7 @@ void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode l } } - float width = unconstrained_width; + 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); @@ -161,7 +161,7 @@ void InlineFormattingContext::dimension_box_on_line(Box const& box, LayoutMode l width = max(width, min_width); } - box_state.set_content_width(width); + box_state.set_content_width(width.value()); auto independent_formatting_context = layout_inside(box, layout_mode, box_state.available_inner_space_or_constraints_from(*m_available_space)); @@ -190,28 +190,28 @@ void InlineFormattingContext::apply_justification_to_fragments(CSS::TextJustify break; } - float excess_horizontal_space = m_available_space->width.to_px().value() - line_box.width(); + CSSPixels excess_horizontal_space = m_available_space->width.to_px() - line_box.width(); // Only justify the text if the excess horizontal space is less than or // equal to 10%, or if we are not looking at the last line box. if (is_last_line && excess_horizontal_space / m_available_space->width.to_px().value() > text_justification_threshold) return; - float excess_horizontal_space_including_whitespace = excess_horizontal_space; + CSSPixels excess_horizontal_space_including_whitespace = excess_horizontal_space; size_t whitespace_count = 0; for (auto& fragment : line_box.fragments()) { if (fragment.is_justifiable_whitespace()) { ++whitespace_count; - excess_horizontal_space_including_whitespace += fragment.width().value(); + excess_horizontal_space_including_whitespace += fragment.width(); } } - float justified_space_width = whitespace_count > 0 ? (excess_horizontal_space_including_whitespace / static_cast<float>(whitespace_count)) : 0; + CSSPixels justified_space_width = whitespace_count > 0 ? (excess_horizontal_space_including_whitespace / static_cast<float>(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 // subsequent fragments, and decreases to pull them back otherwise. - float running_diff = 0; + CSSPixels running_diff = 0; for (size_t i = 0; i < line_box.fragments().size(); ++i) { auto& fragment = line_box.fragments()[i]; @@ -221,7 +221,7 @@ void InlineFormattingContext::apply_justification_to_fragments(CSS::TextJustify if (fragment.is_justifiable_whitespace() && fragment.width() != justified_space_width) { - running_diff += justified_space_width - fragment.width().value(); + running_diff += justified_space_width - fragment.width(); fragment.set_width(justified_space_width); } } @@ -315,18 +315,18 @@ void InlineFormattingContext::generate_line_boxes(LayoutMode layout_mode) } } -bool InlineFormattingContext::any_floats_intrude_at_y(float y) const +bool InlineFormattingContext::any_floats_intrude_at_y(CSSPixels y) const { - auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root(), m_state); - float y_in_root = box_in_root_rect.y() + y; + auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root(), m_state).to_type<CSSPixels>(); + CSSPixels y_in_root = box_in_root_rect.y() + y; auto space = parent().space_used_by_floats(y_in_root); return space.left > 0 || space.right > 0; } -bool InlineFormattingContext::can_fit_new_line_at_y(float y) const +bool InlineFormattingContext::can_fit_new_line_at_y(CSSPixels y) const { - auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root(), m_state); - float y_in_root = box_in_root_rect.y() + y; + auto box_in_root_rect = content_box_rect_in_ancestor_coordinate_space(containing_block(), parent().root(), m_state).to_type<CSSPixels>(); + CSSPixels y_in_root = box_in_root_rect.y() + y; auto space_top = parent().space_used_by_floats(y_in_root); auto space_bottom = parent().space_used_by_floats(y_in_root + containing_block().line_height() - 1); diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h index 38033eaded..c795c345fd 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.h @@ -29,10 +29,10 @@ public: void dimension_box_on_line(Box const&, LayoutMode); - float leftmost_x_offset_at(float y) const; - float available_space_for_line(float y) const; - bool any_floats_intrude_at_y(float y) const; - bool can_fit_new_line_at_y(float y) const; + CSSPixels leftmost_x_offset_at(CSSPixels y) const; + CSSPixels available_space_for_line(CSSPixels y) const; + bool any_floats_intrude_at_y(CSSPixels y) const; + bool can_fit_new_line_at_y(CSSPixels y) const; private: void generate_line_boxes(LayoutMode); @@ -42,8 +42,8 @@ private: Optional<AvailableSpace> m_available_space; - float m_automatic_content_width { 0 }; - float m_automatic_content_height { 0 }; + CSSPixels m_automatic_content_width { 0 }; + CSSPixels m_automatic_content_height { 0 }; }; } diff --git a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp index bee5cc6594..bc430f0c69 100644 --- a/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp +++ b/Userland/Libraries/LibWeb/Layout/LineBuilder.cpp @@ -110,8 +110,8 @@ float LineBuilder::y_for_float_to_be_inserted_here(Box const& box) // FIXME: This is super dumb, we move 1px downwards per iteration and stop // when we find an Y value where we don't collide with other floats. while (true) { - auto space_at_y_top = m_context.available_space_for_line(candidate_y); - auto space_at_y_bottom = m_context.available_space_for_line(candidate_y + height); + auto space_at_y_top = m_context.available_space_for_line(candidate_y).value(); + auto space_at_y_bottom = m_context.available_space_for_line(candidate_y + height).value(); if (width > space_at_y_top || width > space_at_y_bottom) { if (!m_context.any_floats_intrude_at_y(candidate_y) && !m_context.any_floats_intrude_at_y(candidate_y + height)) { return candidate_y; @@ -154,8 +154,8 @@ void LineBuilder::update_last_line() auto text_align = m_context.containing_block().computed_values().text_align(); auto current_line_height = max(m_max_height_on_current_line, m_context.containing_block().line_height()); - float x_offset_top = m_context.leftmost_x_offset_at(m_current_y); - float x_offset_bottom = m_context.leftmost_x_offset_at(m_current_y + current_line_height - 1); + float x_offset_top = m_context.leftmost_x_offset_at(m_current_y).value(); + float x_offset_bottom = m_context.leftmost_x_offset_at(m_current_y + current_line_height - 1).value(); float x_offset = max(x_offset_top, x_offset_bottom); float excess_horizontal_space = m_available_width_for_current_line - line_box.width(); @@ -306,7 +306,7 @@ void LineBuilder::recalculate_available_space() auto current_line_height = max(m_max_height_on_current_line, m_context.containing_block().line_height()); auto available_at_top_of_line_box = m_context.available_space_for_line(m_current_y); auto available_at_bottom_of_line_box = m_context.available_space_for_line(m_current_y + current_line_height - 1); - m_available_width_for_current_line = min(available_at_bottom_of_line_box, available_at_top_of_line_box); + m_available_width_for_current_line = min(available_at_bottom_of_line_box, available_at_top_of_line_box).value(); } } |