Rename font_face::FontFaceRule to FontFaceData. r=Manishearth draft
authorXidorn Quan <me@upsuper.org>
Mon, 27 Mar 2017 20:54:33 +1100
changeset 552760 e67f8aedca12e9241169e0654faa571fe47d5797
parent 552759 a0caac7341bc70b730c75e98d27e1cfdd4785eea
child 552761 036a91e26a4a065e1b8dc5c0769b86b9511c8c19
push id51449
push userxquan@mozilla.com
push dateTue, 28 Mar 2017 23:45:05 +0000
reviewersManishearth
milestone55.0a1
Rename font_face::FontFaceRule to FontFaceData. r=Manishearth MozReview-Commit-ID: 2kP8eTxshhz
servo/components/script/dom/bindings/trace.rs
servo/components/script/dom/cssfontfacerule.rs
servo/components/style/font_face.rs
servo/components/style/stylesheets.rs
servo/tests/unit/gfx/font_cache_thread.rs
--- a/servo/components/script/dom/bindings/trace.rs
+++ b/servo/components/script/dom/bindings/trace.rs
@@ -89,24 +89,23 @@ use std::path::PathBuf;
 use std::rc::Rc;
 use std::sync::{Arc, Mutex};
 use std::sync::atomic::{AtomicBool, AtomicUsize};
 use std::sync::mpsc::{Receiver, Sender};
 use std::time::{SystemTime, Instant};
 use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
 use style::context::QuirksMode;
 use style::element_state::*;
-use style::font_face::FontFaceRule;
 use style::keyframes::Keyframe;
 use style::media_queries::MediaList;
 use style::properties::PropertyDeclarationBlock;
 use style::selector_parser::{PseudoElement, Snapshot};
 use style::shared_lock::{SharedRwLock as StyleSharedRwLock, Locked as StyleLocked};
-use style::stylesheets::{CssRules, KeyframesRule, MediaRule, NamespaceRule, StyleRule, ImportRule};
-use style::stylesheets::SupportsRule;
+use style::stylesheets::{CssRules, FontFaceRule, KeyframesRule, MediaRule};
+use style::stylesheets::{NamespaceRule, StyleRule, ImportRule, SupportsRule};
 use style::values::specified::Length;
 use style::viewport::ViewportRule;
 use time::Duration;
 use uuid::Uuid;
 use webrender_traits::{WebGLBufferId, WebGLError, WebGLFramebufferId, WebGLProgramId};
 use webrender_traits::{WebGLRenderbufferId, WebGLShaderId, WebGLTextureId};
 
 /// A trait to allow tracing (only) DOM objects.
--- a/servo/components/script/dom/cssfontfacerule.rs
+++ b/servo/components/script/dom/cssfontfacerule.rs
@@ -6,17 +6,17 @@ use dom::bindings::codegen::Bindings::CS
 use dom::bindings::js::Root;
 use dom::bindings::reflector::reflect_dom_object;
 use dom::bindings::str::DOMString;
 use dom::cssrule::{CSSRule, SpecificCSSRule};
 use dom::cssstylesheet::CSSStyleSheet;
 use dom::window::Window;
 use dom_struct::dom_struct;
 use std::sync::Arc;
-use style::font_face::FontFaceRule;
+use style::stylesheets::FontFaceRule;
 use style::shared_lock::{Locked, ToCssWithGuard};
 
 #[dom_struct]
 pub struct CSSFontFaceRule {
     cssrule: CSSRule,
     #[ignore_heap_size_of = "Arc"]
     fontfacerule: Arc<Locked<FontFaceRule>>,
 }
--- a/servo/components/style/font_face.rs
+++ b/servo/components/style/font_face.rs
@@ -70,18 +70,18 @@ impl ToCss for UrlSource {
         dest.write_str(self.url.as_str())
     }
 }
 
 /// Parse the block inside a `@font-face` rule.
 ///
 /// Note that the prelude parsing code lives in the `stylesheets` module.
 pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser)
