aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2016-08-31 01:06:45 +0200
committerSimon Sapin <simon.sapin@exyr.org>2016-08-31 02:34:07 +0200
commitacc38aa8c2c35e27038d20d1de48e32c6503082a (patch)
treed366a5620bdcbb1b9922a54d15cc597cfe01c846 /components/script
parentc50e6add4ac975c91d19bf35155c846bc5921aac (diff)
downloadservo-acc38aa8c2c35e27038d20d1de48e32c6503082a.tar.gz
servo-acc38aa8c2c35e27038d20d1de48e32c6503082a.zip
Use Arc<PropertyDeclarationBlock> everwhere it’s appropriate.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/cssstyledeclaration.rs3
-rw-r--r--components/script/dom/element.rs27
-rw-r--r--components/script/layout_wrapper.rs4
3 files changed, 22 insertions, 12 deletions
diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs
index ae62ebb483e..e36652c446a 100644
--- a/components/script/dom/cssstyledeclaration.rs
+++ b/components/script/dom/cssstyledeclaration.rs
@@ -15,6 +15,7 @@ use dom::node::{Node, NodeDamage, window_from_node};
use dom::window::Window;
use std::ascii::AsciiExt;
use std::slice;
+use std::sync::Arc;
use string_cache::Atom;
use style::parser::ParserContextExtraData;
use style::properties::{PropertyDeclaration, Shorthand, Importance};
@@ -367,7 +368,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
*element.style_attribute().borrow_mut() = if decl_block.declarations.is_empty() {
None // Step 2
} else {
- Some(decl_block)
+ Some(Arc::new(decl_block))
};
element.sync_property_with_attrs_style();
let node = element.upcast::<Node>();
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 01fb45e9eae..a38367f23cc 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -109,7 +109,7 @@ pub struct Element {
prefix: Option<DOMString>,
attrs: DOMRefCell<Vec<JS<Attr>>>,
id_attribute: DOMRefCell<Option<Atom>>,
- style_attribute: DOMRefCell<Option<PropertyDeclarationBlock>>,
+ style_attribute: DOMRefCell<Option<Arc<PropertyDeclarationBlock>>>,
attr_list: MutNullableHeap<JS<NamedNodeMap>>,
class_list: MutNullableHeap<JS<DOMTokenList>>,
state: Cell<ElementState>,
@@ -297,7 +297,7 @@ pub trait LayoutElementHelpers {
#[allow(unsafe_code)]
unsafe fn html_element_in_html_document_for_layout(&self) -> bool;
fn id_attribute(&self) -> *const Option<Atom>;
- fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock>;
+ fn style_attribute(&self) -> *const Option<Arc<PropertyDeclarationBlock>>;
fn local_name(&self) -> &Atom;
fn namespace(&self) -> &Namespace;
fn get_checked_state_for_layout(&self) -> bool;
@@ -329,7 +329,10 @@ impl LayoutElementHelpers for LayoutJS<Element> {
#[inline]
fn from_declaration(rule: PropertyDeclaration) -> DeclarationBlock {
DeclarationBlock::from_declarations(
- Arc::new(vec![(rule, Importance::Normal)]),
+ Arc::new(PropertyDeclarationBlock {
+ declarations: Arc::new(vec![(rule, Importance::Normal)]),
+ important_count: 0,
+ }),
Importance::Normal)
}
@@ -615,7 +618,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
}
#[allow(unsafe_code)]
- fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock> {
+ fn style_attribute(&self) -> *const Option<Arc<PropertyDeclarationBlock>> {
unsafe {
(*self.unsafe_get()).style_attribute.borrow_for_layout()
}
@@ -704,7 +707,7 @@ impl Element {
self.attrs.borrow()
}
- pub fn style_attribute(&self) -> &DOMRefCell<Option<PropertyDeclarationBlock>> {
+ pub fn style_attribute(&self) -> &DOMRefCell<Option<Arc<PropertyDeclarationBlock>>> {
&self.style_attribute
}
@@ -774,6 +777,7 @@ impl Element {
matching
});
if let Some(index) = index {
+ let declarations = Arc::make_mut(declarations);
Arc::make_mut(&mut declarations.declarations).remove(index);
if importance.unwrap().important() {
declarations.important_count -= 1;
@@ -796,6 +800,7 @@ impl Element {
{
// Usually, the reference count will be 1 here. But transitions could make it greater
// than that.
+ let declaration_block = Arc::make_mut(declaration_block);
let existing_declarations = Arc::make_mut(&mut declaration_block.declarations);
'outer: for incoming_declaration in declarations {
@@ -829,10 +834,10 @@ impl Element {
0
};
- *inline_declarations = Some(PropertyDeclarationBlock {
+ *inline_declarations = Some(Arc::new(PropertyDeclarationBlock {
declarations: Arc::new(declarations.into_iter().map(|d| (d, importance)).collect()),
important_count: important_count,
- });
+ }));
}
update(self, declarations, importance);
@@ -847,6 +852,7 @@ impl Element {
if let &mut Some(ref mut block) = &mut *inline_declarations {
// Usually, the reference counts of `from` and `to` will be 1 here. But transitions
// could make them greater than that.
+ let block = Arc::make_mut(block);
let declarations = Arc::make_mut(&mut block.declarations);
for &mut (ref declaration, ref mut importance) in declarations {
if properties.iter().any(|p| declaration.name() == **p) {
@@ -2102,8 +2108,11 @@ impl VirtualMethods for Element {
*self.style_attribute.borrow_mut() =
mutation.new_value(attr).map(|value| {
let win = window_from_node(self);
- parse_style_attribute(&value, &doc.base_url(), win.css_error_reporter(),
- ParserContextExtraData::default())
+ Arc::new(parse_style_attribute(
+ &value,
+ &doc.base_url(),
+ win.css_error_reporter(),
+ ParserContextExtraData::default()))
});
if node.is_in_doc() {
node.dirty(NodeDamage::NodeStyleDamaged);
diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs
index 906bde60550..2b6c8080f06 100644
--- a/components/script/layout_wrapper.rs
+++ b/components/script/layout_wrapper.rs
@@ -451,9 +451,9 @@ impl<'le> TElement for ServoLayoutElement<'le> {
ServoLayoutNode::from_layout_js(self.element.upcast())
}
- fn style_attribute(&self) -> &Option<PropertyDeclarationBlock> {
+ fn style_attribute(&self) -> Option<&Arc<PropertyDeclarationBlock>> {
unsafe {
- &*self.element.style_attribute()
+ (*self.element.style_attribute()).as_ref()
}
}