From cafc0aabdf77deb15b7becb90223c2fbcd436691 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Mon, 25 Jan 2016 14:13:39 -0800 Subject: [PATCH] Hoist style-only traversal into geckolib. Implementing StandaloneStyleContext::new is going to require a TLS key (just like LayoutContext::new), and we don't want that key in shared code. --- components/style/traversal.rs | 45 +------------------------------ ports/geckolib/glue.rs | 2 +- ports/geckolib/lib.rs | 1 + ports/geckolib/traversal.rs | 51 +++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 45 deletions(-) create mode 100644 ports/geckolib/traversal.rs diff --git a/components/style/traversal.rs b/components/style/traversal.rs index d39da40f03e..781c99f619e 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -2,13 +2,11 @@ * 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 context::{LocalStyleContext, SharedStyleContext, StyleContext}; +use context::{SharedStyleContext, StyleContext}; use dom::{OpaqueNode, TNode, TRestyleDamage, UnsafeNode}; use matching::{ApplicableDeclarations, ElementMatchMethods, MatchMethods, StyleSharingResult}; use selectors::bloom::BloomFilter; use std::cell::RefCell; -use std::mem; -use std::rc::Rc; use util::opts; use util::tid::tid; @@ -115,47 +113,6 @@ pub trait DomTraversalContext<'ln, N: TNode<'ln>> { fn process_postorder(&self, node: N); } -pub struct StandaloneStyleContext<'a> { - pub shared: &'a SharedStyleContext, - cached_local_style_context: Rc, -} - -impl<'a> StandaloneStyleContext<'a> { - pub fn new(_: &'a SharedStyleContext) -> Self { panic!("Not implemented") } -} - -impl<'a> StyleContext<'a> for StandaloneStyleContext<'a> { - fn shared_context(&self) -> &'a SharedStyleContext { - &self.shared - } - - fn local_context(&self) -> &LocalStyleContext { - &self.cached_local_style_context - } -} - -pub struct RecalcStyleOnly<'lc> { - context: StandaloneStyleContext<'lc>, - root: OpaqueNode, -} - -impl<'lc, 'ln, N: TNode<'ln>> DomTraversalContext<'ln, N> for RecalcStyleOnly<'lc> { - type SharedContext = SharedStyleContext; - #[allow(unsafe_code)] - fn new<'a>(shared: &'a Self::SharedContext, root: OpaqueNode) -> Self { - // See the comment in RecalcStyleAndConstructFlows::new for an explanation of why this is - // necessary. - let shared_lc: &'lc SharedStyleContext = unsafe { mem::transmute(shared) }; - RecalcStyleOnly { - context: StandaloneStyleContext::new(shared_lc), - root: root, - } - } - - fn process_preorder(&self, node: N) { recalc_style_at(&self.context, self.root, node); } - fn process_postorder(&self, _: N) {} -} - /// The recalc-style-for-node traversal, which styles each node and must run before /// layout computation. This computes the styles applied to each node. #[inline] diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 0c5b76bec61..5bfa980ef7d 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -25,7 +25,7 @@ use style::media_queries::{Device, MediaType}; use style::parallel::{self, WorkQueueData}; use style::selector_matching::Stylist; use style::stylesheets::{Origin, Stylesheet}; -use style::traversal::RecalcStyleOnly; +use traversal::RecalcStyleOnly; use url::Url; use util::geometry::ViewportPx; use util::resource_files::set_resources_path; diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index d1548b7fd94..e224864dc6c 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -25,4 +25,5 @@ extern crate util; mod bindings; #[allow(non_snake_case)] pub mod glue; +mod traversal; mod wrapper; diff --git a/ports/geckolib/traversal.rs b/ports/geckolib/traversal.rs new file mode 100644 index 00000000000..b33d1f7b3e2 --- /dev/null +++ b/ports/geckolib/traversal.rs @@ -0,0 +1,51 @@ +/* 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 std::mem; +use std::rc::Rc; +use style::context::{LocalStyleContext, SharedStyleContext, StyleContext}; +use style::dom::{OpaqueNode, TNode}; +use style::traversal::{DomTraversalContext, recalc_style_at}; + +pub struct StandaloneStyleContext<'a> { + pub shared: &'a SharedStyleContext, + cached_local_style_context: Rc, +} + +impl<'a> StandaloneStyleContext<'a> { + pub fn new(_: &'a SharedStyleContext) -> Self { panic!("Not implemented") } +} + +impl<'a> StyleContext<'a> for StandaloneStyleContext<'a> { + fn shared_context(&self) -> &'a SharedStyleContext { + &self.shared + } + + fn local_context(&self) -> &LocalStyleContext { + &self.cached_local_style_context + } +} + +pub struct RecalcStyleOnly<'lc> { + context: StandaloneStyleContext<'lc>, + root: OpaqueNode, +} + +impl<'lc, 'ln, N: TNode<'ln>> DomTraversalContext<'ln, N> for RecalcStyleOnly<'lc> { + type SharedContext = SharedStyleContext; + #[allow(unsafe_code)] + fn new<'a>(shared: &'a Self::SharedContext, root: OpaqueNode) -> Self { + // See the comment in RecalcStyleAndConstructFlows::new for an explanation of why this is + // necessary. + let shared_lc: &'lc SharedStyleContext = unsafe { mem::transmute(shared) }; + RecalcStyleOnly { + context: StandaloneStyleContext::new(shared_lc), + root: root, + } + } + + fn process_preorder(&self, node: N) { recalc_style_at(&self.context, self.root, node); } + fn process_postorder(&self, _: N) {} +} +