mirror of
				https://github.com/LadybirdBrowser/ladybird.git
				synced 2025-10-30 21:01:00 +00:00 
			
		
		
		
	LibWeb: Split StyleValueList out of StyleValue.{h,cpp}
This commit is contained in:
		
							parent
							
								
									3a2de67c7b
								
							
						
					
					
						commit
						4c54c5d3dd
					
				
				
				Notes:
				
					sideshowbarker
				
				2024-07-17 06:51:10 +09:00 
				
			
			Author: https://github.com/AtkinsSJ
Commit: 4c54c5d3dd
Pull-request: https://github.com/SerenityOS/serenity/pull/18040
			
					 12 changed files with 102 additions and 63 deletions
				
			
		|  | @ -94,6 +94,7 @@ set(SOURCES | ||||||
|     CSS/StyleValues/RadialGradientStyleValue.cpp |     CSS/StyleValues/RadialGradientStyleValue.cpp | ||||||
|     CSS/StyleValues/RectStyleValue.cpp |     CSS/StyleValues/RectStyleValue.cpp | ||||||
|     CSS/StyleValues/ShadowStyleValue.cpp |     CSS/StyleValues/ShadowStyleValue.cpp | ||||||
|  |     CSS/StyleValues/StyleValueList.cpp | ||||||
|     CSS/StyleValues/TextDecorationStyleValue.cpp |     CSS/StyleValues/TextDecorationStyleValue.cpp | ||||||
|     CSS/StyleValues/TransformationStyleValue.cpp |     CSS/StyleValues/TransformationStyleValue.cpp | ||||||
|     CSS/StyleValues/UnresolvedStyleValue.cpp |     CSS/StyleValues/UnresolvedStyleValue.cpp | ||||||
|  |  | ||||||
|  | @ -65,6 +65,7 @@ | ||||||
| #include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h> | #include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h> | #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/StringStyleValue.h> | #include <LibWeb/CSS/StyleValues/StringStyleValue.h> | ||||||
|  | #include <LibWeb/CSS/StyleValues/StyleValueList.h> | ||||||
| #include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h> | #include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/TimeStyleValue.h> | #include <LibWeb/CSS/StyleValues/TimeStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/TransformationStyleValue.h> | #include <LibWeb/CSS/StyleValues/TransformationStyleValue.h> | ||||||
|  |  | ||||||
|  | @ -30,6 +30,7 @@ | ||||||
| #include <LibWeb/CSS/StyleValues/PositionStyleValue.h> | #include <LibWeb/CSS/StyleValues/PositionStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/RectStyleValue.h> | #include <LibWeb/CSS/StyleValues/RectStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h> | #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h> | ||||||
|  | #include <LibWeb/CSS/StyleValues/StyleValueList.h> | ||||||
| #include <LibWeb/CSS/StyleValues/TransformationStyleValue.h> | #include <LibWeb/CSS/StyleValues/TransformationStyleValue.h> | ||||||
| #include <LibWeb/DOM/Document.h> | #include <LibWeb/DOM/Document.h> | ||||||
| #include <LibWeb/DOM/Element.h> | #include <LibWeb/DOM/Element.h> | ||||||
|  |  | ||||||
|  | @ -43,6 +43,7 @@ | ||||||
| #include <LibWeb/CSS/StyleValues/NumericStyleValue.h> | #include <LibWeb/CSS/StyleValues/NumericStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/OverflowStyleValue.h> | #include <LibWeb/CSS/StyleValues/OverflowStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h> | #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h> | ||||||
|  | #include <LibWeb/CSS/StyleValues/StyleValueList.h> | ||||||
| #include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h> | #include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h> | #include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h> | ||||||
| #include <LibWeb/DOM/Document.h> | #include <LibWeb/DOM/Document.h> | ||||||
|  |  | ||||||
|  | @ -18,6 +18,7 @@ | ||||||
| #include <LibWeb/CSS/StyleValues/RectStyleValue.h> | #include <LibWeb/CSS/StyleValues/RectStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h> | #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/StringStyleValue.h> | #include <LibWeb/CSS/StyleValues/StringStyleValue.h> | ||||||
|  | #include <LibWeb/CSS/StyleValues/StyleValueList.h> | ||||||
| #include <LibWeb/CSS/StyleValues/TransformationStyleValue.h> | #include <LibWeb/CSS/StyleValues/TransformationStyleValue.h> | ||||||
| #include <LibWeb/FontCache.h> | #include <LibWeb/FontCache.h> | ||||||
| #include <LibWeb/Layout/BlockContainer.h> | #include <LibWeb/Layout/BlockContainer.h> | ||||||
|  |  | ||||||
|  | @ -48,6 +48,7 @@ | ||||||
| #include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h> | #include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h> | #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/StringStyleValue.h> | #include <LibWeb/CSS/StyleValues/StringStyleValue.h> | ||||||
|  | #include <LibWeb/CSS/StyleValues/StyleValueList.h> | ||||||
| #include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h> | #include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/TimeStyleValue.h> | #include <LibWeb/CSS/StyleValues/TimeStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/TransformationStyleValue.h> | #include <LibWeb/CSS/StyleValues/TransformationStyleValue.h> | ||||||
|  | @ -1149,34 +1150,6 @@ ErrorOr<void> PositionValue::serialize(StringBuilder& builder) const | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool StyleValueList::Properties::operator==(Properties const& other) const |  | ||||||
| { |  | ||||||
|     return separator == other.separator && values.span() == other.values.span(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| ErrorOr<String> StyleValueList::to_string() const |  | ||||||
| { |  | ||||||
|     auto separator = ""sv; |  | ||||||
|     switch (m_properties.separator) { |  | ||||||
|     case Separator::Space: |  | ||||||
|         separator = " "sv; |  | ||||||
|         break; |  | ||||||
|     case Separator::Comma: |  | ||||||
|         separator = ", "sv; |  | ||||||
|         break; |  | ||||||
|     default: |  | ||||||
|         VERIFY_NOT_REACHED(); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     StringBuilder builder; |  | ||||||
|     for (size_t i = 0; i < m_properties.values.size(); ++i) { |  | ||||||
|         TRY(builder.try_append(TRY(m_properties.values[i]->to_string()))); |  | ||||||
|         if (i != m_properties.values.size() - 1) |  | ||||||
|             TRY(builder.try_append(separator)); |  | ||||||
|     } |  | ||||||
|     return builder.to_string(); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| Optional<CSS::Length> absolutized_length(CSS::Length const& length, CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) | Optional<CSS::Length> absolutized_length(CSS::Length const& length, CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const& font_metrics, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) | ||||||
| { | { | ||||||
|     if (length.is_px()) |     if (length.is_px()) | ||||||
|  |  | ||||||
|  | @ -622,41 +622,6 @@ private: | ||||||
|     NonnullOwnPtr<CalcSum> m_expression; |     NonnullOwnPtr<CalcSum> m_expression; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class StyleValueList final : public StyleValueWithDefaultOperators<StyleValueList> { |  | ||||||
| public: |  | ||||||
|     enum class Separator { |  | ||||||
|         Space, |  | ||||||
|         Comma, |  | ||||||
|     }; |  | ||||||
|     static ValueComparingNonnullRefPtr<StyleValueList> create(StyleValueVector&& values, Separator separator) { return adopt_ref(*new StyleValueList(move(values), separator)); } |  | ||||||
| 
 |  | ||||||
|     size_t size() const { return m_properties.values.size(); } |  | ||||||
|     StyleValueVector const& values() const { return m_properties.values; } |  | ||||||
|     ValueComparingNonnullRefPtr<StyleValue const> value_at(size_t i, bool allow_loop) const |  | ||||||
|     { |  | ||||||
|         if (allow_loop) |  | ||||||
|             return m_properties.values[i % size()]; |  | ||||||
|         return m_properties.values[i]; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     virtual ErrorOr<String> to_string() const override; |  | ||||||
| 
 |  | ||||||
|     bool properties_equal(StyleValueList const& other) const { return m_properties == other.m_properties; } |  | ||||||
| 
 |  | ||||||
| private: |  | ||||||
|     StyleValueList(StyleValueVector&& values, Separator separator) |  | ||||||
|         : StyleValueWithDefaultOperators(Type::ValueList) |  | ||||||
|         , m_properties { .separator = separator, .values = move(values) } |  | ||||||
|     { |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     struct Properties { |  | ||||||
|         Separator separator; |  | ||||||
|         StyleValueVector values; |  | ||||||
|         bool operator==(Properties const&) const; |  | ||||||
|     } m_properties; |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| template<> | template<> | ||||||
|  |  | ||||||
|  | @ -8,6 +8,7 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include "BackgroundStyleValue.h" | #include "BackgroundStyleValue.h" | ||||||
|  | #include <LibWeb/CSS/StyleValues/StyleValueList.h> | ||||||
| 
 | 
 | ||||||
| namespace Web::CSS { | namespace Web::CSS { | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -8,6 +8,7 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| #include "ContentStyleValue.h" | #include "ContentStyleValue.h" | ||||||
|  | #include <LibWeb/CSS/StyleValues/StyleValueList.h> | ||||||
| 
 | 
 | ||||||
| namespace Web::CSS { | namespace Web::CSS { | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										42
									
								
								Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,42 @@ | ||||||
|  | /*
 | ||||||
|  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | ||||||
|  |  * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> | ||||||
|  |  * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> | ||||||
|  |  * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> | ||||||
|  |  * | ||||||
|  |  * SPDX-License-Identifier: BSD-2-Clause | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | #include "StyleValueList.h" | ||||||
|  | 
 | ||||||
|  | namespace Web::CSS { | ||||||
|  | 
 | ||||||
|  | bool StyleValueList::Properties::operator==(Properties const& other) const | ||||||
|  | { | ||||||
|  |     return separator == other.separator && values.span() == other.values.span(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | ErrorOr<String> StyleValueList::to_string() const | ||||||
|  | { | ||||||
|  |     auto separator = ""sv; | ||||||
|  |     switch (m_properties.separator) { | ||||||
|  |     case Separator::Space: | ||||||
|  |         separator = " "sv; | ||||||
|  |         break; | ||||||
|  |     case Separator::Comma: | ||||||
|  |         separator = ", "sv; | ||||||
|  |         break; | ||||||
|  |     default: | ||||||
|  |         VERIFY_NOT_REACHED(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     StringBuilder builder; | ||||||
|  |     for (size_t i = 0; i < m_properties.values.size(); ++i) { | ||||||
|  |         TRY(builder.try_append(TRY(m_properties.values[i]->to_string()))); | ||||||
|  |         if (i != m_properties.values.size() - 1) | ||||||
|  |             TRY(builder.try_append(separator)); | ||||||
|  |     } | ||||||
|  |     return builder.to_string(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										51
									
								
								Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								Userland/Libraries/LibWeb/CSS/StyleValues/StyleValueList.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,51 @@ | ||||||
|  | /*
 | ||||||
|  |  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> | ||||||
|  |  * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org> | ||||||
|  |  * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> | ||||||
|  |  * Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech> | ||||||
|  |  * | ||||||
|  |  * SPDX-License-Identifier: BSD-2-Clause | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <LibWeb/CSS/StyleValue.h> | ||||||
|  | 
 | ||||||
|  | namespace Web::CSS { | ||||||
|  | 
 | ||||||
|  | class StyleValueList final : public StyleValueWithDefaultOperators<StyleValueList> { | ||||||
|  | public: | ||||||
|  |     enum class Separator { | ||||||
|  |         Space, | ||||||
|  |         Comma, | ||||||
|  |     }; | ||||||
|  |     static ValueComparingNonnullRefPtr<StyleValueList> create(StyleValueVector&& values, Separator separator) { return adopt_ref(*new StyleValueList(move(values), separator)); } | ||||||
|  | 
 | ||||||
|  |     size_t size() const { return m_properties.values.size(); } | ||||||
|  |     StyleValueVector const& values() const { return m_properties.values; } | ||||||
|  |     ValueComparingNonnullRefPtr<StyleValue const> value_at(size_t i, bool allow_loop) const | ||||||
|  |     { | ||||||
|  |         if (allow_loop) | ||||||
|  |             return m_properties.values[i % size()]; | ||||||
|  |         return m_properties.values[i]; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     virtual ErrorOr<String> to_string() const override; | ||||||
|  | 
 | ||||||
|  |     bool properties_equal(StyleValueList const& other) const { return m_properties == other.m_properties; } | ||||||
|  | 
 | ||||||
|  | private: | ||||||
|  |     StyleValueList(StyleValueVector&& values, Separator separator) | ||||||
|  |         : StyleValueWithDefaultOperators(Type::ValueList) | ||||||
|  |         , m_properties { .separator = separator, .values = move(values) } | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     struct Properties { | ||||||
|  |         Separator separator; | ||||||
|  |         StyleValueVector values; | ||||||
|  |         bool operator==(Properties const&) const; | ||||||
|  |     } m_properties; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -10,6 +10,7 @@ | ||||||
| #include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h> | #include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> | #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> | ||||||
| #include <LibWeb/CSS/StyleValues/PositionStyleValue.h> | #include <LibWeb/CSS/StyleValues/PositionStyleValue.h> | ||||||
|  | #include <LibWeb/CSS/StyleValues/StyleValueList.h> | ||||||
| #include <LibWeb/DOM/Document.h> | #include <LibWeb/DOM/Document.h> | ||||||
| #include <LibWeb/Dump.h> | #include <LibWeb/Dump.h> | ||||||
| #include <LibWeb/HTML/BrowsingContext.h> | #include <LibWeb/HTML/BrowsingContext.h> | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sam Atkins
						Sam Atkins