diff --git a/devtools/server/actors/animation-type-longhand.js b/devtools/server/actors/animation-type-longhand.js index 889a798a156e..b899e866b950 100644 --- a/devtools/server/actors/animation-type-longhand.js +++ b/devtools/server/actors/animation-type-longhand.js @@ -143,6 +143,7 @@ exports.ANIMATION_TYPE_FOR_LONGHANDS = [ "paint-order", "pointer-events", "position", + "position-anchor", "print-color-adjust", "quotes", "resize", diff --git a/dom/base/use_counter_metrics.yaml b/dom/base/use_counter_metrics.yaml index 72074436843a..677dd2c9585b 100644 --- a/dom/base/use_counter_metrics.yaml +++ b/dom/base/use_counter_metrics.yaml @@ -107,7 +107,7 @@ use.counter: send_in_pings: - use-counters -# Total of 2305 use counter metrics (excludes denominators). +# Total of 2307 use counter metrics (excludes denominators). # Total of 354 'page' use counters. use.counter.page: svgsvgelement_getelementbyid: @@ -15541,7 +15541,7 @@ use.counter.deprecated_ops.doc: send_in_pings: - use-counters -# Total of 699 'CSS (page)' use counters. +# Total of 700 'CSS (page)' use counters. use.counter.css.page: css_align_content: type: counter @@ -19759,6 +19759,23 @@ use.counter.css.page: send_in_pings: - use-counters + css_position_anchor: + type: counter + description: > + Whether a page used the CSS property position-anchor. + 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_quotes: type: counter description: > @@ -27426,7 +27443,7 @@ use.counter.css.page: send_in_pings: - use-counters -# Total of 699 'CSS (document)' use counters. +# Total of 700 'CSS (document)' use counters. use.counter.css.doc: css_align_content: type: counter @@ -31644,6 +31661,23 @@ use.counter.css.doc: send_in_pings: - use-counters + css_position_anchor: + type: counter + description: > + Whether a document used the CSS property position-anchor. + 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_quotes: type: counter description: > diff --git a/layout/style/ServoBindings.toml b/layout/style/ServoBindings.toml index aa87232400e4..adcc9eb25771 100644 --- a/layout/style/ServoBindings.toml +++ b/layout/style/ServoBindings.toml @@ -622,6 +622,7 @@ cbindgen-types = [ { gecko = "StyleAu", servo = "app_units::Au" }, { gecko = "StyleAnchorName", servo = "crate::values::computed::position::AnchorName" }, { gecko = "StyleAnchorScope", servo = "crate::values::computed::position::AnchorScope" }, + { gecko = "StylePositionAnchor", servo = "crate::values::computed::position::PositionAnchor" }, ] mapped-generic-types = [ diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp index c08f534f4dfb..5594bd67a9a1 100644 --- a/layout/style/nsStyleStruct.cpp +++ b/layout/style/nsStyleStruct.cpp @@ -1051,6 +1051,7 @@ nsStylePosition::nsStylePosition() mHeight(StyleSize::Auto()), mMinHeight(StyleSize::Auto()), mMaxHeight(StyleMaxSize::None()), + mPositionAnchor(StylePositionAnchor::Auto()), mFlexBasis(StyleFlexBasis::Size(StyleSize::Auto())), mAspectRatio(StyleAspectRatio::Auto()), mGridAutoFlow(StyleGridAutoFlow::ROW), @@ -1099,6 +1100,7 @@ nsStylePosition::nsStylePosition(const nsStylePosition& aSource) mHeight(aSource.mHeight), mMinHeight(aSource.mMinHeight), mMaxHeight(aSource.mMaxHeight), + mPositionAnchor(aSource.mPositionAnchor), mFlexBasis(aSource.mFlexBasis), mGridAutoColumns(aSource.mGridAutoColumns), mGridAutoRows(aSource.mGridAutoRows), @@ -1276,6 +1278,13 @@ nsChangeHint nsStylePosition::CalcDifference( } } + if (mPositionAnchor != aNewData.mPositionAnchor) { + // 'position-anchor' provides a default anchor for other anchor positioning + // properties in the event that they don't specify one explicitly. + // TODO(jwatt): Re-evaluate what we're doing here. + hint |= nsChangeHint_NeutralChange; + } + if (mAspectRatio != aNewData.mAspectRatio) { hint |= nsChangeHint_ReflowHintsForISizeChange | nsChangeHint_ReflowHintsForBSizeChange; diff --git a/layout/style/nsStyleStruct.h b/layout/style/nsStyleStruct.h index b6176aeaa720..68d926f5f727 100644 --- a/layout/style/nsStyleStruct.h +++ b/layout/style/nsStyleStruct.h @@ -744,6 +744,11 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition { StyleSize mHeight; StyleSize mMinHeight; StyleMaxSize mMaxHeight; + + // 'auto' or a `` referencing an anchor positioning anchor + // element. + mozilla::StylePositionAnchor mPositionAnchor; + mozilla::StyleFlexBasis mFlexBasis; StyleImplicitGridTracks mGridAutoColumns; StyleImplicitGridTracks mGridAutoRows; diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index 9d14264ca26a..1f432c331b94 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -13337,6 +13337,15 @@ if (IsCSSPropertyPrefEnabled("layout.css.anchor-positioning.enabled")) { "--foo,", ], }; + + gCSSProperties["position-anchor"] = { + domProp: "positionAnchor", + inherited: false, + type: CSS_TYPE_LONGHAND, + initial_values: ["auto"], + other_values: ["--foo"], + invalid_values: ["none", "--foo, auto", "auto, --bar", "foo"], + }; } if (false) { diff --git a/servo/components/style/properties/longhands/position.mako.rs b/servo/components/style/properties/longhands/position.mako.rs index e71803e026ff..707dff89a2eb 100644 --- a/servo/components/style/properties/longhands/position.mako.rs +++ b/servo/components/style/properties/longhands/position.mako.rs @@ -331,6 +331,17 @@ ${helpers.predefined_type( )} % endfor +${helpers.predefined_type( + "position-anchor", + "PositionAnchor", + "computed::PositionAnchor::auto()", + engines="gecko", + animation_value_type="discrete", + gecko_pref="layout.css.anchor-positioning.enabled", + spec="https://drafts.csswg.org/css-anchor-position-1/#propdef-position-anchor", + affects="layout", +)} + ${helpers.single_keyword( "box-sizing", "content-box border-box", diff --git a/servo/components/style/values/computed/mod.rs b/servo/components/style/values/computed/mod.rs index 1dffb2637a92..69b10e2bdf0d 100644 --- a/servo/components/style/values/computed/mod.rs +++ b/servo/components/style/values/computed/mod.rs @@ -90,6 +90,7 @@ pub use self::page::{PageName, PageOrientation, PageSize, PageSizeOrientation, P pub use self::percentage::{NonNegativePercentage, Percentage}; pub use self::position::AnchorName; pub use self::position::AnchorScope; +pub use self::position::PositionAnchor; pub use self::position::AspectRatio; pub use self::position::{ GridAutoFlow, GridTemplateAreas, MasonryAutoFlow, Position, PositionOrAuto, ZIndex, diff --git a/servo/components/style/values/computed/position.rs b/servo/components/style/values/computed/position.rs index 1b5dcbb9b0b2..055aa4d9032c 100644 --- a/servo/components/style/values/computed/position.rs +++ b/servo/components/style/values/computed/position.rs @@ -13,7 +13,8 @@ use crate::values::generics::position::Position as GenericPosition; use crate::values::generics::position::PositionComponent as GenericPositionComponent; use crate::values::generics::position::PositionOrAuto as GenericPositionOrAuto; use crate::values::generics::position::ZIndex as GenericZIndex; -pub use crate::values::specified::position::{AnchorName, AnchorScope, GridAutoFlow, GridTemplateAreas, MasonryAutoFlow}; +pub use crate::values::specified::position::{GridAutoFlow, GridTemplateAreas, MasonryAutoFlow}; +pub use crate::values::specified::position::{AnchorName, AnchorScope, PositionAnchor}; use crate::Zero; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; diff --git a/servo/components/style/values/specified/mod.rs b/servo/components/style/values/specified/mod.rs index 64e66cf92d37..f6916efffc25 100644 --- a/servo/components/style/values/specified/mod.rs +++ b/servo/components/style/values/specified/mod.rs @@ -83,6 +83,7 @@ pub use self::percentage::{NonNegativePercentage, Percentage}; pub use self::position::AspectRatio; pub use self::position::AnchorName; pub use self::position::AnchorScope; +pub use self::position::PositionAnchor; pub use self::position::{GridAutoFlow, GridTemplateAreas, Position, PositionOrAuto}; pub use self::position::{MasonryAutoFlow, MasonryItemOrder, MasonryPlacement}; pub use self::position::{PositionComponent, ZIndex}; diff --git a/servo/components/style/values/specified/position.rs b/servo/components/style/values/specified/position.rs index 10e1bd849e91..87f653dee82f 100644 --- a/servo/components/style/values/specified/position.rs +++ b/servo/components/style/values/specified/position.rs @@ -456,6 +456,39 @@ impl Parse for AnchorScope { } } +/// https://drafts.csswg.org/css-anchor-position-1/#propdef-position-anchor +#[derive( + Clone, + Debug, + MallocSizeOf, + Parse, + PartialEq, + SpecifiedValueInfo, + ToComputedValue, + ToCss, + ToResolvedValue, + ToShmem, +)] +#[repr(u8)] +pub enum PositionAnchor { + /// `auto` + Auto, + /// `` + Ident(DashedIdent), +} + +impl PositionAnchor { + /// Return the `auto` value. + pub fn auto() -> Self { + Self::Auto + } + + /// Returns whether this is the `auto` value. + pub fn is_auto(&self) -> bool { + *self == Self::Auto + } +} + /// Represents a side, either horizontal or vertical, of a CSS position. pub trait Side { /// Returns the start side. diff --git a/servo/ports/geckolib/cbindgen.toml b/servo/ports/geckolib/cbindgen.toml index d07926ea4813..0197cc0f9c36 100644 --- a/servo/ports/geckolib/cbindgen.toml +++ b/servo/ports/geckolib/cbindgen.toml @@ -111,6 +111,7 @@ include = [ "DisplayInside", "DisplayMode", "Platform", + "PositionAnchor", "GtkThemeFamily", "PrefersColorScheme", "PrefersContrast",