mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Correctly serialize CSS Custom Property names.
This commit is contained in:
parent
f284a15e4b
commit
53eb1bb5c6
2 changed files with 35 additions and 4 deletions
|
@ -18,7 +18,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
#[cfg(feature = "servo")] use cssparser::{Color as CSSParserColor, RGBA};
|
#[cfg(feature = "servo")] use cssparser::{Color as CSSParserColor, RGBA};
|
||||||
use cssparser::{Parser, TokenSerializationType};
|
use cssparser::{Parser, TokenSerializationType, serialize_identifier};
|
||||||
use error_reporting::ParseErrorReporter;
|
use error_reporting::ParseErrorReporter;
|
||||||
#[cfg(feature = "servo")] use euclid::side_offsets::SideOffsets2D;
|
#[cfg(feature = "servo")] use euclid::side_offsets::SideOffsets2D;
|
||||||
use computed_values;
|
use computed_values;
|
||||||
|
@ -775,7 +775,9 @@ impl<'a> ToCss for PropertyDeclarationId<'a> {
|
||||||
{
|
{
|
||||||
match *self {
|
match *self {
|
||||||
PropertyDeclarationId::Longhand(id) => dest.write_str(id.name()),
|
PropertyDeclarationId::Longhand(id) => dest.write_str(id.name()),
|
||||||
PropertyDeclarationId::Custom(name) => write!(dest, "--{}", name),
|
PropertyDeclarationId::Custom(_) => {
|
||||||
|
serialize_identifier(&self.name(), dest)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -806,6 +808,19 @@ impl<'a> PropertyDeclarationId<'a> {
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the name of the property without CSS escaping.
|
||||||
|
pub fn name(&self) -> Cow<'static, str> {
|
||||||
|
match *self {
|
||||||
|
PropertyDeclarationId::Longhand(id) => id.name().into(),
|
||||||
|
PropertyDeclarationId::Custom(name) => {
|
||||||
|
use std::fmt::Write;
|
||||||
|
let mut s = String::new();
|
||||||
|
write!(&mut s, "--{}", name).unwrap();
|
||||||
|
s.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Servo's representation of a CSS property, that is, either a longhand, a
|
/// Servo's representation of a CSS property, that is, either a longhand, a
|
||||||
|
@ -833,7 +848,9 @@ impl ToCss for PropertyId {
|
||||||
match *self {
|
match *self {
|
||||||
PropertyId::Longhand(id) => dest.write_str(id.name()),
|
PropertyId::Longhand(id) => dest.write_str(id.name()),
|
||||||
PropertyId::Shorthand(id) => dest.write_str(id.name()),
|
PropertyId::Shorthand(id) => dest.write_str(id.name()),
|
||||||
PropertyId::Custom(ref name) => write!(dest, "--{}", name),
|
PropertyId::Custom(_) => {
|
||||||
|
serialize_identifier(&self.name(), dest)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -935,6 +952,20 @@ impl PropertyId {
|
||||||
PropertyId::Custom(ref name) => Err(PropertyDeclarationId::Custom(name)),
|
PropertyId::Custom(ref name) => Err(PropertyDeclarationId::Custom(name)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the name of the property without CSS escaping.
|
||||||
|
pub fn name(&self) -> Cow<'static, str> {
|
||||||
|
match *self {
|
||||||
|
PropertyId::Shorthand(id) => id.name().into(),
|
||||||
|
PropertyId::Longhand(id) => id.name().into(),
|
||||||
|
PropertyId::Custom(ref name) => {
|
||||||
|
use std::fmt::Write;
|
||||||
|
let mut s = String::new();
|
||||||
|
write!(&mut s, "--{}", name).unwrap();
|
||||||
|
s.into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Includes shorthands before expansion
|
/// Includes shorthands before expansion
|
||||||
|
|
|
@ -1169,7 +1169,7 @@ pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDe
|
||||||
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
|
||||||
if let Some(&(ref decl, _)) = decls.declarations().get(index as usize) {
|
if let Some(&(ref decl, _)) = decls.declarations().get(index as usize) {
|
||||||
let result = unsafe { result.as_mut().unwrap() };
|
let result = unsafe { result.as_mut().unwrap() };
|
||||||
decl.id().to_css(result).unwrap();
|
result.assign_utf8(&decl.id().name());
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue