No bug - sync some changes from servo. r=me
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 29 Apr 2018 01:59:00 +0200
changeset 472308 fb87372128d5fcd92e5ddc0e7d55211c0f4035d7
parent 472307 ee0ac8a8f46e105098f953bab0bf08a17fb12fa7
child 472309 b5e72af686a26cae2d311217a28083b26cfb187d
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
No bug - sync some changes from servo. r=me MozReview-Commit-ID: HyRI5CfZh5w
servo/components/style/font_face.rs
servo/components/style/properties/properties.mako.rs
servo/components/style/values/computed/font.rs
--- a/servo/components/style/font_face.rs
+++ b/servo/components/style/font_face.rs
@@ -17,23 +17,22 @@ use properties::longhands::font_language
 use selectors::parser::SelectorParseErrorKind;
 use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
 use std::fmt::{self, Write};
 use str::CssStringWriter;
 use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
 use style_traits::{StyleParseErrorKind, ToCss};
 use style_traits::values::SequenceWriter;
 use values::computed::font::FamilyName;
-#[cfg(feature = "gecko")]
+use values::generics::font::FontStyle as GenericFontStyle;
+use values::specified::Angle;
 use values::specified::font::{AbsoluteFontWeight, FontStretch as SpecifiedFontStretch};
 #[cfg(feature = "gecko")]
 use values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
 use values::specified::font::SpecifiedFontStyle;
-use values::generics::font::FontStyle as GenericFontStyle;
-use values::specified::Angle;
 use values::specified::url::SpecifiedUrl;
 
 /// A source for a font-face rule.
 #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
 #[derive(Clone, Debug, Eq, PartialEq, ToCss)]
 pub enum Source {
     /// A `url()` source.
     Url(UrlSource),
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -2306,19 +2306,23 @@ pub mod style_structs {
                     }
                 % endfor
             % elif style_struct.name == "Font":
                 /// Computes a font hash in order to be able to cache fonts
                 /// effectively in GFX and layout.
                 pub fn compute_font_hash(&mut self) {
                     // Corresponds to the fields in
                     // `gfx::font_template::FontTemplateDescriptor`.
+                    //
+                    // FIXME(emilio): Where's font-style?
                     let mut hasher: FnvHasher = Default::default();
-                    self.font_weight.hash(&mut hasher);
-                    self.font_stretch.hash(&mut hasher);
+                    // We hash the floating point number with four decimal
+                    // places.
+                    hasher.write_u64((self.font_weight.0 * 10000.).trunc() as u64);
+                    hasher.write_u64(((self.font_stretch.0).0 * 10000.).trunc() as u64);
                     self.font_family.hash(&mut hasher);
                     self.hash = hasher.finish()
                 }
 
                 /// (Servo does not handle MathML, so this just calls copy_font_size_from)
                 pub fn inherit_font_size_from(&mut self, parent: &Self,
                                               _: Option<NonNegativeLength>,
                                               _: &Device) {
--- a/servo/components/style/values/computed/font.rs
+++ b/servo/components/style/values/computed/font.rs
@@ -118,26 +118,16 @@ impl FontWeight {
         } else if self.0 < 750. {
             FontWeight(400.)
         } else {
             FontWeight(700.)
         }
     }
 }
 
-impl Hash for FontWeight {
-    fn hash<H>(&self, state: &mut H)
-    where
-        H: Hasher,
-    {
-        // We hash the floating point number with four decimal places.
-        state.write_u32((self.0 * 10000.).trunc() as u32)
-    }
-}
-
 impl FontSize {
     /// The actual computed font size.
     pub fn size(self) -> Au {
         self.size.into()
     }
 
     #[inline]
     /// Get default value of font size.
@@ -837,16 +827,17 @@ impl ToComputedValue for specified::MozS
     fn from_computed_value(other: &i8) -> Self {
         specified::MozScriptLevel::MozAbsolute(*other as i32)
     }
 }
 
 /// A wrapper over an `Angle`, that handles clamping to the appropriate range
 /// for `font-style` animation.
 #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToCss)]
+#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
 pub struct FontStyleAngle(pub Angle);
 
 impl ToAnimatedValue for FontStyleAngle {
     type AnimatedValue = Angle;
 
     #[inline]
     fn to_animated_value(self) -> Self::AnimatedValue {
         self.0
@@ -874,17 +865,17 @@ impl FontStyle {
     pub fn normal() -> Self {
         generics::FontStyle::Normal
     }
 
     /// The default angle for font-style: oblique. This is 20deg per spec:
     ///
     /// https://drafts.csswg.org/css-fonts-4/#valdef-font-style-oblique-angle
     #[inline]
-    fn default_angle() -> FontStyleAngle {
+    pub fn default_angle() -> FontStyleAngle {
         FontStyleAngle(Angle::Deg(specified::DEFAULT_FONT_STYLE_OBLIQUE_ANGLE_DEGREES))
     }
 
 
     /// Get the font style from Gecko's nsFont struct.
     #[cfg(feature = "gecko")]
     pub fn from_gecko(style: structs::FontSlantStyle) -> Self {
         let mut angle = 0.;
@@ -908,17 +899,20 @@ impl ToCss for FontStyle {
     where
         W: fmt::Write,
     {
         match *self {
             generics::FontStyle::Normal => dest.write_str("normal"),
             generics::FontStyle::Italic => dest.write_str("italic"),
             generics::FontStyle::Oblique(ref angle) => {
                 dest.write_str("oblique")?;
-                if *angle != Self::default_angle() {
+                // Use `degrees` instead of just comparing Angle because
+                // `degrees` can return slightly different values due to
+                // floating point conversions.
+                if angle.0.degrees() != Self::default_angle().0.degrees() {
                     dest.write_char(' ')?;
                     angle.to_css(dest)?;
                 }
                 Ok(())
             }
         }
     }
 }