ladybird/Userland/Libraries/LibWeb/Layout/BlockContainer.cpp
Andreas Kling 4d401bf796 LibWeb: Make the paint tree GC-allocated
This simplifies the ownership model between DOM/layout/paint nodes
immensely by deferring to the garbage collector for figuring out what's
live and what's not.
2023-01-11 12:55:00 +01:00

49 lines
1.3 KiB
C++

/*
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Layout/BlockContainer.h>
#include <LibWeb/Painting/PaintableBox.h>
namespace Web::Layout {
BlockContainer::BlockContainer(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
: Box(document, node, move(style))
{
}
BlockContainer::BlockContainer(DOM::Document& document, DOM::Node* node, CSS::ComputedValues computed_values)
: Box(document, node, move(computed_values))
{
}
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());
}
JS::GCPtr<Painting::Paintable> BlockContainer::create_paintable() const
{
return Painting::PaintableWithLines::create(*this);
}
}