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.
This commit is contained in:
Bobby Holley 2016-01-25 14:13:39 -08:00
parent 92d8e8bcdf
commit cafc0aabdf
4 changed files with 54 additions and 45 deletions

View file

@ -2,13 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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 dom::{OpaqueNode, TNode, TRestyleDamage, UnsafeNode};
use matching::{ApplicableDeclarations, ElementMatchMethods, MatchMethods, StyleSharingResult}; use matching::{ApplicableDeclarations, ElementMatchMethods, MatchMethods, StyleSharingResult};
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use std::cell::RefCell; use std::cell::RefCell;
use std::mem;
use std::rc::Rc;
use util::opts; use util::opts;
use util::tid::tid; use util::tid::tid;
@ -115,47 +113,6 @@ pub trait DomTraversalContext<'ln, N: TNode<'ln>> {
fn process_postorder(&self, node: N); fn process_postorder(&self, node: N);
} }
pub struct StandaloneStyleContext<'a> {
pub shared: &'a SharedStyleContext,
cached_local_style_context: Rc<LocalStyleContext>,
}
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 /// The recalc-style-for-node traversal, which styles each node and must run before
/// layout computation. This computes the styles applied to each node. /// layout computation. This computes the styles applied to each node.
#[inline] #[inline]

View file

@ -25,7 +25,7 @@ use style::media_queries::{Device, MediaType};
use style::parallel::{self, WorkQueueData}; use style::parallel::{self, WorkQueueData};
use style::selector_matching::Stylist; use style::selector_matching::Stylist;
use style::stylesheets::{Origin, Stylesheet}; use style::stylesheets::{Origin, Stylesheet};
use style::traversal::RecalcStyleOnly; use traversal::RecalcStyleOnly;
use url::Url; use url::Url;
use util::geometry::ViewportPx; use util::geometry::ViewportPx;
use util::resource_files::set_resources_path; use util::resource_files::set_resources_path;

View file

@ -25,4 +25,5 @@ extern crate util;
mod bindings; mod bindings;
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub mod glue; pub mod glue;
mod traversal;
mod wrapper; mod wrapper;

View file

@ -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<LocalStyleContext>,
}
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) {}
}