Skip to content

Commit 663de51

Browse files
committed
Only use two value overflow shorthand when supported
1 parent ce348df commit 663de51

File tree

5 files changed

+102
-9
lines changed

5 files changed

+102
-9
lines changed

build-prefixes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ let mdnFeatures = {
183183
clamp: mdn.css.types.clamp.__compat.support,
184184
placeSelf: mdn.css.properties['place-self'].__compat.support,
185185
placeContent: mdn.css.properties['place-content'].__compat.support,
186-
placeItems: mdn.css.properties['place-items'].__compat.support
186+
placeItems: mdn.css.properties['place-items'].__compat.support,
187+
overflowShorthand: mdn.css.properties['overflow'].multiple_keywords.__compat.support
187188
};
188189

189190
for (let feature in mdnFeatures) {

src/compat.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub enum Feature {
3131
DoublePositionGradients,
3232
FormValidation,
3333
Fullscreen,
34+
OverflowShorthand,
3435
PlaceContent,
3536
PlaceItems,
3637
PlaceSelf,
@@ -1242,6 +1243,38 @@ impl Feature {
12421243
}
12431244
}
12441245
}
1246+
Feature::OverflowShorthand => {
1247+
if let Some(version) = browsers.chrome {
1248+
if version >= 4456448 {
1249+
return true
1250+
}
1251+
}
1252+
if let Some(version) = browsers.edge {
1253+
if version >= 5177344 {
1254+
return true
1255+
}
1256+
}
1257+
if let Some(version) = browsers.firefox {
1258+
if version >= 3997696 {
1259+
return true
1260+
}
1261+
}
1262+
if let Some(version) = browsers.opera {
1263+
if version >= 3145728 {
1264+
return true
1265+
}
1266+
}
1267+
if let Some(version) = browsers.samsung {
1268+
if version >= 655360 {
1269+
return true
1270+
}
1271+
}
1272+
if let Some(version) = browsers.android {
1273+
if version >= 4456448 {
1274+
return true
1275+
}
1276+
}
1277+
}
12451278
}
12461279
false
12471280
}

src/declaration.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ impl DeclarationHandler {
148148
animation: AnimationHandler::new(targets),
149149
display: DisplayHandler::new(targets),
150150
position: PositionHandler::new(targets),
151+
overflow: OverflowHandler::new(targets),
151152
transform: TransformHandler::new(targets),
152153
text: TextDecorationHandler::new(targets),
153154
prefix: PrefixHandler::new(targets),

src/lib.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5231,6 +5231,46 @@ mod tests {
52315231
overflow: hidden auto;
52325232
}
52335233
"#});
5234+
prefix_test(r#"
5235+
.foo {
5236+
overflow: hidden auto;
5237+
}
5238+
"#, indoc! {r#"
5239+
.foo {
5240+
overflow-x: hidden;
5241+
overflow-y: auto;
5242+
}
5243+
"#},
5244+
Browsers {
5245+
chrome: Some(67 << 16),
5246+
..Browsers::default()
5247+
});
5248+
prefix_test(r#"
5249+
.foo {
5250+
overflow: hidden hidden;
5251+
}
5252+
"#, indoc! {r#"
5253+
.foo {
5254+
overflow: hidden;
5255+
}
5256+
"#},
5257+
Browsers {
5258+
chrome: Some(67 << 16),
5259+
..Browsers::default()
5260+
});
5261+
prefix_test(r#"
5262+
.foo {
5263+
overflow: hidden auto;
5264+
}
5265+
"#, indoc! {r#"
5266+
.foo {
5267+
overflow: hidden auto;
5268+
}
5269+
"#},
5270+
Browsers {
5271+
chrome: Some(68 << 16),
5272+
..Browsers::default()
5273+
});
52345274

52355275
minify_test(".foo { text-overflow: ellipsis }", ".foo{text-overflow:ellipsis}");
52365276
prefix_test(r#"

src/properties/overflow.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use super::Property;
44
use crate::declaration::DeclarationList;
55
use crate::macros::enum_property;
66
use crate::printer::Printer;
7+
use crate::properties::prefixes::Browsers;
8+
use crate::compat::Feature;
79

810
enum_property!(OverflowKeyword,
911
Visible,
@@ -47,10 +49,21 @@ enum_property!(TextOverflow,
4749

4850
#[derive(Default)]
4951
pub struct OverflowHandler {
52+
targets: Option<Browsers>,
5053
x: Option<OverflowKeyword>,
5154
y: Option<OverflowKeyword>
5255
}
5356

57+
impl OverflowHandler {
58+
pub fn new(targets: Option<Browsers>) -> OverflowHandler {
59+
OverflowHandler {
60+
targets,
61+
..OverflowHandler::default()
62+
}
63+
}
64+
}
65+
66+
5467
impl PropertyHandler for OverflowHandler {
5568
fn handle_property(&mut self, property: &Property, _: &mut DeclarationList) -> bool {
5669
use Property::*;
@@ -72,15 +85,20 @@ impl PropertyHandler for OverflowHandler {
7285
let x = std::mem::take(&mut self.x);
7386
let y = std::mem::take(&mut self.y);
7487

75-
if let (Some(x), Some(y)) = (x, y) {
76-
dest.push(Property::Overflow(Overflow { x, y }))
77-
} else {
78-
if let Some(x) = x {
79-
dest.push(Property::OverflowX(x))
88+
match (x, y) {
89+
// Only use shorthand syntax if the x and y values are the
90+
// same or the two-value syntax is supported by all targets.
91+
(Some(x), Some(y)) if x == y || self.targets.is_none() || Feature::OverflowShorthand.is_compatible(self.targets.unwrap()) => {
92+
dest.push(Property::Overflow(Overflow { x, y }))
8093
}
81-
82-
if let Some(y) = y {
83-
dest.push(Property::OverflowY(y))
94+
_ => {
95+
if let Some(x) = x {
96+
dest.push(Property::OverflowX(x))
97+
}
98+
99+
if let Some(y) = y {
100+
dest.push(Property::OverflowY(y))
101+
}
84102
}
85103
}
86104
}

0 commit comments

Comments
 (0)