| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Noncopyable.h>
 | 
					
						
							| 
									
										
										
										
											2022-01-21 14:37:05 +01:00
										 |  |  | #include <LibWeb/Layout/BlockContainer.h>
 | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:29 +01:00
										 |  |  | #include <LibWeb/Layout/InlineNode.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-13 17:42:39 +02:00
										 |  |  | #include <LibWeb/Layout/LayoutState.h>
 | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  | #include <LibWeb/Layout/TextNode.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::Layout { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This class iterates over all the inline-level objects within an inline formatting context.
 | 
					
						
							|  |  |  | // By repeatedly calling next() with the remaining available width on the current line,
 | 
					
						
							|  |  |  | // it returns an "Item" representing the next piece of inline-level content to be placed on the line.
 | 
					
						
							|  |  |  | class InlineLevelIterator { | 
					
						
							|  |  |  |     AK_MAKE_NONCOPYABLE(InlineLevelIterator); | 
					
						
							|  |  |  |     AK_MAKE_NONMOVABLE(InlineLevelIterator); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     struct Item { | 
					
						
							|  |  |  |         enum class Type { | 
					
						
							|  |  |  |             Text, | 
					
						
							|  |  |  |             Element, | 
					
						
							|  |  |  |             ForcedBreak, | 
					
						
							| 
									
										
										
										
											2022-03-07 22:27:09 +01:00
										 |  |  |             AbsolutelyPositionedElement, | 
					
						
							| 
									
										
										
										
											2022-03-22 19:18:05 +01:00
										 |  |  |             FloatingElement, | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  |         }; | 
					
						
							|  |  |  |         Type type {}; | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |         GC::Ptr<Layout::Node const> node {}; | 
					
						
							| 
									
										
										
										
											2024-06-29 17:14:23 +02:00
										 |  |  |         RefPtr<Gfx::GlyphRun> glyph_run {}; | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  |         size_t offset_in_node { 0 }; | 
					
						
							|  |  |  |         size_t length_in_node { 0 }; | 
					
						
							| 
									
										
										
										
											2022-11-04 17:19:11 +00:00
										 |  |  |         CSSPixels width { 0.0f }; | 
					
						
							|  |  |  |         CSSPixels padding_start { 0.0f }; | 
					
						
							|  |  |  |         CSSPixels padding_end { 0.0f }; | 
					
						
							|  |  |  |         CSSPixels border_start { 0.0f }; | 
					
						
							|  |  |  |         CSSPixels border_end { 0.0f }; | 
					
						
							|  |  |  |         CSSPixels margin_start { 0.0f }; | 
					
						
							|  |  |  |         CSSPixels margin_end { 0.0f }; | 
					
						
							| 
									
										
										
										
											2022-01-21 14:15:10 +01:00
										 |  |  |         bool is_collapsible_whitespace { false }; | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:29 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-04 17:19:11 +00:00
										 |  |  |         CSSPixels border_box_width() const | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:29 +01:00
										 |  |  |         { | 
					
						
							|  |  |  |             return border_start + padding_start + width + padding_end + border_end; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-15 19:25:00 +01:00
										 |  |  |     InlineLevelIterator(Layout::InlineFormattingContext&, LayoutState&, Layout::BlockContainer const& containing_block, LayoutState::UsedValues const& containing_block_used_values, LayoutMode); | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-17 05:38:52 +00:00
										 |  |  |     Optional<Item> next(); | 
					
						
							| 
									
										
										
										
											2023-08-19 03:36:53 +00:00
										 |  |  |     CSSPixels next_non_whitespace_sequence_width(); | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-08-19 03:36:53 +00:00
										 |  |  |     Optional<Item> next_without_lookahead(); | 
					
						
							| 
									
										
										
										
											2024-08-18 17:58:05 +01:00
										 |  |  |     Gfx::GlyphRun::TextType resolve_text_direction_from_context(); | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  |     void skip_to_next(); | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:29 +01:00
										 |  |  |     void compute_next(); | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-27 21:14:10 +02:00
										 |  |  |     void enter_text_node(Layout::TextNode const&); | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-20 15:51:24 +01:00
										 |  |  |     void enter_node_with_box_model_metrics(Layout::NodeWithStyleAndBoxModelMetrics const&); | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:29 +01:00
										 |  |  |     void exit_node_with_box_model_metrics(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void add_extra_box_model_metrics_to_item(Item&, bool add_leading_metrics, bool add_trailing_metrics); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-05 01:21:45 +01:00
										 |  |  |     HashMap<StringView, u8> shape_features_map() const; | 
					
						
							|  |  |  |     Gfx::ShapeFeatures create_and_merge_font_features() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-20 15:51:24 +01:00
										 |  |  |     Layout::Node const* next_inline_node_in_pre_order(Layout::Node const& current, Layout::Node const* stay_within); | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Layout::InlineFormattingContext& m_inline_formatting_context; | 
					
						
							| 
									
										
										
										
											2022-07-16 23:43:48 +02:00
										 |  |  |     Layout::LayoutState& m_layout_state; | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<BlockContainer const> m_containing_block; | 
					
						
							| 
									
										
										
										
											2024-03-15 19:25:00 +01:00
										 |  |  |     LayoutState::UsedValues const& m_containing_block_used_values; | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ptr<Layout::Node const> m_current_node; | 
					
						
							|  |  |  |     GC::Ptr<Layout::Node const> m_next_node; | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  |     LayoutMode const m_layout_mode; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct TextNodeContext { | 
					
						
							|  |  |  |         bool do_collapse {}; | 
					
						
							|  |  |  |         bool do_wrap_lines {}; | 
					
						
							|  |  |  |         bool do_respect_linebreaks {}; | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:29 +01:00
										 |  |  |         bool is_first_chunk {}; | 
					
						
							|  |  |  |         bool is_last_chunk {}; | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  |         TextNode::ChunkIterator chunk_iterator; | 
					
						
							| 
									
										
										
										
											2024-08-18 17:58:05 +01:00
										 |  |  |         Optional<Gfx::GlyphRun::TextType> last_known_direction {}; | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Optional<TextNodeContext> m_text_node_context; | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:29 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     struct ExtraBoxMetrics { | 
					
						
							| 
									
										
										
										
											2022-11-04 17:19:11 +00:00
										 |  |  |         CSSPixels margin { 0 }; | 
					
						
							|  |  |  |         CSSPixels border { 0 }; | 
					
						
							|  |  |  |         CSSPixels padding { 0 }; | 
					
						
							| 
									
										
										
										
											2022-02-14 15:52:29 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Optional<ExtraBoxMetrics> m_extra_leading_metrics; | 
					
						
							|  |  |  |     Optional<ExtraBoxMetrics> m_extra_trailing_metrics; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     Vector<GC::Ref<NodeWithStyleAndBoxModelMetrics const>> m_box_model_node_stack; | 
					
						
							| 
									
										
										
										
											2023-08-19 03:36:53 +00:00
										 |  |  |     Queue<InlineLevelIterator::Item> m_lookahead_items; | 
					
						
							| 
									
										
										
										
											2022-01-17 15:07:19 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |