/* * Copyright (c) 2021, Andreas Kling * Copyright (c) 2024, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace Web::ResizeObserver { struct ResizeObserverOptions { Bindings::ResizeObserverBoxOptions box; }; // https://drafts.csswg.org/resize-observer-1/#resize-observer-interface class ResizeObserver : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(ResizeObserver, Bindings::PlatformObject); GC_DECLARE_ALLOCATOR(ResizeObserver); public: static WebIDL::ExceptionOr> construct_impl(JS::Realm&, WebIDL::CallbackType* callback); virtual ~ResizeObserver() override; void observe(DOM::Element& target, ResizeObserverOptions); void unobserve(DOM::Element& target); void disconnect(); void invoke_callback(ReadonlySpan> entries) const; Vector>& observation_targets() { return m_observation_targets; } Vector>& active_targets() { return m_active_targets; } Vector>& skipped_targets() { return m_skipped_targets; } private: explicit ResizeObserver(JS::Realm&, WebIDL::CallbackType* callback); virtual void initialize(JS::Realm&) override; virtual void visit_edges(JS::Cell::Visitor&) override; virtual void finalize() override; GC::Ptr m_callback; Vector> m_observation_targets; Vector> m_active_targets; Vector> m_skipped_targets; // AD-HOC: This is the document where we've registered the observer. WeakPtr m_document; }; }