From 48332046538eae79613824efa73821af22f94773 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 5 Aug 2015 19:33:40 +0200 Subject: [PATCH] Support @font-face in user and user agent stylesheets. --- components/layout/layout_task.rs | 21 +++++++++++++++------ components/style/selector_matching.rs | 5 +++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index 575aee4a71a..a2278179885 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -297,6 +297,14 @@ impl<'a> DerefMut for RWGuard<'a> { } } +fn add_font_face_rules(stylesheet: &Stylesheet, device: &Device, font_cache_task: &FontCacheTask) { + for font_face in stylesheet.effective_rules(&device).font_face() { + for source in font_face.sources.iter() { + font_cache_task.add_web_font(font_face.family.clone(), source.clone()); + } + } +} + impl LayoutTask { /// Creates a new `LayoutTask` structure. fn new(id: PipelineId, @@ -336,6 +344,11 @@ impl LayoutTask { let image_cache_receiver = ROUTER.route_ipc_receiver_to_new_mpsc_receiver(ipc_image_cache_receiver); + let stylist = box Stylist::new(device); + for user_or_user_agent_stylesheet in stylist.stylesheets() { + add_font_face_rules(user_or_user_agent_stylesheet, &stylist.device, &font_cache_task); + } + LayoutTask { id: id, url: url, @@ -362,7 +375,7 @@ impl LayoutTask { constellation_chan: constellation_chan, screen_size: screen_size, stacking_context: None, - stylist: box Stylist::new(device), + stylist: stylist, parallel_traversal: parallel_traversal, dirty: Rect::zero(), generation: 0, @@ -735,11 +748,7 @@ impl LayoutTask { let mut rw_data = self.lock_rw_data(possibly_locked_rw_data); if mq.evaluate(&rw_data.stylist.device) { - for font_face in sheet.effective_rules(&rw_data.stylist.device).font_face() { - for source in font_face.sources.iter() { - self.font_cache_task.add_web_font(font_face.family.clone(), source.clone()); - } - } + add_font_face_rules(&sheet, &rw_data.stylist.device, &self.font_cache_task); rw_data.stylist.add_stylesheet(sheet); } diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index 28236326183..6d4c22e399b 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -84,6 +84,11 @@ impl Stylist { stylist } + #[inline] + pub fn stylesheets(&self) -> &[Stylesheet] { + &self.stylesheets + } + pub fn constrain_viewport(&self) -> Option { let cascaded_rule = self.stylesheets.iter() .flat_map(|s| s.effective_rules(&self.device).viewport())