ladybird/Userland/Libraries/LibWeb/HTML/SourceSet.h
Shannon Booth e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00

56 lines
1.4 KiB
C++

/*
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Variant.h>
#include <LibURL/URL.h>
#include <LibWeb/CSS/CalculatedOr.h>
namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/images.html#image-source
struct ImageSource {
struct PixelDensityDescriptorValue {
double value { 0 };
};
struct WidthDescriptorValue {
CSSPixels value { 0 };
};
String url;
Variant<Empty, PixelDensityDescriptorValue, WidthDescriptorValue> descriptor;
};
struct ImageSourceAndPixelDensity {
ImageSource source;
double pixel_density { 1.0f };
};
// https://html.spec.whatwg.org/multipage/images.html#source-set
struct SourceSet {
static SourceSet create(DOM::Element const&, String default_source, String srcset, String sizes);
[[nodiscard]] bool is_empty() const;
// https://html.spec.whatwg.org/multipage/images.html#select-an-image-source-from-a-source-set
[[nodiscard]] ImageSourceAndPixelDensity select_an_image_source();
// https://html.spec.whatwg.org/multipage/images.html#normalise-the-source-densities
void normalize_source_densities(DOM::Element const&);
SourceSet();
Vector<ImageSource> m_sources;
CSS::LengthOrCalculated m_source_size;
};
SourceSet parse_a_srcset_attribute(StringView);
[[nodiscard]] CSS::LengthOrCalculated parse_a_sizes_attribute(DOM::Document const&, StringView);
}