mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-06 09:36:08 +00:00
LibWeb/CSS: Add has_property()
to CSSStyleDeclaration
This isn't part of the CSSOM API directly, but will be used by StylePropertyMapReadOnly.has() to avoid doing the work to serialize a string version of the property's value, just to throw it away again.
This commit is contained in:
parent
fcd39b67af
commit
37ea9a4ce3
Notes:
github-actions[bot]
2025-08-18 09:14:31 +00:00
Author: https://github.com/AtkinsSJ
Commit: 37ea9a4ce3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5862
Reviewed-by: https://github.com/Calme1709
5 changed files with 22 additions and 0 deletions
|
@ -281,6 +281,14 @@ RefPtr<StyleValue const> CSSDescriptors::descriptor_or_initial_value(DescriptorI
|
||||||
return descriptor_initial_value(m_at_rule_id, descriptor_id);
|
return descriptor_initial_value(m_at_rule_id, descriptor_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSSDescriptors::has_property(StringView property_name) const
|
||||||
|
{
|
||||||
|
auto descriptor_id = descriptor_id_from_string(m_at_rule_id, property_name);
|
||||||
|
if (!descriptor_id.has_value())
|
||||||
|
return false;
|
||||||
|
return descriptor(*descriptor_id) != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_shorthand(AtRuleID at_rule, DescriptorID descriptor)
|
bool is_shorthand(AtRuleID at_rule, DescriptorID descriptor)
|
||||||
{
|
{
|
||||||
if (at_rule == AtRuleID::Page && descriptor == DescriptorID::Margin)
|
if (at_rule == AtRuleID::Page && descriptor == DescriptorID::Margin)
|
||||||
|
|
|
@ -33,6 +33,8 @@ public:
|
||||||
|
|
||||||
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
|
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
|
||||||
|
|
||||||
|
virtual bool has_property(StringView property_name) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CSSDescriptors(JS::Realm&, AtRuleID, Vector<Descriptor>);
|
CSSDescriptors(JS::Realm&, AtRuleID, Vector<Descriptor>);
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,8 @@ public:
|
||||||
[[nodiscard]] bool is_updating() const { return m_updating; }
|
[[nodiscard]] bool is_updating() const { return m_updating; }
|
||||||
void set_is_updating(bool value) { m_updating = value; }
|
void set_is_updating(bool value) { m_updating = value; }
|
||||||
|
|
||||||
|
virtual bool has_property(StringView property_name) const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum class Computed : u8 {
|
enum class Computed : u8 {
|
||||||
No,
|
No,
|
||||||
|
|
|
@ -426,6 +426,14 @@ StringView CSSStyleProperties::get_property_priority(StringView property_name) c
|
||||||
return maybe_property->important == Important::Yes ? "important"sv : ""sv;
|
return maybe_property->important == Important::Yes ? "important"sv : ""sv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSSStyleProperties::has_property(StringView property_name) const
|
||||||
|
{
|
||||||
|
auto property_id = property_id_from_string(property_name);
|
||||||
|
if (!property_id.has_value())
|
||||||
|
return false;
|
||||||
|
return get_property_internal(*property_id).has_value();
|
||||||
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
// https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
||||||
Optional<StyleProperty> CSSStyleProperties::get_property_internal(PropertyID property_id) const
|
Optional<StyleProperty> CSSStyleProperties::get_property_internal(PropertyID property_id) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,8 @@ public:
|
||||||
|
|
||||||
size_t custom_property_count() const { return m_custom_properties.size(); }
|
size_t custom_property_count() const { return m_custom_properties.size(); }
|
||||||
|
|
||||||
|
virtual bool has_property(StringView property_name) const override;
|
||||||
|
|
||||||
String css_float() const;
|
String css_float() const;
|
||||||
WebIDL::ExceptionOr<void> set_css_float(StringView);
|
WebIDL::ExceptionOr<void> set_css_float(StringView);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue