diff options
Diffstat (limited to 'src/components/main/layout/context.rs')
-rw-r--r-- | src/components/main/layout/context.rs | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/src/components/main/layout/context.rs b/src/components/main/layout/context.rs index 5385e2bcb99..61b8c3e03e6 100644 --- a/src/components/main/layout/context.rs +++ b/src/components/main/layout/context.rs @@ -4,28 +4,37 @@ //! Data needed by the layout task. -use extra::arc::{Arc, MutexArc}; -use green::task::GreenTask; +use css::matching::{ApplicableDeclarationsCache, StyleSharingCandidateCache}; use layout::flow::FlowLeafSet; use layout::util::OpaqueNode; use layout::wrapper::DomLeafSet; -use std::cast; -use std::ptr; -use std::rt::Runtime; -use std::rt::local::Local; -use std::rt::task::Task; +use extra::arc::{Arc, MutexArc}; use geom::size::Size2D; use gfx::font_context::{FontContext, FontContextInfo}; +use green::task::GreenTask; use script::layout_interface::LayoutChan; use servo_msg::constellation_msg::ConstellationChan; use servo_net::local_image_cache::LocalImageCache; use servo_util::geometry::Au; -use style::Stylist; +use std::cast; +use std::ptr; +use std::rt::Runtime; +use std::rt::local::Local; +use std::rt::task::Task; +use style::{ComputedValues, Stylist}; #[thread_local] static mut FONT_CONTEXT: *mut FontContext = 0 as *mut FontContext; +#[thread_local] +static mut APPLICABLE_DECLARATIONS_CACHE: *mut ApplicableDeclarationsCache = + 0 as *mut ApplicableDeclarationsCache; + +#[thread_local] +static mut STYLE_SHARING_CANDIDATE_CACHE: *mut StyleSharingCandidateCache = + 0 as *mut StyleSharingCandidateCache; + /// Data shared by all layout workers. #[deriving(Clone)] pub struct LayoutContext { @@ -55,6 +64,9 @@ pub struct LayoutContext { /// FIXME(pcwalton): Make this no longer an unsafe pointer once we have fast `RWArc`s. stylist: *Stylist, + /// The initial set of CSS properties. + initial_css_values: Arc<ComputedValues>, + /// The root node at which we're starting the layout. reflow_root: OpaqueNode, } @@ -79,5 +91,49 @@ impl LayoutContext { cast::transmute(FONT_CONTEXT) } } + + pub fn applicable_declarations_cache<'a>(&'a self) -> &'a mut ApplicableDeclarationsCache { + // Sanity check. + { + let mut task = Local::borrow(None::<Task>); + match task.get().maybe_take_runtime::<GreenTask>() { + Some(green) => { + task.get().put_runtime(green as ~Runtime); + fail!("can't call this on a green task!") + } + None => {} + } + } + + unsafe { + if APPLICABLE_DECLARATIONS_CACHE == ptr::mut_null() { + let cache = ~ApplicableDeclarationsCache::new(); + APPLICABLE_DECLARATIONS_CACHE = cast::transmute(cache) + } + cast::transmute(APPLICABLE_DECLARATIONS_CACHE) + } + } + + pub fn style_sharing_candidate_cache<'a>(&'a self) -> &'a mut StyleSharingCandidateCache { + // Sanity check. + { + let mut task = Local::borrow(None::<Task>); + match task.get().maybe_take_runtime::<GreenTask>() { + Some(green) => { + task.get().put_runtime(green as ~Runtime); + fail!("can't call this on a green task!") + } + None => {} + } + } + + unsafe { + if STYLE_SHARING_CANDIDATE_CACHE == ptr::mut_null() { + let cache = ~StyleSharingCandidateCache::new(); + STYLE_SHARING_CANDIDATE_CACHE = cast::transmute(cache) + } + cast::transmute(STYLE_SHARING_CANDIDATE_CACHE) + } + } } |