mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
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:
parent
92d8e8bcdf
commit
cafc0aabdf
4 changed files with 54 additions and 45 deletions
|
@ -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]
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
51
ports/geckolib/traversal.rs
Normal file
51
ports/geckolib/traversal.rs
Normal 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) {}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue