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]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[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
|
// cast to point to T in RefCell<T> directly
|
||||||
let attrs = elem.attrs.borrow_for_layout();
|
let attrs = elem.attrs.borrow_for_layout();
|
||||||
attrs.iter().find(|attr: & &JS<Attr>| {
|
attrs.iter().find(|attr: & &JS<Attr>| {
|
||||||
let attr = attr.to_layout().unsafe_get();
|
let attr = attr.to_layout().unsafe_get();
|
||||||
*name == (*attr).local_name_atom_forever() &&
|
*name == (*attr).local_name_atom_forever() &&
|
||||||
(*attr).namespace() == namespace
|
(*attr).namespace() == namespace
|
||||||
})
|
}).map(|attr| attr.to_layout())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[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)
|
unsafe fn get_attr_val_for_layout<'a>(&'a self, namespace: &Namespace, name: &Atom)
|
||||||
-> Option<&'a str> {
|
-> Option<&'a str> {
|
||||||
get_attr_for_layout(self, namespace, name).map(|attr| {
|
get_attr_for_layout(self, namespace, name).map(|attr| {
|
||||||
let attr = attr.to_layout().unsafe_get();
|
(*attr.unsafe_get()).value_ref_forever()
|
||||||
(*attr).value_ref_forever()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,40 +207,22 @@ impl RawLayoutElementHelpers for Element {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &Atom)
|
unsafe fn get_attr_atom_for_layout(&self, namespace: &Namespace, name: &Atom)
|
||||||
-> Option<Atom> {
|
-> Option<Atom> {
|
||||||
let attrs = self.attrs.borrow_for_layout();
|
get_attr_for_layout(self, namespace, name).and_then(|attr| {
|
||||||
(*attrs).iter().find(|attr: & &JS<Attr>| {
|
(*attr.unsafe_get()).value_atom_forever()
|
||||||
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()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn has_class_for_layout(&self, name: &Atom) -> bool {
|
unsafe fn has_class_for_layout(&self, name: &Atom) -> bool {
|
||||||
let attrs = self.attrs.borrow_for_layout();
|
get_attr_for_layout(self, &ns!(""), &atom!("class")).map_or(false, |attr| {
|
||||||
(*attrs).iter().find(|attr: & &JS<Attr>| {
|
(*attr.unsafe_get()).value_tokens_forever().unwrap().iter().any(|atom| atom == name)
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn get_classes_for_layout(&self) -> Option<&'static [Atom]> {
|
unsafe fn get_classes_for_layout(&self) -> Option<&'static [Atom]> {
|
||||||
let attrs = self.attrs.borrow_for_layout();
|
get_attr_for_layout(self, &ns!(""), &atom!("class")).map(|attr| {
|
||||||
(*attrs).iter().find(|attr: & &JS<Attr>| {
|
(*attr.unsafe_get()).value_tokens_forever().unwrap()
|
||||||
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()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,20 @@
|
||||||
"local_changes": {
|
"local_changes": {
|
||||||
"deleted": [],
|
"deleted": [],
|
||||||
"items": {
|
"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": {
|
"testharness": {
|
||||||
"mozilla/DOMParser.html": [
|
"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": {},
|
"reftest_nodes": {},
|
||||||
"rev": null,
|
"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