/src/serenity/Userland/Libraries/LibWeb/CSS/StyleValues/PositionStyleValue.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "PositionStyleValue.h" |
11 | | |
12 | | namespace Web::CSS { |
13 | | |
14 | | bool PositionStyleValue::is_center() const |
15 | 0 | { |
16 | 0 | return (edge_x()->edge() == PositionEdge::Left |
17 | 0 | && edge_x()->offset().is_percentage() && edge_x()->offset().percentage() == Percentage { 50 }) |
18 | 0 | && (edge_y()->edge() == PositionEdge::Top |
19 | 0 | && edge_y()->offset().is_percentage() && edge_y()->offset().percentage() == Percentage { 50 }); |
20 | 0 | } |
21 | | |
22 | | CSSPixelPoint PositionStyleValue::resolved(Layout::Node const& node, CSSPixelRect const& rect) const |
23 | 0 | { |
24 | | // Note: A preset + a none default x/y_relative_to is impossible in the syntax (and makes little sense) |
25 | 0 | CSSPixels x = m_properties.edge_x->offset().to_px(node, rect.width()); |
26 | 0 | CSSPixels y = m_properties.edge_y->offset().to_px(node, rect.height()); |
27 | 0 | if (m_properties.edge_x->edge() == PositionEdge::Right) |
28 | 0 | x = rect.width() - x; |
29 | 0 | if (m_properties.edge_y->edge() == PositionEdge::Bottom) |
30 | 0 | y = rect.height() - y; |
31 | 0 | return CSSPixelPoint { rect.x() + x, rect.y() + y }; |
32 | 0 | } |
33 | | |
34 | | String PositionStyleValue::to_string() const |
35 | 0 | { |
36 | 0 | return MUST(String::formatted("{} {}", m_properties.edge_x->to_string(), m_properties.edge_y->to_string())); |
37 | 0 | } |
38 | | |
39 | | } |