Bug 644959 - Do not try to restore HTMLButtonElement state when created from parser fragment. r=hsivonen

This commit is contained in:
Mounir Lamouri 2011-05-31 23:57:16 +02:00
Родитель 96c5ee86a9
Коммит 87072dea1e
3 изменённых файлов: 75 добавлений и 6 удалений

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

@ -64,6 +64,8 @@
#include "nsIConstraintValidation.h"
#include "mozAutoDocUpdate.h"
using namespace mozilla::dom;
#define NS_IN_SUBMIT_CLICK (1 << 0)
#define NS_OUTER_ACTIVATE_EVENT (1 << 1)
@ -84,7 +86,8 @@ class nsHTMLButtonElement : public nsGenericHTMLFormElement,
public:
using nsIConstraintValidation::GetValidationMessage;
nsHTMLButtonElement(already_AddRefed<nsINodeInfo> aNodeInfo);
nsHTMLButtonElement(already_AddRefed<nsINodeInfo> aNodeInfo,
FromParser aFromParser = NOT_FROM_PARSER);
virtual ~nsHTMLButtonElement();
// nsISupports
@ -139,6 +142,7 @@ protected:
PRUint8 mType;
PRPackedBool mDisabledChanged;
PRPackedBool mInInternalActivate;
PRPackedBool mInhibitStateRestoration;
private:
// The analogue of defaultValue in the DOM for input and textarea
@ -150,14 +154,16 @@ private:
// Construction, destruction
NS_IMPL_NS_NEW_HTML_ELEMENT(Button)
NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Button)
nsHTMLButtonElement::nsHTMLButtonElement(already_AddRefed<nsINodeInfo> aNodeInfo)
nsHTMLButtonElement::nsHTMLButtonElement(already_AddRefed<nsINodeInfo> aNodeInfo,
FromParser aFromParser)
: nsGenericHTMLFormElement(aNodeInfo),
mType(kButtonDefaultType->value),
mDisabledChanged(PR_FALSE),
mInInternalActivate(PR_FALSE)
mInInternalActivate(PR_FALSE),
mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT))
{
// <button> is always barred from constraint validation.
SetBarredFromConstraintValidation(PR_TRUE);
@ -545,8 +551,10 @@ nsHTMLButtonElement::SubmitNamesValues(nsFormSubmission* aFormSubmission)
void
nsHTMLButtonElement::DoneCreatingElement()
{
// Restore state as needed.
RestoreFormControlState(this, this);
if (!mInhibitStateRestoration) {
// Restore state as needed.
RestoreFormControlState(this, this);
}
}
nsresult

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

@ -279,6 +279,7 @@ _TEST_FILES = \
test_bug658746.html \
test_bug659596.html \
test_bug659743.xml \
test_restore_from_parser_fragment.html \
$(NULL)
libs:: $(_TEST_FILES)

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

@ -0,0 +1,60 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=644959
-->
<head>
<title>Test for Bug 644959</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>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=644959">Mozilla Bug 644959</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 644959 **/
var content = document.getElementById('content');
function appendHTML(aParent, aElementString)
{
aParent.innerHTML = "<form>" + aElementString + "</form>";
}
function clearHTML(aParent)
{
aParent.innerHTML = "";
}
var tests = [
[ "button", "<button></button>" ],
[ "input", "<input>" ],
[ "textarea", "<textarea></textarea>" ],
[ "select", "<select></select>" ],
];
var element = null;
for each (var test in tests) {
appendHTML(content, test[1]);
element = content.getElementsByTagName(test[0])[0];
is(element.disabled, false, "element shouldn't be disabled");
element.disabled = true;
is(element.disabled, true, "element should be disabled");
clearHTML(content);
appendHTML(content, test[1]);
element = content.getElementsByTagName(test[0])[0];
is(element.disabled, false, "element shouldn't be disabled");
}
</script>
</pre>
</body>
</html>