diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index cd42bc8e9c6..afec7280ac3 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -26,19 +26,12 @@ impl<'a> ToNsCssValue for &'a FamilyName { impl<'a> ToNsCssValue for &'a SpecifiedFontStretch { fn convert(self, nscssvalue: &mut nsCSSValue) { - use values::specified::font::FontStretchKeyword; - match *self { - SpecifiedFontStretch::Stretch(ref p) => nscssvalue.set_number(p.get()), - SpecifiedFontStretch::Keyword(ref kw) => { - // TODO(emilio): Use this branch instead. - if false { - nscssvalue.set_number(kw.compute().0) - } else { - nscssvalue.set_enum(FontStretchKeyword::gecko_keyword(kw.compute().0) as i32) - } - } + let number = match *self { + SpecifiedFontStretch::Stretch(ref p) => p.get(), + SpecifiedFontStretch::Keyword(ref kw) => kw.compute().0, SpecifiedFontStretch::System(..) => unreachable!(), - } + }; + nscssvalue.set_font_stretch(number); } } @@ -123,8 +116,8 @@ impl<'a> ToNsCssValue for &'a FontStyle { let mut a = nsCSSValue::null(); let mut b = nsCSSValue::null(); - a.set_angle(SpecifiedFontStyle::compute_angle(first)); - b.set_angle(SpecifiedFontStyle::compute_angle(second)); + a.set_font_style(SpecifiedFontStyle::compute_angle(first).degrees()); + b.set_font_style(SpecifiedFontStyle::compute_angle(second).degrees()); nscssvalue.set_pair(&a, &b); } diff --git a/components/style/gecko_bindings/sugar/ns_css_value.rs b/components/style/gecko_bindings/sugar/ns_css_value.rs index ef89c723dce..644166e3797 100644 --- a/components/style/gecko_bindings/sugar/ns_css_value.rs +++ b/components/style/gecko_bindings/sugar/ns_css_value.rs @@ -167,16 +167,26 @@ impl nsCSSValue { unsafe { bindings::Gecko_CSSValue_SetAtomIdent(self, s.into_addrefed()) } } - /// Set to a font format + /// Set to a font format. pub fn set_font_format(&mut self, s: &str) { self.set_string_internal(s, nsCSSUnit::eCSSUnit_Font_Format); } - /// Set to a local font value + /// Set to a local font value. pub fn set_local_font(&mut self, s: &Atom) { self.set_string_from_atom_internal(s, nsCSSUnit::eCSSUnit_Local_Font); } + /// Set to a font stretch. + pub fn set_font_stretch(&mut self, s: f32) { + unsafe { bindings::Gecko_CSSValue_SetFontStretch(self, s) } + } + + /// Set to a font style + pub fn set_font_style(&mut self, s: f32) { + unsafe { bindings::Gecko_CSSValue_SetFontSlantStyle(self, s) } + } + /// Set to a font weight pub fn set_font_weight(&mut self, w: f32) { unsafe { bindings::Gecko_CSSValue_SetFontWeight(self, w) } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 81aa0bb0836..a3d316df321 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -25,8 +25,6 @@ use gecko_bindings::bindings::Gecko_CopyFontFamilyFrom; use gecko_bindings::bindings::Gecko_CopyImageValueFrom; use gecko_bindings::bindings::Gecko_CopyListStyleImageFrom; use gecko_bindings::bindings::Gecko_EnsureImageLayersLength; -use gecko_bindings::bindings::Gecko_FontWeight_SetFloat; -use gecko_bindings::bindings::Gecko_FontWeight_ToFloat; use gecko_bindings::bindings::Gecko_SetCursorArrayLength; use gecko_bindings::bindings::Gecko_SetCursorImageValue; use gecko_bindings::bindings::Gecko_StyleTransition_SetUnsupportedProperty; @@ -2601,12 +2599,14 @@ fn static_assert() { } pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) { - unsafe { Gecko_FontWeight_SetFloat(&mut self.gecko.mFont.weight, v.0) }; + unsafe { bindings::Gecko_FontWeight_SetFloat(&mut self.gecko.mFont.weight, v.0) }; } ${impl_simple_copy('font_weight', 'mFont.weight')} pub fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T { - let weight: f32 = unsafe { Gecko_FontWeight_ToFloat(self.gecko.mFont.weight) }; + let weight: f32 = unsafe { + bindings::Gecko_FontWeight_ToFloat(self.gecko.mFont.weight) + }; longhands::font_weight::computed_value::T(weight) } @@ -2618,7 +2618,8 @@ fn static_assert() { use values::computed::Percentage; use values::generics::NonNegative; - let stretch = self.gecko.mFont.stretch as f32 / 100.; + let stretch = + unsafe { bindings::Gecko_FontStretch_ToFloat(self.gecko.mFont.stretch) }; debug_assert!(stretch >= 0.); NonNegative(Percentage(stretch)) @@ -2626,12 +2627,16 @@ fn static_assert() { pub fn set_font_style(&mut self, v: longhands::font_style::computed_value::T) { use values::generics::font::FontStyle; - self.gecko.mFont.style = match v { - FontStyle::Normal => structs::NS_STYLE_FONT_STYLE_NORMAL, - FontStyle::Italic => structs::NS_STYLE_FONT_STYLE_ITALIC, - // FIXME(emilio): Honor the angle. - FontStyle::Oblique(ref _angle) => structs::NS_STYLE_FONT_STYLE_OBLIQUE, - } as u8; + let s = &mut self.gecko.mFont.style; + unsafe { + match v { + FontStyle::Normal => bindings::Gecko_FontSlantStyle_SetNormal(s), + FontStyle::Italic => bindings::Gecko_FontSlantStyle_SetItalic(s), + FontStyle::Oblique(ref angle) => { + bindings::Gecko_FontSlantStyle_SetOblique(s, angle.0.degrees()) + } + } + } } ${impl_simple_copy('font_style', 'mFont.style')} pub fn clone_font_style(&self) -> longhands::font_style::computed_value::T { diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index e6f6ea34a79..0477a2cd0d5 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -350,7 +350,9 @@ ${helpers.predefined_type("-x-text-zoom", ) } let font_weight = longhands::font_weight::computed_value::T::from_gecko_weight(system.weight); - let font_stretch = NonNegative(Percentage(system.stretch as f32)); + let font_stretch = NonNegative(Percentage(unsafe { + bindings::Gecko_FontStretch_ToFloat(system.stretch) + })); let font_style = FontStyle::from_gecko(system.style); let ret = ComputedSystemFont { font_family: longhands::font_family::computed_value::T( diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 3abcb2723b6..1a4a2ed4849 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -885,16 +885,20 @@ impl FontStyle { /// Get the font style from Gecko's nsFont struct. #[cfg(feature = "gecko")] - pub fn from_gecko(kw: u8) -> Self { - use gecko_bindings::structs; - - match kw as u32 { - structs::NS_STYLE_FONT_STYLE_NORMAL => generics::FontStyle::Normal, - structs::NS_STYLE_FONT_STYLE_ITALIC => generics::FontStyle::Italic, - // FIXME(emilio): Grab the angle when we honor it :) - structs::NS_STYLE_FONT_STYLE_OBLIQUE => generics::FontStyle::Oblique(Self::default_angle()), - _ => unreachable!("Unknown font style"), + pub fn from_gecko(style: structs::FontSlantStyle) -> Self { + let mut angle = 0.; + let mut italic = false; + let mut normal = false; + unsafe { + bindings::Gecko_FontSlantStyle_Get(style, &mut normal, &mut italic, &mut angle); } + if normal { + return generics::FontStyle::Normal; + } + if italic { + return generics::FontStyle::Italic; + } + generics::FontStyle::Oblique(FontStyleAngle(Angle::Deg(angle))) } } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 7c0aacb8c14..815fadc70ef 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -3801,6 +3801,7 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue( use style::properties::{PropertyDeclaration, LonghandId}; use style::properties::longhands; use style::values::specified::BorderStyle; + use style::values::generics::font::FontStyle; let long = get_longhand_from_id!(property); let value = value as u32; @@ -3820,7 +3821,14 @@ pub extern "C" fn Servo_DeclarationBlock_SetKeywordValue( longhands::font_size::SpecifiedValue::from_html_size(value as u8) }, FontStyle => { - ToComputedValue::from_computed_value(&longhands::font_style::computed_value::T::from_gecko(value as u8)) + let val = if value == structs::NS_FONT_STYLE_ITALIC { + FontStyle::Italic + } else { + debug_assert_eq!(value, structs::NS_FONT_STYLE_NORMAL); + FontStyle::Normal + }; + + ToComputedValue::from_computed_value(&val) }, FontWeight => longhands::font_weight::SpecifiedValue::from_gecko_keyword(value), ListStyleType => Box::new(longhands::list_style_type::SpecifiedValue::from_gecko_keyword(value)), @@ -5434,16 +5442,16 @@ pub extern "C" fn Servo_ParseFontShorthandForMatching( FontFamily::Values(list) => family.set_move(list.0), FontFamily::System(_) => return false, } + let specified_font_style = match font.font_style { FontStyle::Specified(ref s) => s, FontStyle::System(_) => return false, }; - match *specified_font_style { GenericFontStyle::Normal => style.set_normal(), GenericFontStyle::Italic => style.set_enum(structs::NS_FONT_STYLE_ITALIC as i32), GenericFontStyle::Oblique(ref angle) => { - style.set_angle(SpecifiedFontStyle::compute_angle(angle)) + style.set_font_style(SpecifiedFontStyle::compute_angle(angle).degrees()) } }