mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Auto merge of #5741 - Ms2ger:attr-for-layout, r=jdm
<!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5741) <!-- Reviewable:end -->
This commit is contained in:
commit
e5ec55f0d8
4 changed files with 59 additions and 30 deletions
|
@ -171,14 +171,14 @@ pub trait RawLayoutElementHelpers {
|
|||
|
||||
#[inline]
|
||||
#[allow(unsafe_code)]
|
||||
unsafe fn get_attr_for_layout<'a>(elem: &'a Element, namespace: &Namespace, name: &Atom) -> Option<&'a JS<Attr>> {
|
||||
unsafe fn get_attr_for_layout(elem: &Element, namespace: &Namespace, name: &Atom) -> Option<LayoutJS<Attr>> {
|
||||
// cast to point to T in RefCell<T> directly
|
||||
let attrs = elem.attrs.borrow_for_layout();
|
||||
attrs.iter().find(|attr: & &JS<Attr>| {
|
||||
let attr = attr.to_layout().unsafe_get();
|
||||
*name == (*attr).local_name_atom_forever() &&
|
||||
(*attr).namespace() == namespace
|
||||
})
|
||||
}).map(|attr| attr.to_layout())
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -187,8 +187,7 @@ impl RawLayoutElementHelpers for Element {
|
|||
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
||||
-> Option<&'a str> {
|
||||
get_attr_for_layout(self, namespace, name).map(|attr| {
|
||||
let attr = attr.to_layout().unsafe_get();
|
||||
(*attr).value_ref_forever()
|
||||
(*attr.unsafe_get()).value_ref_forever()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -208,40 +207,22 @@ impl RawLayoutElementHelpers for Element {
|
|||
#[inline]
|
||||
unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &Atom)
|
||||
-> Option<Atom> {
|
||||
let attrs = self.attrs.borrow_for_layout();
|
||||
(*attrs).iter().find(|attr: & &JS<Attr>| {
|
||||
let attr = attr.to_layout().unsafe_get();
|
||||
*name == (*attr).local_name_atom_forever() &&
|
||||
(*attr).namespace() == namespace
|
||||
}).and_then(|attr| {
|
||||
let attr = attr.to_layout().unsafe_get();
|
||||
(*attr).value_atom_forever()
|
||||
get_attr_for_layout(self, namespace, name).and_then(|attr| {
|
||||
(*attr.unsafe_get()).value_atom_forever()
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn has_class_for_layout(&self, name: &Atom) -> bool {
|
||||
let attrs = self.attrs.borrow_for_layout();
|
||||
(*attrs).iter().find(|attr: & &JS<Attr>| {
|
||||
let attr = attr.to_layout().unsafe_get();
|
||||
(*attr).local_name_atom_forever() == atom!("class")
|
||||
}).map_or(false, |attr| {
|
||||
let attr = attr.to_layout().unsafe_get();
|
||||
(*attr).value_tokens_forever().map(|tokens| {
|
||||
tokens.iter().any(|atom| atom == name)
|
||||
})
|
||||
}.take().unwrap())
|
||||
get_attr_for_layout(self, &ns!(""), &atom!("class")).map_or(false, |attr| {
|
||||
(*attr.unsafe_get()).value_tokens_forever().unwrap().iter().any(|atom| atom == name)
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn get_classes_for_layout(&self) -> Option<&'static [Atom]> {
|
||||
let attrs = self.attrs.borrow_for_layout();
|
||||
(*attrs).iter().find(|attr: & &JS<Attr>| {
|
||||
let attr = attr.to_layout().unsafe_get();
|
||||
(*attr).local_name_atom_forever() == atom!("class")
|
||||
}).and_then(|attr| {
|
||||
let attr = attr.to_layout().unsafe_get();
|
||||
(*attr).value_tokens_forever()
|
||||
get_attr_for_layout(self, &ns!(""), &atom!("class")).map(|attr| {
|
||||
(*attr.unsafe_get()).value_tokens_forever().unwrap()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,20 @@
|
|||
"local_changes": {
|
||||
"deleted": [],
|
||||
"items": {
|
||||
"reftest": {
|
||||
"css/class-namespaces.html": [
|
||||
{
|
||||
"path": "css/class-namespaces.html",
|
||||
"references": [
|
||||
[
|
||||
"/_mozilla/css/class-namespaces-ref.html",
|
||||
"=="
|
||||
]
|
||||
],
|
||||
"url": "/_mozilla/css/class-namespaces.html"
|
||||
}
|
||||
]
|
||||
},
|
||||
"testharness": {
|
||||
"mozilla/DOMParser.html": [
|
||||
{
|
||||
|
@ -515,7 +529,20 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"reftest_nodes": {}
|
||||
"reftest_nodes": {
|
||||
"css/class-namespaces.html": [
|
||||
{
|
||||
"path": "css/class-namespaces.html",
|
||||
"references": [
|
||||
[
|
||||
"/_mozilla/css/class-namespaces-ref.html",
|
||||
"=="
|
||||
]
|
||||
],
|
||||
"url": "/_mozilla/css/class-namespaces.html"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"reftest_nodes": {},
|
||||
"rev": null,
|
||||
|
|
5
tests/wpt/mozilla/tests/css/class-namespaces-ref.html
Normal file
5
tests/wpt/mozilla/tests/css/class-namespaces-ref.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
<style>
|
||||
p { background: green; }
|
||||
</style>
|
||||
<body>
|
||||
<p>AAA</p><p>BBB</p>
|
16
tests/wpt/mozilla/tests/css/class-namespaces.html
Normal file
16
tests/wpt/mozilla/tests/css/class-namespaces.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
<link rel=match href=class-namespaces-ref.html>
|
||||
<style>
|
||||
.foo { background: green; }
|
||||
</style>
|
||||
<body>
|
||||
<script>
|
||||
var p = document.body.appendChild(document.createElement("p"));
|
||||
p.setAttributeNS("foo", "class", "bar");
|
||||
p.setAttributeNS("", "class", "foo");
|
||||
p.textContent = "AAA";
|
||||
|
||||
var p = document.body.appendChild(document.createElement("p"));
|
||||
p.setAttributeNS("", "class", "foo");
|
||||
p.setAttributeNS("foo", "class", "bar");
|
||||
p.textContent = "BBB";
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue