mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Add gecko glue for grid <track-size>
This commit is contained in:
parent
6d4cf7424c
commit
5d740e4edd
2 changed files with 66 additions and 2 deletions
|
@ -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<L: GeckoStyleCoordConvertible> GeckoStyleCoordConvertible for TrackBreadth<L> {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&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<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
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<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
|
|
|
@ -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
|
||||
|
||||
</%self:impl_trait>
|
||||
|
||||
<% skip_outline_longhands = " ".join("outline-style outline-width".split() +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue