diff --git a/Libraries/LibWeb/DOM/Range.cpp b/Libraries/LibWeb/DOM/Range.cpp index aad4a0098db..e72067d7639 100644 --- a/Libraries/LibWeb/DOM/Range.cpp +++ b/Libraries/LibWeb/DOM/Range.cpp @@ -1199,9 +1199,8 @@ GC::Ref Range::get_client_rects() if (is(*containing_block)) { auto const& paintable_lines = static_cast(*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(), diff --git a/Libraries/LibWeb/Painting/PaintableBox.cpp b/Libraries/LibWeb/Painting/PaintableBox.cpp index 0e66033c006..e613b72f5c7 100644 --- a/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -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(), *glyph_run, paintable.computed_values().webkit_text_fill_color(), fragment_absolute_device_rect.to_type(), scale, fragment.orientation()); - auto selection_rect = context.enclosing_device_rect(fragment.selection_rect(paintable.layout_node().first_available_font())).to_type(); + auto selection_rect = context.enclosing_device_rect(fragment.selection_rect()).to_type(); if (!selection_rect.is_empty()) { painter.fill_rect(selection_rect, CSS::SystemColor::highlight()); DisplayListRecorderStateSaver saver(painter); diff --git a/Libraries/LibWeb/Painting/PaintableFragment.cpp b/Libraries/LibWeb/Painting/PaintableFragment.cpp index afd4e10128d..7e7fccf73d7 100644 --- a/Libraries/LibWeb/Painting/PaintableFragment.cpp +++ b/Libraries/LibWeb/Painting/PaintableFragment.cpp @@ -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(m_start); auto const end_index = static_cast(m_start) + static_cast(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(*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 diff --git a/Libraries/LibWeb/Painting/PaintableFragment.h b/Libraries/LibWeb/Painting/PaintableFragment.h index 313a51a353b..19bb8ba104d 100644 --- a/Libraries/LibWeb/Painting/PaintableFragment.h +++ b/Libraries/LibWeb/Painting/PaintableFragment.h @@ -39,8 +39,8 @@ public: RefPtr 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(); }