mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:37:35 +00:00
LibWeb: Make the paint tree GC-allocated
This simplifies the ownership model between DOM/layout/paint nodes immensely by deferring to the garbage collector for figuring out what's live and what's not.
This commit is contained in:
parent
35ba13802d
commit
4d401bf796
64 changed files with 148 additions and 108 deletions
|
@ -41,7 +41,7 @@ Painting::PaintableWithLines const* BlockContainer::paint_box() const
|
|||
return static_cast<Painting::PaintableWithLines const*>(Box::paint_box());
|
||||
}
|
||||
|
||||
RefPtr<Painting::Paintable> BlockContainer::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> BlockContainer::create_paintable() const
|
||||
{
|
||||
return Painting::PaintableWithLines::create(*this);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
|
||||
Painting::PaintableWithLines const* paint_box() const;
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
private:
|
||||
virtual bool is_block_container() const final { return true; }
|
||||
|
|
|
@ -40,7 +40,7 @@ bool Box::is_body() const
|
|||
return dom_node() && dom_node() == document().body();
|
||||
}
|
||||
|
||||
RefPtr<Painting::Paintable> Box::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> Box::create_paintable() const
|
||||
{
|
||||
return Painting::PaintableBox::create(*this);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
|
||||
virtual void did_set_rect() { }
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
protected:
|
||||
Box(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
|
||||
|
|
|
@ -30,7 +30,7 @@ void ButtonBox::prepare_for_replaced_layout()
|
|||
}
|
||||
}
|
||||
|
||||
RefPtr<Painting::Paintable> ButtonBox::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> ButtonBox::create_paintable() const
|
||||
{
|
||||
return Painting::ButtonPaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
virtual void prepare_for_replaced_layout() override;
|
||||
|
||||
private:
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ void CanvasBox::prepare_for_replaced_layout()
|
|||
set_intrinsic_height(dom_node().height());
|
||||
}
|
||||
|
||||
RefPtr<Painting::Paintable> CanvasBox::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> CanvasBox::create_paintable() const
|
||||
{
|
||||
return Painting::CanvasPaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
|
||||
const HTML::HTMLCanvasElement& dom_node() const { return static_cast<const HTML::HTMLCanvasElement&>(ReplacedBox::dom_node()); }
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ CheckBox::CheckBox(DOM::Document& document, HTML::HTMLInputElement& element, Non
|
|||
|
||||
CheckBox::~CheckBox() = default;
|
||||
|
||||
RefPtr<Painting::Paintable> CheckBox::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> CheckBox::create_paintable() const
|
||||
{
|
||||
return Painting::CheckBoxPaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
virtual ~CheckBox() override;
|
||||
|
||||
private:
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ void FrameBox::did_set_rect()
|
|||
dom_node().nested_browsing_context()->set_size(paint_box()->content_size());
|
||||
}
|
||||
|
||||
RefPtr<Painting::Paintable> FrameBox::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> FrameBox::create_paintable() const
|
||||
{
|
||||
return Painting::NestedBrowsingContextPaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
const HTML::HTMLIFrameElement& dom_node() const { return verify_cast<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); }
|
||||
HTML::HTMLIFrameElement& dom_node() { return verify_cast<HTML::HTMLIFrameElement>(ReplacedBox::dom_node()); }
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
private:
|
||||
virtual void did_set_rect() override;
|
||||
|
|
|
@ -97,7 +97,7 @@ void ImageBox::browsing_context_did_set_viewport_rect(CSSPixelRect const& viewpo
|
|||
m_image_loader.set_visible_in_viewport(paint_box() && viewport_rect.intersects(paint_box()->absolute_rect()));
|
||||
}
|
||||
|
||||
RefPtr<Painting::Paintable> ImageBox::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> ImageBox::create_paintable() const
|
||||
{
|
||||
return Painting::ImagePaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
bool renders_as_alt_text() const;
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
auto const& image_loader() const { return m_image_loader; }
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ InlineNode::InlineNode(DOM::Document& document, DOM::Element* element, NonnullRe
|
|||
|
||||
InlineNode::~InlineNode() = default;
|
||||
|
||||
RefPtr<Painting::Paintable> InlineNode::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> InlineNode::create_paintable() const
|
||||
{
|
||||
return Painting::InlinePaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
InlineNode(DOM::Document&, DOM::Element*, NonnullRefPtr<CSS::StyleProperties>);
|
||||
virtual ~InlineNode() override;
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ ListItemMarkerBox::ListItemMarkerBox(DOM::Document& document, CSS::ListStyleType
|
|||
|
||||
ListItemMarkerBox::~ListItemMarkerBox() = default;
|
||||
|
||||
RefPtr<Painting::Paintable> ListItemMarkerBox::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> ListItemMarkerBox::create_paintable() const
|
||||
{
|
||||
return Painting::MarkerPaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
|
||||
DeprecatedString const& text() const { return m_text; }
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
CSS::ListStyleType list_style_type() const { return m_list_style_type; }
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ void Node::visit_edges(Cell::Visitor& visitor)
|
|||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_dom_node);
|
||||
visitor.visit(m_paintable);
|
||||
visitor.visit(m_browsing_context);
|
||||
TreeNode::visit_edges(visitor);
|
||||
}
|
||||
|
@ -679,12 +680,12 @@ void NodeWithStyle::reset_table_box_computed_values_used_by_wrapper_to_init_valu
|
|||
mutable_computed_values.set_margin({ CSS::Length::make_px(0), CSS::Length::make_px(0), CSS::Length::make_px(0), CSS::Length::make_px(0) });
|
||||
}
|
||||
|
||||
void Node::set_paintable(RefPtr<Painting::Paintable> paintable)
|
||||
void Node::set_paintable(JS::GCPtr<Painting::Paintable> paintable)
|
||||
{
|
||||
m_paintable = move(paintable);
|
||||
}
|
||||
|
||||
RefPtr<Painting::Paintable> Node::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> Node::create_paintable() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -51,9 +51,9 @@ public:
|
|||
|
||||
Painting::Paintable* paintable() { return m_paintable; }
|
||||
Painting::Paintable const* paintable() const { return m_paintable; }
|
||||
void set_paintable(RefPtr<Painting::Paintable>);
|
||||
void set_paintable(JS::GCPtr<Painting::Paintable>);
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const;
|
||||
|
||||
DOM::Document& document();
|
||||
DOM::Document const& document() const;
|
||||
|
@ -150,7 +150,7 @@ private:
|
|||
friend class NodeWithStyle;
|
||||
|
||||
JS::NonnullGCPtr<DOM::Node> m_dom_node;
|
||||
RefPtr<Painting::Paintable> m_paintable;
|
||||
JS::GCPtr<Painting::Paintable> m_paintable;
|
||||
|
||||
JS::NonnullGCPtr<HTML::BrowsingContext> m_browsing_context;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ Progress::Progress(DOM::Document& document, HTML::HTMLProgressElement& element,
|
|||
|
||||
Progress::~Progress() = default;
|
||||
|
||||
RefPtr<Painting::Paintable> Progress::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> Progress::create_paintable() const
|
||||
{
|
||||
return Painting::ProgressPaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
const HTML::HTMLProgressElement& dom_node() const { return static_cast<const HTML::HTMLProgressElement&>(LabelableNode::dom_node()); }
|
||||
HTML::HTMLProgressElement& dom_node() { return static_cast<HTML::HTMLProgressElement&>(LabelableNode::dom_node()); }
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ RadioButton::RadioButton(DOM::Document& document, HTML::HTMLInputElement& elemen
|
|||
|
||||
RadioButton::~RadioButton() = default;
|
||||
|
||||
RefPtr<Painting::Paintable> RadioButton::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> RadioButton::create_paintable() const
|
||||
{
|
||||
return Painting::RadioButtonPaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
virtual ~RadioButton() override;
|
||||
|
||||
private:
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ CSSPixelPoint SVGGeometryBox::viewbox_origin() const
|
|||
return { svg_box->view_box().value().min_x, svg_box->view_box().value().min_y };
|
||||
}
|
||||
|
||||
RefPtr<Painting::Paintable> SVGGeometryBox::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> SVGGeometryBox::create_paintable() const
|
||||
{
|
||||
return Painting::SVGGeometryPaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
float viewbox_scaling() const;
|
||||
CSSPixelPoint viewbox_origin() const;
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
private:
|
||||
virtual bool is_svg_geometry_box() const final { return true; }
|
||||
|
|
|
@ -17,7 +17,7 @@ SVGSVGBox::SVGSVGBox(DOM::Document& document, SVG::SVGSVGElement& element, Nonnu
|
|||
{
|
||||
}
|
||||
|
||||
RefPtr<Painting::Paintable> SVGSVGBox::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> SVGSVGBox::create_paintable() const
|
||||
{
|
||||
return Painting::SVGSVGPaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
|
||||
virtual bool can_have_children() const override { return true; }
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
virtual void prepare_for_replaced_layout() override;
|
||||
};
|
||||
|
|
|
@ -188,7 +188,7 @@ Optional<TextNode::Chunk> TextNode::ChunkIterator::try_commit_chunk(Utf8View::It
|
|||
return {};
|
||||
}
|
||||
|
||||
RefPtr<Painting::Paintable> TextNode::create_paintable() const
|
||||
JS::GCPtr<Painting::Paintable> TextNode::create_paintable() const
|
||||
{
|
||||
return Painting::TextPaintable::create(*this);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
void compute_text_for_rendering(bool collapse);
|
||||
|
||||
virtual RefPtr<Painting::Paintable> create_paintable() const override;
|
||||
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
|
||||
|
||||
private:
|
||||
virtual bool is_text_node() const final { return true; }
|
||||
|
|
|
@ -160,7 +160,7 @@ bool EventHandler::handle_mousewheel(CSSPixelPoint position, unsigned button, un
|
|||
|
||||
bool handled_event = false;
|
||||
|
||||
RefPtr<Painting::Paintable> paintable;
|
||||
JS::GCPtr<Painting::Paintable> paintable;
|
||||
if (m_mouse_event_tracking_layout_node) {
|
||||
paintable = m_mouse_event_tracking_layout_node->paintable();
|
||||
} else {
|
||||
|
@ -208,7 +208,7 @@ bool EventHandler::handle_mouseup(CSSPixelPoint position, unsigned button, unsig
|
|||
|
||||
bool handled_event = false;
|
||||
|
||||
RefPtr<Painting::Paintable> paintable;
|
||||
JS::GCPtr<Painting::Paintable> paintable;
|
||||
if (m_mouse_event_tracking_layout_node) {
|
||||
paintable = m_mouse_event_tracking_layout_node->paintable();
|
||||
} else {
|
||||
|
@ -327,7 +327,7 @@ bool EventHandler::handle_mousedown(CSSPixelPoint position, unsigned button, uns
|
|||
JS::GCPtr<DOM::Node> node;
|
||||
|
||||
{
|
||||
RefPtr<Painting::Paintable> paintable;
|
||||
JS::GCPtr<Painting::Paintable> paintable;
|
||||
if (m_mouse_event_tracking_layout_node) {
|
||||
paintable = m_mouse_event_tracking_layout_node->paintable();
|
||||
} else {
|
||||
|
@ -422,7 +422,7 @@ bool EventHandler::handle_mousemove(CSSPixelPoint position, unsigned buttons, un
|
|||
bool is_hovering_link = false;
|
||||
Gfx::StandardCursor hovered_node_cursor = Gfx::StandardCursor::None;
|
||||
|
||||
RefPtr<Painting::Paintable> paintable;
|
||||
JS::GCPtr<Painting::Paintable> paintable;
|
||||
Optional<int> start_index;
|
||||
if (m_mouse_event_tracking_layout_node) {
|
||||
paintable = m_mouse_event_tracking_layout_node->paintable();
|
||||
|
@ -530,7 +530,7 @@ bool EventHandler::handle_doubleclick(CSSPixelPoint position, unsigned button, u
|
|||
if (!paint_root())
|
||||
return false;
|
||||
|
||||
RefPtr<Painting::Paintable> paintable;
|
||||
JS::GCPtr<Painting::Paintable> paintable;
|
||||
if (m_mouse_event_tracking_layout_node) {
|
||||
paintable = m_mouse_event_tracking_layout_node->paintable();
|
||||
} else {
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<ButtonPaintable> ButtonPaintable::create(Layout::ButtonBox const& layout_box)
|
||||
JS::NonnullGCPtr<ButtonPaintable> ButtonPaintable::create(Layout::ButtonBox const& layout_box)
|
||||
{
|
||||
return adopt_ref(*new ButtonPaintable(layout_box));
|
||||
return layout_box.heap().allocate_without_realm<ButtonPaintable>(layout_box);
|
||||
}
|
||||
|
||||
ButtonPaintable::ButtonPaintable(Layout::ButtonBox const& layout_box)
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class ButtonPaintable final : public LabelablePaintable {
|
||||
JS_CELL(ButtonPaintable, LabelablePaintable);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<ButtonPaintable> create(Layout::ButtonBox const&);
|
||||
static JS::NonnullGCPtr<ButtonPaintable> create(Layout::ButtonBox const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<CanvasPaintable> CanvasPaintable::create(Layout::CanvasBox const& layout_box)
|
||||
JS::NonnullGCPtr<CanvasPaintable> CanvasPaintable::create(Layout::CanvasBox const& layout_box)
|
||||
{
|
||||
return adopt_ref(*new CanvasPaintable(layout_box));
|
||||
return layout_box.heap().allocate_without_realm<CanvasPaintable>(layout_box);
|
||||
}
|
||||
|
||||
CanvasPaintable::CanvasPaintable(Layout::CanvasBox const& layout_box)
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class CanvasPaintable final : public PaintableBox {
|
||||
JS_CELL(CanvasPaintable, PaintableBox);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<CanvasPaintable> create(Layout::CanvasBox const&);
|
||||
static JS::NonnullGCPtr<CanvasPaintable> create(Layout::CanvasBox const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<CheckBoxPaintable> CheckBoxPaintable::create(Layout::CheckBox const& layout_box)
|
||||
JS::NonnullGCPtr<CheckBoxPaintable> CheckBoxPaintable::create(Layout::CheckBox const& layout_box)
|
||||
{
|
||||
return adopt_ref(*new CheckBoxPaintable(layout_box));
|
||||
return layout_box.heap().allocate_without_realm<CheckBoxPaintable>(layout_box);
|
||||
}
|
||||
|
||||
CheckBoxPaintable::CheckBoxPaintable(Layout::CheckBox const& layout_box)
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class CheckBoxPaintable final : public LabelablePaintable {
|
||||
JS_CELL(CheckBoxPaintable, LabelablePaintable);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<CheckBoxPaintable> create(Layout::CheckBox const&);
|
||||
static JS::NonnullGCPtr<CheckBoxPaintable> create(Layout::CheckBox const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<ImagePaintable> ImagePaintable::create(Layout::ImageBox const& layout_box)
|
||||
JS::NonnullGCPtr<ImagePaintable> ImagePaintable::create(Layout::ImageBox const& layout_box)
|
||||
{
|
||||
return adopt_ref(*new ImagePaintable(layout_box));
|
||||
return layout_box.heap().allocate_without_realm<ImagePaintable>(layout_box);
|
||||
}
|
||||
|
||||
ImagePaintable::ImagePaintable(Layout::ImageBox const& layout_box)
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class ImagePaintable final : public PaintableBox {
|
||||
JS_CELL(ImagePaintable, PaintableBox);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<ImagePaintable> create(Layout::ImageBox const&);
|
||||
static JS::NonnullGCPtr<ImagePaintable> create(Layout::ImageBox const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<InlinePaintable> InlinePaintable::create(Layout::InlineNode const& layout_node)
|
||||
JS::NonnullGCPtr<InlinePaintable> InlinePaintable::create(Layout::InlineNode const& layout_node)
|
||||
{
|
||||
return adopt_ref(*new InlinePaintable(layout_node));
|
||||
return layout_node.heap().allocate_without_realm<InlinePaintable>(layout_node);
|
||||
}
|
||||
|
||||
InlinePaintable::InlinePaintable(Layout::InlineNode const& layout_node)
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class InlinePaintable final : public Paintable {
|
||||
JS_CELL(InlinePaintable, Paintable);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<InlinePaintable> create(Layout::InlineNode const&);
|
||||
static JS::NonnullGCPtr<InlinePaintable> create(Layout::InlineNode const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -81,10 +81,6 @@ void LabelablePaintable::handle_associated_label_mousedown(Badge<Layout::Label>)
|
|||
|
||||
void LabelablePaintable::handle_associated_label_mouseup(Badge<Layout::Label>)
|
||||
{
|
||||
// NOTE: Handling the click may run arbitrary JS, which could disappear this node.
|
||||
NonnullRefPtr protected_this = *this;
|
||||
JS::NonnullGCPtr protected_browsing_context { browsing_context() };
|
||||
|
||||
set_being_pressed(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ namespace Web::Painting {
|
|||
// FIXME: Splinter this into FormAssociatedLabelablePaintable once
|
||||
// ProgressPaintable switches over to this.
|
||||
class LabelablePaintable : public PaintableBox {
|
||||
JS_CELL(LabelablePaintable, PaintableBox);
|
||||
|
||||
public:
|
||||
Layout::FormAssociatedLabelableNode const& layout_box() const;
|
||||
Layout::FormAssociatedLabelableNode& layout_box();
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<MarkerPaintable> MarkerPaintable::create(Layout::ListItemMarkerBox const& layout_box)
|
||||
JS::NonnullGCPtr<MarkerPaintable> MarkerPaintable::create(Layout::ListItemMarkerBox const& layout_box)
|
||||
{
|
||||
return adopt_ref(*new MarkerPaintable(layout_box));
|
||||
return layout_box.heap().allocate_without_realm<MarkerPaintable>(layout_box);
|
||||
}
|
||||
|
||||
MarkerPaintable::MarkerPaintable(Layout::ListItemMarkerBox const& layout_box)
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class MarkerPaintable final : public PaintableBox {
|
||||
JS_CELL(MarkerPaintable, PaintableBox);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<MarkerPaintable> create(Layout::ListItemMarkerBox const&);
|
||||
static JS::NonnullGCPtr<MarkerPaintable> create(Layout::ListItemMarkerBox const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<NestedBrowsingContextPaintable> NestedBrowsingContextPaintable::create(Layout::FrameBox const& layout_box)
|
||||
JS::NonnullGCPtr<NestedBrowsingContextPaintable> NestedBrowsingContextPaintable::create(Layout::FrameBox const& layout_box)
|
||||
{
|
||||
return adopt_ref(*new NestedBrowsingContextPaintable(layout_box));
|
||||
return layout_box.heap().allocate_without_realm<NestedBrowsingContextPaintable>(layout_box);
|
||||
}
|
||||
|
||||
NestedBrowsingContextPaintable::NestedBrowsingContextPaintable(Layout::FrameBox const& layout_box)
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class NestedBrowsingContextPaintable final : public PaintableBox {
|
||||
JS_CELL(NestedBrowsingContextPaintable, PaintableBox);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<NestedBrowsingContextPaintable> create(Layout::FrameBox const&);
|
||||
static JS::NonnullGCPtr<NestedBrowsingContextPaintable> create(Layout::FrameBox const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -10,6 +10,12 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
void Paintable::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_layout_node);
|
||||
}
|
||||
|
||||
Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
|
||||
{
|
||||
return DispatchEventOfSameName::Yes;
|
||||
|
@ -48,7 +54,7 @@ Optional<HitTestResult> Paintable::hit_test(CSSPixelPoint, HitTestType) const
|
|||
|
||||
Paintable const* Paintable::first_child() const
|
||||
{
|
||||
auto* layout_child = m_layout_node.first_child();
|
||||
auto* layout_child = m_layout_node->first_child();
|
||||
for (; layout_child && !layout_child->paintable(); layout_child = layout_child->next_sibling())
|
||||
;
|
||||
return layout_child ? layout_child->paintable() : nullptr;
|
||||
|
@ -56,7 +62,7 @@ Paintable const* Paintable::first_child() const
|
|||
|
||||
Paintable const* Paintable::next_sibling() const
|
||||
{
|
||||
auto* layout_node = m_layout_node.next_sibling();
|
||||
auto* layout_node = m_layout_node->next_sibling();
|
||||
for (; layout_node && !layout_node->paintable(); layout_node = layout_node->next_sibling())
|
||||
;
|
||||
return layout_node ? layout_node->paintable() : nullptr;
|
||||
|
@ -64,7 +70,7 @@ Paintable const* Paintable::next_sibling() const
|
|||
|
||||
Paintable const* Paintable::last_child() const
|
||||
{
|
||||
auto* layout_child = m_layout_node.last_child();
|
||||
auto* layout_child = m_layout_node->last_child();
|
||||
for (; layout_child && !layout_child->paintable(); layout_child = layout_child->previous_sibling())
|
||||
;
|
||||
return layout_child ? layout_child->paintable() : nullptr;
|
||||
|
@ -72,7 +78,7 @@ Paintable const* Paintable::last_child() const
|
|||
|
||||
Paintable const* Paintable::previous_sibling() const
|
||||
{
|
||||
auto* layout_node = m_layout_node.previous_sibling();
|
||||
auto* layout_node = m_layout_node->previous_sibling();
|
||||
for (; layout_node && !layout_node->paintable(); layout_node = layout_node->previous_sibling())
|
||||
;
|
||||
return layout_node ? layout_node->paintable() : nullptr;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -28,7 +28,7 @@ enum class PaintPhase {
|
|||
};
|
||||
|
||||
struct HitTestResult {
|
||||
NonnullRefPtr<Painting::Paintable> paintable;
|
||||
JS::Handle<Painting::Paintable> paintable;
|
||||
int index_in_node { 0 };
|
||||
|
||||
enum InternalPosition {
|
||||
|
@ -48,9 +48,8 @@ enum class HitTestType {
|
|||
TextCursor, // Clicking past the right/bottom edge of text will still hit the text
|
||||
};
|
||||
|
||||
class Paintable : public RefCounted<Paintable> {
|
||||
AK_MAKE_NONMOVABLE(Paintable);
|
||||
AK_MAKE_NONCOPYABLE(Paintable);
|
||||
class Paintable : public JS::Cell {
|
||||
JS_CELL(Paintable, Cell);
|
||||
|
||||
public:
|
||||
virtual ~Paintable() = default;
|
||||
|
@ -108,24 +107,24 @@ public:
|
|||
virtual bool handle_mousewheel(Badge<EventHandler>, CSSPixelPoint, unsigned buttons, unsigned modifiers, int wheel_delta_x, int wheel_delta_y);
|
||||
|
||||
Layout::Node const& layout_node() const { return m_layout_node; }
|
||||
Layout::Node& layout_node() { return const_cast<Layout::Node&>(m_layout_node); }
|
||||
Layout::Node& layout_node() { return const_cast<Layout::Node&>(*m_layout_node); }
|
||||
|
||||
DOM::Node* dom_node() { return layout_node().dom_node(); }
|
||||
DOM::Node const* dom_node() const { return layout_node().dom_node(); }
|
||||
|
||||
auto const& computed_values() const { return m_layout_node.computed_values(); }
|
||||
auto const& computed_values() const { return m_layout_node->computed_values(); }
|
||||
|
||||
bool visible_for_hit_testing() const { return computed_values().pointer_events() != CSS::PointerEvents::None; }
|
||||
|
||||
HTML::BrowsingContext const& browsing_context() const { return m_layout_node.browsing_context(); }
|
||||
HTML::BrowsingContext const& browsing_context() const { return m_layout_node->browsing_context(); }
|
||||
HTML::BrowsingContext& browsing_context() { return layout_node().browsing_context(); }
|
||||
|
||||
void set_needs_display() const { const_cast<Layout::Node&>(m_layout_node).set_needs_display(); }
|
||||
void set_needs_display() const { const_cast<Layout::Node&>(*m_layout_node).set_needs_display(); }
|
||||
|
||||
Layout::BlockContainer const* containing_block() const
|
||||
{
|
||||
if (!m_containing_block.has_value())
|
||||
m_containing_block = const_cast<Layout::Node&>(m_layout_node).containing_block();
|
||||
m_containing_block = m_layout_node->containing_block();
|
||||
return *m_containing_block;
|
||||
}
|
||||
|
||||
|
@ -138,8 +137,10 @@ protected:
|
|||
{
|
||||
}
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
private:
|
||||
Layout::Node const& m_layout_node;
|
||||
JS::NonnullGCPtr<Layout::Node> m_layout_node;
|
||||
Optional<Layout::BlockContainer*> mutable m_containing_block;
|
||||
};
|
||||
|
||||
|
@ -154,6 +155,6 @@ inline DOM::Node const* HitTestResult::dom_node() const
|
|||
}
|
||||
|
||||
template<>
|
||||
inline bool Paintable::fast_is<PaintableBox>() const { return m_layout_node.is_box(); }
|
||||
inline bool Paintable::fast_is<PaintableBox>() const { return m_layout_node->is_box(); }
|
||||
|
||||
}
|
||||
|
|
|
@ -19,9 +19,14 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<PaintableBox> PaintableBox::create(Layout::Box const& layout_box)
|
||||
JS::NonnullGCPtr<PaintableWithLines> PaintableWithLines::create(Layout::BlockContainer const& block_container)
|
||||
{
|
||||
return adopt_ref(*new PaintableBox(layout_box));
|
||||
return block_container.heap().allocate_without_realm<PaintableWithLines>(block_container);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<PaintableBox> PaintableBox::create(Layout::Box const& layout_box)
|
||||
{
|
||||
return layout_box.heap().allocate_without_realm<PaintableBox>(layout_box);
|
||||
}
|
||||
|
||||
PaintableBox::PaintableBox(Layout::Box const& layout_box)
|
||||
|
@ -679,7 +684,7 @@ Optional<HitTestResult> PaintableBox::hit_test(CSSPixelPoint position, HitTestTy
|
|||
continue;
|
||||
return result;
|
||||
}
|
||||
return HitTestResult { *this };
|
||||
return HitTestResult { const_cast<PaintableBox&>(*this) };
|
||||
}
|
||||
|
||||
Optional<HitTestResult> PaintableWithLines::hit_test(CSSPixelPoint position, HitTestType type) const
|
||||
|
@ -700,7 +705,7 @@ Optional<HitTestResult> PaintableWithLines::hit_test(CSSPixelPoint position, Hit
|
|||
if (fragment_absolute_rect.contains(position)) {
|
||||
if (is<Layout::BlockContainer>(fragment.layout_node()) && fragment.layout_node().paintable())
|
||||
return fragment.layout_node().paintable()->hit_test(position, type);
|
||||
return HitTestResult { *fragment.layout_node().paintable(), fragment.text_index_at(position.x()) };
|
||||
return HitTestResult { const_cast<Paintable&>(const_cast<Paintable&>(*fragment.layout_node().paintable())), fragment.text_index_at(position.x()) };
|
||||
}
|
||||
|
||||
// If we reached this point, the position is not within the fragment. However, the fragment start or end might be the place to place the cursor.
|
||||
|
@ -709,14 +714,14 @@ Optional<HitTestResult> PaintableWithLines::hit_test(CSSPixelPoint position, Hit
|
|||
// We arbitrarily choose to consider the end of the line above and ignore the beginning of the line below.
|
||||
// If we knew the direction of selection, we could make a better choice.
|
||||
if (fragment_absolute_rect.bottom() <= position.y()) { // fully below the fragment
|
||||
last_good_candidate = HitTestResult { *fragment.layout_node().paintable(), fragment.start() + fragment.length() };
|
||||
last_good_candidate = HitTestResult { const_cast<Paintable&>(*fragment.layout_node().paintable()), fragment.start() + fragment.length() };
|
||||
} else if (fragment_absolute_rect.top() <= position.y()) { // vertically within the fragment
|
||||
if (position.x() < fragment_absolute_rect.left()) { // left of the fragment
|
||||
if (!last_good_candidate.has_value()) { // first fragment of the line
|
||||
last_good_candidate = HitTestResult { *fragment.layout_node().paintable(), fragment.start() };
|
||||
last_good_candidate = HitTestResult { const_cast<Paintable&>(*fragment.layout_node().paintable()), fragment.start() };
|
||||
}
|
||||
} else { // right of the fragment
|
||||
last_good_candidate = HitTestResult { *fragment.layout_node().paintable(), fragment.start() + fragment.length() };
|
||||
last_good_candidate = HitTestResult { const_cast<Paintable&>(*fragment.layout_node().paintable()), fragment.start() + fragment.length() };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -725,7 +730,7 @@ Optional<HitTestResult> PaintableWithLines::hit_test(CSSPixelPoint position, Hit
|
|||
if (type == HitTestType::TextCursor && last_good_candidate.has_value())
|
||||
return last_good_candidate;
|
||||
if (is_visible() && absolute_border_box_rect().contains(position.x(), position.y()))
|
||||
return HitTestResult { *this };
|
||||
return HitTestResult { const_cast<PaintableWithLines&>(*this) };
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class PaintableBox : public Paintable {
|
||||
JS_CELL(PaintableBox, Paintable);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<PaintableBox> create(Layout::Box const&);
|
||||
static JS::NonnullGCPtr<PaintableBox> create(Layout::Box const&);
|
||||
virtual ~PaintableBox();
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
@ -162,11 +164,10 @@ private:
|
|||
};
|
||||
|
||||
class PaintableWithLines : public PaintableBox {
|
||||
JS_CELL(PaintableWithLines, PaintableBox);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<PaintableWithLines> create(Layout::BlockContainer const& block_container)
|
||||
{
|
||||
return adopt_ref(*new PaintableWithLines(block_container));
|
||||
}
|
||||
static JS::NonnullGCPtr<PaintableWithLines> create(Layout::BlockContainer const&);
|
||||
virtual ~PaintableWithLines() override;
|
||||
|
||||
Layout::BlockContainer const& layout_box() const;
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<ProgressPaintable> ProgressPaintable::create(Layout::Progress const& layout_box)
|
||||
JS::NonnullGCPtr<ProgressPaintable> ProgressPaintable::create(Layout::Progress const& layout_box)
|
||||
{
|
||||
return adopt_ref(*new ProgressPaintable(layout_box));
|
||||
return layout_box.heap().allocate_without_realm<ProgressPaintable>(layout_box);
|
||||
}
|
||||
|
||||
ProgressPaintable::ProgressPaintable(Layout::Progress const& layout_box)
|
||||
|
|
|
@ -15,8 +15,10 @@ namespace Web::Painting {
|
|||
// LabelablePaintable should be split into FormAssociatedLabelablePaintable once this
|
||||
// happens.
|
||||
class ProgressPaintable final : public PaintableBox {
|
||||
JS_CELL(ProgressPaintable, PaintableBox);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<ProgressPaintable> create(Layout::Progress const&);
|
||||
static JS::NonnullGCPtr<ProgressPaintable> create(Layout::Progress const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<RadioButtonPaintable> RadioButtonPaintable::create(Layout::RadioButton const& layout_box)
|
||||
JS::NonnullGCPtr<RadioButtonPaintable> RadioButtonPaintable::create(Layout::RadioButton const& layout_box)
|
||||
{
|
||||
return adopt_ref(*new RadioButtonPaintable(layout_box));
|
||||
return layout_box.heap().allocate_without_realm<RadioButtonPaintable>(layout_box);
|
||||
}
|
||||
|
||||
RadioButtonPaintable::RadioButtonPaintable(Layout::RadioButton const& layout_box)
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class RadioButtonPaintable final : public LabelablePaintable {
|
||||
JS_CELL(RadioButtonPaintable, LabelablePaintable);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<RadioButtonPaintable> create(Layout::RadioButton const&);
|
||||
static JS::NonnullGCPtr<RadioButtonPaintable> create(Layout::RadioButton const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<SVGGeometryPaintable> SVGGeometryPaintable::create(Layout::SVGGeometryBox const& layout_box)
|
||||
JS::NonnullGCPtr<SVGGeometryPaintable> SVGGeometryPaintable::create(Layout::SVGGeometryBox const& layout_box)
|
||||
{
|
||||
return adopt_ref(*new SVGGeometryPaintable(layout_box));
|
||||
return layout_box.heap().allocate_without_realm<SVGGeometryPaintable>(layout_box);
|
||||
}
|
||||
|
||||
SVGGeometryPaintable::SVGGeometryPaintable(Layout::SVGGeometryBox const& layout_box)
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class SVGGeometryPaintable : public SVGGraphicsPaintable {
|
||||
JS_CELL(SVGGeometryPaintable, SVGGraphicsPaintable);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<SVGGeometryPaintable> create(Layout::SVGGeometryBox const&);
|
||||
static JS::NonnullGCPtr<SVGGeometryPaintable> create(Layout::SVGGeometryBox const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class SVGGraphicsPaintable : public SVGPaintable {
|
||||
JS_CELL(SVGGraphicsPaintable, SVGPaintable);
|
||||
|
||||
public:
|
||||
virtual void before_children_paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class SVGPaintable : public PaintableBox {
|
||||
JS_CELL(SVGPaintable, PaintableBox);
|
||||
|
||||
public:
|
||||
virtual void before_children_paint(PaintContext&, PaintPhase) const override;
|
||||
virtual void after_children_paint(PaintContext&, PaintPhase) const override;
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<SVGSVGPaintable> SVGSVGPaintable::create(Layout::SVGSVGBox const& layout_box)
|
||||
JS::NonnullGCPtr<SVGSVGPaintable> SVGSVGPaintable::create(Layout::SVGSVGBox const& layout_box)
|
||||
{
|
||||
return adopt_ref(*new SVGSVGPaintable(layout_box));
|
||||
return layout_box.heap().allocate_without_realm<SVGSVGPaintable>(layout_box);
|
||||
}
|
||||
|
||||
SVGSVGPaintable::SVGSVGPaintable(Layout::SVGSVGBox const& layout_box)
|
||||
|
|
|
@ -12,8 +12,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class SVGSVGPaintable : public PaintableBox {
|
||||
JS_CELL(SVGSVGPaintable, PaintableBox);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<SVGSVGPaintable> create(Layout::SVGSVGBox const&);
|
||||
static JS::NonnullGCPtr<SVGSVGPaintable> create(Layout::SVGSVGBox const&);
|
||||
|
||||
virtual void before_children_paint(PaintContext&, PaintPhase) const override;
|
||||
virtual void after_children_paint(PaintContext&, PaintPhase) const override;
|
||||
|
|
|
@ -578,7 +578,7 @@ Optional<HitTestResult> StackingContext::hit_test(CSSPixelPoint position, HitTes
|
|||
// 1. the background and borders of the element forming the stacking context.
|
||||
if (paintable().absolute_border_box_rect().contains(transformed_position.x().value(), transformed_position.y().value())) {
|
||||
return HitTestResult {
|
||||
.paintable = paintable(),
|
||||
.paintable = const_cast<PaintableBox&>(paintable()),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
namespace Web::Painting {
|
||||
|
||||
NonnullRefPtr<TextPaintable> TextPaintable::create(Layout::TextNode const& layout_node)
|
||||
JS::NonnullGCPtr<TextPaintable> TextPaintable::create(Layout::TextNode const& layout_node)
|
||||
{
|
||||
return adopt_ref(*new TextPaintable(layout_node));
|
||||
return layout_node.heap().allocate_without_realm<TextPaintable>(layout_node);
|
||||
}
|
||||
|
||||
TextPaintable::TextPaintable(Layout::TextNode const& layout_node)
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
namespace Web::Painting {
|
||||
|
||||
class TextPaintable : public Paintable {
|
||||
JS_CELL(TextPaintable, Paintable);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<TextPaintable> create(Layout::TextNode const&);
|
||||
static JS::NonnullGCPtr<TextPaintable> create(Layout::TextNode const&);
|
||||
|
||||
Layout::TextNode const& layout_node() const { return static_cast<Layout::TextNode const&>(Paintable::layout_node()); }
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue