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