зеркало из https://github.com/mozilla/gecko-dev.git
Bug 619278 - :-moz-ui-invalid should apply as soon as the user tries to submit the form. r=sicking a=jst
This commit is contained in:
Родитель
0cb659bdb1
Коммит
bf7a141c34
|
@ -1757,6 +1757,14 @@ nsHTMLFormElement::CheckValidFormSubmission()
|
|||
|
||||
for (PRUint32 i = 0, length = mControls->mElements.Length();
|
||||
i < length; ++i) {
|
||||
// Input elements can trigger a form submission and we want to
|
||||
// update the style in that case.
|
||||
if (mControls->mElements[i]->IsHTML(nsGkAtoms::input) &&
|
||||
nsContentUtils::IsFocusedContent(mControls->mElements[i])) {
|
||||
static_cast<nsHTMLInputElement*>(mControls->mElements[i])
|
||||
->UpdateValidityUIBits(true);
|
||||
}
|
||||
|
||||
doc->ContentStatesChanged(mControls->mElements[i], nsnull,
|
||||
NS_EVENT_STATE_MOZ_UI_VALID |
|
||||
NS_EVENT_STATE_MOZ_UI_INVALID);
|
||||
|
|
|
@ -2096,20 +2096,12 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
|||
nsEventStates states;
|
||||
|
||||
if (aVisitor.mEvent->message == NS_FOCUS_CONTENT) {
|
||||
// If the invalid UI is shown, we should show it while focusing (and
|
||||
// update). Otherwise, we should not.
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_INVALID_UI,
|
||||
!IsValid() && ShouldShowInvalidUI());
|
||||
|
||||
// If neither invalid UI nor valid UI is shown, we shouldn't show the valid
|
||||
// UI while typing.
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_VALID_UI, ShouldShowValidUI());
|
||||
UpdateValidityUIBits(true);
|
||||
|
||||
// We don't have to update NS_EVENT_STATE_MOZ_UI_INVALID nor
|
||||
// NS_EVENT_STATE_MOZ_UI_VALID given that the states should not change.
|
||||
} else { // NS_BLUR_CONTENT
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_INVALID_UI, PR_TRUE);
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_VALID_UI, PR_TRUE);
|
||||
UpdateValidityUIBits(false);
|
||||
states |= NS_EVENT_STATE_MOZ_UI_VALID | NS_EVENT_STATE_MOZ_UI_INVALID;
|
||||
}
|
||||
|
||||
|
@ -4586,3 +4578,21 @@ nsHTMLInputElement::GetFilterFromAccept()
|
|||
return filter;
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLInputElement::UpdateValidityUIBits(bool aIsFocused)
|
||||
{
|
||||
if (aIsFocused) {
|
||||
// If the invalid UI is shown, we should show it while focusing (and
|
||||
// update). Otherwise, we should not.
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_INVALID_UI,
|
||||
!IsValid() && ShouldShowInvalidUI());
|
||||
|
||||
// If neither invalid UI nor valid UI is shown, we shouldn't show the valid
|
||||
// UI while typing.
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_VALID_UI, ShouldShowValidUI());
|
||||
} else {
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_INVALID_UI, PR_TRUE);
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_VALID_UI, PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -307,6 +307,17 @@ public:
|
|||
*/
|
||||
PRInt32 GetFilterFromAccept();
|
||||
|
||||
/**
|
||||
* The form might need to request an update of the UI bits
|
||||
* (BF_CAN_SHOW_INVALID_UI and BF_CAN_SHOW_VALID_UI) when an invalid form
|
||||
* submission is tried.
|
||||
*
|
||||
* @param aIsFocused Whether the element is currently focused.
|
||||
*
|
||||
* @note The caller is responsible to call ContentStatesChanged.
|
||||
*/
|
||||
void UpdateValidityUIBits(bool aIsFocused);
|
||||
|
||||
protected:
|
||||
// Pull IsSingleLineTextControl into our scope, otherwise it'd be hidden
|
||||
// by the nsITextControlElement version.
|
||||
|
|
|
@ -251,6 +251,7 @@ _TEST_FILES = \
|
|||
test_bug610687.html \
|
||||
test_bug618948.html \
|
||||
test_bug623291.html \
|
||||
test_bug619278.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=619278
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 619278</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=619278">Mozilla Bug 619278</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
<form>
|
||||
<input required><button>submit</button>
|
||||
</form>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 619278 **/
|
||||
|
||||
function doElementMatchesSelector(aElement, aSelector)
|
||||
{
|
||||
ok(aElement.mozMatchesSelector(aSelector),
|
||||
aSelector + " should match for " + aElement);
|
||||
}
|
||||
|
||||
var e = document.forms[0].elements[0];
|
||||
|
||||
e.addEventListener("invalid", function(event) {
|
||||
e.addEventListener("invalid", arguments.callee, false);
|
||||
|
||||
SimpleTest.executeSoon(function() {
|
||||
doElementMatchesSelector(e, ":-moz-ui-invalid");
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}, false);
|
||||
|
||||
e.addEventListener("focus", function() {
|
||||
e.removeEventListener("focus", arguments.callee, false);
|
||||
|
||||
SimpleTest.executeSoon(function() {
|
||||
synthesizeKey("VK_RETURN", {});
|
||||
});
|
||||
}, false);
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.waitForFocus(function() {
|
||||
e.focus();
|
||||
});
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче