/src/serenity/Userland/Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> |
3 | | * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> |
4 | | * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> |
5 | | * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> |
6 | | * |
7 | | * SPDX-License-Identifier: BSD-2-Clause |
8 | | */ |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include <LibWeb/CSS/CSSStyleValue.h> |
13 | | #include <LibWeb/CSS/Enums.h> |
14 | | #include <LibWeb/CSS/PercentageOr.h> |
15 | | #include <LibWeb/CSS/StyleValues/EdgeStyleValue.h> |
16 | | |
17 | | namespace Web::CSS { |
18 | | |
19 | | class PositionStyleValue final : public StyleValueWithDefaultOperators<PositionStyleValue> { |
20 | | public: |
21 | | static ValueComparingNonnullRefPtr<PositionStyleValue> create(ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x, ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y) |
22 | 0 | { |
23 | 0 | return adopt_ref(*new (nothrow) PositionStyleValue(move(edge_x), move(edge_y))); |
24 | 0 | } |
25 | | static ValueComparingNonnullRefPtr<PositionStyleValue> create_center() |
26 | 0 | { |
27 | 0 | return adopt_ref(*new (nothrow) PositionStyleValue( |
28 | 0 | EdgeStyleValue::create(PositionEdge::Left, Percentage { 50 }), |
29 | 0 | EdgeStyleValue::create(PositionEdge::Top, Percentage { 50 }))); |
30 | 0 | } |
31 | 0 | virtual ~PositionStyleValue() override = default; |
32 | | |
33 | 0 | ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x() const { return m_properties.edge_x; } |
34 | 0 | ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y() const { return m_properties.edge_y; } |
35 | | bool is_center() const; |
36 | | CSSPixelPoint resolved(Layout::Node const&, CSSPixelRect const&) const; |
37 | | |
38 | | virtual String to_string() const override; |
39 | | |
40 | 0 | bool properties_equal(PositionStyleValue const& other) const { return m_properties == other.m_properties; } |
41 | | |
42 | | private: |
43 | | PositionStyleValue(ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x, ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y) |
44 | 0 | : StyleValueWithDefaultOperators(Type::Position) |
45 | 0 | , m_properties { .edge_x = edge_x, .edge_y = edge_y } |
46 | 0 | { |
47 | 0 | } |
48 | | |
49 | | struct Properties { |
50 | | ValueComparingNonnullRefPtr<EdgeStyleValue> edge_x; |
51 | | ValueComparingNonnullRefPtr<EdgeStyleValue> edge_y; |
52 | 0 | bool operator==(Properties const&) const = default; |
53 | | } m_properties; |
54 | | }; |
55 | | |
56 | | } |