mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Implement GridTemplateAreas with reference counting
This commit is contained in:
parent
469dc84b6e
commit
9004ffff46
4 changed files with 38 additions and 15 deletions
|
@ -2188,10 +2188,10 @@ fn static_assert() {
|
||||||
|
|
||||||
let mut refptr = unsafe {
|
let mut refptr = unsafe {
|
||||||
UniqueRefPtr::from_addrefed(
|
UniqueRefPtr::from_addrefed(
|
||||||
Gecko_NewGridTemplateAreasValue(v.areas.len() as u32, v.strings.len() as u32, v.width))
|
Gecko_NewGridTemplateAreasValue(v.0.areas.len() as u32, v.0.strings.len() as u32, v.0.width))
|
||||||
};
|
};
|
||||||
|
|
||||||
for (servo, gecko) in v.areas.into_iter().zip(refptr.mNamedAreas.iter_mut()) {
|
for (servo, gecko) in v.0.areas.into_iter().zip(refptr.mNamedAreas.iter_mut()) {
|
||||||
gecko.mName.assign_utf8(&*servo.name);
|
gecko.mName.assign_utf8(&*servo.name);
|
||||||
gecko.mColumnStart = servo.columns.start;
|
gecko.mColumnStart = servo.columns.start;
|
||||||
gecko.mColumnEnd = servo.columns.end;
|
gecko.mColumnEnd = servo.columns.end;
|
||||||
|
@ -2199,7 +2199,7 @@ fn static_assert() {
|
||||||
gecko.mRowEnd = servo.rows.end;
|
gecko.mRowEnd = servo.rows.end;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (servo, gecko) in v.strings.into_iter().zip(refptr.mTemplates.iter_mut()) {
|
for (servo, gecko) in v.0.strings.into_iter().zip(refptr.mTemplates.iter_mut()) {
|
||||||
gecko.assign_utf8(&*servo);
|
gecko.assign_utf8(&*servo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2217,7 +2217,7 @@ 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 std::ops::Range;
|
||||||
use values::None_;
|
use values::None_;
|
||||||
use values::specified::position::{NamedArea, TemplateAreas};
|
use values::specified::position::{NamedArea, TemplateAreas, TemplateAreasArc};
|
||||||
|
|
||||||
if self.gecko.mGridTemplateAreas.mRawPtr.is_null() {
|
if self.gecko.mGridTemplateAreas.mRawPtr.is_null() {
|
||||||
return Either::Second(None_);
|
return Either::Second(None_);
|
||||||
|
@ -2253,7 +2253,7 @@ fn static_assert() {
|
||||||
(*gecko_grid_template_areas).mNColumns
|
(*gecko_grid_template_areas).mNColumns
|
||||||
};
|
};
|
||||||
|
|
||||||
Either::First(TemplateAreas{ areas, strings, width })
|
Either::First(TemplateAreasArc(Arc::new(TemplateAreas{ areas, strings, width })))
|
||||||
}
|
}
|
||||||
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
|
@ -301,5 +301,5 @@ ${helpers.predefined_type("grid-template-areas",
|
||||||
initial_value="computed::GridTemplateAreas::none()",
|
initial_value="computed::GridTemplateAreas::none()",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
animation_value_type="discrete",
|
animation_value_type="discrete",
|
||||||
boxed=True,
|
gecko_pref="layout.css.grid.enabled",
|
||||||
spec="https://drafts.csswg.org/css-grid/#propdef-grid-template-areas")}
|
spec="https://drafts.csswg.org/css-grid/#propdef-grid-template-areas")}
|
||||||
|
|
|
@ -242,18 +242,19 @@
|
||||||
spec="https://drafts.csswg.org/css-grid/#propdef-grid-template"
|
spec="https://drafts.csswg.org/css-grid/#propdef-grid-template"
|
||||||
products="gecko">
|
products="gecko">
|
||||||
use parser::Parse;
|
use parser::Parse;
|
||||||
|
use servo_arc::Arc;
|
||||||
use values::{Either, None_};
|
use values::{Either, None_};
|
||||||
use values::generics::grid::{LineNameList, TrackSize, TrackList, TrackListType};
|
use values::generics::grid::{LineNameList, TrackSize, TrackList, TrackListType};
|
||||||
use values::generics::grid::{TrackListValue, concat_serialize_idents};
|
use values::generics::grid::{TrackListValue, concat_serialize_idents};
|
||||||
use values::specified::{GridTemplateComponent, GenericGridTemplateComponent};
|
use values::specified::{GridTemplateComponent, GenericGridTemplateComponent};
|
||||||
use values::specified::grid::parse_line_names;
|
use values::specified::grid::parse_line_names;
|
||||||
use values::specified::position::TemplateAreas;
|
use values::specified::position::{TemplateAreas, TemplateAreasArc};
|
||||||
|
|
||||||
/// Parsing for `<grid-template>` shorthand (also used by `grid` shorthand).
|
/// Parsing for `<grid-template>` shorthand (also used by `grid` shorthand).
|
||||||
pub fn parse_grid_template<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse_grid_template<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<(GridTemplateComponent,
|
-> Result<(GridTemplateComponent,
|
||||||
GridTemplateComponent,
|
GridTemplateComponent,
|
||||||
Either<TemplateAreas, None_>), ParseError<'i>> {
|
Either<TemplateAreasArc, None_>), ParseError<'i>> {
|
||||||
// Other shorthand sub properties also parse `none` and `subgrid` keywords and this
|
// Other shorthand sub properties also parse `none` and `subgrid` keywords and this
|
||||||
// shorthand should know after these keywords there is nothing to parse. Otherwise it
|
// shorthand should know after these keywords there is nothing to parse. Otherwise it
|
||||||
// gets confused and rejects the sub properties that contains `none` or `subgrid`.
|
// gets confused and rejects the sub properties that contains `none` or `subgrid`.
|
||||||
|
@ -332,7 +333,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((GenericGridTemplateComponent::TrackList(template_rows),
|
Ok((GenericGridTemplateComponent::TrackList(template_rows),
|
||||||
template_cols, Either::First(template_areas)))
|
template_cols, Either::First(TemplateAreasArc(Arc::new(template_areas)))))
|
||||||
} else {
|
} else {
|
||||||
let mut template_rows = GridTemplateComponent::parse(context, input)?;
|
let mut template_rows = GridTemplateComponent::parse(context, input)?;
|
||||||
if let GenericGridTemplateComponent::TrackList(ref mut list) = template_rows {
|
if let GenericGridTemplateComponent::TrackList(ref mut list) = template_rows {
|
||||||
|
@ -365,7 +366,7 @@
|
||||||
pub fn serialize_grid_template<W>(
|
pub fn serialize_grid_template<W>(
|
||||||
template_rows: &GridTemplateComponent,
|
template_rows: &GridTemplateComponent,
|
||||||
template_columns: &GridTemplateComponent,
|
template_columns: &GridTemplateComponent,
|
||||||
template_areas: &Either<TemplateAreas, None_>,
|
template_areas: &Either<TemplateAreasArc, None_>,
|
||||||
dest: &mut CssWriter<W>,
|
dest: &mut CssWriter<W>,
|
||||||
) -> fmt::Result
|
) -> fmt::Result
|
||||||
where
|
where
|
||||||
|
@ -378,7 +379,7 @@
|
||||||
},
|
},
|
||||||
Either::First(ref areas) => {
|
Either::First(ref areas) => {
|
||||||
// The length of template-area and template-rows values should be equal.
|
// The length of template-area and template-rows values should be equal.
|
||||||
if areas.strings.len() != template_rows.track_list_len() {
|
if areas.0.strings.len() != template_rows.track_list_len() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,7 +424,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut names_iter = track_list.line_names.iter();
|
let mut names_iter = track_list.line_names.iter();
|
||||||
for (((i, string), names), value) in areas.strings.iter().enumerate()
|
for (((i, string), names), value) in areas.0.strings.iter().enumerate()
|
||||||
.zip(&mut names_iter)
|
.zip(&mut names_iter)
|
||||||
.zip(track_list.values.iter()) {
|
.zip(track_list.values.iter()) {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
|
@ -456,8 +457,12 @@
|
||||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
|
||||||
serialize_grid_template(self.grid_template_rows, self.grid_template_columns,
|
serialize_grid_template(
|
||||||
self.grid_template_areas, dest)
|
self.grid_template_rows,
|
||||||
|
self.grid_template_columns,
|
||||||
|
self.grid_template_areas,
|
||||||
|
dest
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</%helpers:shorthand>
|
</%helpers:shorthand>
|
||||||
|
|
|
@ -11,6 +11,7 @@ use cssparser::Parser;
|
||||||
use hash::FnvHashMap;
|
use hash::FnvHashMap;
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
|
use servo_arc::Arc;
|
||||||
use std::fmt::{self, Write};
|
use std::fmt::{self, Write};
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use str::HTML_SPACE_CHARACTERS;
|
use str::HTML_SPACE_CHARACTERS;
|
||||||
|
@ -624,6 +625,23 @@ impl Parse for TemplateAreas {
|
||||||
|
|
||||||
trivial_to_computed_value!(TemplateAreas);
|
trivial_to_computed_value!(TemplateAreas);
|
||||||
|
|
||||||
|
/// Arc type for `Arc<TemplateAreas>`
|
||||||
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
|
pub struct TemplateAreasArc(#[ignore_malloc_size_of = "Arc"] pub Arc<TemplateAreas>);
|
||||||
|
|
||||||
|
impl Parse for TemplateAreasArc {
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
let parsed = TemplateAreas::parse(context, input)?;
|
||||||
|
|
||||||
|
Ok(TemplateAreasArc(Arc::new(parsed)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trivial_to_computed_value!(TemplateAreasArc);
|
||||||
|
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
/// Not associated with any particular grid item, but can
|
/// Not associated with any particular grid item, but can
|
||||||
|
@ -673,7 +691,7 @@ fn is_name_code_point(c: char) -> bool {
|
||||||
/// The syntax of this property also provides a visualization of
|
/// The syntax of this property also provides a visualization of
|
||||||
/// the structure of the grid, making the overall layout of
|
/// the structure of the grid, making the overall layout of
|
||||||
/// the grid container easier to understand.
|
/// the grid container easier to understand.
|
||||||
pub type GridTemplateAreas = Either<TemplateAreas, None_>;
|
pub type GridTemplateAreas = Either<TemplateAreasArc, None_>;
|
||||||
|
|
||||||
impl GridTemplateAreas {
|
impl GridTemplateAreas {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue