Auto merge of #13656 - bholley:existing_style, r=emilio

Refactor style logic to avoid direct access to the node data during the cascade

The new restyle architecture doesn't store these things in consistent places, so we need a more abstract API.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13656)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-10-10 23:22:05 -05:00 committed by GitHub
commit abcc4aeaf2
9 changed files with 189 additions and 157 deletions

View file

@ -6,7 +6,7 @@
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use data::PersistentStyleData;
use data::{PersistentStyleData, PseudoStyles};
use dom::{LayoutIterator, NodeInfo, TDocument, TElement, TNode, TRestyleDamage, UnsafeNode};
use dom::{OpaqueNode, PresentationalHintsSynthetizer};
use element_state::ElementState;
@ -149,6 +149,20 @@ impl<'ln> GeckoNode<'ln> {
self.0.mServoData.set(ptr::null_mut());
}
}
pub fn get_pseudo_style(&self, pseudo: &PseudoElement) -> Option<Arc<ComputedValues>> {
self.borrow_data().and_then(|data| data.per_pseudo.get(pseudo).map(|c| c.clone()))
}
#[inline(always)]
fn borrow_data(&self) -> Option<AtomicRef<PersistentStyleData>> {
self.get_node_data().as_ref().map(|d| d.0.borrow())
}
#[inline(always)]
fn mutate_data(&self) -> Option<AtomicRefMut<PersistentStyleData>> {
self.get_node_data().as_ref().map(|d| d.0.borrow_mut())
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
@ -319,14 +333,24 @@ impl<'ln> TNode for GeckoNode<'ln> {
panic!("Atomic child count not implemented in Gecko");
}
#[inline(always)]
fn borrow_data(&self) -> Option<AtomicRef<PersistentStyleData>> {
self.get_node_data().as_ref().map(|d| d.0.borrow())
fn get_existing_style(&self) -> Option<Arc<ComputedValues>> {
self.borrow_data().and_then(|x| x.style.clone())
}
#[inline(always)]
fn mutate_data(&self) -> Option<AtomicRefMut<PersistentStyleData>> {
self.get_node_data().as_ref().map(|d| d.0.borrow_mut())
fn set_style(&self, style: Option<Arc<ComputedValues>>) {
self.mutate_data().unwrap().style = style;
}
fn take_pseudo_styles(&self) -> PseudoStyles {
use std::mem;
let mut tmp = PseudoStyles::default();
mem::swap(&mut tmp, &mut self.mutate_data().unwrap().per_pseudo);
tmp
}
fn set_pseudo_styles(&self, styles: PseudoStyles) {
debug_assert!(self.borrow_data().unwrap().per_pseudo.is_empty());
self.mutate_data().unwrap().per_pseudo = styles;
}
fn restyle_damage(self) -> Self::ConcreteRestyleDamage {