Node.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Demangle.h>
  7. #include <LibGfx/FontDatabase.h>
  8. #include <LibWeb/DOM/Document.h>
  9. #include <LibWeb/Dump.h>
  10. #include <LibWeb/HTML/BrowsingContext.h>
  11. #include <LibWeb/HTML/HTMLHtmlElement.h>
  12. #include <LibWeb/Layout/BlockContainer.h>
  13. #include <LibWeb/Layout/FormattingContext.h>
  14. #include <LibWeb/Layout/InitialContainingBlock.h>
  15. #include <LibWeb/Layout/Node.h>
  16. #include <LibWeb/Layout/TextNode.h>
  17. #include <typeinfo>
  18. namespace Web::Layout {
  19. Node::Node(DOM::Document& document, DOM::Node* node)
  20. : m_document(document)
  21. , m_dom_node(node)
  22. {
  23. if (m_dom_node)
  24. m_dom_node->set_layout_node({}, this);
  25. }
  26. Node::~Node()
  27. {
  28. if (m_dom_node && m_dom_node->layout_node() == this)
  29. m_dom_node->set_layout_node({}, nullptr);
  30. }
  31. // https://www.w3.org/TR/css-display-3/#out-of-flow
  32. bool Node::is_out_of_flow(FormattingContext const& formatting_context) const
  33. {
  34. // A layout node is out of flow if either:
  35. // 1. It is floated (which requires that floating is not inhibited).
  36. if (!formatting_context.inhibits_floating() && computed_values().float_() != CSS::Float::None)
  37. return true;
  38. // 2. It is "absolutely positioned".
  39. if (is_absolutely_positioned())
  40. return true;
  41. return false;
  42. }
  43. bool Node::can_contain_boxes_with_position_absolute() const
  44. {
  45. return computed_values().position() != CSS::Position::Static || is<InitialContainingBlock>(*this);
  46. }
  47. const BlockContainer* Node::containing_block() const
  48. {
  49. if (is<TextNode>(*this))
  50. return first_ancestor_of_type<BlockContainer>();
  51. auto position = computed_values().position();
  52. if (position == CSS::Position::Absolute) {
  53. auto* ancestor = parent();
  54. while (ancestor && !ancestor->can_contain_boxes_with_position_absolute())
  55. ancestor = ancestor->parent();
  56. while (ancestor && (!is<BlockContainer>(*ancestor) || ancestor->is_anonymous()))
  57. ancestor = ancestor->containing_block();
  58. return static_cast<const BlockContainer*>(ancestor);
  59. }
  60. if (position == CSS::Position::Fixed)
  61. return &root();
  62. return first_ancestor_of_type<BlockContainer>();
  63. }
  64. bool Node::establishes_stacking_context() const
  65. {
  66. if (!has_style())
  67. return false;
  68. if (dom_node() == &document().root())
  69. return true;
  70. auto position = computed_values().position();
  71. if (position == CSS::Position::Absolute || position == CSS::Position::Relative || position == CSS::Position::Fixed || position == CSS::Position::Sticky)
  72. return true;
  73. if (!computed_values().transformations().is_empty())
  74. return true;
  75. return computed_values().opacity() < 1.0f;
  76. }
  77. HTML::BrowsingContext const& Node::browsing_context() const
  78. {
  79. VERIFY(document().browsing_context());
  80. return *document().browsing_context();
  81. }
  82. HTML::BrowsingContext& Node::browsing_context()
  83. {
  84. VERIFY(document().browsing_context());
  85. return *document().browsing_context();
  86. }
  87. const InitialContainingBlock& Node::root() const
  88. {
  89. VERIFY(document().layout_node());
  90. return *document().layout_node();
  91. }
  92. InitialContainingBlock& Node::root()
  93. {
  94. VERIFY(document().layout_node());
  95. return *document().layout_node();
  96. }
  97. void Node::set_needs_display()
  98. {
  99. if (auto* block = containing_block()) {
  100. block->paint_box()->for_each_fragment([&](auto& fragment) {
  101. if (&fragment.layout_node() == this || is_ancestor_of(fragment.layout_node())) {
  102. browsing_context().set_needs_display(enclosing_int_rect(fragment.absolute_rect()));
  103. }
  104. return IterationDecision::Continue;
  105. });
  106. }
  107. }
  108. Gfx::FloatPoint Node::box_type_agnostic_position() const
  109. {
  110. if (is<Box>(*this))
  111. return verify_cast<Box>(*this).paint_box()->absolute_position();
  112. VERIFY(is_inline());
  113. Gfx::FloatPoint position;
  114. if (auto* block = containing_block()) {
  115. block->paint_box()->for_each_fragment([&](auto& fragment) {
  116. if (&fragment.layout_node() == this || is_ancestor_of(fragment.layout_node())) {
  117. position = fragment.absolute_rect().location();
  118. return IterationDecision::Break;
  119. }
  120. return IterationDecision::Continue;
  121. });
  122. }
  123. return position;
  124. }
  125. bool Node::is_floating() const
  126. {
  127. if (!has_style())
  128. return false;
  129. // flex-items don't float.
  130. if (is_flex_item())
  131. return false;
  132. return computed_values().float_() != CSS::Float::None;
  133. }
  134. bool Node::is_positioned() const
  135. {
  136. return has_style() && computed_values().position() != CSS::Position::Static;
  137. }
  138. bool Node::is_absolutely_positioned() const
  139. {
  140. if (!has_style())
  141. return false;
  142. auto position = computed_values().position();
  143. return position == CSS::Position::Absolute || position == CSS::Position::Fixed;
  144. }
  145. bool Node::is_fixed_position() const
  146. {
  147. if (!has_style())
  148. return false;
  149. auto position = computed_values().position();
  150. return position == CSS::Position::Fixed;
  151. }
  152. NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> specified_style)
  153. : Node(document, node)
  154. {
  155. m_has_style = true;
  156. apply_style(*specified_style);
  157. }
  158. NodeWithStyle::NodeWithStyle(DOM::Document& document, DOM::Node* node, CSS::ComputedValues computed_values)
  159. : Node(document, node)
  160. , m_computed_values(move(computed_values))
  161. {
  162. m_has_style = true;
  163. m_font = Gfx::FontDatabase::default_font();
  164. }
  165. void NodeWithStyle::did_insert_into_layout_tree(CSS::StyleProperties const& style)
  166. {
  167. // https://drafts.csswg.org/css-sizing-3/#definite
  168. auto is_definite_size = [&](CSS::PropertyID property_id, bool width) {
  169. // A size that can be determined without performing layout; that is,
  170. // a <length>,
  171. // a measure of text (without consideration of line-wrapping),
  172. // a size of the initial containing block,
  173. // or a <percentage> or other formula (such as the “stretch-fit” sizing of non-replaced blocks [CSS2]) that is resolved solely against definite sizes.
  174. auto maybe_value = style.property(property_id);
  175. auto const* containing_block = this->containing_block();
  176. auto containing_block_has_definite_size = containing_block && (width ? containing_block->m_has_definite_width : containing_block->m_has_definite_height);
  177. if (!maybe_value.has_value() || maybe_value.value()->has_auto()) {
  178. // NOTE: The width of a non-flex-item block is considered definite if it's auto and the containing block has definite width.
  179. if (width && is_block_container() && parent() && !parent()->computed_values().display().is_flex_inside())
  180. return containing_block_has_definite_size;
  181. return false;
  182. }
  183. auto maybe_length_percentage = style.length_percentage(property_id);
  184. if (!maybe_length_percentage.has_value())
  185. return false;
  186. auto length_percentage = maybe_length_percentage.release_value();
  187. if (length_percentage.is_length())
  188. return true;
  189. if (length_percentage.is_percentage())
  190. return containing_block_has_definite_size;
  191. // FIXME: Determine if calc() value is definite.
  192. return false;
  193. };
  194. m_has_definite_width = is_definite_size(CSS::PropertyID::Width, true);
  195. m_has_definite_height = is_definite_size(CSS::PropertyID::Height, false);
  196. }
  197. void NodeWithStyle::apply_style(const CSS::StyleProperties& specified_style)
  198. {
  199. auto& computed_values = static_cast<CSS::MutableComputedValues&>(m_computed_values);
  200. m_font = specified_style.computed_font();
  201. m_line_height = specified_style.line_height(*this);
  202. computed_values.set_vertical_align(specified_style.vertical_align());
  203. {
  204. auto attachments = specified_style.property(CSS::PropertyID::BackgroundAttachment);
  205. auto clips = specified_style.property(CSS::PropertyID::BackgroundClip);
  206. auto images = specified_style.property(CSS::PropertyID::BackgroundImage);
  207. auto origins = specified_style.property(CSS::PropertyID::BackgroundOrigin);
  208. auto positions = specified_style.property(CSS::PropertyID::BackgroundPosition);
  209. auto repeats = specified_style.property(CSS::PropertyID::BackgroundRepeat);
  210. auto sizes = specified_style.property(CSS::PropertyID::BackgroundSize);
  211. auto count_layers = [](auto maybe_style_value) -> size_t {
  212. if (maybe_style_value.has_value() && maybe_style_value.value()->is_value_list())
  213. return maybe_style_value.value()->as_value_list().size();
  214. else
  215. return 1;
  216. };
  217. auto value_for_layer = [](auto maybe_style_value, size_t layer_index) -> RefPtr<CSS::StyleValue> {
  218. if (!maybe_style_value.has_value())
  219. return nullptr;
  220. auto& style_value = maybe_style_value.value();
  221. if (style_value->is_value_list())
  222. return style_value->as_value_list().value_at(layer_index, true);
  223. return style_value;
  224. };
  225. size_t layer_count = 1;
  226. layer_count = max(layer_count, count_layers(attachments));
  227. layer_count = max(layer_count, count_layers(clips));
  228. layer_count = max(layer_count, count_layers(images));
  229. layer_count = max(layer_count, count_layers(origins));
  230. layer_count = max(layer_count, count_layers(positions));
  231. layer_count = max(layer_count, count_layers(repeats));
  232. layer_count = max(layer_count, count_layers(sizes));
  233. Vector<CSS::BackgroundLayerData> layers;
  234. layers.ensure_capacity(layer_count);
  235. for (size_t layer_index = 0; layer_index < layer_count; layer_index++) {
  236. CSS::BackgroundLayerData layer;
  237. if (auto image_value = value_for_layer(images, layer_index); image_value && image_value->is_image()) {
  238. layer.image = image_value->as_image();
  239. layer.image->load_bitmap(document());
  240. }
  241. if (auto attachment_value = value_for_layer(attachments, layer_index); attachment_value && attachment_value->has_identifier()) {
  242. switch (attachment_value->to_identifier()) {
  243. case CSS::ValueID::Fixed:
  244. layer.attachment = CSS::BackgroundAttachment::Fixed;
  245. break;
  246. case CSS::ValueID::Local:
  247. layer.attachment = CSS::BackgroundAttachment::Local;
  248. break;
  249. case CSS::ValueID::Scroll:
  250. layer.attachment = CSS::BackgroundAttachment::Scroll;
  251. break;
  252. default:
  253. break;
  254. }
  255. }
  256. auto as_box = [](auto value_id) {
  257. switch (value_id) {
  258. case CSS::ValueID::BorderBox:
  259. return CSS::BackgroundBox::BorderBox;
  260. case CSS::ValueID::ContentBox:
  261. return CSS::BackgroundBox::ContentBox;
  262. case CSS::ValueID::PaddingBox:
  263. return CSS::BackgroundBox::PaddingBox;
  264. default:
  265. VERIFY_NOT_REACHED();
  266. }
  267. };
  268. if (auto origin_value = value_for_layer(origins, layer_index); origin_value && origin_value->has_identifier()) {
  269. layer.origin = as_box(origin_value->to_identifier());
  270. }
  271. if (auto clip_value = value_for_layer(clips, layer_index); clip_value && clip_value->has_identifier()) {
  272. layer.clip = as_box(clip_value->to_identifier());
  273. }
  274. if (auto position_value = value_for_layer(positions, layer_index); position_value && position_value->is_position()) {
  275. auto& position = position_value->as_position();
  276. layer.position_edge_x = position.edge_x();
  277. layer.position_edge_y = position.edge_y();
  278. layer.position_offset_x = position.offset_x();
  279. layer.position_offset_y = position.offset_y();
  280. }
  281. if (auto size_value = value_for_layer(sizes, layer_index); size_value) {
  282. if (size_value->is_background_size()) {
  283. auto& size = size_value->as_background_size();
  284. layer.size_type = CSS::BackgroundSize::LengthPercentage;
  285. layer.size_x = size.size_x();
  286. layer.size_y = size.size_y();
  287. } else if (size_value->has_identifier()) {
  288. switch (size_value->to_identifier()) {
  289. case CSS::ValueID::Contain:
  290. layer.size_type = CSS::BackgroundSize::Contain;
  291. break;
  292. case CSS::ValueID::Cover:
  293. layer.size_type = CSS::BackgroundSize::Cover;
  294. break;
  295. default:
  296. break;
  297. }
  298. }
  299. }
  300. if (auto repeat_value = value_for_layer(repeats, layer_index); repeat_value && repeat_value->is_background_repeat()) {
  301. layer.repeat_x = repeat_value->as_background_repeat().repeat_x();
  302. layer.repeat_y = repeat_value->as_background_repeat().repeat_y();
  303. }
  304. layers.append(move(layer));
  305. }
  306. computed_values.set_background_layers(move(layers));
  307. }
  308. computed_values.set_background_color(specified_style.color_or_fallback(CSS::PropertyID::BackgroundColor, *this, CSS::InitialValues::background_color()));
  309. computed_values.set_box_sizing(specified_style.box_sizing());
  310. computed_values.set_font_size(specified_style.property(CSS::PropertyID::FontSize).value()->to_length().to_px(*this));
  311. computed_values.set_font_weight(specified_style.property(CSS::PropertyID::FontWeight).value()->to_integer());
  312. // FIXME: BorderXRadius properties are now BorderRadiusStyleValues, so make use of that.
  313. auto border_bottom_left_radius = specified_style.property(CSS::PropertyID::BorderBottomLeftRadius);
  314. if (border_bottom_left_radius.has_value() && border_bottom_left_radius.value()->is_border_radius())
  315. computed_values.set_border_bottom_left_radius(border_bottom_left_radius.value()->as_border_radius().horizontal_radius());
  316. auto border_bottom_right_radius = specified_style.property(CSS::PropertyID::BorderBottomRightRadius);
  317. if (border_bottom_right_radius.has_value() && border_bottom_right_radius.value()->is_border_radius())
  318. computed_values.set_border_bottom_right_radius(border_bottom_right_radius.value()->as_border_radius().horizontal_radius());
  319. auto border_top_left_radius = specified_style.property(CSS::PropertyID::BorderTopLeftRadius);
  320. if (border_top_left_radius.has_value() && border_top_left_radius.value()->is_border_radius())
  321. computed_values.set_border_top_left_radius(border_top_left_radius.value()->as_border_radius().horizontal_radius());
  322. auto border_top_right_radius = specified_style.property(CSS::PropertyID::BorderTopRightRadius);
  323. if (border_top_right_radius.has_value() && border_top_right_radius.value()->is_border_radius())
  324. computed_values.set_border_top_right_radius(border_top_right_radius.value()->as_border_radius().horizontal_radius());
  325. computed_values.set_display(specified_style.display());
  326. auto flex_direction = specified_style.flex_direction();
  327. if (flex_direction.has_value())
  328. computed_values.set_flex_direction(flex_direction.value());
  329. auto flex_wrap = specified_style.flex_wrap();
  330. if (flex_wrap.has_value())
  331. computed_values.set_flex_wrap(flex_wrap.value());
  332. auto flex_basis = specified_style.flex_basis();
  333. if (flex_basis.has_value())
  334. computed_values.set_flex_basis(flex_basis.value());
  335. computed_values.set_flex_grow(specified_style.flex_grow());
  336. computed_values.set_flex_shrink(specified_style.flex_shrink());
  337. auto justify_content = specified_style.justify_content();
  338. if (justify_content.has_value())
  339. computed_values.set_justify_content(justify_content.value());
  340. auto align_items = specified_style.align_items();
  341. if (align_items.has_value())
  342. computed_values.set_align_items(align_items.value());
  343. auto position = specified_style.position();
  344. if (position.has_value())
  345. computed_values.set_position(position.value());
  346. auto text_align = specified_style.text_align();
  347. if (text_align.has_value())
  348. computed_values.set_text_align(text_align.value());
  349. auto text_justify = specified_style.text_justify();
  350. if (text_align.has_value())
  351. computed_values.set_text_justify(text_justify.value());
  352. auto white_space = specified_style.white_space();
  353. if (white_space.has_value())
  354. computed_values.set_white_space(white_space.value());
  355. auto float_ = specified_style.float_();
  356. if (float_.has_value())
  357. computed_values.set_float(float_.value());
  358. auto clear = specified_style.clear();
  359. if (clear.has_value())
  360. computed_values.set_clear(clear.value());
  361. auto overflow_x = specified_style.overflow_x();
  362. if (overflow_x.has_value())
  363. computed_values.set_overflow_x(overflow_x.value());
  364. auto overflow_y = specified_style.overflow_y();
  365. if (overflow_y.has_value())
  366. computed_values.set_overflow_y(overflow_y.value());
  367. auto cursor = specified_style.cursor();
  368. if (cursor.has_value())
  369. computed_values.set_cursor(cursor.value());
  370. auto image_rendering = specified_style.image_rendering();
  371. if (image_rendering.has_value())
  372. computed_values.set_image_rendering(image_rendering.value());
  373. auto pointer_events = specified_style.pointer_events();
  374. if (pointer_events.has_value())
  375. computed_values.set_pointer_events(pointer_events.value());
  376. auto text_decoration_line = specified_style.text_decoration_line();
  377. if (text_decoration_line.has_value())
  378. computed_values.set_text_decoration_line(text_decoration_line.value());
  379. auto text_decoration_style = specified_style.text_decoration_style();
  380. if (text_decoration_style.has_value())
  381. computed_values.set_text_decoration_style(text_decoration_style.value());
  382. auto text_transform = specified_style.text_transform();
  383. if (text_transform.has_value())
  384. computed_values.set_text_transform(text_transform.value());
  385. if (auto list_style_type = specified_style.list_style_type(); list_style_type.has_value())
  386. computed_values.set_list_style_type(list_style_type.value());
  387. auto list_style_image = specified_style.property(CSS::PropertyID::ListStyleImage);
  388. if (list_style_image.has_value() && list_style_image.value()->is_image()) {
  389. m_list_style_image = list_style_image.value()->as_image();
  390. m_list_style_image->load_bitmap(document());
  391. }
  392. computed_values.set_color(specified_style.color_or_fallback(CSS::PropertyID::Color, *this, CSS::InitialValues::color()));
  393. // FIXME: The default text decoration color value is `currentcolor`, but since we can't resolve that easily,
  394. // we just manually grab the value from `color`. This makes it dependent on `color` being
  395. // specified first, so it's far from ideal.
  396. computed_values.set_text_decoration_color(specified_style.color_or_fallback(CSS::PropertyID::TextDecorationColor, *this, computed_values.color()));
  397. if (auto maybe_text_decoration_thickness = specified_style.length_percentage(CSS::PropertyID::TextDecorationThickness); maybe_text_decoration_thickness.has_value())
  398. computed_values.set_text_decoration_thickness(maybe_text_decoration_thickness.release_value());
  399. computed_values.set_z_index(specified_style.z_index());
  400. computed_values.set_opacity(specified_style.opacity());
  401. if (auto maybe_visibility = specified_style.visibility(); maybe_visibility.has_value())
  402. computed_values.set_visibility(maybe_visibility.release_value());
  403. if (computed_values.opacity() == 0 || computed_values.visibility() != CSS::Visibility::Visible)
  404. m_visible = false;
  405. if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::Width); maybe_length_percentage.has_value())
  406. computed_values.set_width(maybe_length_percentage.release_value());
  407. if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::MinWidth); maybe_length_percentage.has_value())
  408. computed_values.set_min_width(maybe_length_percentage.release_value());
  409. if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::MaxWidth); maybe_length_percentage.has_value())
  410. computed_values.set_max_width(maybe_length_percentage.release_value());
  411. if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::Height); maybe_length_percentage.has_value())
  412. computed_values.set_height(maybe_length_percentage.release_value());
  413. if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::MinHeight); maybe_length_percentage.has_value())
  414. computed_values.set_min_height(maybe_length_percentage.release_value());
  415. if (auto maybe_length_percentage = specified_style.length_percentage(CSS::PropertyID::MaxHeight); maybe_length_percentage.has_value())
  416. computed_values.set_max_height(maybe_length_percentage.release_value());
  417. computed_values.set_offset(specified_style.length_box(CSS::PropertyID::Left, CSS::PropertyID::Top, CSS::PropertyID::Right, CSS::PropertyID::Bottom, CSS::Length::make_auto()));
  418. computed_values.set_margin(specified_style.length_box(CSS::PropertyID::MarginLeft, CSS::PropertyID::MarginTop, CSS::PropertyID::MarginRight, CSS::PropertyID::MarginBottom, CSS::Length::make_px(0)));
  419. computed_values.set_padding(specified_style.length_box(CSS::PropertyID::PaddingLeft, CSS::PropertyID::PaddingTop, CSS::PropertyID::PaddingRight, CSS::PropertyID::PaddingBottom, CSS::Length::make_px(0)));
  420. computed_values.set_box_shadow(specified_style.box_shadow());
  421. computed_values.set_transformations(specified_style.transformations());
  422. computed_values.set_transform_origin(specified_style.transform_origin());
  423. auto do_border_style = [&](CSS::BorderData& border, CSS::PropertyID width_property, CSS::PropertyID color_property, CSS::PropertyID style_property) {
  424. // FIXME: The default border color value is `currentcolor`, but since we can't resolve that easily,
  425. // we just manually grab the value from `color`. This makes it dependent on `color` being
  426. // specified first, so it's far from ideal.
  427. border.color = specified_style.color_or_fallback(color_property, *this, computed_values.color());
  428. border.line_style = specified_style.line_style(style_property).value_or(CSS::LineStyle::None);
  429. if (border.line_style == CSS::LineStyle::None)
  430. border.width = 0;
  431. else
  432. border.width = specified_style.length_or_fallback(width_property, CSS::Length::make_px(0)).to_px(*this);
  433. };
  434. do_border_style(computed_values.border_left(), CSS::PropertyID::BorderLeftWidth, CSS::PropertyID::BorderLeftColor, CSS::PropertyID::BorderLeftStyle);
  435. do_border_style(computed_values.border_top(), CSS::PropertyID::BorderTopWidth, CSS::PropertyID::BorderTopColor, CSS::PropertyID::BorderTopStyle);
  436. do_border_style(computed_values.border_right(), CSS::PropertyID::BorderRightWidth, CSS::PropertyID::BorderRightColor, CSS::PropertyID::BorderRightStyle);
  437. do_border_style(computed_values.border_bottom(), CSS::PropertyID::BorderBottomWidth, CSS::PropertyID::BorderBottomColor, CSS::PropertyID::BorderBottomStyle);
  438. computed_values.set_content(specified_style.content());
  439. if (auto fill = specified_style.property(CSS::PropertyID::Fill); fill.has_value())
  440. computed_values.set_fill(fill.value()->to_color(*this));
  441. if (auto stroke = specified_style.property(CSS::PropertyID::Stroke); stroke.has_value())
  442. computed_values.set_stroke(stroke.value()->to_color(*this));
  443. if (auto stroke_width = specified_style.property(CSS::PropertyID::StrokeWidth); stroke_width.has_value()) {
  444. // FIXME: Converting to pixels isn't really correct - values should be in "user units"
  445. // https://svgwg.org/svg2-draft/coords.html#TermUserUnits
  446. if (stroke_width.value()->is_numeric())
  447. computed_values.set_stroke_width(CSS::Length::make_px(stroke_width.value()->to_number()));
  448. else
  449. computed_values.set_stroke_width(stroke_width.value()->to_length());
  450. }
  451. }
  452. bool Node::is_root_element() const
  453. {
  454. if (is_anonymous())
  455. return false;
  456. return is<HTML::HTMLHtmlElement>(*dom_node());
  457. }
  458. String Node::class_name() const
  459. {
  460. return demangle(typeid(*this).name());
  461. }
  462. String Node::debug_description() const
  463. {
  464. StringBuilder builder;
  465. builder.append(class_name().substring_view(13));
  466. if (dom_node()) {
  467. builder.appendff("<{}>", dom_node()->node_name());
  468. if (dom_node()->is_element()) {
  469. auto& element = static_cast<DOM::Element const&>(*dom_node());
  470. if (auto id = element.get_attribute(HTML::AttributeNames::id); !id.is_null())
  471. builder.appendff("#{}", id);
  472. for (auto const& class_name : element.class_names())
  473. builder.appendff(".{}", class_name);
  474. }
  475. } else {
  476. builder.append("(anonymous)");
  477. }
  478. return builder.to_string();
  479. }
  480. bool Node::is_inline_block() const
  481. {
  482. return is_inline() && is<BlockContainer>(*this);
  483. }
  484. NonnullRefPtr<NodeWithStyle> NodeWithStyle::create_anonymous_wrapper() const
  485. {
  486. auto wrapper = adopt_ref(*new BlockContainer(const_cast<DOM::Document&>(document()), nullptr, m_computed_values.clone_inherited_values()));
  487. wrapper->m_font = m_font;
  488. wrapper->m_line_height = m_line_height;
  489. return wrapper;
  490. }
  491. void Node::set_paintable(RefPtr<Painting::Paintable> paintable)
  492. {
  493. m_paintable = move(paintable);
  494. }
  495. RefPtr<Painting::Paintable> Node::create_paintable() const
  496. {
  497. return nullptr;
  498. }
  499. }