Rename NodeData and associated data structures to Element*.

MozReview-Commit-ID: 96VsmsoZtjZ
This commit is contained in:
Bobby Holley 2016-10-28 14:01:07 -07:00
parent 5442fbec3f
commit be89f73675
15 changed files with 75 additions and 77 deletions

View file

@ -15,7 +15,7 @@ use script_layout_interface::wrapper_traits::{LayoutElement, LayoutNode, ThreadS
use std::mem;
use style::atomic_refcell::AtomicRefCell;
use style::context::{LocalStyleContext, SharedStyleContext, StyleContext};
use style::data::NodeData;
use style::data::ElementData;
use style::dom::{StylingMode, TElement, TNode};
use style::traversal::{DomTraversalContext, put_thread_local_bloom_filter};
use style::traversal::{recalc_style_at, remove_from_bloom_filter};
@ -131,7 +131,7 @@ impl<'lc, N> DomTraversalContext<N> for RecalcStyleAndConstructFlows<'lc>
}
}
fn ensure_element_data(element: &N::ConcreteElement) -> &AtomicRefCell<NodeData> {
fn ensure_element_data(element: &N::ConcreteElement) -> &AtomicRefCell<ElementData> {
element.as_node().initialize_data();
element.get_style_data().unwrap()
}

View file

@ -42,7 +42,7 @@ pub type NonOpaqueStyleAndLayoutData = AtomicRefCell<PersistentLayoutData>;
pub trait LayoutNodeLayoutData {
/// Similar to borrow_data*, but returns the full PersistentLayoutData rather
/// than only the style::data::NodeData.
/// than only the style::data::ElementData.
fn borrow_layout_data(&self) -> Option<AtomicRef<PersistentLayoutData>>;
fn mutate_layout_data(&self) -> Option<AtomicRefMut<PersistentLayoutData>>;
fn flow_debug_id(self) -> usize;

View file

@ -60,7 +60,7 @@ use style::atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use style::attr::AttrValue;
use style::computed_values::display;
use style::context::SharedStyleContext;
use style::data::NodeData;
use style::data::ElementData;
use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TDocument, TElement, TNode};
use style::dom::{TRestyleDamage, UnsafeNode};
use style::element_state::*;
@ -506,24 +506,24 @@ impl<'le> TElement for ServoLayoutElement<'le> {
old_value - 1
}
fn begin_styling(&self) -> AtomicRefMut<NodeData> {
fn begin_styling(&self) -> AtomicRefMut<ElementData> {
let mut data = self.mutate_data().unwrap();
data.gather_previous_styles(|| None);
data
}
fn borrow_data(&self) -> Option<AtomicRef<NodeData>> {
fn borrow_data(&self) -> Option<AtomicRef<ElementData>> {
self.get_style_data().map(|d| d.borrow())
}
}
impl<'le> LayoutElement for ServoLayoutElement<'le> {
fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>> {
fn get_style_data(&self) -> Option<&AtomicRefCell<ElementData>> {
unsafe {
self.get_style_and_layout_data().map(|d| {
let ppld: &AtomicRefCell<PartialPersistentLayoutData> = &**d.ptr;
let psd: &AtomicRefCell<NodeData> = transmute(ppld);
let psd: &AtomicRefCell<ElementData> = transmute(ppld);
psd
})
}
@ -551,15 +551,13 @@ impl<'le> ServoLayoutElement<'le> {
}
}
fn mutate_data(&self) -> Option<AtomicRefMut<NodeData>> {
fn mutate_data(&self) -> Option<AtomicRefMut<ElementData>> {
self.get_style_data().map(|d| d.borrow_mut())
}
fn get_partial_layout_data(&self) -> Option<&AtomicRefCell<PartialPersistentLayoutData>> {
unsafe {
self.get_style_and_layout_data().map(|d| {
&**d.ptr
})
self.get_style_and_layout_data().map(|d| &**d.ptr)
}
}
}
@ -1090,7 +1088,7 @@ impl<'le> ThreadSafeLayoutElement for ServoThreadSafeLayoutElement<'le> {
self.element.get_attr(namespace, name)
}
fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>> {
fn get_style_data(&self) -> Option<&AtomicRefCell<ElementData>> {
self.element.get_style_data()
}
}

View file

@ -53,14 +53,14 @@ use libc::c_void;
use restyle_damage::RestyleDamage;
use std::sync::atomic::AtomicIsize;
use style::atomic_refcell::AtomicRefCell;
use style::data::NodeData;
use style::data::ElementData;
pub struct PartialPersistentLayoutData {
/// Data that the style system associates with a node. When the
/// style system is being used standalone, this is all that hangs
/// off the node. This must be first to permit the various
/// transmutations between NodeData and PersistentLayoutData.
pub style_data: NodeData,
/// transmutations between ElementData and PersistentLayoutData.
pub style_data: ElementData,
/// Description of how to account for recent style changes.
pub restyle_damage: RestyleDamage,
@ -72,7 +72,7 @@ pub struct PartialPersistentLayoutData {
impl PartialPersistentLayoutData {
pub fn new() -> Self {
PartialPersistentLayoutData {
style_data: NodeData::new(),
style_data: ElementData::new(),
restyle_damage: RestyleDamage::empty(),
parallel: DomParallelInfo::new(),
}

View file

@ -18,7 +18,7 @@ use string_cache::{Atom, Namespace};
use style::atomic_refcell::AtomicRefCell;
use style::computed_values::display;
use style::context::SharedStyleContext;
use style::data::NodeData;
use style::data::ElementData;
use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TElement, TNode};
use style::dom::OpaqueNode;
use style::properties::ServoComputedValues;
@ -274,7 +274,7 @@ pub trait DangerousThreadSafeLayoutNode: ThreadSafeLayoutNode {
}
pub trait LayoutElement: Clone + Copy + Sized + Debug + GetLayoutData + TElement {
fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>>;
fn get_style_data(&self) -> Option<&AtomicRefCell<ElementData>>;
}
pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
@ -296,7 +296,7 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug +
#[inline]
fn get_attr(&self, namespace: &Namespace, name: &Atom) -> Option<&str>;
fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>>;
fn get_style_data(&self) -> Option<&AtomicRefCell<ElementData>>;
#[inline]
fn get_pseudo_element_type(&self) -> PseudoElementType<Option<display::T>>;

View file

@ -67,7 +67,7 @@ COMPILATION_TARGETS = {
},
"raw_lines": [
"use atomic_refcell::AtomicRefCell;",
"use data::NodeData;",
"use data::ElementData;",
"pub use nsstring::nsStringRepr as nsString;"
],
"blacklist_types": ["nsString"],
@ -226,7 +226,7 @@ COMPILATION_TARGETS = {
}, {
"generic": False,
"gecko": "ServoNodeData",
"servo": "AtomicRefCell<NodeData>",
"servo": "AtomicRefCell<ElementData>",
}
],
},

View file

@ -35,7 +35,7 @@ impl DerefMut for PseudoStyles {
/// The styles associated with a node, including the styles for any
/// pseudo-elements.
#[derive(Clone, Debug)]
pub struct NodeStyles {
pub struct ElementStyles {
/// The results of CSS styling for this node.
pub primary: Arc<ComputedValues>,
@ -43,9 +43,9 @@ pub struct NodeStyles {
pub pseudos: PseudoStyles,
}
impl NodeStyles {
impl ElementStyles {
pub fn new(primary: Arc<ComputedValues>) -> Self {
NodeStyles {
ElementStyles {
primary: primary,
pseudos: PseudoStyles::empty(),
}
@ -53,7 +53,7 @@ impl NodeStyles {
}
#[derive(Debug)]
enum NodeDataStyles {
enum ElementDataStyles {
/// The field has not been initialized.
Uninitialized,
@ -64,19 +64,19 @@ enum NodeDataStyles {
/// immutable, but for now we need to mutate it a bit before styling to
/// handle animations.
///
/// Note that since NodeStyles contains an Arc, the null pointer
/// Note that since ElementStyles contains an Arc, the null pointer
/// optimization prevents the Option<> here from consuming an extra word.
Previous(Option<NodeStyles>),
Previous(Option<ElementStyles>),
/// The field holds the current, up-to-date style.
///
/// This is the output of the styling algorithm.
Current(NodeStyles),
Current(ElementStyles),
}
impl NodeDataStyles {
impl ElementDataStyles {
fn is_previous(&self) -> bool {
use self::NodeDataStyles::*;
use self::ElementDataStyles::*;
match *self {
Previous(_) => true,
_ => false,
@ -113,34 +113,34 @@ impl RestyleData {
/// In both cases, it is wrapped inside an AtomicRefCell to ensure thread
/// safety.
#[derive(Debug)]
pub struct NodeData {
styles: NodeDataStyles,
pub struct ElementData {
styles: ElementDataStyles,
pub restyle_data: Option<RestyleData>,
}
impl NodeData {
impl ElementData {
pub fn new() -> Self {
NodeData {
styles: NodeDataStyles::Uninitialized,
ElementData {
styles: ElementDataStyles::Uninitialized,
restyle_data: None,
}
}
pub fn has_current_styles(&self) -> bool {
match self.styles {
NodeDataStyles::Current(_) => true,
ElementDataStyles::Current(_) => true,
_ => false,
}
}
pub fn get_current_styles(&self) -> Option<&NodeStyles> {
pub fn get_current_styles(&self) -> Option<&ElementStyles> {
match self.styles {
NodeDataStyles::Current(ref s) => Some(s),
ElementDataStyles::Current(ref s) => Some(s),
_ => None,
}
}
pub fn current_styles(&self) -> &NodeStyles {
pub fn current_styles(&self) -> &ElementStyles {
self.get_current_styles().expect("Calling current_styles before or during styling")
}
@ -149,29 +149,29 @@ impl NodeData {
#[cfg(not(feature = "gecko"))]
pub fn current_pseudos_mut(&mut self) -> &mut PseudoStyles {
match self.styles {
NodeDataStyles::Current(ref mut s) => &mut s.pseudos,
ElementDataStyles::Current(ref mut s) => &mut s.pseudos,
_ => panic!("Calling current_pseudos_mut before or during styling"),
}
}
pub fn previous_styles(&self) -> Option<&NodeStyles> {
pub fn previous_styles(&self) -> Option<&ElementStyles> {
match self.styles {
NodeDataStyles::Previous(ref s) => s.as_ref(),
ElementDataStyles::Previous(ref s) => s.as_ref(),
_ => panic!("Calling previous_styles without having gathered it"),
}
}
pub fn previous_styles_mut(&mut self) -> Option<&mut NodeStyles> {
pub fn previous_styles_mut(&mut self) -> Option<&mut ElementStyles> {
match self.styles {
NodeDataStyles::Previous(ref mut s) => s.as_mut(),
ElementDataStyles::Previous(ref mut s) => s.as_mut(),
_ => panic!("Calling previous_styles without having gathered it"),
}
}
pub fn gather_previous_styles<F>(&mut self, f: F)
where F: FnOnce() -> Option<NodeStyles>
where F: FnOnce() -> Option<ElementStyles>
{
use self::NodeDataStyles::*;
use self::ElementDataStyles::*;
self.styles = match mem::replace(&mut self.styles, Uninitialized) {
Uninitialized => Previous(f()),
Current(x) => Previous(Some(x)),
@ -186,13 +186,13 @@ impl NodeData {
}
pub fn style_text_node(&mut self, style: Arc<ComputedValues>) {
self.styles = NodeDataStyles::Current(NodeStyles::new(style));
self.styles = ElementDataStyles::Current(ElementStyles::new(style));
self.restyle_data = None;
}
pub fn finish_styling(&mut self, styles: NodeStyles) {
pub fn finish_styling(&mut self, styles: ElementStyles) {
debug_assert!(self.styles.is_previous());
self.styles = NodeDataStyles::Current(styles);
self.styles = ElementDataStyles::Current(styles);
self.restyle_data = None;
}
}

View file

@ -7,7 +7,7 @@
#![allow(unsafe_code)]
use atomic_refcell::{AtomicRef, AtomicRefMut};
use data::{NodeStyles, NodeData};
use data::{ElementStyles, ElementData};
use element_state::ElementState;
use parking_lot::RwLock;
use properties::{ComputedValues, PropertyDeclarationBlock};
@ -219,10 +219,10 @@ pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + Pre
/// Returns the styles from the layout frame that owns them, if any.
///
/// FIXME(bholley): Once we start dropping NodeData from nodes when
/// FIXME(bholley): Once we start dropping ElementData from nodes when
/// creating frames, we'll want to teach this method to actually get
/// style data from the frame.
fn get_styles_from_frame(&self) -> Option<NodeStyles> { None }
fn get_styles_from_frame(&self) -> Option<ElementStyles> { None }
/// Returns the styling mode for this node. This is only valid to call before
/// and during restyling, before finish_styling is invoked.
@ -262,10 +262,10 @@ pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + Pre
/// Sets up the appropriate data structures to style a node, returing a
/// mutable handle to the node data upon which further style calculations
/// can be performed.
fn begin_styling(&self) -> AtomicRefMut<NodeData>;
fn begin_styling(&self) -> AtomicRefMut<ElementData>;
/// Immutable borrows the NodeData.
fn borrow_data(&self) -> Option<AtomicRef<NodeData>>;
/// Immutable borrows the ElementData.
fn borrow_data(&self) -> Option<AtomicRef<ElementData>>;
/// Properly marks nodes as dirty in response to restyle hints.
fn note_restyle_hint<C: DomTraversalContext<Self::ConcreteNode>>(&self, hint: RestyleHint) {

View file

@ -4,7 +4,7 @@
use atomic_refcell::AtomicRefCell;
use context::{LocalStyleContext, SharedStyleContext, StyleContext};
use data::NodeData;
use data::ElementData;
use dom::{NodeInfo, OpaqueNode, StylingMode, TElement, TNode};
use gecko::context::StandaloneStyleContext;
use gecko::wrapper::{GeckoElement, GeckoNode};
@ -55,7 +55,7 @@ impl<'lc, 'ln> DomTraversalContext<GeckoNode<'ln>> for RecalcStyleOnly<'lc> {
}
}
fn ensure_element_data<'a>(element: &'a GeckoElement<'ln>) -> &'a AtomicRefCell<NodeData> {
fn ensure_element_data<'a>(element: &'a GeckoElement<'ln>) -> &'a AtomicRefCell<ElementData> {
element.ensure_data()
}

View file

@ -6,7 +6,7 @@
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use data::NodeData;
use data::ElementData;
use dom::{LayoutIterator, NodeInfo, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
use dom::{OpaqueNode, PresentationalHintsSynthetizer};
use element_state::ElementState;
@ -332,15 +332,15 @@ impl<'le> GeckoElement<'le> {
.get(pseudo).map(|c| c.clone()))
}
fn get_node_data(&self) -> Option<&AtomicRefCell<NodeData>> {
fn get_node_data(&self) -> Option<&AtomicRefCell<ElementData>> {
unsafe { self.raw_node().mServoData.get().as_ref() }
}
pub fn ensure_data(&self) -> &AtomicRefCell<NodeData> {
pub fn ensure_data(&self) -> &AtomicRefCell<ElementData> {
match self.get_node_data() {
Some(x) => x,
None => {
let ptr = Box::into_raw(Box::new(AtomicRefCell::new(NodeData::new())));
let ptr = Box::into_raw(Box::new(AtomicRefCell::new(ElementData::new())));
self.raw_node().mServoData.set(ptr);
unsafe { &* ptr }
},
@ -444,13 +444,13 @@ impl<'le> TElement for GeckoElement<'le> {
panic!("Atomic child count not implemented in Gecko");
}
fn begin_styling(&self) -> AtomicRefMut<NodeData> {
fn begin_styling(&self) -> AtomicRefMut<ElementData> {
let mut data = self.ensure_data().borrow_mut();
data.gather_previous_styles(|| self.get_styles_from_frame());
data
}
fn borrow_data(&self) -> Option<AtomicRef<NodeData>> {
fn borrow_data(&self) -> Option<AtomicRef<ElementData>> {
self.get_node_data().map(|x| x.borrow())
}
}

View file

@ -1,11 +1,11 @@
/* automatically generated by rust-bindgen */
use atomic_refcell::AtomicRefCell;
use data::NodeData;
use data::ElementData;
pub use nsstring::nsStringRepr as nsString;
pub type ServoUnsafeCell<T> = ::std::cell::UnsafeCell<T>;
pub type ServoCell<T> = ::std::cell::Cell<T>;
pub type ServoNodeData = AtomicRefCell<NodeData>;
pub type ServoNodeData = AtomicRefCell<ElementData>;
#[derive(Debug)]
#[repr(C)]

View file

@ -1,11 +1,11 @@
/* automatically generated by rust-bindgen */
use atomic_refcell::AtomicRefCell;
use data::NodeData;
use data::ElementData;
pub use nsstring::nsStringRepr as nsString;
pub type ServoUnsafeCell<T> = ::std::cell::UnsafeCell<T>;
pub type ServoCell<T> = ::std::cell::Cell<T>;
pub type ServoNodeData = AtomicRefCell<NodeData>;
pub type ServoNodeData = AtomicRefCell<ElementData>;
#[derive(Debug)]
#[repr(C)]

View file

@ -11,7 +11,7 @@ use arc_ptr_eq;
use cache::{LRUCache, SimpleHashCache};
use cascade_info::CascadeInfo;
use context::{SharedStyleContext, StyleContext};
use data::{NodeStyles, PseudoStyles};
use data::{ElementStyles, PseudoStyles};
use dom::{TElement, TNode, TRestyleDamage, UnsafeNode};
use properties::{CascadeFlags, ComputedValues, SHAREABLE, cascade};
use properties::longhands::display::computed_value as display;
@ -737,7 +737,7 @@ pub trait MatchMethods : TElement {
RestyleResult::Continue
};
data.finish_styling(NodeStyles::new(shared_style));
data.finish_styling(ElementStyles::new(shared_style));
return StyleSharingResult::StyleWasShared(i, damage, restyle_result)
}
@ -882,7 +882,7 @@ pub trait MatchMethods : TElement {
};
new_styles = NodeStyles::new(
new_styles = ElementStyles::new(
self.cascade_node_pseudo_element(context,
parent_style.clone(),
old_primary,

View file

@ -6,7 +6,7 @@
use atomic_refcell::AtomicRefCell;
use context::{LocalStyleContext, SharedStyleContext, StyleContext};
use data::NodeData;
use data::ElementData;
use dom::{OpaqueNode, StylingMode, TElement, TNode, UnsafeNode};
use matching::{ApplicableDeclarations, MatchMethods, StyleSharingResult};
use selectors::bloom::BloomFilter;
@ -197,10 +197,10 @@ pub trait DomTraversalContext<N: TNode> {
}
}
/// Ensures the existence of the NodeData, and returns it. This can't live
/// Ensures the existence of the ElementData, and returns it. This can't live
/// on TNode because of the trait-based separation between Servo's script
/// and layout crates.
fn ensure_element_data(element: &N::ConcreteElement) -> &AtomicRefCell<NodeData>;
fn ensure_element_data(element: &N::ConcreteElement) -> &AtomicRefCell<ElementData>;
fn local_context(&self) -> &LocalStyleContext;
}

View file

@ -260,7 +260,7 @@ pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed)
if node.is_text_node() {
error!("Don't call Servo_ComputedValue_Get() for text nodes");
let parent = node.parent_node().unwrap().as_element().unwrap();
let parent_cv = parent.borrow_data().map_or(Arc::new(ComputedValues::initial_values().clone()),
let parent_cv = parent.borrow_data().map_or_else(|| Arc::new(ComputedValues::initial_values().clone()),
|x| x.get_current_styles().unwrap()
.primary.clone());
return ComputedValues::inherit_from(&parent_cv).into_strong();