2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-10-31 19:46:55 +00:00
|
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2021-02-10 08:25:35 +01:00
|
|
|
#include <LibGfx/Painter.h>
|
2020-03-07 10:32:51 +01:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
2021-05-13 09:39:30 -04:00
|
|
|
#include <LibWeb/HTML/HTMLHtmlElement.h>
|
2021-10-06 20:02:41 +02:00
|
|
|
#include <LibWeb/Layout/BlockContainer.h>
|
2020-11-22 15:53:01 +01:00
|
|
|
#include <LibWeb/Layout/Box.h>
|
2021-09-15 12:19:42 +01:00
|
|
|
#include <LibWeb/Layout/FormattingContext.h>
|
2022-03-10 23:13:37 +01:00
|
|
|
#include <LibWeb/Painting/PaintableBox.h>
|
2019-10-15 16:48:38 +02:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
namespace Web::Layout {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2022-03-09 23:53:41 +01:00
|
|
|
Box::Box(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
|
|
|
|
: NodeWithStyleAndBoxModelMetrics(document, node, move(style))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Box::Box(DOM::Document& document, DOM::Node* node, CSS::ComputedValues computed_values)
|
|
|
|
: NodeWithStyleAndBoxModelMetrics(document, node, move(computed_values))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Box::~Box()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-23 17:04:24 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
void Box::set_needs_display()
|
2019-10-15 16:48:38 +02:00
|
|
|
{
|
2022-04-11 23:58:41 +02:00
|
|
|
if (paint_box())
|
2022-11-03 12:49:54 +00:00
|
|
|
browsing_context().set_needs_display(paint_box()->absolute_rect());
|
2019-10-15 16:48:38 +02:00
|
|
|
}
|
2019-10-19 11:49:46 +02:00
|
|
|
|
2020-11-22 15:53:01 +01:00
|
|
|
bool Box::is_body() const
|
2019-10-19 11:49:46 +02:00
|
|
|
{
|
2020-11-22 14:46:36 +01:00
|
|
|
return dom_node() && dom_node() == document().body();
|
2019-10-19 11:49:46 +02:00
|
|
|
}
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2023-01-11 12:51:49 +01:00
|
|
|
JS::GCPtr<Painting::Paintable> Box::create_paintable() const
|
2021-10-28 17:08:42 +02:00
|
|
|
{
|
2022-03-10 15:50:57 +01:00
|
|
|
return Painting::PaintableBox::create(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Painting::PaintableBox const* Box::paint_box() const
|
|
|
|
{
|
|
|
|
return static_cast<Painting::PaintableBox const*>(Node::paintable());
|
2021-10-28 17:08:42 +02:00
|
|
|
}
|
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
}
|