forked from LadybirdBrowser/ladybird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlex.cpp
59 lines (48 loc) · 979 Bytes
/
Flex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Flex.h"
#include <LibWeb/CSS/Percentage.h>
namespace Web::CSS {
Flex::Flex(double value, Type type)
: m_type(type)
, m_value(value)
{
}
Flex Flex::make_fr(double value)
{
return { value, Type::Fr };
}
Flex Flex::percentage_of(Percentage const& percentage) const
{
return Flex { percentage.as_fraction() * m_value, m_type };
}
String Flex::to_string() const
{
return MUST(String::formatted("{}fr", to_fr()));
}
double Flex::to_fr() const
{
switch (m_type) {
case Type::Fr:
return m_value;
}
VERIFY_NOT_REACHED();
}
StringView Flex::unit_name() const
{
switch (m_type) {
case Type::Fr:
return "fr"sv;
}
VERIFY_NOT_REACHED();
}
Optional<Flex::Type> Flex::unit_from_name(StringView name)
{
if (name.equals_ignoring_ascii_case("fr"sv))
return Type::Fr;
return {};
}
}