Node.cpp 45 KB

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