LibWeb: Add non-const version of paintable_box() in DOM::Node

This commit is contained in:
Aliaksandr Kalenik 2023-08-07 00:59:23 +02:00 committed by Andreas Kling
parent 6868ace8f4
commit c985a1b2af
Notes: sideshowbarker 2024-07-16 20:51:53 +09:00
5 changed files with 16 additions and 6 deletions

View File

@ -2231,7 +2231,7 @@ void Document::decrement_number_of_things_delaying_the_load_event(Badge<Document
void Document::invalidate_stacking_context_tree()
{
if (auto* paintable_box = this->paintable_box())
const_cast<Painting::PaintableBox*>(paintable_box)->invalidate_stacking_context();
paintable_box->invalidate_stacking_context();
}
void Document::check_favicon_after_loading_link_resource()

View File

@ -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<float>(x));
const_cast<Painting::PaintableBox*>(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<float>(y));
const_cast<Painting::PaintableBox*>(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<DeprecatedFlyString, CSS::StyleProperty> const& Element::custom_properti
void Element::scroll(double x, double y)
{
// AD-HOC:
const_cast<Painting::PaintableBox*>(paintable_box())->scroll_by(x, y);
paintable_box()->scroll_by(x, y);
}
// https://drafts.csswg.org/cssom-view/#dom-element-scroll

View File

@ -1454,6 +1454,15 @@ Painting::PaintableBox const* Node::paintable_box() const
return static_cast<Layout::Box const&>(*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::Box&>(*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<JS::Handle<Node>> added_nodes, Vector<JS::Handle<Node>> removed_nodes, Node* previous_sibling, Node* next_sibling) const
{

View File

@ -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<Layout::Node>, JS::NonnullGCPtr<Layout::Node>);

View File

@ -134,14 +134,14 @@ Painting::PaintableBox* EventHandler::paint_root()
{
if (!m_browsing_context->active_document())
return nullptr;
return const_cast<Painting::PaintableBox*>(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<Painting::PaintableBox*>(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)