Node.cpp 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. /*
  2. * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/Demangle.h>
  8. #include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
  9. #include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
  10. #include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
  11. #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
  12. #include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
  13. #include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
  14. #include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
  15. #include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
  16. #include <LibWeb/CSS/StyleValues/MathDepthStyleValue.h>
  17. #include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
  18. #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
  19. #include <LibWeb/CSS/StyleValues/RatioStyleValue.h>
  20. #include <LibWeb/CSS/StyleValues/StyleValueList.h>
  21. #include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
  22. #include <LibWeb/CSS/StyleValues/URLStyleValue.h>
  23. #include <LibWeb/DOM/Document.h>
  24. #include <LibWeb/Dump.h>
  25. #include <LibWeb/HTML/BrowsingContext.h>
  26. #include <LibWeb/HTML/HTMLHtmlElement.h>
  27. #include <LibWeb/Layout/BlockContainer.h>
  28. #include <LibWeb/Layout/FormattingContext.h>
  29. #include <LibWeb/Layout/Node.h>
  30. #include <LibWeb/Layout/TableWrapper.h>
  31. #include <LibWeb/Layout/TextNode.h>
  32. #include <LibWeb/Layout/Viewport.h>
  33. #include <LibWeb/Page/Page.h>
  34. #include <LibWeb/Painting/InlinePaintable.h>
  35. #include <LibWeb/Platform/FontPlugin.h>
  36. namespace Web::Layout {
  37. Node::Node(DOM::Document& document, DOM::Node* node)
  38. : m_dom_node(node ? *node : document)
  39. , m_browsing_context(*document.browsing_context())
  40. , m_anonymous(node == nullptr)
  41. {
  42. if (node)
  43. node->set_layout_node({}, *this);
  44. }
  45. Node::~Node() = default;
  46. void Node::visit_edges(Cell::Visitor& visitor)
  47. {
  48. Base::visit_edges(visitor);
  49. visitor.visit(m_dom_node);
  50. visitor.visit(m_paintable);
  51. visitor.visit(m_pseudo_element_generator);
  52. visitor.visit(m_browsing_context);
  53. TreeNode::visit_edges(visitor);
  54. }
  55. // https://www.w3.org/TR/css-display-3/#out-of-flow
  56. bool Node::is_out_of_flow(FormattingContext const& formatting_context) const
  57. {
  58. // A layout node is out of flow if either:
  59. // 1. It is floated (which requires that floating is not inhibited).
  60. if (!formatting_context.inhibits_floating() && computed_values().float_() != CSS::Float::None)
  61. return true;
  62. // 2. It is "absolutely positioned".
  63. if (is_absolutely_positioned())
  64. return true;
  65. return false;
  66. }
  67. bool Node::can_contain_boxes_with_position_absolute() const
  68. {
  69. if (computed_values().position() != CSS::Positioning::Static)
  70. return true;
  71. if (is<Viewport>(*this))
  72. return true;
  73. // https://w3c.github.io/csswg-drafts/css-transforms-1/#propdef-transform
  74. // Any computed value other than none for the transform affects containing block and stacking context
  75. if (!computed_values().transformations().is_empty())
  76. return true;
  77. return false;
  78. }
  79. static Box const* nearest_ancestor_capable_of_forming_a_containing_block(Node const& node)
  80. {
  81. for (auto const* ancestor = node.parent(); ancestor; ancestor = ancestor->parent()) {
  82. if (ancestor->is_block_container()
  83. || ancestor->display().is_flex_inside()
  84. || ancestor->display().is_grid_inside()
  85. || ancestor->is_svg_svg_box()) {
  86. return verify_cast<Box>(ancestor);
  87. }
  88. }
  89. return nullptr;
  90. }
  91. Box const* Node::containing_block() const
  92. {
  93. if (is<TextNode>(*this))
  94. return nearest_ancestor_capable_of_forming_a_containing_block(*this);
  95. auto position = computed_values().position();
  96. // https://drafts.csswg.org/css-position-3/#absolute-cb
  97. if (position == CSS::Positioning::Absolute) {
  98. auto const* ancestor = parent();
  99. while (ancestor && !ancestor->can_contain_boxes_with_position_absolute())
  100. ancestor = ancestor->parent();
  101. while (ancestor && ancestor->is_anonymous())
  102. ancestor = nearest_ancestor_capable_of_forming_a_containing_block(*ancestor);
  103. return static_cast<Box const*>(ancestor);
  104. }
  105. if (position == CSS::Positioning::Fixed)
  106. return &root();
  107. return nearest_ancestor_capable_of_forming_a_containing_block(*this);
  108. }
  109. Box const* Node::static_position_containing_block() const
  110. {
  111. return nearest_ancestor_capable_of_forming_a_containing_block(*this);
  112. }
  113. Box const* Node::non_anonymous_containing_block() const
  114. {
  115. auto nearest_ancestor_box = containing_block();
  116. VERIFY(nearest_ancestor_box);
  117. while (nearest_ancestor_box->is_anonymous()) {
  118. nearest_ancestor_box = nearest_ancestor_box->containing_block();
  119. VERIFY(nearest_ancestor_box);
  120. }
  121. return nearest_ancestor_box;
  122. }
  123. // https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
  124. bool Node::establishes_stacking_context() const
  125. {
  126. // NOTE: While MDN is not authoritative, there isn't a single convenient location
  127. // in the CSS specifications where the rules for stacking contexts is described.
  128. // That's why the "spec link" here points to MDN.
  129. if (!has_style())
  130. return false;
  131. // We make a stacking context for the viewport. Painting and hit testing starts from here.
  132. if (is_viewport())
  133. return true;
  134. // Root element of the document (<html>).
  135. if (is_root_element())
  136. return true;
  137. auto position = computed_values().position();
  138. // Element with a position value absolute or relative and z-index value other than auto.
  139. if (position == CSS::Positioning::Absolute || position == CSS::Positioning::Relative) {
  140. if (computed_values().z_index().has_value()) {
  141. return true;
  142. }
  143. }
  144. // Element with a position value fixed or sticky.
  145. if (position == CSS::Positioning::Fixed || position == CSS::Positioning::Sticky)
  146. return true;
  147. if (!computed_values().transformations().is_empty())
  148. return true;
  149. // Element that is a child of a flex container, with z-index value other than auto.
  150. if (parent() && parent()->display().is_flex_inside() && computed_values().z_index().has_value())
  151. return true;
  152. // Element that is a child of a grid container, with z-index value other than auto.
  153. if (parent() && parent()->display().is_grid_inside() && computed_values().z_index().has_value())
  154. return true;
  155. // https://drafts.fxtf.org/filter-effects-2/#backdrop-filter-operation
  156. // A computed value of other than none results in the creation of both a stacking context [CSS21] and a Containing Block for absolute and fixed position descendants,
  157. // unless the element it applies to is a document root element in the current browsing context.
  158. // Spec Note: This rule works in the same way as for the filter property.
  159. if (!computed_values().backdrop_filter().is_none())
  160. return true;
  161. // Element with any of the following properties with value other than none:
  162. // - transform
  163. // - filter
  164. // - backdrop-filter
  165. // - perspective
  166. // - clip-path
  167. // - mask / mask-image / mask-border
  168. if (computed_values().mask().has_value() || computed_values().clip_path().has_value())
  169. return true;
  170. return computed_values().opacity() < 1.0f;
  171. }
  172. HTML::BrowsingContext const& Node::browsing_context() const
  173. {
  174. return *m_browsing_context;
  175. }
  176. HTML::BrowsingContext& Node::browsing_context()
  177. {
  178. return *m_browsing_context;
  179. }
  180. JS::GCPtr<HTML::Navigable> Node::navigable() const
  181. {
  182. return document().navigable();
  183. }
  184. Viewport const& Node::root() const
  185. {
  186. VERIFY(document().layout_node());
  187. return *document().layout_node();
  188. }
  189. Viewport& Node::root()
  190. {
  191. VERIFY(document().layout_node());
  192. return *document().layout_node();
  193. }
  194. bool Node::is_floating() const
  195. {
  196. if (!has_style())
  197. return false;
  198. // flex-items don't float.
  199. if (is_flex_item())
  200. return false;
  201. return computed_values().float_() != CSS::Float::None;
  202. }
  203. bool Node::is_positioned() const
  204. {
  205. return has_style() && computed_values().position() != CSS::Positioning::Static;
  206. }
  207. bool Node::is_absolutely_positioned() const
  208. {
  209. if (!has_style())
  210. return false;
  211. auto position = computed_values().position();
  212. return position == CSS::Positioning::Absolute || position == CSS::Positioning::Fixed;
  213. }
  214. bool Node::is_fixed_position() const
  215. {
  216. if (!has_style())
  217. return false;
  218. auto position = computed_values().position();
  219. return position == CSS::Positioning::Fixed;
  220. }
  221. NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> computed_style)
  222. : Node(document, node)
  223. , m_computed_values(make<CSS::ComputedValues>())
  224. {
  225. m_has_style = true;
  226. apply_style(*computed_style);
  227. }
  228. NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, NonnullOwnPtr<CSS::ComputedValues> computed_values)
  229. : Node(document, node)
  230. , m_computed_values(move(computed_values))
  231. {
  232. m_has_style = true;
  233. }
  234. void NodeWithStyle::visit_edges(Visitor& visitor)
  235. {
  236. Base::visit_edges(visitor);
  237. for (auto& layer : computed_values().background_layers()) {
  238. if (layer.background_image && layer.background_image->is_image())
  239. layer.background_image->as_image().visit_edges(visitor);
  240. }
  241. if (m_list_style_image && m_list_style_image->is_image())
  242. m_list_style_image->as_image().visit_edges(visitor);
  243. }
  244. // https://www.w3.org/TR/css-values-4/#snap-a-length-as-a-border-width
  245. static CSSPixels snap_a_length_as_a_border_width(double device_pixels_per_css_pixel, CSSPixels length)
  246. {
  247. // 1. Assert: len is non-negative.
  248. VERIFY(length >= 0);
  249. // 2. If len is an integer number of device pixels, do nothing.
  250. auto device_pixels = length.to_double() * device_pixels_per_css_pixel;
  251. if (device_pixels == trunc(device_pixels))
  252. return length;
  253. // 3. If len is greater than zero, but less than 1 device pixel, round len up to 1 device pixel.
  254. if (device_pixels > 0 && device_pixels < 1)
  255. return CSSPixels::nearest_value_for(1 / device_pixels_per_css_pixel);
  256. // 4. If len is greater than 1 device pixel, round it down to the nearest integer number of device pixels.
  257. if (device_pixels > 1)
  258. return CSSPixels::nearest_value_for(floor(device_pixels) / device_pixels_per_css_pixel);
  259. return length;
  260. }
  261. void NodeWithStyle::apply_style(const CSS::StyleProperties& computed_style)
  262. {
  263. auto& computed_values = mutable_computed_values();
  264. // NOTE: color must be set first to ensure currentColor can be resolved in other properties (e.g. background-color).
  265. computed_values.set_color(computed_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color()));
  266. // NOTE: We have to be careful that font-related properties get set in the right order.
  267. // m_font is used by Length::to_px() when resolving sizes against this layout node.
  268. // That's why it has to be set before everything else.
  269. computed_values.set_font_list(computed_style.computed_font_list());
  270. computed_values.set_font_size(computed_style.property(CSS::PropertyID::FontSize)->as_length().length().to_px(*this));
  271. computed_values.set_font_weight(round_to<int>(computed_style.property(CSS::PropertyID::FontWeight)->as_number().number()));
  272. computed_values.set_line_height(computed_style.line_height());
  273. computed_values.set_vertical_align(computed_style.vertical_align());
  274. {
  275. auto attachments = computed_style.property(CSS::PropertyID::BackgroundAttachment);
  276. auto clips = computed_style.property(CSS::PropertyID::BackgroundClip);
  277. auto images = computed_style.property(CSS::PropertyID::BackgroundImage);
  278. auto origins = computed_style.property(CSS::PropertyID::BackgroundOrigin);
  279. auto x_positions = computed_style.property(CSS::PropertyID::BackgroundPositionX);
  280. auto y_positions = computed_style.property(CSS::PropertyID::BackgroundPositionY);
  281. auto repeats = computed_style.property(CSS::PropertyID::BackgroundRepeat);
  282. auto sizes = computed_style.property(CSS::PropertyID::BackgroundSize);
  283. auto count_layers = [](auto maybe_style_value) -> size_t {
  284. if (maybe_style_value->is_value_list())
  285. return maybe_style_value->as_value_list().size();
  286. else
  287. return 1;
  288. };
  289. auto value_for_layer = [](auto& style_value, size_t layer_index) -> RefPtr<CSS::StyleValue const> {
  290. if (style_value->is_value_list())
  291. return style_value->as_value_list().value_at(layer_index, true);
  292. return style_value;
  293. };
  294. size_t layer_count = 1;
  295. layer_count = max(layer_count, count_layers(attachments));
  296. layer_count = max(layer_count, count_layers(clips));
  297. layer_count = max(layer_count, count_layers(images));
  298. layer_count = max(layer_count, count_layers(origins));
  299. layer_count = max(layer_count, count_layers(x_positions));
  300. layer_count = max(layer_count, count_layers(y_positions));
  301. layer_count = max(layer_count, count_layers(repeats));
  302. layer_count = max(layer_count, count_layers(sizes));
  303. Vector<CSS::BackgroundLayerData> layers;
  304. layers.ensure_capacity(layer_count);
  305. for (size_t layer_index = 0; layer_index < layer_count; layer_index++) {
  306. CSS::BackgroundLayerData layer;
  307. if (auto image_value = value_for_layer(images, layer_index); image_value) {
  308. if (image_value->is_abstract_image()) {
  309. layer.background_image = image_value->as_abstract_image();
  310. const_cast<CSS::AbstractImageStyleValue&>(*layer.background_image).load_any_resources(document());
  311. }
  312. }
  313. if (auto attachment_value = value_for_layer(attachments, layer_index); attachment_value && attachment_value->is_identifier()) {
  314. switch (attachment_value->to_identifier()) {
  315. case CSS::ValueID::Fixed:
  316. layer.attachment = CSS::BackgroundAttachment::Fixed;
  317. break;
  318. case CSS::ValueID::Local:
  319. layer.attachment = CSS::BackgroundAttachment::Local;
  320. break;
  321. case CSS::ValueID::Scroll:
  322. layer.attachment = CSS::BackgroundAttachment::Scroll;
  323. break;
  324. default:
  325. break;
  326. }
  327. }
  328. auto as_box = [](auto value_id) {
  329. switch (value_id) {
  330. case CSS::ValueID::BorderBox:
  331. return CSS::BackgroundBox::BorderBox;
  332. case CSS::ValueID::ContentBox:
  333. return CSS::BackgroundBox::ContentBox;
  334. case CSS::ValueID::PaddingBox:
  335. return CSS::BackgroundBox::PaddingBox;
  336. case CSS::ValueID::Text:
  337. return CSS::BackgroundBox::Text;
  338. default:
  339. VERIFY_NOT_REACHED();
  340. }
  341. };
  342. if (auto origin_value = value_for_layer(origins, layer_index); origin_value && origin_value->is_identifier()) {
  343. layer.origin = as_box(origin_value->to_identifier());
  344. }
  345. if (auto clip_value = value_for_layer(clips, layer_index); clip_value && clip_value->is_identifier()) {
  346. layer.clip = as_box(clip_value->to_identifier());
  347. }
  348. if (auto position_value = value_for_layer(x_positions, layer_index); position_value && position_value->is_edge()) {
  349. auto& position = position_value->as_edge();
  350. layer.position_edge_x = position.edge();
  351. layer.position_offset_x = position.offset();
  352. }
  353. if (auto position_value = value_for_layer(y_positions, layer_index); position_value && position_value->is_edge()) {
  354. auto& position = position_value->as_edge();
  355. layer.position_edge_y = position.edge();
  356. layer.position_offset_y = position.offset();
  357. };
  358. if (auto size_value = value_for_layer(sizes, layer_index); size_value) {
  359. if (size_value->is_background_size()) {
  360. auto& size = size_value->as_background_size();
  361. layer.size_type = CSS::BackgroundSize::LengthPercentage;
  362. layer.size_x = size.size_x();
  363. layer.size_y = size.size_y();
  364. } else if (size_value->is_identifier()) {
  365. switch (size_value->to_identifier()) {
  366. case CSS::ValueID::Contain:
  367. layer.size_type = CSS::BackgroundSize::Contain;
  368. break;
  369. case CSS::ValueID::Cover:
  370. layer.size_type = CSS::BackgroundSize::Cover;
  371. break;
  372. default:
  373. break;
  374. }
  375. }
  376. }
  377. if (auto repeat_value = value_for_layer(repeats, layer_index); repeat_value && repeat_value->is_background_repeat()) {
  378. layer.repeat_x = repeat_value->as_background_repeat().repeat_x();
  379. layer.repeat_y = repeat_value->as_background_repeat().repeat_y();
  380. }
  381. layers.append(move(layer));
  382. }
  383. computed_values.set_background_layers(move(layers));
  384. }
  385. computed_values.set_background_color(computed_style.color_or_fallback(CSS::PropertyID::BackgroundColor, *this, CSS::InitialValues::background_color()));
  386. if (auto box_sizing = computed_style.box_sizing(); box_sizing.has_value())
  387. computed_values.set_box_sizing(box_sizing.release_value());
  388. if (auto maybe_font_variant = computed_style.font_variant(); maybe_font_variant.has_value())
  389. computed_values.set_font_variant(maybe_font_variant.release_value());
  390. // FIXME: BorderXRadius properties are now BorderRadiusStyleValues, so make use of that.
  391. auto border_bottom_left_radius = computed_style.property(CSS::PropertyID::BorderBottomLeftRadius);
  392. if (border_bottom_left_radius->is_border_radius()) {
  393. computed_values.set_border_bottom_left_radius(
  394. CSS::BorderRadiusData {
  395. border_bottom_left_radius->as_border_radius().horizontal_radius(),
  396. border_bottom_left_radius->as_border_radius().vertical_radius() });
  397. }
  398. auto border_bottom_right_radius = computed_style.property(CSS::PropertyID::BorderBottomRightRadius);
  399. if (border_bottom_right_radius->is_border_radius()) {
  400. computed_values.set_border_bottom_right_radius(
  401. CSS::BorderRadiusData {
  402. border_bottom_right_radius->as_border_radius().horizontal_radius(),
  403. border_bottom_right_radius->as_border_radius().vertical_radius() });
  404. }
  405. auto border_top_left_radius = computed_style.property(CSS::PropertyID::BorderTopLeftRadius);
  406. if (border_top_left_radius->is_border_radius()) {
  407. computed_values.set_border_top_left_radius(
  408. CSS::BorderRadiusData {
  409. border_top_left_radius->as_border_radius().horizontal_radius(),
  410. border_top_left_radius->as_border_radius().vertical_radius() });
  411. }
  412. auto border_top_right_radius = computed_style.property(CSS::PropertyID::BorderTopRightRadius);
  413. if (border_top_right_radius->is_border_radius()) {
  414. computed_values.set_border_top_right_radius(
  415. CSS::BorderRadiusData {
  416. border_top_right_radius->as_border_radius().horizontal_radius(),
  417. border_top_right_radius->as_border_radius().vertical_radius() });
  418. }
  419. computed_values.set_display(computed_style.display());
  420. auto flex_direction = computed_style.flex_direction();
  421. if (flex_direction.has_value())
  422. computed_values.set_flex_direction(flex_direction.value());
  423. auto flex_wrap = computed_style.flex_wrap();
  424. if (flex_wrap.has_value())
  425. computed_values.set_flex_wrap(flex_wrap.value());
  426. auto flex_basis = computed_style.flex_basis();
  427. if (flex_basis.has_value())
  428. computed_values.set_flex_basis(flex_basis.value());
  429. computed_values.set_flex_grow(computed_style.flex_grow());
  430. computed_values.set_flex_shrink(computed_style.flex_shrink());
  431. computed_values.set_order(computed_style.order());
  432. computed_values.set_clip(computed_style.clip());
  433. if (computed_style.backdrop_filter().has_filters()) {
  434. CSS::ResolvedBackdropFilter resolved_backdrop_filter;
  435. for (auto& filter : computed_style.backdrop_filter().filters()) {
  436. filter.visit(
  437. [&](CSS::Filter::Blur const& blur) {
  438. resolved_backdrop_filter.filters.append(CSS::ResolvedBackdropFilter::Blur {
  439. .radius = blur.resolved_radius(*this) });
  440. },
  441. [&](CSS::Filter::DropShadow const& drop_shadow) {
  442. // The default value for omitted values is missing length values set to 0
  443. // and the missing used color is taken from the color property.
  444. resolved_backdrop_filter.filters.append(CSS::ResolvedBackdropFilter::DropShadow {
  445. .offset_x = drop_shadow.offset_x.to_px(*this).to_double(),
  446. .offset_y = drop_shadow.offset_y.to_px(*this).to_double(),
  447. .radius = drop_shadow.radius.has_value() ? drop_shadow.radius->to_px(*this).to_double() : 0.0,
  448. .color = drop_shadow.color.has_value() ? *drop_shadow.color : this->computed_values().color() });
  449. },
  450. [&](CSS::Filter::Color const& color_operation) {
  451. resolved_backdrop_filter.filters.append(CSS::ResolvedBackdropFilter::ColorOperation {
  452. .operation = color_operation.operation,
  453. .amount = color_operation.resolved_amount() });
  454. },
  455. [&](CSS::Filter::HueRotate const& hue_rotate) {
  456. resolved_backdrop_filter.filters.append(CSS::ResolvedBackdropFilter::HueRotate { .angle_degrees = hue_rotate.angle_degrees() });
  457. });
  458. }
  459. computed_values.set_backdrop_filter(resolved_backdrop_filter);
  460. }
  461. auto justify_content = computed_style.justify_content();
  462. if (justify_content.has_value())
  463. computed_values.set_justify_content(justify_content.value());
  464. auto justify_items = computed_style.justify_items();
  465. if (justify_items.has_value())
  466. computed_values.set_justify_items(justify_items.value());
  467. auto justify_self = computed_style.justify_self();
  468. if (justify_self.has_value())
  469. computed_values.set_justify_self(justify_self.value());
  470. auto accent_color = computed_style.accent_color(*this);
  471. if (accent_color.has_value())
  472. computed_values.set_accent_color(accent_color.value());
  473. auto align_content = computed_style.align_content();
  474. if (align_content.has_value())
  475. computed_values.set_align_content(align_content.value());
  476. auto align_items = computed_style.align_items();
  477. if (align_items.has_value())
  478. computed_values.set_align_items(align_items.value());
  479. auto align_self = computed_style.align_self();
  480. if (align_self.has_value())
  481. computed_values.set_align_self(align_self.value());
  482. auto appearance = computed_style.appearance();
  483. if (appearance.has_value())
  484. computed_values.set_appearance(appearance.value());
  485. auto position = computed_style.position();
  486. if (position.has_value())
  487. computed_values.set_position(position.value());
  488. auto text_align = computed_style.text_align();
  489. if (text_align.has_value())
  490. computed_values.set_text_align(text_align.value());
  491. auto text_justify = computed_style.text_justify();
  492. if (text_align.has_value())
  493. computed_values.set_text_justify(text_justify.value());
  494. if (auto text_indent = computed_style.length_percentage(CSS::PropertyID::TextIndent); text_indent.has_value())
  495. computed_values.set_text_indent(text_indent.release_value());
  496. if (auto text_overflow = computed_style.text_overflow(); text_overflow.has_value())
  497. computed_values.set_text_overflow(text_overflow.release_value());
  498. auto white_space = computed_style.white_space();
  499. if (white_space.has_value())
  500. computed_values.set_white_space(white_space.value());
  501. auto float_ = computed_style.float_();
  502. if (float_.has_value())
  503. computed_values.set_float(float_.value());
  504. computed_values.set_border_spacing_horizontal(computed_style.border_spacing_horizontal());
  505. computed_values.set_border_spacing_vertical(computed_style.border_spacing_vertical());
  506. auto caption_side = computed_style.caption_side();
  507. if (caption_side.has_value())
  508. computed_values.set_caption_side(caption_side.value());
  509. auto clear = computed_style.clear();
  510. if (clear.has_value())
  511. computed_values.set_clear(clear.value());
  512. auto overflow_x = computed_style.overflow_x();
  513. if (overflow_x.has_value())
  514. computed_values.set_overflow_x(overflow_x.value());
  515. auto overflow_y = computed_style.overflow_y();
  516. if (overflow_y.has_value())
  517. computed_values.set_overflow_y(overflow_y.value());
  518. auto content_visibility = computed_style.content_visibility();
  519. if (content_visibility.has_value())
  520. computed_values.set_content_visibility(content_visibility.value());
  521. auto cursor = computed_style.cursor();
  522. if (cursor.has_value())
  523. computed_values.set_cursor(cursor.value());
  524. auto image_rendering = computed_style.image_rendering();
  525. if (image_rendering.has_value())
  526. computed_values.set_image_rendering(image_rendering.value());
  527. auto pointer_events = computed_style.pointer_events();
  528. if (pointer_events.has_value())
  529. computed_values.set_pointer_events(pointer_events.value());
  530. computed_values.set_text_decoration_line(computed_style.text_decoration_line());
  531. auto text_decoration_style = computed_style.text_decoration_style();
  532. if (text_decoration_style.has_value())
  533. computed_values.set_text_decoration_style(text_decoration_style.value());
  534. auto text_transform = computed_style.text_transform();
  535. if (text_transform.has_value())
  536. computed_values.set_text_transform(text_transform.value());
  537. if (auto list_style_type = computed_style.list_style_type(); list_style_type.has_value())
  538. computed_values.set_list_style_type(list_style_type.value());
  539. auto list_style_image = computed_style.property(CSS::PropertyID::ListStyleImage);
  540. if (list_style_image->is_abstract_image()) {
  541. m_list_style_image = list_style_image->as_abstract_image();
  542. const_cast<CSS::AbstractImageStyleValue&>(*m_list_style_image).load_any_resources(document());
  543. }
  544. if (auto list_style_position = computed_style.list_style_position(); list_style_position.has_value())
  545. computed_values.set_list_style_position(list_style_position.value());
  546. // FIXME: The default text decoration color value is `currentcolor`, but since we can't resolve that easily,
  547. // we just manually grab the value from `color`. This makes it dependent on `color` being
  548. // specified first, so it's far from ideal.
  549. computed_values.set_text_decoration_color(computed_style.color_or_fallback(CSS::PropertyID::TextDecorationColor, *this, computed_values.color()));
  550. if (auto maybe_text_decoration_thickness = computed_style.length_percentage(CSS::PropertyID::TextDecorationThickness); maybe_text_decoration_thickness.has_value())
  551. computed_values.set_text_decoration_thickness(maybe_text_decoration_thickness.release_value());
  552. computed_values.set_webkit_text_fill_color(computed_style.color_or_fallback(CSS::PropertyID::WebkitTextFillColor, *this, computed_values.color()));
  553. computed_values.set_text_shadow(computed_style.text_shadow(*this));
  554. computed_values.set_z_index(computed_style.z_index());
  555. computed_values.set_opacity(computed_style.opacity());
  556. if (auto maybe_visibility = computed_style.visibility(); maybe_visibility.has_value())
  557. computed_values.set_visibility(maybe_visibility.release_value());
  558. computed_values.set_width(computed_style.size_value(CSS::PropertyID::Width));
  559. computed_values.set_min_width(computed_style.size_value(CSS::PropertyID::MinWidth));
  560. computed_values.set_max_width(computed_style.size_value(CSS::PropertyID::MaxWidth));
  561. computed_values.set_height(computed_style.size_value(CSS::PropertyID::Height));
  562. computed_values.set_min_height(computed_style.size_value(CSS::PropertyID::MinHeight));
  563. computed_values.set_max_height(computed_style.size_value(CSS::PropertyID::MaxHeight));
  564. computed_values.set_inset(computed_style.length_box(CSS::PropertyID::Left, CSS::PropertyID::Top, CSS::PropertyID::Right, CSS::PropertyID::Bottom, CSS::Length::make_auto()));
  565. computed_values.set_margin(computed_style.length_box(CSS::PropertyID::MarginLeft, CSS::PropertyID::MarginTop, CSS::PropertyID::MarginRight, CSS::PropertyID::MarginBottom, CSS::Length::make_px(0)));
  566. computed_values.set_padding(computed_style.length_box(CSS::PropertyID::PaddingLeft, CSS::PropertyID::PaddingTop, CSS::PropertyID::PaddingRight, CSS::PropertyID::PaddingBottom, CSS::Length::make_px(0)));
  567. computed_values.set_box_shadow(computed_style.box_shadow(*this));
  568. computed_values.set_transformations(computed_style.transformations());
  569. if (auto transform_box = computed_style.transform_box(); transform_box.has_value())
  570. computed_values.set_transform_box(transform_box.value());
  571. computed_values.set_transform_origin(computed_style.transform_origin());
  572. auto transition_delay_property = computed_style.property(CSS::PropertyID::TransitionDelay);
  573. if (transition_delay_property->is_time()) {
  574. auto& transition_delay = transition_delay_property->as_time();
  575. computed_values.set_transition_delay(transition_delay.time());
  576. } else if (transition_delay_property->is_calculated()) {
  577. auto& transition_delay = transition_delay_property->as_calculated();
  578. computed_values.set_transition_delay(transition_delay.resolve_time().value());
  579. }
  580. auto do_border_style = [&](CSS::BorderData& border, CSS::PropertyID width_property, CSS::PropertyID color_property, CSS::PropertyID style_property) {
  581. // FIXME: The default border color value is `currentcolor`, but since we can't resolve that easily,
  582. // we just manually grab the value from `color`. This makes it dependent on `color` being
  583. // specified first, so it's far from ideal.
  584. border.color = computed_style.color_or_fallback(color_property, *this, computed_values.color());
  585. border.line_style = computed_style.line_style(style_property).value_or(CSS::LineStyle::None);
  586. // https://w3c.github.io/csswg-drafts/css-backgrounds/#border-style
  587. // none
  588. // No border. Color and width are ignored (i.e., the border has width 0). Note this means that the initial value of border-image-width will also resolve to zero.
  589. // hidden
  590. // Same as none, but has different behavior in the border conflict resolution rules for border-collapsed tables [CSS2].
  591. if (border.line_style == CSS::LineStyle::None || border.line_style == CSS::LineStyle::Hidden) {
  592. border.width = 0;
  593. } else {
  594. auto resolve_border_width = [&]() -> CSSPixels {
  595. auto value = computed_style.property(width_property);
  596. if (value->is_calculated())
  597. return max(CSSPixels { 0 }, value->as_calculated().resolve_length(*this)->to_px(*this));
  598. if (value->is_length())
  599. return value->as_length().length().to_px(*this);
  600. if (value->is_identifier()) {
  601. // https://www.w3.org/TR/css-backgrounds-3/#valdef-line-width-thin
  602. switch (value->to_identifier()) {
  603. case CSS::ValueID::Thin:
  604. return 1;
  605. case CSS::ValueID::Medium:
  606. return 3;
  607. case CSS::ValueID::Thick:
  608. return 5;
  609. default:
  610. VERIFY_NOT_REACHED();
  611. }
  612. }
  613. VERIFY_NOT_REACHED();
  614. };
  615. border.width = snap_a_length_as_a_border_width(document().page().client().device_pixels_per_css_pixel(), resolve_border_width());
  616. }
  617. };
  618. do_border_style(computed_values.border_left(), CSS::PropertyID::BorderLeftWidth, CSS::PropertyID::BorderLeftColor, CSS::PropertyID::BorderLeftStyle);
  619. do_border_style(computed_values.border_top(), CSS::PropertyID::BorderTopWidth, CSS::PropertyID::BorderTopColor, CSS::PropertyID::BorderTopStyle);
  620. do_border_style(computed_values.border_right(), CSS::PropertyID::BorderRightWidth, CSS::PropertyID::BorderRightColor, CSS::PropertyID::BorderRightStyle);
  621. do_border_style(computed_values.border_bottom(), CSS::PropertyID::BorderBottomWidth, CSS::PropertyID::BorderBottomColor, CSS::PropertyID::BorderBottomStyle);
  622. if (auto outline_color = computed_style.property(CSS::PropertyID::OutlineColor); outline_color->has_color())
  623. computed_values.set_outline_color(outline_color->to_color(*this));
  624. if (auto outline_offset = computed_style.property(CSS::PropertyID::OutlineOffset); outline_offset->is_length())
  625. computed_values.set_outline_offset(outline_offset->as_length().length());
  626. if (auto outline_style = computed_style.outline_style(); outline_style.has_value())
  627. computed_values.set_outline_style(outline_style.value());
  628. if (auto outline_width = computed_style.property(CSS::PropertyID::OutlineWidth); outline_width->is_length())
  629. computed_values.set_outline_width(outline_width->as_length().length());
  630. computed_values.set_grid_auto_columns(computed_style.grid_auto_columns());
  631. computed_values.set_grid_auto_rows(computed_style.grid_auto_rows());
  632. computed_values.set_grid_template_columns(computed_style.grid_template_columns());
  633. computed_values.set_grid_template_rows(computed_style.grid_template_rows());
  634. computed_values.set_grid_column_end(computed_style.grid_column_end());
  635. computed_values.set_grid_column_start(computed_style.grid_column_start());
  636. computed_values.set_grid_row_end(computed_style.grid_row_end());
  637. computed_values.set_grid_row_start(computed_style.grid_row_start());
  638. computed_values.set_grid_template_areas(computed_style.grid_template_areas());
  639. computed_values.set_grid_auto_flow(computed_style.grid_auto_flow());
  640. if (auto cx_value = computed_style.length_percentage(CSS::PropertyID::Cx); cx_value.has_value())
  641. computed_values.set_cx(*cx_value);
  642. if (auto cy_value = computed_style.length_percentage(CSS::PropertyID::Cy); cy_value.has_value())
  643. computed_values.set_cy(*cy_value);
  644. if (auto r_value = computed_style.length_percentage(CSS::PropertyID::R); r_value.has_value())
  645. computed_values.set_r(*r_value);
  646. if (auto rx_value = computed_style.length_percentage(CSS::PropertyID::Rx); rx_value.has_value())
  647. computed_values.set_rx(*rx_value);
  648. if (auto ry_value = computed_style.length_percentage(CSS::PropertyID::Ry); ry_value.has_value())
  649. computed_values.set_ry(*ry_value);
  650. if (auto x_value = computed_style.length_percentage(CSS::PropertyID::X); x_value.has_value())
  651. computed_values.set_x(*x_value);
  652. if (auto y_value = computed_style.length_percentage(CSS::PropertyID::Y); y_value.has_value())
  653. computed_values.set_y(*y_value);
  654. auto fill = computed_style.property(CSS::PropertyID::Fill);
  655. if (fill->has_color())
  656. computed_values.set_fill(fill->to_color(*this));
  657. else if (fill->is_url())
  658. computed_values.set_fill(fill->as_url().url());
  659. auto stroke = computed_style.property(CSS::PropertyID::Stroke);
  660. if (stroke->has_color())
  661. computed_values.set_stroke(stroke->to_color(*this));
  662. else if (stroke->is_url())
  663. computed_values.set_stroke(stroke->as_url().url());
  664. if (auto stop_color = computed_style.property(CSS::PropertyID::StopColor); stop_color->has_color())
  665. computed_values.set_stop_color(stop_color->to_color(*this));
  666. auto stroke_width = computed_style.property(CSS::PropertyID::StrokeWidth);
  667. // FIXME: Converting to pixels isn't really correct - values should be in "user units"
  668. // https://svgwg.org/svg2-draft/coords.html#TermUserUnits
  669. if (stroke_width->is_number())
  670. computed_values.set_stroke_width(CSS::Length::make_px(CSSPixels::nearest_value_for(stroke_width->as_number().number())));
  671. else if (stroke_width->is_length())
  672. computed_values.set_stroke_width(stroke_width->as_length().length());
  673. else if (stroke_width->is_percentage())
  674. computed_values.set_stroke_width(CSS::LengthPercentage { stroke_width->as_percentage().percentage() });
  675. if (auto mask_type = computed_style.mask_type(); mask_type.has_value())
  676. computed_values.set_mask_type(*mask_type);
  677. if (auto mask = computed_style.property(CSS::PropertyID::Mask); mask->is_url())
  678. computed_values.set_mask(mask->as_url().url());
  679. auto clip_path = computed_style.property(CSS::PropertyID::ClipPath);
  680. if (clip_path->is_url())
  681. computed_values.set_clip_path(clip_path->as_url().url());
  682. else if (clip_path->is_basic_shape())
  683. computed_values.set_clip_path(clip_path->as_basic_shape());
  684. if (auto clip_rule = computed_style.clip_rule(); clip_rule.has_value())
  685. computed_values.set_clip_rule(*clip_rule);
  686. if (auto fill_rule = computed_style.fill_rule(); fill_rule.has_value())
  687. computed_values.set_fill_rule(*fill_rule);
  688. computed_values.set_fill_opacity(computed_style.fill_opacity());
  689. computed_values.set_stroke_opacity(computed_style.stroke_opacity());
  690. computed_values.set_stop_opacity(computed_style.stop_opacity());
  691. if (auto text_anchor = computed_style.text_anchor(); text_anchor.has_value())
  692. computed_values.set_text_anchor(*text_anchor);
  693. if (auto column_count = computed_style.property(CSS::PropertyID::ColumnCount); column_count->is_integer())
  694. computed_values.set_column_count(CSS::ColumnCount::make_integer(column_count->as_integer().integer()));
  695. computed_values.set_column_gap(computed_style.size_value(CSS::PropertyID::ColumnGap));
  696. computed_values.set_row_gap(computed_style.size_value(CSS::PropertyID::RowGap));
  697. if (auto border_collapse = computed_style.border_collapse(); border_collapse.has_value())
  698. computed_values.set_border_collapse(border_collapse.value());
  699. if (auto table_layout = computed_style.table_layout(); table_layout.has_value())
  700. computed_values.set_table_layout(table_layout.value());
  701. auto aspect_ratio = computed_style.property(CSS::PropertyID::AspectRatio);
  702. if (aspect_ratio->is_value_list()) {
  703. auto& values_list = aspect_ratio->as_value_list().values();
  704. if (values_list.size() == 2
  705. && values_list[0]->is_identifier() && values_list[0]->as_identifier().id() == CSS::ValueID::Auto
  706. && values_list[1]->is_ratio()) {
  707. computed_values.set_aspect_ratio({ true, values_list[1]->as_ratio().ratio() });
  708. }
  709. } else if (aspect_ratio->is_identifier() && aspect_ratio->as_identifier().id() == CSS::ValueID::Auto) {
  710. computed_values.set_aspect_ratio({ true, {} });
  711. } else if (aspect_ratio->is_ratio()) {
  712. computed_values.set_aspect_ratio({ false, aspect_ratio->as_ratio().ratio() });
  713. }
  714. auto math_shift_value = computed_style.property(CSS::PropertyID::MathShift);
  715. if (auto math_shift = value_id_to_math_shift(math_shift_value->to_identifier()); math_shift.has_value())
  716. computed_values.set_math_shift(math_shift.value());
  717. auto math_style_value = computed_style.property(CSS::PropertyID::MathStyle);
  718. if (auto math_style = value_id_to_math_style(math_style_value->to_identifier()); math_style.has_value())
  719. computed_values.set_math_style(math_style.value());
  720. computed_values.set_math_depth(computed_style.math_depth());
  721. computed_values.set_quotes(computed_style.quotes());
  722. computed_values.set_counter_increment(computed_style.counter_data(CSS::PropertyID::CounterIncrement));
  723. computed_values.set_counter_reset(computed_style.counter_data(CSS::PropertyID::CounterReset));
  724. computed_values.set_counter_set(computed_style.counter_data(CSS::PropertyID::CounterSet));
  725. if (auto object_fit = computed_style.object_fit(); object_fit.has_value())
  726. computed_values.set_object_fit(object_fit.value());
  727. computed_values.set_object_position(computed_style.object_position());
  728. if (auto direction = computed_style.direction(); direction.has_value())
  729. computed_values.set_direction(direction.value());
  730. if (auto scrollbar_width = computed_style.scrollbar_width(); scrollbar_width.has_value())
  731. computed_values.set_scrollbar_width(scrollbar_width.value());
  732. propagate_style_to_anonymous_wrappers();
  733. }
  734. void NodeWithStyle::propagate_style_to_anonymous_wrappers()
  735. {
  736. // Update the style of any anonymous wrappers that inherit from this node.
  737. // FIXME: This is pretty hackish. It would be nicer if they shared the inherited style
  738. // data structure somehow, so this wasn't necessary.
  739. // If this is a `display:table` box with an anonymous wrapper parent,
  740. // the parent inherits style from *this* node, not the other way around.
  741. if (display().is_table_inside() && is<TableWrapper>(parent())) {
  742. auto& table_wrapper = *static_cast<TableWrapper*>(parent());
  743. static_cast<CSS::MutableComputedValues&>(static_cast<CSS::ComputedValues&>(const_cast<CSS::ImmutableComputedValues&>(table_wrapper.computed_values()))).inherit_from(computed_values());
  744. transfer_table_box_computed_values_to_wrapper_computed_values(table_wrapper.mutable_computed_values());
  745. }
  746. // Propagate style to all anonymous children (except table wrappers!)
  747. for_each_child_of_type<NodeWithStyle>([&](NodeWithStyle& child) {
  748. if (child.is_anonymous() && !is<TableWrapper>(child)) {
  749. auto& child_computed_values = static_cast<CSS::MutableComputedValues&>(static_cast<CSS::ComputedValues&>(const_cast<CSS::ImmutableComputedValues&>(child.computed_values())));
  750. child_computed_values.inherit_from(computed_values());
  751. }
  752. return IterationDecision::Continue;
  753. });
  754. }
  755. bool Node::is_root_element() const
  756. {
  757. if (is_anonymous())
  758. return false;
  759. return is<HTML::HTMLHtmlElement>(*dom_node());
  760. }
  761. String Node::debug_description() const
  762. {
  763. StringBuilder builder;
  764. builder.append(class_name());
  765. if (dom_node()) {
  766. builder.appendff("<{}>", dom_node()->node_name());
  767. if (dom_node()->is_element()) {
  768. auto& element = static_cast<DOM::Element const&>(*dom_node());
  769. if (element.id().has_value())
  770. builder.appendff("#{}", element.id().value());
  771. for (auto const& class_name : element.class_names())
  772. builder.appendff(".{}", class_name);
  773. }
  774. } else {
  775. builder.append("(anonymous)"sv);
  776. }
  777. return MUST(builder.to_string());
  778. }
  779. CSS::Display Node::display() const
  780. {
  781. if (!has_style()) {
  782. // NOTE: No style means this is dumb text content.
  783. return CSS::Display(CSS::DisplayOutside::Inline, CSS::DisplayInside::Flow);
  784. }
  785. return computed_values().display();
  786. }
  787. bool Node::is_inline() const
  788. {
  789. return display().is_inline_outside();
  790. }
  791. bool Node::is_inline_block() const
  792. {
  793. auto display = this->display();
  794. return display.is_inline_outside() && display.is_flow_root_inside();
  795. }
  796. bool Node::is_inline_table() const
  797. {
  798. auto display = this->display();
  799. return display.is_inline_outside() && display.is_table_inside();
  800. }
  801. JS::NonnullGCPtr<NodeWithStyle> NodeWithStyle::create_anonymous_wrapper() const
  802. {
  803. auto wrapper = heap().allocate_without_realm<BlockContainer>(const_cast<DOM::Document&>(document()), nullptr, computed_values().clone_inherited_values());
  804. wrapper->mutable_computed_values().set_display(CSS::Display(CSS::DisplayOutside::Block, CSS::DisplayInside::Flow));
  805. return *wrapper;
  806. }
  807. void NodeWithStyle::reset_table_box_computed_values_used_by_wrapper_to_init_values()
  808. {
  809. VERIFY(this->display().is_table_inside());
  810. auto& mutable_computed_values = this->mutable_computed_values();
  811. mutable_computed_values.set_position(CSS::InitialValues::position());
  812. mutable_computed_values.set_float(CSS::InitialValues::float_());
  813. mutable_computed_values.set_clear(CSS::InitialValues::clear());
  814. mutable_computed_values.set_inset(CSS::InitialValues::inset());
  815. mutable_computed_values.set_margin(CSS::InitialValues::margin());
  816. }
  817. void NodeWithStyle::transfer_table_box_computed_values_to_wrapper_computed_values(CSS::ComputedValues& wrapper_computed_values)
  818. {
  819. // The computed values of properties 'position', 'float', 'margin-*', 'top', 'right', 'bottom', and 'left' on the table element are used on the table wrapper box and not the table box;
  820. // all other values of non-inheritable properties are used on the table box and not the table wrapper box.
  821. // (Where the table element's values are not used on the table and table wrapper boxes, the initial values are used instead.)
  822. auto& mutable_wrapper_computed_values = static_cast<CSS::MutableComputedValues&>(wrapper_computed_values);
  823. if (display().is_inline_outside())
  824. mutable_wrapper_computed_values.set_display(CSS::Display::from_short(CSS::Display::Short::InlineBlock));
  825. else
  826. mutable_wrapper_computed_values.set_display(CSS::Display::from_short(CSS::Display::Short::FlowRoot));
  827. mutable_wrapper_computed_values.set_position(computed_values().position());
  828. mutable_wrapper_computed_values.set_inset(computed_values().inset());
  829. mutable_wrapper_computed_values.set_float(computed_values().float_());
  830. mutable_wrapper_computed_values.set_clear(computed_values().clear());
  831. mutable_wrapper_computed_values.set_margin(computed_values().margin());
  832. reset_table_box_computed_values_used_by_wrapper_to_init_values();
  833. }
  834. void Node::set_paintable(JS::GCPtr<Painting::Paintable> paintable)
  835. {
  836. m_paintable = move(paintable);
  837. }
  838. JS::GCPtr<Painting::Paintable> Node::create_paintable() const
  839. {
  840. return nullptr;
  841. }
  842. bool Node::is_anonymous() const
  843. {
  844. return m_anonymous;
  845. }
  846. DOM::Node const* Node::dom_node() const
  847. {
  848. if (m_anonymous)
  849. return nullptr;
  850. return m_dom_node.ptr();
  851. }
  852. DOM::Node* Node::dom_node()
  853. {
  854. if (m_anonymous)
  855. return nullptr;
  856. return m_dom_node.ptr();
  857. }
  858. DOM::Element const* Node::pseudo_element_generator() const
  859. {
  860. VERIFY(m_generated_for != GeneratedFor::NotGenerated);
  861. return m_pseudo_element_generator.ptr();
  862. }
  863. DOM::Element* Node::pseudo_element_generator()
  864. {
  865. VERIFY(m_generated_for != GeneratedFor::NotGenerated);
  866. return m_pseudo_element_generator.ptr();
  867. }
  868. DOM::Document& Node::document()
  869. {
  870. return m_dom_node->document();
  871. }
  872. DOM::Document const& Node::document() const
  873. {
  874. return m_dom_node->document();
  875. }
  876. }