IntersectionObserver.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibJS/Heap/Handle.h>
  8. #include <LibWeb/Bindings/PlatformObject.h>
  9. namespace Web::IntersectionObserver {
  10. struct IntersectionObserverInit {
  11. Optional<Variant<JS::Handle<DOM::Element>, JS::Handle<DOM::Document>>> root;
  12. DeprecatedString root_margin { "0px"sv };
  13. Variant<double, Vector<double>> threshold { 0 };
  14. };
  15. // https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
  16. class IntersectionObserver : public Bindings::PlatformObject {
  17. WEB_PLATFORM_OBJECT(IntersectionObserver, Bindings::PlatformObject);
  18. public:
  19. static WebIDL::ExceptionOr<JS::NonnullGCPtr<IntersectionObserver>> construct_impl(JS::Realm&, WebIDL::CallbackType* callback, IntersectionObserverInit const& options = {});
  20. virtual ~IntersectionObserver() override;
  21. void observe(DOM::Element& target);
  22. void unobserve(DOM::Element& target);
  23. void disconnect();
  24. private:
  25. explicit IntersectionObserver(JS::Realm&);
  26. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  27. };
  28. }