Bug 1345767 - Part 5: Factor HasPatternMismatch() out of HTMLInputElement. r?smaug draft
authorJessica Jong <jjong@mozilla.com>
Thu, 04 May 2017 15:10:57 +0800
changeset 572491 9aae21fad5340d0f24295c07e02afb19deac4ce3
parent 572490 8af7c637475972b25b28a3277c39f3de16b6aa9b
child 572492 af0798ce0d52d021c2dd0ba0943b0e2fcddfd49c
push id57094
push userjjong@mozilla.com
push dateThu, 04 May 2017 07:44:57 +0000
reviewerssmaug
bugs1345767
milestone55.0a1
Bug 1345767 - Part 5: Factor HasPatternMismatch() out of HTMLInputElement. r?smaug MozReview-Commit-ID: 2JWhbfEJhTm
dom/html/HTMLInputElement.cpp
dom/html/HTMLInputElement.h
dom/html/input/InputType.cpp
dom/html/input/InputType.h
dom/html/input/SingleLineTextInputTypes.cpp
dom/html/input/SingleLineTextInputTypes.h
--- 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;