Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#include <LibGfx/Painter.h>
9#include <LibWeb/DOM/Document.h>
10#include <LibWeb/HTML/HTMLHtmlElement.h>
11#include <LibWeb/Layout/BlockContainer.h>
12#include <LibWeb/Layout/Box.h>
13#include <LibWeb/Layout/FormattingContext.h>
14#include <LibWeb/Painting/PaintableBox.h>
15
16namespace Web::Layout {
17
18Box::Box(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
19 : NodeWithStyleAndBoxModelMetrics(document, node, move(style))
20{
21}
22
23Box::Box(DOM::Document& document, DOM::Node* node, CSS::ComputedValues computed_values)
24 : NodeWithStyleAndBoxModelMetrics(document, node, move(computed_values))
25{
26}
27
28Box::~Box()
29{
30}
31
32bool Box::is_scrollable() const
33{
34 // FIXME: Support horizontal scroll as well (overflow-x)
35 return computed_values().overflow_y() == CSS::Overflow::Scroll;
36}
37
38void Box::set_scroll_offset(CSSPixelPoint offset)
39{
40 // FIXME: If there is horizontal and vertical scroll ignore only part of the new offset
41 if (offset.y() < 0 || m_scroll_offset == offset)
42 return;
43 m_scroll_offset = offset;
44 set_needs_display();
45}
46
47void Box::set_needs_display()
48{
49 if (paint_box())
50 browsing_context().set_needs_display(paint_box()->absolute_rect());
51}
52
53bool Box::is_body() const
54{
55 return dom_node() && dom_node() == document().body();
56}
57
58JS::GCPtr<Painting::Paintable> Box::create_paintable() const
59{
60 return Painting::PaintableBox::create(*this);
61}
62
63Painting::PaintableBox const* Box::paint_box() const
64{
65 return static_cast<Painting::PaintableBox const*>(Node::paintable());
66}
67
68}