mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-11 09:27:00 +02:00
Previously we were inconsistent by generating code for enum definitions but not generating code for dictionaries. With future changes to the IDL generator to expose helpers to convert to and from IDL values this produced circular depdendencies. To solve this problem, also generate the dictionary definitions in bindings headers.
63 lines
2.1 KiB
C++
63 lines
2.1 KiB
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
|
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
|
#include <LibWeb/Bindings/ResizeObserver.h>
|
|
#include <LibWeb/ResizeObserver/ResizeObservation.h>
|
|
#include <LibWeb/ResizeObserver/ResizeObserverEntry.h>
|
|
|
|
namespace Web::ResizeObserver {
|
|
|
|
// 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 constexpr bool OVERRIDES_FINALIZE = true;
|
|
|
|
static WebIDL::ExceptionOr<GC::Ref<ResizeObserver>> construct_impl(JS::Realm&, WebIDL::CallbackType* callback);
|
|
|
|
virtual ~ResizeObserver() override;
|
|
|
|
void observe(DOM::Element& target, Bindings::ResizeObserverOptions);
|
|
void unobserve(DOM::Element& target);
|
|
void disconnect();
|
|
|
|
void invoke_callback(ReadonlySpan<GC::Ref<ResizeObserverEntry>> entries) const;
|
|
|
|
Vector<GC::Ref<ResizeObservation>>& observation_targets() { return m_observation_targets; }
|
|
Vector<GC::Ref<ResizeObservation>>& active_targets() { return m_active_targets; }
|
|
Vector<GC::Ref<ResizeObservation>>& 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;
|
|
|
|
void unregister_observer_if_needed();
|
|
|
|
GC::Ptr<WebIDL::CallbackType> m_callback;
|
|
Vector<GC::Ref<ResizeObservation>> m_observation_targets;
|
|
Vector<GC::Ref<ResizeObservation>> m_active_targets;
|
|
Vector<GC::Ref<ResizeObservation>> m_skipped_targets;
|
|
|
|
// AD-HOC: This is the document where we've registered the observer.
|
|
GC::Weak<DOM::Document> m_document;
|
|
|
|
IntrusiveListNode<ResizeObserver> m_list_node;
|
|
|
|
public:
|
|
using ResizeObserversList = IntrusiveList<&ResizeObserver::m_list_node>;
|
|
};
|
|
|
|
}
|