aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/style/properties/longhand/position.mako.rs129
-rw-r--r--components/style/properties/shorthand/position.mako.rs6
-rw-r--r--components/style/values/computed/mod.rs2
-rw-r--r--components/style/values/computed/position.rs1
-rw-r--r--components/style/values/specified/mod.rs2
-rw-r--r--components/style/values/specified/position.rs122
6 files changed, 134 insertions, 128 deletions
diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs
index 179ef350c1a..00a8fd56ce3 100644
--- a/components/style/properties/longhand/position.mako.rs
+++ b/components/style/properties/longhand/position.mako.rs
@@ -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"
diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs
index a04283c0321..bb0900f27f8 100644
--- a/components/style/properties/shorthand/position.mako.rs
+++ b/components/style/properties/shorthand/position.mako.rs
@@ -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,
}
diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs
index 9c8b1f18bc0..d792007bf7c 100644
--- a/components/style/values/computed/mod.rs
+++ b/components/style/values/computed/mod.rs
@@ -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};
diff --git a/components/style/values/computed/position.rs b/components/style/values/computed/position.rs
index d17f6172310..6416104e8e7 100644
--- a/components/style/values/computed/position.rs
+++ b/components/style/values/computed/position.rs
@@ -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>;
diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs
index da4ae4be7b4..b43e6926a6e 100644
--- a/components/style/values/specified/mod.rs
+++ b/components/style/values/specified/mod.rs
@@ -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};
diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs
index 7d2cef458c3..f48923f4f37 100644
--- a/components/style/values/specified/position.rs
+++ b/components/style/values/specified/position.rs
@@ -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
+ }
+}