зеркало из https://github.com/mozilla/pjs.git
Bug 656218, document.activeElement should not throw, r=bz
This commit is contained in:
Родитель
28f3944002
Коммит
fad6d66d9c
content/base
|
@ -2719,28 +2719,16 @@ nsDocument::GetActiveElement(nsIDOMElement **aElement)
|
|||
|
||||
// Get the focused element.
|
||||
nsCOMPtr<nsPIDOMWindow> window = GetWindow();
|
||||
if (!window) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
||||
if (!fm)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> focusedWindow;
|
||||
nsIContent* focusedContent =
|
||||
nsFocusManager::GetFocusedDescendant(window, PR_FALSE, getter_AddRefs(focusedWindow));
|
||||
|
||||
// an element in this document is focused, so return it
|
||||
if (focusedContent) {
|
||||
if (window) {
|
||||
nsCOMPtr<nsPIDOMWindow> focusedWindow;
|
||||
nsIContent* focusedContent =
|
||||
nsFocusManager::GetFocusedDescendant(window, PR_FALSE,
|
||||
getter_AddRefs(focusedWindow));
|
||||
// be safe and make sure the element is from this document
|
||||
if (focusedContent->GetOwnerDoc() != this) {
|
||||
NS_WARNING("Focused element found from another document");
|
||||
return NS_ERROR_FAILURE;
|
||||
if (focusedContent && focusedContent->GetOwnerDoc() == this) {
|
||||
CallQueryInterface(focusedContent, aElement);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
CallQueryInterface(focusedContent, aElement);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// No focused element anywhere in this document. Try to get the BODY.
|
||||
|
|
|
@ -480,6 +480,7 @@ _TEST_FILES2 = \
|
|||
test_bug638112.html \
|
||||
bug638112-response.txt \
|
||||
bug638112.sjs \
|
||||
test_bug656283.html \
|
||||
$(NULL)
|
||||
|
||||
# This test fails on the Mac for some reason
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=656283
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 656283</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body onload="test()">
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=656283">Mozilla Bug 656283</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 656283 **/
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var ifr;
|
||||
function test() {
|
||||
// First a test with data documents.
|
||||
var d = document.implementation.createHTMLDocument("");
|
||||
is(d.activeElement, d.body, "Active element should be body by default! (1)");
|
||||
|
||||
|
||||
ifr = document.getElementById("ifr");
|
||||
ifr.onload = test2;
|
||||
ifr.src = "data:text/html,1";
|
||||
}
|
||||
|
||||
var firstDoc;
|
||||
function test2() {
|
||||
firstDoc = ifr.contentDocument;
|
||||
is(firstDoc.activeElement, firstDoc.body,
|
||||
"Active element should be body by default! (2)");
|
||||
ifr.onload = test3;
|
||||
ifr.src = "data:text/html,<input>";
|
||||
}
|
||||
|
||||
function test3() {
|
||||
ifr.contentDocument.getElementsByTagName("input")[0].focus();
|
||||
is(firstDoc.activeElement, firstDoc.body,
|
||||
"Active element should be body by default! (3)");
|
||||
ifr.parentNode.removeChild(ifr);
|
||||
is(firstDoc.activeElement, firstDoc.body,
|
||||
"Active element should be body by default! (4)");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
<iframe id="ifr"></irame>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче