diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 3ff3be2a2ec..5a2418112c8 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1433,7 +1433,7 @@ fn static_assert() { Gecko_NewGridTemplateAreasValue(v.0.areas.len() as u32, v.0.strings.len() as u32, v.0.width)) }; - for (servo, gecko) in v.0.areas.into_iter().zip(refptr.mNamedAreas.iter_mut()) { + for (servo, gecko) in v.0.areas.iter().zip(refptr.mNamedAreas.iter_mut()) { gecko.mName.assign_str(&*servo.name); gecko.mColumnStart = servo.columns.start; gecko.mColumnEnd = servo.columns.end; @@ -1441,7 +1441,7 @@ fn static_assert() { gecko.mRowEnd = servo.rows.end; } - for (servo, gecko) in v.0.strings.into_iter().zip(refptr.mTemplates.iter_mut()) { + for (servo, gecko) in v.0.strings.iter().zip(refptr.mTemplates.iter_mut()) { gecko.assign_str(&*servo); } @@ -1457,9 +1457,8 @@ fn static_assert() { } pub fn clone_grid_template_areas(&self) -> values::computed::position::GridTemplateAreas { - use std::ops::Range; use crate::values::None_; - use crate::values::specified::position::{NamedArea, TemplateAreas, TemplateAreasArc}; + use crate::values::specified::position::{NamedArea, TemplateAreas, TemplateAreasArc, UnsignedRange}; if self.gecko.mGridTemplateAreas.mRawPtr.is_null() { return Either::Second(None_); @@ -1469,33 +1468,33 @@ fn static_assert() { let areas = unsafe { let vec: Vec = (*gecko_grid_template_areas).mNamedAreas.iter().map(|gecko_name_area| { - let name = gecko_name_area.mName.to_string().into_boxed_str(); - let rows = Range { + let name = gecko_name_area.mName.to_string().into(); + let rows = UnsignedRange { start: gecko_name_area.mRowStart, end: gecko_name_area.mRowEnd }; - let columns = Range { + let columns = UnsignedRange { start: gecko_name_area.mColumnStart, end: gecko_name_area.mColumnEnd }; - NamedArea{ name, rows, columns } + NamedArea { name, rows, columns } }).collect(); - vec.into_boxed_slice() + vec.into() }; let strings = unsafe { - let vec: Vec> = + let vec: Vec = (*gecko_grid_template_areas).mTemplates.iter().map(|gecko_template| { - gecko_template.to_string().into_boxed_str() + gecko_template.to_string().into() }).collect(); - vec.into_boxed_slice() + vec.into() }; let width = unsafe { (*gecko_grid_template_areas).mNColumns }; - Either::First(TemplateAreasArc(Arc::new(TemplateAreas{ areas, strings, width }))) + Either::First(TemplateAreasArc(Arc::new(TemplateAreas { areas, strings, width }))) } diff --git a/components/style/properties/shorthands/position.mako.rs b/components/style/properties/shorthands/position.mako.rs index 63298b86ba1..73d47e1bea7 100644 --- a/components/style/properties/shorthands/position.mako.rs +++ b/components/style/properties/shorthands/position.mako.rs @@ -290,7 +290,7 @@ % endfor let first_line_names = input.try(parse_line_names).unwrap_or(vec![].into_boxed_slice()); - if let Ok(mut string) = input.try(|i| i.expect_string().map(|s| s.as_ref().into())) { + if let Ok(mut string) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { let mut strings = vec![]; let mut values = vec![]; let mut line_names = vec![]; @@ -305,7 +305,7 @@ names.extend(v.into_vec()); } - string = match input.try(|i| i.expect_string().map(|s| s.as_ref().into())) { + string = match input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { Ok(s) => s, _ => { // only the named area determines whether we should bail out line_names.push(names.into_boxed_slice()); @@ -323,7 +323,7 @@ .map_err(|()| input.new_custom_error(StyleParseErrorKind::UnspecifiedError))?; let template_rows = TrackList { list_type: TrackListType::Normal, - values: values, + values, line_names: line_names.into_boxed_slice(), auto_repeat: None, }; diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index fed0c5d3098..9f1fa7f2ee4 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -21,7 +21,6 @@ use cssparser::Parser; use selectors::parser::SelectorParseErrorKind; use servo_arc::Arc; use std::fmt::{self, Write}; -use std::ops::Range; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; /// The specified value of a CSS `` @@ -482,10 +481,10 @@ impl From for u8 { pub struct TemplateAreas { /// `named area` containing for each template area #[css(skip)] - pub areas: Box<[NamedArea]>, + pub areas: crate::OwnedSlice, /// The original CSS string value of each template area #[css(iterable)] - pub strings: Box<[Box]>, + pub strings: crate::OwnedSlice, /// The number of columns of the grid. #[css(skip)] pub width: u32, @@ -493,7 +492,7 @@ pub struct TemplateAreas { impl TemplateAreas { /// Transform `vector` of str into `template area` - pub fn from_vec(strings: Vec>) -> Result { + pub fn from_vec(strings: Vec) -> Result { if strings.is_empty() { return Err(()); } @@ -539,9 +538,15 @@ impl TemplateAreas { } let index = areas.len(); areas.push(NamedArea { - name: token.to_owned().into_boxed_str(), - columns: column..(column + 1), - rows: row..(row + 1), + name: token.to_owned().into(), + columns: UnsignedRange { + start: column, + end: column + 1, + }, + rows: UnsignedRange { + start: row, + end: row + 1, + }, }); assert!(area_indices.insert(token, index).is_none()); current_area_index = Some(index); @@ -560,8 +565,8 @@ impl TemplateAreas { } } Ok(TemplateAreas { - areas: areas.into_boxed_slice(), - strings: strings.into_boxed_slice(), + areas: areas.into(), + strings: strings.into(), width: width, }) } @@ -573,7 +578,7 @@ impl Parse for TemplateAreas { input: &mut Parser<'i, 't>, ) -> Result> { let mut strings = vec![]; - while let Ok(string) = input.try(|i| i.expect_string().map(|s| s.as_ref().into())) { + while let Ok(string) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { strings.push(string); } @@ -602,21 +607,31 @@ impl Parse for TemplateAreasArc { input: &mut Parser<'i, 't>, ) -> Result> { let parsed = TemplateAreas::parse(context, input)?; - Ok(TemplateAreasArc(Arc::new(parsed))) } } +/// A range of rows or columns. Using this instead of std::ops::Range for FFI +/// purposes. +#[repr(C)] +#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem)] +pub struct UnsignedRange { + /// The start of the range. + pub start: u32, + /// The end of the range. + pub end: u32, +} + #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem)] /// Not associated with any particular grid item, but can /// be referenced from the grid-placement properties. pub struct NamedArea { /// Name of the `named area` - pub name: Box, + pub name: crate::OwnedStr, /// Rows of the `named area` - pub rows: Range, + pub rows: UnsignedRange, /// Columns of the `named area` - pub columns: Range, + pub columns: UnsignedRange, } /// Tokenize the string into a list of the tokens,