From 2c0347ac5b4e70b2eab5ace0e83af1b620a2dfc3 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Thu, 30 Mar 2017 11:39:58 +1100 Subject: [PATCH] Rename font_face::FontFaceRule to FontFaceData. --- components/script/dom/bindings/trace.rs | 5 ++--- components/script/dom/cssfontfacerule.rs | 2 +- components/style/font_face.rs | 18 +++++++++--------- components/style/stylesheets.rs | 7 +++++-- tests/unit/gfx/font_cache_thread.rs | 4 ++-- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 25e738a0d1c9..890074974d31 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -94,14 +94,13 @@ 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; diff --git a/components/script/dom/cssfontfacerule.rs b/components/script/dom/cssfontfacerule.rs index 184f6784afa6..1f247c25fdc9 100644 --- a/components/script/dom/cssfontfacerule.rs +++ b/components/script/dom/cssfontfacerule.rs @@ -11,8 +11,8 @@ use dom::cssstylesheet::CSSStyleSheet; use dom::window::Window; use dom_struct::dom_struct; use std::sync::Arc; -use style::font_face::FontFaceRule; use style::shared_lock::{Locked, ToCssWithGuard}; +use style::stylesheets::FontFaceRule; #[dom_struct] pub struct CSSFontFaceRule { diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 8bad3a93aee5..e585f15efaa2 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -75,8 +75,8 @@ impl ToCss for UrlSource { /// /// Note that the prelude parsing code lives in the `stylesheets` module. pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser) - -> Result { - let mut rule = FontFaceRule::initial(); + -> Result { + let mut rule = FontFaceData::initial(); { let parser = FontFaceRuleParser { context: context, @@ -104,7 +104,7 @@ pub fn parse_font_face_block(context: &ParserContext, input: &mut Parser) #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] pub struct EffectiveSources(Vec); -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". @@ -134,7 +134,7 @@ impl iter::Iterator for EffectiveSources { struct FontFaceRuleParser<'a, 'b: 'a> { context: &'a ParserContext<'b>, - rule: &'a mut FontFaceRule, + rule: &'a mut FontFaceData, missing: MissingDescriptors, } @@ -181,11 +181,11 @@ macro_rules! font_face_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, @@ -218,9 +218,9 @@ macro_rules! font_face_descriptors { } } - impl FontFaceRule { + impl FontFaceData { fn initial() -> Self { - FontFaceRule { + FontFaceData { $( $m_ident: $m_initial, )* @@ -231,7 +231,7 @@ macro_rules! font_face_descriptors { } } - impl ToCssWithGuard for FontFaceRule { + impl ToCssWithGuard for FontFaceData { // Serialization of FontFaceRule is not specced. fn to_css(&self, _guard: &SharedRwLockReadGuard, dest: &mut W) -> fmt::Result where W: fmt::Write { diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index e5b821611334..c40f81a2ef10 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -11,7 +11,7 @@ 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; @@ -551,6 +551,9 @@ impl ToCssWithGuard for StyleRule { } } +/// 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, @@ -1004,7 +1007,7 @@ impl<'a, 'b> AtRuleParser for NestedRuleParser<'a, 'b> { 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 { diff --git a/tests/unit/gfx/font_cache_thread.rs b/tests/unit/gfx/font_cache_thread.rs index dc192090ae15..4c62c15ec344 100644 --- a/tests/unit/gfx/font_cache_thread.rs +++ b/tests/unit/gfx/font_cache_thread.rs @@ -5,7 +5,7 @@ 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() { @@ -14,7 +14,7 @@ fn test_local_web_font() { 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)], };