mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibWeb: Rename PaintableFragment::m_start
and ::m_length
Make it extra clear that we're dealing with byte offsets here. No functional changes.
This commit is contained in:
parent
3df83dade8
commit
7beecaa43d
Notes:
github-actions[bot]
2025-06-13 13:09:41 +00:00
Author: https://github.com/gmta
Commit: 7beecaa43d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5067
Reviewed-by: https://github.com/tcl3
Reviewed-by: https://github.com/trflynn89
4 changed files with 26 additions and 26 deletions
|
@ -386,15 +386,15 @@ void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool sho
|
|||
color_off,
|
||||
fragment.layout_node().class_name());
|
||||
builder.appendff("start: {}, length: {}, rect: {} baseline: {}\n",
|
||||
fragment.start(),
|
||||
fragment.length(),
|
||||
fragment.start_byte_offset(),
|
||||
fragment.length_in_bytes(),
|
||||
fragment.absolute_rect(),
|
||||
fragment.baseline());
|
||||
if (is<Layout::TextNode>(fragment.layout_node())) {
|
||||
for (size_t i = 0; i < indent; ++i)
|
||||
builder.append(" "sv);
|
||||
auto const& layout_text = static_cast<Layout::TextNode const&>(fragment.layout_node());
|
||||
auto fragment_text = MUST(layout_text.text_for_rendering().substring_from_byte_offset(fragment.start(), fragment.length()));
|
||||
auto fragment_text = MUST(layout_text.text_for_rendering().substring_from_byte_offset(fragment.start_byte_offset(), fragment.length_in_bytes()));
|
||||
builder.appendff(" \"{}\"\n", fragment_text);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -677,7 +677,7 @@ void paint_cursor_if_needed(PaintContext& context, TextPaintable const& paintabl
|
|||
auto cursor_position_code_point_offset = fragment.utf16_view().code_point_offset_of(cursor_position->offset());
|
||||
cursor_position_byte_offset = fragment.utf8_view().byte_offset_of(cursor_position_code_point_offset);
|
||||
}
|
||||
if (cursor_position_byte_offset < fragment.start() || cursor_position_byte_offset > (fragment.start() + fragment.length()))
|
||||
if (cursor_position_byte_offset < fragment.start_byte_offset() || cursor_position_byte_offset > (fragment.start_byte_offset() + fragment.length_in_bytes()))
|
||||
return;
|
||||
|
||||
auto active_element = document.active_element();
|
||||
|
@ -696,7 +696,7 @@ void paint_cursor_if_needed(PaintContext& context, TextPaintable const& paintabl
|
|||
|
||||
auto const& font = fragment.glyph_run() ? fragment.glyph_run()->font() : fragment.layout_node().first_available_font();
|
||||
auto utf8_text = fragment.utf8_view();
|
||||
auto cursor_offset = font.width(utf8_text.substring_view(fragment.start(), cursor_position_byte_offset - fragment.start()));
|
||||
auto cursor_offset = font.width(utf8_text.substring_view(fragment.start_byte_offset(), cursor_position_byte_offset - fragment.start_byte_offset()));
|
||||
|
||||
CSSPixelRect cursor_rect {
|
||||
fragment_rect.x() + CSSPixels::nearest_value_for(cursor_offset),
|
||||
|
@ -1217,7 +1217,7 @@ TraversalDecision PaintableWithLines::hit_test(CSSPixelPoint position, HitTestTy
|
|||
if (fragment_absolute_rect.bottom() - 1 <= transformed_position_adjusted_by_scroll_offset.y()) { // fully below the fragment
|
||||
HitTestResult hit_test_result {
|
||||
.paintable = const_cast<Paintable&>(fragment.paintable()),
|
||||
.index_in_node = fragment.index_in_node_for_byte_offset(fragment.start() + fragment.length()),
|
||||
.index_in_node = fragment.index_in_node_for_byte_offset(fragment.start_byte_offset() + fragment.length_in_bytes()),
|
||||
.vertical_distance = transformed_position_adjusted_by_scroll_offset.y() - fragment_absolute_rect.bottom(),
|
||||
};
|
||||
if (callback(hit_test_result) == TraversalDecision::Break)
|
||||
|
@ -1226,7 +1226,7 @@ TraversalDecision PaintableWithLines::hit_test(CSSPixelPoint position, HitTestTy
|
|||
if (transformed_position_adjusted_by_scroll_offset.x() < fragment_absolute_rect.left()) {
|
||||
HitTestResult hit_test_result {
|
||||
.paintable = const_cast<Paintable&>(fragment.paintable()),
|
||||
.index_in_node = fragment.index_in_node_for_byte_offset(fragment.start()),
|
||||
.index_in_node = fragment.index_in_node_for_byte_offset(fragment.start_byte_offset()),
|
||||
.vertical_distance = 0,
|
||||
.horizontal_distance = fragment_absolute_rect.left() - transformed_position_adjusted_by_scroll_offset.x(),
|
||||
};
|
||||
|
@ -1235,7 +1235,7 @@ TraversalDecision PaintableWithLines::hit_test(CSSPixelPoint position, HitTestTy
|
|||
} else if (transformed_position_adjusted_by_scroll_offset.x() > fragment_absolute_rect.right()) {
|
||||
HitTestResult hit_test_result {
|
||||
.paintable = const_cast<Paintable&>(fragment.paintable()),
|
||||
.index_in_node = fragment.index_in_node_for_byte_offset(fragment.start() + fragment.length()),
|
||||
.index_in_node = fragment.index_in_node_for_byte_offset(fragment.start_byte_offset() + fragment.length_in_bytes()),
|
||||
.vertical_distance = 0,
|
||||
.horizontal_distance = transformed_position_adjusted_by_scroll_offset.x() - fragment_absolute_rect.right(),
|
||||
};
|
||||
|
|
|
@ -19,8 +19,8 @@ PaintableFragment::PaintableFragment(Layout::LineBoxFragment const& fragment)
|
|||
, m_offset(fragment.offset())
|
||||
, m_size(fragment.size())
|
||||
, m_baseline(fragment.baseline())
|
||||
, m_start(fragment.start())
|
||||
, m_length(fragment.length())
|
||||
, m_start_byte_offset(fragment.start())
|
||||
, m_length_in_bytes(fragment.length())
|
||||
, m_glyph_run(fragment.glyph_run())
|
||||
, m_writing_mode(fragment.writing_mode())
|
||||
{
|
||||
|
@ -37,9 +37,9 @@ CSSPixelRect const PaintableFragment::absolute_rect() const
|
|||
|
||||
size_t PaintableFragment::index_in_node_for_byte_offset(size_t byte_offset) const
|
||||
{
|
||||
if (m_length == 0)
|
||||
if (m_length_in_bytes == 0)
|
||||
return 0;
|
||||
if (byte_offset >= m_start + m_length)
|
||||
if (byte_offset >= m_start_byte_offset + m_length_in_bytes)
|
||||
return utf16_view().length_in_code_units();
|
||||
auto code_point_offset = utf8_view().code_point_offset_of(byte_offset);
|
||||
return utf16_view().code_unit_offset_of(code_point_offset);
|
||||
|
@ -63,7 +63,7 @@ size_t PaintableFragment::index_in_node_for_point(CSSPixelPoint position) const
|
|||
return 0;
|
||||
|
||||
// Find the code point offset of the glyph matching the position.
|
||||
auto code_point_offset = utf8_view().code_point_offset_of(m_start);
|
||||
auto code_point_offset = utf8_view().code_point_offset_of(m_start_byte_offset);
|
||||
auto const& glyphs = m_glyph_run->glyphs();
|
||||
auto smallest_distance = AK::NumericLimits<float>::max();
|
||||
for (size_t i = 0; i < glyphs.size(); ++i) {
|
||||
|
@ -97,25 +97,25 @@ CSSPixelRect PaintableFragment::range_rect(size_t start_offset_in_code_units, si
|
|||
auto code_unit_to_byte_offset = [&](size_t offset_in_code_units) -> size_t {
|
||||
auto text_in_utf16 = utf16_view();
|
||||
if (offset_in_code_units >= text_in_utf16.length_in_code_units())
|
||||
return m_length;
|
||||
return m_length_in_bytes;
|
||||
auto offset_code_point = text_in_utf16.code_point_offset_of(offset_in_code_units);
|
||||
auto byte_offset = utf8_view().byte_offset_of(offset_code_point);
|
||||
if (byte_offset <= m_start)
|
||||
if (byte_offset <= m_start_byte_offset)
|
||||
return 0;
|
||||
if (byte_offset > m_start + m_length)
|
||||
return m_length;
|
||||
return byte_offset - m_start;
|
||||
if (byte_offset > m_start_byte_offset + m_length_in_bytes)
|
||||
return m_length_in_bytes;
|
||||
return byte_offset - m_start_byte_offset;
|
||||
};
|
||||
|
||||
// We operate on the UTF-8 string that is part of this fragment.
|
||||
auto text = utf8_view().substring_view(m_start, m_length);
|
||||
auto text = utf8_view().substring_view(m_start_byte_offset, m_length_in_bytes);
|
||||
|
||||
if (paintable().selection_state() == Paintable::SelectionState::StartAndEnd) {
|
||||
auto selection_start_in_this_fragment = code_unit_to_byte_offset(start_offset_in_code_units);
|
||||
auto selection_end_in_this_fragment = code_unit_to_byte_offset(end_offset_in_code_units);
|
||||
|
||||
// we are in the start/end node (both the same)
|
||||
if (selection_start_in_this_fragment >= m_length)
|
||||
if (selection_start_in_this_fragment >= m_length_in_bytes)
|
||||
return {};
|
||||
if (selection_end_in_this_fragment == 0)
|
||||
return {};
|
||||
|
@ -143,10 +143,10 @@ CSSPixelRect PaintableFragment::range_rect(size_t start_offset_in_code_units, si
|
|||
}
|
||||
if (paintable().selection_state() == Paintable::SelectionState::Start) {
|
||||
auto selection_start_in_this_fragment = code_unit_to_byte_offset(start_offset_in_code_units);
|
||||
auto selection_end_in_this_fragment = m_length;
|
||||
auto selection_end_in_this_fragment = m_length_in_bytes;
|
||||
|
||||
// we are in the start node
|
||||
if (selection_start_in_this_fragment >= m_length)
|
||||
if (selection_start_in_this_fragment >= m_length_in_bytes)
|
||||
return {};
|
||||
|
||||
auto pixel_distance_to_first_selected_character = CSSPixels::nearest_value_for(font.width(text.substring_view(0, selection_start_in_this_fragment)));
|
||||
|
|
|
@ -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(); }
|
||||
|
||||
size_t start() const { return m_start; }
|
||||
size_t length() const { return m_length; }
|
||||
size_t start_byte_offset() const { return m_start_byte_offset; }
|
||||
size_t length_in_bytes() const { return m_length_in_bytes; }
|
||||
|
||||
CSSPixels baseline() const { return m_baseline; }
|
||||
CSSPixelPoint offset() const { return m_offset; }
|
||||
|
@ -58,8 +58,8 @@ private:
|
|||
CSSPixelPoint m_offset;
|
||||
CSSPixelSize m_size;
|
||||
CSSPixels m_baseline;
|
||||
size_t m_start;
|
||||
size_t m_length;
|
||||
size_t m_start_byte_offset;
|
||||
size_t m_length_in_bytes;
|
||||
RefPtr<Gfx::GlyphRun> m_glyph_run;
|
||||
CSS::WritingMode m_writing_mode;
|
||||
Vector<ShadowData> m_shadows;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue