mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +00:00
LibWeb: Make CSSStyleDeclaration GC-allocated
This commit is contained in:
parent
12042f0757
commit
72bacba97b
18 changed files with 146 additions and 129 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
@ -25,14 +25,14 @@ struct StyleProperty {
|
|||
String custom_name {};
|
||||
};
|
||||
|
||||
class CSSStyleDeclaration
|
||||
: public RefCounted<CSSStyleDeclaration>
|
||||
, public Bindings::Wrappable {
|
||||
public:
|
||||
using WrapperType = Bindings::CSSStyleDeclarationWrapper;
|
||||
class CSSStyleDeclaration : public Bindings::PlatformObject {
|
||||
JS_OBJECT(CSSStyleDeclaration, Bindings::PlatformObject);
|
||||
|
||||
public:
|
||||
virtual ~CSSStyleDeclaration() = default;
|
||||
|
||||
CSSStyleDeclaration& impl() { return *this; }
|
||||
|
||||
virtual size_t length() const = 0;
|
||||
virtual String item(size_t index) const = 0;
|
||||
|
||||
|
@ -52,18 +52,21 @@ public:
|
|||
|
||||
virtual String serialized() const = 0;
|
||||
|
||||
virtual JS::ThrowCompletionOr<bool> internal_has_property(JS::PropertyKey const& name) const override;
|
||||
virtual JS::ThrowCompletionOr<JS::Value> internal_get(JS::PropertyKey const&, JS::Value receiver) const override;
|
||||
virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyKey const&, JS::Value value, JS::Value receiver) override;
|
||||
|
||||
protected:
|
||||
CSSStyleDeclaration() = default;
|
||||
CSSStyleDeclaration(Bindings::WindowObject&);
|
||||
};
|
||||
|
||||
class PropertyOwningCSSStyleDeclaration : public CSSStyleDeclaration {
|
||||
JS_OBJECT(PropertyOwningCSSStyleDeclaration, CSSStyleDeclaration);
|
||||
friend class ElementInlineCSSStyleDeclaration;
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<PropertyOwningCSSStyleDeclaration> create(Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
|
||||
{
|
||||
return adopt_ref(*new PropertyOwningCSSStyleDeclaration(move(properties), move(custom_properties)));
|
||||
}
|
||||
static PropertyOwningCSSStyleDeclaration* create(Bindings::WindowObject&, Vector<StyleProperty>, HashMap<String, StyleProperty> custom_properties);
|
||||
PropertyOwningCSSStyleDeclaration(Bindings::WindowObject&, Vector<StyleProperty>, HashMap<String, StyleProperty>);
|
||||
|
||||
virtual ~PropertyOwningCSSStyleDeclaration() override = default;
|
||||
|
||||
|
@ -83,8 +86,6 @@ public:
|
|||
virtual String serialized() const final override;
|
||||
|
||||
protected:
|
||||
explicit PropertyOwningCSSStyleDeclaration(Vector<StyleProperty>, HashMap<String, StyleProperty>);
|
||||
|
||||
virtual void update_style_attribute() { }
|
||||
|
||||
private:
|
||||
|
@ -95,8 +96,12 @@ private:
|
|||
};
|
||||
|
||||
class ElementInlineCSSStyleDeclaration final : public PropertyOwningCSSStyleDeclaration {
|
||||
JS_OBJECT(ElementInlineCSSStyleDeclaration, PropertyOwningCSSStyleDeclaration);
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<ElementInlineCSSStyleDeclaration> create(DOM::Element& element, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties) { return adopt_ref(*new ElementInlineCSSStyleDeclaration(element, move(properties), move(custom_properties))); }
|
||||
static ElementInlineCSSStyleDeclaration* create(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties);
|
||||
explicit ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties);
|
||||
|
||||
virtual ~ElementInlineCSSStyleDeclaration() override = default;
|
||||
|
||||
DOM::Element* element() { return m_element.ptr(); }
|
||||
|
@ -105,8 +110,6 @@ public:
|
|||
bool is_updating() const { return m_updating; }
|
||||
|
||||
private:
|
||||
explicit ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties);
|
||||
|
||||
virtual void update_style_attribute() override;
|
||||
|
||||
WeakPtr<DOM::Element> m_element;
|
||||
|
@ -118,7 +121,6 @@ private:
|
|||
}
|
||||
|
||||
namespace Web::Bindings {
|
||||
|
||||
CSSStyleDeclarationWrapper* wrap(JS::Realm&, CSS::CSSStyleDeclaration&);
|
||||
|
||||
inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSStyleDeclaration& object) { return &object; }
|
||||
using CSSStyleDeclarationWrapper = Web::CSS::CSSStyleDeclaration;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue