/src/serenity/Userland/Libraries/LibWeb/Layout/Box.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/OwnPtr.h> |
10 | | #include <LibGfx/Rect.h> |
11 | | #include <LibJS/Heap/Cell.h> |
12 | | #include <LibWeb/Layout/Node.h> |
13 | | |
14 | | namespace Web::Layout { |
15 | | |
16 | | struct LineBoxFragmentCoordinate { |
17 | | size_t line_box_index { 0 }; |
18 | | size_t fragment_index { 0 }; |
19 | | }; |
20 | | |
21 | | class Box : public NodeWithStyleAndBoxModelMetrics { |
22 | | JS_CELL(Box, NodeWithStyleAndBoxModelMetrics); |
23 | | |
24 | | public: |
25 | | Painting::PaintableBox const* paintable_box() const; |
26 | | Painting::PaintableBox* paintable_box(); |
27 | | |
28 | | bool is_body() const; |
29 | | |
30 | | // https://www.w3.org/TR/css-images-3/#natural-dimensions |
31 | 0 | Optional<CSSPixels> natural_width() const { return m_natural_width; } |
32 | 0 | Optional<CSSPixels> natural_height() const { return m_natural_height; } |
33 | 0 | Optional<CSSPixelFraction> natural_aspect_ratio() const { return m_natural_aspect_ratio; } |
34 | | |
35 | 0 | bool has_natural_width() const { return natural_width().has_value(); } |
36 | 0 | bool has_natural_height() const { return natural_height().has_value(); } |
37 | 0 | bool has_natural_aspect_ratio() const { return natural_aspect_ratio().has_value(); } |
38 | | |
39 | 0 | void set_natural_width(Optional<CSSPixels> width) { m_natural_width = width; } |
40 | 0 | void set_natural_height(Optional<CSSPixels> height) { m_natural_height = height; } |
41 | 0 | void set_natural_aspect_ratio(Optional<CSSPixelFraction> ratio) { m_natural_aspect_ratio = ratio; } |
42 | | |
43 | | // https://www.w3.org/TR/css-sizing-4/#preferred-aspect-ratio |
44 | | Optional<CSSPixelFraction> preferred_aspect_ratio() const; |
45 | 0 | bool has_preferred_aspect_ratio() const { return preferred_aspect_ratio().has_value(); } |
46 | | |
47 | | virtual ~Box() override; |
48 | | |
49 | 0 | virtual void did_set_content_size() { } |
50 | | |
51 | | virtual JS::GCPtr<Painting::Paintable> create_paintable() const override; |
52 | | |
53 | | bool is_scroll_container() const; |
54 | | |
55 | | bool is_user_scrollable() const; |
56 | | |
57 | | protected: |
58 | | Box(DOM::Document&, DOM::Node*, NonnullRefPtr<CSS::StyleProperties>); |
59 | | Box(DOM::Document&, DOM::Node*, NonnullOwnPtr<CSS::ComputedValues>); |
60 | | |
61 | | private: |
62 | 0 | virtual bool is_box() const final { return true; } |
63 | | |
64 | | Optional<CSSPixels> m_natural_width; |
65 | | Optional<CSSPixels> m_natural_height; |
66 | | Optional<CSSPixelFraction> m_natural_aspect_ratio; |
67 | | }; |
68 | | |
69 | | template<> |
70 | 0 | inline bool Node::fast_is<Box>() const { return is_box(); } |
71 | | |
72 | | } |