Auto merge of #19378 - CYBAI:grid-auto-flow-out-of-mako, r=emilio

style: Move grid-auto-flow outside of mako

This is a sub-PR of #19015
r? emilio

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #19375
- [x] These changes do not require tests

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19378)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-11-28 05:16:49 -06:00 committed by GitHub
commit 66d0a41127
6 changed files with 134 additions and 128 deletions

View file

@ -293,128 +293,13 @@ ${helpers.predefined_type("object-position",
% endfor
<%helpers:longhand name="grid-auto-flow"
spec="https://drafts.csswg.org/css-grid/#propdef-grid-auto-flow"
products="gecko"
gecko_pref="layout.css.grid.enabled"
animation_value_type="discrete">
use std::fmt;
use style_traits::ToCss;
pub type SpecifiedValue = computed_value::T;
pub mod computed_value {
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
pub enum AutoFlow {
Row,
Column,
}
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
pub struct T {
pub autoflow: AutoFlow,
pub dense: bool,
}
}
impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str(match self.autoflow {
computed_value::AutoFlow::Column => "column",
computed_value::AutoFlow::Row => "row"
})?;
if self.dense { dest.write_str(" dense")?; }
Ok(())
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T {
autoflow: computed_value::AutoFlow::Row,
dense: false,
}
}
/// [ row | column ] || dense
pub fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
use self::computed_value::AutoFlow;
let mut value = None;
let mut dense = false;
while !input.is_exhausted() {
let location = input.current_source_location();
let ident = input.expect_ident()?;
let success = match_ignore_ascii_case! { &ident,
"row" if value.is_none() => {
value = Some(AutoFlow::Row);
true
},
"column" if value.is_none() => {
value = Some(AutoFlow::Column);
true
},
"dense" if !dense => {
dense = true;
true
},
_ => false
};
if !success {
return Err(location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())));
}
}
if value.is_some() || dense {
Ok(computed_value::T {
autoflow: value.unwrap_or(AutoFlow::Row),
dense: dense,
})
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
#[cfg(feature = "gecko")]
impl From<u8> for SpecifiedValue {
fn from(bits: u8) -> SpecifiedValue {
use gecko_bindings::structs;
use self::computed_value::AutoFlow;
SpecifiedValue {
autoflow:
if bits & structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8 != 0 {
AutoFlow::Row
} else {
AutoFlow::Column
},
dense:
bits & structs::NS_STYLE_GRID_AUTO_FLOW_DENSE as u8 != 0,
}
}
}
#[cfg(feature = "gecko")]
impl From<SpecifiedValue> for u8 {
fn from(v: SpecifiedValue) -> u8 {
use gecko_bindings::structs;
use self::computed_value::AutoFlow;
let mut result: u8 = match v.autoflow {
AutoFlow::Row => structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8,
AutoFlow::Column => structs::NS_STYLE_GRID_AUTO_FLOW_COLUMN as u8,
};
if v.dense {
result |= structs::NS_STYLE_GRID_AUTO_FLOW_DENSE as u8;
}
result
}
}
</%helpers:longhand>
${helpers.predefined_type("grid-auto-flow",
"GridAutoFlow",
initial_value="computed::GridAutoFlow::row()",
products="gecko",
animation_value_type="discrete",
gecko_pref="layout.css.grid.enabled",
spec="https://drafts.csswg.org/css-grid/#propdef-grid-auto-flow")}
<%helpers:longhand name="grid-template-areas"
spec="https://drafts.csswg.org/css-grid/#propdef-grid-template-areas"

View file

@ -470,10 +470,10 @@
products="gecko">
use parser::Parse;
use properties::longhands::{grid_auto_columns, grid_auto_rows, grid_auto_flow};
use properties::longhands::grid_auto_flow::computed_value::{AutoFlow, T as SpecifiedAutoFlow};
use values::{Either, None_};
use values::generics::grid::{GridTemplateComponent, TrackListType};
use values::specified::{GenericGridTemplateComponent, TrackSize};
use values::specified::position::{AutoFlow, GridAutoFlow};
pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> {
@ -485,7 +485,7 @@
let mut flow = grid_auto_flow::get_initial_value();
fn parse_auto_flow<'i, 't>(input: &mut Parser<'i, 't>, is_row: bool)
-> Result<SpecifiedAutoFlow, ParseError<'i>> {
-> Result<GridAutoFlow, ParseError<'i>> {
let mut auto_flow = None;
let mut dense = false;
for _ in 0..2 {
@ -503,7 +503,7 @@
}
auto_flow.map(|flow| {
SpecifiedAutoFlow {
GridAutoFlow {
autoflow: flow,
dense: dense,
}

View file

@ -54,7 +54,7 @@ pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNum
pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength};
pub use self::length::{CSSPixelLength, NonNegativeLength, NonNegativeLengthOrPercentage};
pub use self::percentage::Percentage;
pub use self::position::Position;
pub use self::position::{Position, GridAutoFlow};
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray, SVGWidth};
pub use self::table::XSpan;
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextOverflow, WordSpacing};

View file

@ -11,6 +11,7 @@ use std::fmt;
use style_traits::ToCss;
use values::computed::{LengthOrPercentage, Percentage};
use values::generics::position::Position as GenericPosition;
pub use values::specified::position::GridAutoFlow;
/// The computed value of a CSS `<position>`
pub type Position = GenericPosition<HorizontalPosition, VerticalPosition>;

View file

@ -50,7 +50,7 @@ pub use self::length::{NoCalcLength, ViewportPercentageLength};
pub use self::length::NonNegativeLengthOrPercentage;
pub use self::rect::LengthOrNumberRect;
pub use self::percentage::Percentage;
pub use self::position::{Position, PositionComponent};
pub use self::position::{Position, PositionComponent, GridAutoFlow};
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind, SVGStrokeDashArray, SVGWidth};
pub use self::table::XSpan;
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextDecorationLine, TextOverflow, WordSpacing};

