mirror of
https://github.com/servo/servo.git
synced 2025-07-04 22:13:40 +01:00
style: Add a declaration iterator to AllShorthand for simplify code.
Bug: 1461285 Reviewed-by: emilio MozReview-Commit-ID: 9w2B3SpdkQo
This commit is contained in:
parent
36038869aa
commit
2be1375745
2 changed files with 47 additions and 28 deletions
|
@ -455,34 +455,9 @@ impl PropertyDeclarationBlock {
|
||||||
mode,
|
mode,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
match drain.all_shorthand {
|
drain.all_shorthand.declarations().fold(changed, |changed, decl| {
|
||||||
AllShorthand::NotSet => {}
|
changed | self.push(decl, importance, mode)
|
||||||
AllShorthand::CSSWideKeyword(keyword) => {
|
})
|
||||||
for id in ShorthandId::All.longhands() {
|
|
||||||
let decl = PropertyDeclaration::CSSWideKeyword(
|
|
||||||
WideKeywordDeclaration { id, keyword },
|
|
||||||
);
|
|
||||||
changed |= self.push(
|
|
||||||
decl,
|
|
||||||
importance,
|
|
||||||
mode,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AllShorthand::WithVariables(unparsed) => {
|
|
||||||
for id in ShorthandId::All.longhands() {
|
|
||||||
let decl = PropertyDeclaration::WithVariables(
|
|
||||||
VariableDeclaration { id, value: unparsed.clone() },
|
|
||||||
);
|
|
||||||
changed |= self.push(
|
|
||||||
decl,
|
|
||||||
importance,
|
|
||||||
mode,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
changed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds or overrides the declaration for a given property in this block.
|
/// Adds or overrides the declaration for a given property in this block.
|
||||||
|
|
|
@ -2222,6 +2222,50 @@ enum AllShorthand {
|
||||||
WithVariables(Arc<UnparsedValue>)
|
WithVariables(Arc<UnparsedValue>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AllShorthand {
|
||||||
|
/// Iterates property declarations from the given all shorthand value.
|
||||||
|
#[inline]
|
||||||
|
fn declarations(&self) -> AllShorthandDeclarationIterator {
|
||||||
|
AllShorthandDeclarationIterator {
|
||||||
|
all_shorthand: self,
|
||||||
|
longhands: ShorthandId::All.longhands(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AllShorthandDeclarationIterator<'a> {
|
||||||
|
all_shorthand: &'a AllShorthand,
|
||||||
|
longhands: NonCustomPropertyIterator<LonghandId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Iterator for AllShorthandDeclarationIterator<'a> {
|
||||||
|
type Item = PropertyDeclaration;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
match *self.all_shorthand {
|
||||||
|
AllShorthand::NotSet => None,
|
||||||
|
AllShorthand::CSSWideKeyword(ref keyword) => {
|
||||||
|
Some(PropertyDeclaration::CSSWideKeyword(
|
||||||
|
WideKeywordDeclaration {
|
||||||
|
id: self.longhands.next()?,
|
||||||
|
keyword: *keyword
|
||||||
|
}
|
||||||
|
))
|
||||||
|
}
|
||||||
|
AllShorthand::WithVariables(ref unparsed) => {
|
||||||
|
let id = self.longhands.next()?;
|
||||||
|
Some(PropertyDeclaration::WithVariables(
|
||||||
|
VariableDeclaration {
|
||||||
|
id: self.longhands.next()?,
|
||||||
|
value: unparsed.clone()
|
||||||
|
}
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use gecko_properties::style_structs;
|
pub use gecko_properties::style_structs;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue