diff --git a/Libraries/LibWeb/Layout/AudioBox.cpp b/Libraries/LibWeb/Layout/AudioBox.cpp index c21635d19e8..69499751b78 100644 --- a/Libraries/LibWeb/Layout/AudioBox.cpp +++ b/Libraries/LibWeb/Layout/AudioBox.cpp @@ -21,12 +21,12 @@ AudioBox::AudioBox(DOM::Document& document, DOM::Element& element, GC::Ref(ReplacedBox::dom_node()); + return static_cast(*ReplacedBox::dom_node()); } HTML::HTMLAudioElement const& AudioBox::dom_node() const { - return static_cast(ReplacedBox::dom_node()); + return static_cast(*ReplacedBox::dom_node()); } GC::Ptr AudioBox::create_paintable() const diff --git a/Libraries/LibWeb/Layout/CanvasBox.h b/Libraries/LibWeb/Layout/CanvasBox.h index 35db61ede58..9ac48b42df4 100644 --- a/Libraries/LibWeb/Layout/CanvasBox.h +++ b/Libraries/LibWeb/Layout/CanvasBox.h @@ -21,7 +21,7 @@ public: virtual void prepare_for_replaced_layout() override; - const HTML::HTMLCanvasElement& dom_node() const { return static_cast(ReplacedBox::dom_node()); } + HTML::HTMLCanvasElement const& dom_node() const { return static_cast(*ReplacedBox::dom_node()); } virtual GC::Ptr create_paintable() const override; }; diff --git a/Libraries/LibWeb/Layout/ImageBox.cpp b/Libraries/LibWeb/Layout/ImageBox.cpp index 591f34b2e51..741070670a1 100644 --- a/Libraries/LibWeb/Layout/ImageBox.cpp +++ b/Libraries/LibWeb/Layout/ImageBox.cpp @@ -15,7 +15,7 @@ namespace Web::Layout { GC_DEFINE_ALLOCATOR(ImageBox); -ImageBox::ImageBox(DOM::Document& document, DOM::Element& element, GC::Ref style, ImageProvider const& image_provider) +ImageBox::ImageBox(DOM::Document& document, GC::Ptr element, GC::Ref style, ImageProvider const& image_provider) : ReplacedBox(document, element, move(style)) , m_image_provider(image_provider) { @@ -36,8 +36,9 @@ void ImageBox::prepare_for_replaced_layout() set_natural_aspect_ratio(m_image_provider.intrinsic_aspect_ratio()); if (renders_as_alt_text()) { - auto const& element = as(dom_node()); - auto alt = element.get_attribute_value(HTML::AttributeNames::alt); + String alt; + if (auto element = dom_node()) + alt = element->get_attribute_value(HTML::AttributeNames::alt); if (alt.is_empty()) { set_natural_width(0); @@ -66,7 +67,7 @@ void ImageBox::dom_node_did_update_alt_text(Badge) bool ImageBox::renders_as_alt_text() const { - if (auto const* image_provider = dynamic_cast(&dom_node())) + if (auto const* image_provider = dynamic_cast(dom_node().ptr())) return !image_provider->is_image_available(); return false; } diff --git a/Libraries/LibWeb/Layout/ImageBox.h b/Libraries/LibWeb/Layout/ImageBox.h index 294960d3663..1f61b0739d5 100644 --- a/Libraries/LibWeb/Layout/ImageBox.h +++ b/Libraries/LibWeb/Layout/ImageBox.h @@ -16,13 +16,11 @@ class ImageBox final : public ReplacedBox { GC_DECLARE_ALLOCATOR(ImageBox); public: - ImageBox(DOM::Document&, DOM::Element&, GC::Ref, ImageProvider const&); + ImageBox(DOM::Document&, GC::Ptr, GC::Ref, ImageProvider const&); virtual ~ImageBox() override; virtual void prepare_for_replaced_layout() override; - const DOM::Element& dom_node() const { return static_cast(ReplacedBox::dom_node()); } - bool renders_as_alt_text() const; virtual GC::Ptr create_paintable() const override; diff --git a/Libraries/LibWeb/Layout/LabelableNode.h b/Libraries/LibWeb/Layout/LabelableNode.h index a052bcd6ab8..b03bf726833 100644 --- a/Libraries/LibWeb/Layout/LabelableNode.h +++ b/Libraries/LibWeb/Layout/LabelableNode.h @@ -18,6 +18,9 @@ public: Painting::LabelablePaintable* paintable(); Painting::LabelablePaintable const* paintable() const; + DOM::Element const& dom_node() const { return *ReplacedBox::dom_node(); } + DOM::Element& dom_node() { return *ReplacedBox::dom_node(); } + protected: LabelableNode(DOM::Document& document, DOM::Element& element, GC::Ref style) : ReplacedBox(document, element, move(style)) diff --git a/Libraries/LibWeb/Layout/NavigableContainerViewport.h b/Libraries/LibWeb/Layout/NavigableContainerViewport.h index e548c0f52a0..bc756d1a9f1 100644 --- a/Libraries/LibWeb/Layout/NavigableContainerViewport.h +++ b/Libraries/LibWeb/Layout/NavigableContainerViewport.h @@ -21,8 +21,8 @@ public: virtual void prepare_for_replaced_layout() override; - [[nodiscard]] HTML::NavigableContainer const& dom_node() const { return as(ReplacedBox::dom_node()); } - [[nodiscard]] HTML::NavigableContainer& dom_node() { return as(ReplacedBox::dom_node()); } + [[nodiscard]] HTML::NavigableContainer const& dom_node() const { return as(*ReplacedBox::dom_node()); } + [[nodiscard]] HTML::NavigableContainer& dom_node() { return as(*ReplacedBox::dom_node()); } virtual GC::Ptr create_paintable() const override; diff --git a/Libraries/LibWeb/Layout/ReplacedBox.cpp b/Libraries/LibWeb/Layout/ReplacedBox.cpp index a829e7ad391..5a7810940b7 100644 --- a/Libraries/LibWeb/Layout/ReplacedBox.cpp +++ b/Libraries/LibWeb/Layout/ReplacedBox.cpp @@ -11,8 +11,8 @@ namespace Web::Layout { -ReplacedBox::ReplacedBox(DOM::Document& document, DOM::Element& element, GC::Ref style) - : Box(document, &element, move(style)) +ReplacedBox::ReplacedBox(DOM::Document& document, GC::Ptr element, GC::Ref style) + : Box(document, element, move(style)) { } diff --git a/Libraries/LibWeb/Layout/ReplacedBox.h b/Libraries/LibWeb/Layout/ReplacedBox.h index 87d93ae2197..b3ccdee2f4a 100644 --- a/Libraries/LibWeb/Layout/ReplacedBox.h +++ b/Libraries/LibWeb/Layout/ReplacedBox.h @@ -15,11 +15,11 @@ class ReplacedBox : public Box { GC_CELL(ReplacedBox, Box); public: - ReplacedBox(DOM::Document&, DOM::Element&, GC::Ref); + ReplacedBox(DOM::Document&, GC::Ptr, GC::Ref); virtual ~ReplacedBox() override; - DOM::Element const& dom_node() const { return as(*Node::dom_node()); } - DOM::Element& dom_node() { return as(*Node::dom_node()); } + GC::Ptr dom_node() const { return as(Node::dom_node()); } + GC::Ptr dom_node() { return as(Node::dom_node()); } virtual void prepare_for_replaced_layout() { } diff --git a/Libraries/LibWeb/Layout/SVGSVGBox.h b/Libraries/LibWeb/Layout/SVGSVGBox.h index d7b5472cebb..d631aff2040 100644 --- a/Libraries/LibWeb/Layout/SVGSVGBox.h +++ b/Libraries/LibWeb/Layout/SVGSVGBox.h @@ -19,8 +19,8 @@ public: SVGSVGBox(DOM::Document&, SVG::SVGSVGElement&, GC::Ref); virtual ~SVGSVGBox() override = default; - SVG::SVGSVGElement& dom_node() { return as(ReplacedBox::dom_node()); } - SVG::SVGSVGElement const& dom_node() const { return as(ReplacedBox::dom_node()); } + SVG::SVGSVGElement& dom_node() { return as(*ReplacedBox::dom_node()); } + SVG::SVGSVGElement const& dom_node() const { return as(*ReplacedBox::dom_node()); } virtual bool can_have_children() const override { return true; } diff --git a/Libraries/LibWeb/Layout/VideoBox.cpp b/Libraries/LibWeb/Layout/VideoBox.cpp index a21df46938e..add74daaa27 100644 --- a/Libraries/LibWeb/Layout/VideoBox.cpp +++ b/Libraries/LibWeb/Layout/VideoBox.cpp @@ -29,12 +29,12 @@ void VideoBox::finalize() HTML::HTMLVideoElement& VideoBox::dom_node() { - return static_cast(ReplacedBox::dom_node()); + return static_cast(*ReplacedBox::dom_node()); } HTML::HTMLVideoElement const& VideoBox::dom_node() const { - return static_cast(ReplacedBox::dom_node()); + return static_cast(*ReplacedBox::dom_node()); } void VideoBox::prepare_for_replaced_layout() diff --git a/Libraries/LibWeb/Painting/ImagePaintable.cpp b/Libraries/LibWeb/Painting/ImagePaintable.cpp index 034f9e7c7b9..31447704278 100644 --- a/Libraries/LibWeb/Painting/ImagePaintable.cpp +++ b/Libraries/LibWeb/Painting/ImagePaintable.cpp @@ -26,7 +26,9 @@ GC::Ref ImagePaintable::create(Layout::SVGImageBox const& layout GC::Ref ImagePaintable::create(Layout::ImageBox const& layout_box) { - auto alt = layout_box.dom_node().get_attribute_value(HTML::AttributeNames::alt); + String alt; + if (auto element = layout_box.dom_node()) + alt = element->get_attribute_value(HTML::AttributeNames::alt); return layout_box.heap().allocate(layout_box, layout_box.image_provider(), layout_box.renders_as_alt_text(), move(alt), false); }