MediaList.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
  3. * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
  4. * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/Optional.h>
  10. #include <LibJS/Runtime/Object.h>
  11. #include <LibWeb/Bindings/LegacyPlatformObject.h>
  12. #include <LibWeb/CSS/MediaQuery.h>
  13. namespace Web::CSS {
  14. // https://www.w3.org/TR/cssom-1/#the-medialist-interface
  15. class MediaList final : public Bindings::LegacyPlatformObject {
  16. WEB_PLATFORM_OBJECT(MediaList, Bindings::LegacyPlatformObject);
  17. public:
  18. static WebIDL::ExceptionOr<JS::NonnullGCPtr<MediaList>> create(JS::Realm&, Vector<NonnullRefPtr<MediaQuery>>&& media);
  19. ~MediaList() = default;
  20. DeprecatedString media_text() const;
  21. void set_media_text(DeprecatedString const&);
  22. size_t length() const { return m_media.size(); }
  23. DeprecatedString item(u32 index) const;
  24. void append_medium(DeprecatedString);
  25. void delete_medium(DeprecatedString);
  26. virtual bool is_supported_property_index(u32 index) const override;
  27. virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
  28. bool evaluate(HTML::Window const&);
  29. bool matches() const;
  30. private:
  31. MediaList(JS::Realm&, Vector<NonnullRefPtr<MediaQuery>>&&);
  32. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  33. // ^Bindings::LegacyPlatformObject
  34. virtual bool supports_indexed_properties() const override { return true; }
  35. virtual bool supports_named_properties() const override { return false; }
  36. virtual bool has_indexed_property_setter() const override { return false; }
  37. virtual bool has_named_property_setter() const override { return false; }
  38. virtual bool has_named_property_deleter() const override { return false; }
  39. virtual bool has_legacy_override_built_ins_interface_extended_attribute() const override { return false; }
  40. virtual bool has_legacy_unenumerable_named_properties_interface_extended_attribute() const override { return false; }
  41. virtual bool has_global_interface_extended_attribute() const override { return false; }
  42. virtual bool indexed_property_setter_has_identifier() const override { return false; }
  43. virtual bool named_property_setter_has_identifier() const override { return false; }
  44. virtual bool named_property_deleter_has_identifier() const override { return false; }
  45. Vector<NonnullRefPtr<MediaQuery>> m_media;
  46. };
  47. }