mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb: Support non-fixed <random-value-sharing>
This works by generating random values using XorShift128PlusRNG at compute time and then caching them on the document using the relevant random-caching-key
This commit is contained in:
parent
86e6aa0291
commit
12e8f503aa
Notes:
github-actions[bot]
2025-12-01 11:01:47 +00:00
Author: https://github.com/Calme1709
Commit: 12e8f503aa
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6707
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/gmta
15 changed files with 226 additions and 54 deletions
|
|
@ -33,6 +33,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/RandomValueSharingStyleValue.h>
|
||||
#include <LibWeb/DOM/Attr.h>
|
||||
#include <LibWeb/DOM/DOMTokenList.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
|
@ -4311,6 +4312,19 @@ GC::Ref<CSS::StylePropertyMapReadOnly> Element::computed_style_map()
|
|||
return *m_computed_style_map_cache;
|
||||
}
|
||||
|
||||
double Element::ensure_css_random_base_value(CSS::RandomCachingKey const& random_caching_key)
|
||||
{
|
||||
// NB: We cache element-shared random base values on the Document and non-element-shared ones on the Element itself
|
||||
// so that when an element is removed it takes its non-shared cache with it.
|
||||
if (!random_caching_key.element_id.has_value())
|
||||
return document().ensure_element_shared_css_random_base_value(random_caching_key);
|
||||
|
||||
return m_element_specific_css_random_base_value_cache.ensure(random_caching_key, []() {
|
||||
static XorShift128PlusRNG random_number_generator;
|
||||
return random_number_generator.get();
|
||||
});
|
||||
}
|
||||
|
||||
// The element to inherit style from.
|
||||
// If a pseudo-element is specified, this will return the element itself.
|
||||
// Otherwise, if this element is slotted somewhere, it will return the slot's element to inherit style from.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue