1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:37:44 +00:00

LibWeb: Move scroll offset state from layout tree to dom tree

Scroll offset state should not be reset by layout tree rebuilt.
This commit is contained in:
Aliaksandr Kalenik 2023-08-06 02:15:21 +02:00 committed by Andreas Kling
parent b6ea4b002b
commit 55b5c61a79
3 changed files with 36 additions and 5 deletions

View file

@ -314,6 +314,14 @@ public:
void unregister_intersection_observer(Badge<IntersectionObserver::IntersectionObserver>, JS::NonnullGCPtr<IntersectionObserver::IntersectionObserver>); void unregister_intersection_observer(Badge<IntersectionObserver::IntersectionObserver>, JS::NonnullGCPtr<IntersectionObserver::IntersectionObserver>);
IntersectionObserver::IntersectionObserverRegistration& get_intersection_observer_registration(Badge<DOM::Document>, IntersectionObserver::IntersectionObserver const&); IntersectionObserver::IntersectionObserverRegistration& get_intersection_observer_registration(Badge<DOM::Document>, IntersectionObserver::IntersectionObserver const&);
enum class ScrollOffsetFor {
Self,
PseudoBefore,
PseudoAfter
};
CSSPixelPoint scroll_offset(ScrollOffsetFor type) const { return m_scroll_offset[to_underlying(type)]; }
void set_scroll_offset(ScrollOffsetFor type, CSSPixelPoint offset) { m_scroll_offset[to_underlying(type)] = offset; }
protected: protected:
Element(Document&, DOM::QualifiedName); Element(Document&, DOM::QualifiedName);
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override; virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
@ -367,6 +375,8 @@ private:
// https://www.w3.org/TR/intersection-observer/#dom-element-registeredintersectionobservers-slot // https://www.w3.org/TR/intersection-observer/#dom-element-registeredintersectionobservers-slot
// Element objects have an internal [[RegisteredIntersectionObservers]] slot, which is initialized to an empty list. // Element objects have an internal [[RegisteredIntersectionObservers]] slot, which is initialized to an empty list.
Vector<IntersectionObserver::IntersectionObserverRegistration> m_registered_intersection_observers; Vector<IntersectionObserver::IntersectionObserverRegistration> m_registered_intersection_observers;
Array<CSSPixelPoint, 3> m_scroll_offset;
}; };
template<> template<>

View file

@ -61,12 +61,35 @@ bool Box::is_scrollable() const
return computed_values().overflow_y() == CSS::Overflow::Scroll; return computed_values().overflow_y() == CSS::Overflow::Scroll;
} }
CSSPixelPoint Box::scroll_offset() const
{
if (is_generated_for_before_pseudo_element())
return pseudo_element_generator()->scroll_offset(DOM::Element::ScrollOffsetFor::PseudoBefore);
if (is_generated_for_after_pseudo_element())
return pseudo_element_generator()->scroll_offset(DOM::Element::ScrollOffsetFor::PseudoAfter);
if (!is<DOM::Element>(*dom_node()))
return {};
return static_cast<DOM::Element const*>(dom_node())->scroll_offset(DOM::Element::ScrollOffsetFor::Self);
}
void Box::set_scroll_offset(CSSPixelPoint offset) void Box::set_scroll_offset(CSSPixelPoint offset)
{ {
// FIXME: If there is horizontal and vertical scroll ignore only part of the new offset // FIXME: If there is horizontal and vertical scroll ignore only part of the new offset
if (offset.y() < 0 || m_scroll_offset == offset) if (offset.y() < 0 || scroll_offset() == offset)
return; return;
m_scroll_offset = offset;
if (is_generated_for_before_pseudo_element()) {
pseudo_element_generator()->set_scroll_offset(DOM::Element::ScrollOffsetFor::PseudoBefore, offset);
} else if (is_generated_for_after_pseudo_element()) {
pseudo_element_generator()->set_scroll_offset(DOM::Element::ScrollOffsetFor::PseudoAfter, offset);
} else if (is<DOM::Element>(*dom_node())) {
static_cast<DOM::Element*>(dom_node())->set_scroll_offset(DOM::Element::ScrollOffsetFor::Self, offset);
} else {
return;
}
set_needs_display(); set_needs_display();
} }

View file

@ -54,7 +54,7 @@ public:
bool is_scroll_container() const; bool is_scroll_container() const;
bool is_scrollable() const; bool is_scrollable() const;
CSSPixelPoint scroll_offset() const { return m_scroll_offset; } CSSPixelPoint scroll_offset() const;
void set_scroll_offset(CSSPixelPoint); void set_scroll_offset(CSSPixelPoint);
protected: protected:
@ -64,8 +64,6 @@ protected:
private: private:
virtual bool is_box() const final { return true; } virtual bool is_box() const final { return true; }
CSSPixelPoint m_scroll_offset;
Optional<CSSPixels> m_natural_width; Optional<CSSPixels> m_natural_width;
Optional<CSSPixels> m_natural_height; Optional<CSSPixels> m_natural_height;
Optional<float> m_natural_aspect_ratio; Optional<float> m_natural_aspect_ratio;