| 
									
										
										
										
											2020-11-22 13:38:18 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-11-22 13:38:18 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2022-12-04 21:57:21 +03:00
										 |  |  | #include <LibWeb/Layout/FormattingContext.h>
 | 
					
						
							| 
									
										
										
										
											2023-01-14 15:05:08 +01:00
										 |  |  | #include <LibWeb/Layout/TableWrapper.h>
 | 
					
						
							| 
									
										
										
										
											2020-11-22 13:38:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::Layout { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 21:57:21 +03:00
										 |  |  | class TableFormattingContext final : public FormattingContext { | 
					
						
							| 
									
										
										
										
											2020-11-22 13:38:18 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-01-09 07:25:05 +03:00
										 |  |  |     explicit TableFormattingContext(LayoutState&, TableBox const&, FormattingContext* parent); | 
					
						
							| 
									
										
										
										
											2020-11-22 13:38:18 +01:00
										 |  |  |     ~TableFormattingContext(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-27 15:29:17 +02:00
										 |  |  |     virtual void run(Box const&, LayoutMode, AvailableSpace const&) override; | 
					
						
							| 
									
										
										
										
											2022-11-23 17:46:10 +00:00
										 |  |  |     virtual CSSPixels automatic_content_height() const override; | 
					
						
							| 
									
										
										
										
											2020-11-22 13:38:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-08 01:54:25 +03:00
										 |  |  |     TableBox const& table_box() const { return static_cast<TableBox const&>(context_box()); } | 
					
						
							| 
									
										
										
										
											2023-01-14 15:05:08 +01:00
										 |  |  |     TableWrapper const& table_wrapper() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return verify_cast<TableWrapper>(*table_box().containing_block()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-01-08 01:54:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 13:38:18 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2022-12-04 22:39:38 +03:00
										 |  |  |     void calculate_row_column_grid(Box const&); | 
					
						
							|  |  |  |     void compute_table_measures(); | 
					
						
							| 
									
										
										
										
											2023-01-05 18:56:34 +03:00
										 |  |  |     void compute_table_width(); | 
					
						
							|  |  |  |     void distribute_width_to_columns(); | 
					
						
							| 
									
										
										
										
											2022-12-04 22:39:38 +03:00
										 |  |  |     void determine_intrisic_size_of_table_container(AvailableSpace const& available_space); | 
					
						
							| 
									
										
										
										
											2023-01-08 00:31:00 +03:00
										 |  |  |     void calculate_row_heights(); | 
					
						
							| 
									
										
										
										
											2023-01-08 00:48:17 +03:00
										 |  |  |     void position_row_boxes(); | 
					
						
							| 
									
										
										
										
											2023-01-08 00:57:57 +03:00
										 |  |  |     void position_cell_boxes(); | 
					
						
							| 
									
										
										
										
											2022-09-24 13:39:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-15 12:57:36 +00:00
										 |  |  |     CSSPixels m_automatic_content_height { 0 }; | 
					
						
							| 
									
										
										
										
											2022-12-04 22:39:38 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-05 18:44:04 +03:00
										 |  |  |     Optional<AvailableSpace> m_available_space; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-05 18:56:34 +03:00
										 |  |  |     enum class ColumnType { | 
					
						
							|  |  |  |         Percent, | 
					
						
							|  |  |  |         Pixel, | 
					
						
							|  |  |  |         Auto | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 22:39:38 +03:00
										 |  |  |     struct Column { | 
					
						
							| 
									
										
										
										
											2023-01-05 18:56:34 +03:00
										 |  |  |         ColumnType type { ColumnType::Auto }; | 
					
						
							| 
									
										
										
										
											2022-12-15 12:57:36 +00:00
										 |  |  |         CSSPixels left_offset { 0 }; | 
					
						
							|  |  |  |         CSSPixels min_width { 0 }; | 
					
						
							|  |  |  |         CSSPixels max_width { 0 }; | 
					
						
							|  |  |  |         CSSPixels used_width { 0 }; | 
					
						
							| 
									
										
										
										
											2023-01-05 18:56:34 +03:00
										 |  |  |         float percentage_width { 0 }; | 
					
						
							| 
									
										
										
										
											2022-12-04 22:39:38 +03:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct Row { | 
					
						
							|  |  |  |         Box& box; | 
					
						
							| 
									
										
										
										
											2023-01-08 01:14:02 +03:00
										 |  |  |         CSSPixels used_height { 0 }; | 
					
						
							| 
									
										
										
										
											2022-12-15 12:57:36 +00:00
										 |  |  |         CSSPixels baseline { 0 }; | 
					
						
							| 
									
										
										
										
											2022-12-04 22:39:38 +03:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct Cell { | 
					
						
							|  |  |  |         Box& box; | 
					
						
							|  |  |  |         size_t column_index; | 
					
						
							|  |  |  |         size_t row_index; | 
					
						
							|  |  |  |         size_t column_span; | 
					
						
							| 
									
										
										
										
											2022-12-09 13:36:56 +03:00
										 |  |  |         size_t row_span; | 
					
						
							| 
									
										
										
										
											2022-12-15 12:57:36 +00:00
										 |  |  |         CSSPixels baseline { 0 }; | 
					
						
							| 
									
										
										
										
											2023-01-07 01:19:52 +03:00
										 |  |  |         CSSPixels min_width { 0 }; | 
					
						
							|  |  |  |         CSSPixels max_width { 0 }; | 
					
						
							| 
									
										
										
										
											2022-12-04 22:39:38 +03:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Vector<Cell> m_cells; | 
					
						
							|  |  |  |     Vector<Column> m_columns; | 
					
						
							|  |  |  |     Vector<Row> m_rows; | 
					
						
							| 
									
										
										
										
											2020-11-22 13:38:18 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |