mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 18:22:45 +00:00 
			
		
		
		
	LibWeb: Split ColorStyleValue out of StyleValue.{h,cpp}
This commit is contained in:
		
							parent
							
								
									66bc816284
								
							
						
					
					
						commit
						77b2826402
					
				
					 13 changed files with 89 additions and 47 deletions
				
			
		|  | @ -71,6 +71,7 @@ set(SOURCES | |||
|     CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp | ||||
|     CSS/StyleValues/BorderRadiusStyleValue.cpp | ||||
|     CSS/StyleValues/BorderStyleValue.cpp | ||||
|     CSS/StyleValues/ColorStyleValue.cpp | ||||
|     CSS/Supports.cpp | ||||
|     CSS/SyntaxHighlighter/SyntaxHighlighter.cpp | ||||
|     CSS/Time.cpp | ||||
|  |  | |||
|  | @ -36,6 +36,7 @@ | |||
| #include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/BorderStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/Dump.h> | ||||
| #include <LibWeb/Infra/Strings.h> | ||||
|  |  | |||
|  | @ -17,6 +17,7 @@ | |||
| #include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/BorderStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/Element.h> | ||||
| #include <LibWeb/Layout/Viewport.h> | ||||
|  |  | |||
|  | @ -29,6 +29,7 @@ | |||
| #include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/BorderStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/Element.h> | ||||
| #include <LibWeb/FontCache.h> | ||||
|  |  | |||
|  | @ -18,6 +18,7 @@ | |||
| #include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/BorderStyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/HTML/BrowsingContext.h> | ||||
| #include <LibWeb/Loader/LoadRequest.h> | ||||
|  | @ -1020,11 +1021,6 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcNumberSumPartW | |||
|     return value->resolve(layout_node, percentage_basis); | ||||
| } | ||||
| 
 | ||||
| ErrorOr<String> ColorStyleValue::to_string() const | ||||
| { | ||||
|     return serialize_a_srgb_value(m_color); | ||||
| } | ||||
| 
 | ||||
| ErrorOr<String> ContentStyleValue::to_string() const | ||||
| { | ||||
|     if (has_alt_text()) | ||||
|  | @ -2088,26 +2084,6 @@ ErrorOr<String> StyleValueList::to_string() const | |||
|     return builder.to_string(); | ||||
| } | ||||
| 
 | ||||
| ValueComparingNonnullRefPtr<ColorStyleValue> ColorStyleValue::create(Color color) | ||||
| { | ||||
|     if (color.value() == 0) { | ||||
|         static auto transparent = adopt_ref(*new ColorStyleValue(color)); | ||||
|         return transparent; | ||||
|     } | ||||
| 
 | ||||
|     if (color == Color::from_rgb(0x000000)) { | ||||
|         static auto black = adopt_ref(*new ColorStyleValue(color)); | ||||
|         return black; | ||||
|     } | ||||
| 
 | ||||
|     if (color == Color::from_rgb(0xffffff)) { | ||||
|         static auto white = adopt_ref(*new ColorStyleValue(color)); | ||||
|         return white; | ||||
|     } | ||||
| 
 | ||||
|     return adopt_ref(*new ColorStyleValue(color)); | ||||
| } | ||||
| 
 | ||||
| ValueComparingNonnullRefPtr<GridTemplateAreaStyleValue> GridTemplateAreaStyleValue::create(Vector<Vector<String>> grid_template_area) | ||||
| { | ||||
|     return adopt_ref(*new GridTemplateAreaStyleValue(grid_template_area)); | ||||
|  |  | |||
|  | @ -713,28 +713,6 @@ private: | |||
|     NonnullOwnPtr<CalcSum> m_expression; | ||||
| }; | ||||
| 
 | ||||
| class ColorStyleValue : public StyleValueWithDefaultOperators<ColorStyleValue> { | ||||
| public: | ||||
|     static ValueComparingNonnullRefPtr<ColorStyleValue> create(Color color); | ||||
|     virtual ~ColorStyleValue() override = default; | ||||
| 
 | ||||
|     Color color() const { return m_color; } | ||||
|     virtual ErrorOr<String> to_string() const override; | ||||
|     virtual bool has_color() const override { return true; } | ||||
|     virtual Color to_color(Layout::NodeWithStyle const&) const override { return m_color; } | ||||
| 
 | ||||
|     bool properties_equal(ColorStyleValue const& other) const { return m_color == other.m_color; }; | ||||
| 
 | ||||
| private: | ||||
|     explicit ColorStyleValue(Color color) | ||||
|         : StyleValueWithDefaultOperators(Type::Color) | ||||
|         , m_color(color) | ||||
|     { | ||||
|     } | ||||
| 
 | ||||
|     Color m_color; | ||||
| }; | ||||
| 
 | ||||
