SourceSet.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/URL.h>
  8. #include <AK/Variant.h>
  9. #include <LibWeb/CSS/CalculatedOr.h>
  10. namespace Web::HTML {
  11. // https://html.spec.whatwg.org/multipage/images.html#image-source
  12. struct ImageSource {
  13. struct PixelDensityDescriptorValue {
  14. double value { 0 };
  15. };
  16. struct WidthDescriptorValue {
  17. CSSPixels value { 0 };
  18. };
  19. String url;
  20. Variant<Empty, PixelDensityDescriptorValue, WidthDescriptorValue> descriptor;
  21. };
  22. struct ImageSourceAndPixelDensity {
  23. ImageSource source;
  24. double pixel_density { 1.0f };
  25. };
  26. // https://html.spec.whatwg.org/multipage/images.html#source-set
  27. struct SourceSet {
  28. static SourceSet create(DOM::Element const&, String default_source, String srcset, String sizes);
  29. [[nodiscard]] bool is_empty() const;
  30. // https://html.spec.whatwg.org/multipage/images.html#select-an-image-source-from-a-source-set
  31. [[nodiscard]] ImageSourceAndPixelDensity select_an_image_source();
  32. // https://html.spec.whatwg.org/multipage/images.html#normalise-the-source-densities
  33. void normalize_source_densities(DOM::Element const&);
  34. SourceSet();
  35. Vector<ImageSource> m_sources;
  36. CSS::LengthOrCalculated m_source_size;
  37. };
  38. SourceSet parse_a_srcset_attribute(StringView);
  39. [[nodiscard]] CSS::LengthOrCalculated parse_a_sizes_attribute(DOM::Document const&, StringView);
  40. }