| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-08-02 14:28:24 +02:00
										 |  |  |  * Copyright (c) 2020-2024, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2021-08-09 21:28:56 +02:00
										 |  |  |  * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> | 
					
						
							| 
									
										
										
										
											2025-05-16 20:02:16 +01:00
										 |  |  |  * Copyright (c) 2022-2025, Sam Atkins <sam@ladybird.org> | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-12 00:50:16 +02:00
										 |  |  | #include <AK/NonnullOwnPtr.h>
 | 
					
						
							|  |  |  | #include <AK/Variant.h>
 | 
					
						
							| 
									
										
										
										
											2022-04-09 09:28:38 +02:00
										 |  |  | #include <LibGfx/Font/Font.h>
 | 
					
						
							| 
									
										
										
										
											2021-09-23 13:13:51 +02:00
										 |  |  | #include <LibGfx/Rect.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  | #include <LibWeb/CSS/Length.h>
 | 
					
						
							| 
									
										
										
										
											2022-01-14 12:23:54 +00:00
										 |  |  | #include <LibWeb/CSS/Percentage.h>
 | 
					
						
							| 
									
										
										
										
											2025-02-18 09:19:56 +01:00
										 |  |  | #include <LibWeb/CSS/StyleComputer.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							| 
									
										
										
										
											2021-11-18 15:01:28 +01:00
										 |  |  | #include <LibWeb/HTML/BrowsingContext.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-29 13:16:15 +01:00
										 |  |  | #include <LibWeb/HTML/Window.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-08 07:51:03 +02:00
										 |  |  | #include <LibWeb/Layout/Node.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-26 20:01:35 +02:00
										 |  |  | namespace Web::CSS { | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-23 00:18:51 +12:00
										 |  |  | Length::FontMetrics::FontMetrics(CSSPixels font_size, Gfx::FontPixelMetrics const& pixel_metrics, CSSPixels line_height) | 
					
						
							| 
									
										
										
										
											2023-04-28 16:29:12 +01:00
										 |  |  |     : font_size(font_size) | 
					
						
							|  |  |  |     , x_height(pixel_metrics.x_height) | 
					
						
							| 
									
										
										
										
											2023-04-28 17:10:30 +01:00
										 |  |  |     // FIXME: This is only approximately the cap height. The spec suggests measuring the "O" glyph:
 | 
					
						
							|  |  |  |     //        https://www.w3.org/TR/css-values-4/#cap
 | 
					
						
							|  |  |  |     , cap_height(pixel_metrics.ascent) | 
					
						
							| 
									
										
										
										
											2024-06-04 07:02:22 +02:00
										 |  |  |     , zero_advance(pixel_metrics.advance_of_ascii_zero) | 
					
						
							| 
									
										
										
										
											2025-09-23 00:18:51 +12:00
										 |  |  |     , line_height(line_height) | 
					
						
							| 
									
										
										
										
											2023-04-28 16:29:12 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-14 12:23:54 +00:00
										 |  |  | Length Length::percentage_of(Percentage const& percentage) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     return Length { percentage.as_fraction() * raw_value(), m_unit }; | 
					
						
							| 
									
										
										
										
											2022-01-14 12:23:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-28 20:07:41 +01:00
										 |  |  | CSSPixels Length::font_relative_length_to_px(Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     switch (m_unit) { | 
					
						
							|  |  |  |     case LengthUnit::Em: | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * font_metrics.font_size.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Rem: | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * root_font_metrics.font_size.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Ex: | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * font_metrics.x_height.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Rex: | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * root_font_metrics.x_height.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Cap: | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * font_metrics.cap_height.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Rcap: | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * root_font_metrics.cap_height.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Ch: | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * font_metrics.zero_advance.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Rch: | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * root_font_metrics.zero_advance.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Ic: | 
					
						
							| 
									
										
										
										
											2023-04-28 17:18:18 +01:00
										 |  |  |         // FIXME: Use the "advance measure of the “水” (CJK water ideograph, U+6C34) glyph"
 | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * font_metrics.font_size.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Ric: | 
					
						
							| 
									
										
										
										
											2023-04-28 17:18:18 +01:00
										 |  |  |         // FIXME: Use the "advance measure of the “水” (CJK water ideograph, U+6C34) glyph"
 | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * root_font_metrics.font_size.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Lh: | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * font_metrics.line_height.to_double()); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Rlh: | 
					
						
							| 
									
										
										
										
											2023-08-26 15:57:31 +01:00
										 |  |  |         return CSSPixels::nearest_value_for(m_value * root_font_metrics.line_height.to_double()); | 
					
						
							| 
									
										
										
										
											2023-04-28 20:07:41 +01:00
										 |  |  |     default: | 
					
						
							|  |  |  |         VERIFY_NOT_REACHED(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CSSPixels Length::viewport_relative_length_to_px(CSSPixelRect const& viewport_rect) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     switch (m_unit) { | 
					
						
							|  |  |  |     case LengthUnit::Vw: | 
					
						
							|  |  |  |     case LengthUnit::Svw: | 
					
						
							|  |  |  |     case LengthUnit::Lvw: | 
					
						
							|  |  |  |     case LengthUnit::Dvw: | 
					
						
							| 
									
										
										
										
											2023-08-31 19:57:20 -05:00
										 |  |  |         return viewport_rect.width() * (CSSPixels::nearest_value_for(m_value) / 100); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Vh: | 
					
						
							|  |  |  |     case LengthUnit::Svh: | 
					
						
							|  |  |  |     case LengthUnit::Lvh: | 
					
						
							|  |  |  |     case LengthUnit::Dvh: | 
					
						
							| 
									
										
										
										
											2023-08-31 19:57:20 -05:00
										 |  |  |         return viewport_rect.height() * (CSSPixels::nearest_value_for(m_value) / 100); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Vi: | 
					
						
							|  |  |  |     case LengthUnit::Svi: | 
					
						
							|  |  |  |     case LengthUnit::Lvi: | 
					
						
							|  |  |  |     case LengthUnit::Dvi: | 
					
						
							| 
									
										
										
										
											2023-04-28 19:50:09 +01:00
										 |  |  |         // FIXME: Select the width or height based on which is the inline axis.
 | 
					
						
							| 
									
										
										
										
											2023-08-31 19:57:20 -05:00
										 |  |  |         return viewport_rect.width() * (CSSPixels::nearest_value_for(m_value) / 100); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Vb: | 
					
						
							|  |  |  |     case LengthUnit::Svb: | 
					
						
							|  |  |  |     case LengthUnit::Lvb: | 
					
						
							|  |  |  |     case LengthUnit::Dvb: | 
					
						
							| 
									
										
										
										
											2023-04-28 19:50:09 +01:00
										 |  |  |         // FIXME: Select the width or height based on which is the block axis.
 | 
					
						
							| 
									
										
										
										
											2023-08-31 19:57:20 -05:00
										 |  |  |         return viewport_rect.height() * (CSSPixels::nearest_value_for(m_value) / 100); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Vmin: | 
					
						
							|  |  |  |     case LengthUnit::Svmin: | 
					
						
							|  |  |  |     case LengthUnit::Lvmin: | 
					
						
							|  |  |  |     case LengthUnit::Dvmin: | 
					
						
							| 
									
										
										
										
											2023-08-31 19:57:20 -05:00
										 |  |  |         return min(viewport_rect.width(), viewport_rect.height()) * (CSSPixels::nearest_value_for(m_value) / 100); | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     case LengthUnit::Vmax: | 
					
						
							|  |  |  |     case LengthUnit::Svmax: | 
					
						
							|  |  |  |     case LengthUnit::Lvmax: | 
					
						
							|  |  |  |     case LengthUnit::Dvmax: | 
					
						
							| 
									
										
										
										
											2023-08-31 19:57:20 -05:00
										 |  |  |         return max(viewport_rect.width(), viewport_rect.height()) * (CSSPixels::nearest_value_for(m_value) / 100); | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  |     default: | 
					
						
							| 
									
										
										
										
											2021-02-23 20:42:32 +01:00
										 |  |  |         VERIFY_NOT_REACHED(); | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-19 15:38:16 +12:00
										 |  |  | Length::ResolutionContext Length::ResolutionContext::for_element(DOM::AbstractElement const& element) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto const* root_element = element.element().document().document_element(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     VERIFY(element.computed_properties()); | 
					
						
							|  |  |  |     VERIFY(root_element); | 
					
						
							|  |  |  |     VERIFY(root_element->computed_properties()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return Length::ResolutionContext { | 
					
						
							|  |  |  |         .viewport_rect = element.element().navigable()->viewport_rect(), | 
					
						
							| 
									
										
										
										
											2025-09-23 00:18:51 +12:00
										 |  |  |         .font_metrics = { element.computed_properties()->font_size(), element.computed_properties()->first_available_computed_font().pixel_metrics(), element.computed_properties()->line_height() }, | 
					
						
							|  |  |  |         .root_font_metrics = { root_element->computed_properties()->font_size(), root_element->computed_properties()->first_available_computed_font().pixel_metrics(), element.computed_properties()->line_height() } | 
					
						
							| 
									
										
										
										
											2025-07-19 15:38:16 +12:00
										 |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-29 13:16:15 +01:00
										 |  |  | Length::ResolutionContext Length::ResolutionContext::for_window(HTML::Window const& window) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto const& initial_font = window.associated_document().style_computer().initial_font(); | 
					
						
							|  |  |  |     Gfx::FontPixelMetrics const& initial_font_metrics = initial_font.pixel_metrics(); | 
					
						
							| 
									
										
										
										
											2025-09-23 00:18:51 +12:00
										 |  |  |     Length::FontMetrics font_metrics { CSSPixels { initial_font.pixel_size() }, initial_font_metrics, InitialValues::line_height() }; | 
					
						
							| 
									
										
										
										
											2024-11-29 13:16:15 +01:00
										 |  |  |     return Length::ResolutionContext { | 
					
						
							|  |  |  |         .viewport_rect = window.page().web_exposed_screen_area(), | 
					
						
							|  |  |  |         .font_metrics = font_metrics, | 
					
						
							|  |  |  |         .root_font_metrics = font_metrics, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 12:39:39 +02:00
										 |  |  | Length::ResolutionContext Length::ResolutionContext::for_layout_node(Layout::Node const& node) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2025-07-03 20:39:23 +12:00
										 |  |  |     Layout::Node const* root_layout_node; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (is<DOM::Document>(node.dom_node())) { | 
					
						
							|  |  |  |         root_layout_node = &node; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         auto const* root_element = node.document().document_element(); | 
					
						
							|  |  |  |         VERIFY(root_element); | 
					
						
							|  |  |  |         VERIFY(root_element->layout_node()); | 
					
						
							|  |  |  |         root_layout_node = root_element->layout_node(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-02 12:39:39 +02:00
										 |  |  |     return Length::ResolutionContext { | 
					
						
							| 
									
										
										
										
											2023-08-22 16:00:42 +02:00
										 |  |  |         .viewport_rect = node.navigable()->viewport_rect(), | 
					
						
							| 
									
										
										
										
											2025-09-23 00:18:51 +12:00
										 |  |  |         .font_metrics = { node.computed_values().font_size(), node.first_available_font().pixel_metrics(), node.computed_values().line_height() }, | 
					
						
							|  |  |  |         .root_font_metrics = { root_layout_node->computed_values().font_size(), root_layout_node->first_available_font().pixel_metrics(), node.computed_values().line_height() }, | 
					
						
							| 
									
										
										
										
											2023-06-02 12:39:39 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CSSPixels Length::to_px(ResolutionContext const& context) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return to_px(context.viewport_rect, context.font_metrics, context.root_font_metrics); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-02 11:17:06 +01:00
										 |  |  | CSSPixels Length::to_px_slow_case(Layout::Node const& layout_node) const | 
					
						
							| 
									
										
										
										
											2021-09-23 13:13:51 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     if (!layout_node.document().browsing_context()) | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2023-04-28 16:29:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-28 20:07:41 +01:00
										 |  |  |     if (is_font_relative()) { | 
					
						
							|  |  |  |         auto* root_element = layout_node.document().document_element(); | 
					
						
							|  |  |  |         if (!root_element || !root_element->layout_node()) | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         FontMetrics font_metrics { | 
					
						
							| 
									
										
										
										
											2023-08-31 19:53:41 -05:00
										 |  |  |             layout_node.computed_values().font_size(), | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  |             layout_node.first_available_font().pixel_metrics(), | 
					
						
							| 
									
										
										
										
											2025-09-23 00:18:51 +12:00
										 |  |  |             layout_node.computed_values().line_height() | 
					
						
							| 
									
										
										
										
											2023-04-28 20:07:41 +01:00
										 |  |  |         }; | 
					
						
							|  |  |  |         FontMetrics root_font_metrics { | 
					
						
							| 
									
										
										
										
											2023-08-31 19:53:41 -05:00
										 |  |  |             root_element->layout_node()->computed_values().font_size(), | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  |             root_element->layout_node()->first_available_font().pixel_metrics(), | 
					
						
							| 
									
										
										
										
											2025-09-23 00:18:51 +12:00
										 |  |  |             layout_node.computed_values().line_height() | 
					
						
							| 
									
										
										
										
											2023-04-28 20:07:41 +01:00
										 |  |  |         }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return font_relative_length_to_px(font_metrics, root_font_metrics); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     VERIFY(is_viewport_relative()); | 
					
						
							| 
									
										
										
										
											2023-08-22 16:00:42 +02:00
										 |  |  |     auto const& viewport_rect = layout_node.document().viewport_rect(); | 
					
						
							| 
									
										
										
										
											2023-04-28 20:07:41 +01:00
										 |  |  |     return viewport_relative_length_to_px(viewport_rect); | 
					
						
							| 
									
										
										
										
											2021-09-23 13:13:51 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-16 20:02:16 +01:00
										 |  |  | String Length::to_string(SerializationMode serialization_mode) const | 
					
						
							| 
									
										
										
										
											2022-02-21 17:35:52 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-08-18 12:56:29 +01:00
										 |  |  |     // https://drafts.csswg.org/cssom/#serialize-a-css-value
 | 
					
						
							|  |  |  |     // -> <length>
 | 
					
						
							|  |  |  |     // The <number> component serialized as per <number> followed by the unit in its canonical form as defined in its
 | 
					
						
							|  |  |  |     // respective specification.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-16 20:02:16 +01:00
										 |  |  |     // FIXME: Manually skip this for px so we avoid rounding errors in absolute_length_to_px.
 | 
					
						
							|  |  |  |     //        Maybe provide alternative functions that don't produce CSSPixels?
 | 
					
						
							| 
									
										
										
										
											2025-09-02 13:48:49 +01:00
										 |  |  |     if (serialization_mode == SerializationMode::ResolvedValue && is_absolute() && m_unit != LengthUnit::Px) { | 
					
						
							| 
									
										
										
										
											2025-08-18 12:56:29 +01:00
										 |  |  |         StringBuilder builder; | 
					
						
							|  |  |  |         serialize_a_number(builder, absolute_length_to_px().to_double()); | 
					
						
							|  |  |  |         builder.append("px"sv); | 
					
						
							|  |  |  |         return builder.to_string_without_validation(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     StringBuilder builder; | 
					
						
							|  |  |  |     serialize_a_number(builder, m_value); | 
					
						
							|  |  |  |     builder.append(unit_name()); | 
					
						
							|  |  |  |     return builder.to_string_without_validation(); | 
					
						
							| 
									
										
										
										
											2022-02-21 17:35:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-28 16:29:12 +01:00
										 |  |  | Optional<Length> Length::absolutize(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const | 
					
						
							| 
									
										
										
										
											2023-03-30 15:01:23 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     if (is_px()) | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     if (is_absolute() || is_relative()) { | 
					
						
							| 
									
										
										
										
											2023-04-28 16:29:12 +01:00
										 |  |  |         auto px = to_px(viewport_rect, font_metrics, root_font_metrics); | 
					
						
							| 
									
										
										
										
											2023-03-30 15:01:23 +01:00
										 |  |  |         return CSS::Length::make_px(px); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return {}; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-28 16:29:12 +01:00
										 |  |  | Length Length::absolutized(CSSPixelRect const& viewport_rect, FontMetrics const& font_metrics, FontMetrics const& root_font_metrics) const | 
					
						
							| 
									
										
										
										
											2023-03-30 15:01:23 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-04-28 16:29:12 +01:00
										 |  |  |     return absolutize(viewport_rect, font_metrics, root_font_metrics).value_or(*this); | 
					
						
							| 
									
										
										
										
											2023-03-30 15:01:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Length Length::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, Length const& reference_value) | 
					
						
							| 
									
										
										
										
											2024-08-02 14:28:24 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-05 16:22:17 +02:00
										 |  |  |     CalculationResolutionContext context { | 
					
						
							|  |  |  |         .percentage_basis = reference_value, | 
					
						
							|  |  |  |         .length_resolution_context = ResolutionContext::for_layout_node(layout_node), | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     return calculated->resolve_length(context).value(); | 
					
						
							| 
									
										
										
										
											2024-08-02 14:28:24 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:18:27 -06:00
										 |  |  | Length Length::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, Layout::Node const& layout_node, CSSPixels reference_value) | 
					
						
							| 
									
										
										
										
											2024-08-02 14:28:24 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-05 16:22:17 +02:00
										 |  |  |     return resolve_calculated(calculated, layout_node, make_px(reference_value)); | 
					
						
							| 
									
										
										
										
											2024-08-02 14:28:24 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-07 17:55:46 +02:00
										 |  |  | } |