From 5d740e4eddcb5c96ea879e0fadee5c95aae73a6e Mon Sep 17 00:00:00 2001 From: Ravi Shankar Date: Sat, 18 Feb 2017 11:13:19 +0530 Subject: [PATCH] Add gecko glue for grid --- components/style/gecko/values.rs | 36 ++++++++++++++++++++++- components/style/properties/gecko.mako.rs | 32 +++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 5e9f6dabd45..9cea3f36357 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -8,13 +8,14 @@ use app_units::Au; use cssparser::RGBA; -use gecko_bindings::structs::{nsStyleCoord, StyleShapeRadius}; +use gecko_bindings::structs::{nsStyleCoord, StyleGridTrackBreadth, StyleShapeRadius}; use gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue}; use std::cmp::max; use values::{Auto, Either, None_}; use values::computed::{Angle, LengthOrPercentageOrNone, Number}; use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; use values::computed::basic_shape::ShapeRadius; +use values::specified::grid::{TrackBreadth, TrackKeyword}; /// A trait that defines an interface to convert from and to `nsStyleCoord`s. pub trait GeckoStyleCoordConvertible : Sized { @@ -137,6 +138,39 @@ impl GeckoStyleCoordConvertible for LengthOrPercentageOrNone { } } +impl GeckoStyleCoordConvertible for TrackBreadth { + fn to_gecko_style_coord(&self, coord: &mut T) { + match *self { + TrackBreadth::Breadth(ref lop) => lop.to_gecko_style_coord(coord), + TrackBreadth::Flex(fr) => coord.set_value(CoordDataValue::FlexFraction(fr)), + TrackBreadth::Keyword(TrackKeyword::Auto) => coord.set_value(CoordDataValue::Auto), + TrackBreadth::Keyword(TrackKeyword::MinContent) => + coord.set_value(CoordDataValue::Enumerated(StyleGridTrackBreadth::MinContent as u32)), + TrackBreadth::Keyword(TrackKeyword::MaxContent) => + coord.set_value(CoordDataValue::Enumerated(StyleGridTrackBreadth::MaxContent as u32)), + } + } + + fn from_gecko_style_coord(coord: &T) -> Option { + L::from_gecko_style_coord(coord).map(TrackBreadth::Breadth).or_else(|| { + match coord.as_value() { + CoordDataValue::Enumerated(v) => { + if v == StyleGridTrackBreadth::MinContent as u32 { + Some(TrackBreadth::Keyword(TrackKeyword::MinContent)) + } else if v == StyleGridTrackBreadth::MaxContent as u32 { + Some(TrackBreadth::Keyword(TrackKeyword::MaxContent)) + } else { + None + } + }, + CoordDataValue::FlexFraction(fr) => Some(TrackBreadth::Flex(fr)), + CoordDataValue::Auto => Some(TrackBreadth::Keyword(TrackKeyword::Auto)), + _ => L::from_gecko_style_coord(coord).map(TrackBreadth::Breadth), + } + }) + } +} + impl GeckoStyleCoordConvertible for ShapeRadius { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 88766d34fe6..73a53dfe259 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -961,7 +961,7 @@ fn static_assert() { <%self:impl_trait style_struct_name="Position" skip_longhands="${skip_position_longhands} z-index box-sizing order align-content justify-content align-self justify-self align-items - justify-items"> + justify-items grid-auto-rows grid-auto-columns"> % for side in SIDES: <% impl_split_style_coord("%s" % side.ident, "mOffset", @@ -1083,6 +1083,36 @@ fn static_assert() { } % endfor + % for kind in ["rows", "columns"]: + pub fn set_grid_auto_${kind}(&mut self, v: longhands::grid_auto_rows::computed_value::T) { + use values::specified::grid::TrackSize; + + match v { + TrackSize::FitContent(lop) => { + // Gecko sets min value to None and max value to the actual value in fit-content + // https://dxr.mozilla.org/mozilla-central/rev/0eef1d5/layout/style/nsRuleNode.cpp#8221 + self.gecko.mGridAuto${kind.title()}Min.set_value(CoordDataValue::None); + lop.to_gecko_style_coord(&mut self.gecko.mGridAuto${kind.title()}Max); + }, + TrackSize::Breadth(breadth) => { + // Set the value to both fields if there's one breadth value + // https://dxr.mozilla.org/mozilla-central/rev/0eef1d5/layout/style/nsRuleNode.cpp#8230 + breadth.to_gecko_style_coord(&mut self.gecko.mGridAuto${kind.title()}Min); + breadth.to_gecko_style_coord(&mut self.gecko.mGridAuto${kind.title()}Max); + }, + TrackSize::MinMax(min, max) => { + min.to_gecko_style_coord(&mut self.gecko.mGridAuto${kind.title()}Min); + max.to_gecko_style_coord(&mut self.gecko.mGridAuto${kind.title()}Max); + }, + } + } + + pub fn copy_grid_auto_${kind}_from(&mut self, other: &Self) { + self.gecko.mGridAuto${kind.title()}Min.copy_from(&other.gecko.mGridAuto${kind.title()}Min); + self.gecko.mGridAuto${kind.title()}Max.copy_from(&other.gecko.mGridAuto${kind.title()}Max); + } + % endfor + <% skip_outline_longhands = " ".join("outline-style outline-width".split() +