LibWeb: Make :hover invalidation logic reusable for all pseudo classes

We achieve this by keeping track of all checked pseudo class selectors
in the SelectorEngine code. We also give StyleComputer per-pseudo-class
rule caches.
This commit is contained in:
Andreas Kling
2025-04-17 13:39:30 +02:00
committed by Andreas Kling
parent ed35f9e7c2
commit e1777f6e79
Notes: github-actions[bot] 2025-04-17 17:47:22 +00:00
13 changed files with 134 additions and 59 deletions

View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2025, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/PseudoClass.h>
namespace Web::CSS {
class PseudoClassBitmap {
public:
PseudoClassBitmap() = default;
~PseudoClassBitmap() = default;
void set(PseudoClass pseudo_class, bool bit)
{
size_t const index = to_underlying(pseudo_class);
if (bit)
m_bits |= 1LLU << index;
else
m_bits &= ~(1LLU << index);
}
bool get(PseudoClass pseudo_class) const
{
size_t const index = to_underlying(pseudo_class);
return (m_bits & (1LLU << index)) != 0;
}
void operator|=(PseudoClassBitmap const& other)
{
m_bits |= other.m_bits;
}
private:
u64 m_bits { 0 };
};
// NOTE: If this changes, we'll have to tweak PseudoClassBitmap a little bit :)
static_assert(to_underlying(PseudoClass::__Count) <= 64);
}