Skip to content

Commit dadcb46

Browse files
AtkinsSJawesomekling
authored andcommitted
LibWeb: Convert CSS Dump, Selector, & SelectorEngine to east const
1 parent cd55b81 commit dadcb46

File tree

6 files changed

+57
-57
lines changed

6 files changed

+57
-57
lines changed

Userland/Libraries/LibWeb/CSS/Selector.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ u32 Selector::specificity() const
4747
return ids * 0x10000 + classes * 0x100 + tag_names;
4848
}
4949

50-
Selector::SimpleSelector::NthChildPattern Selector::SimpleSelector::NthChildPattern::parse(const StringView& args)
50+
Selector::SimpleSelector::NthChildPattern Selector::SimpleSelector::NthChildPattern::parse(StringView const& args)
5151
{
5252
CSS::Selector::SimpleSelector::NthChildPattern pattern;
5353
if (args.equals_ignoring_case("odd")) {
@@ -56,7 +56,7 @@ Selector::SimpleSelector::NthChildPattern Selector::SimpleSelector::NthChildPatt
5656
} else if (args.equals_ignoring_case("even")) {
5757
pattern.step_size = 2;
5858
} else {
59-
const auto consume_int = [](GenericLexer& lexer) -> Optional<int> {
59+
auto const consume_int = [](GenericLexer& lexer) -> Optional<int> {
6060
return AK::StringUtils::convert_to_int(lexer.consume_while([](char c) -> bool {
6161
return isdigit(c) || c == '+' || c == '-';
6262
}));
@@ -81,7 +81,7 @@ Selector::SimpleSelector::NthChildPattern Selector::SimpleSelector::NthChildPatt
8181
step_size_or_offset = -1;
8282
lexer.retreat();
8383
} else {
84-
const auto value = consume_int(lexer);
84+
auto const value = consume_int(lexer);
8585
if (!value.has_value())
8686
return {};
8787
step_size_or_offset = value.value();
@@ -90,12 +90,12 @@ Selector::SimpleSelector::NthChildPattern Selector::SimpleSelector::NthChildPatt
9090
if (lexer.consume_specific("n")) {
9191
lexer.ignore_while(isspace);
9292
if (lexer.next_is('+') || lexer.next_is('-')) {
93-
const auto sign = lexer.next_is('+') ? 1 : -1;
93+
auto const sign = lexer.next_is('+') ? 1 : -1;
9494
lexer.ignore();
9595
lexer.ignore_while(isspace);
9696

9797
// "An+B" pattern
98-
const auto offset = consume_int(lexer);
98+
auto const offset = consume_int(lexer);
9999
if (!offset.has_value())
100100
return {};
101101
pattern.step_size = step_size_or_offset;

Userland/Libraries/LibWeb/CSS/Selector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Selector {
7575
int step_size = 0;
7676
int offset = 0;
7777

78-
static NthChildPattern parse(const StringView& args);
78+
static NthChildPattern parse(StringView const& args);
7979
};
8080

8181
// FIXME: We don't need this field on every single SimpleSelector, but it's also annoying to malloc it somewhere.
@@ -103,7 +103,7 @@ class Selector {
103103
explicit Selector(Vector<ComplexSelector>&&);
104104
~Selector();
105105

106-
const Vector<ComplexSelector>& complex_selectors() const { return m_complex_selectors; }
106+
Vector<ComplexSelector> const& complex_selectors() const { return m_complex_selectors; }
107107

108108
u32 specificity() const;
109109

Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace Web::SelectorEngine {
1616

17-
static bool matches_hover_pseudo_class(const DOM::Element& element)
17+
static bool matches_hover_pseudo_class(DOM::Element const& element)
1818
{
1919
auto* hovered_node = element.document().hovered_node();
2020
if (!hovered_node)
@@ -24,7 +24,7 @@ static bool matches_hover_pseudo_class(const DOM::Element& element)
2424
return element.is_ancestor_of(*hovered_node);
2525
}
2626

27-
static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::Element& element)
27+
static bool matches(CSS::Selector::SimpleSelector const& component, DOM::Element const& element)
2828
{
2929
switch (component.pseudo_element) {
3030
case CSS::Selector::SimpleSelector::PseudoElement::None:
@@ -119,12 +119,12 @@ static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::E
119119
}
120120
case CSS::Selector::SimpleSelector::PseudoClass::NthChild:
121121
case CSS::Selector::SimpleSelector::PseudoClass::NthLastChild:
122-
const auto step_size = component.nth_child_pattern.step_size;
123-
const auto offset = component.nth_child_pattern.offset;
122+
auto const step_size = component.nth_child_pattern.step_size;
123+
auto const offset = component.nth_child_pattern.offset;
124124
if (step_size == 0 && offset == 0)
125125
return false; // "If both a and b are equal to zero, the pseudo-class represents no element in the document tree."
126126

127-
const auto* parent = element.parent_element();
127+
auto const* parent = element.parent_element();
128128
if (!parent)
129129
return false;
130130

@@ -152,7 +152,7 @@ static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::E
152152
}
153153

154154
// Like "a % b", but handles negative integers correctly.
155-
const auto canonical_modulo = [](int a, int b) -> int {
155+
auto const canonical_modulo = [](int a, int b) -> int {
156156
int c = a % b;
157157
if ((c < 0 && b > 0) || (c > 0 && b < 0)) {
158158
c += b;
@@ -218,7 +218,7 @@ static bool matches(const CSS::Selector::SimpleSelector& component, const DOM::E
218218
}
219219
}
220220

221-
static bool matches(const CSS::Selector& selector, int component_list_index, const DOM::Element& element)
221+
static bool matches(CSS::Selector const& selector, int component_list_index, DOM::Element const& element)
222222
{
223223
auto& component_list = selector.complex_selectors()[component_list_index];
224224
for (auto& component : component_list.compound_selector) {
@@ -260,7 +260,7 @@ static bool matches(const CSS::Selector& selector, int component_list_index, con
260260
VERIFY_NOT_REACHED();
261261
}
262262

263-
bool matches(const CSS::Selector& selector, const DOM::Element& element)
263+
bool matches(CSS::Selector const& selector, DOM::Element const& element)
264264
{
265265
VERIFY(!selector.complex_selectors().is_empty());
266266
return matches(selector, selector.complex_selectors().size() - 1, element);

Userland/Libraries/LibWeb/CSS/SelectorEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Web::SelectorEngine {
1313

14-
bool matches(const CSS::Selector&, const DOM::Element&);
14+
bool matches(CSS::Selector const&, DOM::Element const&);
1515

1616
}

Userland/Libraries/LibWeb/Dump.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727

2828
namespace Web {
2929

30-
void dump_tree(const DOM::Node& node)
30+
void dump_tree(DOM::Node const& node)
3131
{
3232
StringBuilder builder;
3333
dump_tree(builder, node);
3434
dbgln("{}", builder.string_view());
3535
}
3636

37-
void dump_tree(StringBuilder& builder, const DOM::Node& node)
37+
void dump_tree(StringBuilder& builder, DOM::Node const& node)
3838
{
3939
static int indent = 0;
4040
for (int i = 0; i < indent; ++i)
@@ -56,7 +56,7 @@ void dump_tree(StringBuilder& builder, const DOM::Node& node)
5656
}
5757
if (is<DOM::ParentNode>(node)) {
5858
if (!is<HTML::HTMLTemplateElement>(node)) {
59-
static_cast<const DOM::ParentNode&>(node).for_each_child([](auto& child) {
59+
static_cast<DOM::ParentNode const&>(node).for_each_child([](auto& child) {
6060
dump_tree(child);
6161
});
6262
} else {
@@ -67,14 +67,14 @@ void dump_tree(StringBuilder& builder, const DOM::Node& node)
6767
--indent;
6868
}
6969

70-
void dump_tree(const Layout::Node& layout_node, bool show_box_model, bool show_specified_style)
70+
void dump_tree(Layout::Node const& layout_node, bool show_box_model, bool show_specified_style)
7171
{
7272
StringBuilder builder;
7373
dump_tree(builder, layout_node, show_box_model, show_specified_style, true);
7474
dbgln("{}", builder.string_view());
7575
}
7676

77-
void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool show_box_model, bool show_specified_style, bool interactive)
77+
void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool show_box_model, bool show_specified_style, bool interactive)
7878
{
7979
static size_t indent = 0;
8080
for (size_t i = 0; i < indent; ++i)
@@ -104,15 +104,15 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
104104
identifier = builder.to_string();
105105
}
106106

107-
const char* nonbox_color_on = "";
108-
const char* box_color_on = "";
109-
const char* positioned_color_on = "";
110-
const char* floating_color_on = "";
111-
const char* inline_block_color_on = "";
112-
const char* line_box_color_on = "";
113-
const char* fragment_color_on = "";
114-
const char* flex_color_on = "";
115-
const char* color_off = "";
107+
char const* nonbox_color_on = "";
108+
char const* box_color_on = "";
109+
char const* positioned_color_on = "";
110+
char const* floating_color_on = "";
111+
char const* inline_block_color_on = "";
112+
char const* line_box_color_on = "";
113+
char const* fragment_color_on = "";
114+
char const* flex_color_on = "";
115+
char const* color_off = "";
116116

117117
if (interactive) {
118118
nonbox_color_on = "\033[33m";
@@ -194,8 +194,8 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
194194
builder.append("\n");
195195
}
196196

197-
if (is<Layout::BlockBox>(layout_node) && static_cast<const Layout::BlockBox&>(layout_node).children_are_inline()) {
198-
auto& block = static_cast<const Layout::BlockBox&>(layout_node);
197+
if (is<Layout::BlockBox>(layout_node) && static_cast<Layout::BlockBox const&>(layout_node).children_are_inline()) {
198+
auto& block = static_cast<Layout::BlockBox const&>(layout_node);
199199
for (size_t line_box_index = 0; line_box_index < block.line_boxes().size(); ++line_box_index) {
200200
auto& line_box = block.line_boxes()[line_box_index];
201201
for (size_t i = 0; i < indent; ++i)
@@ -223,7 +223,7 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
223223
if (is<Layout::TextNode>(fragment.layout_node())) {
224224
for (size_t i = 0; i < indent; ++i)
225225
builder.append(" ");
226-
auto& layout_text = static_cast<const Layout::TextNode&>(fragment.layout_node());
226+
auto& layout_text = static_cast<Layout::TextNode const&>(fragment.layout_node());
227227
auto fragment_text = layout_text.text_for_rendering().substring(fragment.start(), fragment.length());
228228
builder.appendff(" \"{}\"\n", fragment_text);
229229
}
@@ -256,21 +256,21 @@ void dump_tree(StringBuilder& builder, const Layout::Node& layout_node, bool sho
256256
--indent;
257257
}
258258

259-
void dump_selector(const CSS::Selector& selector)
259+
void dump_selector(CSS::Selector const& selector)
260260
{
261261
StringBuilder builder;
262262
dump_selector(builder, selector);
263263
dbgln("{}", builder.string_view());
264264
}
265265

266-
void dump_selector(StringBuilder& builder, const CSS::Selector& selector)
266+
void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
267267
{
268268
builder.append(" CSS::Selector:\n");
269269

270270
for (auto& complex_selector : selector.complex_selectors()) {
271271
builder.append(" ");
272272

273-
const char* relation_description = "";
273+
char const* relation_description = "";
274274
switch (complex_selector.relation) {
275275
case CSS::Selector::ComplexSelector::Relation::None:
276276
relation_description = "None";
@@ -297,7 +297,7 @@ void dump_selector(StringBuilder& builder, const CSS::Selector& selector)
297297

298298
for (size_t i = 0; i < complex_selector.compound_selector.size(); ++i) {
299299
auto& simple_selector = complex_selector.compound_selector[i];
300-
const char* type_description = "Unknown";
300+
char const* type_description = "Unknown";
301301
switch (simple_selector.type) {
302302
case CSS::Selector::SimpleSelector::Type::Invalid:
303303
type_description = "Invalid";
@@ -342,7 +342,7 @@ void dump_selector(StringBuilder& builder, const CSS::Selector& selector)
342342
break;
343343
}
344344

345-
const char* pseudo_class_description = "";
345+
char const* pseudo_class_description = "";
346346
switch (simple_selector.pseudo_class) {
347347
case CSS::Selector::SimpleSelector::PseudoClass::Link:
348348
pseudo_class_description = "Link";
@@ -417,34 +417,34 @@ void dump_selector(StringBuilder& builder, const CSS::Selector& selector)
417417
}
418418
}
419419

420-
void dump_rule(const CSS::CSSRule& rule)
420+
void dump_rule(CSS::CSSRule const& rule)
421421
{
422422
StringBuilder builder;
423423
dump_rule(builder, rule);
424424
dbgln("{}", builder.string_view());
425425
}
426426

427-
void dump_rule(StringBuilder& builder, const CSS::CSSRule& rule)
427+
void dump_rule(StringBuilder& builder, CSS::CSSRule const& rule)
428428
{
429429
builder.appendff("{}:\n", rule.class_name());
430430
switch (rule.type()) {
431431
case CSS::CSSRule::Type::Style:
432-
dump_style_rule(builder, verify_cast<const CSS::CSSStyleRule>(rule));
432+
dump_style_rule(builder, verify_cast<CSS::CSSStyleRule const>(rule));
433433
break;
434434
case CSS::CSSRule::Type::Import:
435-
dump_import_rule(builder, verify_cast<const CSS::CSSImportRule>(rule));
435+
dump_import_rule(builder, verify_cast<CSS::CSSImportRule const>(rule));
436436
break;
437437
default:
438438
VERIFY_NOT_REACHED();
439439
}
440440
}
441441

442-
void dump_import_rule(StringBuilder& builder, const CSS::CSSImportRule& rule)
442+
void dump_import_rule(StringBuilder& builder, CSS::CSSImportRule const& rule)
443443
{
444444
builder.appendff(" Document URL: {}\n", rule.url());
445445
}
446446

447-
void dump_style_rule(StringBuilder& builder, const CSS::CSSStyleRule& rule)
447+
void dump_style_rule(StringBuilder& builder, CSS::CSSStyleRule const& rule)
448448
{
449449
for (auto& selector : rule.selectors()) {
450450
dump_selector(builder, selector);
@@ -455,7 +455,7 @@ void dump_style_rule(StringBuilder& builder, const CSS::CSSStyleRule& rule)
455455
}
456456
}
457457

458-
void dump_sheet(const CSS::StyleSheet& sheet)
458+
void dump_sheet(CSS::StyleSheet const& sheet)
459459
{
460460
StringBuilder builder;
461461
dump_sheet(builder, sheet);

Userland/Libraries/LibWeb/Dump.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212

1313
namespace Web {
1414

15-
void dump_tree(StringBuilder&, const DOM::Node&);
16-
void dump_tree(const DOM::Node&);
17-
void dump_tree(StringBuilder&, const Layout::Node&, bool show_box_model = false, bool show_specified_style = false, bool colorize = false);
18-
void dump_tree(const Layout::Node&, bool show_box_model = false, bool show_specified_style = false);
19-
void dump_sheet(StringBuilder&, const CSS::StyleSheet&);
20-
void dump_sheet(const CSS::StyleSheet&);
21-
void dump_rule(StringBuilder&, const CSS::CSSRule&);
22-
void dump_rule(const CSS::CSSRule&);
23-
void dump_style_rule(StringBuilder&, const CSS::CSSStyleRule&);
24-
void dump_import_rule(StringBuilder&, const CSS::CSSImportRule&);
25-
void dump_selector(StringBuilder&, const CSS::Selector&);
26-
void dump_selector(const CSS::Selector&);
15+
void dump_tree(StringBuilder&, DOM::Node const&);
16+
void dump_tree(DOM::Node const&);
17+
void dump_tree(StringBuilder&, Layout::Node const&, bool show_box_model = false, bool show_specified_style = false, bool colorize = false);
18+
void dump_tree(Layout::Node const&, bool show_box_model = false, bool show_specified_style = false);
19+
void dump_sheet(StringBuilder&, CSS::StyleSheet const&);
20+
void dump_sheet(CSS::StyleSheet const&);
21+
void dump_rule(StringBuilder&, CSS::CSSRule const&);
22+
void dump_rule(CSS::CSSRule const&);
23+
void dump_style_rule(StringBuilder&, CSS::CSSStyleRule const&);
24+
void dump_import_rule(StringBuilder&, CSS::CSSImportRule const&);
25+
void dump_selector(StringBuilder&, CSS::Selector const&);
26+
void dump_selector(CSS::Selector const&);
2727

2828
}

0 commit comments

Comments
 (0)