Commit 833286f4 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

mshtml: Implement querySelector for document fragments.

parent 80d629ac
......@@ -4720,8 +4720,18 @@ static HRESULT WINAPI DocumentSelector_querySelector(IDocumentSelector *iface, B
TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
nsAString_InitDepend(&nsstr, v);
nsres = nsIDOMDocument_QuerySelector(This->dom_document, &nsstr, &nselem);
if(This->dom_document)
nsres = nsIDOMDocument_QuerySelector(This->dom_document, &nsstr, &nselem);
else {
nsIDOMDocumentFragment *frag;
nsres = nsIDOMNode_QueryInterface(This->node.nsnode, &IID_nsIDOMDocumentFragment, (void**)&frag);
if(NS_SUCCEEDED(nsres)) {
nsres = nsIDOMDocumentFragment_QuerySelector(frag, &nsstr, &nselem);
nsIDOMDocumentFragment_Release(frag);
}
}
nsAString_Finish(&nsstr);
if(NS_FAILED(nsres)) {
WARN("QuerySelector failed: %08lx\n", nsres);
return map_nsresult(nsres);
......
......@@ -244,10 +244,20 @@ sync_test("query_selector", function() {
+ '</div>'
+ '<script class="class1"></script>';
var e = document.querySelector("nomatch");
var frag = document.createDocumentFragment()
var e = document.createElement("div");
e.innerHTML = '<div class="class3"></div><a id="class3" class="class4"></a></div>';
frag.appendChild(e);
var e = document.createElement("script");
e.className = "class3";
frag.appendChild(e);
e = document.querySelector("nomatch");
ok(e === null, "e = " + e);
e = document.body.querySelector("nomatch");
ok(e === null, "e = " + e);
e = frag.querySelector("nomatch");
ok(e === null, "e = " + e);
e = document.querySelector(".class1");
ok(e.tagName === "DIV", "e.tagName = " + e.tagName);
......@@ -255,11 +265,26 @@ sync_test("query_selector", function() {
ok(e.tagName === "DIV", "e.tagName = " + e.tagName);
ok(e.msMatchesSelector(".class1") === true, "msMatchesSelector returned " + e.msMatchesSelector(".class1"));
ok(e.msMatchesSelector(".class2") === false, "msMatchesSelector returned " + e.msMatchesSelector(".class2"));
e = document.querySelector(".class3");
ok(e === null, "e = " + e);
e = document.body.querySelector(".class3");
ok(e === null, "e = " + e);
e = frag.querySelector(".class3");
ok(e.tagName === "DIV", "e.tagName = " + e.tagName);
e = frag.querySelector(".class4");
ok(e.tagName === "A", "e.tagName = " + e.tagName);
e = frag.querySelector(".class1");
ok(e === null, "e = " + e);
e = frag.querySelector(".class2");
ok(e === null, "e = " + e);
e = document.querySelector("a");
ok(e.tagName === "A", "e.tagName = " + e.tagName);
e = document.body.querySelector("a");
ok(e.tagName === "A", "e.tagName = " + e.tagName);
e = frag.querySelector("a");
ok(e.tagName === "A", "e.tagName = " + e.tagName);
});
sync_test("compare_position", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment