mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 605125 (5/5) - :-moz-ui-valid should not apply while typing if the element had no style when it was focused. r=bz a=jst
--HG-- rename : content/html/content/test/test_bug605125.html => content/html/content/test/test_bug605125-1.html rename : content/html/content/test/test_bug605124-2.html => content/html/content/test/test_bug605125-2.html
This commit is contained in:
parent
4b6eaeefda
commit
4cb3a45367
@ -626,6 +626,7 @@ nsHTMLInputElement::nsHTMLInputElement(already_AddRefed<nsINodeInfo> aNodeInfo,
|
||||
SET_BOOLBIT(mBitField, BF_INHIBIT_RESTORATION,
|
||||
aFromParser & mozilla::dom::FROM_PARSER_FRAGMENT);
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_INVALID_UI, PR_TRUE);
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_VALID_UI, PR_TRUE);
|
||||
mInputData.mState = new nsTextEditorState(this);
|
||||
NS_ADDREF(mInputData.mState);
|
||||
|
||||
@ -2118,11 +2119,17 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
||||
// update). Otherwise, we should not.
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_INVALID_UI,
|
||||
!IsValid() && ShouldShowInvalidUI());
|
||||
// We don't have to update NS_EVENT_STATE_MOZ_UI_INVALID given that
|
||||
// the state should not change.
|
||||
|
||||
// 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());
|
||||
|
||||
// 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);
|
||||
states |= NS_EVENT_STATE_MOZ_UI_INVALID;
|
||||
SET_BOOLBIT(mBitField, BF_CAN_SHOW_VALID_UI, PR_TRUE);
|
||||
states |= NS_EVENT_STATE_MOZ_UI_VALID | NS_EVENT_STATE_MOZ_UI_INVALID;
|
||||
}
|
||||
|
||||
if (PlaceholderApplies() &&
|
||||
@ -3321,17 +3328,6 @@ nsHTMLInputElement::IntrinsicState() const
|
||||
if (IsCandidateForConstraintValidation()) {
|
||||
if (IsValid()) {
|
||||
state |= NS_EVENT_STATE_VALID;
|
||||
|
||||
// NS_EVENT_STATE_MOZ_UI_VALID applies if the value has been changed.
|
||||
// This doesn't apply to elements with value mode default.
|
||||
ValueModeType valueMode = GetValueMode();
|
||||
if ((mForm && mForm->HasEverTriedInvalidSubmit()) ||
|
||||
valueMode == VALUE_MODE_DEFAULT ||
|
||||
(valueMode == VALUE_MODE_DEFAULT_ON && GetCheckedChanged()) ||
|
||||
((valueMode == VALUE_MODE_VALUE ||
|
||||
valueMode == VALUE_MODE_FILENAME) && GetValueChanged())) {
|
||||
state |= NS_EVENT_STATE_MOZ_UI_VALID;
|
||||
}
|
||||
} else {
|
||||
state |= NS_EVENT_STATE_INVALID;
|
||||
|
||||
@ -3340,6 +3336,19 @@ nsHTMLInputElement::IntrinsicState() const
|
||||
state |= NS_EVENT_STATE_MOZ_UI_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
// :-moz-ui-valid applies if all of the following conditions are true:
|
||||
// 1. The element is not focused, or had either :-moz-ui-valid or
|
||||
// :-moz-ui-invalid applying before it was focused ;
|
||||
// 2. The element is either valid or isn't allowed to have
|
||||
// :-moz-ui-invalid applying ;
|
||||
// 3. The rules to have :-moz-ui-valid applying are fulfilled
|
||||
// (see ShouldShowValidUI()).
|
||||
if (GET_BOOLBIT(mBitField, BF_CAN_SHOW_VALID_UI) &&
|
||||
(IsValid() || !GET_BOOLBIT(mBitField, BF_CAN_SHOW_INVALID_UI)) &&
|
||||
ShouldShowValidUI()) {
|
||||
state |= NS_EVENT_STATE_MOZ_UI_VALID;
|
||||
}
|
||||
}
|
||||
|
||||
if (PlaceholderApplies() && HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder) &&
|
||||
|
@ -67,6 +67,7 @@
|
||||
#define BF_INDETERMINATE 10
|
||||
#define BF_INHIBIT_RESTORATION 11
|
||||
#define BF_CAN_SHOW_INVALID_UI 12
|
||||
#define BF_CAN_SHOW_VALID_UI 13
|
||||
|
||||
#define GET_BOOLBIT(bitfield, field) (((bitfield) & (0x01 << (field))) \
|
||||
? PR_TRUE : PR_FALSE)
|
||||
@ -582,6 +583,31 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether an element should show the valid UI.
|
||||
*
|
||||
* @return Whether the valid UI should be shown.
|
||||
* @note This doesn't take into account the validity of the element.
|
||||
*/
|
||||
bool ShouldShowValidUI() const {
|
||||
if (mForm && mForm->HasEverTriedInvalidSubmit()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (GetValueMode()) {
|
||||
case VALUE_MODE_DEFAULT:
|
||||
return true;
|
||||
case VALUE_MODE_DEFAULT_ON:
|
||||
return GetCheckedChanged();
|
||||
case VALUE_MODE_VALUE:
|
||||
case VALUE_MODE_FILENAME:
|
||||
return GetValueChanged();
|
||||
default:
|
||||
NS_NOTREACHED("We should not be there: there are no other modes.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIControllers> mControllers;
|
||||
|
||||
/**
|
||||
|
@ -240,6 +240,8 @@ protected:
|
||||
PRPackedBool mDisabledChanged;
|
||||
/** Whether we should make :-moz-ui-invalid apply on the element. **/
|
||||
PRPackedBool mCanShowInvalidUI;
|
||||
/** Whether we should make :-moz-ui-valid apply on the element. **/
|
||||
PRPackedBool mCanShowValidUI;
|
||||
|
||||
/** The state of the text editor (selection controller and the editor) **/
|
||||
nsRefPtr<nsTextEditorState> mState;
|
||||
@ -296,6 +298,16 @@ protected:
|
||||
mValueChanged || GetValidityState(VALIDITY_STATE_CUSTOM_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether an element should show the valid UI.
|
||||
*
|
||||
* @return Whether the valid UI should be shown.
|
||||
* @note This doesn't take into account the validity of the element.
|
||||
*/
|
||||
bool ShouldShowValidUI() const {
|
||||
return (mForm && mForm->HasEverTriedInvalidSubmit()) || mValueChanged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mutable state of the element.
|
||||
*/
|
||||
@ -315,6 +327,7 @@ nsHTMLTextAreaElement::nsHTMLTextAreaElement(already_AddRefed<nsINodeInfo> aNode
|
||||
mInhibitStateRestoration(!!(aFromParser & FROM_PARSER_FRAGMENT)),
|
||||
mDisabledChanged(PR_FALSE),
|
||||
mCanShowInvalidUI(PR_TRUE),
|
||||
mCanShowValidUI(PR_TRUE),
|
||||
mState(new nsTextEditorState(this))
|
||||
{
|
||||
AddMutationObserver(this);
|
||||
@ -766,11 +779,17 @@ nsHTMLTextAreaElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
||||
// If the invalid UI is shown, we should show it while focusing (and
|
||||
// update). Otherwise, we should not.
|
||||
mCanShowInvalidUI = !IsValid() && ShouldShowInvalidUI();
|
||||
// We don't have to update NS_EVENT_STATE_MOZ_UI_INVALID given that
|
||||
// the state should not change.
|
||||
|
||||
// If neither invalid UI nor valid UI is shown, we shouldn't show the valid
|
||||
// UI while typing.
|
||||
mCanShowValidUI = ShouldShowValidUI();
|
||||
|
||||
// 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
|
||||
mCanShowInvalidUI = PR_TRUE;
|
||||
states |= NS_EVENT_STATE_MOZ_UI_INVALID;
|
||||
mCanShowValidUI = PR_TRUE;
|
||||
states |= NS_EVENT_STATE_MOZ_UI_VALID | NS_EVENT_STATE_MOZ_UI_INVALID;
|
||||
}
|
||||
|
||||
if (HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder)) {
|
||||
@ -1059,9 +1078,6 @@ nsHTMLTextAreaElement::IntrinsicState() const
|
||||
if (IsCandidateForConstraintValidation()) {
|
||||
if (IsValid()) {
|
||||
state |= NS_EVENT_STATE_VALID;
|
||||
if ((mForm && mForm->HasEverTriedInvalidSubmit()) || mValueChanged) {
|
||||
state |= NS_EVENT_STATE_MOZ_UI_VALID;
|
||||
}
|
||||
} else {
|
||||
state |= NS_EVENT_STATE_INVALID;
|
||||
// NS_EVENT_STATE_MOZ_UI_INVALID always apply if the element suffers from
|
||||
@ -1073,6 +1089,19 @@ nsHTMLTextAreaElement::IntrinsicState() const
|
||||
state |= NS_EVENT_STATE_MOZ_UI_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
// :-moz-ui-valid applies if all the following are true:
|
||||
// 1. The element is not focused, or had either :-moz-ui-valid or
|
||||
// :-moz-ui-invalid applying before it was focused ;
|
||||
// 2. The element is either valid or isn't allowed to have
|
||||
// :-moz-ui-invalid applying ;
|
||||
// 3. The rules to have :-moz-ui-valid applying are fulfilled
|
||||
// (see ShouldShowValidUI()).
|
||||
if (mCanShowValidUI &&
|
||||
(IsValid() || !mCanShowInvalidUI) &&
|
||||
ShouldShowValidUI()) {
|
||||
state |= NS_EVENT_STATE_MOZ_UI_VALID;
|
||||
}
|
||||
}
|
||||
|
||||
if (HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder) &&
|
||||
|
@ -245,7 +245,8 @@ _TEST_FILES = \
|
||||
test_bug613113.html \
|
||||
test_bug605124-1.html \
|
||||
test_bug605124-2.html \
|
||||
test_bug605125.html \
|
||||
test_bug605125-1.html \
|
||||
test_bug605125-2.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
94
content/html/content/test/test_bug605125-2.html
Normal file
94
content/html/content/test/test_bug605125-2.html
Normal file
@ -0,0 +1,94 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=605125
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 605125</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=605125">Mozilla Bug 605125</a>
|
||||
<p id="display"></p>
|
||||
<div id="content">
|
||||
<input>
|
||||
<textarea></textarea>
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
/** Test for Bug 605125 **/
|
||||
|
||||
function checkPseudoClass(aElement, aExpected)
|
||||
{
|
||||
is(aElement.mozMatchesSelector(":-moz-ui-valid"), aExpected,
|
||||
"mozMatchesSelector(':-moz-ui-valid') should return " + aExpected + " for " + aElement);
|
||||
}
|
||||
|
||||
function checkElement(aElement)
|
||||
{
|
||||
checkPseudoClass(aElement, false);
|
||||
|
||||
// Focusing while :-moz-ui-valid doesn't apply,
|
||||
// the pseudo-class should not apply while typing.
|
||||
aElement.focus();
|
||||
checkPseudoClass(aElement, false);
|
||||
// with keys
|
||||
synthesizeKey('f', {});
|
||||
checkPseudoClass(aElement, false);
|
||||
synthesizeKey('VK_BACK_SPACE', {});
|
||||
checkPseudoClass(aElement, false);
|
||||
// with .value
|
||||
aElement.value = 'f';
|
||||
checkPseudoClass(aElement, false);
|
||||
aElement.value = '';
|
||||
checkPseudoClass(aElement, false);
|
||||
|
||||
aElement.blur();
|
||||
checkPseudoClass(aElement, true);
|
||||
|
||||
// Focusing while :-moz-ui-valid applies,
|
||||
// the pseudo-class should apply while typing if appropriate.
|
||||
aElement.focus();
|
||||
checkPseudoClass(aElement, true);
|
||||
// with keys
|
||||
synthesizeKey('f', {});
|
||||
checkPseudoClass(aElement, true);
|
||||
synthesizeKey('VK_BACK_SPACE', {});
|
||||
checkPseudoClass(aElement, true);
|
||||
// with .value
|
||||
aElement.value = 'f';
|
||||
checkPseudoClass(aElement, true);
|
||||
aElement.value = '';
|
||||
checkPseudoClass(aElement, true);
|
||||
|
||||
aElement.blur();
|
||||
aElement.required = true;
|
||||
checkPseudoClass(aElement, false);
|
||||
|
||||
// Focusing while :-moz-ui-invalid applies,
|
||||
// the pseudo-class should apply while typing if appropriate.
|
||||
aElement.focus();
|
||||
checkPseudoClass(aElement, false);
|
||||
// with keys
|
||||
synthesizeKey('f', {});
|
||||
checkPseudoClass(aElement, true);
|
||||
synthesizeKey('VK_BACK_SPACE', {});
|
||||
checkPseudoClass(aElement, false);
|
||||
// with .value
|
||||
aElement.value = 'f';
|
||||
checkPseudoClass(aElement, true);
|
||||
aElement.value = '';
|
||||
checkPseudoClass(aElement, false);
|
||||
}
|
||||
|
||||
checkElement(document.getElementsByTagName('input')[0]);
|
||||
checkElement(document.getElementsByTagName('textarea')[0]);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user