mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibWeb/Painting: Use GlyphRun font for measuring selection rectangle
We incorrectly used the first available font to measure this before, which may or may not be the correct font for this text.
This commit is contained in:
parent
7a0c675f45
commit
e457252c97
Notes:
github-actions[bot]
2024-12-06 01:58:40 +00:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/LadybirdBrowser/ladybird/commit/e457252c975 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2796
4 changed files with 10 additions and 9 deletions
|
@ -1199,9 +1199,8 @@ GC::Ref<Geometry::DOMRectList> Range::get_client_rects()
|
|||
if (is<Painting::PaintableWithLines>(*containing_block)) {
|
||||
auto const& paintable_lines = static_cast<Painting::PaintableWithLines const&>(*containing_block);
|
||||
auto fragments = paintable_lines.fragments();
|
||||
auto const& font = paintable->layout_node().first_available_font();
|
||||
for (auto frag = fragments.begin(); frag != fragments.end(); frag++) {
|
||||
auto rect = frag->range_rect(font, start_offset(), end_offset());
|
||||
auto rect = frag->range_rect(start_offset(), end_offset());
|
||||
if (rect.is_empty())
|
||||
continue;
|
||||
rects.append(Geometry::DOMRect::create(realm(),
|
||||
|
|
|
@ -681,7 +681,7 @@ void paint_text_fragment(PaintContext& context, TextPaintable const& paintable,
|
|||
auto scale = context.device_pixels_per_css_pixel();
|
||||
painter.draw_text_run(baseline_start.to_type<int>(), *glyph_run, paintable.computed_values().webkit_text_fill_color(), fragment_absolute_device_rect.to_type<int>(), scale, fragment.orientation());
|
||||
|
||||
auto selection_rect = context.enclosing_device_rect(fragment.selection_rect(paintable.layout_node().first_available_font())).to_type<int>();
|
||||
auto selection_rect = context.enclosing_device_rect(fragment.selection_rect()).to_type<int>();
|
||||
if (!selection_rect.is_empty()) {
|
||||
painter.fill_rect(selection_rect, CSS::SystemColor::highlight());
|
||||
DisplayListRecorderStateSaver saver(painter);
|
||||
|
|
|
@ -70,7 +70,8 @@ int PaintableFragment::text_index_at(CSSPixelPoint position) const
|
|||
|
||||
return m_start + m_length;
|
||||
}
|
||||
CSSPixelRect PaintableFragment::range_rect(Gfx::Font const& font, size_t start_offset, size_t end_offset) const
|
||||
|
||||
CSSPixelRect PaintableFragment::range_rect(size_t start_offset, size_t end_offset) const
|
||||
{
|
||||
if (paintable().selection_state() == Paintable::SelectionState::None)
|
||||
return {};
|
||||
|
@ -82,6 +83,7 @@ CSSPixelRect PaintableFragment::range_rect(Gfx::Font const& font, size_t start_o
|
|||
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& font = glyph_run() ? glyph_run()->font() : layout_node().first_available_font();
|
||||
auto text = string_view();
|
||||
|
||||
if (paintable().selection_state() == Paintable::SelectionState::StartAndEnd) {
|
||||
|
@ -185,7 +187,7 @@ Gfx::Orientation PaintableFragment::orientation() const
|
|||
}
|
||||
}
|
||||
|
||||
CSSPixelRect PaintableFragment::selection_rect(Gfx::Font const& font) const
|
||||
CSSPixelRect PaintableFragment::selection_rect() const
|
||||
{
|
||||
if (auto const* focused_element = paintable().document().focused_element(); focused_element && is<HTML::FormAssociatedTextControlElement>(*focused_element)) {
|
||||
HTML::FormAssociatedTextControlElement const* text_control_element = nullptr;
|
||||
|
@ -200,7 +202,7 @@ CSSPixelRect PaintableFragment::selection_rect(Gfx::Font const& font) const
|
|||
auto selection_end = text_control_element->selection_end();
|
||||
if (!selection_start.has_value() || !selection_end.has_value())
|
||||
return {};
|
||||
return range_rect(font, selection_start.value(), selection_end.value());
|
||||
return range_rect(selection_start.value(), selection_end.value());
|
||||
}
|
||||
auto selection = paintable().document().get_selection();
|
||||
if (!selection)
|
||||
|
@ -209,7 +211,7 @@ CSSPixelRect PaintableFragment::selection_rect(Gfx::Font const& font) const
|
|||
if (!range)
|
||||
return {};
|
||||
|
||||
return range_rect(font, range->start_offset(), range->end_offset());
|
||||
return range_rect(range->start_offset(), range->end_offset());
|
||||
}
|
||||
|
||||
StringView PaintableFragment::string_view() const
|
||||
|
|
|
@ -39,8 +39,8 @@ public:
|
|||
RefPtr<Gfx::GlyphRun> glyph_run() const { return m_glyph_run; }
|
||||
Gfx::Orientation orientation() const;
|
||||
|
||||
CSSPixelRect selection_rect(Gfx::Font const&) const;
|
||||
CSSPixelRect range_rect(Gfx::Font const&, size_t start_offset, size_t end_offset) const;
|
||||
CSSPixelRect selection_rect() const;
|
||||
CSSPixelRect range_rect(size_t start_offset, size_t end_offset) const;
|
||||
|
||||
CSSPixels width() const { return m_size.width(); }
|
||||
CSSPixels height() const { return m_size.height(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue