|
37 | 37 | #include <LibWeb/CSS/CSSStyleRule.h>
|
38 | 38 | #include <LibWeb/CSS/CSSTransition.h>
|
39 | 39 | #include <LibWeb/CSS/Interpolation.h>
|
| 40 | +#include <LibWeb/CSS/InvalidationSet.h> |
40 | 41 | #include <LibWeb/CSS/Parser/Parser.h>
|
41 | 42 | #include <LibWeb/CSS/SelectorEngine.h>
|
42 | 43 | #include <LibWeb/CSS/StyleComputer.h>
|
@@ -427,6 +428,46 @@ Vector<MatchingRule> const& StyleComputer::get_hover_rules() const
|
427 | 428 | return m_hover_rules;
|
428 | 429 | }
|
429 | 430 |
|
| 431 | +InvalidationSet StyleComputer::invalidation_set_for_properties(Vector<InvalidationSet::Property> const& properties) const |
| 432 | +{ |
| 433 | + if (!m_style_invalidation_data) |
| 434 | + return {}; |
| 435 | + auto const& descendant_invalidation_sets = m_style_invalidation_data->descendant_invalidation_sets; |
| 436 | + InvalidationSet result; |
| 437 | + for (auto const& property : properties) { |
| 438 | + if (auto it = descendant_invalidation_sets.find(property); it != descendant_invalidation_sets.end()) |
| 439 | + result.include_all_from(it->value); |
| 440 | + } |
| 441 | + return result; |
| 442 | +} |
| 443 | + |
| 444 | +bool StyleComputer::invalidation_property_used_in_has_selector(InvalidationSet::Property const& property) const |
| 445 | +{ |
| 446 | + if (!m_style_invalidation_data) |
| 447 | + return true; |
| 448 | + switch (property.type) { |
| 449 | + case InvalidationSet::Property::Type::Id: |
| 450 | + if (m_style_invalidation_data->ids_used_in_has_selectors.contains(property.name)) |
| 451 | + return true; |
| 452 | + break; |
| 453 | + case InvalidationSet::Property::Type::Class: |
| 454 | + if (m_style_invalidation_data->class_names_used_in_has_selectors.contains(property.name)) |
| 455 | + return true; |
| 456 | + break; |
| 457 | + case InvalidationSet::Property::Type::Attribute: |
| 458 | + if (m_style_invalidation_data->attribute_names_used_in_has_selectors.contains(property.name)) |
| 459 | + return true; |
| 460 | + break; |
| 461 | + case InvalidationSet::Property::Type::TagName: |
| 462 | + if (m_style_invalidation_data->tag_names_used_in_has_selectors.contains(property.name)) |
| 463 | + return true; |
| 464 | + break; |
| 465 | + default: |
| 466 | + break; |
| 467 | + } |
| 468 | + return false; |
| 469 | +} |
| 470 | + |
430 | 471 | Vector<MatchingRule> StyleComputer::collect_matching_rules(DOM::Element const& element, CascadeOrigin cascade_origin, Optional<CSS::Selector::PseudoElement::Type> pseudo_element, bool& did_match_any_hover_rules, FlyString const& qualified_layer_name) const
|
431 | 472 | {
|
432 | 473 | auto const& root_node = element.root();
|
@@ -2576,6 +2617,11 @@ NonnullOwnPtr<StyleComputer::RuleCache> StyleComputer::make_rule_cache_for_casca
|
2576 | 2617 | return static_cast<CSSNestedDeclarations const&>(rule).parent_style_rule().absolutized_selectors();
|
2577 | 2618 | VERIFY_NOT_REACHED();
|
2578 | 2619 | }();
|
| 2620 | + |
| 2621 | + for (auto const& selector : absolutized_selectors) { |
| 2622 | + m_style_invalidation_data->build_invalidation_sets_for_selector(selector); |
| 2623 | + } |
| 2624 | + |
2579 | 2625 | for (CSS::Selector const& selector : absolutized_selectors) {
|
2580 | 2626 | MatchingRule matching_rule {
|
2581 | 2627 | shadow_root,
|
@@ -2842,6 +2888,7 @@ void StyleComputer::build_qualified_layer_names_cache()
|
2842 | 2888 | void StyleComputer::build_rule_cache()
|
2843 | 2889 | {
|
2844 | 2890 | m_selector_insights = make<SelectorInsights>();
|
| 2891 | + m_style_invalidation_data = make<StyleInvalidationData>(); |
2845 | 2892 |
|
2846 | 2893 | if (auto user_style_source = document().page().user_style(); user_style_source.has_value()) {
|
2847 | 2894 | m_user_style_sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingContext(document()), user_style_source.value()));
|
@@ -2869,6 +2916,7 @@ void StyleComputer::invalidate_rule_cache()
|
2869 | 2916 | m_user_agent_rule_cache = nullptr;
|
2870 | 2917 |
|
2871 | 2918 | m_hover_rules.clear_with_capacity();
|
| 2919 | + m_style_invalidation_data = nullptr; |
2872 | 2920 | }
|
2873 | 2921 |
|
2874 | 2922 | void StyleComputer::did_load_font(FlyString const&)
|
|
0 commit comments