Bug 1866707 - Make `InspectorUtils.isInheritedProperty` check property definition in custom properties registry. r=zrhoffman.

Since registered custom properties can be specified to not inherit,
DevTools need to retrieve this information in order to display accurate
data in the rules view.
The method signature is changed and now take a Document so we can lookup
the registry.
The existing test is updated with registered and unregistered custom properties.

Next patch in queue handles the impact in DevTools code.

Differential Revision: https://phabricator.services.mozilla.com/D194629
This commit is contained in:
Nicolas Chevobbe 2023-11-27 18:39:10 +00:00
Родитель e77161a317
Коммит a41df8b4ed
5 изменённых файлов: 74 добавлений и 12 удалений

Просмотреть файл

@ -26,7 +26,7 @@ namespace InspectorUtils {
// Useful for DevTools as this is faster than in JS where we'd have a lot of
// proxy access overhead building the same list.
sequence<CSSRule> getAllStyleSheetCSSStyleRules(CSSStyleSheet sheet);
boolean isInheritedProperty(UTF8String property);
boolean isInheritedProperty(Document document, UTF8String property);
sequence<DOMString> getCSSPropertyNames(optional PropertyNamesOptions options = {});
sequence<PropertyPref> getCSSPropertyPrefs();
[Throws] sequence<DOMString> getCSSValuesForProperty(UTF8String property);

Просмотреть файл

@ -361,8 +361,10 @@ void InspectorUtils::GetAllStyleSheetCSSStyleRules(
/* static */
bool InspectorUtils::IsInheritedProperty(GlobalObject& aGlobalObject,
Document& aDocument,
const nsACString& aPropertyName) {
return Servo_Property_IsInherited(&aPropertyName);
return Servo_Property_IsInherited(aDocument.EnsureStyleSet().RawData(),
&aPropertyName);
}
/* static */

Просмотреть файл

@ -82,7 +82,7 @@ class InspectorUtils {
// Utilities for working with CSS properties
//
// Returns true if the string names a property that is inherited by default.
static bool IsInheritedProperty(GlobalObject& aGlobal,
static bool IsInheritedProperty(GlobalObject& aGlobal, Document& aDocument,
const nsACString& aPropertyName);
// Get a list of all our supported property names. Optionally

Просмотреть файл

@ -7,22 +7,69 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=699592
<title>Test for InspectorUtils::isInheritedProperty</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<style>
@property --css-registered-inherits {
syntax: "*";
inherits: true;
}
@property --css-registered-no-inherits {
syntax: "*";
inherits: false;
}
</style>
<script>
CSS.registerProperty({
name: "--js-registered-inherits",
syntax: "*",
inherits: true,
});
CSS.registerProperty({
name: "--js-registered-no-inherits",
syntax: "*",
inherits: false,
});
</script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
const InspectorUtils = SpecialPowers.InspectorUtils;
function do_test() {
is(InspectorUtils.isInheritedProperty("font-size"), true, "font-size is inherited.");
const isInherited = (name) =>
SpecialPowers.InspectorUtils.isInheritedProperty(document, name);
is(InspectorUtils.isInheritedProperty("min-width"), false, "min-width is not inherited.");
is(isInherited("font-size"), true, "font-size is inherited.");
is(isInherited("min-width"), false, "min-width is not inherited.");
is(InspectorUtils.isInheritedProperty("font"), true, "shorthand font property is inherited.");
is(isInherited("font"), true, "shorthand font property is inherited.");
is(InspectorUtils.isInheritedProperty("border"), false, "shorthand border property not inherited.");
is(InspectorUtils.isInheritedProperty("garbage"), false, "Unknown property isn't inherited.");
is(isInherited("border"), false, "shorthand border property not inherited.");
is(isInherited("garbage"), false, "Unknown property isn't inherited.");
info("Checking isInheritedProperty result on custom properties");
is(isInherited("--unregistered-var"),true,
"Unregistered custom property is inherited."
);
is(
isInherited("--css-registered-inherits"),
true,
"Returns true for @property that inherits"
);
is(
isInherited("--css-registered-no-inherits"),
false,
"Returns false for @property that does not inherits"
);
is(
isInherited("--js-registered-inherits"),
true,
"Returns true for property registered in JS that inherits"
);
is(
isInherited("--js-registered-no-inherits"),
false,
"Returns false for property registered in JS that does not inherits"
);
SimpleTest.finish();
}

Просмотреть файл

@ -1333,14 +1333,27 @@ pub unsafe extern "C" fn Servo_Property_IsShorthand(
}
#[no_mangle]
pub unsafe extern "C" fn Servo_Property_IsInherited(prop_name: &nsACString) -> bool {
pub unsafe extern "C" fn Servo_Property_IsInherited(
per_doc_data: &PerDocumentStyleData,
prop_name: &nsACString,
) -> bool {
let prop_name = prop_name.as_str_unchecked();
let prop_id = match PropertyId::parse_enabled_for_all_content(prop_name) {
Ok(id) => id,
Err(_) => return false,
};
let longhand_id = match prop_id {
PropertyId::Custom(_) => return true,
PropertyId::Custom(property_name) => {
// let's check if the custom property is registered so we can check the
// property definition `inherits` value.
let stylist = &per_doc_data.borrow().stylist;
if let Some(registration) = stylist.get_custom_property_registration(&property_name) {
return registration.inherits();
}
// unregistered custom properties always inherits
return true;
},
PropertyId::Longhand(id) | PropertyId::LonghandAlias(id, _) => id,
PropertyId::Shorthand(id) | PropertyId::ShorthandAlias(id, _) => {
id.longhands().next().unwrap()