Coverage Report

Created: 2025-09-05 06:52

/src/serenity/Userland/Libraries/LibWeb/CSS/Resolution.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#pragma once
8
9
#include <AK/String.h>
10
#include <LibWeb/Forward.h>
11
12
namespace Web::CSS {
13
14
class Resolution {
15
public:
16
    enum class Type {
17
        Dpi,
18
        Dpcm,
19
        Dppx,
20
    };
21
22
    static Optional<Type> unit_from_name(StringView);
23
24
    Resolution(double value, Type type);
25
    static Resolution make_dots_per_pixel(double);
26
27
    String to_string() const;
28
    double to_dots_per_pixel() const;
29
30
0
    Type type() const { return m_type; }
31
0
    double raw_value() const { return m_value; }
32
    StringView unit_name() const;
33
34
    bool operator==(Resolution const& other) const
35
0
    {
36
0
        return m_type == other.m_type && m_value == other.m_value;
37
0
    }
38
39
    int operator<=>(Resolution const& other) const
40
0
    {
41
0
        auto this_dots_per_pixel = to_dots_per_pixel();
42
0
        auto other_dots_per_pixel = other.to_dots_per_pixel();
43
0
44
0
        if (this_dots_per_pixel < other_dots_per_pixel)
45
0
            return -1;
46
0
        if (this_dots_per_pixel > other_dots_per_pixel)
47
0
            return 1;
48
0
        return 0;
49
0
    }
50
51
private:
52
    Type m_type;
53
    double m_value { 0 };
54
};
55
}