mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-23 02:55:15 +00:00
LibWeb: Port custom properties to FlyString
This commit is contained in:
parent
346825bd78
commit
ea2b733862
|
@ -27,12 +27,12 @@ void CSSStyleDeclaration::initialize(JS::Realm& realm)
|
|||
set_prototype(&Bindings::ensure_web_prototype<Bindings::CSSStyleDeclarationPrototype>(realm, "CSSStyleDeclaration"));
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration> PropertyOwningCSSStyleDeclaration::create(JS::Realm& realm, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties)
|
||||
JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration> PropertyOwningCSSStyleDeclaration::create(JS::Realm& realm, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties)
|
||||
{
|
||||
return realm.heap().allocate<PropertyOwningCSSStyleDeclaration>(realm, realm, move(properties), move(custom_properties));
|
||||
}
|
||||
|
||||
PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(JS::Realm& realm, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties)
|
||||
PropertyOwningCSSStyleDeclaration::PropertyOwningCSSStyleDeclaration(JS::Realm& realm, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties)
|
||||
: CSSStyleDeclaration(realm)
|
||||
, m_properties(move(properties))
|
||||
, m_custom_properties(move(custom_properties))
|
||||
|
@ -55,13 +55,13 @@ String PropertyOwningCSSStyleDeclaration::item(size_t index) const
|
|||
return MUST(String::from_utf8(CSS::string_from_property_id(m_properties[index].property_id)));
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration> ElementInlineCSSStyleDeclaration::create(DOM::Element& element, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties)
|
||||
JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration> ElementInlineCSSStyleDeclaration::create(DOM::Element& element, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties)
|
||||
{
|
||||
auto& realm = element.realm();
|
||||
return realm.heap().allocate<ElementInlineCSSStyleDeclaration>(realm, element, move(properties), move(custom_properties));
|
||||
}
|
||||
|
||||
ElementInlineCSSStyleDeclaration::ElementInlineCSSStyleDeclaration(DOM::Element& element, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties)
|
||||
ElementInlineCSSStyleDeclaration::ElementInlineCSSStyleDeclaration(DOM::Element& element, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties)
|
||||
: PropertyOwningCSSStyleDeclaration(element.realm(), move(properties), move(custom_properties))
|
||||
, m_element(element.make_weak_ptr<DOM::Element>())
|
||||
{
|
||||
|
@ -446,7 +446,7 @@ void PropertyOwningCSSStyleDeclaration::empty_the_declarations()
|
|||
m_custom_properties.clear();
|
||||
}
|
||||
|
||||
void PropertyOwningCSSStyleDeclaration::set_the_declarations(Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties)
|
||||
void PropertyOwningCSSStyleDeclaration::set_the_declarations(Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties)
|
||||
{
|
||||
m_properties = move(properties);
|
||||
m_custom_properties = move(custom_properties);
|
||||
|
|
|
@ -54,7 +54,7 @@ class PropertyOwningCSSStyleDeclaration : public CSSStyleDeclaration {
|
|||
|
||||
public:
|
||||
[[nodiscard]] static JS::NonnullGCPtr<PropertyOwningCSSStyleDeclaration>
|
||||
create(JS::Realm&, Vector<StyleProperty>, HashMap<DeprecatedString, StyleProperty> custom_properties);
|
||||
create(JS::Realm&, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties);
|
||||
|
||||
virtual ~PropertyOwningCSSStyleDeclaration() override = default;
|
||||
|
||||
|
@ -67,20 +67,20 @@ public:
|
|||
virtual WebIDL::ExceptionOr<String> remove_property(PropertyID) override;
|
||||
|
||||
Vector<StyleProperty> const& properties() const { return m_properties; }
|
||||
HashMap<DeprecatedString, StyleProperty> const& custom_properties() const { return m_custom_properties; }
|
||||
Optional<StyleProperty> custom_property(DeprecatedString const& custom_property_name) const { return m_custom_properties.get(custom_property_name); }
|
||||
HashMap<FlyString, StyleProperty> const& custom_properties() const { return m_custom_properties; }
|
||||
Optional<StyleProperty> custom_property(FlyString const& custom_property_name) const { return m_custom_properties.get(custom_property_name); }
|
||||
size_t custom_property_count() const { return m_custom_properties.size(); }
|
||||
|
||||
virtual DeprecatedString serialized() const final override;
|
||||
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
|
||||
|
||||
protected:
|
||||
PropertyOwningCSSStyleDeclaration(JS::Realm&, Vector<StyleProperty>, HashMap<DeprecatedString, StyleProperty>);
|
||||
PropertyOwningCSSStyleDeclaration(JS::Realm&, Vector<StyleProperty>, HashMap<FlyString, StyleProperty>);
|
||||
|
||||
virtual void update_style_attribute() { }
|
||||
|
||||
void empty_the_declarations();
|
||||
void set_the_declarations(Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties);
|
||||
void set_the_declarations(Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties);
|
||||
|
||||
private:
|
||||
bool set_a_css_declaration(PropertyID, NonnullRefPtr<StyleValue const>, Important);
|
||||
|
@ -88,14 +88,14 @@ private:
|
|||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
Vector<StyleProperty> m_properties;
|
||||
HashMap<DeprecatedString, StyleProperty> m_custom_properties;
|
||||
HashMap<FlyString, StyleProperty> m_custom_properties;
|
||||
};
|
||||
|
||||
class ElementInlineCSSStyleDeclaration final : public PropertyOwningCSSStyleDeclaration {
|
||||
WEB_PLATFORM_OBJECT(ElementInlineCSSStyleDeclaration, PropertyOwningCSSStyleDeclaration);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration> create(DOM::Element&, Vector<StyleProperty>, HashMap<DeprecatedString, StyleProperty> custom_properties);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<ElementInlineCSSStyleDeclaration> create(DOM::Element&, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties);
|
||||
|
||||
virtual ~ElementInlineCSSStyleDeclaration() override = default;
|
||||
|
||||
|
@ -107,7 +107,7 @@ public:
|
|||
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
|
||||
|
||||
private:
|
||||
ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<DeprecatedString, StyleProperty> custom_properties);
|
||||
ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties);
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
Declaration(FlyString name, Vector<ComponentValue> values, Important);
|
||||
~Declaration();
|
||||
|
||||
StringView name() const { return m_name; }
|
||||
FlyString const& name() const { return m_name; }
|
||||
Vector<ComponentValue> const& values() const { return m_values; }
|
||||
Important importance() const { return m_important; }
|
||||
|
||||
|
|
|
@ -1667,15 +1667,15 @@ PropertyOwningCSSStyleDeclaration* Parser::convert_to_style_declaration(Vector<D
|
|||
|
||||
Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& declaration)
|
||||
{
|
||||
auto property_name = declaration.name();
|
||||
auto const& property_name = declaration.name();
|
||||
auto property_id = property_id_from_string(property_name);
|
||||
|
||||
if (!property_id.has_value()) {
|
||||
if (property_name.starts_with("--"sv)) {
|
||||
if (property_name.bytes_as_string_view().starts_with("--"sv)) {
|
||||
property_id = PropertyID::Custom;
|
||||
} else if (has_ignored_vendor_prefix(property_name)) {
|
||||
return {};
|
||||
} else if (!property_name.starts_with('-')) {
|
||||
} else if (!property_name.bytes_as_string_view().starts_with('-')) {
|
||||
dbgln_if(CSS_PARSER_DEBUG, "Unrecognized CSS property '{}'", property_name);
|
||||
return {};
|
||||
}
|
||||
|
@ -6735,12 +6735,12 @@ NonnullRefPtr<StyleValue> Parser::resolve_unresolved_style_value(DOM::Element& e
|
|||
static RefPtr<StyleValue const> get_custom_property(DOM::Element const& element, Optional<CSS::Selector::PseudoElement> pseudo_element, FlyString const& custom_property_name)
|
||||
{
|
||||
if (pseudo_element.has_value()) {
|
||||
if (auto it = element.custom_properties(pseudo_element).find(custom_property_name.to_string().to_deprecated_string()); it != element.custom_properties(pseudo_element).end())
|
||||
if (auto it = element.custom_properties(pseudo_element).find(custom_property_name.to_string()); it != element.custom_properties(pseudo_element).end())
|
||||
return it->value.value;
|
||||
}
|
||||
|
||||
for (auto const* current_element = &element; current_element; current_element = current_element->parent_element()) {
|
||||
if (auto it = current_element->custom_properties({}).find(custom_property_name.to_string().to_deprecated_string()); it != current_element->custom_properties({}).end())
|
||||
if (auto it = current_element->custom_properties({}).find(custom_property_name.to_string()); it != current_element->custom_properties({}).end())
|
||||
return it->value.value;
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -299,7 +299,7 @@ private:
|
|||
|
||||
struct PropertiesAndCustomProperties {
|
||||
Vector<StyleProperty> properties;
|
||||
HashMap<DeprecatedString, StyleProperty> custom_properties;
|
||||
HashMap<FlyString, StyleProperty> custom_properties;
|
||||
};
|
||||
|
||||
PropertiesAndCustomProperties extract_properties(Vector<DeclarationOrAtRule> const&);
|
||||
|
|
|
@ -724,7 +724,7 @@ static ErrorOr<void> cascade_custom_properties(DOM::Element& element, Optional<C
|
|||
needed_capacity += inline_style->custom_properties().size();
|
||||
}
|
||||
|
||||
HashMap<DeprecatedFlyString, StyleProperty> custom_properties;
|
||||
HashMap<FlyString, StyleProperty> custom_properties;
|
||||
TRY(custom_properties.try_ensure_capacity(needed_capacity));
|
||||
|
||||
for (auto const& matching_rule : matching_rules) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
@ -22,7 +22,7 @@ struct StyleProperty {
|
|||
Important important { Important::No };
|
||||
CSS::PropertyID property_id;
|
||||
NonnullRefPtr<StyleValue const> value;
|
||||
DeprecatedString custom_name {};
|
||||
FlyString custom_name {};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1918,7 +1918,7 @@ void Element::set_computed_css_values(RefPtr<CSS::StyleProperties> style)
|
|||
m_computed_css_values = move(style);
|
||||
}
|
||||
|
||||
void Element::set_custom_properties(Optional<CSS::Selector::PseudoElement> pseudo_element, HashMap<DeprecatedFlyString, CSS::StyleProperty> custom_properties)
|
||||
void Element::set_custom_properties(Optional<CSS::Selector::PseudoElement> pseudo_element, HashMap<FlyString, CSS::StyleProperty> custom_properties)
|
||||
{
|
||||
if (!pseudo_element.has_value()) {
|
||||
m_custom_properties = move(custom_properties);
|
||||
|
@ -1927,7 +1927,7 @@ void Element::set_custom_properties(Optional<CSS::Selector::PseudoElement> pseud
|
|||
m_pseudo_element_custom_properties[to_underlying(pseudo_element.value())] = move(custom_properties);
|
||||
}
|
||||
|
||||
HashMap<DeprecatedFlyString, CSS::StyleProperty> const& Element::custom_properties(Optional<CSS::Selector::PseudoElement> pseudo_element) const
|
||||
HashMap<FlyString, CSS::StyleProperty> const& Element::custom_properties(Optional<CSS::Selector::PseudoElement> pseudo_element) const
|
||||
{
|
||||
if (!pseudo_element.has_value())
|
||||
return m_custom_properties;
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedFlyString.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <LibWeb/ARIA/ARIAMixin.h>
|
||||
#include <LibWeb/Bindings/ElementPrototype.h>
|
||||
|
@ -205,8 +204,8 @@ public:
|
|||
ShadowRoot const* shadow_root_internal() const { return m_shadow_root.ptr(); }
|
||||
void set_shadow_root(JS::GCPtr<ShadowRoot>);
|
||||
|
||||
void set_custom_properties(Optional<CSS::Selector::PseudoElement>, HashMap<DeprecatedFlyString, CSS::StyleProperty> custom_properties);
|
||||
[[nodiscard]] HashMap<DeprecatedFlyString, CSS::StyleProperty> const& custom_properties(Optional<CSS::Selector::PseudoElement>) const;
|
||||
void set_custom_properties(Optional<CSS::Selector::PseudoElement>, HashMap<FlyString, CSS::StyleProperty> custom_properties);
|
||||
[[nodiscard]] HashMap<FlyString, CSS::StyleProperty> const& custom_properties(Optional<CSS::Selector::PseudoElement>) const;
|
||||
|
||||
int queue_an_element_task(HTML::Task::Source, JS::SafeFunction<void()>);
|
||||
|
||||
|
@ -400,8 +399,8 @@ private:
|
|||
JS::GCPtr<ShadowRoot> m_shadow_root;
|
||||
|
||||
RefPtr<CSS::StyleProperties> m_computed_css_values;
|
||||
HashMap<DeprecatedFlyString, CSS::StyleProperty> m_custom_properties;
|
||||
Array<HashMap<DeprecatedFlyString, CSS::StyleProperty>, to_underlying(CSS::Selector::PseudoElement::PseudoElementCount)> m_pseudo_element_custom_properties;
|
||||
HashMap<FlyString, CSS::StyleProperty> m_custom_properties;
|
||||
Array<HashMap<FlyString, CSS::StyleProperty>, to_underlying(CSS::Selector::PseudoElement::PseudoElementCount)> m_pseudo_element_custom_properties;
|
||||
|
||||
Vector<FlyString> m_classes;
|
||||
Optional<Dir> m_dir;
|
||||
|
|
|
@ -545,14 +545,14 @@ Messages::WebContentServer::InspectDomNodeResponse ConnectionFromClient::inspect
|
|||
auto serialize_custom_properties_json = [](Web::DOM::Element const& element, Optional<Web::CSS::Selector::PseudoElement> pseudo_element) -> DeprecatedString {
|
||||
StringBuilder builder;
|
||||
auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
|
||||
HashTable<DeprecatedString> seen_properties;
|
||||
HashTable<FlyString> seen_properties;
|
||||
|
||||
auto const* element_to_check = &element;
|
||||
while (element_to_check) {
|
||||
for (auto const& property : element_to_check->custom_properties(pseudo_element)) {
|
||||
if (!seen_properties.contains(property.key)) {
|
||||
seen_properties.set(property.key);
|
||||
MUST(serializer.add(property.key, property.value.value->to_string().to_deprecated_string()));
|
||||
MUST(serializer.add(property.key, property.value.value->to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue