Files
ladybird/Libraries/LibWeb/CSS/CustomPropertyRegistration.h
Andreas Kling a94f9aa4c7 LibWeb: Filter non-inheriting registered custom properties on inherit
When inheriting custom-property data from a parent element, we were
copying the parent's full CustomPropertyData regardless of whether
each property was registered with `inherits: false`. That caused
non-inheriting registered properties to leak from the parent,
contrary to the @property spec.

Wrap the parent-side lookup so we strip any custom property whose
registration says it should not inherit, and only build a fresh
CustomPropertyData when at least one property was actually filtered.

Key the filtered view's cache on both the destination document's
identity and its custom-property registration generation. The
generation counter is local to each document, so a subtree adopted
into another document (or queried via getComputedStyle from another
window) could otherwise pick up a cached view computed under an
unrelated registration set and silently skip non-inheriting filtering
in the new document.
2026-04-22 20:59:00 +02:00

51 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Copyright (c) 2026, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/FlyString.h>
#include <AK/RefPtr.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
#include <LibWeb/Forward.h>
namespace Web::CSS {
// https://drafts.css-houdini.org/css-properties-values-api/#custom-property-registration
// A registered custom property has a custom property registration that contains all the data necessary to treat it
// like a real property. Its a struct consisting of:
struct CustomPropertyRegistration {
// - a property name (a custom property name string)
FlyString property_name;
// - a syntax (a syntax string)
String syntax;
// - an inherit flag (a boolean)
bool inherit;
// - optionally, an initial value (a string which successfully parses according to the syntax)
// NB: Spec actually wants this to be a parsed value, and that's what's most useful to us.
// See https://drafts.css-houdini.org/css-properties-values-api/#register-a-custom-property
RefPtr<StyleValue const> initial_value;
};
inline bool operator==(CustomPropertyRegistration const& a, CustomPropertyRegistration const& b)
{
if (a.property_name != b.property_name)
return false;
if (a.syntax != b.syntax)
return false;
if (a.inherit != b.inherit)
return false;
if (a.initial_value.ptr() == b.initial_value.ptr())
return true;
if (!a.initial_value || !b.initial_value)
return false;
return a.initial_value->equals(*b.initial_value);
}
}