diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-03-24 16:42:50 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-03-25 16:56:04 +0000 |
commit | e61a5ad18021e9ca90717a3b1c8ef0e4ebc03776 (patch) | |
tree | 7dcb2c31bd357c766c8151a8fd62bd13a7496978 /Userland/Libraries/LibWeb | |
parent | 0f04fa2e6e8ffa9907641baf9b1a64d9bcc45a25 (diff) | |
download | serenity-e61a5ad18021e9ca90717a3b1c8ef0e4ebc03776.zip |
LibWeb: Split AbstractImageStyleValue out of StyleValue.{h,cpp}
Diffstat (limited to 'Userland/Libraries/LibWeb')
13 files changed, 89 insertions, 131 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/ComputedValues.h b/Userland/Libraries/LibWeb/CSS/ComputedValues.h index 7b9859ef2b..5c9ab79a8e 100644 --- a/Userland/Libraries/LibWeb/CSS/ComputedValues.h +++ b/Userland/Libraries/LibWeb/CSS/ComputedValues.h @@ -12,6 +12,7 @@ #include <LibWeb/CSS/LengthBox.h> #include <LibWeb/CSS/Size.h> #include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h> namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h index e8c33131f7..06da7844c1 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.h @@ -25,6 +25,7 @@ #include <LibWeb/CSS/Ratio.h> #include <LibWeb/CSS/Selector.h> #include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h> #include <LibWeb/CSS/Supports.h> #include <LibWeb/CSS/UnicodeRange.h> #include <LibWeb/Forward.h> diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index 40712b95e3..bc57fbf1ec 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -11,6 +11,7 @@ #include <LibGfx/Palette.h> #include <LibWeb/CSS/Serialize.h> #include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h> #include <LibWeb/CSS/StyleValues/AngleStyleValue.h> #include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h> #include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h> @@ -1037,26 +1038,6 @@ CalculatedStyleValue::CalculationResult CalculatedStyleValue::CalcNumberSumPartW return value->resolve(layout_node, percentage_basis); } -static ErrorOr<void> serialize_color_stop_list(StringBuilder& builder, auto const& color_stop_list) -{ - bool first = true; - for (auto const& element : color_stop_list) { - if (!first) - TRY(builder.try_append(", "sv)); - - if (element.transition_hint.has_value()) - TRY(builder.try_appendff("{}, "sv, TRY(element.transition_hint->value.to_string()))); - - TRY(serialize_a_srgb_value(builder, element.color_stop.color)); - for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) { - if (position->has_value()) - TRY(builder.try_appendff(" {}"sv, TRY((*position)->to_string()))); - } - first = false; - } - return {}; -} - CSSPixelPoint PositionValue::resolved(Layout::Node const& node, CSSPixelRect const& rect) const { // Note: A preset + a none default x/y_relative_to is impossible in the syntax (and makes little sense) diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index f58e7ad10d..eabbcb5790 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -63,28 +63,6 @@ enum class FlexBasis { Auto, }; -template<typename TPosition> -struct ColorStopListElement { - using PositionType = TPosition; - struct ColorHint { - TPosition value; - inline bool operator==(ColorHint const&) const = default; - }; - - Optional<ColorHint> transition_hint; - struct ColorStop { - Color color; - Optional<TPosition> position; - Optional<TPosition> second_position = {}; - inline bool operator==(ColorStop const&) const = default; - } color_stop; - - inline bool operator==(ColorStopListElement const&) const = default; -}; - -using LinearColorStopListElement = ColorStopListElement<LengthPercentage>; -using AngularColorStopListElement = ColorStopListElement<AnglePercentage>; - // FIXME: Named PositionValue to avoid conflicts with enums, but this represents a <position> struct PositionValue { enum class HorizontalPreset { @@ -649,25 +627,6 @@ private: NonnullOwnPtr<CalcSum> m_expression; }; -class AbstractImageStyleValue : public StyleValue { -public: - using StyleValue::StyleValue; - - virtual Optional<CSSPixels> natural_width() const { return {}; } - virtual Optional<CSSPixels> natural_height() const { return {}; } - - virtual void load_any_resources(DOM::Document&) {}; - virtual void resolve_for_size(Layout::Node const&, CSSPixelSize) const {}; - - virtual bool is_paintable() const = 0; - virtual void paint(PaintContext& context, DevicePixelRect const& dest_rect, CSS::ImageRendering image_rendering) const = 0; -}; - -enum class GradientRepeating { - Yes, - No -}; - class InheritStyleValue final : public StyleValueWithDefaultOperators<InheritStyleValue> { public: static ValueComparingNonnullRefPtr<InheritStyleValue> the() diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h new file mode 100644 index 0000000000..6cc8bace8f --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/AbstractImageStyleValue.h @@ -0,0 +1,81 @@ +/* + * 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/Enums.h> +#include <LibWeb/CSS/Serialize.h> +#include <LibWeb/CSS/StyleValue.h> + +namespace Web::CSS { + +class AbstractImageStyleValue : public StyleValue { +public: + using StyleValue::StyleValue; + + virtual Optional<CSSPixels> natural_width() const { return {}; } + virtual Optional<CSSPixels> natural_height() const { return {}; } + + virtual void load_any_resources(DOM::Document&) {}; + virtual void resolve_for_size(Layout::Node const&, CSSPixelSize) const {}; + + virtual bool is_paintable() const = 0; + virtual void paint(PaintContext& context, DevicePixelRect const& dest_rect, ImageRendering) const = 0; +}; + +// And now, some gradient related things. Maybe these should live somewhere else. + +enum class GradientRepeating { + Yes, + No +}; + +template<typename TPosition> +struct ColorStopListElement { + using PositionType = TPosition; + struct ColorHint { + TPosition value; + inline bool operator==(ColorHint const&) const = default; + }; + + Optional<ColorHint> transition_hint; + struct ColorStop { + Color color; + Optional<TPosition> position; + Optional<TPosition> second_position = {}; + inline bool operator==(ColorStop const&) const = default; + } color_stop; + + inline bool operator==(ColorStopListElement const&) const = default; +}; + +using LinearColorStopListElement = ColorStopListElement<LengthPercentage>; +using AngularColorStopListElement = ColorStopListElement<AnglePercentage>; + +static ErrorOr<void> serialize_color_stop_list(StringBuilder& builder, auto const& color_stop_list) +{ + bool first = true; + for (auto const& element : color_stop_list) { + if (!first) + TRY(builder.try_append(", "sv)); + + if (element.transition_hint.has_value()) + TRY(builder.try_appendff("{}, "sv, TRY(element.transition_hint->value.to_string()))); + + TRY(serialize_a_srgb_value(builder, element.color_stop.color)); + for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) { + if (position->has_value()) + TRY(builder.try_appendff(" {}"sv, TRY((*position)->to_string()))); + } + first = false; + } + return {}; +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.cpp index d0248be218..8b2d61be9c 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.cpp @@ -8,31 +8,9 @@ */ #include "ConicGradientStyleValue.h" -#include <LibWeb/CSS/Serialize.h> namespace Web::CSS { -// FIXME: Temporary until AbstractImageStyleValue.h exists. (And the Serialize.h include above.) -static ErrorOr<void> serialize_color_stop_list(StringBuilder& builder, auto const& color_stop_list) -{ - bool first = true; - for (auto const& element : color_stop_list) { - if (!first) - TRY(builder.try_append(", "sv)); - - if (element.transition_hint.has_value()) - TRY(builder.try_appendff("{}, "sv, TRY(element.transition_hint->value.to_string()))); - - TRY(serialize_a_srgb_value(builder, element.color_stop.color)); - for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) { - if (position->has_value()) - TRY(builder.try_appendff(" {}"sv, TRY((*position)->to_string()))); - } - first = false; - } - return {}; -} - ErrorOr<String> ConicGradientStyleValue::to_string() const { StringBuilder builder; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.h index 82a01d4156..fbdaf4b033 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/ConicGradientStyleValue.h @@ -9,7 +9,7 @@ #pragma once -#include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h> namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h index 584461a17b..131192f3d8 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.h @@ -11,7 +11,7 @@ #include <AK/URL.h> #include <LibWeb/CSS/Enums.h> -#include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h> namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.cpp index 233378ee52..c6938ed74f 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.cpp @@ -8,31 +8,9 @@ */ #include "LinearGradientStyleValue.h" -#include <LibWeb/CSS/Serialize.h> namespace Web::CSS { -// FIXME: Temporary until AbstractImageStyleValue.h exists. (And the Serialize.h include above.) -static ErrorOr<void> serialize_color_stop_list(StringBuilder& builder, auto const& color_stop_list) -{ - bool first = true; - for (auto const& element : color_stop_list) { - if (!first) - TRY(builder.try_append(", "sv)); - - if (element.transition_hint.has_value()) - TRY(builder.try_appendff("{}, "sv, TRY(element.transition_hint->value.to_string()))); - - TRY(serialize_a_srgb_value(builder, element.color_stop.color)); - for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) { - if (position->has_value()) - TRY(builder.try_appendff(" {}"sv, TRY((*position)->to_string()))); - } - first = false; - } - return {}; -} - ErrorOr<String> LinearGradientStyleValue::to_string() const { StringBuilder builder; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.h index c1bc87f718..41eb400443 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/LinearGradientStyleValue.h @@ -10,7 +10,7 @@ #pragma once #include <AK/Vector.h> -#include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h> namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp index 27bc0cbd31..72b68b70ba 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.cpp @@ -8,31 +8,9 @@ */ #include "RadialGradientStyleValue.h" -#include <LibWeb/CSS/Serialize.h> namespace Web::CSS { -// FIXME: Temporary until AbstractImageStyleValue.h exists. -static ErrorOr<void> serialize_color_stop_list(StringBuilder& builder, auto const& color_stop_list) -{ - bool first = true; - for (auto const& element : color_stop_list) { - if (!first) - TRY(builder.try_append(", "sv)); - - if (element.transition_hint.has_value()) - TRY(builder.try_appendff("{}, "sv, TRY(element.transition_hint->value.to_string()))); - - TRY(serialize_a_srgb_value(builder, element.color_stop.color)); - for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) { - if (position->has_value()) - TRY(builder.try_appendff(" {}"sv, TRY((*position)->to_string()))); - } - first = false; - } - return {}; -} - ErrorOr<String> RadialGradientStyleValue::to_string() const { StringBuilder builder; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h index cfa0639e2e..179e6004fa 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/RadialGradientStyleValue.h @@ -11,7 +11,7 @@ #include <AK/Vector.h> #include <LibWeb/CSS/Enums.h> -#include <LibWeb/CSS/StyleValue.h> +#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h> namespace Web::CSS { diff --git a/Userland/Libraries/LibWeb/Layout/Node.cpp b/Userland/Libraries/LibWeb/Layout/Node.cpp index 7fc6b5d781..f2ad64c6dc 100644 --- a/Userland/Libraries/LibWeb/Layout/Node.cpp +++ b/Userland/Libraries/LibWeb/Layout/Node.cpp @@ -5,6 +5,7 @@ */ #include <AK/Demangle.h> +#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h> #include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h> #include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h> #include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h> |