Bug 886308. Implement Element.matches. r=heycam

This commit is contained in:
Boris Zbarsky 2014-08-01 23:37:09 -04:00
parent 2595aca124
commit 0023ed4d23
5 changed files with 39 additions and 3 deletions

View File

@ -645,6 +645,8 @@ public:
}
bool HasAttributeNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName) const;
bool Matches(const nsAString& aSelector,
ErrorResult& aError);
already_AddRefed<nsIHTMLCollection>
GetElementsByTagName(const nsAString& aQualifiedName);
already_AddRefed<nsIHTMLCollection>
@ -654,7 +656,10 @@ public:
already_AddRefed<nsIHTMLCollection>
GetElementsByClassName(const nsAString& aClassNames);
bool MozMatchesSelector(const nsAString& aSelector,
ErrorResult& aError);
ErrorResult& aError)
{
return Matches(aSelector, aError);
}
void SetPointerCapture(int32_t aPointerId, ErrorResult& aError)
{
bool activeState = false;

View File

@ -2736,8 +2736,7 @@ Element::SetTokenList(nsIAtom* aAtom, nsIVariant* aValue)
}
bool
Element::MozMatchesSelector(const nsAString& aSelector,
ErrorResult& aError)
Element::Matches(const nsAString& aSelector, ErrorResult& aError)
{
nsCSSSelectorList* selectorList = ParseSelectorList(aSelector, aError);
if (!selectorList) {

View File

@ -651,3 +651,4 @@ support-files = file_bug503473-frame.sjs
skip-if = buildapp == 'b2g' || e10s
support-files = file_bug1011748_redirect.sjs file_bug1011748_OK.sjs
[test_bug1025933.html]
[test_element.matches.html]

View File

@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=886308
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 886308</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
/** Test for Bug 886308 **/
ok(document.head.matches("head"), "head should match 'head'");
ok(document.querySelector("link").matches("html *"), "link is a descendant of 'html'");
</script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=886308">Mozilla Bug 886308</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>

View File

@ -52,6 +52,9 @@ interface Element : Node {
[Pure]
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
[Throws, Pure]
boolean matches(DOMString selector);
[Pure]
HTMLCollection getElementsByTagName(DOMString localName);
[Throws, Pure]