| 
									
										
										
										
											2022-01-19 11:57:58 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2022-01-19 11:57:58 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibWeb/Layout/InlineFormattingContext.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::Layout { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class LineBuilder { | 
					
						
							|  |  |  |     AK_MAKE_NONCOPYABLE(LineBuilder); | 
					
						
							|  |  |  |     AK_MAKE_NONMOVABLE(LineBuilder); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-10-29 11:32:59 +00:00
										 |  |  |     LineBuilder(InlineFormattingContext&, LayoutState&, LayoutState::UsedValues& containing_block_used_values, CSS::Direction, CSS::WritingMode); | 
					
						
							| 
									
										
										
										
											2022-01-19 11:57:58 +01:00
										 |  |  |     ~LineBuilder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-10 15:49:17 +02:00
										 |  |  |     enum class ForcedBreak { | 
					
						
							|  |  |  |         No, | 
					
						
							|  |  |  |         Yes, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void break_line(ForcedBreak, Optional<CSSPixels> next_item_width = {}); | 
					
						
							| 
									
										
										
										
											2022-11-04 17:19:11 +00:00
										 |  |  |     void append_box(Box const&, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin); | 
					
						
							| 
									
										
										
										
											2024-06-29 17:14:23 +02:00
										 |  |  |     void append_text_chunk(TextNode const&, size_t offset_in_node, size_t length_in_node, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin, CSSPixels content_width, CSSPixels content_height, RefPtr<Gfx::GlyphRun>); | 
					
						
							| 
									
										
										
										
											2022-01-19 11:57:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-26 18:50:43 +01:00
										 |  |  |     // Returns whether a line break occurred.
 | 
					
						
							| 
									
										
										
										
											2022-11-04 17:19:11 +00:00
										 |  |  |     bool break_if_needed(CSSPixels next_item_width) | 
					
						
							| 
									
										
										
										
											2022-01-20 16:19:05 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-09 15:17:47 +02:00
										 |  |  |         if (should_break(next_item_width)) { | 
					
						
							| 
									
										
										
										
											2023-06-10 15:49:17 +02:00
										 |  |  |             break_line(LineBuilder::ForcedBreak::No, next_item_width); | 
					
						
							| 
									
										
										
										
											2022-03-26 18:50:43 +01:00
										 |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return false; | 
					
						
							| 
									
										
										
										
											2022-01-20 16:19:05 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-01-19 11:57:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void update_last_line(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-22 10:32:49 +01:00
										 |  |  |     void remove_last_line_if_empty(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-29 11:32:59 +00:00
										 |  |  |     CSSPixels current_block_offset() const { return m_current_block_offset; } | 
					
						
							|  |  |  |     void set_current_block_offset(CSSPixels block_offset) { m_current_block_offset = block_offset; } | 
					
						
							| 
									
										
										
										
											2022-03-22 19:18:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-16 14:21:52 +02:00
										 |  |  |     void recalculate_available_space(); | 
					
						
							| 
									
										
										
										
											2022-11-04 17:19:11 +00:00
										 |  |  |     CSSPixels y_for_float_to_be_inserted_here(Box const&); | 
					
						
							| 
									
										
										
										
											2022-03-22 19:18:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-29 04:05:45 +00:00
										 |  |  |     auto& inline_formatting_context() { return m_context; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-19 11:57:58 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-09-16 14:21:52 +02:00
										 |  |  |     void begin_new_line(bool increment_y, bool is_first_break_in_sequence = true); | 
					
						
							| 
									
										
										
										
											2022-01-23 01:34:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-04 17:19:11 +00:00
										 |  |  |     bool should_break(CSSPixels next_item_width); | 
					
						
							| 
									
										
										
										
											2022-01-20 16:19:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-20 15:51:24 +01:00
										 |  |  |     LineBox& ensure_last_line_box(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-19 11:57:58 +01:00
										 |  |  |     InlineFormattingContext& m_context; | 
					
						
							| 
									
										
										
										
											2022-07-16 23:43:48 +02:00
										 |  |  |     LayoutState& m_layout_state; | 
					
						
							| 
									
										
										
										
											2024-03-15 19:25:00 +01:00
										 |  |  |     LayoutState::UsedValues& m_containing_block_used_values; | 
					
						
							| 
									
										
										
										
											2023-08-12 18:30:18 +02:00
										 |  |  |     AvailableSize m_available_width_for_current_line { AvailableSize::make_indefinite() }; | 
					
						
							| 
									
										
										
										
											2024-10-29 11:32:59 +00:00
										 |  |  |     CSSPixels m_current_block_offset { 0 }; | 
					
						
							| 
									
										
										
										
											2022-11-04 17:19:11 +00:00
										 |  |  |     CSSPixels m_max_height_on_current_line { 0 }; | 
					
						
							| 
									
										
										
										
											2023-05-15 16:42:28 +02:00
										 |  |  |     CSSPixels m_text_indent { 0 }; | 
					
						
							| 
									
										
										
										
											2024-08-18 17:58:05 +01:00
										 |  |  |     CSS::Direction m_direction { CSS::Direction::Ltr }; | 
					
						
							| 
									
										
										
										
											2024-10-29 11:32:59 +00:00
										 |  |  |     CSS::WritingMode m_writing_mode { CSS::WritingMode::HorizontalTb }; | 
					
						
							| 
									
										
										
										
											2022-01-22 10:32:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool m_last_line_needs_update { false }; | 
					
						
							| 
									
										
										
										
											2022-01-19 11:57:58 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |