1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 16:45:08 +00:00

LibWeb: Port CSSStyleDeclaration from DeprecatedString to String

This commit is contained in:
Shannon Booth 2023-11-21 10:39:54 +13:00 committed by Tim Flynn
parent 629f661e3b
commit af7df1dbbf
5 changed files with 18 additions and 18 deletions

View file

@ -187,7 +187,7 @@ void ElementInlineCSSStyleDeclaration::update_style_attribute()
m_updating = true;
// 5. Set an attribute value for owner node using "style" and the result of serializing declaration block.
MUST(m_element->set_attribute(HTML::AttributeNames::style, MUST(String::from_deprecated_string(serialized()))));
MUST(m_element->set_attribute(HTML::AttributeNames::style, serialized()));
// 6. Unset declaration blocks updating flag.
m_updating = false;
@ -256,7 +256,7 @@ WebIDL::ExceptionOr<String> CSSStyleDeclaration::remove_property(StringView prop
}
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
DeprecatedString CSSStyleDeclaration::css_text() const
String CSSStyleDeclaration::css_text() const
{
// 1. If the computed flag is set, then return the empty string.
// NOTE: See ResolvedCSSStyleDeclaration::serialized()
@ -266,7 +266,7 @@ DeprecatedString CSSStyleDeclaration::css_text() const
}
// https://www.w3.org/TR/cssom/#serialize-a-css-declaration
static DeprecatedString serialize_a_css_declaration(CSS::PropertyID property, DeprecatedString value, Important important)
static String serialize_a_css_declaration(CSS::PropertyID property, StringView value, Important important)
{
StringBuilder builder;
@ -288,14 +288,14 @@ static DeprecatedString serialize_a_css_declaration(CSS::PropertyID property, De
builder.append(';');
// 7. Return s.
return builder.to_deprecated_string();
return MUST(builder.to_string());
}
// https://www.w3.org/TR/cssom/#serialize-a-css-declaration-block
DeprecatedString PropertyOwningCSSStyleDeclaration::serialized() const
String PropertyOwningCSSStyleDeclaration::serialized() const
{
// 1. Let list be an empty array.
Vector<DeprecatedString> list;
Vector<String> list;
// 2. Let already serialized be an empty array.
HashTable<PropertyID> already_serialized;
@ -322,7 +322,7 @@ DeprecatedString PropertyOwningCSSStyleDeclaration::serialized() const
// 6. Let serialized declaration be the result of invoking serialize a CSS declaration with property name property, value value,
// and the important flag set if declaration has its important flag set.
// NOTE: We have to inline this here as the actual implementation does not accept custom properties.
DeprecatedString serialized_declaration = [&] {
String serialized_declaration = [&] {
// https://www.w3.org/TR/cssom/#serialize-a-css-declaration
StringBuilder builder;
@ -344,7 +344,7 @@ DeprecatedString PropertyOwningCSSStyleDeclaration::serialized() const
builder.append(';');
// 7. Return s.
return builder.to_deprecated_string();
return MUST(builder.to_string());
}();
// 7. Append serialized declaration to list.
@ -368,7 +368,7 @@ DeprecatedString PropertyOwningCSSStyleDeclaration::serialized() const
// FIXME: 4. Shorthand loop: For each shorthand in shorthands, follow these substeps: ...
// 5. Let value be the result of invoking serialize a CSS value of declaration.
auto value = declaration.value->to_string().to_deprecated_string();
auto value = declaration.value->to_string();
// 6. Let serialized declaration be the result of invoking serialize a CSS declaration with property name property, value value,
// and the important flag set if declaration has its important flag set.
@ -384,7 +384,7 @@ DeprecatedString PropertyOwningCSSStyleDeclaration::serialized() const
// 4. Return list joined with " " (U+0020).
StringBuilder builder;
builder.join(' ', list);
return builder.to_deprecated_string();
return MUST(builder.to_string());
}
static CSS::PropertyID property_id_from_name(StringView name)

View file

@ -6,7 +6,7 @@
#pragma once
#include <AK/DeprecatedString.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/CSS/StyleProperty.h>
@ -36,10 +36,10 @@ public:
String get_property_value(StringView property) const;
StringView get_property_priority(StringView property) const;
DeprecatedString css_text() const;
String css_text() const;
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) = 0;
virtual DeprecatedString 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, JS::CacheablePropertyMetadata*) const override;
@ -74,7 +74,7 @@ public:
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 String serialized() const final override;
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
protected:

View file

@ -55,7 +55,7 @@ String CSSStyleRule::serialized() const
builder.append(" {"sv);
// 2. Let decls be the result of performing serialize a CSS declaration block on the rules associated declarations, or null if there are no such declarations.
auto decls = declaration().length() > 0 ? declaration().serialized() : Optional<DeprecatedString>();
auto decls = declaration().length() > 0 ? declaration().serialized() : Optional<String>();
// FIXME: 3. Let rules be the result of performing serialize a CSS rule on each rule in the rules cssRules list, or null if there are no such rules.
Optional<String> rules;

View file

@ -567,14 +567,14 @@ WebIDL::ExceptionOr<String> ResolvedCSSStyleDeclaration::remove_property(Propert
return WebIDL::NoModificationAllowedError::create(realm(), "Cannot remove properties from result of getComputedStyle()"_fly_string);
}
DeprecatedString ResolvedCSSStyleDeclaration::serialized() const
String ResolvedCSSStyleDeclaration::serialized() const
{
// https://www.w3.org/TR/cssom/#dom-cssstyledeclaration-csstext
// If the computed flag is set, then return the empty string.
// NOTE: ResolvedCSSStyleDeclaration is something you would only get from window.getComputedStyle(),
// which returns what the spec calls "resolved style". The "computed flag" is always set here.
return DeprecatedString::empty();
return String {};
}
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext

View file

@ -25,7 +25,7 @@ public:
virtual WebIDL::ExceptionOr<void> set_property(PropertyID, StringView css_text, StringView priority) override;
virtual WebIDL::ExceptionOr<String> remove_property(PropertyID) override;
virtual DeprecatedString serialized() const override;
virtual String serialized() const override;
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
private: