mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:57:35 +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:
parent
b6ea4b002b
commit
55b5c61a79
3 changed files with 36 additions and 5 deletions
|
@ -314,6 +314,14 @@ public:
|
|||
void unregister_intersection_observer(Badge<IntersectionObserver::IntersectionObserver>, JS::NonnullGCPtr<IntersectionObserver::IntersectionObserver>);
|
||||
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:
|
||||
Element(Document&, DOM::QualifiedName);
|
||||
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
||||
|
@ -367,6 +375,8 @@ private:
|
|||
// 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.
|
||||
Vector<IntersectionObserver::IntersectionObserverRegistration> m_registered_intersection_observers;
|
||||
|
||||
Array<CSSPixelPoint, 3> m_scroll_offset;
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
|
@ -61,12 +61,35 @@ bool Box::is_scrollable() const
|
|||
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)
|
||||
{
|
||||
// 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;
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public:
|
|||
bool is_scroll_container() const;
|
||||
|
||||
bool is_scrollable() const;
|
||||
CSSPixelPoint scroll_offset() const { return m_scroll_offset; }
|
||||
CSSPixelPoint scroll_offset() const;
|
||||
void set_scroll_offset(CSSPixelPoint);
|
||||
|
||||
protected:
|
||||
|
@ -64,8 +64,6 @@ protected:
|
|||
private:
|
||||
virtual bool is_box() const final { return true; }
|
||||
|
||||
CSSPixelPoint m_scroll_offset;
|
||||
|
||||
Optional<CSSPixels> m_natural_width;
|
||||
Optional<CSSPixels> m_natural_height;
|
||||
Optional<float> m_natural_aspect_ratio;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue