Bug 557087 (1/6) - Fieldset elements can be disabled. r+a=sicking

--HG--
extra : rebase_source : 9a11a362b24285af3a5d87ebb88e39be0cf1e098
This commit is contained in:
Mounir Lamouri 2010-09-18 23:24:58 +02:00
Родитель 11f8632577
Коммит b867cc9718
20 изменённых файлов: 234 добавлений и 16 удалений

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

@ -2687,7 +2687,6 @@ nsGenericHTMLFormElement::CanBeDisabled() const
// It's easier to test the types that _cannot_ be disabled
return
type != NS_FORM_LABEL &&
type != NS_FORM_FIELDSET &&
type != NS_FORM_OBJECT &&
type != NS_FORM_OUTPUT;
}

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

@ -42,6 +42,7 @@
#include "nsIForm.h"
#include "nsIFormControl.h"
#include "nsIConstraintValidation.h"
#include "nsEventDispatcher.h"
class nsHTMLFieldSetElement : public nsGenericHTMLFormElement,
@ -69,6 +70,9 @@ public:
// nsIDOMHTMLFieldSetElement
NS_DECL_NSIDOMHTMLFIELDSETELEMENT
// nsIContent
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
// nsIFormControl
NS_IMETHOD_(PRUint32) GetType() const { return NS_FORM_FIELDSET; }
NS_IMETHOD Reset();
@ -134,11 +138,25 @@ NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLFieldSetElement)
NS_IMPL_ELEMENT_CLONE(nsHTMLFieldSetElement)
NS_IMPL_BOOL_ATTR(nsHTMLFieldSetElement, Disabled, disabled)
NS_IMPL_STRING_ATTR(nsHTMLFieldSetElement, Name, name)
// nsIConstraintValidation
NS_IMPL_NSICONSTRAINTVALIDATION(nsHTMLFieldSetElement)
// nsIContent
nsresult
nsHTMLFieldSetElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
{
// Do not process any DOM events if the element is disabled.
aVisitor.mCanHandle = PR_FALSE;
if (HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
return NS_OK;
}
return nsGenericHTMLFormElement::PreHandleEvent(aVisitor);
}
// nsIDOMHTMLFieldSetElement
NS_IMETHODIMP

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

@ -229,6 +229,7 @@ _TEST_FILES = \
test_bug595447.html \
test_bug595449.html \
test_bug595457.html \
test_bug557087-1.html \
$(NULL)
libs:: $(_TEST_FILES)

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

@ -0,0 +1,127 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=557087
-->
<head>
<title>Test for Bug 557087</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/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=557087">Mozilla Bug 557087</a>
<p id="display"></p>
<div id="content">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 557087 **/
function checkDisabledAttribute(aFieldset)
{
ok('disabled' in aFieldset,
"fieldset elements should have the disabled attribute");
ok(!aFieldset.disabled,
"fieldset elements disabled attribute should be disabled");
is(aFieldset.getAttribute('disabled'), null,
"fieldset elements disabled attribute should be disabled");
aFieldset.disabled = true;
ok(aFieldset.disabled,
"fieldset elements disabled attribute should be enabled");
isnot(aFieldset.getAttribute('disabled'), null,
"fieldset elements disabled attribute should be enabled");
aFieldset.removeAttribute('disabled');
aFieldset.setAttribute('disabled', '');
ok(aFieldset.disabled,
"fieldset elements disabled attribute should be enabled");
isnot(aFieldset.getAttribute('disabled'), null,
"fieldset elements disabled attribute should be enabled");
aFieldset.removeAttribute('disabled');
ok(!aFieldset.disabled,
"fieldset elements disabled attribute should be disabled");
is(aFieldset.getAttribute('disabled'), null,
"fieldset elements disabled attribute should be disabled");
}
function checkDisabledPseudoClass(aFieldset)
{
is(document.querySelector(":disabled"), null,
"no elements should have :disabled applied to them");
aFieldset.disabled = true;
is(document.querySelector(":disabled"), aFieldset,
":disabled should apply to fieldset elements");
aFieldset.disabled = false;
is(document.querySelector(":disabled"), null,
"no elements should have :disabled applied to them");
}
function checkEnabledPseudoClass(aFieldset)
{
is(document.querySelector(":enabled"), aFieldset,
":enabled should apply to fieldset elements");
aFieldset.disabled = true;
is(document.querySelector(":enabled"), null,
"no elements should have :enabled applied to them");
aFieldset.disabled = false;
is(document.querySelector(":enabled"), aFieldset,
":enabled should apply to fieldset elements");
}
function checkFocus(aFieldset)
{
aFieldset.disabled = true;
aFieldset.setAttribute('tabindex', 1);
aFieldset.focus();
isnot(document.activeElement, aFieldset,
"fieldset can't be focused when disabled");
aFieldset.removeAttribute('tabindex');
aFieldset.disabled = false;
}
function checkClickEvent(aFieldset)
{
var clickHandled = false;
aFieldset.disabled = true;
aFieldset.addEventListener("click", function(aEvent) {
aEvent.target.removeEventListener("click", arguments.callee, false);
clickHandled = true;
}, false);
sendMouseEvent({type:'click'}, aFieldset);
SimpleTest.executeSoon(function() {
ok(!clickHandled, "When disabled, fieldset should prevent click events");
SimpleTest.finish();
});
}
SimpleTest.waitForExplicitFinish();
var fieldset = document.createElement("fieldset");
var content = document.getElementById('content');
content.appendChild(fieldset);
checkDisabledAttribute(fieldset);
checkDisabledPseudoClass(fieldset);
checkEnabledPseudoClass(fieldset);
checkFocus(fieldset);
checkClickEvent(fieldset);
</script>
</pre>
</body>
</html>

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

@ -49,9 +49,10 @@
interface nsIDOMValidityState;
[scriptable, uuid(b38efb33-ec68-487a-bf9b-2920425fa408)]
[scriptable, uuid(58db2166-36fc-482c-a9f8-84ad262537b2)]
interface nsIDOMHTMLFieldSetElement : nsIDOMHTMLElement
{
attribute boolean disabled;
readonly attribute nsIDOMHTMLFormElement form;
attribute DOMString name;

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

@ -30,13 +30,6 @@
<label disabled="disabled">bogus</label> <span>FAIL</span>
</div>
<div>
fieldset:
<fieldset class="hideme"><legend>bogus</legend></fieldset> <span>FAIL</span>
<fieldset class="hideme" disabled="disabled"><legend>bogus</legend></fieldset> <span>FAIL</span>
<fieldset class="hideme"><legend disabled="disabled">bogus</legend></fieldset> <span>FAIL</span>
</div>
<div>
legend:
<fieldset><legend>FAIL</legend></fieldset>

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

@ -33,13 +33,6 @@
<label disabled="disabled">bogus</label> <span>FAIL</span>
</div>
<div>
fieldset:
<fieldset class="hideme"><legend>bogus</legend></fieldset> <span>FAIL</span>
<fieldset class="hideme" disabled="disabled"><legend>bogus</legend></fieldset> <span>FAIL</span>
<fieldset class="hideme"><legend disabled="disabled">bogus</legend></fieldset> <span>FAIL</span>
</div>
<div>
legend:
<fieldset><legend>FAIL</legend></fieldset>

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

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<link rel='stylesheet' type='text/css' href='style.css'>
<body>
<fieldset class="disabled" disabled></fieldset>
</body>
</html>

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

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<link rel='stylesheet' type='text/css' href='style.css'>
<body>
<fieldset class="enabled"></fieldset>
</body>
</html>

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

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<link rel='stylesheet' type='text/css' href='style.css'>
<body>
<fieldset class='ref'></fieldset>
</body>
</html>

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

@ -0,0 +1,2 @@
== fieldset-enabled.html fieldset-ref.html
== fieldset-disabled.html fieldset-ref.html

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

@ -0,0 +1,16 @@
fieldset.disabled {
background-color: red;
}
fieldset:disabled.disabled,
fieldset.ref {
background-color: green;
}
fieldset.enabled {
background-color: green;
}
fieldset:disabled.enabled {
background-color: red;
}

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

@ -0,0 +1 @@
include fieldset/reftest.list

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

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<link rel='stylesheet' type='text/css' href='style.css'>
<body>
<fieldset class="disabled" disabled></fieldset>
</body>
</html>

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

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<link rel='stylesheet' type='text/css' href='style.css'>
<body>
<fieldset class="enabled"></fieldset>
</body>
</html>

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

@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<link rel='stylesheet' type='text/css' href='style.css'>
<body>
<fieldset class='ref'></fieldset>
</body>
</html>

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

@ -0,0 +1,2 @@
== fieldset-enabled.html fieldset-ref.html
== fieldset-disabled.html fieldset-ref.html

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

@ -0,0 +1,16 @@
fieldset.enabled {
background-color: red;
}
fieldset:enabled.enabled,
fieldset.ref {
background-color: green;
}
fieldset.disabled {
background-color: green;
}
fieldset:enabled.disabled {
background-color: red;
}

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

@ -0,0 +1 @@
include fieldset/reftest.list

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

@ -50,6 +50,12 @@ include css-charset/reftest.list
# css default pseudo class tests
include css-default/reftest.list
# css :disable tests
include css-disabled/reftest.list
# css :enable tests
include css-enabled/reftest.list
# css @import tests
include css-import/reftest.list