Bug 460568 removeAttribute('contenteditable') doesn't work fine r+sr=peterv

This commit is contained in:
Masayuki Nakano 2008-10-26 01:21:56 +09:00
Родитель e5804e32d1
Коммит c917bc9fa1
3 изменённых файлов: 96 добавлений и 7 удалений

Просмотреть файл

@ -1178,13 +1178,17 @@ nsresult
nsGenericHTMLElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsGenericHTMLElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
PRBool aNotify) PRBool aNotify)
{ {
PRBool contentEditable = PR_FALSE;
PRInt32 contentEditableChange;
if (aNameSpaceID == kNameSpaceID_None) {
contentEditable = PR_TRUE;
contentEditableChange = GetContentEditableValue() == eTrue ? -1 : 0;
}
// Check for event handlers // Check for event handlers
if (aNameSpaceID == kNameSpaceID_None) { if (aNameSpaceID == kNameSpaceID_None) {
if (aAttribute == nsGkAtoms::contenteditable) { if (nsContentUtils::IsEventAttributeName(aAttribute, EventNameType_HTML)) {
ChangeEditableState(GetContentEditableValue() == eTrue ? -1 : 0);
}
else if (nsContentUtils::IsEventAttributeName(aAttribute,
EventNameType_HTML)) {
nsCOMPtr<nsIEventListenerManager> manager; nsCOMPtr<nsIEventListenerManager> manager;
GetListenerManager(PR_FALSE, getter_AddRefs(manager)); GetListenerManager(PR_FALSE, getter_AddRefs(manager));
@ -1194,8 +1198,15 @@ nsGenericHTMLElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
} }
} }
return nsGenericHTMLElementBase::UnsetAttr(aNameSpaceID, aAttribute, nsresult rv = nsGenericHTMLElementBase::UnsetAttr(aNameSpaceID, aAttribute,
aNotify); aNotify);
NS_ENSURE_SUCCESS(rv, rv);
if (contentEditable) {
ChangeEditableState(contentEditableChange);
}
return NS_OK;
} }
already_AddRefed<nsIURI> already_AddRefed<nsIURI>

Просмотреть файл

@ -122,6 +122,7 @@ _TEST_FILES = test_bug589.html \
test_bug441930.html \ test_bug441930.html \
test_bug442801.html \ test_bug442801.html \
test_bug448166.html \ test_bug448166.html \
test_bug460568.html \
$(NULL) $(NULL)
libs:: $(_TEST_FILES) libs:: $(_TEST_FILES)

Просмотреть файл

@ -0,0 +1,77 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=460568
-->
<head>
<title>Test for Bug 460568</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=460568">Mozilla Bug 460568</a>
<p id="display"><a href="" id="anchor">a[href]</a></p>
<div id="editor">
<a href="" id="anchorInEditor">a[href] in editor</a>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 460568 **/
function runTest()
{
var editor = document.getElementById("editor");
var anchor = document.getElementById("anchor");
var anchorInEditor = document.getElementById("anchorInEditor");
var focused;
anchorInEditor.onfocus = function() { focused = true; };
focused = false;
anchor.focus();
editor.setAttribute("contenteditable", "true");
anchorInEditor.focus();
is(focused, false, "focus moved to element in contenteditable=true");
focused = false;
anchor.focus();
editor.setAttribute("contenteditable", "false");
anchorInEditor.focus();
is(focused, true, "focus didn't move to element in contenteditable=false");
focused = false;
anchor.focus();
editor.setAttribute("contenteditable", "true");
anchorInEditor.focus();
is(focused, false, "focus moved to element in contenteditable=true");
focused = false;
anchor.focus();
editor.removeAttribute("contenteditable");
anchorInEditor.focus();
is(focused, true, "focus didn't move to element in contenteditable removed element");
focused = false;
anchor.focus();
editor.contentEditable = true;
anchorInEditor.focus();
is(focused, false, "focus moved to element in contenteditable=true by property");
focused = false;
anchor.focus();
editor.contentEditable = false;
anchorInEditor.focus();
is(focused, true, "focus didn't move to element in contenteditable=false by property");
}
SimpleTest.waitForExplicitFinish();
addLoadEvent(runTest);
addLoadEvent(SimpleTest.finish);
</script>
</pre>
</body>
</html>