servo: Merge #16194 - stylo: Serialize unquoted font-family without quote (from canaltinova:font-family); r=Manishearth

<!-- Please describe your changes on the following line: -->
Reviewed by Manishearth

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix [Bug 1351262](https://bugzilla.mozilla.org/show_bug.cgi?id=1351262)

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: ecf42ca6e94bc50b835defc084a357152c24cdaf

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 8a76af0acde6144d12013df5a12babbd6e82a744
This commit is contained in:
Nazım Can Altınova 2017-03-30 15:45:39 -05:00
parent e31083ac08
commit bf065fb0d0
7 changed files with 53 additions and 21 deletions

View File

@ -269,7 +269,7 @@ impl FontCache {
});
}
Source::Local(ref font) => {
let font_face_name = LowercaseString::new(&font.0);
let font_face_name = LowercaseString::new(&font.name);
let templates = &mut self.web_families.get_mut(&family_name).unwrap();
let mut found = false;
for_each_variation(&font_face_name, |path| {
@ -464,7 +464,7 @@ impl FontCacheThread {
}
pub fn add_web_font(&self, family: FamilyName, sources: EffectiveSources, sender: IpcSender<()>) {
self.chan.send(Command::AddWebFont(LowercaseString::new(&family.0), sources, sender)).unwrap();
self.chan.send(Command::AddWebFont(LowercaseString::new(&family.name), sources, sender)).unwrap();
}
pub fn exit(&self) {

View File

@ -282,7 +282,10 @@ macro_rules! font_face_descriptors {
font_face_descriptors! {
mandatory descriptors = [
/// The name of this font face
"font-family" family: FamilyName = FamilyName(atom!("")),
"font-family" family: FamilyName = FamilyName {
name: atom!(""),
quoted: true,
},
/// The alternative sources for this font face.
"src" sources: Vec<Source> = Vec::new(),
@ -308,7 +311,10 @@ font_face_descriptors! {
font_face_descriptors! {
mandatory descriptors = [
/// The name of this font face
"font-family" family: FamilyName = FamilyName(atom!("")),
"font-family" family: FamilyName = FamilyName {
name: atom!(""),
quoted: true,
},
/// The alternative sources for this font face.
"src" sources: Vec<Source> = Vec::new(),

View File

@ -17,7 +17,7 @@ pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
fn set_font_face_descriptors(descriptors: &mut CSSFontFaceDescriptors,
data: FontFaceData) {
// font-family
descriptors.mFamily.set_string_from_atom(&data.family.0);
descriptors.mFamily.set_string_from_atom(&data.family.name);
macro_rules! map_enum {
($target:ident = ($data:ident: $prop:ident) {
@ -74,8 +74,8 @@ fn set_font_face_descriptors(descriptors: &mut CSSFontFaceDescriptors,
next!().set_font_format(&hint);
}
}
Source::Local(ref name) => {
next!().set_local_font(&name.0);
Source::Local(ref family) => {
next!().set_local_font(&family.name);
}
}
}

View File

@ -660,7 +660,8 @@ extern "C" {
}
extern "C" {
pub fn Gecko_FontFamilyList_AppendNamed(aList: *mut FontFamilyList,
aName: *mut nsIAtom);
aName: *mut nsIAtom,
aQuoted: bool);
}
extern "C" {
pub fn Gecko_FontFamilyList_AppendGeneric(list: *mut FontFamilyList,

View File

@ -1257,8 +1257,8 @@ fn static_assert() {
for family in &v.0 {
match *family {
FontFamily::FamilyName(ref name) => {
unsafe { Gecko_FontFamilyList_AppendNamed(list, name.0.as_ptr()); }
FontFamily::FamilyName(ref f) => {
unsafe { Gecko_FontFamilyList_AppendNamed(list, f.name.as_ptr(), f.quoted); }
}
FontFamily::Generic(ref name) => {
let (family_type, generic) =

View File

@ -18,7 +18,7 @@
no_viewport_percentage!(SpecifiedValue);
pub mod computed_value {
use cssparser::{CssStringWriter, Parser};
use cssparser::{CssStringWriter, Parser, serialize_identifier};
use std::fmt::{self, Write};
use Atom;
use style_traits::ToCss;
@ -33,13 +33,16 @@
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub struct FamilyName(pub Atom);
pub struct FamilyName {
pub name: Atom,
pub quoted: bool,
}
impl FontFamily {
#[inline]
pub fn atom(&self) -> &Atom {
match *self {
FontFamily::FamilyName(ref name) => &name.0,
FontFamily::FamilyName(ref family_name) => &family_name.name,
FontFamily::Generic(ref name) => name,
}
}
@ -70,13 +73,22 @@
"monospace" => return FontFamily::Generic(atom!("monospace")),
_ => {}
}
FontFamily::FamilyName(FamilyName(input))
// We don't know if it's quoted or not. So we set it to
// quoted by default.
FontFamily::FamilyName(FamilyName {
name: input,
quoted: true,
})
}
/// Parse a font-family value
pub fn parse(input: &mut Parser) -> Result<Self, ()> {
if let Ok(value) = input.try(|input| input.expect_string()) {
return Ok(FontFamily::FamilyName(FamilyName(Atom::from(&*value))))
return Ok(FontFamily::FamilyName(FamilyName {
name: Atom::from(&*value),
quoted: true,
}))
}
let first_ident = try!(input.expect_ident());
@ -120,15 +132,22 @@
value.push_str(" ");
value.push_str(&ident);
}
Ok(FontFamily::FamilyName(FamilyName(Atom::from(value))))
Ok(FontFamily::FamilyName(FamilyName {
name: Atom::from(value),
quoted: false,
}))
}
}
impl ToCss for FamilyName {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_char('"')?;
write!(CssStringWriter::new(dest), "{}", self.0)?;
dest.write_char('"')
if self.quoted {
dest.write_char('"')?;
write!(CssStringWriter::new(dest), "{}", self.name)?;
dest.write_char('"')
} else {
serialize_identifier(&*self.name.to_string(), dest)
}
}
}

View File

@ -12,8 +12,14 @@ fn test_local_web_font() {
let (inp_chan, _) = ipc::channel().unwrap();
let (out_chan, out_receiver) = ipc::channel().unwrap();
let font_cache_thread = FontCacheThread::new(inp_chan, None);
let family_name = FamilyName(From::from("test family"));
let variant_name = FamilyName(From::from("test font face"));
let family_name = FamilyName {
name: From::from("test family"),
quoted: true,
};
let variant_name = FamilyName {
name: From::from("test font face"),
quoted: true,
};
let font_face_rule = FontFaceData {
family: family_name.clone(),
sources: vec![Source::Local(variant_name)],