ladybird/Userland/Libraries/LibWeb/Painting/TextPaintable.h
Andreas Kling dd8504c68d LibWeb: Store "text for rendering" in TextPaintable
Instead of TextPaintable fragments being an offset+length view into the
layout node, they are now a view into the paintable instead.

This removes an awkward time window where we'd have bogus state in text
fragments after layout invalidation but before relayout. It also makes
the code slightly nicer in general, since there's less mixing of layout
and painting concepts.
2024-03-18 13:42:16 +01:00

41 lines
1.5 KiB
C++

/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Painting/PaintableBox.h>
namespace Web::Painting {
class TextPaintable final : public Paintable {
JS_CELL(TextPaintable, Paintable);
public:
static JS::NonnullGCPtr<TextPaintable> create(Layout::TextNode const&, String const& text_for_rendering);
Layout::TextNode const& layout_node() const { return static_cast<Layout::TextNode const&>(Paintable::layout_node()); }
virtual bool wants_mouse_events() const override;
virtual DOM::Node* mouse_event_target() const override;
virtual DispatchEventOfSameName handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mouseup(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
virtual DispatchEventOfSameName handle_mousemove(Badge<EventHandler>, CSSPixelPoint, unsigned button, unsigned modifiers) override;
void set_text_decoration_thickness(CSSPixels thickness) { m_text_decoration_thickness = thickness; }
CSSPixels text_decoration_thickness() const { return m_text_decoration_thickness; }
String const& text_for_rendering() const { return m_text_for_rendering; }
private:
virtual bool is_text_paintable() const override { return true; }
TextPaintable(Layout::TextNode const&, String const& text_for_rendering);
String m_text_for_rendering;
CSSPixels m_text_decoration_thickness { 0 };
};
}