mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
LibWeb: Move set_scroll_offset() from Layout::Box to PaintableBox
Nodes in layout tree should not be aware of scroll state.
This commit is contained in:
parent
5b7926fa53
commit
fee5b4deb6
Notes:
sideshowbarker
2024-07-16 21:30:46 +09:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/SerenityOS/serenity/commit/fee5b4deb6 Pull-request: https://github.com/SerenityOS/serenity/pull/20395 Reviewed-by: https://github.com/MacDue
5 changed files with 24 additions and 23 deletions
|
@ -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));
|
||||
box->set_scroll_offset(scroll_offset);
|
||||
const_cast<Painting::PaintableBox*>(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));
|
||||
box->set_scroll_offset(scroll_offset);
|
||||
const_cast<Painting::PaintableBox*>(paintable_box())->set_scroll_offset(scroll_offset);
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-scrollwidth
|
||||
|
|
|
@ -61,25 +61,6 @@ bool Box::is_scrollable() const
|
|||
return computed_values().overflow_y() == CSS::Overflow::Scroll;
|
||||
}
|
||||
|
||||
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 || paintable_box()->scroll_offset() == offset)
|
||||
return;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void Box::set_needs_display()
|
||||
{
|
||||
if (paintable_box())
|
||||
|
|
|
@ -54,7 +54,6 @@ public:
|
|||
bool is_scroll_container() const;
|
||||
|
||||
bool is_scrollable() const;
|
||||
void set_scroll_offset(CSSPixelPoint);
|
||||
|
||||
protected:
|
||||
Box(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
|
||||
|
|
|
@ -71,6 +71,26 @@ CSSPixelPoint PaintableBox::scroll_offset() const
|
|||
return static_cast<DOM::Element const*>(dom_node())->scroll_offset(DOM::Element::ScrollOffsetFor::Self);
|
||||
}
|
||||
|
||||
void PaintableBox::set_scroll_offset(CSSPixelPoint offset)
|
||||
{
|
||||
// FIXME: If there is horizontal and vertical scroll ignore only part of the new offset
|
||||
if (offset.y() < 0 || scroll_offset() == offset)
|
||||
return;
|
||||
|
||||
auto& node = layout_node();
|
||||
if (node.is_generated_for_before_pseudo_element()) {
|
||||
node.pseudo_element_generator()->set_scroll_offset(DOM::Element::ScrollOffsetFor::PseudoBefore, offset);
|
||||
} else if (node.is_generated_for_after_pseudo_element()) {
|
||||
node.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;
|
||||
}
|
||||
|
||||
node.set_needs_display();
|
||||
}
|
||||
|
||||
void PaintableBox::scroll_by(int delta_x, int delta_y)
|
||||
{
|
||||
auto scrollable_overflow_rect = this->scrollable_overflow_rect();
|
||||
|
@ -81,7 +101,7 @@ void PaintableBox::scroll_by(int delta_x, int delta_y)
|
|||
auto current_offset = scroll_offset();
|
||||
auto new_offset_x = clamp(current_offset.x() + delta_x, 0, max_x_offset);
|
||||
auto new_offset_y = clamp(current_offset.y() + delta_y, 0, max_y_offset);
|
||||
layout_box().set_scroll_offset({ new_offset_x, new_offset_y });
|
||||
set_scroll_offset({ new_offset_x, new_offset_y });
|
||||
}
|
||||
|
||||
void PaintableBox::set_offset(CSSPixelPoint offset)
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
CSSPixelPoint effective_offset() const;
|
||||
|
||||
CSSPixelPoint scroll_offset() const;
|
||||
void set_scroll_offset(CSSPixelPoint);
|
||||
void scroll_by(int delta_x, int delta_y);
|
||||
|
||||
void set_offset(CSSPixelPoint);
|
||||
|
|
Loading…
Reference in a new issue