forked from LadybirdBrowser/ladybird
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay.cpp
66 lines (61 loc) · 2.6 KB
/
Display.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
60
61
62
63
64
65
66
/*
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/CSS/Display.h>
namespace Web::CSS {
String Display::to_string() const
{
StringBuilder builder;
switch (m_type) {
case Type::OutsideAndInside:
// NOTE: Following the precedence rules of “most backwards-compatible, then shortest”,
// serialization of equivalent display values uses the “Short display” column.
if (*this == Display::from_short(Display::Short::Block))
return "block"_string;
if (*this == Display::from_short(Display::Short::FlowRoot))
return "flow-root"_string;
if (*this == Display::from_short(Display::Short::Inline))
return "inline"_string;
if (*this == Display::from_short(Display::Short::InlineBlock))
return "inline-block"_string;
if (*this == Display::from_short(Display::Short::RunIn))
return "run-in"_string;
if (*this == Display::from_short(Display::Short::ListItem))
return "list-item"_string;
if (*this == Display::from_short(Display::Short::Flex))
return "flex"_string;
if (*this == Display::from_short(Display::Short::InlineFlex))
return "inline-flex"_string;
if (*this == Display::from_short(Display::Short::Grid))
return "grid"_string;
if (*this == Display::from_short(Display::Short::InlineGrid))
return "inline-grid"_string;
if (*this == Display::from_short(Display::Short::Ruby))
return "ruby"_string;
if (*this == Display::from_short(Display::Short::Table))
return "table"_string;
if (*this == Display::from_short(Display::Short::InlineTable))
return "inline-table"_string;
{
Vector<StringView, 3> parts;
if (!(m_value.outside_inside.outside == DisplayOutside::Block && m_value.outside_inside.inside == DisplayInside::FlowRoot))
parts.append(CSS::to_string(m_value.outside_inside.outside));
if (m_value.outside_inside.inside != DisplayInside::Flow)
parts.append(CSS::to_string(m_value.outside_inside.inside));
if (m_value.outside_inside.list_item == ListItem::Yes)
parts.append("list-item"sv);
builder.join(' ', parts);
}
break;
case Type::Internal:
builder.append(CSS::to_string(m_value.internal));
break;
case Type::Box:
builder.append(CSS::to_string(m_value.box));
break;
};
return MUST(builder.to_string());
}
}