| class ContentStyleValue final : public StyleValueWithDefaultOperators<ContentStyleValue> { | ||||
| public: | ||||
|     static ValueComparingNonnullRefPtr<ContentStyleValue> create(ValueComparingNonnullRefPtr<StyleValueList> content, ValueComparingRefPtr<StyleValueList> alt_text) | ||||
|  |  | |||
|  | @ -0,0 +1,40 @@ | |||
| /*
 | ||||
|  * 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 "ColorStyleValue.h" | ||||
| #include <LibWeb/CSS/Serialize.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| ValueComparingNonnullRefPtr<ColorStyleValue> ColorStyleValue::create(Color color) | ||||
| { | ||||
|     if (color.value() == 0) { | ||||
|         static auto transparent = adopt_ref(*new ColorStyleValue(color)); | ||||
|         return transparent; | ||||
|     } | ||||
| 
 | ||||
|     if (color == Color::from_rgb(0x000000)) { | ||||
|         static auto black = adopt_ref(*new ColorStyleValue(color)); | ||||
|         return black; | ||||
|     } | ||||
| 
 | ||||
|     if (color == Color::from_rgb(0xffffff)) { | ||||
|         static auto white = adopt_ref(*new ColorStyleValue(color)); | ||||
|         return white; | ||||
|     } | ||||
| 
 | ||||
|     return adopt_ref(*new ColorStyleValue(color)); | ||||
| } | ||||
| 
 | ||||
| ErrorOr<String> ColorStyleValue::to_string() const | ||||
| { | ||||
|     return serialize_a_srgb_value(m_color); | ||||
| } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										39
									
								
								Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Userland/Libraries/LibWeb/CSS/StyleValues/ColorStyleValue.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,39 @@ | |||
| /*
 | ||||
|  * 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 <LibGfx/Color.h> | ||||
| #include <LibWeb/CSS/StyleValue.h> | ||||
| 
 | ||||
| namespace Web::CSS { | ||||
| 
 | ||||
| class ColorStyleValue : public StyleValueWithDefaultOperators<ColorStyleValue> { | ||||
| public: | ||||
|     static ValueComparingNonnullRefPtr<ColorStyleValue> create(Color color); | ||||
|     virtual ~ColorStyleValue() override = default; | ||||
| 
 | ||||
|     Color color() const { return m_color; } | ||||
|     virtual ErrorOr<String> to_string() const override; | ||||
|     virtual bool has_color() const override { return true; } | ||||
|     virtual Color to_color(Layout::NodeWithStyle const&) const override { return m_color; } | ||||
| 
 | ||||
|     bool properties_equal(ColorStyleValue const& other) const { return m_color == other.m_color; }; | ||||
| 
 | ||||
| private: | ||||
|     explicit ColorStyleValue(Color color) | ||||
|         : StyleValueWithDefaultOperators(Type::Color) | ||||
|         , m_color(color) | ||||
|     { | ||||
|     } | ||||
| 
 | ||||
|     Color m_color; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -6,6 +6,7 @@ | |||
| 
 | ||||
| #include <LibWeb/CSS/StyleProperties.h> | ||||
| #include <LibWeb/CSS/StyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/HTML/HTMLBodyElement.h> | ||||
| #include <LibWeb/HTML/Window.h> | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ | |||
| #include <LibWeb/Bindings/Intrinsics.h> | ||||
| #include <LibWeb/CSS/StyleProperties.h> | ||||
| #include <LibWeb/CSS/StyleValue.h> | ||||
| #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> | ||||
| #include <LibWeb/HTML/HTMLFontElement.h> | ||||
| 
 | ||||
| namespace Web::HTML { | ||||
|  |  | |||
|  | @ -5,6 +5,7 @@ | |||
|  */ | ||||
| 
 | ||||
| #include <LibWeb/Bindings/Intrinsics.h> | ||||
| #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> | ||||
| #include <LibWeb/HTML/HTMLMarqueeElement.h> | ||||
| 
 | ||||
| namespace Web::HTML { | ||||
|  |  | |||
|  | @ -6,6 +6,7 @@ | |||
| 
 | ||||
| #include <LibWeb/Bindings/Intrinsics.h> | ||||
| #include <LibWeb/CSS/Parser/Parser.h> | ||||
| #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> | ||||
| #include <LibWeb/HTML/HTMLTableCellElement.h> | ||||
| #include <LibWeb/HTML/Parser/HTMLParser.h> | ||||
| 
 | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ | |||
| 
 | ||||
| #include <LibWeb/Bindings/Intrinsics.h> | ||||
| #include <LibWeb/CSS/Parser/Parser.h> | ||||
| #include <LibWeb/CSS/StyleValues/ColorStyleValue.h> | ||||
| #include <LibWeb/DOM/ElementFactory.h> | ||||
| #include <LibWeb/DOM/HTMLCollection.h> | ||||
| #include <LibWeb/HTML/HTMLTableColElement.h> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sam Atkins
						Sam Atkins