mirror of
https://github.com/RGBCube/serenity
synced 2025-07-19 02:07:36 +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
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".
|
// FIXME: Implement this in terms of calling "scroll the element".
|
||||||
auto scroll_offset = paintable_box()->scroll_offset();
|
auto scroll_offset = paintable_box()->scroll_offset();
|
||||||
scroll_offset.set_x(static_cast<float>(x));
|
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)
|
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".
|
// FIXME: Implement this in terms of calling "scroll the element".
|
||||||
auto scroll_offset = paintable_box()->scroll_offset();
|
auto scroll_offset = paintable_box()->scroll_offset();
|
||||||
scroll_offset.set_y(static_cast<float>(y));
|
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
|
// 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;
|
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()
|
void Box::set_needs_display()
|
||||||
{
|
{
|
||||||
if (paintable_box())
|
if (paintable_box())
|
||||||
|
|
|
@ -54,7 +54,6 @@ public:
|
||||||
bool is_scroll_container() const;
|
bool is_scroll_container() const;
|
||||||
|
|
||||||
bool is_scrollable() const;
|
bool is_scrollable() const;
|
||||||
void set_scroll_offset(CSSPixelPoint);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Box(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
|
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);
|
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)
|
void PaintableBox::scroll_by(int delta_x, int delta_y)
|
||||||
{
|
{
|
||||||
auto scrollable_overflow_rect = this->scrollable_overflow_rect();
|
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 current_offset = scroll_offset();
|
||||||
auto new_offset_x = clamp(current_offset.x() + delta_x, 0, max_x_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);
|
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)
|
void PaintableBox::set_offset(CSSPixelPoint offset)
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
CSSPixelPoint effective_offset() const;
|
CSSPixelPoint effective_offset() const;
|
||||||
|
|
||||||
CSSPixelPoint scroll_offset() const;
|
CSSPixelPoint scroll_offset() const;
|
||||||
|
void set_scroll_offset(CSSPixelPoint);
|
||||||
void scroll_by(int delta_x, int delta_y);
|
void scroll_by(int delta_x, int delta_y);
|
||||||
|
|
||||||
void set_offset(CSSPixelPoint);
|
void set_offset(CSSPixelPoint);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue