mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Fix CalcLengthOrPercentage serialization
This commit is contained in:
parent
2a32cf1352
commit
29ac1714c4
2 changed files with 17 additions and 39 deletions
|
@ -761,20 +761,6 @@ impl HasViewportPercentage for CalcLengthOrPercentage {
|
||||||
impl ToCss for CalcLengthOrPercentage {
|
impl ToCss for CalcLengthOrPercentage {
|
||||||
#[allow(unused_assignments)]
|
#[allow(unused_assignments)]
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
macro_rules! count {
|
|
||||||
( $( $val:ident ),* ) => {
|
|
||||||
{
|
|
||||||
let mut count = 0;
|
|
||||||
$(
|
|
||||||
if let Some(_) = self.$val {
|
|
||||||
count += 1;
|
|
||||||
}
|
|
||||||
)*
|
|
||||||
count
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut first_value = true;
|
let mut first_value = true;
|
||||||
macro_rules! first_value_check {
|
macro_rules! first_value_check {
|
||||||
() => {
|
() => {
|
||||||
|
@ -798,12 +784,7 @@ impl ToCss for CalcLengthOrPercentage {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let count = count!(ch, em, ex, absolute, rem, vh, vmax, vmin, vw, percentage);
|
try!(write!(dest, "calc("));
|
||||||
assert!(count > 0);
|
|
||||||
|
|
||||||
if count > 1 {
|
|
||||||
try!(write!(dest, "calc("));
|
|
||||||
}
|
|
||||||
|
|
||||||
serialize!(ch, em, ex, rem, vh, vmax, vmin, vw);
|
serialize!(ch, em, ex, rem, vh, vmax, vmin, vw);
|
||||||
if let Some(val) = self.absolute {
|
if let Some(val) = self.absolute {
|
||||||
|
@ -816,11 +797,7 @@ impl ToCss for CalcLengthOrPercentage {
|
||||||
try!(write!(dest, "{}%", val * 100.));
|
try!(write!(dest, "{}%", val * 100.));
|
||||||
}
|
}
|
||||||
|
|
||||||
if count > 1 {
|
write!(dest, ")")
|
||||||
try!(write!(dest, ")"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,28 +15,29 @@
|
||||||
var div = document.getElementById('inner');
|
var div = document.getElementById('inner');
|
||||||
|
|
||||||
var widthTests = [
|
var widthTests = [
|
||||||
['calc(10px)', '10px', '10px'],
|
['calc(10px)', 'calc(10px)', '10px'],
|
||||||
|
|
||||||
// Basic Arithmetic
|
// Basic Arithmetic
|
||||||
['calc(10px + 10px)', '20px', '20px'],
|
['calc(10px + 10px)', 'calc(20px)', '20px'],
|
||||||
['calc(10px - 5px)', '5px', '5px'],
|
['calc(10px - 5px)', 'calc(5px)', '5px'],
|
||||||
['calc(2 * 10px)', '20px', '20px'],
|
['calc(2 * 10px)', 'calc(20px)', '20px'],
|
||||||
['calc(10px / 2)', '5px', '5px'],
|
['calc(10px / 2)', 'calc(5px)', '5px'],
|
||||||
|
|
||||||
// Parse ok
|
// Parse ok
|
||||||
['calc(20px/2)', '10px', '10px'],
|
['calc(20px/2)', 'calc(10px)', '10px'],
|
||||||
['calc(10px*2)', '20px', '20px'],
|
['calc(10px*2)', 'calc(20px)', '20px'],
|
||||||
|
|
||||||
// Parse errors - value left over from previous test
|
// Parse errors - value left over from previous test
|
||||||
['calc(10px-10px)', '20px', '20px'],
|
['calc(10px-10px)', 'calc(20px)', '20px'],
|
||||||
['calc(5px+5px)', '20px', '20px'],
|
['calc(5px+5px)', 'calc(20px)', '20px'],
|
||||||
|
['calc()', 'calc(20px)', '20px'],
|
||||||
|
|
||||||
// Combining units
|
// Combining units
|
||||||
['calc(10px + 10em)', 'calc(10em + 10px)', '170px'],
|
['calc(10px + 10em)', 'calc(10em + 10px)', '170px'],
|
||||||
['calc(10px + 10em - 10px)', 'calc(10em + 0px)', '160px'],
|
['calc(10px + 10em - 10px)', 'calc(10em + 0px)', '160px'],
|
||||||
|
|
||||||
// Fold absolute units
|
// Fold absolute units
|
||||||
['calc(1px + 1pt + 1pc + 1in + 1cm + 1mm)', '155.88333333333333px', '155.88333333333333px'],
|
['calc(1px + 1pt + 1pc + 1in + 1cm + 1mm)', 'calc(155.88333333333333px)', '155.88333333333333px'],
|
||||||
|
|
||||||
// Alphabetical order
|
// Alphabetical order
|
||||||
['calc(0ch + 0px + 0pt + 0pc + 0in + 0cm + 0mm + 0rem + 0em + 0ex + 0% + 0vw + 0vh + 0vmin + 0vmax)',
|
['calc(0ch + 0px + 0pt + 0pc + 0in + 0cm + 0mm + 0rem + 0em + 0ex + 0% + 0vw + 0vh + 0vmin + 0vmax)',
|
||||||
|
@ -44,8 +45,8 @@ var widthTests = [
|
||||||
'0px'],
|
'0px'],
|
||||||
|
|
||||||
// Simplification
|
// Simplification
|
||||||
['calc((2 - 1) * 10px)', '10px', '10px'],
|
['calc((2 - 1) * 10px)', 'calc(10px)', '10px'],
|
||||||
['calc(((3 - 1) * (8 + 4)) * 10px)', '240px', '240px'],
|
['calc(((3 - 1) * (8 + 4)) * 10px)', 'calc(240px)', '240px'],
|
||||||
['calc(5 * (20px / 2 + 7 * (3em + 12px/4 + (8 - 2) * 2rem)))', 'calc(105em + 420rem + 155px)', '8555px'],
|
['calc(5 * (20px / 2 + 7 * (3em + 12px/4 + (8 - 2) * 2rem)))', 'calc(105em + 420rem + 155px)', '8555px'],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
@ -75,7 +76,7 @@ var lengthProperties = [
|
||||||
lengthProperties.forEach(function(prop) {
|
lengthProperties.forEach(function(prop) {
|
||||||
test(function() {
|
test(function() {
|
||||||
div.style.setProperty(prop, 'calc(1px)');
|
div.style.setProperty(prop, 'calc(1px)');
|
||||||
assert_equals(div.style.getPropertyValue(prop), '1px');
|
assert_equals(div.style.getPropertyValue(prop), 'calc(1px)');
|
||||||
}, 'calc for ' + prop);
|
}, 'calc for ' + prop);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -130,7 +131,7 @@ numberProperties.forEach(function(prop) {
|
||||||
|
|
||||||
var otherProperties = [
|
var otherProperties = [
|
||||||
['border-width', 'calc(1px)', '1px 1px 1px 1px'],
|
['border-width', 'calc(1px)', '1px 1px 1px 1px'],
|
||||||
['border-spacing', 'calc(1px)', '1px 1px'],
|
['border-spacing', 'calc(1px)', 'calc(1px) calc(1px)'],
|
||||||
['transform-origin', 'calc(1px + 0%)', 'calc(1px + 0%) 50% 0px'],
|
['transform-origin', 'calc(1px + 0%)', 'calc(1px + 0%) 50% 0px'],
|
||||||
['perspective-origin', 'calc(1px + 0%)', 'calc(1px + 0%) 50%'],
|
['perspective-origin', 'calc(1px + 0%)', 'calc(1px + 0%) 50%'],
|
||||||
['background-size', 'calc(1px + 0%)', 'calc(1px + 0%) auto'],
|
['background-size', 'calc(1px + 0%)', 'calc(1px + 0%) auto'],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue