diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 9b56f732835..0349e7ec220 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -14,10 +14,11 @@ use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue use gecko_bindings::bindings::{Gecko_InitializeImageCropRect, Gecko_SetImageElement}; use gecko_bindings::structs::{nsCSSUnit, nsStyleCoord_CalcValue, nsStyleImage}; use gecko_bindings::structs::{nsresult, SheetType}; -use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut}; +use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut}; use stylesheets::{Origin, RulesMutateError}; use values::computed::{Angle, CalcLengthOrPercentage, Gradient, Image}; use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; +use values::generics::grid::TrackSize; use values::generics::image::{CompatMode, Image as GenericImage, GradientItem}; use values::specified::length::Percentage; @@ -584,3 +585,53 @@ impl From for SheetType { } } } + +impl TrackSize { + /// Return TrackSize from given two nsStyleCoord + pub fn from_gecko_style_coords(gecko_min: &T, gecko_max: &T) -> Self { + use gecko_bindings::structs::root::nsStyleUnit; + use values::computed::length::LengthOrPercentage; + use values::generics::grid::{TrackBreadth, TrackSize}; + + if gecko_min.unit() == nsStyleUnit::eStyleUnit_None { + debug_assert!(gecko_max.unit() == nsStyleUnit::eStyleUnit_Coord || + gecko_max.unit() == nsStyleUnit::eStyleUnit_Percent); + return TrackSize::FitContent(LengthOrPercentage::from_gecko_style_coord(gecko_max) + .expect("gecko_max could not convert to LengthOrPercentage")); + } + + let min = TrackBreadth::from_gecko_style_coord(gecko_min) + .expect("gecko_min could not convert to TrackBreadth"); + let max = TrackBreadth::from_gecko_style_coord(gecko_max) + .expect("gecko_max could not convert to TrackBreadth"); + if min == max { + TrackSize::Breadth(max) + } else { + TrackSize::MinMax(min, max) + } + } + + /// Save TrackSize to given gecko fields. + pub fn to_gecko_style_coords(&self, gecko_min: &mut T, gecko_max: &mut T) { + use values::generics::grid::TrackSize; + + match *self { + TrackSize::FitContent(ref 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 + gecko_min.set_value(CoordDataValue::None); + lop.to_gecko_style_coord(gecko_max); + }, + TrackSize::Breadth(ref 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(gecko_min); + breadth.to_gecko_style_coord(gecko_max); + }, + TrackSize::MinMax(ref min, ref max) => { + min.to_gecko_style_coord(gecko_min); + max.to_gecko_style_coord(gecko_max); + }, + } + } +} diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 384ba40cda0..3796a98b58c 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1219,30 +1219,38 @@ fn static_assert() { self.gecko.${value.gecko}.mInteger = other.gecko.${value.gecko}.mInteger; self.gecko.${value.gecko}.mLineName.assign(&*other.gecko.${value.gecko}.mLineName); } + + pub fn clone_${value.name}(&self) -> longhands::${value.name}::computed_value::T { + use gecko_bindings::structs::{nsStyleGridLine_kMinLine, nsStyleGridLine_kMaxLine}; + use string_cache::Atom; + use values::specified::Integer; + + longhands::${value.name}::computed_value::T { + is_span: self.gecko.${value.gecko}.mHasSpan, + ident: { + let name = self.gecko.${value.gecko}.mLineName.to_string(); + if name.len() == 0 { + None + } else { + Some(CustomIdent(Atom::from(name))) + } + }, + line_num: + if self.gecko.${value.gecko}.mInteger == 0 { + None + } else { + debug_assert!(nsStyleGridLine_kMinLine <= self.gecko.${value.gecko}.mInteger); + debug_assert!(self.gecko.${value.gecko}.mInteger <= nsStyleGridLine_kMaxLine); + Some(Integer::new(self.gecko.${value.gecko}.mInteger)) + }, + } + } % endfor % for kind in ["rows", "columns"]: pub fn set_grid_auto_${kind}(&mut self, v: longhands::grid_auto_${kind}::computed_value::T) { - use values::generics::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); - }, - } + v.to_gecko_style_coords(&mut self.gecko.mGridAuto${kind.title()}Min, + &mut self.gecko.mGridAuto${kind.title()}Max) } pub fn copy_grid_auto_${kind}_from(&mut self, other: &Self) { @@ -1251,38 +1259,18 @@ fn static_assert() { } pub fn clone_grid_auto_${kind}(&self) -> longhands::grid_auto_${kind}::computed_value::T { - use gecko_bindings::structs::root::nsStyleUnit::eStyleUnit_None; - use values::computed::length::LengthOrPercentage; - use values::generics::grid::{TrackSize, TrackBreadth}; - - let ref min_gecko = self.gecko.mGridAuto${kind.title()}Min; - let ref max_gecko = self.gecko.mGridAuto${kind.title()}Max; - if min_gecko.unit() == eStyleUnit_None { - debug_assert!(max_gecko.unit() != eStyleUnit_None); - return TrackSize::FitContent(LengthOrPercentage::from_gecko_style_coord(max_gecko) - .expect("mGridAuto${kind.title()}Max contains style coord")); - } - - let min = TrackBreadth::from_gecko_style_coord(min_gecko) - .expect("mGridAuto${kind.title()}Min contains style coord"); - let max = TrackBreadth::from_gecko_style_coord(max_gecko) - .expect("mGridAuto${kind.title()}Max contains style coord"); - if min == max { - TrackSize::Breadth(max) - } else { - TrackSize::MinMax(min, max) - } + ::values::generics::grid::TrackSize::from_gecko_style_coords(&self.gecko.mGridAuto${kind.title()}Min, + &self.gecko.mGridAuto${kind.title()}Max) } pub fn set_grid_template_${kind}(&mut self, v: longhands::grid_template_${kind}::computed_value::T) { <% self_grid = "self.gecko.mGridTemplate%s" % kind.title() %> - use gecko::values::GeckoStyleCoordConvertible; use gecko_bindings::structs::{nsTArray, nsStyleGridLine_kMaxLine}; use nsstring::nsStringRepr; use std::usize; use values::CustomIdent; use values::generics::grid::TrackListType::Auto; - use values::generics::grid::{GridTemplateComponent, RepeatCount, TrackSize}; + use values::generics::grid::{GridTemplateComponent, RepeatCount}; #[inline] fn set_line_names(servo_names: &[CustomIdent], gecko_names: &mut nsTArray) { @@ -1295,25 +1283,6 @@ fn static_assert() { } } - fn set_track_size(value: TrackSize, gecko_min: &mut G, gecko_max: &mut G) - where G: CoordDataMut, T: GeckoStyleCoordConvertible - { - match value { - TrackSize::FitContent(lop) => { - gecko_min.set_value(CoordDataValue::None); - lop.to_gecko_style_coord(gecko_max); - }, - TrackSize::Breadth(breadth) => { - breadth.to_gecko_style_coord(gecko_min); - breadth.to_gecko_style_coord(gecko_max); - }, - TrackSize::MinMax(min, max) => { - min.to_gecko_style_coord(gecko_min); - max.to_gecko_style_coord(gecko_max); - }, - } - } - // Set defaults ${self_grid}.mRepeatAutoIndex = -1; ${self_grid}.set_mIsAutoFill(false); @@ -1367,13 +1336,13 @@ fn static_assert() { let name_list = line_names.next().expect("expected line-names"); set_line_names(&name_list, &mut ${self_grid}.mLineNameLists[i]); if i == auto_idx { - set_track_size(auto_track_size.take().expect("expected for "), - gecko_min, gecko_max); + let track_size = auto_track_size.take().expect("expected for "); + track_size.to_gecko_style_coords(gecko_min, gecko_max); continue } let track_size = values_iter.next().expect("expected value"); - set_track_size(track_size, gecko_min, gecko_max); + track_size.to_gecko_style_coords(gecko_min, gecko_max); } let final_names = line_names.next().unwrap(); diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index 1ab47d007ab..bcf6d110fce 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -260,7 +260,7 @@ ${helpers.predefined_type("object-position", ${helpers.predefined_type("grid-%s-%s" % (kind, range), "GridLine", "Default::default()", - animation_value_type="none", + animation_value_type="discrete", spec="https://drafts.csswg.org/css-grid/#propdef-grid-%s-%s" % (kind, range), products="gecko", boxed=True)}