Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stylo: Rearrange some data structures in preparation for the new incremental restyle algorithm #13863

Merged
merged 1 commit into from Oct 21, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -41,7 +41,7 @@ pub type NonOpaqueStyleAndLayoutData = *mut AtomicRefCell<PersistentLayoutData>;

pub trait LayoutNodeLayoutData {
/// Similar to borrow_data*, but returns the full PersistentLayoutData rather
/// than only the PersistentStyleData.
/// than only the style::data::NodeData.
fn borrow_layout_data(&self) -> Option<AtomicRef<PersistentLayoutData>>;
fn mutate_layout_data(&self) -> Option<AtomicRefMut<PersistentLayoutData>>;
fn initialize_data(self);
@@ -52,15 +52,15 @@ use selectors::matching::ElementFlags;
use selectors::parser::{AttrSelector, NamespaceConstraint};
use std::fmt;
use std::marker::PhantomData;
use std::mem::{replace, transmute};
use std::mem::transmute;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use string_cache::{Atom, Namespace};
use style::atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use style::attr::AttrValue;
use style::computed_values::display;
use style::context::SharedStyleContext;
use style::data::{PersistentStyleData, PseudoStyles};
use style::data::NodeData;
use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TDocument, TElement, TNode};
use style::dom::{TRestyleDamage, UnsafeNode};
use style::element_state::*;
@@ -107,11 +107,7 @@ impl<'ln> ServoLayoutNode<'ln> {
}
}

pub fn borrow_data(&self) -> Option<AtomicRef<PersistentStyleData>> {
self.get_style_data().map(|d| d.borrow())
}

pub fn mutate_data(&self) -> Option<AtomicRefMut<PersistentStyleData>> {
pub fn mutate_data(&self) -> Option<AtomicRefMut<NodeData>> {
self.get_style_data().map(|d| d.borrow_mut())
}

@@ -234,32 +230,25 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
old_value - 1
}

fn get_existing_style(&self) -> Option<Arc<ComputedValues>> {
self.borrow_data().and_then(|x| x.style.clone())
}

fn set_style(&self, style: Arc<ComputedValues>) {
self.mutate_data().unwrap().style = Some(style);
}

fn take_pseudo_styles(&self) -> PseudoStyles {
replace(&mut self.mutate_data().unwrap().per_pseudo, PseudoStyles::default())
}

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 begin_styling(&self) -> AtomicRefMut<NodeData> {
let mut data = self.mutate_data().unwrap();
data.gather_previous_styles(|| None);
data
}

fn style_text_node(&self, style: Arc<ComputedValues>) {
debug_assert!(self.is_text_node());
let mut data = self.get_partial_layout_data().unwrap().borrow_mut();
data.style_data.style = Some(style);
data.style_data.style_text_node(style);
if self.has_changed() {
data.restyle_damage = RestyleDamage::rebuild_and_reflow();
}
}

fn borrow_data(&self) -> Option<AtomicRef<NodeData>> {
self.get_style_data().map(|d| d.borrow())
}

fn restyle_damage(self) -> RestyleDamage {
self.get_partial_layout_data().unwrap().borrow().restyle_damage
}
@@ -345,11 +334,11 @@ impl<'ln> LayoutNode for ServoLayoutNode<'ln> {
self.node.set_flag(HAS_DIRTY_DESCENDANTS, false);
}

