IntersectionObserver.h 930 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2021, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/NonnullRefPtr.h>
  8. #include <AK/RefCounted.h>
  9. #include <LibWeb/Bindings/Wrappable.h>
  10. namespace Web::IntersectionObserver {
  11. struct IntersectionObserverInit {
  12. DOM::Node* root { nullptr };
  13. String root_margin { "0px"sv };
  14. JS::Value threshold { 0 };
  15. };
  16. // https://w3c.github.io/IntersectionObserver/#intersection-observer-interface
  17. class IntersectionObserver
  18. : public RefCounted<IntersectionObserver>
  19. , public Bindings::Wrappable {
  20. public:
  21. using WrapperType = Bindings::IntersectionObserverWrapper;
  22. static NonnullRefPtr<IntersectionObserver> create_with_global_object(JS::GlobalObject&, JS::Value callback, IntersectionObserverInit const& options = {});
  23. void observe(DOM::Element& target);
  24. void unobserve(DOM::Element& target);
  25. void disconnect();
  26. };
  27. }