-                             -> Result<FontFaceRule, ()> {
-    let mut rule = FontFaceRule::initial();
+                             -> Result<FontFaceData, ()> {
+    let mut rule = FontFaceData::initial();
     {
         let parser = FontFaceRuleParser {
             context: context,
             rule: &mut rule,
             missing: MissingDescriptors::new(),
         };
         let mut iter = DeclarationListParser::new(input, parser);
         while let Some(declaration) = iter.next() {
@@ -99,17 +99,17 @@ pub fn parse_font_face_block(context: &P
     Ok(rule)
 }
 
 /// A list of effective sources that we send over through IPC to the font cache.
 #[derive(Clone, Debug)]
 #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
 pub struct EffectiveSources(Vec<Source>);
 
-impl FontFaceRule {
+impl FontFaceData {
     /// Returns the list of effective sources for that font-face, that is the
     /// sources which don't list any format hint, or the ones which list at
     /// least "truetype" or "opentype".
     pub fn effective_sources(&self) -> EffectiveSources {
         EffectiveSources(self.sources.iter().rev().filter(|source| {
             if let Source::Url(ref url_source) = **source {
                 let hints = &url_source.format_hints;
                 // We support only opentype fonts and truetype is an alias for
@@ -129,17 +129,17 @@ impl iter::Iterator for EffectiveSources
     type Item = Source;
     fn next(&mut self) -> Option<Source> {
         self.0.pop()
     }
 }
 
 struct FontFaceRuleParser<'a, 'b: 'a> {
     context: &'a ParserContext<'b>,
-    rule: &'a mut FontFaceRule,
+    rule: &'a mut FontFaceData,
     missing: MissingDescriptors,
 }
 
 /// Default methods reject all at rules.
 impl<'a, 'b> AtRuleParser for FontFaceRuleParser<'a, 'b> {
     type Prelude = ();
     type AtRule = ();
 }
@@ -176,21 +176,21 @@ macro_rules! font_face_descriptors {
     (
         mandatory descriptors = [
             $( #[$m_doc: meta] $m_name: tt $m_ident: ident: $m_ty: ty = $m_initial: expr, )*
         ]
         optional descriptors = [
             $( #[$o_doc: meta] $o_name: tt $o_ident: ident: $o_ty: ty = $o_initial: expr, )*
         ]
     ) => {
-        /// A `@font-face` rule.
+        /// Data inside a `@font-face` rule.
         ///
         /// https://drafts.csswg.org/css-fonts/#font-face-rule
         #[derive(Debug, PartialEq, Eq)]
-        pub struct FontFaceRule {
+        pub struct FontFaceData {
             $(
                 #[$m_doc]
                 pub $m_ident: $m_ty,
             )*
             $(
                 #[$o_doc]
                 pub $o_ident: $o_ty,
             )*
@@ -213,30 +213,30 @@ macro_rules! font_face_descriptors {
 
             fn any(&self) -> bool {
                 $(
                     self.$m_ident
                 )||*
             }
         }
 
-        impl FontFaceRule {
+        impl FontFaceData {
             fn initial() -> Self {
-                FontFaceRule {
+                FontFaceData {
                     $(
                         $m_ident: $m_initial,
                     )*
                     $(
                         $o_ident: $o_initial,
                     )*
                 }
             }
         }
 
-        impl ToCssWithGuard for FontFaceRule {
+        impl ToCssWithGuard for FontFaceData {
             // Serialization of FontFaceRule is not specced.
             fn to_css<W>(&self, _guard: &SharedRwLockReadGuard, dest: &mut W) -> fmt::Result
             where W: fmt::Write {
                 dest.write_str("@font-face {\n")?;
                 $(
                     dest.write_str(concat!("  ", $m_name, ": "))?;
                     ToCss::to_css(&self.$m_ident, dest)?;
                     dest.write_str(";\n")?;
--- a/servo/components/style/stylesheets.rs
+++ b/servo/components/style/stylesheets.rs
@@ -6,17 +6,17 @@
 
 #![deny(missing_docs)]
 
 use {Atom, Prefix, Namespace};
 use cssparser::{AtRuleParser, Parser, QualifiedRuleParser};
 use cssparser::{AtRuleType, RuleListParser, SourcePosition, Token, parse_one_rule};
 use cssparser::ToCss as ParserToCss;
 use error_reporting::ParseErrorReporter;
-use font_face::{FontFaceRule, parse_font_face_block};
+use font_face::{FontFaceData, parse_font_face_block};
 use keyframes::{Keyframe, parse_keyframe_list};
 use media_queries::{Device, MediaList, parse_media_query_list};
 use parking_lot::RwLock;
 use parser::{ParserContext, ParserContextExtraData, log_css_error};
 use properties::{PropertyDeclarationBlock, parse_property_declaration_list};
 use selector_parser::{SelectorImpl, SelectorParser};
 use selectors::parser::SelectorList;
 use servo_config::prefs::PREFS;
@@ -546,16 +546,19 @@ impl ToCssWithGuard for StyleRule {
             try!(write!(dest, " "));
         }
         // Step 5
         try!(dest.write_str("}"));
         Ok(())
     }
 }
 
+/// A @font-face rule
+pub type FontFaceRule = FontFaceData;
+
 impl Stylesheet {
     /// Updates an empty stylesheet from a given string of text.
     pub fn update_from_str(existing: &Stylesheet,
                            css: &str,
                            stylesheet_loader: Option<&StylesheetLoader>,
                            error_reporter: &ParseErrorReporter,
                            extra_data: ParserContextExtraData) {
         let mut namespaces = Namespaces::default();
@@ -999,17 +1002,17 @@ impl<'a, 'b> AtRuleParser for NestedRule
             _ => Err(())
         }
     }
 
     fn parse_block(&mut self, prelude: AtRulePrelude, input: &mut Parser) -> Result<CssRule, ()> {
         match prelude {
             AtRulePrelude::FontFace => {
                 Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap(
-                    try!(parse_font_face_block(self.context, input))))))
+                    parse_font_face_block(self.context, input)?.into()))))
             }
             AtRulePrelude::Media(media_queries) => {
                 Ok(CssRule::Media(Arc::new(self.shared_lock.wrap(MediaRule {
                     media_queries: media_queries,
                     rules: self.parse_nested_rules(input),
                 }))))
             }
             AtRulePrelude::Supports(cond) => {
--- a/servo/tests/unit/gfx/font_cache_thread.rs
+++ b/servo/tests/unit/gfx/font_cache_thread.rs
@@ -1,25 +1,25 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use gfx::font_cache_thread::FontCacheThread;
 use ipc_channel::ipc;
 use style::computed_values::font_family::FamilyName;
-use style::font_face::{FontFaceRule, Source};
+use style::font_face::{FontFaceData, Source};
 
 #[test]
 fn test_local_web_font() {
     let (inp_chan, _) = ipc::channel().unwrap();
     let (out_chan, out_receiver) = ipc::channel().unwrap();
     let font_cache_thread = FontCacheThread::new(inp_chan, None);
     let family_name = FamilyName(From::from("test family"));
     let variant_name = FamilyName(From::from("test font face"));
-    let font_face_rule = FontFaceRule {
+    let font_face_rule = FontFaceData {
         family: family_name.clone(),
         sources: vec![Source::Local(variant_name)],
     };
 
     font_cache_thread.add_web_font(family_name, font_face_rule.effective_sources(), out_chan);
 
     assert_eq!(out_receiver.recv().unwrap(), ());
 }