mirror of
https://github.com/servo/servo.git
synced 2025-07-18 12:53:40 +01:00
Remove unnecessary rooting from CSSStyleDeclaration
This commit will replace calls to `self.owner.root()` with `self.owner` to avoid unnecessary rooting of JS elements objects. Ref.- Issue: #8126
This commit is contained in:
parent
2de5407cda
commit
fe2401c566
1 changed files with 10 additions and 20 deletions
|
@ -74,23 +74,21 @@ impl CSSStyleDeclaration {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_computed_style(&self, property: &Atom) -> Option<DOMString> {
|
fn get_computed_style(&self, property: &Atom) -> Option<DOMString> {
|
||||||
let owner = self.owner.root();
|
let node = self.owner.upcast::<Node>();
|
||||||
let node = owner.upcast::<Node>();
|
|
||||||
if !node.is_in_doc() {
|
if !node.is_in_doc() {
|
||||||
// TODO: Node should be matched against the style rules of this window.
|
// TODO: Node should be matched against the style rules of this window.
|
||||||
// Firefox is currently the only browser to implement this.
|
// Firefox is currently the only browser to implement this.
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let addr = node.to_trusted_node_address();
|
let addr = node.to_trusted_node_address();
|
||||||
window_from_node(owner.r()).resolved_style_query(addr, self.pseudo.clone(), property)
|
window_from_node(&*self.owner).resolved_style_query(addr, self.pseudo.clone(), property)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-length
|
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-length
|
||||||
fn Length(&self) -> u32 {
|
fn Length(&self) -> u32 {
|
||||||
let owner = self.owner.root();
|
let elem = self.owner.upcast::<Element>();
|
||||||
let elem = owner.upcast::<Element>();
|
|
||||||
let len = match *elem.style_attribute().borrow() {
|
let len = match *elem.style_attribute().borrow() {
|
||||||
Some(ref declarations) => declarations.normal.len() + declarations.important.len(),
|
Some(ref declarations) => declarations.normal.len() + declarations.important.len(),
|
||||||
None => 0
|
None => 0
|
||||||
|
@ -101,8 +99,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-item
|
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-item
|
||||||
fn Item(&self, index: u32) -> DOMString {
|
fn Item(&self, index: u32) -> DOMString {
|
||||||
let index = index as usize;
|
let index = index as usize;
|
||||||
let owner = self.owner.root();
|
let elem = self.owner.upcast::<Element>();
|
||||||
let elem = owner.upcast::<Element>();
|
|
||||||
let style_attribute = elem.style_attribute().borrow();
|
let style_attribute = elem.style_attribute().borrow();
|
||||||
let result = style_attribute.as_ref().and_then(|declarations| {
|
let result = style_attribute.as_ref().and_then(|declarations| {
|
||||||
if index > declarations.normal.len() {
|
if index > declarations.normal.len() {
|
||||||
|
@ -121,7 +118,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
|
|
||||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
|
||||||
fn GetPropertyValue(&self, mut property: DOMString) -> DOMString {
|
fn GetPropertyValue(&self, mut property: DOMString) -> DOMString {
|
||||||
let owner = self.owner.root();
|
let owner = &self.owner;
|
||||||
|
|
||||||
// Step 1
|
// Step 1
|
||||||
property.make_ascii_lowercase();
|
property.make_ascii_lowercase();
|
||||||
|
@ -155,7 +152,6 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3 & 4
|
// Step 3 & 4
|
||||||
// FIXME: redundant let binding https://github.com/rust-lang/rust/issues/22252
|
|
||||||
let result = match owner.get_inline_style_declaration(&property) {
|
let result = match owner.get_inline_style_declaration(&property) {
|
||||||
Some(declaration) => declaration.value(),
|
Some(declaration) => declaration.value(),
|
||||||
None => "".to_owned(),
|
None => "".to_owned(),
|
||||||
|
@ -181,9 +177,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
}
|
}
|
||||||
// Step 3
|
// Step 3
|
||||||
} else {
|
} else {
|
||||||
// FIXME: extra let binding https://github.com/rust-lang/rust/issues/22323
|
if self.owner.get_important_inline_style_declaration(&property).is_some() {
|
||||||
let owner = self.owner.root();
|
|
||||||
if owner.get_important_inline_style_declaration(&property).is_some() {
|
|
||||||
return "important".to_owned();
|
return "important".to_owned();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,8 +215,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 6
|
// Step 6
|
||||||
let owner = self.owner.root();
|
let window = window_from_node(&*self.owner);
|
||||||
let window = window_from_node(owner.r());
|
|
||||||
let declarations = parse_one_declaration(&property, &value, &window.r().get_url());
|
let declarations = parse_one_declaration(&property, &value, &window.r().get_url());
|
||||||
|
|
||||||
// Step 7
|
// Step 7
|
||||||
|
@ -232,8 +225,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
let owner = self.owner.root();
|
let element = self.owner.upcast::<Element>();
|
||||||
let element = owner.upcast::<Element>();
|
|
||||||
|
|
||||||
// Step 8
|
// Step 8
|
||||||
for decl in declarations {
|
for decl in declarations {
|
||||||
|
@ -266,8 +258,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
_ => return Ok(()),
|
_ => return Ok(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let owner = self.owner.root();
|
let element = self.owner.upcast::<Element>();
|
||||||
let element = owner.upcast::<Element>();
|
|
||||||
|
|
||||||
// Step 5 & 6
|
// Step 5 & 6
|
||||||
match longhands_from_shorthand(&property) {
|
match longhands_from_shorthand(&property) {
|
||||||
|
@ -299,8 +290,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
// Step 3
|
// Step 3
|
||||||
let value = self.GetPropertyValue(property.clone());
|
let value = self.GetPropertyValue(property.clone());
|
||||||
|
|
||||||
let owner = self.owner.root();
|
let elem = self.owner.upcast::<Element>();
|
||||||
let elem = owner.upcast::<Element>();
|
|
||||||
|
|
||||||
match longhands_from_shorthand(&property) {
|
match longhands_from_shorthand(&property) {
|
||||||
// Step 4
|
// Step 4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue