Issue #2790 - Part 4: Working non persistent autofill highlight

This commit is contained in:
MeladJM 2025-07-25 11:12:29 +08:00 • committed by roytam1
commit bf8cfcc980
12 changed files with 207 additions and 68 deletions

View file

@ -1270,6 +1270,14 @@ ComputeSelectorStateDependence(nsCSSSelector& aSelector)
continue;
}
// --- BEGIN PATCH: Explicit autofill state dependence ---
if (pseudoClass->mType == CSSPseudoClassType::autofill ||
pseudoClass->mType == CSSPseudoClassType::mozAutofillHighlight) {
states |= NS_EVENT_STATE_AUTOFILL;
continue;
}
// --- END PATCH ---
auto idx = static_cast<CSSPseudoClassTypeBase>(pseudoClass->mType);
states |= nsCSSPseudoClasses::sPseudoClassStateDependences[idx];
}

View file

@ -576,6 +576,16 @@ nsCSSRuleUtils::StateSelectorMatches(Element* aElement,
for (nsPseudoClassList* pseudoClass = aSelector->mPseudoClassList;
pseudoClass;
pseudoClass = pseudoClass->mNext) {
// --- Autofill explicit matching ---
if (pseudoClass->mType == CSSPseudoClassType::autofill ||
pseudoClass->mType == CSSPseudoClassType::mozAutofillHighlight) {
// Match if the element has the autofill state, regardless of focus
if (!aElement->State().HasState(NS_EVENT_STATE_AUTOFILL)) {
return false;
}
continue; // This pseudo-class matches
}
// --- End autofill explicit matching ---
auto idx = static_cast<CSSPseudoClassTypeBase>(pseudoClass->mType);
EventStates statesToCheck = nsCSSPseudoClasses::sPseudoClassStates[idx];
if (!statesToCheck.IsEmpty() && !StateSelectorMatches(aElement,

View file

@ -1152,6 +1152,11 @@ input[type="time"] {
/* Autofill highlight for internal-only pseudo-class */
input:-moz-autofill-highlight,
select:-moz-autofill-highlight,
textarea:-moz-autofill-highlight {
background-color: #ffff99 !important;
}
.custom-autofill-highlight {
background: yellow !important;
}