Skip to content

Commit

Permalink
Don't output duplicate properties when incompatible with targets
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Feb 13, 2024
1 parent 808ce79 commit 981175b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
8 changes: 4 additions & 4 deletions src/properties/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ impl<'i> PropertyHandler<'i> for BackgroundHandler<'i> {
context: &mut PropertyHandlerContext<'i, '_>,
) -> bool {
macro_rules! background_image {
($val: ident) => {
($val: expr) => {
flush!(images, $val);

// Store prefixed properties. Clear if we hit an unprefixed property and we have
Expand All @@ -831,7 +831,7 @@ impl<'i> PropertyHandler<'i> for BackgroundHandler<'i> {

macro_rules! flush {
($key: ident, $val: expr) => {{
if self.$key.is_some() && matches!(context.targets.browsers, Some(targets) if !$val.is_compatible(targets)) {
if self.$key.is_some() && self.$key.as_ref().unwrap() != $val && matches!(context.targets.browsers, Some(targets) if !$val.is_compatible(targets)) {
self.flush(dest, context);
}
}};
Expand Down Expand Up @@ -873,9 +873,9 @@ impl<'i> PropertyHandler<'i> for BackgroundHandler<'i> {
}
Property::Background(val) => {
let images: SmallVec<[Image; 1]> = val.iter().map(|b| b.image.clone()).collect();
background_image!(images);
background_image!(&images);
let color = val.last().unwrap().color.clone();
flush!(color, color);
flush!(color, &color);
let clips = val.iter().map(|b| b.clip.clone()).collect();
let mut clips_vp = VendorPrefix::None;
if let Some((cur_clips, cur_clips_vp)) = &mut self.clips {
Expand Down
50 changes: 25 additions & 25 deletions src/properties/border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ impl<'i> PropertyHandler<'i> for BorderHandler<'i> {
self.flush(dest, context);
}

if self.$key.$prop.is_some() && matches!(context.targets.browsers, Some(targets) if !$val.is_compatible(targets)) {
if self.$key.$prop.is_some() && self.$key.$prop.as_ref().unwrap() != $val && matches!(context.targets.browsers, Some(targets) if !$val.is_compatible(targets)) {
self.flush(dest, context);
}
}};
Expand Down Expand Up @@ -647,14 +647,14 @@ impl<'i> PropertyHandler<'i> for BorderHandler<'i> {
BorderBlockStartColor(val) => property!(border_block_start, color, val, Logical),
BorderBlockEndColor(val) => property!(border_block_end, color, val, Logical),
BorderBlockColor(val) => {
property!(border_block_start, color, val.start, Logical);
property!(border_block_end, color, val.end, Logical);
property!(border_block_start, color, &val.start, Logical);
property!(border_block_end, color, &val.end, Logical);
}
BorderInlineStartColor(val) => property!(border_inline_start, color, val, Logical),
BorderInlineEndColor(val) => property!(border_inline_end, color, val, Logical),
BorderInlineColor(val) => {
property!(border_inline_start, color, val.start, Logical);
property!(border_inline_end, color, val.end, Logical);
property!(border_inline_start, color, &val.start, Logical);
property!(border_inline_end, color, &val.end, Logical);
}
BorderTopWidth(val) => property!(border_top, width, val, Physical),
BorderBottomWidth(val) => property!(border_bottom, width, val, Physical),
Expand All @@ -663,14 +663,14 @@ impl<'i> PropertyHandler<'i> for BorderHandler<'i> {
BorderBlockStartWidth(val) => property!(border_block_start, width, val, Logical),
BorderBlockEndWidth(val) => property!(border_block_end, width, val, Logical),
BorderBlockWidth(val) => {
property!(border_block_start, width, val.start, Logical);
property!(border_block_end, width, val.end, Logical);
property!(border_block_start, width, &val.start, Logical);
property!(border_block_end, width, &val.end, Logical);
}
BorderInlineStartWidth(val) => property!(border_inline_start, width, val, Logical),
BorderInlineEndWidth(val) => property!(border_inline_end, width, val, Logical),
BorderInlineWidth(val) => {
property!(border_inline_start, width, val.start, Logical);
property!(border_inline_end, width, val.end, Logical);
property!(border_inline_start, width, &val.start, Logical);
property!(border_inline_end, width, &val.end, Logical);
}
BorderTopStyle(val) => property!(border_top, style, val, Physical),
BorderBottomStyle(val) => property!(border_bottom, style, val, Physical),
Expand All @@ -679,14 +679,14 @@ impl<'i> PropertyHandler<'i> for BorderHandler<'i> {
BorderBlockStartStyle(val) => property!(border_block_start, style, val, Logical),
BorderBlockEndStyle(val) => property!(border_block_end, style, val, Logical),
BorderBlockStyle(val) => {
property!(border_block_start, style, val.start, Logical);
property!(border_block_end, style, val.end, Logical);
property!(border_block_start, style, &val.start, Logical);
property!(border_block_end, style, &val.end, Logical);
}
BorderInlineStartStyle(val) => property!(border_inline_start, style, val, Logical),
BorderInlineEndStyle(val) => property!(border_inline_end, style, val, Logical),
BorderInlineStyle(val) => {
property!(border_inline_start, style, val.start, Logical);
property!(border_inline_end, style, val.end, Logical);
property!(border_inline_start, style, &val.start, Logical);
property!(border_inline_end, style, &val.end, Logical);
}
BorderTop(val) => set_border!(border_top, val, Physical),
BorderBottom(val) => set_border!(border_bottom, val, Physical),
Expand All @@ -705,32 +705,32 @@ impl<'i> PropertyHandler<'i> for BorderHandler<'i> {
set_border!(border_inline_end, val, Logical);
}
BorderWidth(val) => {
property!(border_top, width, val.top, Physical);
property!(border_right, width, val.right, Physical);
property!(border_bottom, width, val.bottom, Physical);
property!(border_left, width, val.left, Physical);
property!(border_top, width, &val.top, Physical);
property!(border_right, width, &val.right, Physical);
property!(border_bottom, width, &val.bottom, Physical);
property!(border_left, width, &val.left, Physical);
self.border_block_start.width = None;
self.border_block_end.width = None;
self.border_inline_start.width = None;
self.border_inline_end.width = None;
self.has_any = true;
}
BorderStyle(val) => {
property!(border_top, style, val.top, Physical);
property!(border_right, style, val.right, Physical);
property!(border_bottom, style, val.bottom, Physical);
property!(border_left, style, val.left, Physical);
property!(border_top, style, &val.top, Physical);
property!(border_right, style, &val.right, Physical);
property!(border_bottom, style, &val.bottom, Physical);
property!(border_left, style, &val.left, Physical);
self.border_block_start.style = None;
self.border_block_end.style = None;
self.border_inline_start.style = None;
self.border_inline_end.style = None;
self.has_any = true;
}
BorderColor(val) => {
property!(border_top, color, val.top, Physical);
property!(border_right, color, val.right, Physical);
property!(border_bottom, color, val.bottom, Physical);
property!(border_left, color, val.left, Physical);
property!(border_top, color, &val.top, Physical);
property!(border_right, color, &val.right, Physical);
property!(border_bottom, color, &val.bottom, Physical);
property!(border_left, color, &val.left, Physical);
self.border_block_start.color = None;
self.border_block_end.color = None;
self.border_inline_start.color = None;
Expand Down
12 changes: 6 additions & 6 deletions src/properties/border_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl<'i> PropertyHandler<'i> for BorderImageHandler<'i> {

macro_rules! flush {
($name: ident, $val: expr) => {{
if self.$name.is_some() && matches!(context.targets.browsers, Some(targets) if !$val.is_compatible(targets)) {
if self.$name.is_some() && self.$name.as_ref().unwrap() != $val && matches!(context.targets.browsers, Some(targets) if !$val.is_compatible(targets)) {
self.flush(dest, context);
}
}};
Expand All @@ -459,11 +459,11 @@ impl<'i> PropertyHandler<'i> for BorderImageHandler<'i> {
BorderImageOutset(val) => property!(outset, val),
BorderImageRepeat(val) => property!(repeat, val),
BorderImage(val, vp) => {
flush!(source, val.source);
flush!(slice, val.slice);
flush!(width, val.width);
flush!(outset, val.outset);
flush!(repeat, val.repeat);
flush!(source, &val.source);
flush!(slice, &val.slice);
flush!(width, &val.width);
flush!(outset, &val.outset);
flush!(repeat, &val.repeat);
self.source = Some(val.source.clone());
self.slice = Some(val.slice.clone());
self.width = Some(val.width.clone());
Expand Down
16 changes: 8 additions & 8 deletions src/properties/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ impl<'i> PropertyHandler<'i> for FontHandler<'i> {

macro_rules! flush {
($prop: ident, $val: expr) => {{
if self.$prop.is_some() && matches!(context.targets.browsers, Some(targets) if !$val.is_compatible(targets)) {
if self.$prop.is_some() && self.$prop.as_ref().unwrap() != $val && matches!(context.targets.browsers, Some(targets) if !$val.is_compatible(targets)) {
self.flush(dest, context);
}
}};
Expand All @@ -971,13 +971,13 @@ impl<'i> PropertyHandler<'i> for FontHandler<'i> {
FontVariantCaps(val) => property!(variant_caps, val),
LineHeight(val) => property!(line_height, val),
Font(val) => {
flush!(family, val.family);
flush!(size, val.size);
flush!(style, val.style);
flush!(weight, val.weight);
flush!(stretch, val.stretch);
flush!(line_height, val.line_height);
flush!(variant_caps, val.variant_caps);
flush!(family, &val.family);
flush!(size, &val.size);
flush!(style, &val.style);
flush!(weight, &val.weight);
flush!(stretch, &val.stretch);
flush!(line_height, &val.line_height);
flush!(variant_caps, &val.variant_caps);
self.family = Some(val.family.clone());
self.size = Some(val.size.clone());
self.style = Some(val.style.clone());
Expand Down

0 comments on commit 981175b

Please sign in to comment.