mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 12:55:08 +00:00
LibWeb: Implement CSSStyleDeclaration.cssText
This commit is contained in:
parent
8066a67da2
commit
c247fefee7
5 changed files with 65 additions and 7 deletions
|
@ -232,15 +232,14 @@ WebIDL::ExceptionOr<String> CSSStyleDeclaration::remove_property(StringView prop
|
||||||
return remove_property(property_id);
|
return remove_property(property_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
|
||||||
String CSSStyleDeclaration::css_text() const
|
String CSSStyleDeclaration::css_text() const
|
||||||
{
|
{
|
||||||
TODO();
|
// 1. If the computed flag is set, then return the empty string.
|
||||||
return "";
|
// NOTE: See ResolvedCSSStyleDeclaration::serialized()
|
||||||
}
|
|
||||||
|
|
||||||
void CSSStyleDeclaration::set_css_text(StringView)
|
// 2. Return the result of serializing the declarations.
|
||||||
{
|
return serialized();
|
||||||
TODO();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://www.w3.org/TR/cssom/#serialize-a-css-declaration
|
// https://www.w3.org/TR/cssom/#serialize-a-css-declaration
|
||||||
|
@ -360,4 +359,47 @@ JS::ThrowCompletionOr<bool> CSSStyleDeclaration::internal_set(JS::PropertyKey co
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<void> PropertyOwningCSSStyleDeclaration::set_css_text(StringView css_text)
|
||||||
|
{
|
||||||
|
dbgln("(STUBBED) PropertyOwningCSSStyleDeclaration::set_css_text(css_text='{}')", css_text);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertyOwningCSSStyleDeclaration::empty_the_declarations()
|
||||||
|
{
|
||||||
|
m_properties.clear();
|
||||||
|
m_custom_properties.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertyOwningCSSStyleDeclaration::set_the_declarations(Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties)
|
||||||
|
{
|
||||||
|
m_properties = move(properties);
|
||||||
|
m_custom_properties = move(custom_properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
|
||||||
|
WebIDL::ExceptionOr<void> ElementInlineCSSStyleDeclaration::set_css_text(StringView css_text)
|
||||||
|
{
|
||||||
|
// FIXME: What do we do if the element is null?
|
||||||
|
if (!m_element) {
|
||||||
|
dbgln("FIXME: Returning from ElementInlineCSSStyleDeclaration::set_css_text as m_element is null.");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. If the computed flag is set, then throw a NoModificationAllowedError exception.
|
||||||
|
// NOTE: See ResolvedCSSStyleDeclaration.
|
||||||
|
|
||||||
|
// 2. Empty the declarations.
|
||||||
|
empty_the_declarations();
|
||||||
|
|
||||||
|
// 3. Parse the given value and, if the return value is not the empty list, insert the items in the list into the declarations, in specified order.
|
||||||
|
auto style = parse_css_style_attribute(CSS::Parser::ParsingContext(m_element->document()), css_text, *m_element.ptr());
|
||||||
|
set_the_declarations(style->properties(), style->custom_properties());
|
||||||
|
|
||||||
|
// 4. Update style attribute for the CSS declaration block.
|
||||||
|
update_style_attribute();
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
String get_property_priority(StringView property) const;
|
String get_property_priority(StringView property) const;
|
||||||
|
|
||||||
String css_text() const;
|
String css_text() const;
|
||||||
void set_css_text(StringView);
|
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) = 0;
|
||||||
|
|
||||||
virtual String serialized() const = 0;
|
virtual String serialized() const = 0;
|
||||||
|
|
||||||
|
@ -81,12 +81,16 @@ public:
|
||||||
size_t custom_property_count() const { return m_custom_properties.size(); }
|
size_t custom_property_count() const { return m_custom_properties.size(); }
|
||||||
|
|
||||||
virtual String serialized() const final override;
|
virtual String serialized() const final override;
|
||||||
|
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PropertyOwningCSSStyleDeclaration(JS::Realm&, Vector<StyleProperty>, HashMap<String, StyleProperty>);
|
PropertyOwningCSSStyleDeclaration(JS::Realm&, Vector<StyleProperty>, HashMap<String, StyleProperty>);
|
||||||
|
|
||||||
virtual void update_style_attribute() { }
|
virtual void update_style_attribute() { }
|
||||||
|
|
||||||
|
void empty_the_declarations();
|
||||||
|
void set_the_declarations(Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool set_a_css_declaration(PropertyID, NonnullRefPtr<StyleValue>, Important);
|
bool set_a_css_declaration(PropertyID, NonnullRefPtr<StyleValue>, Important);
|
||||||
|
|
||||||
|
@ -107,6 +111,8 @@ public:
|
||||||
|
|
||||||
bool is_updating() const { return m_updating; }
|
bool is_updating() const { return m_updating; }
|
||||||
|
|
||||||
|
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties);
|
ElementInlineCSSStyleDeclaration(DOM::Element&, Vector<StyleProperty> properties, HashMap<String, StyleProperty> custom_properties);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
[Exposed=Window]
|
[Exposed=Window]
|
||||||
interface CSSStyleDeclaration {
|
interface CSSStyleDeclaration {
|
||||||
|
|
||||||
|
[CEReactions] attribute CSSOMString cssText;
|
||||||
|
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
CSSOMString item(unsigned long index);
|
CSSOMString item(unsigned long index);
|
||||||
|
|
||||||
|
|
|
@ -570,4 +570,11 @@ String ResolvedCSSStyleDeclaration::serialized() const
|
||||||
return String::empty();
|
return String::empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
|
||||||
|
WebIDL::ExceptionOr<void> ResolvedCSSStyleDeclaration::set_css_text(StringView)
|
||||||
|
{
|
||||||
|
// 1. If the computed flag is set, then throw a NoModificationAllowedError exception.
|
||||||
|
return WebIDL::NoModificationAllowedError::create(realm(), "Cannot modify properties in result of getComputedStyle()");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ public:
|
||||||
virtual WebIDL::ExceptionOr<String> remove_property(PropertyID) override;
|
virtual WebIDL::ExceptionOr<String> remove_property(PropertyID) override;
|
||||||
|
|
||||||
virtual String serialized() const override;
|
virtual String serialized() const override;
|
||||||
|
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ResolvedCSSStyleDeclaration(DOM::Element&);
|
explicit ResolvedCSSStyleDeclaration(DOM::Element&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue