MediaQueryList.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Forward.h>
  8. #include <LibWeb/CSS/MediaQuery.h>
  9. #include <LibWeb/DOM/EventTarget.h>
  10. namespace Web::CSS {
  11. // 4.2. The MediaQueryList Interface, https://drafts.csswg.org/cssom-view/#the-mediaquerylist-interface
  12. class MediaQueryList final : public DOM::EventTarget {
  13. WEB_PLATFORM_OBJECT(MediaQueryList, DOM::EventTarget);
  14. JS_DECLARE_ALLOCATOR(MediaQueryList);
  15. public:
  16. [[nodiscard]] static JS::NonnullGCPtr<MediaQueryList> create(DOM::Document&, Vector<NonnullRefPtr<MediaQuery>>&&);
  17. virtual ~MediaQueryList() override = default;
  18. String media() const;
  19. bool matches() const;
  20. bool evaluate();
  21. void add_listener(DOM::IDLEventListener*);
  22. void remove_listener(DOM::IDLEventListener*);
  23. void set_onchange(WebIDL::CallbackType*);
  24. WebIDL::CallbackType* onchange();
  25. private:
  26. MediaQueryList(DOM::Document&, Vector<NonnullRefPtr<MediaQuery>>&&);
  27. virtual void initialize(JS::Realm&) override;
  28. virtual void visit_edges(Cell::Visitor&) override;
  29. JS::NonnullGCPtr<DOM::Document> m_document;
  30. Vector<NonnullRefPtr<MediaQuery>> m_media;
  31. };
  32. }