mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Further changes required by Servo
This commit is contained in:
parent
67f9b97735
commit
4f0e0c888c
4 changed files with 47 additions and 5 deletions
|
@ -120,7 +120,9 @@ fn font_family(names: Vec<&str>) -> FontFamily {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
FontFamily {
|
FontFamily {
|
||||||
families: FontFamilyList::new(names.into_boxed_slice()),
|
families: FontFamilyList {
|
||||||
|
list: names.into_boxed_slice(),
|
||||||
|
},
|
||||||
is_system_font: false,
|
is_system_font: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -733,9 +733,9 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
hints.push(from_declaration(
|
hints.push(from_declaration(
|
||||||
shared_lock,
|
shared_lock,
|
||||||
PropertyDeclaration::FontFamily(font_family::SpecifiedValue::Values(
|
PropertyDeclaration::FontFamily(font_family::SpecifiedValue::Values(
|
||||||
computed::font::FontFamilyList::new(Box::new([
|
computed::font::FontFamilyList {
|
||||||
computed::font::SingleFontFamily::from_atom(font_family),
|
list: Box::new([computed::font::SingleFontFamily::from_atom(font_family)]),
|
||||||
])),
|
},
|
||||||
)),
|
)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,11 @@ macro_rules! static_font_family {
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref $ident: FontFamily = FontFamily {
|
static ref $ident: FontFamily = FontFamily {
|
||||||
families: FontFamilyList {
|
families: FontFamilyList {
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
list: crate::ArcSlice::from_iter_leaked(std::iter::once($family)),
|
list: crate::ArcSlice::from_iter_leaked(std::iter::once($family)),
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
|
list: Box::new([$family]),
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
fallback: GenericFontFamily::None,
|
fallback: GenericFontFamily::None,
|
||||||
},
|
},
|
||||||
is_system_font: false,
|
is_system_font: false,
|
||||||
|
@ -206,6 +210,7 @@ impl FontFamily {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the font family for `-moz-bullet-font`.
|
/// Returns the font family for `-moz-bullet-font`.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
pub(crate) fn moz_bullet() -> &'static Self {
|
pub(crate) fn moz_bullet() -> &'static Self {
|
||||||
static_font_family!(MOZ_BULLET, SingleFontFamily::FamilyName(FamilyName {
|
static_font_family!(MOZ_BULLET, SingleFontFamily::FamilyName(FamilyName {
|
||||||
name: atom!("-moz-bullet-font"),
|
name: atom!("-moz-bullet-font"),
|
||||||
|
@ -216,6 +221,7 @@ impl FontFamily {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a font family for a single system font.
|
/// Returns a font family for a single system font.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
pub fn for_system_font(name: &str) -> Self {
|
pub fn for_system_font(name: &str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
families: FontFamilyList {
|
families: FontFamilyList {
|
||||||
|
@ -242,6 +248,7 @@ impl FontFamily {
|
||||||
generic_font_family!(MONOSPACE, Monospace);
|
generic_font_family!(MONOSPACE, Monospace);
|
||||||
generic_font_family!(CURSIVE, Cursive);
|
generic_font_family!(CURSIVE, Cursive);
|
||||||
generic_font_family!(FANTASY, Fantasy);
|
generic_font_family!(FANTASY, Fantasy);
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
generic_font_family!(MOZ_EMOJI, MozEmoji);
|
generic_font_family!(MOZ_EMOJI, MozEmoji);
|
||||||
|
|
||||||
match generic {
|
match generic {
|
||||||
|
@ -254,6 +261,7 @@ impl FontFamily {
|
||||||
GenericFontFamily::Monospace => &*MONOSPACE,
|
GenericFontFamily::Monospace => &*MONOSPACE,
|
||||||
GenericFontFamily::Cursive => &*CURSIVE,
|
GenericFontFamily::Cursive => &*CURSIVE,
|
||||||
GenericFontFamily::Fantasy => &*FANTASY,
|
GenericFontFamily::Fantasy => &*FANTASY,
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
GenericFontFamily::MozEmoji => &*MOZ_EMOJI,
|
GenericFontFamily::MozEmoji => &*MOZ_EMOJI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +291,12 @@ impl ToCss for FontFamily {
|
||||||
let mut iter = self.families.iter();
|
let mut iter = self.families.iter();
|
||||||
match iter.next() {
|
match iter.next() {
|
||||||
Some(f) => f.to_css(dest)?,
|
Some(f) => f.to_css(dest)?,
|
||||||
None => return self.families.fallback.to_css(dest),
|
None => {
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
return self.families.fallback.to_css(dest);
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
|
unreachable!();
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for family in iter {
|
for family in iter {
|
||||||
dest.write_str(", ")?;
|
dest.write_str(", ")?;
|
||||||
|
@ -499,6 +512,7 @@ impl SingleFontFamily {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A list of font families.
|
/// A list of font families.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
#[derive(Clone, Debug, ToComputedValue, ToResolvedValue, ToShmem, PartialEq, Eq)]
|
#[derive(Clone, Debug, ToComputedValue, ToResolvedValue, ToShmem, PartialEq, Eq)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct FontFamilyList {
|
pub struct FontFamilyList {
|
||||||
|
@ -508,6 +522,26 @@ pub struct FontFamilyList {
|
||||||
pub fallback: GenericFontFamily,
|
pub fallback: GenericFontFamily,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A list of font families.
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
|
#[derive(
|
||||||
|
Clone,
|
||||||
|
Debug,
|
||||||
|
Deserialize,
|
||||||
|
Eq,
|
||||||
|
Hash,
|
||||||
|
MallocSizeOf,
|
||||||
|
PartialEq,
|
||||||
|
Serialize,
|
||||||
|
ToComputedValue,
|
||||||
|
ToResolvedValue,
|
||||||
|
ToShmem,
|
||||||
|
)]
|
||||||
|
pub struct FontFamilyList {
|
||||||
|
/// The actual list of font families specified.
|
||||||
|
pub list: Box<[SingleFontFamily]>,
|
||||||
|
}
|
||||||
|
|
||||||
impl FontFamilyList {
|
impl FontFamilyList {
|
||||||
/// Return iterator of SingleFontFamily
|
/// Return iterator of SingleFontFamily
|
||||||
pub fn iter(&self) -> impl Iterator<Item = &SingleFontFamily> {
|
pub fn iter(&self) -> impl Iterator<Item = &SingleFontFamily> {
|
||||||
|
@ -515,6 +549,7 @@ impl FontFamilyList {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Puts the fallback in the list if needed.
|
/// Puts the fallback in the list if needed.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
pub fn normalize(&mut self) {
|
pub fn normalize(&mut self) {
|
||||||
if self.fallback == GenericFontFamily::None {
|
if self.fallback == GenericFontFamily::None {
|
||||||
return;
|
return;
|
||||||
|
@ -527,6 +562,7 @@ impl FontFamilyList {
|
||||||
/// If there's a generic font family on the list (which isn't cursive or
|
/// If there's a generic font family on the list (which isn't cursive or
|
||||||
/// fantasy), then move it to the front of the list. Otherwise, prepend the
|
/// fantasy), then move it to the front of the list. Otherwise, prepend the
|
||||||
/// default generic.
|
/// default generic.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
pub (crate) fn prioritize_first_generic_or_prepend(&mut self, generic: GenericFontFamily) {
|
pub (crate) fn prioritize_first_generic_or_prepend(&mut self, generic: GenericFontFamily) {
|
||||||
let index_of_first_generic = self.iter().position(|f| {
|
let index_of_first_generic = self.iter().position(|f| {
|
||||||
match *f {
|
match *f {
|
||||||
|
|
|
@ -686,7 +686,11 @@ impl FontFamily {
|
||||||
pub fn parse_specified<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
pub fn parse_specified<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
let values = input.parse_comma_separated(SingleFontFamily::parse)?;
|
let values = input.parse_comma_separated(SingleFontFamily::parse)?;
|
||||||
Ok(FontFamily::Values(FontFamilyList {
|
Ok(FontFamily::Values(FontFamilyList {
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
list: crate::ArcSlice::from_iter(values.into_iter()),
|
list: crate::ArcSlice::from_iter(values.into_iter()),
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
|
list: values.into_boxed_slice(),
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
fallback: computed::GenericFontFamily::None,
|
fallback: computed::GenericFontFamily::None,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue