mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-27 03:10:01 +00:00
This change fixes at least two issues: - `update_associated_selection()` is responsible for selectionchange dispatch, and we were incorrectly dispatching this event on ranges that were not associated with a selection. - `Range::get_client_rects()` was using `update_associated_selection()` to refresh the selection state in the paintable tree for the current range, but since a range might not be associated with a selection, this could make the painted selection reflect the state of an arbitrary range instead of the actual selection range. Fixes a bug on Discord where any text typed into the message input would get selected.
70 lines
2.3 KiB
C++
70 lines
2.3 KiB
C++
/*
|
|
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGfx/TextLayout.h>
|
|
#include <LibWeb/Layout/Node.h>
|
|
#include <LibWeb/Painting/ShadowData.h>
|
|
#include <LibWeb/PixelUnits.h>
|
|
|
|
namespace Web::Painting {
|
|
|
|
class PaintableFragment {
|
|
friend class PaintableWithLines;
|
|
|
|
public:
|
|
explicit PaintableFragment(Layout::LineBoxFragment const&);
|
|
|
|
Layout::Node const& layout_node() const { return m_layout_node; }
|
|
Paintable const& paintable() const { return *m_layout_node->first_paintable(); }
|
|
|
|
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; }
|
|
void set_offset(CSSPixelPoint offset) { m_offset = offset; }
|
|
CSSPixelSize size() const { return m_size; }
|
|
|
|
Vector<ShadowData> const& shadows() const { return m_shadows; }
|
|
void set_shadows(Vector<ShadowData>&& shadows) { m_shadows = shadows; }
|
|
|
|
CSSPixelRect const absolute_rect() const;
|
|
|
|
RefPtr<Gfx::GlyphRun> glyph_run() const { return m_glyph_run; }
|
|
Gfx::Orientation orientation() const;
|
|
|
|
CSSPixelRect selection_rect() const;
|
|
CSSPixelRect range_rect(Paintable::SelectionState selection_state, size_t start_offset_in_code_units, size_t end_offset_in_code_units) const;
|
|
|
|
CSSPixels width() const { return m_size.width(); }
|
|
CSSPixels height() const { return m_size.height(); }
|
|
|
|
size_t index_in_node_for_byte_offset(size_t) const;
|
|
size_t index_in_node_for_point(CSSPixelPoint) const;
|
|
|
|
Utf8View utf8_view() const;
|
|
Utf16View utf16_view() const;
|
|
|
|
CSSPixels text_decoration_thickness() const { return m_text_decoration_thickness; }
|
|
void set_text_decoration_thickness(CSSPixels thickness) { m_text_decoration_thickness = thickness; }
|
|
|
|
private:
|
|
GC::Ref<Layout::Node const> m_layout_node;
|
|
CSSPixelPoint m_offset;
|
|
CSSPixelSize m_size;
|
|
CSSPixels m_baseline;
|
|
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;
|
|
CSSPixels m_text_decoration_thickness { 0 };
|
|
mutable Optional<AK::Utf16ConversionResult> m_text_in_utf16;
|
|
};
|
|
|
|
}
|