Bug 1547231 - Add an internal aspect-ratio CSS property. r=dholbert
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 26 Jun 2019 22:10:04 +0000
changeset 543086 e7fd34a8c655220798eb284eb05f09e00839376e
parent 543085 fe2a14fc3e45f9f09fc46a6e913a824025d47045
child 543087 e314c697fe89257715b8743fcf936a6384bade47
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1547231
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1547231 - Add an internal aspect-ratio CSS property. r=dholbert Differential Revision: https://phabricator.services.mozilla.com/D29037
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
layout/style/test/ListCSSProperties.cpp
servo/components/style/properties/data.py
servo/components/style/properties/longhands/position.mako.rs
servo/ports/geckolib/glue.rs
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -1272,16 +1272,17 @@ nsStylePosition::nsStylePosition(const D
       mHeight(StyleSize::Auto()),
       mMinHeight(StyleSize::Auto()),
       mMaxHeight(StyleMaxSize::None()),
       mFlexBasis(StyleFlexBasis::Size(StyleSize::Auto())),
       mGridAutoColumnsMin(eStyleUnit_Auto),
       mGridAutoColumnsMax(eStyleUnit_Auto),
       mGridAutoRowsMin(eStyleUnit_Auto),
       mGridAutoRowsMax(eStyleUnit_Auto),
+      mAspectRatio(0.0f),
       mGridAutoFlow(NS_STYLE_GRID_AUTO_FLOW_ROW),
       mBoxSizing(StyleBoxSizing::Content),
       mAlignContent(NS_STYLE_ALIGN_NORMAL),
       mAlignItems(NS_STYLE_ALIGN_NORMAL),
       mAlignSelf(NS_STYLE_ALIGN_AUTO),
       mJustifyContent(NS_STYLE_JUSTIFY_NORMAL),
       mSpecifiedJustifyItems(NS_STYLE_JUSTIFY_LEGACY),
       mJustifyItems(NS_STYLE_JUSTIFY_NORMAL),
@@ -1318,16 +1319,17 @@ nsStylePosition::nsStylePosition(const n
       mHeight(aSource.mHeight),
       mMinHeight(aSource.mMinHeight),
       mMaxHeight(aSource.mMaxHeight),
       mFlexBasis(aSource.mFlexBasis),
       mGridAutoColumnsMin(aSource.mGridAutoColumnsMin),
       mGridAutoColumnsMax(aSource.mGridAutoColumnsMax),
       mGridAutoRowsMin(aSource.mGridAutoRowsMin),
       mGridAutoRowsMax(aSource.mGridAutoRowsMax),
+      mAspectRatio(aSource.mAspectRatio),
       mGridAutoFlow(aSource.mGridAutoFlow),
       mBoxSizing(aSource.mBoxSizing),
       mAlignContent(aSource.mAlignContent),
       mAlignItems(aSource.mAlignItems),
       mAlignSelf(aSource.mAlignSelf),
       mJustifyContent(aSource.mJustifyContent),
       mSpecifiedJustifyItems(aSource.mSpecifiedJustifyItems),
       mJustifyItems(aSource.mJustifyItems),
@@ -1492,16 +1494,21 @@ nsChangeHint nsStylePosition::CalcDiffer
   if (isVertical ? widthChanged : heightChanged) {
     hint |= nsChangeHint_ReflowHintsForBSizeChange;
   }
 
   if (isVertical ? heightChanged : widthChanged) {
     hint |= nsChangeHint_ReflowHintsForISizeChange;
   }
 
+  if (mAspectRatio != aNewData.mAspectRatio) {
+    hint |= nsChangeHint_ReflowHintsForISizeChange |
+            nsChangeHint_ReflowHintsForBSizeChange;
+  }
+
   // If any of the offsets have changed, then return the respective hints
   // so that we would hopefully be able to avoid reflowing.
   // Note that it is possible that we'll need to reflow when processing
   // restyles, but we don't have enough information to make a good decision
   // right now.
   // Don't try to handle changes between "auto" and non-auto efficiently;
   // that's tricky to do and will hardly ever be able to avoid a reflow.
   if (mOffset != aNewData.mOffset) {
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -1067,16 +1067,17 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
   StyleSize mHeight;
   StyleSize mMinHeight;
   StyleMaxSize mMaxHeight;
   StyleFlexBasis mFlexBasis;
   nsStyleCoord mGridAutoColumnsMin;  // coord, percent, enum, calc, flex
   nsStyleCoord mGridAutoColumnsMax;  // coord, percent, enum, calc, flex
   nsStyleCoord mGridAutoRowsMin;     // coord, percent, enum, calc, flex
   nsStyleCoord mGridAutoRowsMax;     // coord, percent, enum, calc, flex
+  float mAspectRatio;
   uint8_t mGridAutoFlow;             // NS_STYLE_GRID_AUTO_FLOW_*
   mozilla::StyleBoxSizing mBoxSizing;
 
   // All align/justify properties here take NS_STYLE_ALIGN_* values.
   uint16_t mAlignContent;  // fallback value in the high byte
   uint8_t mAlignItems;
   uint8_t mAlignSelf;
   uint16_t mJustifyContent;  // fallback value in the high byte
--- a/layout/style/test/ListCSSProperties.cpp
+++ b/layout/style/test/ListCSSProperties.cpp
@@ -85,16 +85,17 @@ const char* gShorthandPropertiesWithDOMP
 
 const char* gInaccessibleProperties[] = {
     // Don't print the properties that aren't accepted by the parser, per
     // CSSParserImpl::ParseProperty
     "-x-cols",
     "-x-lang",
     "-x-span",
     "-x-text-zoom",
+    "aspect-ratio",  // for now.
     "-moz-context-properties",
     "-moz-control-character-visibility",
     "-moz-list-reversed",  // parsed by UA sheets only
     "-moz-script-level",   // parsed by UA sheets only
     "-moz-script-size-multiplier",
     "-moz-script-min-size",
     "-moz-math-variant",
     "-moz-math-display",                     // parsed by UA sheets only
--- a/servo/components/style/properties/data.py
+++ b/servo/components/style/properties/data.py
@@ -332,16 +332,17 @@ class Longhand(object):
                 "JustifySelf",
                 "LineBreak",
                 "MozForceBrokenImageIcon",
                 "MozListReversed",
                 "MozScriptLevel",
                 "MozScriptMinSize",
                 "MozScriptSizeMultiplier",
                 "NonNegativeNumber",
+                "Number",
                 "OffsetRotate",
                 "Opacity",
                 "OutlineStyle",
                 "Overflow",
                 "OverflowAnchor",
                 "OverflowClipBox",
                 "OverflowWrap",
                 "OverscrollBehavior",
--- a/servo/components/style/properties/longhands/position.mako.rs
+++ b/servo/components/style/properties/longhands/position.mako.rs
@@ -386,8 +386,22 @@ macro_rules! impl_align_conversions {
     "length::NonNegativeLengthPercentageOrNormal",
     "computed::length::NonNegativeLengthPercentageOrNormal::normal()",
     alias="grid-row-gap",
     products="gecko",
     spec="https://drafts.csswg.org/css-align-3/#propdef-row-gap",
     animation_value_type="NonNegativeLengthPercentageOrNormal",
     servo_restyle_damage="reflow",
 )}
+
+// NOTE(emilio): Before exposing this property to content, we probably need to
+// change syntax and such, and make it apply to more elements.
+//
+// For now, it's used only for mapped attributes.
+${helpers.predefined_type(
+    "aspect-ratio",
+    "Number",
+    "computed::Number::zero()",
+    animation_value_type="ComputedValue",
+    spec="Internal, for now",
+    enabled_in="",
+    servo_restyle_damage="reflow",
+)}
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -4800,23 +4800,25 @@ pub extern "C" fn Servo_DeclarationBlock
 pub extern "C" fn Servo_DeclarationBlock_SetNumberValue(
     declarations: &RawServoDeclarationBlock,
     property: nsCSSPropertyID,
     value: f32,
 ) {
     use style::properties::longhands::_moz_script_level::SpecifiedValue as MozScriptLevel;
     use style::properties::longhands::_moz_script_size_multiplier::SpecifiedValue as MozScriptSizeMultiplier;
     use style::properties::PropertyDeclaration;
+    use style::values::specified::Number;
 
     let long = get_longhand_from_id!(property);
 
     let prop = match_wrap_declared! { long,
         MozScriptSizeMultiplier => MozScriptSizeMultiplier(value),
         // Gecko uses Number values to signal that it is absolute
         MozScriptLevel => MozScriptLevel::MozAbsolute(value as i32),
+        AspectRatio => Number::new(value),
     };
     write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| {
         decls.push(prop, Importance::Normal);
     })
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_DeclarationBlock_SetPercentValue(