Skip to content

Commit

Permalink
style: Use a user defined type for font weight everywhere.
Browse files Browse the repository at this point in the history
Bug: 1436048
Reviewed-by: emilio
  • Loading branch information
jwatt authored and emilio committed Apr 14, 2018
1 parent 156ef81 commit 245d848
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions components/style/gecko/rules.rs
Expand Up @@ -25,7 +25,7 @@ impl<'a> ToNsCssValue for &'a FamilyName {

impl ToNsCssValue for font_weight::T {
fn convert(self, nscssvalue: &mut nsCSSValue) {
nscssvalue.set_integer(self.0 as i32)
nscssvalue.set_font_weight(self.0)
}
}

Expand All @@ -34,7 +34,7 @@ impl<'a> ToNsCssValue for &'a FontWeight {
match *self {
FontWeight::Normal => nscssvalue.set_enum(structs::NS_FONT_WEIGHT_NORMAL as i32),
FontWeight::Bold => nscssvalue.set_enum(structs::NS_FONT_WEIGHT_BOLD as i32),
FontWeight::Weight(weight) => nscssvalue.set_integer(weight.0 as i32),
FontWeight::Weight(weight) => nscssvalue.set_font_weight(weight.0),
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions components/style/gecko_bindings/sugar/ns_css_value.rs
Expand Up @@ -177,6 +177,11 @@ impl nsCSSValue {
self.set_string_from_atom_internal(s, nsCSSUnit::eCSSUnit_Local_Font);
}

/// Set to a font weight
pub fn set_font_weight(&mut self, w: u16) {
unsafe { bindings::Gecko_CSSValue_SetFontWeight(self, w as f32) }
}

fn set_int_internal(&mut self, value: i32, unit: nsCSSUnit) {
unsafe { bindings::Gecko_CSSValue_SetInt(self, value, unit) }
}
Expand Down
10 changes: 7 additions & 3 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -25,6 +25,8 @@ 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;
Expand Down Expand Up @@ -2599,13 +2601,15 @@ fn static_assert() {
}

pub fn set_font_weight(&mut self, v: longhands::font_weight::computed_value::T) {
self.gecko.mFont.weight = v.0;
unsafe { Gecko_FontWeight_SetFloat(&mut self.gecko.mFont.weight, v.0 as f32) };
}
${impl_simple_copy('font_weight', 'mFont.weight')}

pub fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T {
debug_assert!(self.gecko.mFont.weight <= ::std::u16::MAX);
longhands::font_weight::computed_value::T(self.gecko.mFont.weight)
let weight: f32 = unsafe { Gecko_FontWeight_ToFloat(self.gecko.mFont.weight) };
debug_assert!(weight >= 0.0 &&
weight <= ::std::u16::MAX as f32);
longhands::font_weight::computed_value::T(weight as u16)
}

${impl_simple_type_with_conversion("font_synthesis", "mFont.synthesis")}
Expand Down
6 changes: 4 additions & 2 deletions components/style/values/computed/font.rs
Expand Up @@ -75,10 +75,12 @@ impl FontWeight {
}

/// Convert from an Gecko weight
pub fn from_gecko_weight(weight: u16) -> Self {
#[cfg(feature = "gecko")]
pub fn from_gecko_weight(weight: structs::FontWeight) -> Self {
// we allow a wider range of weights than is parseable
// because system fonts may provide custom values
FontWeight(weight)
let weight = unsafe { bindings::Gecko_FontWeight_ToFloat(weight) };
FontWeight(weight as u16)
}

/// Weither this weight is bold
Expand Down

0 comments on commit 245d848

Please sign in to comment.