From 9126507dc68d63b91d127a3cdf3c76fbf07002dc Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Wed, 11 Jun 2025 09:07:16 +0200 Subject: [PATCH] LibWeb: Make fragment start/length `size_t` instead of `int` These must always be unsigned. No functional changes. --- Libraries/LibWeb/Layout/LineBox.cpp | 2 +- Libraries/LibWeb/Layout/LineBox.h | 2 +- Libraries/LibWeb/Layout/LineBoxFragment.cpp | 2 +- Libraries/LibWeb/Layout/LineBoxFragment.h | 11 +++++------ Libraries/LibWeb/Painting/Paintable.h | 2 +- Libraries/LibWeb/Painting/PaintableBox.cpp | 1 + Libraries/LibWeb/Painting/PaintableBox.h | 2 -- Libraries/LibWeb/Painting/PaintableFragment.cpp | 9 ++++----- Libraries/LibWeb/Painting/PaintableFragment.h | 10 +++++----- 9 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Libraries/LibWeb/Layout/LineBox.cpp b/Libraries/LibWeb/Layout/LineBox.cpp index 2f749c48c6c..7d31ca5817e 100644 --- a/Libraries/LibWeb/Layout/LineBox.cpp +++ b/Libraries/LibWeb/Layout/LineBox.cpp @@ -35,7 +35,7 @@ CSSPixels LineBox::bottom() const return m_bottom; } -void LineBox::add_fragment(Node const& layout_node, int start, int length, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin, CSSPixels content_width, CSSPixels content_height, CSSPixels border_box_top, CSSPixels border_box_bottom, RefPtr glyph_run) +void LineBox::add_fragment(Node const& layout_node, size_t start, size_t length, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin, CSSPixels content_width, CSSPixels content_height, CSSPixels border_box_top, CSSPixels border_box_bottom, RefPtr glyph_run) { bool text_align_is_justify = layout_node.computed_values().text_align() == CSS::TextAlign::Justify; if (glyph_run && !text_align_is_justify && !m_fragments.is_empty() && &m_fragments.last().layout_node() == &layout_node && &m_fragments.last().m_glyph_run->font() == &glyph_run->font()) { diff --git a/Libraries/LibWeb/Layout/LineBox.h b/Libraries/LibWeb/Layout/LineBox.h index 2daf8473be7..d07aae91947 100644 --- a/Libraries/LibWeb/Layout/LineBox.h +++ b/Libraries/LibWeb/Layout/LineBox.h @@ -27,7 +27,7 @@ public: CSSPixels block_length() const { return m_block_length; } CSSPixels baseline() const { return m_baseline; } - void add_fragment(Node const& layout_node, int start, int length, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin, CSSPixels content_width, CSSPixels content_height, CSSPixels border_box_top, CSSPixels border_box_bottom, RefPtr glyph_run = {}); + void add_fragment(Node const& layout_node, size_t start, size_t length, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin, CSSPixels content_width, CSSPixels content_height, CSSPixels border_box_top, CSSPixels border_box_bottom, RefPtr glyph_run = {}); Vector const& fragments() const { return m_fragments; } Vector& fragments() { return m_fragments; } diff --git a/Libraries/LibWeb/Layout/LineBoxFragment.cpp b/Libraries/LibWeb/Layout/LineBoxFragment.cpp index 3a01c65193b..13c52065185 100644 --- a/Libraries/LibWeb/Layout/LineBoxFragment.cpp +++ b/Libraries/LibWeb/Layout/LineBoxFragment.cpp @@ -11,7 +11,7 @@ namespace Web::Layout { -LineBoxFragment::LineBoxFragment(Node const& layout_node, int start, int length, CSSPixels inline_offset, CSSPixels block_offset, CSSPixels inline_length, CSSPixels block_length, CSSPixels border_box_top, CSS::Direction direction, CSS::WritingMode writing_mode, RefPtr glyph_run) +LineBoxFragment::LineBoxFragment(Node const& layout_node, size_t start, size_t length, CSSPixels inline_offset, CSSPixels block_offset, CSSPixels inline_length, CSSPixels block_length, CSSPixels border_box_top, CSS::Direction direction, CSS::WritingMode writing_mode, RefPtr glyph_run) : m_layout_node(layout_node) , m_start(start) , m_length(length) diff --git a/Libraries/LibWeb/Layout/LineBoxFragment.h b/Libraries/LibWeb/Layout/LineBoxFragment.h index 425a640eebe..888a3b094c0 100644 --- a/Libraries/LibWeb/Layout/LineBoxFragment.h +++ b/Libraries/LibWeb/Layout/LineBoxFragment.h @@ -10,7 +10,6 @@ #include #include #include -#include #include namespace Web::Layout { @@ -19,11 +18,11 @@ class LineBoxFragment { friend class LineBox; public: - LineBoxFragment(Node const& layout_node, int start, int length, CSSPixels inline_offset, CSSPixels block_offset, CSSPixels inline_length, CSSPixels block_length, CSSPixels border_box_top, CSS::Direction, CSS::WritingMode, RefPtr); + LineBoxFragment(Node const& layout_node, size_t start, size_t length, CSSPixels inline_offset, CSSPixels block_offset, CSSPixels inline_length, CSSPixels block_length, CSSPixels border_box_top, CSS::Direction, CSS::WritingMode, RefPtr); Node const& layout_node() const { return m_layout_node; } - int start() const { return m_start; } - int length() const { return m_length; } + size_t start() const { return m_start; } + size_t length() const { return m_length; } CSSPixelPoint offset() const; CSSPixels inline_offset() const { return m_inline_offset; } @@ -61,8 +60,8 @@ private: void append_glyph_run_rtl(RefPtr const&, CSSPixels run_width); GC::Ref m_layout_node; - int m_start { 0 }; - int m_length { 0 }; + size_t m_start { 0 }; + size_t m_length { 0 }; CSSPixels m_inline_offset; CSSPixels m_block_offset; CSSPixels m_inline_length; diff --git a/Libraries/LibWeb/Painting/Paintable.h b/Libraries/LibWeb/Painting/Paintable.h index 90198f8d33b..b0b40f19377 100644 --- a/Libraries/LibWeb/Painting/Paintable.h +++ b/Libraries/LibWeb/Painting/Paintable.h @@ -28,7 +28,7 @@ enum class PaintPhase { struct HitTestResult { GC::Root paintable; - int index_in_node { 0 }; + size_t index_in_node { 0 }; Optional vertical_distance {}; Optional horizontal_distance {}; diff --git a/Libraries/LibWeb/Painting/PaintableBox.cpp b/Libraries/LibWeb/Painting/PaintableBox.cpp index 8a24880e12f..6b35b50c873 100644 --- a/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include diff --git a/Libraries/LibWeb/Painting/PaintableBox.h b/Libraries/LibWeb/Painting/PaintableBox.h index 95e378c36f5..11366391c85 100644 --- a/Libraries/LibWeb/Painting/PaintableBox.h +++ b/Libraries/LibWeb/Painting/PaintableBox.h @@ -14,13 +14,11 @@ #include #include #include -#include #include #include #include #include #include -#include namespace Web::Painting { diff --git a/Libraries/LibWeb/Painting/PaintableFragment.cpp b/Libraries/LibWeb/Painting/PaintableFragment.cpp index 147776675c0..c6aef4599c5 100644 --- a/Libraries/LibWeb/Painting/PaintableFragment.cpp +++ b/Libraries/LibWeb/Painting/PaintableFragment.cpp @@ -36,7 +36,7 @@ CSSPixelRect const PaintableFragment::absolute_rect() const return rect; } -int PaintableFragment::text_index_at(CSSPixelPoint position) const +size_t PaintableFragment::text_index_at(CSSPixelPoint position) const { if (!is(paintable())) return 0; @@ -79,9 +79,8 @@ CSSPixelRect PaintableFragment::range_rect(size_t start_offset, size_t end_offse if (paintable().selection_state() == Paintable::SelectionState::Full) return absolute_rect(); - // FIXME: m_start and m_length should be unsigned and then we won't need these casts. - auto const start_index = static_cast(m_start); - auto const end_index = static_cast(m_start) + static_cast(m_length); + auto const start_index = m_start; + auto const end_index = m_start + m_length; auto const& font = glyph_run() ? glyph_run()->font() : layout_node().first_available_font(); auto text = string_view(); @@ -149,7 +148,7 @@ CSSPixelRect PaintableFragment::range_rect(size_t start_offset, size_t end_offse return {}; auto selection_start_in_this_fragment = 0; - auto selection_end_in_this_fragment = min(end_offset - m_start, m_length); + auto selection_end_in_this_fragment = min(end_offset - m_start, m_length); auto pixel_distance_to_first_selected_character = CSSPixels::nearest_value_for(font.width(text.substring_view(0, selection_start_in_this_fragment))); auto pixel_width_of_selection = CSSPixels::nearest_value_for(font.width(text.substring_view(selection_start_in_this_fragment, selection_end_in_this_fragment - selection_start_in_this_fragment))) + 1; diff --git a/Libraries/LibWeb/Painting/PaintableFragment.h b/Libraries/LibWeb/Painting/PaintableFragment.h index 59c570c5e98..0fe92b7ae6b 100644 --- a/Libraries/LibWeb/Painting/PaintableFragment.h +++ b/Libraries/LibWeb/Painting/PaintableFragment.h @@ -22,8 +22,8 @@ public: Layout::Node const& layout_node() const { return m_layout_node; } Paintable const& paintable() const { return *m_layout_node->first_paintable(); } - int start() const { return m_start; } - int length() const { return m_length; } + size_t start() const { return m_start; } + size_t length() const { return m_length; } CSSPixels baseline() const { return m_baseline; } CSSPixelPoint offset() const { return m_offset; } @@ -44,7 +44,7 @@ public: CSSPixels width() const { return m_size.width(); } CSSPixels height() const { return m_size.height(); } - int text_index_at(CSSPixelPoint) const; + size_t text_index_at(CSSPixelPoint) const; StringView string_view() const; @@ -56,8 +56,8 @@ private: CSSPixelPoint m_offset; CSSPixelSize m_size; CSSPixels m_baseline; - int m_start; - int m_length; + size_t m_start; + size_t m_length; RefPtr m_glyph_run; CSS::WritingMode m_writing_mode; Vector m_shadows;