mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 09:34:57 +09:00
LibWeb: Add method to check if element affected by invalidation set
...by replacing existing method to check if an element is affected by invalidation property. It turned out there is no need to check if an element is affected only by some specific property, so it's more convenient to have a method that accepts the whole set.
This commit is contained in:
parent
74dc335b28
commit
e33037ad52
Notes:
github-actions[bot]
2025-01-29 08:31:28 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: e33037ad52
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3391
3 changed files with 53 additions and 53 deletions
|
@ -1149,52 +1149,64 @@ bool Element::affected_by_hover() const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Element::affected_by_invalidation_property(CSS::InvalidationSet::Property const& property) const
|
||||
bool Element::includes_properties_from_invalidation_set(CSS::InvalidationSet const& set) const
|
||||
{
|
||||
switch (property.type) {
|
||||
case CSS::InvalidationSet::Property::Type::Class:
|
||||
return m_classes.contains_slow(property.name());
|
||||
case CSS::InvalidationSet::Property::Type::Id:
|
||||
return m_id == property.name();
|
||||
case CSS::InvalidationSet::Property::Type::TagName:
|
||||
return local_name() == property.name();
|
||||
case CSS::InvalidationSet::Property::Type::Attribute: {
|
||||
if (property.name() == HTML::AttributeNames::id || property.name() == HTML::AttributeNames::class_)
|
||||
return true;
|
||||
return has_attribute(property.name());
|
||||
}
|
||||
case CSS::InvalidationSet::Property::Type::PseudoClass: {
|
||||
switch (property.value.get<CSS::PseudoClass>()) {
|
||||
case CSS::PseudoClass::Enabled: {
|
||||
return (is<HTML::HTMLButtonElement>(*this) || is<HTML::HTMLInputElement>(*this) || is<HTML::HTMLSelectElement>(*this) || is<HTML::HTMLTextAreaElement>(*this) || is<HTML::HTMLOptGroupElement>(*this) || is<HTML::HTMLOptionElement>(*this) || is<HTML::HTMLFieldSetElement>(*this))
|
||||
&& !is_actually_disabled();
|
||||
auto includes_property = [&](CSS::InvalidationSet::Property const& property) {
|
||||
switch (property.type) {
|
||||
case CSS::InvalidationSet::Property::Type::Class:
|
||||
return m_classes.contains_slow(property.name());
|
||||
case CSS::InvalidationSet::Property::Type::Id:
|
||||
return m_id == property.name();
|
||||
case CSS::InvalidationSet::Property::Type::TagName:
|
||||
return local_name() == property.name();
|
||||
case CSS::InvalidationSet::Property::Type::Attribute: {
|
||||
if (property.name() == HTML::AttributeNames::id || property.name() == HTML::AttributeNames::class_)
|
||||
return true;
|
||||
return has_attribute(property.name());
|
||||
}
|
||||
case CSS::PseudoClass::Disabled: {
|
||||
return is_actually_disabled();
|
||||
}
|
||||
case CSS::PseudoClass::Checked: {
|
||||
// FIXME: This could be narrowed down to return true only if element is actually checked.
|
||||
return is<HTML::HTMLInputElement>(*this) || is<HTML::HTMLOptionElement>(*this);
|
||||
}
|
||||
case CSS::PseudoClass::PlaceholderShown: {
|
||||
if (is<HTML::HTMLInputElement>(*this) && has_attribute(HTML::AttributeNames::placeholder)) {
|
||||
auto const& input_element = static_cast<HTML::HTMLInputElement const&>(*this);
|
||||
return input_element.placeholder_element() && input_element.placeholder_value().has_value();
|
||||
case CSS::InvalidationSet::Property::Type::PseudoClass: {
|
||||
switch (property.value.get<CSS::PseudoClass>()) {
|
||||
case CSS::PseudoClass::Enabled: {
|
||||
return (is<HTML::HTMLButtonElement>(*this) || is<HTML::HTMLInputElement>(*this) || is<HTML::HTMLSelectElement>(*this) || is<HTML::HTMLTextAreaElement>(*this) || is<HTML::HTMLOptGroupElement>(*this) || is<HTML::HTMLOptionElement>(*this) || is<HTML::HTMLFieldSetElement>(*this))
|
||||
&& !is_actually_disabled();
|
||||
}
|
||||
case CSS::PseudoClass::Disabled: {
|
||||
return is_actually_disabled();
|
||||
}
|
||||
case CSS::PseudoClass::Checked: {
|
||||
// FIXME: This could be narrowed down to return true only if element is actually checked.
|
||||
return is<HTML::HTMLInputElement>(*this) || is<HTML::HTMLOptionElement>(*this);
|
||||
}
|
||||
case CSS::PseudoClass::PlaceholderShown: {
|
||||
if (is<HTML::HTMLInputElement>(*this) && has_attribute(HTML::AttributeNames::placeholder)) {
|
||||
auto const& input_element = static_cast<HTML::HTMLInputElement const&>(*this);
|
||||
return input_element.placeholder_element() && input_element.placeholder_value().has_value();
|
||||
}
|
||||
// - FIXME: textarea elements that have a placeholder attribute whose value is currently being presented to the user.
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
// - FIXME: textarea elements that have a placeholder attribute whose value is currently being presented to the user.
|
||||
return false;
|
||||
}
|
||||
case CSS::InvalidationSet::Property::Type::InvalidateSelf:
|
||||
return false;
|
||||
case CSS::InvalidationSet::Property::Type::InvalidateWholeSubtree:
|
||||
return true;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
case CSS::InvalidationSet::Property::Type::InvalidateSelf:
|
||||
return false;
|
||||
case CSS::InvalidationSet::Property::Type::InvalidateWholeSubtree:
|
||||
return true;
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
};
|
||||
|
||||
bool includes_any = false;
|
||||
set.for_each_property([&](auto const& property) {
|
||||
if (includes_property(property)) {
|
||||
includes_any = true;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return includes_any;
|
||||
}
|
||||
|
||||
bool Element::has_pseudo_elements() const
|
||||
|
|
|
@ -266,7 +266,7 @@ public:
|
|||
static GC::Ptr<Layout::NodeWithStyle> create_layout_node_for_display_type(DOM::Document&, CSS::Display const&, GC::Ref<CSS::ComputedProperties>, Element*);
|
||||
|
||||
bool affected_by_hover() const;
|
||||
bool affected_by_invalidation_property(CSS::InvalidationSet::Property const&) const;
|
||||
bool includes_properties_from_invalidation_set(CSS::InvalidationSet const&) const;
|
||||
|
||||
void set_pseudo_element_node(Badge<Layout::TreeBuilder>, CSS::Selector::PseudoElement::Type, GC::Ptr<Layout::NodeWithStyle>);
|
||||
GC::Ptr<Layout::NodeWithStyle> get_pseudo_element_node(CSS::Selector::PseudoElement::Type) const;
|
||||
|
|
|
@ -486,18 +486,6 @@ void Node::invalidate_style(StyleInvalidationReason reason, Vector<CSS::Invalida
|
|||
set_needs_style_update(true);
|
||||
}
|
||||
|
||||
auto element_has_properties_from_invalidation_set = [&](Element& element) {
|
||||
bool result = false;
|
||||
invalidation_set.for_each_property([&](auto const& property) {
|
||||
if (element.affected_by_invalidation_property(property)) {
|
||||
result = true;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
auto invalidate_entire_subtree = [&](Node& subtree_root) {
|
||||
subtree_root.for_each_shadow_including_inclusive_descendant([&](Node& node) {
|
||||
if (!node.is_element())
|
||||
|
@ -506,7 +494,7 @@ void Node::invalidate_style(StyleInvalidationReason reason, Vector<CSS::Invalida
|
|||
bool needs_style_recalculation = false;
|
||||
if (invalidation_set.needs_invalidate_whole_subtree()) {
|
||||
needs_style_recalculation = true;
|
||||
} else if (element_has_properties_from_invalidation_set(element)) {
|
||||
} else if (element.includes_properties_from_invalidation_set(invalidation_set)) {
|
||||
needs_style_recalculation = true;
|
||||
} else if (options.invalidate_elements_that_use_css_custom_properties && element.style_uses_css_custom_properties()) {
|
||||
needs_style_recalculation = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue