/src/serenity/Userland/Libraries/LibWeb/Painting/InlinePaintable.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2022, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibWeb/Layout/InlineNode.h> |
10 | | #include <LibWeb/Painting/ClippableAndScrollable.h> |
11 | | #include <LibWeb/Painting/Paintable.h> |
12 | | #include <LibWeb/Painting/PaintableFragment.h> |
13 | | |
14 | | namespace Web::Painting { |
15 | | |
16 | | class InlinePaintable final : public Paintable |
17 | | , public ClippableAndScrollable { |
18 | | JS_CELL(InlinePaintable, Paintable); |
19 | | JS_DECLARE_ALLOCATOR(InlinePaintable); |
20 | | |
21 | | public: |
22 | | static JS::NonnullGCPtr<InlinePaintable> create(Layout::InlineNode const&); |
23 | | |
24 | | virtual void paint(PaintContext&, PaintPhase) const override; |
25 | | |
26 | | virtual void before_paint(PaintContext& context, PaintPhase) const override; |
27 | | virtual void after_paint(PaintContext& context, PaintPhase) const override; |
28 | | |
29 | | Layout::InlineNode const& layout_node() const; |
30 | 0 | auto const& box_model() const { return layout_node().box_model(); } |
31 | | |
32 | | CSSPixelRect bounding_rect() const; |
33 | 0 | Vector<PaintableFragment> const& fragments() const { return m_fragments; } |
34 | 0 | Vector<PaintableFragment>& fragments() { return m_fragments; } |
35 | | |
36 | 0 | virtual bool is_inline_paintable() const override { return true; } |
37 | | |
38 | | virtual TraversalDecision hit_test(CSSPixelPoint, HitTestType, Function<TraversalDecision(HitTestResult)> const& callback) const override; |
39 | | |
40 | 0 | void set_box_shadow_data(Vector<ShadowData>&& box_shadow_data) { m_box_shadow_data = move(box_shadow_data); } |
41 | 0 | Vector<ShadowData> const& box_shadow_data() const { return m_box_shadow_data; } |
42 | | |
43 | 0 | void set_outline_data(Optional<BordersData> outline_data) { m_outline_data = outline_data; } |
44 | 0 | Optional<BordersData> const& outline_data() const { return m_outline_data; } |
45 | | |
46 | 0 | void set_outline_offset(CSSPixels outline_offset) { m_outline_offset = outline_offset; } |
47 | 0 | CSSPixels outline_offset() const { return m_outline_offset; } |
48 | | |
49 | | virtual void resolve_paint_properties() override; |
50 | | |
51 | | private: |
52 | | InlinePaintable(Layout::InlineNode const&); |
53 | | |
54 | | template<typename Callback> |
55 | | void for_each_fragment(Callback) const; |
56 | | |
57 | | Vector<ShadowData> m_box_shadow_data; |
58 | | Optional<BordersData> m_outline_data; |
59 | | CSSPixels m_outline_offset { 0 }; |
60 | | Vector<PaintableFragment> m_fragments; |
61 | | }; |
62 | | |
63 | | template<> |
64 | 0 | inline bool Paintable::fast_is<InlinePaintable>() const { return is_inline_paintable(); } |
65 | | |
66 | | } |