mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Correctly handle unserializable shorthand
get_shorthand_appendable_value doesn't always return a serializable value. This change makes it handle that case correctly.
This commit is contained in:
parent
183c4772e7
commit
c183899c06
2 changed files with 23 additions and 12 deletions
|
@ -86,21 +86,21 @@ impl PropertyDeclarationBlock {
|
||||||
pub fn property_value_to_css<W>(&self, property: &PropertyId, dest: &mut W) -> fmt::Result
|
pub fn property_value_to_css<W>(&self, property: &PropertyId, dest: &mut W) -> fmt::Result
|
||||||
where W: fmt::Write,
|
where W: fmt::Write,
|
||||||
{
|
{
|
||||||
// Step 1: done when parsing a string to PropertyId
|
// Step 1.1: done when parsing a string to PropertyId
|
||||||
|
|
||||||
// Step 2
|
// Step 1.2
|
||||||
match property.as_shorthand() {
|
match property.as_shorthand() {
|
||||||
Ok(shorthand) => {
|
Ok(shorthand) => {
|
||||||
// Step 2.1
|
// Step 1.2.1
|
||||||
let mut list = Vec::new();
|
let mut list = Vec::new();
|
||||||
let mut important_count = 0;
|
let mut important_count = 0;
|
||||||
|
|
||||||
// Step 2.2
|
// Step 1.2.2
|
||||||
for &longhand in shorthand.longhands() {
|
for &longhand in shorthand.longhands() {
|
||||||
// Step 2.2.1
|
// Step 1.2.2.1
|
||||||
let declaration = self.get(PropertyDeclarationId::Longhand(longhand));
|
let declaration = self.get(PropertyDeclarationId::Longhand(longhand));
|
||||||
|
|
||||||
// Step 2.2.2 & 2.2.3
|
// Step 1.2.2.2 & 1.2.2.3
|
||||||
match declaration {
|
match declaration {
|
||||||
Some(&(ref declaration, importance)) => {
|
Some(&(ref declaration, importance)) => {
|
||||||
list.push(declaration);
|
list.push(declaration);
|
||||||
|
@ -112,26 +112,28 @@ impl PropertyDeclarationBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3.3.2.4
|
|
||||||
// If there is one or more longhand with important, and one or more
|
// If there is one or more longhand with important, and one or more
|
||||||
// without important, we don't serialize it as a shorthand.
|
// without important, we don't serialize it as a shorthand.
|
||||||
if important_count > 0 && important_count != list.len() {
|
if important_count > 0 && important_count != list.len() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2.3
|
// Step 1.2.3
|
||||||
// We don't print !important when serializing individual properties,
|
// We don't print !important when serializing individual properties,
|
||||||
// so we treat this as a normal-importance property
|
// so we treat this as a normal-importance property
|
||||||
let importance = Importance::Normal;
|
let importance = Importance::Normal;
|
||||||
let appendable_value = shorthand.get_shorthand_appendable_value(list).unwrap();
|
match shorthand.get_shorthand_appendable_value(list) {
|
||||||
append_declaration_value(dest, appendable_value, importance, false)
|
Some(appendable_value) =>
|
||||||
|
append_declaration_value(dest, appendable_value, importance, false),
|
||||||
|
None => return Ok(()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(longhand_or_custom) => {
|
Err(longhand_or_custom) => {
|
||||||
if let Some(&(ref value, _importance)) = self.get(longhand_or_custom) {
|
if let Some(&(ref value, _importance)) = self.get(longhand_or_custom) {
|
||||||
// Step 3
|
// Step 2
|
||||||
value.to_css(dest)
|
value.to_css(dest)
|
||||||
} else {
|
} else {
|
||||||
// Step 4
|
// Step 3
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
<div id="foo5" style="margin-right: 10px; margin-left: 10px; margin-top: 10px; margin-bottom: 10px!important;">foo</div>
|
<div id="foo5" style="margin-right: 10px; margin-left: 10px; margin-top: 10px; margin-bottom: 10px!important;">foo</div>
|
||||||
<div id="foo6" style="margin-right: 10px !important; margin-left: 10px !important; margin-top: 10px !important; margin-bottom: 10px!important;">foo</div>
|
<div id="foo6" style="margin-right: 10px !important; margin-left: 10px !important; margin-top: 10px !important; margin-bottom: 10px!important;">foo</div>
|
||||||
|
|
||||||
|
<div id="foo7" style="background:var(--a);">foo</a>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
test(function() {
|
test(function() {
|
||||||
var elem1 = document.getElementById('foo1');
|
var elem1 = document.getElementById('foo1');
|
||||||
|
@ -39,6 +41,13 @@
|
||||||
assert_equals(elem6.style.cssText, 'margin: 10px !important;');
|
assert_equals(elem6.style.cssText, 'margin: 10px !important;');
|
||||||
assert_equals(elem6.style.margin, '10px');
|
assert_equals(elem6.style.margin, '10px');
|
||||||
}, "Shorthand serialization with just longhands.");
|
}, "Shorthand serialization with just longhands.");
|
||||||
|
|
||||||
|
test(function() {
|
||||||
|
var elem7 = document.getElementById('foo7');
|
||||||
|
|
||||||
|
assert_equals(elem7.style.background, 'var(--a)');
|
||||||
|
assert_equals(elem7.style.backgroundPosition, '');
|
||||||
|
}, "Shorthand serialization with variable and variable from other shorthand.");
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue