mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Use more ffi-friendly types in grid template areas.
Differential Revision: https://phabricator.services.mozilla.com/D35116
This commit is contained in:
parent
e1e82dbe5f
commit
e8271ee926
3 changed files with 44 additions and 30 deletions
|
@ -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<NamedArea> =
|
||||
(*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<Box<str>> =
|
||||
let vec: Vec<crate::OwnedStr> =
|
||||
(*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 })))
|
||||
}
|
||||
|
||||
</%self:impl_trait>
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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 `<position>`
|
||||
|
@ -482,10 +481,10 @@ impl From<GridAutoFlow> for u8 {
|
|||
pub struct TemplateAreas {
|
||||
/// `named area` containing for each template area
|
||||
#[css(skip)]
|
||||
pub areas: Box<[NamedArea]>,
|
||||
pub areas: crate::OwnedSlice<NamedArea>,
|
||||
/// The original CSS string value of each template area
|
||||
#[css(iterable)]
|
||||
pub strings: Box<[Box<str>]>,
|
||||
pub strings: crate::OwnedSlice<crate::OwnedStr>,
|
||||
/// 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<Box<str>>) -> Result<TemplateAreas, ()> {
|
||||
pub fn from_vec(strings: Vec<crate::OwnedStr>) -> Result<Self, ()> {
|
||||
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<Self, ParseError<'i>> {
|
||||
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<Self, ParseError<'i>> {
|
||||
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<str>,
|
||||
pub name: crate::OwnedStr,
|
||||
/// Rows of the `named area`
|
||||
pub rows: Range<u32>,
|
||||
pub rows: UnsignedRange,
|
||||
/// Columns of the `named area`
|
||||
pub columns: Range<u32>,
|
||||
pub columns: UnsignedRange,
|
||||
}
|
||||
|
||||
/// Tokenize the string into a list of the tokens,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue