From 670309ec1515c9a5f26761bf0d6bf141263b6b1d Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 7 Jun 2016 11:49:18 -0700 Subject: [PATCH] Support font-family in geckolib --- ports/geckolib/gecko_bindings/bindings.rs | 9 +++++ .../gecko_bindings/tools/regen_bindings.sh | 3 +- ports/geckolib/properties.mako.rs | 39 ++++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/ports/geckolib/gecko_bindings/bindings.rs b/ports/geckolib/gecko_bindings/bindings.rs index 608d22fc63df..d9ce707dc814 100644 --- a/ports/geckolib/gecko_bindings/bindings.rs +++ b/ports/geckolib/gecko_bindings/bindings.rs @@ -32,6 +32,9 @@ use structs::SheetParsingMode; use structs::nsMainThreadPtrHandle; use structs::nsMainThreadPtrHolder; use structs::nscolor; +use structs::nsFont; +use structs::FontFamilyList; +use structs::FontFamilyType; use heapsize::HeapSizeOf; unsafe impl Send for nsStyleFont {} unsafe impl Sync for nsStyleFont {} @@ -185,6 +188,12 @@ extern "C" { aString: *const ::std::os::raw::c_char, aLength: u32) -> bool; + pub fn Gecko_FontFamilyList_Clear(aList: *mut FontFamilyList); + pub fn Gecko_FontFamilyList_AppendNamed(aList: *mut FontFamilyList, + aName: *mut nsIAtom); + pub fn Gecko_FontFamilyList_AppendGeneric(list: *mut FontFamilyList, + familyType: FontFamilyType); + pub fn Gecko_CopyFontFamilyFrom(dst: *mut nsFont, src: *const nsFont); pub fn Gecko_SetListStyleType(style_struct: *mut nsStyleList, type_: u32); pub fn Gecko_CopyListStyleTypeFrom(dst: *mut nsStyleList, src: *const nsStyleList); diff --git a/ports/geckolib/gecko_bindings/tools/regen_bindings.sh b/ports/geckolib/gecko_bindings/tools/regen_bindings.sh index 6af8acb7370e..401ae785a3aa 100755 --- a/ports/geckolib/gecko_bindings/tools/regen_bindings.sh +++ b/ports/geckolib/gecko_bindings/tools/regen_bindings.sh @@ -51,7 +51,8 @@ do done # Other mapped types. -for TYPE in SheetParsingMode nsMainThreadPtrHandle nsMainThreadPtrHolder nscolor +for TYPE in SheetParsingMode nsMainThreadPtrHandle nsMainThreadPtrHolder nscolor nsFont \ + FontFamilyList FontFamilyType do MAP_GECKO_TYPES=$MAP_GECKO_TYPES"-blacklist-type $TYPE " MAP_GECKO_TYPES=$MAP_GECKO_TYPES"-raw-line 'use structs::$TYPE;' " diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 9f1fed583f0f..1b1b65545ebe 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -20,7 +20,9 @@ use gecko_bindings::bindings::{Gecko_CopyMozBindingFrom, Gecko_CopyListStyleType use gecko_bindings::bindings::{Gecko_SetMozBinding, Gecko_SetListStyleType}; use gecko_bindings::bindings::{Gecko_SetNullImageValue, Gecko_SetGradientImageValue}; use gecko_bindings::bindings::{Gecko_CreateGradient}; -use gecko_bindings::bindings::{Gecko_CopyImageValueFrom}; +use gecko_bindings::bindings::{Gecko_CopyImageValueFrom, Gecko_CopyFontFamilyFrom}; +use gecko_bindings::bindings::{Gecko_FontFamilyList_AppendGeneric, Gecko_FontFamilyList_AppendNamed}; +use gecko_bindings::bindings::{Gecko_FontFamilyList_Clear}; use gecko_bindings::structs; use glue::ArcHelpers; use std::fmt::{self, Debug}; @@ -604,7 +606,40 @@ fn static_assert() { } -<%self:impl_trait style_struct_name="Font" skip_longhands="font-style font-size font-weight" skip_additionals="*"> +<%self:impl_trait style_struct_name="Font" + skip_longhands="font-family font-style font-size font-weight" + skip_additionals="*"> + + fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) { + use style::properties::longhands::font_family::computed_value::FontFamily; + use gecko_bindings::structs::FontFamilyType; + + let list = &mut self.gecko.mFont.fontlist; + unsafe { Gecko_FontFamilyList_Clear(list); } + + for family in &v.0 { + match *family { + FontFamily::FamilyName(ref name) => { + unsafe { Gecko_FontFamilyList_AppendNamed(list, name.as_ptr()); } + } + FontFamily::Generic(ref name) => { + let family_type = + if name == &atom!("serif") { FontFamilyType::eFamily_serif } + else if name == &atom!("sans-serif") { FontFamilyType::eFamily_sans_serif } + else if name == &atom!("cursive") { FontFamilyType::eFamily_cursive } + else if name == &atom!("fantasy") { FontFamilyType::eFamily_fantasy } + else if name == &atom!("monospace") { FontFamilyType::eFamily_monospace } + else { panic!("Unknown generic font family") }; + unsafe { Gecko_FontFamilyList_AppendGeneric(list, family_type); } + } + } + } + } + + fn copy_font_family_from(&mut self, other: &Self) { + unsafe { Gecko_CopyFontFamilyFrom(&mut self.gecko.mFont, &other.gecko.mFont); } + } + <%call expr="impl_keyword('font_style', 'mFont.style', data.longhands_by_name['font-style'].keyword, need_clone=False)">