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