| 
									
										
										
										
											2020-01-18 09:38:21 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2022-10-31 19:46:55 +00:00
										 |  |  |  * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.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
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:32:51 +01:00
										 |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							| 
									
										
										
										
											2021-05-13 09:39:30 -04:00
										 |  |  | #include <LibWeb/HTML/HTMLHtmlElement.h>
 | 
					
						
							| 
									
										
										
										
											2021-10-06 20:02:41 +02:00
										 |  |  | #include <LibWeb/Layout/BlockContainer.h>
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  | #include <LibWeb/Layout/Box.h>
 | 
					
						
							| 
									
										
										
										
											2021-09-15 12:19:42 +01:00
										 |  |  | #include <LibWeb/Layout/FormattingContext.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-10 23:13:37 +01:00
										 |  |  | #include <LibWeb/Painting/PaintableBox.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-15 16:48:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-22 15:53:01 +01:00
										 |  |  | namespace Web::Layout { | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-20 16:35:12 +01:00
										 |  |  | Box::Box(DOM::Document& document, DOM::Node* node, GC::Ref<CSS::ComputedProperties> style) | 
					
						
							| 
									
										
										
										
											2022-03-09 23:53:41 +01:00
										 |  |  |     : NodeWithStyleAndBoxModelMetrics(document, node, move(style)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-27 08:38:27 +01:00
										 |  |  | Box::Box(DOM::Document& document, DOM::Node* node, NonnullOwnPtr<CSS::ComputedValues> computed_values) | 
					
						
							| 
									
										
										
										
											2022-03-09 23:53:41 +01:00
										 |  |  |     : NodeWithStyleAndBoxModelMetrics(document, node, move(computed_values)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Box::~Box() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-09-10 19:02:03 +02:00
										 |  |  | void Box::visit_edges(Cell::Visitor& visitor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Base::visit_edges(visitor); | 
					
						
							|  |  |  |     visitor.visit(m_contained_abspos_children); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | GC::Ptr<Painting::Paintable> Box::create_paintable() const | 
					
						
							| 
									
										
										
										
											2021-10-28 17:08:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2022-03-10 15:50:57 +01:00
										 |  |  |     return Painting::PaintableBox::create(*this); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-07 00:51:05 +02:00
										 |  |  | Painting::PaintableBox* Box::paintable_box() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-10-16 15:19:32 +02:00
										 |  |  |     return static_cast<Painting::PaintableBox*>(Node::first_paintable()); | 
					
						
							| 
									
										
										
										
											2023-08-07 00:51:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-20 16:00:42 +01:00
										 |  |  | Painting::PaintableBox const* Box::paintable_box() const | 
					
						
							| 
									
										
										
										
											2022-03-10 15:50:57 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-10-16 15:19:32 +02:00
										 |  |  |     return static_cast<Painting::PaintableBox const*>(Node::first_paintable()); | 
					
						
							| 
									
										
										
										
											2021-10-28 17:08:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-03 17:33:58 -05:00
										 |  |  | Optional<CSSPixelFraction> Box::preferred_aspect_ratio() const | 
					
						
							| 
									
										
										
										
											2023-06-08 16:47:50 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     auto computed_aspect_ratio = computed_values().aspect_ratio(); | 
					
						
							|  |  |  |     if (computed_aspect_ratio.use_natural_aspect_ratio_if_available && natural_aspect_ratio().has_value()) | 
					
						
							|  |  |  |         return natural_aspect_ratio(); | 
					
						
							| 
									
										
										
										
											2024-03-23 15:46:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (!computed_aspect_ratio.preferred_ratio.has_value()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     auto ratio = computed_aspect_ratio.preferred_ratio.release_value(); | 
					
						
							|  |  |  |     if (ratio.is_degenerate()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-22 10:36:03 +01:00
										 |  |  |     return CSSPixelFraction(ratio.numerator(), ratio.denominator()); | 
					
						
							| 
									
										
										
										
											2023-06-08 16:47:50 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-07 10:27:02 +01:00
										 |  |  | } |