From 9cadf878d919f2b3b86bdaa3458bae0db58efe40 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Tue, 11 Jun 2024 12:00:50 +0000 Subject: [PATCH] Bug 1901374: Implement field-sizing parsing r=emilio This change adds a new layout.css.field-sizing.enabled pref that controls the availability of the field-sizing CSS property. With the pref enabled this property now parses according to the spec. Spec: https://drafts.csswg.org/css-ui/#field-sizing Differential Revision: https://phabricator.services.mozilla.com/D212983 --- dom/base/use_counter_metrics.yaml | 34 +++++++++++++++++++ layout/style/ServoBindings.toml | 1 + layout/style/nsStyleConsts.h | 6 ++++ layout/style/nsStyleStruct.cpp | 9 +++-- layout/style/nsStyleStruct.h | 2 ++ layout/style/test/mochitest.toml | 1 + layout/style/test/property_database.js | 13 +++++++ modules/libpref/init/StaticPrefList.yaml | 6 ++++ .../style/properties/longhands/ui.mako.rs | 11 ++++++ .../web-platform/meta/css/css-ui/__dir__.ini | 2 +- .../parsing/field-sizing-computed.html.ini | 6 ---- .../parsing/field-sizing-valid.html.ini | 6 ---- 12 files changed, 82 insertions(+), 15 deletions(-) delete mode 100644 testing/web-platform/meta/css/css-ui/parsing/field-sizing-computed.html.ini delete mode 100644 testing/web-platform/meta/css/css-ui/parsing/field-sizing-valid.html.ini diff --git a/dom/base/use_counter_metrics.yaml b/dom/base/use_counter_metrics.yaml index b6c099e25dcf..7c289569277e 100644 --- a/dom/base/use_counter_metrics.yaml +++ b/dom/base/use_counter_metrics.yaml @@ -16512,6 +16512,23 @@ use.counter.css.page: send_in_pings: - use-counters + css_field_sizing: + type: counter + description: > + Whether a page used the CSS property field-sizing. + Compare against `use.counter.top_level_content_documents_destroyed` + to calculate the rate. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1852098 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1852098 + notification_emails: + - dom-core@mozilla.com + - emilio@mozilla.com + expires: never + send_in_pings: + - use-counters + css_flex_direction: type: counter description: > @@ -28448,6 +28465,23 @@ use.counter.css.doc: send_in_pings: - use-counters + css_field_sizing: + type: counter + description: > + Whether a document used the CSS property field-sizing. + Compare against `use.counter.content_documents_destroyed` + to calculate the rate. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1852098 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1852098 + notification_emails: + - dom-core@mozilla.com + - emilio@mozilla.com + expires: never + send_in_pings: + - use-counters + css_flex_direction: type: counter description: > diff --git a/layout/style/ServoBindings.toml b/layout/style/ServoBindings.toml index 1c2f79c7d3c4..e382c29d407d 100644 --- a/layout/style/ServoBindings.toml +++ b/layout/style/ServoBindings.toml @@ -139,6 +139,7 @@ rusty-enums = [ "mozilla::StyleListStylePosition", "mozilla::StylePointerEvents", "mozilla::StyleScrollbarWidth", + "mozilla::StyleFieldSizing", "mozilla::StyleWhiteSpaceCollapse", "mozilla::StyleTextWrapMode", "mozilla::StyleTextRendering", diff --git a/layout/style/nsStyleConsts.h b/layout/style/nsStyleConsts.h index 99433c902730..a16f921383ac 100644 --- a/layout/style/nsStyleConsts.h +++ b/layout/style/nsStyleConsts.h @@ -130,6 +130,12 @@ enum class StyleScrollbarWidth : uint8_t { None, }; +// field-sizing +enum class StyleFieldSizing : bool { + Fixed, + Content, +}; + // Shape source type enum class StyleShapeSourceType : uint8_t { None, diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index 08b7f7388e72..02a141860bc2 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -3113,7 +3113,8 @@ nsStyleUIReset::nsStyleUIReset() nsStyleAutoArray::WITH_SINGLE_INITIAL_ELEMENT), mViewTimelineNameCount(1), mViewTimelineAxisCount(1), - mViewTimelineInsetCount(1) { + mViewTimelineInsetCount(1), + mFieldSizing(StyleFieldSizing::Fixed) { MOZ_COUNT_CTOR(nsStyleUIReset); } @@ -3152,7 +3153,8 @@ nsStyleUIReset::nsStyleUIReset(const nsStyleUIReset& aSource) mViewTimelines(aSource.mViewTimelines.Clone()), mViewTimelineNameCount(aSource.mViewTimelineNameCount), mViewTimelineAxisCount(aSource.mViewTimelineAxisCount), - mViewTimelineInsetCount(aSource.mViewTimelineInsetCount) { + mViewTimelineInsetCount(aSource.mViewTimelineInsetCount), + mFieldSizing(aSource.mFieldSizing) { MOZ_COUNT_CTOR(nsStyleUIReset); } @@ -3166,6 +3168,9 @@ nsChangeHint nsStyleUIReset::CalcDifference( if (mMozSubtreeHiddenOnlyVisually != aNewData.mMozSubtreeHiddenOnlyVisually) { hint |= nsChangeHint_RepaintFrame; } + if (mFieldSizing != aNewData.mFieldSizing) { + hint |= nsChangeHint_NeutralChange; + } if (mScrollbarWidth != aNewData.mScrollbarWidth) { // For scrollbar-width change, we need some special handling similar // to overflow properties. Specifically, we may need to reconstruct diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index 7fa6625ea174..3eaae4047ae4 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -1737,6 +1737,8 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUIReset { uint32_t mViewTimelineNameCount; uint32_t mViewTimelineAxisCount; uint32_t mViewTimelineInsetCount; + + mozilla::StyleFieldSizing mFieldSizing; }; struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleUI { diff --git a/layout/style/test/mochitest.toml b/layout/style/test/mochitest.toml index c8c36dc4da73..15cc339749a6 100644 --- a/layout/style/test/mochitest.toml +++ b/layout/style/test/mochitest.toml @@ -12,6 +12,7 @@ prefs = [ "layout.css.basic-shape-xywh.enabled=true", "layout.css.transform-box-content-stroke.enabled=true", "layout.css.transition-behavior.enabled=true", + "layout.css.field-sizing.enabled=true", ] support-files = [ "animation_utils.js", diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index c66a36b02465..49347a86c9d8 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -14319,6 +14319,19 @@ if (IsCSSPropertyPrefEnabled("layout.css.transition-behavior.enabled")) { } } +if (IsCSSPropertyPrefEnabled("layout.css.field-sizing.enabled")) { + Object.assign(gCSSProperties, { + "field-sizing": { + domProp: "fieldSizing", + inherited: false, + type: CSS_TYPE_LONGHAND, + initial_values: ["fixed"], + other_values: ["content"], + invalid_values: ["none", "auto"], + }, + }); +} + // Copy aliased properties' fields from their alias targets. Keep this logic // at the bottom of this file to ensure all the aliased properties are // processed. diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 752262a5c2bf..225293f3da50 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -9547,6 +9547,12 @@ value: false mirror: always +# field-sizing CSS property +- name: layout.css.field-sizing.enabled + type: RelaxedAtomicBool + value: false + mirror: always + # Whether supports() conditions in @import is enabled - name: layout.css.import-supports.enabled type: RelaxedAtomicBool diff --git a/servo/components/style/properties/longhands/ui.mako.rs b/servo/components/style/properties/longhands/ui.mako.rs index 762cb64e9a2d..49a7ce563e46 100644 --- a/servo/components/style/properties/longhands/ui.mako.rs +++ b/servo/components/style/properties/longhands/ui.mako.rs @@ -432,3 +432,14 @@ ${helpers.predefined_type( rule_types_allowed=DEFAULT_RULES_EXCEPT_KEYFRAME, affects="", )} + +${helpers.single_keyword( + "field-sizing", + "fixed content", + engines="gecko", + gecko_enum_prefix="StyleFieldSizing", + animation_value_type="discrete", + gecko_pref="layout.css.field-sizing.enabled", + spec="https://drafts.csswg.org/css-ui/#field-sizing", + affects="layout", +)} diff --git a/testing/web-platform/meta/css/css-ui/__dir__.ini b/testing/web-platform/meta/css/css-ui/__dir__.ini index a0723d39bc0b..179944c0c5cf 100644 --- a/testing/web-platform/meta/css/css-ui/__dir__.ini +++ b/testing/web-platform/meta/css/css-ui/__dir__.ini @@ -1 +1 @@ -prefs: [intl.icu4x.segmenter.enabled:true] +prefs: [intl.icu4x.segmenter.enabled:true,layout.css.field-sizing.enabled:true] diff --git a/testing/web-platform/meta/css/css-ui/parsing/field-sizing-computed.html.ini b/testing/web-platform/meta/css/css-ui/parsing/field-sizing-computed.html.ini deleted file mode 100644 index c7eaf80f035d..000000000000 --- a/testing/web-platform/meta/css/css-ui/parsing/field-sizing-computed.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[field-sizing-computed.html] - [Property field-sizing value 'fixed'] - expected: FAIL - - [Property field-sizing value 'content'] - expected: FAIL diff --git a/testing/web-platform/meta/css/css-ui/parsing/field-sizing-valid.html.ini b/testing/web-platform/meta/css/css-ui/parsing/field-sizing-valid.html.ini deleted file mode 100644 index 7b58b5255f03..000000000000 --- a/testing/web-platform/meta/css/css-ui/parsing/field-sizing-valid.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[field-sizing-valid.html] - [e.style['field-sizing'\] = "fixed" should set the property value] - expected: FAIL - - [e.style['field-sizing'\] = "content" should set the property value] - expected: FAIL