fn get_style_data(&self) -> Option<&AtomicRefCell<PersistentStyleData>> {
fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>> {
unsafe {
self.get_jsmanaged().get_style_and_layout_data().map(|d| {
let ppld: &AtomicRefCell<PartialPersistentLayoutData> = &**d.ptr;
let psd: &AtomicRefCell<PersistentStyleData> = transmute(ppld);
let psd: &AtomicRefCell<NodeData> = transmute(ppld);
psd
})
}
@@ -413,11 +402,7 @@ impl<'ln> ServoLayoutNode<'ln> {

fn debug_style_str(self) -> String {
if let Some(data) = self.borrow_data() {
if let Some(data) = data.style.as_ref() {
format!("{:?}: {:?}", self.script_type_id(), data)
} else {
format!("{:?}: style=None", self.script_type_id())
}
format!("{:?}: {:?}", self.script_type_id(), &*data)
} else {
format!("{:?}: style_data=None", self.script_type_id())
}
@@ -922,7 +907,7 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
}
}

fn get_style_data(&self) -> Option<&AtomicRefCell<PersistentStyleData>> {
fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>> {
self.node.get_style_data()
}
}
@@ -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::PersistentStyleData;
use style::data::NodeData;

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 PersistentStyleData and PersistentLayoutData.
pub style_data: PersistentStyleData,
/// transmutations between NodeData and PersistentLayoutData.
pub style_data: NodeData,

/// 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: PersistentStyleData::new(),
style_data: NodeData::new(),
restyle_damage: RestyleDamage::empty(),
parallel: DomParallelInfo::new(),
}
@@ -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::PersistentStyleData;
use style::data::NodeData;
use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TNode};
use style::dom::OpaqueNode;
use style::properties::ServoComputedValues;
@@ -83,7 +83,7 @@ pub trait LayoutNode: TNode {

unsafe fn clear_dirty_bits(&self);

fn get_style_data(&self) -> Option<&AtomicRefCell<PersistentStyleData>>;
fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>>;

fn init_style_and_layout_data(&self, data: OpaqueStyleAndLayoutData);
fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData>;
@@ -190,7 +190,7 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
if self.get_style_data()
.unwrap()
.borrow()
.per_pseudo
.current_styles().pseudos
.contains_key(&PseudoElement::Before) {
Some(self.with_pseudo(PseudoElementType::Before(None)))
} else {
@@ -203,7 +203,7 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
if self.get_style_data()
.unwrap()
.borrow()
.per_pseudo
.current_styles().pseudos
.contains_key(&PseudoElement::After) {
Some(self.with_pseudo(PseudoElementType::After(None)))
} else {
@@ -249,7 +249,7 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
match self.get_pseudo_element_type() {
PseudoElementType::Normal => {
self.get_style_data().unwrap().borrow()
.style.as_ref().unwrap().clone()
.current_styles().primary.clone()
},
other => {
// Precompute non-eagerly-cascaded pseudo-element styles if not
@@ -262,13 +262,13 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
if !self.get_style_data()
.unwrap()
.borrow()
.per_pseudo.contains_key(&style_pseudo) {
.current_styles().pseudos.contains_key(&style_pseudo) {
let mut data = self.get_style_data().unwrap().borrow_mut();
let new_style =
context.stylist
.precomputed_values_for_pseudo(&style_pseudo,
data.style.as_ref());
data.per_pseudo
Some(&data.current_styles().primary));
data.current_pseudos_mut()
.insert(style_pseudo.clone(), new_style.unwrap());
}
}
@@ -277,22 +277,22 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
if !self.get_style_data()
.unwrap()
.borrow()
.per_pseudo.contains_key(&style_pseudo) {
.current_styles().pseudos.contains_key(&style_pseudo) {
let mut data = self.get_style_data().unwrap().borrow_mut();
let new_style =
context.stylist
.lazily_compute_pseudo_element_style(
&self.as_element(),
&style_pseudo,
data.style.as_ref().unwrap());
data.per_pseudo
&data.current_styles().primary);
data.current_pseudos_mut()
.insert(style_pseudo.clone(), new_style.unwrap());
}
}
}

self.get_style_data().unwrap().borrow()
.per_pseudo.get(&style_pseudo)
.current_styles().pseudos.get(&style_pseudo)
.unwrap().clone()
}
}
@@ -310,34 +310,19 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {
let data = self.get_style_data().unwrap().borrow();
match self.get_pseudo_element_type() {
PseudoElementType::Normal
=> data.style.as_ref().unwrap().clone(),
=> data.current_styles().primary.clone(),
other
=> data.per_pseudo.get(&other.style_pseudo_element()).unwrap().clone(),
=> data.current_styles().pseudos.get(&other.style_pseudo_element()).unwrap().clone(),
}
}

#[inline]
fn selected_style(&self, _context: &SharedStyleContext) -> Arc<ServoComputedValues> {
let data = self.get_style_data().unwrap().borrow();
data.per_pseudo
data.current_styles().pseudos
.get(&PseudoElement::Selection)
.unwrap_or(data.style.as_ref().unwrap()).clone()
}

/// Removes the style from this node.
///
/// Unlike the version on TNode, this handles pseudo-elements.
fn unstyle(self) {
let mut data = self.get_style_data().unwrap().borrow_mut();

match self.get_pseudo_element_type() {
PseudoElementType::Normal => {
data.style = None;
}
other => {
data.per_pseudo.remove(&other.style_pseudo_element());
}
};
.unwrap_or(&data.current_styles().primary)
.clone()
}

fn is_ignorable_whitespace(&self, context: &SharedStyleContext) -> bool;
@@ -377,7 +362,7 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized {

fn get_colspan(&self) -> u32;

fn get_style_data(&self) -> Option<&AtomicRefCell<PersistentStyleData>>;
fn get_style_data(&self) -> Option<&AtomicRefCell<NodeData>>;
}

// This trait is only public so that it can be implemented by the gecko wrapper.
@@ -66,8 +66,8 @@
}
},
"raw_lines": [
# We can get rid of this when the bindings move into the style crate.
"pub enum OpaqueStyleData {}",
"use atomic_refcell::AtomicRefCell;",
"use data::NodeData;",
"pub use nsstring::nsStringRepr as nsString;"
],
"blacklist_types": ["nsString"],
@@ -229,7 +229,7 @@
}, {
"generic": False,
"gecko": "ServoNodeData",
"servo": "OpaqueStyleData"
"servo": "AtomicRefCell<NodeData>",
}
],
},
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.