2023-03-24 16:42:50 +00:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2023-03-24 16:42:50 +00:00
|
|
|
* 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
|
|
|
|
|
|
2023-03-30 17:13:37 +01:00
|
|
|
#include <LibWeb/CSS/PercentageOr.h>
|
2025-08-08 11:24:15 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
2025-08-08 10:11:51 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
2023-03-24 16:42:50 +00:00
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
2025-08-08 10:11:51 +01:00
|
|
|
class AbstractImageStyleValue : public StyleValue {
|
2023-03-24 16:42:50 +00:00
|
|
|
public:
|
2025-08-08 10:11:51 +01:00
|
|
|
using StyleValue::StyleValue;
|
2023-03-24 16:42:50 +00:00
|
|
|
|
|
|
|
|
virtual Optional<CSSPixels> natural_width() const { return {}; }
|
|
|
|
|
virtual Optional<CSSPixels> natural_height() const { return {}; }
|
|
|
|
|
|
2023-12-27 23:51:00 +01:00
|
|
|
virtual Optional<CSSPixelFraction> natural_aspect_ratio() const
|
|
|
|
|
{
|
|
|
|
|
auto width = natural_width();
|
|
|
|
|
auto height = natural_height();
|
2025-12-30 18:13:00 +11:00
|
|
|
if (width.has_value() && height.has_value() && *height != 0)
|
2023-12-27 23:51:00 +01:00
|
|
|
return *width / *height;
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 00:59:49 +01:00
|
|
|
virtual void load_any_resources(DOM::Document&) { }
|
2025-02-18 16:13:37 +00:00
|
|
|
virtual void resolve_for_size(Layout::NodeWithStyle const&, CSSPixelSize) const { }
|
2023-03-24 16:42:50 +00:00
|
|
|
|
|
|
|
|
virtual bool is_paintable() const = 0;
|
2025-07-31 23:07:26 +02:00
|
|
|
virtual void paint(DisplayListRecordingContext& context, DevicePixelRect const& dest_rect, ImageRendering) const = 0;
|
2024-01-01 13:48:53 +01:00
|
|
|
|
|
|
|
|
virtual Optional<Gfx::Color> color_if_single_pixel_bitmap() const { return {}; }
|
2025-09-12 15:07:19 +01:00
|
|
|
|
2025-09-25 13:00:43 +01:00
|
|
|
virtual GC::Ref<CSSStyleValue> reify(JS::Realm&, FlyString const& associated_property) const override;
|
2023-03-24 16:42:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// And now, some gradient related things. Maybe these should live somewhere else.
|
|
|
|
|
|
|
|
|
|
enum class GradientRepeating {
|
|
|
|
|
Yes,
|
|
|
|
|
No
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct ColorStopListElement {
|
2026-01-06 13:24:45 +01:00
|
|
|
ValueComparingRefPtr<StyleValue const> transition_hint;
|
2023-03-24 16:42:50 +00:00
|
|
|
struct ColorStop {
|
2026-01-06 13:24:45 +01:00
|
|
|
ValueComparingRefPtr<StyleValue const> color;
|
|
|
|
|
ValueComparingRefPtr<StyleValue const> position;
|
|
|
|
|
ValueComparingRefPtr<StyleValue const> second_position {};
|
2025-11-28 17:14:31 +00:00
|
|
|
bool operator==(ColorStop const&) const = default;
|
2023-03-24 16:42:50 +00:00
|
|
|
} color_stop;
|
|
|
|
|
|
2025-11-28 17:14:31 +00:00
|
|
|
bool operator==(ColorStopListElement const&) const = default;
|
2025-11-20 17:16:15 +00:00
|
|
|
ColorStopListElement absolutized(ComputationContext const& context) const;
|
2026-03-08 16:19:00 +13:00
|
|
|
bool is_computationally_independent() const
|
|
|
|
|
{
|
|
|
|
|
return (!transition_hint || transition_hint->is_computationally_independent())
|
|
|
|
|
&& (!color_stop.color || color_stop.color->is_computationally_independent())
|
|
|
|
|
&& (!color_stop.position || color_stop.position->is_computationally_independent())
|
|
|
|
|
&& (!color_stop.second_position || color_stop.second_position->is_computationally_independent());
|
|
|
|
|
}
|
2023-03-24 16:42:50 +00:00
|
|
|
};
|
2025-11-28 17:14:31 +00:00
|
|
|
void serialize_color_stop_list(StringBuilder&, Vector<ColorStopListElement> const&, SerializationMode);
|
2023-03-24 16:42:50 +00:00
|
|
|
|
|
|
|
|
}
|