diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp
index bd4ed10853..efad221078 100644
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -865,6 +865,7 @@ HTMLInputElement::HTMLInputElement(already_AddRefed& aNo
, mNumberControlSpinnerSpinsUp(false)
, mPickerRunning(false)
, mSelectionCached(true)
+ , mHasPatternAttribute(false)
{
// We are in a type=text so we now we currenty need a nsTextEditorState.
mInputData.mState = new nsTextEditorState(this);
@@ -1150,6 +1151,10 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
} else if (MaxLengthApplies() && aName == nsGkAtoms::maxlength) {
UpdateTooLongValidityState();
} else if (aName == nsGkAtoms::pattern) {
+ // Although pattern attribute only applies to single line text controls,
+ // we set this flag for all input types to save having to check the type
+ // here.
+ mHasPatternAttribute = !!aValue;
UpdatePatternMismatchValidityState();
} else if (aName == nsGkAtoms::multiple) {
UpdateTypeMismatchValidityState();
@@ -6426,8 +6431,7 @@ HTMLInputElement::HasTypeMismatch() const
bool
HTMLInputElement::HasPatternMismatch() const
{
- if (!DoesPatternApply() ||
- !HasAttr(kNameSpaceID_None, nsGkAtoms::pattern)) {
+ if (!mHasPatternAttribute || !DoesPatternApply()) {
return false;
}
diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h
index db91879bab..97246518dd 100644
--- a/dom/html/HTMLInputElement.h
+++ b/dom/html/HTMLInputElement.h
@@ -282,6 +282,11 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState,
return mSelectionProperties;
}
+ bool HasPatternAttribute() const
+ {
+ return mHasPatternAttribute;
+ }
+
// nsIConstraintValidation
bool IsTooLong();
bool IsValueMissing() const;
@@ -1357,6 +1362,7 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState,
bool mNumberControlSpinnerSpinsUp : 1;
bool mPickerRunning : 1;
bool mSelectionCached : 1;
+ bool mHasPatternAttribute : 1;
private:
static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,