mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:07:34 +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,62 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <LibJS/Runtime/Completion.h>
|
|
||||||
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
|
|
||||||
#include <LibWeb/DOM/Element.h>
|
|
||||||
|
|
||||||
namespace Web::Bindings {
|
|
||||||
|
|
||||||
static CSS::PropertyID property_id_from_name(StringView name)
|
|
||||||
{
|
|
||||||
// FIXME: Perhaps this should go in the code generator.
|
|
||||||
if (name == "cssFloat"sv)
|
|
||||||
return CSS::PropertyID::Float;
|
|
||||||
|
|
||||||
if (auto property_id = CSS::property_id_from_camel_case_string(name); property_id != CSS::PropertyID::Invalid)
|
|
||||||
return property_id;
|
|
||||||
|
|
||||||
if (auto property_id = CSS::property_id_from_string(name); property_id != CSS::PropertyID::Invalid)
|
|
||||||
return property_id;
|
|
||||||
|
|
||||||
return CSS::PropertyID::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
JS::ThrowCompletionOr<bool> CSSStyleDeclarationWrapper::internal_has_property(JS::PropertyKey const& name) const
|
|
||||||
{
|
|
||||||
if (!name.is_string())
|
|
||||||
return Base::internal_has_property(name);
|
|
||||||
return property_id_from_name(name.to_string()) != CSS::PropertyID::Invalid;
|
|
||||||
}
|
|
||||||
|
|
||||||
JS::ThrowCompletionOr<JS::Value> CSSStyleDeclarationWrapper::internal_get(JS::PropertyKey const& name, JS::Value receiver) const
|
|
||||||
{
|
|
||||||
if (!name.is_string())
|
|
||||||
return Base::internal_get(name, receiver);
|
|
||||||
auto property_id = property_id_from_name(name.to_string());
|
|
||||||
if (property_id == CSS::PropertyID::Invalid)
|
|
||||||
return Base::internal_get(name, receiver);
|
|
||||||
if (auto maybe_property = impl().property(property_id); maybe_property.has_value())
|
|
||||||
return { js_string(vm(), maybe_property->value->to_string()) };
|
|
||||||
return { js_string(vm(), String::empty()) };
|
|
||||||
}
|
|
||||||
|
|
||||||
JS::ThrowCompletionOr<bool> CSSStyleDeclarationWrapper::internal_set(JS::PropertyKey const& name, JS::Value value, JS::Value receiver)
|
|
||||||
{
|
|
||||||
if (!name.is_string())
|
|
||||||
return Base::internal_set(name, value, receiver);
|
|
||||||
auto& vm = this->vm();
|
|
||||||
auto property_id = property_id_from_name(name.to_string());
|
|
||||||
if (property_id == CSS::PropertyID::Invalid)
|
|
||||||
return Base::internal_set(name, value, receiver);
|
|
||||||
|
|
||||||
auto css_text = TRY(value.to_string(vm));
|
|
||||||
|
|
||||||
impl().set_property(property_id, css_text);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include <LibJS/Runtime/Shape.h>
|
#include <LibJS/Runtime/Shape.h>
|
||||||
#include <LibTextCodec/Decoder.h>
|
#include <LibTextCodec/Decoder.h>
|
||||||
#include <LibWeb/Bindings/CSSNamespace.h>
|
#include <LibWeb/Bindings/CSSNamespace.h>
|
||||||
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
|
|
||||||
#include <LibWeb/Bindings/CryptoWrapper.h>
|
#include <LibWeb/Bindings/CryptoWrapper.h>
|
||||||
#include <LibWeb/Bindings/DocumentWrapper.h>
|
#include <LibWeb/Bindings/DocumentWrapper.h>
|
||||||
#include <LibWeb/Bindings/ElementWrapper.h>
|
#include <LibWeb/Bindings/ElementWrapper.h>
|
||||||
|
@ -526,7 +525,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_computed_style)
|
||||||
if (!is<ElementWrapper>(object))
|
if (!is<ElementWrapper>(object))
|
||||||
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "DOM element");
|
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "DOM element");
|
||||||
|
|
||||||
return wrap(realm, impl->get_computed_style(static_cast<ElementWrapper*>(object)->impl()));
|
return wrap(realm, *impl->get_computed_style(static_cast<ElementWrapper*>(object)->impl()));
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_selection)
|
JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_selection)
|
||||||
|
|
|
@ -4,7 +4,6 @@ set(SOURCES
|
||||||
Bindings/AudioConstructor.cpp
|
Bindings/AudioConstructor.cpp
|
||||||
Bindings/CrossOriginAbstractOperations.cpp
|
Bindings/CrossOriginAbstractOperations.cpp
|
||||||
Bindings/CSSNamespace.cpp
|
Bindings/CSSNamespace.cpp
|
||||||
Bindings/CSSStyleDeclarationWrapperCustom.cpp
|
|
||||||
Bindings/EventListenerWrapper.cpp
|
Bindings/EventListenerWrapper.cpp
|
||||||
Bindings/EventTargetWrapperFactory.cpp
|
Bindings/EventTargetWrapperFactory.cpp
|
||||||
Bindings/EventWrapperFactory.cpp
|
Bindings/EventWrapperFactory.cpp
|
||||||
|
|
|
@ -1,17 +1,31 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/CSSStyleDeclarationPrototype.h>
|
||||||
|
#include <LibWeb/Bindings/WindowObject.h>
|
||||||
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
||||||
#include <LibWeb/CSS/Parser/Parser.h>
|
#include <LibWeb/CSS/Parser/Parser.h>
|
||||||
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/Element.h>
|
#include <LibWeb/DOM/Element.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
|
CSSStyleDeclaration::CSSStyleDeclaration(Bindings::WindowObject& window_object)
|
||||||
: m_properties(move(properties))
|
: PlatformObject(window_object.ensure_web_prototype<Bindings::CSSStyleDeclarationPrototype>("CSSStyleDeclaration"))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertyOwningCSSStyleDeclaration* PropertyOwningCSSStyleDeclaration::create(Bindings::WindowObject& window_object, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
|
||||||
|
{
|
||||||
|
return window_object.heap().allocate<PropertyOwningCSSStyleDeclaration>(window_object.realm(), window_object, move(properties), move(custom_properties));
|
||||||
|
}
|
||||||
|
|
||||||
|
PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(Bindings::WindowObject& window_object, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
|
||||||
|
: CSSStyleDeclaration(window_object)
|
||||||
|
, m_properties(move(properties))
|
||||||
, m_custom_properties(move(custom_properties))
|
, m_custom_properties(move(custom_properties))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -23,8 +37,14 @@ String PropertyOwningCSSStyleDeclaration::item(size_t index) const
|
||||||
return CSS::string_from_property_id(m_properties[index].property_id);
|
return CSS::string_from_property_id(m_properties[index].property_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ElementInlineCSSStyleDeclaration* ElementInlineCSSStyleDeclaration::create(DOM::Element& element, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
|
||||||
|
{
|
||||||
|
auto& window_object = element.document().preferred_window_object();
|
||||||
|
return window_object.heap().allocate<ElementInlineCSSStyleDeclaration>(window_object.realm(), element, move(properties), move(custom_properties));
|
||||||
|
}
|
||||||
|
|
||||||
ElementInlineCSSStyleDeclaration::ElementInlineCSSStyleDeclaration(DOM::Element& element, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
|
ElementInlineCSSStyleDeclaration::ElementInlineCSSStyleDeclaration(DOM::Element& element, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
|
||||||
: PropertyOwningCSSStyleDeclaration(move(properties), move(custom_properties))
|
: PropertyOwningCSSStyleDeclaration(element.document().preferred_window_object(), move(properties), move(custom_properties))
|
||||||
, m_element(element.make_weak_ptr<DOM::Element>())
|
, m_element(element.make_weak_ptr<DOM::Element>())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -284,4 +304,52 @@ String PropertyOwningCSSStyleDeclaration::serialized() const
|
||||||
return builder.to_string();
|
return builder.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CSS::PropertyID property_id_from_name(StringView name)
|
||||||
|
{
|
||||||
|
// FIXME: Perhaps this should go in the code generator.
|
||||||
|
if (name == "cssFloat"sv)
|
||||||
|
return CSS::PropertyID::Float;
|
||||||
|
|
||||||
|
if (auto property_id = CSS::property_id_from_camel_case_string(name); property_id != CSS::PropertyID::Invalid)
|
||||||
|
return property_id;
|
||||||
|
|
||||||
|
if (auto property_id = CSS::property_id_from_string(name); property_id != CSS::PropertyID::Invalid)
|
||||||
|
return property_id;
|
||||||
|
|
||||||
|
return CSS::PropertyID::Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS::ThrowCompletionOr<bool> CSSStyleDeclaration::internal_has_property(JS::PropertyKey const& name) const
|
||||||
|
{
|
||||||
|
if (!name.is_string())
|
||||||
|
return Base::internal_has_property(name);
|
||||||
|
return property_id_from_name(name.to_string()) != CSS::PropertyID::Invalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS::ThrowCompletionOr<JS::Value> CSSStyleDeclaration::internal_get(JS::PropertyKey const& name, JS::Value receiver) const
|
||||||
|
{
|
||||||
|
if (!name.is_string())
|
||||||
|
return Base::internal_get(name, receiver);
|
||||||
|
auto property_id = property_id_from_name(name.to_string());
|
||||||
|
if (property_id == CSS::PropertyID::Invalid)
|
||||||
|
return Base::internal_get(name, receiver);
|
||||||
|
if (auto maybe_property = property(property_id); maybe_property.has_value())
|
||||||
|
return { js_string(vm(), maybe_property->value->to_string()) };
|
||||||
|
return { js_string(vm(), String::empty()) };
|
||||||
|
}
|
||||||
|
|
||||||
|
JS::ThrowCompletionOr<bool> CSSStyleDeclaration::internal_set(JS::PropertyKey const& name, JS::Value value, JS::Value receiver)
|
||||||
|
{
|
||||||
|
if (!name.is_string())
|
||||||
|
return Base::internal_set(name, value, receiver);
|
||||||
|
auto property_id = property_id_from_name(name.to_string());
|
||||||
|
if (property_id == CSS::PropertyID::Invalid)
|
||||||
|
return Base::internal_set(name, value, receiver);
|
||||||
|
|
||||||
|
auto css_text = TRY(value.to_string(vm()));
|
||||||
|
|
||||||
|
impl().set_property(property_id, css_text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibWeb/Bindings/Wrappable.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
#include <LibWeb/CSS/StyleValue.h>
|
#include <LibWeb/CSS/StyleValue.h>
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
@ -25,14 +25,14 @@ struct StyleProperty {
|
||||||
String custom_name {};
|
String custom_name {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class CSSStyleDeclaration
|
class CSSStyleDeclaration : public Bindings::PlatformObject {
|
||||||
: public RefCounted<CSSStyleDeclaration>
|
JS_OBJECT(CSSStyleDeclaration, Bindings::PlatformObject);
|
||||||
, public Bindings::Wrappable {
|
|
||||||
public:
|
|
||||||
using WrapperType = Bindings::CSSStyleDeclarationWrapper;
|
|
||||||
|
|
||||||
|
public:
|
||||||
virtual ~CSSStyleDeclaration() = default;
|
virtual ~CSSStyleDeclaration() = default;
|
||||||
|
|
||||||
|
CSSStyleDeclaration& impl() { return *this; }
|
||||||
|
|
||||||
virtual size_t length() const = 0;
|
virtual size_t length() const = 0;
|
||||||
virtual String item(size_t index) const = 0;
|
virtual String item(size_t index) const = 0;
|
||||||
|
|
||||||
|
@ -52,18 +52,21 @@ public:
|
||||||
|
|
||||||
virtual String serialized() const = 0;
|
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:
|
protected:
|
||||||
CSSStyleDeclaration() = default;
|
CSSStyleDeclaration(Bindings::WindowObject&);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PropertyOwningCSSStyleDeclaration : public CSSStyleDeclaration {
|
class PropertyOwningCSSStyleDeclaration : public CSSStyleDeclaration {
|
||||||
|
JS_OBJECT(PropertyOwningCSSStyleDeclaration, CSSStyleDeclaration);
|
||||||
friend class ElementInlineCSSStyleDeclaration;
|
friend class ElementInlineCSSStyleDeclaration;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<PropertyOwningCSSStyleDeclaration> create(Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
|
static PropertyOwningCSSStyleDeclaration* create(Bindings::WindowObject&, Vector<StyleProperty>, HashMap<String, StyleProperty> custom_properties);
|
||||||
{
|
PropertyOwningCSSStyleDeclaration(Bindings::WindowObject&, Vector<StyleProperty>, HashMap<String, StyleProperty>);
|
||||||
return adopt_ref(*new PropertyOwningCSSStyleDeclaration(move(properties), move(custom_properties)));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~PropertyOwningCSSStyleDeclaration() override = default;
|
virtual ~PropertyOwningCSSStyleDeclaration() override = default;
|
||||||
|
|
||||||
|
@ -83,8 +86,6 @@ public:
|
||||||
virtual String serialized() const final override;
|
virtual String serialized() const final override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit PropertyOwningCSSStyleDeclaration(Vector<StyleProperty>, HashMap<String, StyleProperty>);
|
|
||||||
|
|
||||||
virtual void update_style_attribute() { }
|
virtual void update_style_attribute() { }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -95,8 +96,12 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
class ElementInlineCSSStyleDeclaration final : public PropertyOwningCSSStyleDeclaration {
|
class ElementInlineCSSStyleDeclaration final : public PropertyOwningCSSStyleDeclaration {
|
||||||
|
JS_OBJECT(ElementInlineCSSStyleDeclaration, PropertyOwningCSSStyleDeclaration);
|
||||||
|
|
||||||
public:
|
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;
|
virtual ~ElementInlineCSSStyleDeclaration() override = default;
|
||||||
|
|
||||||
DOM::Element* element() { return m_element.ptr(); }
|
DOM::Element* element() { return m_element.ptr(); }
|
||||||
|
@ -105,8 +110,6 @@ public:
|
||||||
bool is_updating() const { return m_updating; }
|
bool is_updating() const { return m_updating; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties);
|
|
||||||
|
|
||||||
virtual void update_style_attribute() override;
|
virtual void update_style_attribute() override;
|
||||||
|
|
||||||
WeakPtr<DOM::Element> m_element;
|
WeakPtr<DOM::Element> m_element;
|
||||||
|
@ -118,7 +121,6 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Web::Bindings {
|
namespace Web::Bindings {
|
||||||
|
inline JS::Object* wrap(JS::Realm&, Web::CSS::CSSStyleDeclaration& object) { return &object; }
|
||||||
CSSStyleDeclarationWrapper* wrap(JS::Realm&, CSS::CSSStyleDeclaration&);
|
using CSSStyleDeclarationWrapper = Web::CSS::CSSStyleDeclaration;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[CustomGet,CustomSet,CustomHasProperty]
|
[NoInstanceWrapper]
|
||||||
interface CSSStyleDeclaration {
|
interface CSSStyleDeclaration {
|
||||||
|
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
|
|
|
@ -11,23 +11,29 @@
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
CSSStyleRule* CSSStyleRule::create(Bindings::WindowObject& window_object, NonnullRefPtrVector<Web::CSS::Selector>&& selectors, NonnullRefPtr<Web::CSS::CSSStyleDeclaration>&& declaration)
|
CSSStyleRule* CSSStyleRule::create(Bindings::WindowObject& window_object, NonnullRefPtrVector<Web::CSS::Selector>&& selectors, CSSStyleDeclaration& declaration)
|
||||||
{
|
{
|
||||||
return window_object.heap().allocate<CSSStyleRule>(window_object.realm(), window_object, move(selectors), move(declaration));
|
return window_object.heap().allocate<CSSStyleRule>(window_object.realm(), window_object, move(selectors), declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSStyleRule::CSSStyleRule(Bindings::WindowObject& window_object, NonnullRefPtrVector<Selector>&& selectors, NonnullRefPtr<CSSStyleDeclaration>&& declaration)
|
CSSStyleRule::CSSStyleRule(Bindings::WindowObject& window_object, NonnullRefPtrVector<Selector>&& selectors, CSSStyleDeclaration& declaration)
|
||||||
: CSSRule(window_object)
|
: CSSRule(window_object)
|
||||||
, m_selectors(move(selectors))
|
, m_selectors(move(selectors))
|
||||||
, m_declaration(move(declaration))
|
, m_declaration(declaration)
|
||||||
{
|
{
|
||||||
set_prototype(&window_object.ensure_web_prototype<Bindings::CSSStyleRulePrototype>("CSSStyleRule"));
|
set_prototype(&window_object.ensure_web_prototype<Bindings::CSSStyleRulePrototype>("CSSStyleRule"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSSStyleRule::visit_edges(Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(&m_declaration);
|
||||||
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/cssom/#dom-cssstylerule-style
|
// https://www.w3.org/TR/cssom/#dom-cssstylerule-style
|
||||||
CSSStyleDeclaration* CSSStyleRule::style()
|
CSSStyleDeclaration* CSSStyleRule::style()
|
||||||
{
|
{
|
||||||
return m_declaration;
|
return &m_declaration;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/cssom/#serialize-a-css-rule
|
// https://www.w3.org/TR/cssom/#serialize-a-css-rule
|
||||||
|
|
|
@ -21,8 +21,8 @@ class CSSStyleRule final : public CSSRule {
|
||||||
AK_MAKE_NONMOVABLE(CSSStyleRule);
|
AK_MAKE_NONMOVABLE(CSSStyleRule);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static CSSStyleRule* create(Bindings::WindowObject&, NonnullRefPtrVector<Selector>&&, NonnullRefPtr<CSSStyleDeclaration>&&);
|
static CSSStyleRule* create(Bindings::WindowObject&, NonnullRefPtrVector<Selector>&&, CSSStyleDeclaration&);
|
||||||
CSSStyleRule(Bindings::WindowObject&, NonnullRefPtrVector<Selector>&&, NonnullRefPtr<CSSStyleDeclaration>&&);
|
CSSStyleRule(Bindings::WindowObject&, NonnullRefPtrVector<Selector>&&, CSSStyleDeclaration&);
|
||||||
|
|
||||||
virtual ~CSSStyleRule() override = default;
|
virtual ~CSSStyleRule() override = default;
|
||||||
|
|
||||||
|
@ -39,10 +39,11 @@ public:
|
||||||
CSSStyleDeclaration* style();
|
CSSStyleDeclaration* style();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
virtual String serialized() const override;
|
virtual String serialized() const override;
|
||||||
|
|
||||||
NonnullRefPtrVector<Selector> m_selectors;
|
NonnullRefPtrVector<Selector> m_selectors;
|
||||||
NonnullRefPtr<CSSStyleDeclaration> m_declaration;
|
CSSStyleDeclaration& m_declaration;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
@ -2320,7 +2320,7 @@ Vector<Vector<ComponentValue>> Parser::parse_a_comma_separated_list_of_component
|
||||||
return list_of_component_value_lists;
|
return list_of_component_value_lists;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<ElementInlineCSSStyleDeclaration> Parser::parse_as_style_attribute(DOM::Element& element)
|
ElementInlineCSSStyleDeclaration* Parser::parse_as_style_attribute(DOM::Element& element)
|
||||||
{
|
{
|
||||||
auto declarations_and_at_rules = parse_a_list_of_declarations(m_token_stream);
|
auto declarations_and_at_rules = parse_a_list_of_declarations(m_token_stream);
|
||||||
auto [properties, custom_properties] = extract_properties(declarations_and_at_rules);
|
auto [properties, custom_properties] = extract_properties(declarations_and_at_rules);
|
||||||
|
@ -2706,13 +2706,13 @@ CSSRule* Parser::convert_to_rule(NonnullRefPtr<Rule> rule)
|
||||||
auto stream = TokenStream(rule->block()->values());
|
auto stream = TokenStream(rule->block()->values());
|
||||||
auto declarations_and_at_rules = parse_a_style_blocks_contents(stream);
|
auto declarations_and_at_rules = parse_a_style_blocks_contents(stream);
|
||||||
|
|
||||||
auto declaration = convert_to_style_declaration(declarations_and_at_rules);
|
auto* declaration = convert_to_style_declaration(declarations_and_at_rules);
|
||||||
if (!declaration) {
|
if (!declaration) {
|
||||||
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: style rule declaration invalid; discarding.");
|
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: style rule declaration invalid; discarding.");
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return CSSStyleRule::create(m_context.window_object(), move(selectors.value()), move(*declaration));
|
return CSSStyleRule::create(m_context.window_object(), move(selectors.value()), *declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
|
@ -2741,10 +2741,10 @@ auto Parser::extract_properties(Vector<DeclarationOrAtRule> const& declarations_
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<PropertyOwningCSSStyleDeclaration> Parser::convert_to_style_declaration(Vector<DeclarationOrAtRule> declarations_and_at_rules)
|
PropertyOwningCSSStyleDeclaration* Parser::convert_to_style_declaration(Vector<DeclarationOrAtRule> declarations_and_at_rules)
|
||||||
{
|
{
|
||||||
auto [properties, custom_properties] = extract_properties(declarations_and_at_rules);
|
auto [properties, custom_properties] = extract_properties(declarations_and_at_rules);
|
||||||
return PropertyOwningCSSStyleDeclaration::create(move(properties), move(custom_properties));
|
return PropertyOwningCSSStyleDeclaration::create(m_context.window_object(), move(properties), move(custom_properties));
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& declaration)
|
Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& declaration)
|
||||||
|
@ -6396,7 +6396,7 @@ CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& cont
|
||||||
return parser.parse_as_css_stylesheet(location);
|
return parser.parse_as_css_stylesheet(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefPtr<CSS::ElementInlineCSSStyleDeclaration> parse_css_style_attribute(CSS::Parser::ParsingContext const& context, StringView css, DOM::Element& element)
|
CSS::ElementInlineCSSStyleDeclaration* parse_css_style_attribute(CSS::Parser::ParsingContext const& context, StringView css, DOM::Element& element)
|
||||||
{
|
{
|
||||||
if (css.is_empty())
|
if (css.is_empty())
|
||||||
return CSS::ElementInlineCSSStyleDeclaration::create(element, {}, {});
|
return CSS::ElementInlineCSSStyleDeclaration::create(element, {}, {});
|
||||||
|
|
|
@ -127,7 +127,7 @@ public:
|
||||||
~Parser() = default;
|
~Parser() = default;
|
||||||
|
|
||||||
CSSStyleSheet* parse_as_css_stylesheet(Optional<AK::URL> location);
|
CSSStyleSheet* parse_as_css_stylesheet(Optional<AK::URL> location);
|
||||||
RefPtr<ElementInlineCSSStyleDeclaration> parse_as_style_attribute(DOM::Element&);
|
ElementInlineCSSStyleDeclaration* parse_as_style_attribute(DOM::Element&);
|
||||||
CSSRule* parse_as_css_rule();
|
CSSRule* parse_as_css_rule();
|
||||||
Optional<StyleProperty> parse_as_supports_condition();
|
Optional<StyleProperty> parse_as_supports_condition();
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ private:
|
||||||
Vector<FontFace::Source> parse_font_face_src(TokenStream<ComponentValue>&);
|
Vector<FontFace::Source> parse_font_face_src(TokenStream<ComponentValue>&);
|
||||||
|
|
||||||
CSSRule* convert_to_rule(NonnullRefPtr<Rule>);
|
CSSRule* convert_to_rule(NonnullRefPtr<Rule>);
|
||||||
RefPtr<PropertyOwningCSSStyleDeclaration> convert_to_style_declaration(Vector<DeclarationOrAtRule> declarations);
|
PropertyOwningCSSStyleDeclaration* convert_to_style_declaration(Vector<DeclarationOrAtRule> declarations);
|
||||||
Optional<StyleProperty> convert_to_style_property(Declaration const&);
|
Optional<StyleProperty> convert_to_style_property(Declaration const&);
|
||||||
|
|
||||||
class Dimension {
|
class Dimension {
|
||||||
|
@ -421,7 +421,7 @@ private:
|
||||||
namespace Web {
|
namespace Web {
|
||||||
|
|
||||||
CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const&, StringView, Optional<AK::URL> location = {});
|
CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const&, StringView, Optional<AK::URL> location = {});
|
||||||
RefPtr<CSS::ElementInlineCSSStyleDeclaration> parse_css_style_attribute(CSS::Parser::ParsingContext const&, StringView, DOM::Element&);
|
CSS::ElementInlineCSSStyleDeclaration* parse_css_style_attribute(CSS::Parser::ParsingContext const&, StringView, DOM::Element&);
|
||||||
RefPtr<CSS::StyleValue> parse_css_value(CSS::Parser::ParsingContext const&, StringView, CSS::PropertyID property_id = CSS::PropertyID::Invalid);
|
RefPtr<CSS::StyleValue> parse_css_value(CSS::Parser::ParsingContext const&, StringView, CSS::PropertyID property_id = CSS::PropertyID::Invalid);
|
||||||
Optional<CSS::SelectorList> parse_selector(CSS::Parser::ParsingContext const&, StringView);
|
Optional<CSS::SelectorList> parse_selector(CSS::Parser::ParsingContext const&, StringView);
|
||||||
CSS::CSSRule* parse_css_rule(CSS::Parser::ParsingContext const&, StringView);
|
CSS::CSSRule* parse_css_rule(CSS::Parser::ParsingContext const&, StringView);
|
||||||
|
|
|
@ -19,8 +19,15 @@
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
ResolvedCSSStyleDeclaration* ResolvedCSSStyleDeclaration::create(DOM::Element& element)
|
||||||
|
{
|
||||||
|
auto& window_object = element.document().preferred_window_object();
|
||||||
|
return window_object.heap().allocate<ResolvedCSSStyleDeclaration>(window_object.realm(), element);
|
||||||
|
}
|
||||||
|
|
||||||
ResolvedCSSStyleDeclaration::ResolvedCSSStyleDeclaration(DOM::Element& element)
|
ResolvedCSSStyleDeclaration::ResolvedCSSStyleDeclaration(DOM::Element& element)
|
||||||
: m_element(element)
|
: CSSStyleDeclaration(element.document().preferred_window_object())
|
||||||
|
, m_element(element)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
class ResolvedCSSStyleDeclaration final : public CSSStyleDeclaration {
|
class ResolvedCSSStyleDeclaration final : public CSSStyleDeclaration {
|
||||||
|
JS_OBJECT(ResolvedCSSStyleDeclaration, CSSStyleDeclaration);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static NonnullRefPtr<ResolvedCSSStyleDeclaration> create(DOM::Element& element)
|
static ResolvedCSSStyleDeclaration* create(DOM::Element& element);
|
||||||
{
|
explicit ResolvedCSSStyleDeclaration(DOM::Element&);
|
||||||
return adopt_ref(*new ResolvedCSSStyleDeclaration(element));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~ResolvedCSSStyleDeclaration() override = default;
|
virtual ~ResolvedCSSStyleDeclaration() override = default;
|
||||||
|
|
||||||
|
@ -28,8 +28,6 @@ public:
|
||||||
virtual String serialized() const override;
|
virtual String serialized() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ResolvedCSSStyleDeclaration(DOM::Element&);
|
|
||||||
|
|
||||||
RefPtr<StyleValue> style_value_for_property(Layout::NodeWithStyle const&, PropertyID) const;
|
RefPtr<StyleValue> style_value_for_property(Layout::NodeWithStyle const&, PropertyID) const;
|
||||||
|
|
||||||
NonnullRefPtr<DOM::Element> m_element;
|
NonnullRefPtr<DOM::Element> m_element;
|
||||||
|
|
|
@ -295,7 +295,7 @@ RefPtr<Layout::Node> Element::create_layout_node_for_display_type(DOM::Document&
|
||||||
|
|
||||||
CSS::CSSStyleDeclaration const* Element::inline_style() const
|
CSS::CSSStyleDeclaration const* Element::inline_style() const
|
||||||
{
|
{
|
||||||
return m_inline_style;
|
return m_inline_style.cell();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Element::parse_attribute(FlyString const& name, String const& value)
|
void Element::parse_attribute(FlyString const& name, String const& value)
|
||||||
|
@ -311,9 +311,9 @@ void Element::parse_attribute(FlyString const& name, String const& value)
|
||||||
m_class_list->associated_attribute_changed(value);
|
m_class_list->associated_attribute_changed(value);
|
||||||
} else if (name == HTML::AttributeNames::style) {
|
} else if (name == HTML::AttributeNames::style) {
|
||||||
// https://drafts.csswg.org/cssom/#ref-for-cssstyledeclaration-updating-flag
|
// https://drafts.csswg.org/cssom/#ref-for-cssstyledeclaration-updating-flag
|
||||||
if (m_inline_style && m_inline_style->is_updating())
|
if (m_inline_style.cell() && m_inline_style->is_updating())
|
||||||
return;
|
return;
|
||||||
m_inline_style = parse_css_style_attribute(CSS::Parser::ParsingContext(document()), value, *this);
|
m_inline_style = JS::make_handle(parse_css_style_attribute(CSS::Parser::ParsingContext(document()), value, *this));
|
||||||
set_needs_style_update(true);
|
set_needs_style_update(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -321,8 +321,8 @@ void Element::parse_attribute(FlyString const& name, String const& value)
|
||||||
void Element::did_remove_attribute(FlyString const& name)
|
void Element::did_remove_attribute(FlyString const& name)
|
||||||
{
|
{
|
||||||
if (name == HTML::AttributeNames::style) {
|
if (name == HTML::AttributeNames::style) {
|
||||||
if (m_inline_style) {
|
if (m_inline_style.cell()) {
|
||||||
m_inline_style = nullptr;
|
m_inline_style = {};
|
||||||
set_needs_style_update(true);
|
set_needs_style_update(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -507,11 +507,11 @@ void Element::set_shadow_root(RefPtr<ShadowRoot> shadow_root)
|
||||||
invalidate_style();
|
invalidate_style();
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<CSS::CSSStyleDeclaration> Element::style_for_bindings()
|
CSS::CSSStyleDeclaration* Element::style_for_bindings()
|
||||||
{
|
{
|
||||||
if (!m_inline_style)
|
if (m_inline_style.is_null())
|
||||||
m_inline_style = CSS::ElementInlineCSSStyleDeclaration::create(*this, {}, {});
|
m_inline_style = JS::make_handle(CSS::ElementInlineCSSStyleDeclaration::create(*this, {}, {}));
|
||||||
return *m_inline_style;
|
return m_inline_style.cell();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#element-html-uppercased-qualified-name
|
// https://dom.spec.whatwg.org/#element-html-uppercased-qualified-name
|
||||||
|
|
|
@ -105,7 +105,7 @@ public:
|
||||||
|
|
||||||
CSS::CSSStyleDeclaration const* inline_style() const;
|
CSS::CSSStyleDeclaration const* inline_style() const;
|
||||||
|
|
||||||
NonnullRefPtr<CSS::CSSStyleDeclaration> style_for_bindings();
|
CSS::CSSStyleDeclaration* style_for_bindings();
|
||||||
|
|
||||||
String inner_html() const;
|
String inner_html() const;
|
||||||
ExceptionOr<void> set_inner_html(String const&);
|
ExceptionOr<void> set_inner_html(String const&);
|
||||||
|
@ -152,7 +152,7 @@ private:
|
||||||
String m_html_uppercased_qualified_name;
|
String m_html_uppercased_qualified_name;
|
||||||
NonnullRefPtr<NamedNodeMap> m_attributes;
|
NonnullRefPtr<NamedNodeMap> m_attributes;
|
||||||
|
|
||||||
RefPtr<CSS::ElementInlineCSSStyleDeclaration> m_inline_style;
|
JS::Handle<CSS::ElementInlineCSSStyleDeclaration> m_inline_style;
|
||||||
|
|
||||||
RefPtr<CSS::StyleProperties> m_computed_css_values;
|
RefPtr<CSS::StyleProperties> m_computed_css_values;
|
||||||
HashMap<FlyString, CSS::StyleProperty> m_custom_properties;
|
HashMap<FlyString, CSS::StyleProperty> m_custom_properties;
|
||||||
|
|
|
@ -459,7 +459,6 @@ class CharacterDataWrapper;
|
||||||
class CloseEventWrapper;
|
class CloseEventWrapper;
|
||||||
class CommentWrapper;
|
class CommentWrapper;
|
||||||
class CryptoWrapper;
|
class CryptoWrapper;
|
||||||
class CSSStyleDeclarationWrapper;
|
|
||||||
class CustomEventWrapper;
|
class CustomEventWrapper;
|
||||||
class DocumentFragmentWrapper;
|
class DocumentFragmentWrapper;
|
||||||
class DocumentTypeWrapper;
|
class DocumentTypeWrapper;
|
||||||
|
|
|
@ -319,7 +319,7 @@ Page const* Window::page() const
|
||||||
return associated_document().page();
|
return associated_document().page();
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<CSS::CSSStyleDeclaration> Window::get_computed_style(DOM::Element& element) const
|
CSS::CSSStyleDeclaration* Window::get_computed_style(DOM::Element& element) const
|
||||||
{
|
{
|
||||||
return CSS::ResolvedCSSStyleDeclaration::create(element);
|
return CSS::ResolvedCSSStyleDeclaration::create(element);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ public:
|
||||||
DOM::Event const* current_event() const { return m_current_event; }
|
DOM::Event const* current_event() const { return m_current_event; }
|
||||||
void set_current_event(DOM::Event* event) { m_current_event = event; }
|
void set_current_event(DOM::Event* event) { m_current_event = event; }
|
||||||
|
|
||||||
NonnullRefPtr<CSS::CSSStyleDeclaration> get_computed_style(DOM::Element&) const;
|
CSS::CSSStyleDeclaration* get_computed_style(DOM::Element&) const;
|
||||||
NonnullRefPtr<CSS::MediaQueryList> match_media(String);
|
NonnullRefPtr<CSS::MediaQueryList> match_media(String);
|
||||||
Optional<CSS::MediaFeatureValue> query_media_feature(CSS::MediaFeatureID) const;
|
Optional<CSS::MediaFeatureValue> query_media_feature(CSS::MediaFeatureID) const;
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ libweb_js_wrapper(CSS/CSSImportRule NO_INSTANCE)
|
||||||
libweb_js_wrapper(CSS/CSSMediaRule NO_INSTANCE)
|
libweb_js_wrapper(CSS/CSSMediaRule NO_INSTANCE)
|
||||||
libweb_js_wrapper(CSS/CSSRule NO_INSTANCE)
|
libweb_js_wrapper(CSS/CSSRule NO_INSTANCE)
|
||||||
libweb_js_wrapper(CSS/CSSRuleList NO_INSTANCE)
|
libweb_js_wrapper(CSS/CSSRuleList NO_INSTANCE)
|
||||||
libweb_js_wrapper(CSS/CSSStyleDeclaration)
|
libweb_js_wrapper(CSS/CSSStyleDeclaration NO_INSTANCE)
|
||||||
libweb_js_wrapper(CSS/CSSStyleRule NO_INSTANCE)
|
libweb_js_wrapper(CSS/CSSStyleRule NO_INSTANCE)
|
||||||
libweb_js_wrapper(CSS/CSSStyleSheet NO_INSTANCE)
|
libweb_js_wrapper(CSS/CSSStyleSheet NO_INSTANCE)
|
||||||
libweb_js_wrapper(CSS/CSSSupportsRule NO_INSTANCE)
|
libweb_js_wrapper(CSS/CSSSupportsRule NO_INSTANCE)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue