Dump.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/QuickSort.h>
  8. #include <AK/StringBuilder.h>
  9. #include <AK/Utf8View.h>
  10. #include <LibWeb/CSS/CSSImportRule.h>
  11. #include <LibWeb/CSS/CSSMediaRule.h>
  12. #include <LibWeb/CSS/CSSRule.h>
  13. #include <LibWeb/CSS/CSSStyleRule.h>
  14. #include <LibWeb/CSS/CSSStyleSheet.h>
  15. #include <LibWeb/CSS/CSSSupportsRule.h>
  16. #include <LibWeb/CSS/PropertyID.h>
  17. #include <LibWeb/DOM/Comment.h>
  18. #include <LibWeb/DOM/Document.h>
  19. #include <LibWeb/DOM/Element.h>
  20. #include <LibWeb/DOM/ShadowRoot.h>
  21. #include <LibWeb/DOM/Text.h>
  22. #include <LibWeb/Dump.h>
  23. #include <LibWeb/HTML/HTMLTemplateElement.h>
  24. #include <LibWeb/Layout/BlockContainer.h>
  25. #include <LibWeb/Layout/Node.h>
  26. #include <LibWeb/Layout/SVGBox.h>
  27. #include <LibWeb/Layout/TextNode.h>
  28. #include <stdio.h>
  29. namespace Web {
  30. static void indent(StringBuilder& builder, int levels)
  31. {
  32. for (int i = 0; i < levels; i++)
  33. builder.append(" ");
  34. }
  35. void dump_tree(DOM::Node const& node)
  36. {
  37. StringBuilder builder;
  38. dump_tree(builder, node);
  39. dbgln("{}", builder.string_view());
  40. }
  41. void dump_tree(StringBuilder& builder, DOM::Node const& node)
  42. {
  43. static int indent = 0;
  44. for (int i = 0; i < indent; ++i)
  45. builder.append(" ");
  46. if (is<DOM::Element>(node)) {
  47. builder.appendff("<{}", verify_cast<DOM::Element>(node).local_name());
  48. verify_cast<DOM::Element>(node).for_each_attribute([&](auto& name, auto& value) {
  49. builder.appendff(" {}={}", name, value);
  50. });
  51. builder.append(">\n");
  52. } else if (is<DOM::Text>(node)) {
  53. builder.appendff("\"{}\"\n", verify_cast<DOM::Text>(node).data());
  54. } else {
  55. builder.appendff("{}\n", node.node_name());
  56. }
  57. ++indent;
  58. if (is<DOM::Element>(node) && verify_cast<DOM::Element>(node).shadow_root()) {
  59. dump_tree(builder, *verify_cast<DOM::Element>(node).shadow_root());
  60. }
  61. if (is<DOM::ParentNode>(node)) {
  62. if (!is<HTML::HTMLTemplateElement>(node)) {
  63. static_cast<DOM::ParentNode const&>(node).for_each_child([&](auto& child) {
  64. dump_tree(builder, child);
  65. });
  66. } else {
  67. auto& template_element = verify_cast<HTML::HTMLTemplateElement>(node);
  68. dump_tree(builder, template_element.content());
  69. }
  70. }
  71. --indent;
  72. }
  73. void dump_tree(Layout::Node const& layout_node, bool show_box_model, bool show_specified_style)
  74. {
  75. StringBuilder builder;
  76. dump_tree(builder, layout_node, show_box_model, show_specified_style, true);
  77. dbgln("{}", builder.string_view());
  78. }
  79. void dump_tree(StringBuilder& builder, Layout::Node const& layout_node, bool show_box_model, bool show_specified_style, bool interactive)
  80. {
  81. static size_t indent = 0;
  82. for (size_t i = 0; i < indent; ++i)
  83. builder.append(" ");
  84. FlyString tag_name;
  85. if (layout_node.is_anonymous())
  86. tag_name = "(anonymous)";
  87. else if (is<DOM::Element>(layout_node.dom_node()))
  88. tag_name = verify_cast<DOM::Element>(*layout_node.dom_node()).local_name();
  89. else
  90. tag_name = layout_node.dom_node()->node_name();
  91. String identifier = "";
  92. if (layout_node.dom_node() && is<DOM::Element>(*layout_node.dom_node())) {
  93. auto& element = verify_cast<DOM::Element>(*layout_node.dom_node());
  94. StringBuilder builder;
  95. auto id = element.attribute(HTML::AttributeNames::id);
  96. if (!id.is_empty()) {
  97. builder.append('#');
  98. builder.append(id);
  99. }
  100. for (auto& class_name : element.class_names()) {
  101. builder.append('.');
  102. builder.append(class_name);
  103. }
  104. identifier = builder.to_string();
  105. }
  106. char const* nonbox_color_on = "";
  107. char const* box_color_on = "";
  108. char const* svg_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 = "";
  116. if (interactive) {
  117. nonbox_color_on = "\033[33m";
  118. box_color_on = "\033[34m";
  119. svg_box_color_on = "\033[31m";
  120. positioned_color_on = "\033[31;1m";
  121. floating_color_on = "\033[32;1m";
  122. inline_block_color_on = "\033[36;1m";
  123. line_box_color_on = "\033[34;1m";
  124. fragment_color_on = "\033[35;1m";
  125. flex_color_on = "\033[34;1m";
  126. color_off = "\033[0m";
  127. }
  128. if (!is<Layout::Box>(layout_node)) {
  129. builder.appendff("{}{}{} <{}{}{}{}>",
  130. nonbox_color_on,
  131. layout_node.class_name().substring_view(13),
  132. color_off,
  133. tag_name,
  134. nonbox_color_on,
  135. identifier,
  136. color_off);
  137. if (interactive)
  138. builder.appendff(" @{:p}", &layout_node);
  139. builder.append("\n");
  140. } else {
  141. auto& box = verify_cast<Layout::Box>(layout_node);
  142. StringView color_on = is<Layout::SVGBox>(box) ? svg_box_color_on : box_color_on;
  143. builder.appendff("{}{}{} <{}{}{}{}> ",
  144. color_on,
  145. box.class_name().substring_view(13),
  146. color_off,
  147. color_on,
  148. tag_name,
  149. color_off,
  150. identifier.characters());
  151. if (interactive)
  152. builder.appendff("@{:p} ", &layout_node);
  153. builder.appendff("at ({},{}) size {}x{}",
  154. box.absolute_x(),
  155. box.absolute_y(),
  156. box.width(),
  157. box.height());
  158. if (box.is_positioned())
  159. builder.appendff(" {}positioned{}", positioned_color_on, color_off);
  160. if (box.is_floating())
  161. builder.appendff(" {}floating{}", floating_color_on, color_off);
  162. if (box.is_inline_block())
  163. builder.appendff(" {}inline-block{}", inline_block_color_on, color_off);
  164. if (box.computed_values().display().is_flex_inside())
  165. builder.appendff(" {}flex-container{}", flex_color_on, color_off);
  166. if (box.is_flex_item())
  167. builder.appendff(" {}flex-item{}", flex_color_on, color_off);
  168. if (show_box_model) {
  169. // Dump the horizontal box properties
  170. builder.appendff(" [{}+{}+{} {} {}+{}+{}]",
  171. box.box_model().margin.left,
  172. box.box_model().border.left,
  173. box.box_model().padding.left,
  174. box.width(),
  175. box.box_model().padding.right,
  176. box.box_model().border.right,
  177. box.box_model().margin.right);
  178. // And the vertical box properties
  179. builder.appendff(" [{}+{}+{} {} {}+{}+{}]",
  180. box.box_model().margin.top,
  181. box.box_model().border.top,
  182. box.box_model().padding.top,
  183. box.height(),
  184. box.box_model().padding.bottom,
  185. box.box_model().border.bottom,
  186. box.box_model().margin.bottom);
  187. }
  188. builder.append("\n");
  189. }
  190. if (is<Layout::BlockContainer>(layout_node) && static_cast<Layout::BlockContainer const&>(layout_node).children_are_inline()) {
  191. auto& block = static_cast<Layout::BlockContainer const&>(layout_node);
  192. for (size_t line_box_index = 0; line_box_index < block.line_boxes().size(); ++line_box_index) {
  193. auto& line_box = block.line_boxes()[line_box_index];
  194. for (size_t i = 0; i < indent; ++i)
  195. builder.append(" ");
  196. builder.appendff(" {}line {}{} width: {}\n",
  197. line_box_color_on,
  198. line_box_index,
  199. color_off,
  200. (int)line_box.width());
  201. for (size_t fragment_index = 0; fragment_index < line_box.fragments().size(); ++fragment_index) {
  202. auto& fragment = line_box.fragments()[fragment_index];
  203. for (size_t i = 0; i < indent; ++i)
  204. builder.append(" ");
  205. builder.appendff(" {}frag {}{} from {} ",
  206. fragment_color_on,
  207. fragment_index,
  208. color_off,
  209. fragment.layout_node().class_name());
  210. if (interactive)
  211. builder.appendff("@{:p}, ", &fragment.layout_node());
  212. builder.appendff("start: {}, length: {}, rect: {}\n",
  213. fragment.start(),
  214. fragment.length(),
  215. fragment.absolute_rect().to_string());
  216. if (is<Layout::TextNode>(fragment.layout_node())) {
  217. for (size_t i = 0; i < indent; ++i)
  218. builder.append(" ");
  219. auto& layout_text = static_cast<Layout::TextNode const&>(fragment.layout_node());
  220. auto fragment_text = layout_text.text_for_rendering().substring(fragment.start(), fragment.length());
  221. builder.appendff(" \"{}\"\n", fragment_text);
  222. }
  223. }
  224. }
  225. }
  226. if (show_specified_style && layout_node.dom_node() && layout_node.dom_node()->is_element() && verify_cast<DOM::Element>(layout_node.dom_node())->specified_css_values()) {
  227. struct NameAndValue {
  228. String name;
  229. String value;
  230. };
  231. Vector<NameAndValue> properties;
  232. verify_cast<DOM::Element>(*layout_node.dom_node()).specified_css_values()->for_each_property([&](auto property_id, auto& value) {
  233. properties.append({ CSS::string_from_property_id(property_id), value.to_string() });
  234. });
  235. quick_sort(properties, [](auto& a, auto& b) { return a.name < b.name; });
  236. for (auto& property : properties) {
  237. for (size_t i = 0; i < indent; ++i)
  238. builder.append(" ");
  239. builder.appendff(" ({}: {})\n", property.name, property.value);
  240. }
  241. }
  242. ++indent;
  243. layout_node.for_each_child([&](auto& child) {
  244. dump_tree(builder, child, show_box_model, show_specified_style, interactive);
  245. });
  246. --indent;
  247. }
  248. void dump_selector(CSS::Selector const& selector)
  249. {
  250. StringBuilder builder;
  251. dump_selector(builder, selector);
  252. dbgln("{}", builder.string_view());
  253. }
  254. void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
  255. {
  256. builder.append(" CSS::Selector:\n");
  257. for (auto& relative_selector : selector.compound_selectors()) {
  258. builder.append(" ");
  259. char const* relation_description = "";
  260. switch (relative_selector.combinator) {
  261. case CSS::Selector::Combinator::None:
  262. relation_description = "None";
  263. break;
  264. case CSS::Selector::Combinator::ImmediateChild:
  265. relation_description = "ImmediateChild";
  266. break;
  267. case CSS::Selector::Combinator::Descendant:
  268. relation_description = "Descendant";
  269. break;
  270. case CSS::Selector::Combinator::NextSibling:
  271. relation_description = "AdjacentSibling";
  272. break;
  273. case CSS::Selector::Combinator::SubsequentSibling:
  274. relation_description = "GeneralSibling";
  275. break;
  276. case CSS::Selector::Combinator::Column:
  277. relation_description = "Column";
  278. break;
  279. }
  280. if (*relation_description)
  281. builder.appendff("{{{}}} ", relation_description);
  282. for (size_t i = 0; i < relative_selector.simple_selectors.size(); ++i) {
  283. auto& simple_selector = relative_selector.simple_selectors[i];
  284. char const* type_description = "Unknown";
  285. switch (simple_selector.type) {
  286. case CSS::Selector::SimpleSelector::Type::Invalid:
  287. type_description = "Invalid";
  288. break;
  289. case CSS::Selector::SimpleSelector::Type::Universal:
  290. type_description = "Universal";
  291. break;
  292. case CSS::Selector::SimpleSelector::Type::Id:
  293. type_description = "Id";
  294. break;
  295. case CSS::Selector::SimpleSelector::Type::Class:
  296. type_description = "Class";
  297. break;
  298. case CSS::Selector::SimpleSelector::Type::TagName:
  299. type_description = "TagName";
  300. break;
  301. case CSS::Selector::SimpleSelector::Type::Attribute:
  302. type_description = "Attribute";
  303. break;
  304. case CSS::Selector::SimpleSelector::Type::PseudoClass:
  305. type_description = "PseudoClass";
  306. break;
  307. case CSS::Selector::SimpleSelector::Type::PseudoElement:
  308. type_description = "PseudoElement";
  309. break;
  310. }
  311. builder.appendff("{}:{}", type_description, simple_selector.value);
  312. if (simple_selector.type == CSS::Selector::SimpleSelector::Type::PseudoClass) {
  313. auto const& pseudo_class = simple_selector.pseudo_class;
  314. char const* pseudo_class_description = "";
  315. switch (pseudo_class.type) {
  316. case CSS::Selector::SimpleSelector::PseudoClass::Type::Link:
  317. pseudo_class_description = "Link";
  318. break;
  319. case CSS::Selector::SimpleSelector::PseudoClass::Type::Visited:
  320. pseudo_class_description = "Visited";
  321. break;
  322. case CSS::Selector::SimpleSelector::PseudoClass::Type::Active:
  323. pseudo_class_description = "Active";
  324. break;
  325. case CSS::Selector::SimpleSelector::PseudoClass::Type::None:
  326. pseudo_class_description = "None";
  327. break;
  328. case CSS::Selector::SimpleSelector::PseudoClass::Type::Root:
  329. pseudo_class_description = "Root";
  330. break;
  331. case CSS::Selector::SimpleSelector::PseudoClass::Type::FirstOfType:
  332. pseudo_class_description = "FirstOfType";
  333. break;
  334. case CSS::Selector::SimpleSelector::PseudoClass::Type::LastOfType:
  335. pseudo_class_description = "LastOfType";
  336. break;
  337. case CSS::Selector::SimpleSelector::PseudoClass::Type::NthChild:
  338. pseudo_class_description = "NthChild";
  339. break;
  340. case CSS::Selector::SimpleSelector::PseudoClass::Type::NthLastChild:
  341. pseudo_class_description = "NthLastChild";
  342. break;
  343. case CSS::Selector::SimpleSelector::PseudoClass::Type::Focus:
  344. pseudo_class_description = "Focus";
  345. break;
  346. case CSS::Selector::SimpleSelector::PseudoClass::Type::Empty:
  347. pseudo_class_description = "Empty";
  348. break;
  349. case CSS::Selector::SimpleSelector::PseudoClass::Type::Hover:
  350. pseudo_class_description = "Hover";
  351. break;
  352. case CSS::Selector::SimpleSelector::PseudoClass::Type::LastChild:
  353. pseudo_class_description = "LastChild";
  354. break;
  355. case CSS::Selector::SimpleSelector::PseudoClass::Type::FirstChild:
  356. pseudo_class_description = "FirstChild";
  357. break;
  358. case CSS::Selector::SimpleSelector::PseudoClass::Type::OnlyChild:
  359. pseudo_class_description = "OnlyChild";
  360. break;
  361. case CSS::Selector::SimpleSelector::PseudoClass::Type::Disabled:
  362. pseudo_class_description = "Disabled";
  363. break;
  364. case CSS::Selector::SimpleSelector::PseudoClass::Type::Enabled:
  365. pseudo_class_description = "Enabled";
  366. break;
  367. case CSS::Selector::SimpleSelector::PseudoClass::Type::Checked:
  368. pseudo_class_description = "Checked";
  369. break;
  370. case CSS::Selector::SimpleSelector::PseudoClass::Type::Not:
  371. pseudo_class_description = "Not";
  372. break;
  373. }
  374. builder.appendff(" pseudo_class={}", pseudo_class_description);
  375. if (pseudo_class.type == CSS::Selector::SimpleSelector::PseudoClass::Type::Not) {
  376. builder.append("([");
  377. for (auto& selector : pseudo_class.not_selector)
  378. dump_selector(builder, selector);
  379. builder.append("])");
  380. } else if ((pseudo_class.type == CSS::Selector::SimpleSelector::PseudoClass::Type::NthChild)
  381. || (pseudo_class.type == CSS::Selector::SimpleSelector::PseudoClass::Type::NthLastChild)) {
  382. builder.appendff("(step={}, offset={})", pseudo_class.nth_child_pattern.step_size, pseudo_class.nth_child_pattern.offset);
  383. }
  384. }
  385. if (simple_selector.type == CSS::Selector::SimpleSelector::Type::PseudoElement) {
  386. char const* pseudo_element_description = "";
  387. switch (simple_selector.pseudo_element) {
  388. case CSS::Selector::SimpleSelector::PseudoElement::None:
  389. pseudo_element_description = "NONE";
  390. break;
  391. case CSS::Selector::SimpleSelector::PseudoElement::Before:
  392. pseudo_element_description = "before";
  393. break;
  394. case CSS::Selector::SimpleSelector::PseudoElement::After:
  395. pseudo_element_description = "after";
  396. break;
  397. case CSS::Selector::SimpleSelector::PseudoElement::FirstLine:
  398. pseudo_element_description = "first-line";
  399. break;
  400. case CSS::Selector::SimpleSelector::PseudoElement::FirstLetter:
  401. pseudo_element_description = "first-letter";
  402. break;
  403. }
  404. builder.appendff(" pseudo_element={}", pseudo_element_description);
  405. }
  406. if (simple_selector.type == CSS::Selector::SimpleSelector::Type::Attribute) {
  407. char const* attribute_match_type_description = "";
  408. switch (simple_selector.attribute.match_type) {
  409. case CSS::Selector::SimpleSelector::Attribute::MatchType::None:
  410. attribute_match_type_description = "NONE";
  411. break;
  412. case CSS::Selector::SimpleSelector::Attribute::MatchType::HasAttribute:
  413. attribute_match_type_description = "HasAttribute";
  414. break;
  415. case CSS::Selector::SimpleSelector::Attribute::MatchType::ExactValueMatch:
  416. attribute_match_type_description = "ExactValueMatch";
  417. break;
  418. case CSS::Selector::SimpleSelector::Attribute::MatchType::ContainsWord:
  419. attribute_match_type_description = "ContainsWord";
  420. break;
  421. case CSS::Selector::SimpleSelector::Attribute::MatchType::ContainsString:
  422. attribute_match_type_description = "ContainsString";
  423. break;
  424. case CSS::Selector::SimpleSelector::Attribute::MatchType::StartsWithSegment:
  425. attribute_match_type_description = "StartsWithSegment";
  426. break;
  427. case CSS::Selector::SimpleSelector::Attribute::MatchType::StartsWithString:
  428. attribute_match_type_description = "StartsWithString";
  429. break;
  430. case CSS::Selector::SimpleSelector::Attribute::MatchType::EndsWithString:
  431. attribute_match_type_description = "EndsWithString";
  432. break;
  433. }
  434. builder.appendff(" [{}, name='{}', value='{}']", attribute_match_type_description, simple_selector.attribute.name, simple_selector.attribute.value);
  435. }
  436. if (i != relative_selector.simple_selectors.size() - 1)
  437. builder.append(", ");
  438. }
  439. builder.append("\n");
  440. }
  441. }
  442. void dump_rule(CSS::CSSRule const& rule)
  443. {
  444. StringBuilder builder;
  445. dump_rule(builder, rule);
  446. dbgln("{}", builder.string_view());
  447. }
  448. void dump_rule(StringBuilder& builder, CSS::CSSRule const& rule, int indent_levels)
  449. {
  450. indent(builder, indent_levels);
  451. builder.appendff("{}:\n", rule.class_name());
  452. switch (rule.type()) {
  453. case CSS::CSSRule::Type::Style:
  454. dump_style_rule(builder, verify_cast<CSS::CSSStyleRule const>(rule), indent_levels);
  455. break;
  456. case CSS::CSSRule::Type::Import:
  457. dump_import_rule(builder, verify_cast<CSS::CSSImportRule const>(rule), indent_levels);
  458. break;
  459. case CSS::CSSRule::Type::Media:
  460. dump_media_rule(builder, verify_cast<CSS::CSSMediaRule const>(rule), indent_levels);
  461. break;
  462. case CSS::CSSRule::Type::Supports:
  463. dump_supports_rule(builder, verify_cast<CSS::CSSSupportsRule const>(rule), indent_levels);
  464. break;
  465. case CSS::CSSRule::Type::__Count:
  466. VERIFY_NOT_REACHED();
  467. }
  468. }
  469. void dump_import_rule(StringBuilder& builder, CSS::CSSImportRule const& rule, int indent_levels)
  470. {
  471. indent(builder, indent_levels);
  472. builder.appendff(" Document URL: {}\n", rule.url());
  473. }
  474. void dump_media_rule(StringBuilder& builder, CSS::CSSMediaRule const& media, int indent_levels)
  475. {
  476. indent(builder, indent_levels);
  477. builder.appendff(" Media: {}\n Rules ({}):\n", media.condition_text(), media.css_rules().length());
  478. for (auto& rule : media.css_rules()) {
  479. dump_rule(builder, rule, indent_levels + 1);
  480. }
  481. }
  482. void dump_supports_rule(StringBuilder& builder, CSS::CSSSupportsRule const& supports, int indent_levels)
  483. {
  484. indent(builder, indent_levels);
  485. builder.appendff(" Supports: {}\n Rules ({}):\n", supports.condition_text(), supports.css_rules().length());
  486. for (auto& rule : supports.css_rules()) {
  487. dump_rule(builder, rule, indent_levels + 1);
  488. }
  489. }
  490. void dump_style_rule(StringBuilder& builder, CSS::CSSStyleRule const& rule, int indent_levels)
  491. {
  492. for (auto& selector : rule.selectors()) {
  493. dump_selector(builder, selector);
  494. }
  495. indent(builder, indent_levels);
  496. builder.append(" Declarations:\n");
  497. for (auto& property : verify_cast<CSS::PropertyOwningCSSStyleDeclaration>(rule.declaration()).properties()) {
  498. indent(builder, indent_levels);
  499. builder.appendff(" {}: '{}'", CSS::string_from_property_id(property.property_id), property.value->to_string());
  500. if (property.important)
  501. builder.append(" \033[31;1m!important\033[0m");
  502. builder.append('\n');
  503. }
  504. }
  505. void dump_sheet(CSS::StyleSheet const& sheet)
  506. {
  507. StringBuilder builder;
  508. dump_sheet(builder, sheet);
  509. dbgln("{}", builder.string_view());
  510. }
  511. void dump_sheet(StringBuilder& builder, CSS::StyleSheet const& sheet)
  512. {
  513. auto& css_stylesheet = verify_cast<CSS::CSSStyleSheet>(sheet);
  514. builder.appendff("CSSStyleSheet{{{}}}: {} rule(s)\n", &sheet, css_stylesheet.rules().length());
  515. for (auto& rule : css_stylesheet.rules()) {
  516. dump_rule(builder, rule);
  517. }
  518. }
  519. }