/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, Tobias Christiansen * Copyright (c) 2021-2023, Sam Atkins * Copyright (c) 2022-2023, MacDue * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::CSS { class AbstractImageStyleValue : public StyleValue { public: using StyleValue::StyleValue; virtual Optional natural_width() const { return {}; } virtual Optional natural_height() const { return {}; } virtual Optional natural_aspect_ratio() const { auto width = natural_width(); auto height = natural_height(); if (width.has_value() && height.has_value()) return *width / *height; return {}; } virtual void load_any_resources(DOM::Document&) {}; virtual void resolve_for_size(Layout::NodeWithStyleAndBoxModelMetrics const&, CSSPixelSize) const {}; virtual bool is_paintable() const = 0; virtual void paint(PaintContext& context, DevicePixelRect const& dest_rect, ImageRendering, RefPtr text_clip = {}) const = 0; virtual Optional color_if_single_pixel_bitmap() const { return {}; } }; // And now, some gradient related things. Maybe these should live somewhere else. enum class GradientRepeating { Yes, No }; template struct ColorStopListElement { using PositionType = TPosition; struct ColorHint { TPosition value; inline bool operator==(ColorHint const&) const = default; }; Optional transition_hint; struct ColorStop { RefPtr color; Optional position; Optional second_position = {}; inline bool operator==(ColorStop const&) const = default; } color_stop; inline bool operator==(ColorStopListElement const&) const = default; }; using LinearColorStopListElement = ColorStopListElement; using AngularColorStopListElement = ColorStopListElement; static void serialize_color_stop_list(StringBuilder& builder, auto const& color_stop_list) { bool first = true; for (auto const& element : color_stop_list) { if (!first) builder.append(", "sv); if (element.transition_hint.has_value()) builder.appendff("{}, "sv, element.transition_hint->value.to_string()); builder.append(element.color_stop.color->to_string()); for (auto position : Array { &element.color_stop.position, &element.color_stop.second_position }) { if (position->has_value()) builder.appendff(" {}"sv, (*position)->to_string()); } first = false; } } }