mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +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: e457252c97
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)) {
|
if (is<Painting::PaintableWithLines>(*containing_block)) {
|
||||||
auto const& paintable_lines = static_cast<Painting::PaintableWithLines const&>(*containing_block);
|
auto const& paintable_lines = static_cast<Painting::PaintableWithLines const&>(*containing_block);
|
||||||
auto fragments = paintable_lines.fragments();
|
auto fragments = paintable_lines.fragments();
|
||||||
auto const& font = paintable->layout_node().first_available_font();
|
|
||||||
for (auto frag = fragments.begin(); frag != fragments.end(); frag++) {
|
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())
|
if (rect.is_empty())
|
||||||
continue;
|
continue;
|
||||||
rects.append(Geometry::DOMRect::create(realm(),
|
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();
|
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());
|
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()) {
|
if (!selection_rect.is_empty()) {
|
||||||
painter.fill_rect(selection_rect, CSS::SystemColor::highlight());
|
painter.fill_rect(selection_rect, CSS::SystemColor::highlight());
|
||||||
DisplayListRecorderStateSaver saver(painter);
|
DisplayListRecorderStateSaver saver(painter);
|
||||||
|
|
|
@ -70,7 +70,8 @@ int PaintableFragment::text_index_at(CSSPixelPoint position) const
|
||||||
|
|
||||||
return m_start + m_length;
|
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)
|
if (paintable().selection_state() == Paintable::SelectionState::None)
|
||||||
return {};
|
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 start_index = static_cast<unsigned>(m_start);
|
||||||
auto const end_index = static_cast<unsigned>(m_start) + static_cast<unsigned>(m_length);
|
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();
|
auto text = string_view();
|
||||||
|
|
||||||
if (paintable().selection_state() == Paintable::SelectionState::StartAndEnd) {
|
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)) {
|
if (auto const* focused_element = paintable().document().focused_element(); focused_element && is<HTML::FormAssociatedTextControlElement>(*focused_element)) {
|
||||||
HTML::FormAssociatedTextControlElement const* text_control_element = nullptr;
|
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();
|
auto selection_end = text_control_element->selection_end();
|
||||||
if (!selection_start.has_value() || !selection_end.has_value())
|
if (!selection_start.has_value() || !selection_end.has_value())
|
||||||
return {};
|
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();
|
auto selection = paintable().document().get_selection();
|
||||||
if (!selection)
|
if (!selection)
|
||||||
|
@ -209,7 +211,7 @@ CSSPixelRect PaintableFragment::selection_rect(Gfx::Font const& font) const
|
||||||
if (!range)
|
if (!range)
|
||||||
return {};
|
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
|
StringView PaintableFragment::string_view() const
|
||||||
|
|
|
@ -39,8 +39,8 @@ public:
|
||||||
RefPtr<Gfx::GlyphRun> glyph_run() const { return m_glyph_run; }
|
RefPtr<Gfx::GlyphRun> glyph_run() const { return m_glyph_run; }
|
||||||
Gfx::Orientation orientation() const;
|
Gfx::Orientation orientation() const;
|
||||||
|
|
||||||
CSSPixelRect selection_rect(Gfx::Font const&) const;
|
CSSPixelRect selection_rect() const;
|
||||||
CSSPixelRect range_rect(Gfx::Font const&, size_t start_offset, size_t end_offset) const;
|
CSSPixelRect range_rect(size_t start_offset, size_t end_offset) const;
|
||||||
|
|
||||||
CSSPixels width() const { return m_size.width(); }
|
CSSPixels width() const { return m_size.width(); }
|
||||||
CSSPixels height() const { return m_size.height(); }
|
CSSPixels height() const { return m_size.height(); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue