Serenity Operating System
1/*
2 * Copyright (c) 2022, 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
12namespace Web::CSS {
13
14class Resolution {
15public:
16 enum class Type {
17 Dpi,
18 Dpcm,
19 Dppx,
20 };
21
22 static Optional<Type> unit_from_name(StringView);
23
24 Resolution(int value, Type type);
25 Resolution(float value, Type type);
26
27 ErrorOr<String> to_string() const;
28 float to_dots_per_pixel() const;
29
30 bool operator==(Resolution const& other) const
31 {
32 return m_type == other.m_type && m_value == other.m_value;
33 }
34
35private:
36 StringView unit_name() const;
37
38 Type m_type;
39 float m_value { 0 };
40};
41}