Bug 1345767 - Part 5: Factor HasPatternMismatch() out of HTMLInputElement. r?smaug
MozReview-Commit-ID: 2JWhbfEJhTm
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -7354,27 +7354,16 @@ HTMLInputElement::PlaceholderApplies() c
if (IsDateTimeInputType(mType)) {
return false;
}
return IsSingleLineTextControl(false);
}
bool
-HTMLInputElement::DoesPatternApply() const
-{
- // TODO: temporary until bug 773205 is fixed.
- if (IsExperimentalMobileType(mType) || IsDateTimeInputType(mType)) {
- return false;
- }
-
- return IsSingleLineTextControl(false);
-}
-
-bool
HTMLInputElement::DoesMinMaxApply() const
{
switch (mType)
{
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_DATE:
case NS_FORM_INPUT_TIME:
case NS_FORM_INPUT_RANGE:
@@ -7527,34 +7516,17 @@ bool
HTMLInputElement::HasTypeMismatch() const
{
return mInputType->HasTypeMismatch();
}
bool
HTMLInputElement::HasPatternMismatch() const
{
- if (!DoesPatternApply() ||
- !HasAttr(kNameSpaceID_None, nsGkAtoms::pattern)) {
- return false;
- }
-
- nsAutoString pattern;
- GetAttr(kNameSpaceID_None, nsGkAtoms::pattern, pattern);
-
- nsAutoString value;
- GetNonFileValueInternal(value);
-
- if (value.IsEmpty()) {
- return false;
- }
-
- nsIDocument* doc = OwnerDoc();
-
- return !nsContentUtils::IsPatternMatching(value, pattern, doc);
+ return mInputType->HasPatternMismatch();
}
bool
HTMLInputElement::IsRangeOverflow() const
{
if (!DoesMinMaxApply()) {
return false;
}
--- a/dom/html/HTMLInputElement.h
+++ b/dom/html/HTMLInputElement.h
@@ -1073,21 +1073,16 @@ protected:
bool DoesReadOnlyApply() const;
/**
* Returns if the required attribute applies for the current type.
*/
bool DoesRequiredApply() const;
/**
- * Returns if the pattern attribute applies for the current type.
- */
- bool DoesPatternApply() const;
-
- /**
* Returns if the min and max attributes apply for the current type.
*/
bool DoesMinMaxApply() const;
/**
* Returns if the step attribute apply for the current type.
*/
bool DoesStepApply() const { return DoesMinMaxApply(); }
--- a/dom/html/input/InputType.cpp
+++ b/dom/html/input/InputType.cpp
@@ -145,8 +145,14 @@ InputType::IsValueMissing() const
return false;
}
bool
InputType::HasTypeMismatch() const
{
return false;
}
+
+bool
+InputType::HasPatternMismatch() const
+{
+ return false;
+}
--- a/dom/html/input/InputType.h
+++ b/dom/html/input/InputType.h
@@ -35,16 +35,17 @@ public:
* Drop the reference to the input element.
*/
void DropReference();
virtual bool IsTooLong() const;
virtual bool IsTooShort() const;
virtual bool IsValueMissing() const;
virtual bool HasTypeMismatch() const;
+ virtual bool HasPatternMismatch() const;
protected:
explicit InputType(mozilla::dom::HTMLInputElement* aInputElement)
: mInputElement(aInputElement)
{}
/**
* Get the mutable state of the element.
--- a/dom/html/input/SingleLineTextInputTypes.cpp
+++ b/dom/html/input/SingleLineTextInputTypes.cpp
@@ -4,16 +4,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "SingleLineTextInputTypes.h"
#include "mozilla/dom/HTMLInputElement.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "HTMLSplitOnSpacesTokenizer.h"
+#include "nsContentUtils.h"
#include "nsCRTGlue.h"
#include "nsIIDNService.h"
#include "nsIIOService.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
bool
SingleLineTextInputTypeBase::IsMutable() const
@@ -63,16 +64,36 @@ SingleLineTextInputTypeBase::IsValueMiss
if (!IsMutable()) {
return false;
}
return IsValueEmpty();
}
+bool
+SingleLineTextInputTypeBase::HasPatternMismatch() const
+{
+ nsAutoString pattern;
+ if (!mInputElement->GetAttr(kNameSpaceID_None, nsGkAtoms::pattern, pattern)) {
+ return false;
+ }
+
+ nsAutoString value;
+ GetNonFileValueInternal(value);
+
+ if (value.IsEmpty()) {
+ return false;
+ }
+
+ nsIDocument* doc = mInputElement->OwnerDoc();
+
+ return !nsContentUtils::IsPatternMatching(value, pattern, doc);
+}
+
/* input type=url */
bool
URLInputType::HasTypeMismatch() const
{
nsAutoString value;
GetNonFileValueInternal(value);
--- a/dom/html/input/SingleLineTextInputTypes.h
+++ b/dom/html/input/SingleLineTextInputTypes.h
@@ -12,16 +12,17 @@
class SingleLineTextInputTypeBase : public ::InputType
{
public:
~SingleLineTextInputTypeBase() override {}
bool IsTooLong() const override;
bool IsTooShort() const override;
bool IsValueMissing() const override;
+ bool HasPatternMismatch() const override;
protected:
explicit SingleLineTextInputTypeBase(
mozilla::dom::HTMLInputElement* aInputElement)
: InputType(aInputElement)
{}
bool IsMutable() const override;