diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 0d08d2e568..4b97ed5fc6 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -2231,7 +2231,7 @@ void Document::decrement_number_of_things_delaying_the_load_event(Badgepaintable_box()) - const_cast(paintable_box)->invalidate_stacking_context(); + paintable_box->invalidate_stacking_context(); } void Document::check_favicon_after_loading_link_resource() diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 1888d0f458..e54a2dc133 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -1054,7 +1054,7 @@ void Element::set_scroll_left(double x) // FIXME: Implement this in terms of calling "scroll the element". auto scroll_offset = paintable_box()->scroll_offset(); scroll_offset.set_x(static_cast(x)); - const_cast(paintable_box())->set_scroll_offset(scroll_offset); + paintable_box()->set_scroll_offset(scroll_offset); } void Element::set_scroll_top(double y) @@ -1122,7 +1122,7 @@ void Element::set_scroll_top(double y) // FIXME: Implement this in terms of calling "scroll the element". auto scroll_offset = paintable_box()->scroll_offset(); scroll_offset.set_y(static_cast(y)); - const_cast(paintable_box())->set_scroll_offset(scroll_offset); + paintable_box()->set_scroll_offset(scroll_offset); } // https://drafts.csswg.org/cssom-view/#dom-element-scrollwidth @@ -1780,7 +1780,7 @@ HashMap const& Element::custom_properti void Element::scroll(double x, double y) { // AD-HOC: - const_cast(paintable_box())->scroll_by(x, y); + paintable_box()->scroll_by(x, y); } // https://drafts.csswg.org/cssom-view/#dom-element-scroll diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 7406f10e1d..ba73680a6f 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -1454,6 +1454,15 @@ Painting::PaintableBox const* Node::paintable_box() const return static_cast(*layout_node()).paintable_box(); } +Painting::PaintableBox* Node::paintable_box() +{ + if (!layout_node()) + return nullptr; + if (!layout_node()->is_box()) + return nullptr; + return static_cast(*layout_node()).paintable_box(); +} + // https://dom.spec.whatwg.org/#queue-a-mutation-record void Node::queue_mutation_record(FlyString const& type, DeprecatedString attribute_name, DeprecatedString attribute_namespace, DeprecatedString old_value, Vector> added_nodes, Vector> removed_nodes, Node* previous_sibling, Node* next_sibling) const { diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index 3cf1da2e9c..854f6778fa 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -183,6 +183,7 @@ public: Layout::Node* layout_node() { return m_layout_node; } Painting::PaintableBox const* paintable_box() const; + Painting::PaintableBox* paintable_box(); Painting::Paintable const* paintable() const; void set_layout_node(Badge, JS::NonnullGCPtr); diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index ae6f19d209..b97cab5e07 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -134,14 +134,14 @@ Painting::PaintableBox* EventHandler::paint_root() { if (!m_browsing_context->active_document()) return nullptr; - return const_cast(m_browsing_context->active_document()->paintable_box()); + return m_browsing_context->active_document()->paintable_box(); } Painting::PaintableBox const* EventHandler::paint_root() const { if (!m_browsing_context->active_document()) return nullptr; - return const_cast(m_browsing_context->active_document()->paintable_box()); + return m_browsing_context->active_document()->paintable_box(); } bool EventHandler::handle_mousewheel(CSSPixelPoint position, unsigned button, unsigned buttons, unsigned int modifiers, int wheel_delta_x, int wheel_delta_y)