LibWeb: Make fragment start/length size_t instead of int

These must always be unsigned. No functional changes.
This commit is contained in:
Jelle Raaijmakers 2025-06-11 09:07:16 +02:00 committed by Jelle Raaijmakers
commit 9126507dc6
Notes: github-actions[bot] 2025-06-13 13:10:39 +00:00
9 changed files with 19 additions and 22 deletions

View file

@ -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<Gfx::GlyphRun> 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<Gfx::GlyphRun> 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()) {

View file

@ -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<Gfx::GlyphRun> 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<Gfx::GlyphRun> glyph_run = {});
Vector<LineBoxFragment> const& fragments() const { return m_fragments; }
Vector<LineBoxFragment>& fragments() { return m_fragments; }

View file

@ -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<Gfx::GlyphRun> 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<Gfx::GlyphRun> glyph_run)
: m_layout_node(layout_node)
, m_start(start)
, m_length(length)

View file

@ -10,7 +10,6 @@
#include <LibGfx/Rect.h>
#include <LibGfx/TextLayout.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Painting/BorderRadiiData.h>
#include <LibWeb/PixelUnits.h>
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<Gfx::GlyphRun>);
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<Gfx::GlyphRun>);
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<Gfx::GlyphRun> const&, CSSPixels run_width);
GC::Ref<Node const> 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;

View file

@ -28,7 +28,7 @@ enum class PaintPhase {
struct HitTestResult {
GC::Root<Paintable> paintable;
int index_in_node { 0 };
size_t index_in_node { 0 };
Optional<CSSPixels> vertical_distance {};
Optional<CSSPixels> horizontal_distance {};

View file

@ -24,6 +24,7 @@
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Painting/SVGPaintable.h>
#include <LibWeb/Painting/SVGSVGPaintable.h>
#include <LibWeb/Painting/ShadowPainting.h>
#include <LibWeb/Painting/StackingContext.h>
#include <LibWeb/Painting/TableBordersPainting.h>
#include <LibWeb/Painting/TextPaintable.h>

View file

@ -14,13 +14,11 @@
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Painting/BackgroundPainting.h>
#include <LibWeb/Painting/BorderPainting.h>
#include <LibWeb/Painting/BorderRadiusCornerClipper.h>
#include <LibWeb/Painting/BoxModelMetrics.h>
#include <LibWeb/Painting/ClipFrame.h>
#include <LibWeb/Painting/ClippableAndScrollable.h>
#include <LibWeb/Painting/Paintable.h>
#include <LibWeb/Painting/PaintableFragment.h>
#include <LibWeb/Painting/ShadowPainting.h>
namespace Web::Painting {

View file

@ -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<TextPaintable>(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<unsigned>(m_start);
auto const end_index = static_cast<unsigned>(m_start) + static_cast<unsigned>(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<int>(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;

View file

@ -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<Gfx::GlyphRun> m_glyph_run;
CSS::WritingMode m_writing_mode;
Vector<ShadowData> m_shadows;