MediaQueryList.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. public:
  15. static WebIDL::ExceptionOr<JS::NonnullGCPtr<MediaQueryList>> create(DOM::Document&, Vector<NonnullRefPtr<MediaQuery>>&&);
  16. virtual ~MediaQueryList() override = default;
  17. DeprecatedString media() const;
  18. bool matches() const;
  19. bool evaluate();
  20. void add_listener(DOM::IDLEventListener*);
  21. void remove_listener(DOM::IDLEventListener*);
  22. void set_onchange(WebIDL::CallbackType*);
  23. WebIDL::CallbackType* onchange();
  24. private:
  25. MediaQueryList(DOM::Document&, Vector<NonnullRefPtr<MediaQuery>>&&);
  26. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  27. virtual void visit_edges(Cell::Visitor&) override;
  28. JS::NonnullGCPtr<DOM::Document> m_document;
  29. Vector<NonnullRefPtr<MediaQuery>> m_media;
  30. };
  31. }