diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 0248fb1822f4..b85022fccd52 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -14420,6 +14420,7 @@ void Document::PropagateUseCounters(Document* aParentDocument) { return; } + SetCssUseCounterBits(); contentParent->mChildDocumentUseCounters |= mUseCounters; contentParent->mChildDocumentUseCounters |= mChildDocumentUseCounters; } @@ -14476,6 +14477,19 @@ static_assert(size_t(eUseCounter_Count) * 2 == #undef CSS_PROP_PUBLIC_OR_PRIVATE #undef ASSERT_CSS_COUNTER +void Document::SetCssUseCounterBits() { + if (!mStyleUseCounters) { + return; + } + + for (size_t i = 0; i < eCSSProperty_COUNT_with_aliases; ++i) { + auto id = nsCSSPropertyID(i); + if (Servo_IsPropertyIdRecordedInUseCounter(mStyleUseCounters.get(), id)) { + SetUseCounter(nsCSSProps::UseCounterFor(id)); + } + } +} + void Document::PropagateUseCountersToPage() { if (mDisplayDocument) { @@ -14514,6 +14528,7 @@ void Document::ReportUseCounters() { } mReportedUseCounters = true; + SetCssUseCounterBits(); // Call ReportUseCounters in all our outstanding subdocuments and resources // and such. This needs to be here so that all our sub documents propagate our diff --git a/dom/base/Document.h b/dom/base/Document.h index 50e3a041a7c0..8e3bb21a941c 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -4039,6 +4039,10 @@ class Document : public nsINode, private: void InitializeLocalization(nsTArray& aResourceIds); + // Takes the bits from mStyleUseCounters if appropriate, and sets them in + // mUseCounters. + void SetCssUseCounterBits(); + // Returns true if there is any valid value in the viewport meta tag. bool ParseWidthAndHeightInMetaViewport(const nsAString& aWidthString, const nsAString& aHeightString, diff --git a/dom/base/test/browser.ini b/dom/base/test/browser.ini index 484bcd779ab2..39338e66ac90 100644 --- a/dom/base/test/browser.ini +++ b/dom/base/test/browser.ini @@ -24,6 +24,7 @@ support-files = file_messagemanager_unload.html file_pluginAudio.html file_use_counter_outer.html + file_use_counter_style.html file_use_counter_svg_getElementById.svg file_use_counter_svg_currentScale.svg file_use_counter_svg_fill_pattern_definition.svg diff --git a/dom/base/test/browser_use_counters.js b/dom/base/test/browser_use_counters.js index 3cdc73504c89..cc1b5e914193 100644 --- a/dom/base/test/browser_use_counters.js +++ b/dom/base/test/browser_use_counters.js @@ -51,6 +51,24 @@ add_task(async function() { "SVGSVGELEMENT_CURRENTSCALE_setter" ); + // Check for longhands. + await check_use_counter_iframe( + "file_use_counter_style.html", + "CSS_PROPERTY_BackgroundImage" + ); + + // Check for shorthands. + await check_use_counter_iframe( + "file_use_counter_style.html", + "CSS_PROPERTY_Padding" + ); + + // Check for aliases. + await check_use_counter_iframe( + "file_use_counter_style.html", + "CSS_PROPERTY_MozTransform" + ); + // Check that even loads from the imglib cache update use counters. The // images should still be there, because we just loaded them in the last // set of tests. But we won't get updated counts for the document @@ -95,8 +113,9 @@ add_task(async function() { // that reference patterns defined in the same file or in data: URLs. await check_use_counter_direct( "file_use_counter_svg_fill_pattern_internal.svg", - "CSS_PROPERTY_FillOpacity", + "CSS_PROPERTY_FillOpacity" ); + // data: URLs don't correctly propagate to their referring document yet. //yield check_use_counter_direct("file_use_counter_svg_fill_pattern_data.svg", // "PROPERTY_FILL_OPACITY"); diff --git a/dom/base/test/file_use_counter_style.html b/dom/base/test/file_use_counter_style.html new file mode 100644 index 000000000000..4848b0a649d1 --- /dev/null +++ b/dom/base/test/file_use_counter_style.html @@ -0,0 +1,10 @@ + + + +
diff --git a/servo/ports/geckolib/glue.rs b/servo/ports/geckolib/glue.rs index d045ce9d7d99..02a6a117444f 100644 --- a/servo/ports/geckolib/glue.rs +++ b/servo/ports/geckolib/glue.rs @@ -6552,6 +6552,15 @@ pub unsafe extern "C" fn Servo_UseCounters_Merge( doc_counters.merge(sheet_counters) } +#[no_mangle] +pub unsafe extern "C" fn Servo_IsPropertyIdRecordedInUseCounter( + use_counters: &UseCounters, + id: nsCSSPropertyID, +) -> bool { + let id = NonCustomPropertyId::from_nscsspropertyid(id).unwrap(); + use_counters.non_custom_properties.recorded(id) +} + #[no_mangle] pub unsafe extern "C" fn Servo_IsCssPropertyRecordedInUseCounter( use_counters: &UseCounters,