mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 07:47:34 +00:00
LibWeb: Move set_needs_display() from layout node to paintable
For this method, there is no need to go through the layout node when we can directly reach the paintable.
This commit is contained in:
parent
814bed33b4
commit
7c2713c14f
21 changed files with 97 additions and 87 deletions
|
@ -73,6 +73,11 @@ HTML::BrowsingContext& Paintable::browsing_context()
|
|||
return m_browsing_context;
|
||||
}
|
||||
|
||||
JS::GCPtr<HTML::Navigable> Paintable::navigable() const
|
||||
{
|
||||
return document().navigable();
|
||||
}
|
||||
|
||||
Paintable::DispatchEventOfSameName Paintable::handle_mousedown(Badge<EventHandler>, CSSPixelPoint, unsigned, unsigned)
|
||||
{
|
||||
return DispatchEventOfSameName::Yes;
|
||||
|
@ -118,6 +123,31 @@ void Paintable::invalidate_stacking_context()
|
|||
m_stacking_context = nullptr;
|
||||
}
|
||||
|
||||
void Paintable::set_needs_display() const
|
||||
{
|
||||
auto* containing_block = this->containing_block();
|
||||
if (!containing_block)
|
||||
return;
|
||||
if (!containing_block->paintable_box())
|
||||
return;
|
||||
auto navigable = this->navigable();
|
||||
if (!navigable)
|
||||
return;
|
||||
|
||||
if (is<Painting::InlinePaintable>(*this)) {
|
||||
auto const& fragments = static_cast<Painting::InlinePaintable const*>(this)->fragments();
|
||||
for (auto const& fragment : fragments)
|
||||
navigable->set_needs_display(fragment.absolute_rect());
|
||||
}
|
||||
|
||||
if (!is<Painting::PaintableWithLines>(*containing_block->paintable_box()))
|
||||
return;
|
||||
static_cast<Painting::PaintableWithLines const&>(*containing_block->paintable_box()).for_each_fragment([&](auto& fragment) {
|
||||
navigable->set_needs_display(fragment.absolute_rect());
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
PaintableBox const* Paintable::nearest_scrollable_ancestor_within_stacking_context() const
|
||||
{
|
||||
auto* ancestor = parent();
|
||||
|
|
|
@ -165,7 +165,9 @@ public:
|
|||
[[nodiscard]] HTML::BrowsingContext const& browsing_context() const;
|
||||
[[nodiscard]] HTML::BrowsingContext& browsing_context();
|
||||
|
||||
void set_needs_display() const { const_cast<Layout::Node&>(*m_layout_node).set_needs_display(); }
|
||||
JS::GCPtr<HTML::Navigable> navigable() const;
|
||||
|
||||
virtual void set_needs_display() const;
|
||||
|
||||
Layout::Box const* containing_block() const
|
||||
{
|
||||
|
|
|
@ -80,7 +80,7 @@ void PaintableBox::set_scroll_offset(CSSPixelPoint offset)
|
|||
return;
|
||||
}
|
||||
|
||||
node.set_needs_display();
|
||||
set_needs_display();
|
||||
}
|
||||
|
||||
void PaintableBox::scroll_by(int delta_x, int delta_y)
|
||||
|
@ -790,4 +790,10 @@ Optional<HitTestResult> PaintableWithLines::hit_test(CSSPixelPoint position, Hit
|
|||
return {};
|
||||
}
|
||||
|
||||
void PaintableBox::set_needs_display() const
|
||||
{
|
||||
if (auto navigable = this->navigable())
|
||||
navigable->set_needs_display(absolute_rect());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -124,6 +124,8 @@ public:
|
|||
DOM::Node const* dom_node() const { return layout_box().dom_node(); }
|
||||
DOM::Node* dom_node() { return layout_box().dom_node(); }
|
||||
|
||||
virtual void set_needs_display() const override;
|
||||
|
||||
virtual void apply_scroll_offset(PaintContext&, PaintPhase) const override;
|
||||
virtual void reset_scroll_offset(PaintContext&, PaintPhase) const override;
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@ PaintableFragment::PaintableFragment(Layout::LineBoxFragment const& fragment)
|
|||
CSSPixelRect const PaintableFragment::absolute_rect() const
|
||||
{
|
||||
CSSPixelRect rect { {}, size() };
|
||||
rect.set_location(m_layout_node->containing_block()->paintable_box()->absolute_position());
|
||||
if (m_layout_node->containing_block() && m_layout_node->containing_block()->paintable_box())
|
||||
rect.set_location(m_layout_node->containing_block()->paintable_box()->absolute_position());
|
||||
rect.translate_by(offset());
|
||||
return rect;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue