Upgrade rust-selectors, pass ':empty' tests

https://github.com/servo/rust-selectors/pull/36
This commit is contained in:
Corey Farwell 2015-07-13 09:10:50 +09:00
parent 406be7accf
commit b1b03a32db
10 changed files with 110 additions and 10 deletions

View file

@ -211,7 +211,9 @@ impl<'ln> LayoutNode<'ln> {
}
}
impl<'ln> ::selectors::Node<LayoutElement<'ln>> for LayoutNode<'ln> {
impl<'ln> ::selectors::Node for LayoutNode<'ln> {
type Element = LayoutElement<'ln>;
fn parent_node(&self) -> Option<LayoutNode<'ln>> {
unsafe {
self.node.parent_node_ref().map(|node| self.new_with_this_lifetime(&node))
@ -244,7 +246,7 @@ impl<'ln> ::selectors::Node<LayoutElement<'ln>> for LayoutNode<'ln> {
/// If this is an element, accesses the element data.
#[inline]
fn as_element(&self) -> Option<LayoutElement<'ln>> {
fn as_element(&self) -> Option<Self::Element> {
ElementCast::to_layout_js(&self.node).map(|element| {
LayoutElement {
element: element,
@ -259,6 +261,16 @@ impl<'ln> ::selectors::Node<LayoutElement<'ln>> for LayoutNode<'ln> {
_ => false
}
}
fn is_element_or_non_empty_text(&self) -> bool {
if let Some(text) = TextCast::to_layout_js(&self.node) {
unsafe {
!CharacterDataCast::from_layout_js(&text).data_for_layout().is_empty()
}
} else {
ElementCast::to_layout_js(&self.node).is_some()
}
}
}
impl<'ln> LayoutNode<'ln> {

View file

@ -2579,7 +2579,9 @@ impl<'a> VirtualMethods for &'a Node {
}
}
impl<'a> ::selectors::Node<&'a Element> for &'a Node {
impl<'a> ::selectors::Node for &'a Node {
type Element = &'a Element;
fn parent_node(&self) -> Option<&'a Node> {
(*self).parent_node.get()
.map(|node| node.root().get_unsound_ref_forever())
@ -2609,9 +2611,17 @@ impl<'a> ::selectors::Node<&'a Element> for &'a Node {
DocumentDerived::is_document(*self)
}
fn as_element(&self) -> Option<&'a Element> {
fn as_element(&self) -> Option<Self::Element> {
ElementCast::to_ref(*self)
}
fn is_element_or_non_empty_text(&self) -> bool {
if self.is_text() {
self.GetTextContent().map_or(false, |s| !s.is_empty())
} else {
self.is_element()
}
}
}
pub trait DisabledStateHelpers {

View file

@ -1192,7 +1192,7 @@ dependencies = [
[[package]]
name = "selectors"
version = "0.1.0"
source = "git+https://github.com/servo/rust-selectors#a16e32540845548d46857f2896248c382ef34393"
source = "git+https://github.com/servo/rust-selectors#a6cf1fba8f31960254aa62434ab8aeee13aff080"
dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",

2
ports/cef/Cargo.lock generated
View file

@ -1164,7 +1164,7 @@ dependencies = [
[[package]]
name = "selectors"
version = "0.1.0"
source = "git+https://github.com/servo/rust-selectors#a16e32540845548d46857f2896248c382ef34393"
source = "git+https://github.com/servo/rust-selectors#a6cf1fba8f31960254aa62434ab8aeee13aff080"
dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",

2
ports/gonk/Cargo.lock generated
View file

@ -1072,7 +1072,7 @@ dependencies = [
[[package]]
name = "selectors"
version = "0.1.0"
source = "git+https://github.com/servo/rust-selectors#a16e32540845548d46857f2896248c382ef34393"
source = "git+https://github.com/servo/rust-selectors#a6cf1fba8f31960254aa62434ab8aeee13aff080"
dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -1,8 +1,5 @@
[Element-closest.html]
type: testharness
[Element.closest with context node 'test10' and selector ':empty']
expected: FAIL
[Element.closest with context node 'test11' and selector ':invalid']
expected: FAIL

View file

@ -63,6 +63,18 @@
"url": "/_mozilla/css/absolute_hypothetical_float.html"
}
],
"css/empty_pseudo_selector.html": [
{
"path": "css/empty_pseudo_selector.html",
"references": [
[
"/_mozilla/css/empty_pseudo_selector_ref.html",
"=="
]
],
"url": "/_mozilla/css/empty_pseudo_selector.html"
}
],
"css/class-namespaces.html": [
{
"path": "css/class-namespaces.html",
@ -455,6 +467,12 @@
"url": "/_mozilla/mozilla/element_matches.html"
}
],
"mozilla/element_matches_empty.html": [
{
"path": "mozilla/element_matches_empty.html",
"url": "/_mozilla/mozilla/element_matches_empty.html"
}
],
"mozilla/empty_clientrect.html": [
{
"path": "mozilla/empty_clientrect.html",

View file

@ -0,0 +1,17 @@
<style>
div {
width: 100px;
height: 100px;
background-color: purple;
}
div:empty {
background-color: orange;
}
</style>
<body>
<div></div>
<div><!-- hello world --></div>
<div><span></span></div>
<div> </div>
<div>foo</div>

View file

@ -0,0 +1,20 @@
<style>
div {
width: 100px;
height: 100px;
}
.purple {
background-color: purple;
}
.orange {
background-color: orange;
}
</style>
<body>
<div class="orange"></div>
<div class="orange"></div>
<div class="purple"></div>
<div class="purple"></div>
<div class="purple">foo</div>

View file

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div class="empty"></div>
<div class="empty"><!-- hello world --></div>
<div><span></span></div>
<div> </div>
<div>foo</div>
<script>
test(function() {
var testCount = 0;
for (var elem of document.getElementsByTagName("div")) {
var actual = elem.matches(":empty");
var expected = elem.className === "empty";
var testName = "test-matches-empty-" + testCount;
assert_equals(actual, expected, testName);
}
});
</script>
</body>
</html>