Use Ref::map to make ThreadSafeLayoutNode::style safe.

This commit is contained in:
Ms2ger 2015-07-17 14:30:33 +02:00
parent bb444df679
commit 46b36242a3
3 changed files with 10 additions and 11 deletions

View file

@ -667,7 +667,7 @@ impl<'a> FlowConstructor<'a> {
self.create_fragments_for_node_text_content(&mut initial_fragments, self.create_fragments_for_node_text_content(&mut initial_fragments,
node, node,
node.style()); &*node.style());
} }
self.build_flow_for_block_starting_with_fragments(flow, node, initial_fragments) self.build_flow_for_block_starting_with_fragments(flow, node, initial_fragments)

View file

@ -7,16 +7,17 @@
use data::LayoutDataWrapper; use data::LayoutDataWrapper;
use wrapper::{PseudoElementType, ThreadSafeLayoutNode}; use wrapper::{PseudoElementType, ThreadSafeLayoutNode};
use std::mem;
use style::properties::ComputedValues; use style::properties::ComputedValues;
use std::cell::Ref;
use std::sync::Arc; use std::sync::Arc;
/// Node mixin providing `style` method that returns a `NodeStyle` /// Node mixin providing `style` method that returns a `NodeStyle`
pub trait StyledNode { pub trait StyledNode {
fn get_style<'a>(&'a self, layout_data_ref: &'a LayoutDataWrapper) -> &'a Arc<ComputedValues>; fn get_style<'a>(&self, layout_data_ref: &'a LayoutDataWrapper) -> &'a Arc<ComputedValues>;
/// Returns the style results for the given node. If CSS selector matching has not yet been /// Returns the style results for the given node. If CSS selector matching has not yet been
/// performed, fails. /// performed, fails.
fn style<'a>(&'a self) -> &'a Arc<ComputedValues>; fn style<'a>(&'a self) -> Ref<'a, Arc<ComputedValues>>;
/// Does this node have a computed style yet? /// Does this node have a computed style yet?
fn has_style(&self) -> bool; fn has_style(&self) -> bool;
/// Removes the style from this node. /// Removes the style from this node.
@ -34,14 +35,11 @@ impl<'ln> StyledNode for ThreadSafeLayoutNode<'ln> {
} }
#[inline] #[inline]
#[allow(unsafe_code)] fn style<'a>(&'a self) -> Ref<'a, Arc<ComputedValues>> {
fn style<'a>(&'a self) -> &'a Arc<ComputedValues> { Ref::map(self.borrow_layout_data(), |layout_data_ref| {
unsafe {
let layout_data_ref = self.borrow_layout_data();
let layout_data = layout_data_ref.as_ref().expect("no layout data"); let layout_data = layout_data_ref.as_ref().expect("no layout data");
mem::transmute::<&Arc<ComputedValues>, self.get_style(layout_data)
&'a Arc<ComputedValues>>(self.get_style(&layout_data)) })
}
} }
fn has_style(&self) -> bool { fn has_style(&self) -> bool {

View file

@ -5,6 +5,7 @@
#![feature(append)] #![feature(append)]
#![feature(arc_unique)] #![feature(arc_unique)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(cell_extras)]
#![feature(custom_derive)] #![feature(custom_derive)]
#![feature(filling_drop)] #![feature(filling_drop)]
#![feature(hashmap_hasher)] #![feature(hashmap_hasher)]