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

LibWeb: Move scroll state from Layout::BlockContainer to Layout::Box

Let's allow any box to be scrollable, not just block containers.
This commit is contained in:
Andreas Kling 2023-01-23 17:04:24 +01:00
parent 8fe748bb89
commit 3dd006f719
6 changed files with 40 additions and 43 deletions

View file

@ -21,21 +21,6 @@ BlockContainer::BlockContainer(DOM::Document& document, DOM::Node* node, CSS::Co
BlockContainer::~BlockContainer() = default;
bool BlockContainer::is_scrollable() const
{
// FIXME: Support horizontal scroll as well (overflow-x)
return computed_values().overflow_y() == CSS::Overflow::Scroll;
}
void BlockContainer::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)
return;
m_scroll_offset = offset;
set_needs_display();
}
Painting::PaintableWithLines const* BlockContainer::paint_box() const
{
return static_cast<Painting::PaintableWithLines const*>(Box::paint_box());

View file

@ -20,18 +20,12 @@ public:
BlockContainer(DOM::Document&, DOM::Node*, CSS::ComputedValues);
virtual ~BlockContainer() override;
bool is_scrollable() const;
CSSPixelPoint scroll_offset() const { return m_scroll_offset; }
void set_scroll_offset(CSSPixelPoint);
Painting::PaintableWithLines const* paint_box() const;
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
private:
virtual bool is_block_container() const final { return true; }
CSSPixelPoint m_scroll_offset;
};
template<>

View file

@ -29,6 +29,21 @@ Box::~Box()
{
}
bool Box::is_scrollable() const
{
// FIXME: Support horizontal scroll as well (overflow-x)
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 || m_scroll_offset == offset)
return;
m_scroll_offset = offset;
set_needs_display();
}
void Box::set_needs_display()
{
if (paint_box())

View file

@ -41,12 +41,18 @@ public:
virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
bool is_scrollable() const;
CSSPixelPoint scroll_offset() const { return m_scroll_offset; }
void set_scroll_offset(CSSPixelPoint);
protected:
Box(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>);
Box(DOM::Document&, DOM::Node*, CSS::ComputedValues);
private:
virtual bool is_box() const final { return true; }
CSSPixelPoint m_scroll_offset;
};
template<>