diff options
author | Bobby Holley <bobbyholley@gmail.com> | 2016-09-29 17:09:06 -0700 |
---|---|---|
committer | Bobby Holley <bobbyholley@gmail.com> | 2016-10-02 19:19:52 -0700 |
commit | 687e1f701c5b466ed908b2f05243e0ea299d3c9b (patch) | |
tree | 3dab40fe7d8c478e212ab38329bcd75d003faedf /components/script_layout_interface | |
parent | 5bcc4192bf2c0723444ee62b8fbbbc2084d53175 (diff) | |
download | servo-687e1f701c5b466ed908b2f05243e0ea299d3c9b.tar.gz servo-687e1f701c5b466ed908b2f05243e0ea299d3c9b.zip |
Rename PrivateStyleData to PersistentStyleData and use AtomicRefCell instead of RefCell as a container.
This allows us to eliminate the unsafe borrows. \o/
MozReview-Commit-ID: 29hpGaWUFQz
Diffstat (limited to 'components/script_layout_interface')
-rw-r--r-- | components/script_layout_interface/lib.rs | 10 | ||||
-rw-r--r-- | components/script_layout_interface/wrapper_traits.rs | 36 |
2 files changed, 21 insertions, 25 deletions
diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs index d3554422dd7..cad2e012c7c 100644 --- a/components/script_layout_interface/lib.rs +++ b/components/script_layout_interface/lib.rs @@ -52,11 +52,11 @@ use core::nonzero::NonZero; use ipc_channel::ipc::IpcSender; use libc::c_void; use restyle_damage::RestyleDamage; -use style::data::PrivateStyleData; -use style::refcell::RefCell; +use style::atomic_refcell::AtomicRefCell; +use style::data::PersistentStyleData; -pub struct PartialStyleAndLayoutData { - pub style_data: PrivateStyleData, +pub struct PartialPersistentLayoutData { + pub style_data: PersistentStyleData, pub restyle_damage: RestyleDamage, } @@ -64,7 +64,7 @@ pub struct PartialStyleAndLayoutData { pub struct OpaqueStyleAndLayoutData { #[ignore_heap_size_of = "TODO(#6910) Box value that should be counted but \ the type lives in layout"] - pub ptr: NonZero<*mut RefCell<PartialStyleAndLayoutData>> + pub ptr: NonZero<*mut AtomicRefCell<PartialPersistentLayoutData>> } #[allow(unsafe_code)] diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index bd0f2068271..c02d76a2f4e 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -5,7 +5,6 @@ use HTMLCanvasData; use LayoutNodeType; use OpaqueStyleAndLayoutData; -use PartialStyleAndLayoutData; use gfx_traits::{ByteIndex, LayerId, LayerType}; use msg::constellation_msg::PipelineId; use range::Range; @@ -13,12 +12,13 @@ use restyle_damage::RestyleDamage; use std::fmt::Debug; use std::sync::Arc; 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::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TNode}; use style::dom::OpaqueNode; use style::properties::ServoComputedValues; -use style::refcell::RefCell; use style::selector_impl::{PseudoElement, PseudoElementCascadeType, ServoSelectorImpl}; use url::Url; @@ -76,7 +76,7 @@ pub trait LayoutNode: TNode { /// Returns the type ID of this node. fn type_id(&self) -> LayoutNodeType; - fn get_style_data(&self) -> Option<&RefCell<PartialStyleAndLayoutData>>; + fn get_style_data(&self) -> Option<&AtomicRefCell<PersistentStyleData>>; fn init_style_and_layout_data(&self, data: OpaqueStyleAndLayoutData); fn get_style_and_layout_data(&self) -> Option<OpaqueStyleAndLayoutData>; @@ -183,7 +183,6 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized { if self.get_style_data() .unwrap() .borrow() - .style_data .per_pseudo .contains_key(&PseudoElement::Before) { Some(self.with_pseudo(PseudoElementType::Before(None))) @@ -197,7 +196,6 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized { if self.get_style_data() .unwrap() .borrow() - .style_data .per_pseudo .contains_key(&PseudoElement::After) { Some(self.with_pseudo(PseudoElementType::After(None))) @@ -244,7 +242,7 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized { match self.get_pseudo_element_type() { PseudoElementType::Normal => { self.get_style_data().unwrap().borrow() - .style_data.style.as_ref().unwrap().clone() + .style.as_ref().unwrap().clone() }, other => { // Precompute non-eagerly-cascaded pseudo-element styles if not @@ -257,14 +255,13 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized { if !self.get_style_data() .unwrap() .borrow() - .style_data .per_pseudo.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_data.style.as_ref()); - data.style_data.per_pseudo + data.style.as_ref()); + data.per_pseudo .insert(style_pseudo.clone(), new_style.unwrap()); } } @@ -273,7 +270,6 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized { if !self.get_style_data() .unwrap() .borrow() - .style_data .per_pseudo.contains_key(&style_pseudo) { let mut data = self.get_style_data().unwrap().borrow_mut(); let new_style = @@ -281,15 +277,15 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized { .lazily_compute_pseudo_element_style( &self.as_element(), &style_pseudo, - data.style_data.style.as_ref().unwrap()); - data.style_data.per_pseudo + data.style.as_ref().unwrap()); + data.per_pseudo .insert(style_pseudo.clone(), new_style.unwrap()); } } } self.get_style_data().unwrap().borrow() - .style_data.per_pseudo.get(&style_pseudo) + .per_pseudo.get(&style_pseudo) .unwrap().clone() } } @@ -307,18 +303,18 @@ 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_data.style.as_ref().unwrap().clone(), + => data.style.as_ref().unwrap().clone(), other - => data.style_data.per_pseudo.get(&other.style_pseudo_element()).unwrap().clone(), + => data.per_pseudo.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.style_data.per_pseudo + data.per_pseudo .get(&PseudoElement::Selection) - .unwrap_or(data.style_data.style.as_ref().unwrap()).clone() + .unwrap_or(data.style.as_ref().unwrap()).clone() } /// Removes the style from this node. @@ -329,10 +325,10 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized { match self.get_pseudo_element_type() { PseudoElementType::Normal => { - data.style_data.style = None; + data.style = None; } other => { - data.style_data.per_pseudo.remove(&other.style_pseudo_element()); + data.per_pseudo.remove(&other.style_pseudo_element()); } }; } @@ -387,7 +383,7 @@ pub trait ThreadSafeLayoutNode: Clone + Copy + NodeInfo + PartialEq + Sized { LayerId::new_of_type(LayerType::OverflowScroll, self.opaque().id() as usize) } - fn get_style_data(&self) -> Option<&RefCell<PartialStyleAndLayoutData>>; + fn get_style_data(&self) -> Option<&AtomicRefCell<PersistentStyleData>>; } // This trait is only public so that it can be implemented by the gecko wrapper. |