| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-21 18:45:35 +02:00
										 |  |  | #include <AK/NonnullRefPtr.h>
 | 
					
						
							| 
									
										
										
										
											2020-07-26 17:16:18 +02:00
										 |  |  | #include <AK/TypeCasts.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | #include <AK/Vector.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | #include <LibGC/Root.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-06 12:04:00 +01:00
										 |  |  | #include <LibGfx/Rect.h>
 | 
					
						
							| 
									
										
										
										
											2023-01-28 11:26:03 -05:00
										 |  |  | #include <LibJS/Heap/Cell.h>
 | 
					
						
							| 
									
										
										
										
											2021-01-06 10:34:31 +01:00
										 |  |  | #include <LibWeb/CSS/ComputedValues.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-17 18:51:32 +02:00
										 |  |  | #include <LibWeb/CSS/StyleComputer.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/CSS/StyleProperties.h>
 | 
					
						
							| 
									
										
										
										
											2023-09-28 00:26:02 +02:00
										 |  |  | #include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-17 18:51:32 +02:00
										 |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-09 20:42:11 +02:00
										 |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/Layout/BoxModelMetrics.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-18 21:35:44 +02:00
										 |  |  | #include <LibWeb/Painting/PaintContext.h>
 | 
					
						
							| 
									
										
										
										
											2024-10-14 16:07:56 +02:00
										 |  |  | #include <LibWeb/Painting/Paintable.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/TreeNode.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  | namespace Web::Layout { | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 13:38:18 +01:00
										 |  |  | enum class LayoutMode { | 
					
						
							| 
									
										
										
										
											2022-07-09 15:17:47 +02:00
										 |  |  |     // Normal layout. No min-content or max-content constraints applied.
 | 
					
						
							| 
									
										
										
										
											2022-03-19 15:44:02 +01:00
										 |  |  |     Normal, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-09 15:17:47 +02:00
										 |  |  |     // Intrinsic size determination.
 | 
					
						
							| 
									
										
										
										
											2022-07-16 23:43:48 +02:00
										 |  |  |     // Boxes honor min-content and max-content constraints (set via LayoutState::UsedValues::{width,height}_constraint)
 | 
					
						
							| 
									
										
										
										
											2022-07-09 15:17:47 +02:00
										 |  |  |     // by considering their containing block to be 0-sized or infinitely large in the relevant axis.
 | 
					
						
							| 
									
										
										
										
											2022-07-20 18:12:12 +02:00
										 |  |  |     // https://drafts.csswg.org/css-sizing-3/#intrinsic-sizing
 | 
					
						
							|  |  |  |     IntrinsicSizing, | 
					
						
							| 
									
										
										
										
											2020-11-22 13:38:18 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-17 14:41:50 +02:00
										 |  |  | class Node | 
					
						
							|  |  |  |     : public JS::Cell | 
					
						
							| 
									
										
										
										
											2024-05-02 10:24:23 +02:00
										 |  |  |     , public TreeNode<Node> { | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC_CELL(Node, JS::Cell); | 
					
						
							| 
									
										
										
										
											2022-10-17 14:41:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |     virtual ~Node(); | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     bool is_anonymous() const; | 
					
						
							|  |  |  |     DOM::Node const* dom_node() const; | 
					
						
							|  |  |  |     DOM::Node* dom_node(); | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-06 01:29:55 +02:00
										 |  |  |     DOM::Element const* pseudo_element_generator() const; | 
					
						
							|  |  |  |     DOM::Element* pseudo_element_generator(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     enum class GeneratedFor { | 
					
						
							|  |  |  |         NotGenerated, | 
					
						
							|  |  |  |         PseudoBefore, | 
					
						
							|  |  |  |         PseudoAfter | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     bool is_generated() const { return m_generated_for != GeneratedFor::NotGenerated; } | 
					
						
							|  |  |  |     bool is_generated_for_before_pseudo_element() const { return m_generated_for == GeneratedFor::PseudoBefore; } | 
					
						
							|  |  |  |     bool is_generated_for_after_pseudo_element() const { return m_generated_for == GeneratedFor::PseudoAfter; } | 
					
						
							|  |  |  |     void set_generated_for(GeneratedFor type, DOM::Element& element) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_generated_for = type; | 
					
						
							|  |  |  |         m_pseudo_element_generator = &element; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-28 17:11:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-14 16:07:56 +02:00
										 |  |  |     using PaintableList = IntrusiveList<&Painting::Paintable::m_list_node>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-16 15:19:32 +02:00
										 |  |  |     Painting::Paintable* first_paintable() { return m_paintable.first(); } | 
					
						
							|  |  |  |     Painting::Paintable const* first_paintable() const { return m_paintable.first(); } | 
					
						
							| 
									
										
										
										
											2024-10-13 21:29:47 +02:00
										 |  |  |     PaintableList& paintables() { return m_paintable; } | 
					
						
							|  |  |  |     PaintableList const& paintables() const { return m_paintable; } | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     void add_paintable(GC::Ptr<Painting::Paintable>); | 
					
						
							| 
									
										
										
										
											2024-10-14 16:07:56 +02:00
										 |  |  |     void clear_paintables(); | 
					
						
							| 
									
										
										
										
											2022-03-10 15:50:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     virtual GC::Ptr<Painting::Paintable> create_paintable() const; | 
					
						
							| 
									
										
										
										
											2022-03-10 15:50:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-28 13:42:07 +02:00
										 |  |  |     DOM::Document& document(); | 
					
						
							|  |  |  |     DOM::Document const& document() const; | 
					
						
							| 
									
										
										
										
											2019-09-29 11:43:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ptr<HTML::Navigable> navigable() const; | 
					
						
							| 
									
										
										
										
											2023-08-22 16:00:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-25 11:04:29 +01:00
										 |  |  |     Viewport const& root() const; | 
					
						
							|  |  |  |     Viewport& root(); | 
					
						
							| 
									
										
										
										
											2019-11-04 19:37:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-05 20:10:02 +01:00
										 |  |  |     bool is_root_element() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-05 09:26:03 +02:00
										 |  |  |     String debug_description() const; | 
					
						
							| 
									
										
										
										
											2021-01-01 16:42:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 14:19:52 +02:00
										 |  |  |     bool has_style() const { return m_has_style; } | 
					
						
							| 
									
										
										
										
											2023-04-27 09:03:49 -04:00
										 |  |  |     bool has_style_or_parent_with_style() const; | 
					
						
							| 
									
										
										
										
											2019-10-05 22:07:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 15:29:10 +01:00
										 |  |  |     virtual bool can_have_children() const { return true; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-06 15:33:09 +02:00
										 |  |  |     CSS::Display display() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-06 14:39:11 +02:00
										 |  |  |     bool is_inline() const; | 
					
						
							| 
									
										
										
										
											2021-01-01 18:55:47 +01:00
										 |  |  |     bool is_inline_block() const; | 
					
						
							| 
									
										
										
										
											2023-01-16 13:51:49 +01:00
										 |  |  |     bool is_inline_table() const; | 
					
						
							| 
									
										
										
										
											2020-05-05 16:06:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-22 18:34:02 +01:00
										 |  |  |     bool is_out_of_flow(FormattingContext const&) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-17 09:34:01 +01:00
										 |  |  |     // These are used to optimize hot is<T> variants for some classes where dynamic_cast is too slow.
 | 
					
						
							| 
									
										
										
										
											2021-01-07 17:31:26 +01:00
										 |  |  |     virtual bool is_box() const { return false; } | 
					
						
							| 
									
										
										
										
											2021-10-06 20:07:13 +02:00
										 |  |  |     virtual bool is_block_container() const { return false; } | 
					
						
							| 
									
										
										
										
											2021-10-26 16:15:53 +02:00
										 |  |  |     virtual bool is_break_node() const { return false; } | 
					
						
							| 
									
										
										
										
											2021-01-17 09:34:01 +01:00
										 |  |  |     virtual bool is_text_node() const { return false; } | 
					
						
							| 
									
										
										
										
											2023-02-25 11:04:29 +01:00
										 |  |  |     virtual bool is_viewport() const { return false; } | 
					
						
							| 
									
										
										
										
											2021-10-18 16:26:05 +02:00
										 |  |  |     virtual bool is_svg_box() const { return false; } | 
					
						
							| 
									
										
										
										
											2022-02-11 12:37:22 +00:00
										 |  |  |     virtual bool is_svg_geometry_box() const { return false; } | 
					
						
							| 
									
										
										
										
											2024-04-25 21:10:30 +02:00
										 |  |  |     virtual bool is_svg_mask_box() const { return false; } | 
					
						
							| 
									
										
										
										
											2023-03-10 21:16:18 +01:00
										 |  |  |     virtual bool is_svg_svg_box() const { return false; } | 
					
						
							| 
									
										
										
										
											2021-10-27 17:58:19 +02:00
										 |  |  |     virtual bool is_label() const { return false; } | 
					
						
							| 
									
										
										
										
											2022-03-13 17:21:27 +01:00
										 |  |  |     virtual bool is_replaced_box() const { return false; } | 
					
						
							| 
									
										
										
										
											2023-03-10 21:16:18 +01:00
										 |  |  |     virtual bool is_list_item_box() const { return false; } | 
					
						
							| 
									
										
										
										
											2022-03-13 17:21:27 +01:00
										 |  |  |     virtual bool is_list_item_marker_box() const { return false; } | 
					
						
							| 
									
										
										
										
											2024-11-05 08:07:13 +00:00
										 |  |  |     virtual bool is_fieldset_box() const { return false; } | 
					
						
							|  |  |  |     virtual bool is_legend_box() const { return false; } | 
					
						
							| 
									
										
										
										
											2023-01-14 14:48:20 +01:00
										 |  |  |     virtual bool is_table_wrapper() const { return false; } | 
					
						
							| 
									
										
										
										
											2023-03-10 21:16:18 +01:00
										 |  |  |     virtual bool is_node_with_style_and_box_model_metrics() const { return false; } | 
					
						
							| 
									
										
										
										
											2021-01-17 09:34:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     template<typename T> | 
					
						
							|  |  |  |     bool fast_is() const = delete; | 
					
						
							| 
									
										
										
										
											2021-01-07 17:31:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-26 15:08:42 +02:00
										 |  |  |     bool is_floating() const; | 
					
						
							| 
									
										
										
										
											2020-12-06 19:54:23 +01:00
										 |  |  |     bool is_positioned() const; | 
					
						
							| 
									
										
										
										
											2020-06-05 16:54:28 +02:00
										 |  |  |     bool is_absolutely_positioned() const; | 
					
						
							| 
									
										
										
										
											2020-06-12 14:19:03 +02:00
										 |  |  |     bool is_fixed_position() const; | 
					
						
							| 
									
										
										
										
											2024-08-24 19:20:31 +02:00
										 |  |  |     bool is_sticky_position() const; | 
					
						
							| 
									
										
										
										
											2020-06-05 16:54:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-29 22:36:15 +02:00
										 |  |  |     bool is_flex_item() const { return m_is_flex_item; } | 
					
						
							|  |  |  |     void set_flex_item(bool b) { m_is_flex_item = b; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-20 19:30:39 +02:00
										 |  |  |     bool is_grid_item() const { return m_is_grid_item; } | 
					
						
							|  |  |  |     void set_grid_item(bool b) { m_is_grid_item = b; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-23 14:59:51 +01:00
										 |  |  |     Box const* containing_block() const; | 
					
						
							|  |  |  |     Box* containing_block() { return const_cast<Box*>(const_cast<Node const*>(this)->containing_block()); } | 
					
						
							| 
									
										
										
										
											2019-07-01 07:28:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-11 21:54:37 +02:00
										 |  |  |     [[nodiscard]] Box const* static_position_containing_block() const; | 
					
						
							|  |  |  |     [[nodiscard]] Box* static_position_containing_block() { return const_cast<Box*>(const_cast<Node const*>(this)->static_position_containing_block()); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-24 06:57:38 +00:00
										 |  |  |     // Closest non-anonymous ancestor box, to be used when resolving percentage values.
 | 
					
						
							|  |  |  |     // Anonymous block boxes are ignored when resolving percentage values that would refer to it:
 | 
					
						
							|  |  |  |     // the closest non-anonymous ancestor box is used instead.
 | 
					
						
							|  |  |  |     // https://www.w3.org/TR/CSS22/visuren.html#anonymous-block-level
 | 
					
						
							| 
									
										
										
										
											2023-06-14 15:31:40 +02:00
										 |  |  |     Box const* non_anonymous_containing_block() const; | 
					
						
							| 
									
										
										
										
											2023-05-24 06:57:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-07 19:03:25 +03:00
										 |  |  |     bool establishes_stacking_context() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 16:54:28 +02:00
										 |  |  |     bool can_contain_boxes_with_position_absolute() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  |     Gfx::Font const& first_available_font() const; | 
					
						
							| 
									
										
										
										
											2023-04-01 21:12:15 +01:00
										 |  |  |     Gfx::Font const& scaled_font(PaintContext&) const; | 
					
						
							| 
									
										
										
										
											2023-07-20 20:24:22 +01:00
										 |  |  |     Gfx::Font const& scaled_font(float scale_factor) const; | 
					
						
							| 
									
										
										
										
											2023-04-01 21:12:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-08 11:31:24 +00:00
										 |  |  |     CSS::ImmutableComputedValues const& computed_values() const; | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |     NodeWithStyle* parent(); | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  |     NodeWithStyle const* parent() const; | 
					
						
							| 
									
										
										
										
											2019-07-24 07:34:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |     void inserted_into(Node&) { } | 
					
						
							|  |  |  |     void removed_from(Node&) { } | 
					
						
							| 
									
										
										
										
											2020-05-26 21:53:10 +02:00
										 |  |  |     void children_changed() { } | 
					
						
							| 
									
										
										
										
											2019-09-29 17:40:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-17 23:32:08 +02:00
										 |  |  |     bool children_are_inline() const { return m_children_are_inline; } | 
					
						
							|  |  |  |     void set_children_are_inline(bool value) { m_children_are_inline = value; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-18 15:41:17 +01:00
										 |  |  |     u32 initial_quote_nesting_level() const { return m_initial_quote_nesting_level; } | 
					
						
							|  |  |  |     void set_initial_quote_nesting_level(u32 value) { m_initial_quote_nesting_level = value; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-04 23:58:56 +02:00
										 |  |  |     // An element is called out of flow if it is floated, absolutely positioned, or is the root element.
 | 
					
						
							|  |  |  |     // https://www.w3.org/TR/CSS22/visuren.html#positioning-scheme
 | 
					
						
							|  |  |  |     bool is_out_of_flow() const { return is_floating() || is_absolutely_positioned(); } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // An element is called in-flow if it is not out-of-flow.
 | 
					
						
							|  |  |  |     // https://www.w3.org/TR/CSS22/visuren.html#positioning-scheme
 | 
					
						
							|  |  |  |     bool is_in_flow() const { return !is_out_of_flow(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-22 16:11:33 +01:00
										 |  |  |     [[nodiscard]] bool has_css_transform() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (!computed_values().transformations().is_empty()) | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         if (computed_values().rotate().has_value()) | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-07-31 22:26:43 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |     Node(DOM::Document&, DOM::Node*); | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-17 14:41:50 +02:00
										 |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |     friend class NodeWithStyle; | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<DOM::Node> m_dom_node; | 
					
						
							| 
									
										
										
										
											2024-10-14 16:07:56 +02:00
										 |  |  |     PaintableList m_paintable; | 
					
						
							| 
									
										
										
										
											2019-06-25 19:46:01 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ptr<DOM::Element> m_pseudo_element_generator; | 
					
						
							| 
									
										
										
										
											2023-08-06 01:29:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-16 16:42:39 +02:00
										 |  |  |     bool m_anonymous { false }; | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  |     bool m_has_style { false }; | 
					
						
							| 
									
										
										
										
											2019-10-17 23:32:08 +02:00
										 |  |  |     bool m_children_are_inline { false }; | 
					
						
							| 
									
										
										
										
											2021-05-29 22:36:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool m_is_flex_item { false }; | 
					
						
							| 
									
										
										
										
											2023-08-20 19:30:39 +02:00
										 |  |  |     bool m_is_grid_item { false }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-06 01:29:55 +02:00
										 |  |  |     GeneratedFor m_generated_for { GeneratedFor::NotGenerated }; | 
					
						
							| 
									
										
										
										
											2023-09-18 15:41:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     u32 m_initial_quote_nesting_level { 0 }; | 
					
						
							| 
									
										
										
										
											2019-06-15 22:49:44 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  | class NodeWithStyle : public Node { | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC_CELL(NodeWithStyle, Node); | 
					
						
							| 
									
										
										
										
											2022-10-17 14:41:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2022-03-14 13:21:51 -06:00
										 |  |  |     virtual ~NodeWithStyle() override = default; | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-27 08:38:27 +01:00
										 |  |  |     CSS::ImmutableComputedValues const& computed_values() const { return static_cast<CSS::ImmutableComputedValues const&>(*m_computed_values); } | 
					
						
							|  |  |  |     CSS::MutableComputedValues& mutable_computed_values() { return static_cast<CSS::MutableComputedValues&>(*m_computed_values); } | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 20:01:35 +02:00
										 |  |  |     void apply_style(const CSS::StyleProperties&); | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  |     Gfx::Font const& first_available_font() const; | 
					
						
							| 
									
										
										
										
											2021-11-12 12:11:01 +00:00
										 |  |  |     Vector<CSS::BackgroundLayerData> const& background_layers() const { return computed_values().background_layers(); } | 
					
						
							| 
									
										
										
										
											2022-07-31 01:11:59 +01:00
										 |  |  |     const CSS::AbstractImageStyleValue* list_style_image() const { return m_list_style_image; } | 
					
						
							| 
									
										
										
										
											2021-01-06 11:05:23 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<NodeWithStyle> create_anonymous_wrapper() const; | 
					
						
							| 
									
										
										
										
											2021-01-06 14:10:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-22 12:22:29 +00:00
										 |  |  |     void transfer_table_box_computed_values_to_wrapper_computed_values(CSS::ComputedValues& wrapper_computed_values); | 
					
						
							| 
									
										
										
										
											2023-01-09 08:27:39 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-13 21:29:47 +02:00
										 |  |  |     bool is_body() const; | 
					
						
							|  |  |  |     bool is_scroll_container() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-28 00:26:02 +02:00
										 |  |  |     virtual void visit_edges(Cell::Visitor& visitor) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2024-10-26 17:42:27 +02:00
										 |  |  |     NodeWithStyle(DOM::Document&, DOM::Node*, CSS::StyleProperties); | 
					
						
							| 
									
										
										
										
											2024-01-27 08:38:27 +01:00
										 |  |  |     NodeWithStyle(DOM::Document&, DOM::Node*, NonnullOwnPtr<CSS::ComputedValues>); | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-06-22 12:22:29 +00:00
										 |  |  |     void reset_table_box_computed_values_used_by_wrapper_to_init_values(); | 
					
						
							| 
									
										
										
										
											2024-01-07 13:05:20 +01:00
										 |  |  |     void propagate_style_to_anonymous_wrappers(); | 
					
						
							| 
									
										
										
										
											2023-06-22 12:22:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-27 08:38:27 +01:00
										 |  |  |     NonnullOwnPtr<CSS::ComputedValues> m_computed_values; | 
					
						
							| 
									
										
										
										
											2023-02-20 18:56:08 +01:00
										 |  |  |     RefPtr<CSS::AbstractImageStyleValue const> m_list_style_image; | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  | class NodeWithStyleAndBoxModelMetrics : public NodeWithStyle { | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC_CELL(NodeWithStyleAndBoxModelMetrics, NodeWithStyle); | 
					
						
							| 
									
										
										
										
											2022-10-17 14:41:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | public: | 
					
						
							|  |  |  |     BoxModelMetrics& box_model() { return m_box_model; } | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  |     BoxModelMetrics const& box_model() const { return m_box_model; } | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2024-10-26 17:42:27 +02:00
										 |  |  |     NodeWithStyleAndBoxModelMetrics(DOM::Document& document, DOM::Node* node, CSS::StyleProperties style) | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |         : NodeWithStyle(document, node, move(style)) | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-27 08:38:27 +01:00
										 |  |  |     NodeWithStyleAndBoxModelMetrics(DOM::Document& document, DOM::Node* node, NonnullOwnPtr<CSS::ComputedValues> computed_values) | 
					
						
							| 
									
										
										
										
											2021-01-06 14:10:53 +01:00
										 |  |  |         : NodeWithStyle(document, node, move(computed_values)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-03-10 21:16:18 +01:00
										 |  |  |     virtual bool is_node_with_style_and_box_model_metrics() const final { return true; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  |     BoxModelMetrics m_box_model; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-10 21:16:18 +01:00
										 |  |  | template<> | 
					
						
							|  |  |  | inline bool Node::fast_is<NodeWithStyleAndBoxModelMetrics>() const { return is_node_with_style_and_box_model_metrics(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-27 09:03:49 -04:00
										 |  |  | inline bool Node::has_style_or_parent_with_style() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_has_style || (parent() != nullptr && parent()->has_style_or_parent_with_style()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  | inline Gfx::Font const& Node::first_available_font() const | 
					
						
							| 
									
										
										
										
											2021-01-06 11:05:23 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-04-27 09:03:49 -04:00
										 |  |  |     VERIFY(has_style_or_parent_with_style()); | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  |     if (m_has_style) | 
					
						
							|  |  |  |         return static_cast<NodeWithStyle const*>(this)->first_available_font(); | 
					
						
							|  |  |  |     return parent()->first_available_font(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-04-27 09:03:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-01 21:12:15 +01:00
										 |  |  | inline Gfx::Font const& Node::scaled_font(PaintContext& context) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-20 20:24:22 +01:00
										 |  |  |     return scaled_font(context.device_pixels_per_css_pixel()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Gfx::Font const& Node::scaled_font(float scale_factor) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-12-25 12:45:18 +01:00
										 |  |  |     auto const& font = first_available_font(); | 
					
						
							| 
									
										
										
										
											2024-05-06 13:12:16 -04:00
										 |  |  |     return font.with_size(font.point_size() * scale_factor); | 
					
						
							| 
									
										
										
										
											2023-04-01 21:12:15 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 11:07:02 +01:00
										 |  |  | inline const CSS::ImmutableComputedValues& Node::computed_values() const | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-04-27 09:03:49 -04:00
										 |  |  |     VERIFY(has_style_or_parent_with_style()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  |     if (m_has_style) | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  |         return static_cast<NodeWithStyle const*>(this)->computed_values(); | 
					
						
							| 
									
										
										
										
											2021-01-06 10:34:31 +01:00
										 |  |  |     return parent()->computed_values(); | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  | inline NodeWithStyle const* Node::parent() const | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-04-01 20:58:27 +03:00
										 |  |  |     return static_cast<NodeWithStyle const*>(TreeNode<Node>::parent()); | 
					
						
							| 
									
										
										
										
											2019-10-07 09:50:31 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-10-15 14:19:52 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  | inline NodeWithStyle* Node::parent() | 
					
						
							| 
									
										
										
										
											2019-10-18 10:16:33 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  |     return static_cast<NodeWithStyle*>(TreeNode<Node>::parent()); | 
					
						
							| 
									
										
										
										
											2019-10-18 10:16:33 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  | inline Gfx::Font const& NodeWithStyle::first_available_font() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // https://drafts.csswg.org/css-fonts/#first-available-font
 | 
					
						
							| 
									
										
										
										
											2024-01-21 22:53:54 +01:00
										 |  |  |     // First font for which the character U+0020 (space) is not excluded by a unicode-range
 | 
					
						
							|  |  |  |     return computed_values().font_list().font_for_code_point(' '); | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 20:42:11 +02:00
										 |  |  | } |