View file

@ -9,8 +9,9 @@
use cssparser::Parser;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseErrorKind;
use std::fmt;
use style_traits::{ToCss, ParseError};
use style_traits::{ToCss, StyleParseErrorKind, ParseError};
use values::computed::{CalcLengthOrPercentage, LengthOrPercentage as ComputedLengthOrPercentage};
use values::computed::{Context, Percentage, ToComputedValue};
use values::generics::position::Position as GenericPosition;
@ -366,3 +367,122 @@ impl ToCss for LegacyPosition {
self.vertical.to_css(dest)
}
}
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
/// Auto-placement algorithm Option
pub enum AutoFlow {
/// The auto-placement algorithm places items by filling each row in turn,
/// adding new rows as necessary.
Row,
/// The auto-placement algorithm places items by filling each column in turn,
/// adding new columns as necessary.
Column,
}
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)]
/// Controls how the auto-placement algorithm works
/// specifying exactly how auto-placed items get flowed into the grid
pub struct GridAutoFlow {
/// Specifiy how auto-placement algorithm fills each `row` or `column` in turn
pub autoflow: AutoFlow,
/// Specify use `dense` packing algorithm or not
pub dense: bool,
}
impl GridAutoFlow {
#[inline]
/// Get default `grid-auto-flow` as `row`
pub fn row() -> GridAutoFlow {
GridAutoFlow {
autoflow: AutoFlow::Row,
dense: false,
}
}
}
impl ToCss for GridAutoFlow {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.autoflow.to_css(dest)?;
if self.dense { dest.write_str(" dense")?; }
Ok(())
}
}
impl Parse for GridAutoFlow {
/// [ row | column ] || dense
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>
) -> Result<GridAutoFlow, ParseError<'i>> {
let mut value = None;
let mut dense = false;
while !input.is_exhausted() {
let location = input.current_source_location();
let ident = input.expect_ident()?;
let success = match_ignore_ascii_case! { &ident,
"row" if value.is_none() => {
value = Some(AutoFlow::Row);
true
},
"column" if value.is_none() => {
value = Some(AutoFlow::Column);
true
},
"dense" if !dense => {
dense = true;
true
},
_ => false
};
if !success {
return Err(location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())));
}
}
if value.is_some() || dense {
Ok(GridAutoFlow {
autoflow: value.unwrap_or(AutoFlow::Row),
dense: dense,
})
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
}
#[cfg(feature = "gecko")]
impl From<u8> for GridAutoFlow {
fn from(bits: u8) -> GridAutoFlow {
use gecko_bindings::structs;
GridAutoFlow {
autoflow:
if bits & structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8 != 0 {
AutoFlow::Row
} else {
AutoFlow::Column
},
dense:
bits & structs::NS_STYLE_GRID_AUTO_FLOW_DENSE as u8 != 0,
}
}
}
#[cfg(feature = "gecko")]
impl From<GridAutoFlow> for u8 {
fn from(v: GridAutoFlow) -> u8 {
use gecko_bindings::structs;
let mut result: u8 = match v.autoflow {
AutoFlow::Row => structs::NS_STYLE_GRID_AUTO_FLOW_ROW as u8,
AutoFlow::Column => structs::NS_STYLE_GRID_AUTO_FLOW_COLUMN as u8,
};
if v.dense {
result |= structs::NS_STYLE_GRID_AUTO_FLOW_DENSE as u8;
}
result
}
}