LCOV - code coverage report
Current view: top level - dom/html/input - SingleLineTextInputTypes.h (source / functions) Hit Total Coverage
Test: output.info Lines: 15 40 37.5 %
Date: 2017-07-14 16:53:18 Functions: 7 27 25.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef SingleLineTextInputTypes_h__
       8             : #define SingleLineTextInputTypes_h__
       9             : 
      10             : #include "InputType.h"
      11             : 
      12             : class SingleLineTextInputTypeBase : public ::InputType
      13             : {
      14             : public:
      15           1 :   ~SingleLineTextInputTypeBase() override {}
      16             : 
      17             :   bool IsTooLong() const override;
      18             :   bool IsTooShort() const override;
      19             :   bool IsValueMissing() const override;
      20             :   bool HasPatternMismatch() const override;
      21             : 
      22             : protected:
      23           8 :   explicit SingleLineTextInputTypeBase(
      24             :     mozilla::dom::HTMLInputElement* aInputElement)
      25           8 :       : InputType(aInputElement)
      26           8 :   {}
      27             : 
      28             :   bool IsMutable() const override;
      29             : };
      30             : 
      31             : // input type=text
      32           1 : class TextInputType : public SingleLineTextInputTypeBase
      33             : {
      34             : public:
      35             :   static InputType*
      36           7 :   Create(mozilla::dom::HTMLInputElement* aInputElement, void* aMemory)
      37             :   {
      38           7 :     return new (aMemory) TextInputType(aInputElement);
      39             :   }
      40             : 
      41             : private:
      42           7 :   explicit TextInputType(mozilla::dom::HTMLInputElement* aInputElement)
      43           7 :     : SingleLineTextInputTypeBase(aInputElement)
      44           7 :   {}
      45             : };
      46             : 
      47             : // input type=search
      48           0 : class SearchInputType : public SingleLineTextInputTypeBase
      49             : {
      50             : public:
      51             :   static InputType*
      52           1 :   Create(mozilla::dom::HTMLInputElement* aInputElement, void* aMemory)
      53             :   {
      54           1 :     return new (aMemory) SearchInputType(aInputElement);
      55             :   }
      56             : 
      57             : private:
      58           1 :   explicit SearchInputType(mozilla::dom::HTMLInputElement* aInputElement)
      59           1 :     : SingleLineTextInputTypeBase(aInputElement)
      60           1 :   {}
      61             : };
      62             : 
      63             : // input type=tel
      64           0 : class TelInputType : public SingleLineTextInputTypeBase
      65             : {
      66             : public:
      67             :   static InputType*
      68           0 :   Create(mozilla::dom::HTMLInputElement* aInputElement, void* aMemory)
      69             :   {
      70           0 :     return new (aMemory) TelInputType(aInputElement);
      71             :   }
      72             : 
      73             : private:
      74           0 :   explicit TelInputType(mozilla::dom::HTMLInputElement* aInputElement)
      75           0 :     : SingleLineTextInputTypeBase(aInputElement)
      76           0 :   {}
      77             : };
      78             : 
      79             : // input type=url
      80           0 : class URLInputType : public SingleLineTextInputTypeBase
      81             : {
      82             : public:
      83             :   static InputType*
      84           0 :   Create(mozilla::dom::HTMLInputElement* aInputElement, void* aMemory)
      85             :   {
      86           0 :     return new (aMemory) URLInputType(aInputElement);
      87             :   }
      88             : 
      89             :   bool HasTypeMismatch() const override;
      90             : 
      91             :   nsresult GetTypeMismatchMessage(nsXPIDLString& aMessage) override;
      92             : 
      93             : private:
      94           0 :   explicit URLInputType(mozilla::dom::HTMLInputElement* aInputElement)
      95           0 :     : SingleLineTextInputTypeBase(aInputElement)
      96           0 :   {}
      97             : };
      98             : 
      99             : // input type=email
     100           0 : class EmailInputType : public SingleLineTextInputTypeBase
     101             : {
     102             : public:
     103             :   static InputType*
     104           0 :   Create(mozilla::dom::HTMLInputElement* aInputElement, void* aMemory)
     105             :   {
     106           0 :     return new (aMemory) EmailInputType(aInputElement);
     107             :   }
     108             : 
     109             :   bool HasTypeMismatch() const override;
     110             :   bool HasBadInput() const override;
     111             : 
     112             :   nsresult GetTypeMismatchMessage(nsXPIDLString& aMessage) override;
     113             :   nsresult GetBadInputMessage(nsXPIDLString& aMessage) override;
     114             : 
     115             : private:
     116           0 :   explicit EmailInputType(mozilla::dom::HTMLInputElement* aInputElement)
     117           0 :     : SingleLineTextInputTypeBase(aInputElement)
     118           0 :   {}
     119             : 
     120             :   /**
     121             :    * This helper method returns true if aValue is a valid email address.
     122             :    * This is following the HTML5 specification:
     123             :    * http://dev.w3.org/html5/spec/forms.html#valid-e-mail-address
     124             :    *
     125             :    * @param aValue  the email address to check.
     126             :    * @result        whether the given string is a valid email address.
     127             :    */
     128             :   static bool IsValidEmailAddress(const nsAString& aValue);
     129             : 
     130             :   /**
     131             :    * This helper method returns true if aValue is a valid email address list.
     132             :    * Email address list is a list of email address separated by comas (,) which
     133             :    * can be surrounded by space charecters.
     134             :    * This is following the HTML5 specification:
     135             :    * http://dev.w3.org/html5/spec/forms.html#valid-e-mail-address-list
     136             :    *
     137             :    * @param aValue  the email address list to check.
     138             :    * @result        whether the given string is a valid email address list.
     139             :    */
     140             :   static bool IsValidEmailAddressList(const nsAString& aValue);
     141             : 
     142             :   /**
     143             :    * Takes aEmail and attempts to convert everything after the first "@"
     144             :    * character (if anything) to punycode before returning the complete result
     145             :    * via the aEncodedEmail out-param. The aIndexOfAt out-param is set to the
     146             :    * index of the "@" character.
     147             :    *
     148             :    * If no "@" is found in aEmail, aEncodedEmail is simply set to aEmail and
     149             :    * the aIndexOfAt out-param is set to kNotFound.
     150             :    *
     151             :    * Returns true in all cases unless an attempt to punycode encode fails. If
     152             :    * false is returned, aEncodedEmail has not been set.
     153             :    *
     154             :    * This function exists because ConvertUTF8toACE() splits on ".", meaning that
     155             :    * for 'user.name@sld.tld' it would treat "name@sld" as a label. We want to
     156             :    * encode the domain part only.
     157             :    */
     158             :  static bool PunycodeEncodeEmailAddress(const nsAString& aEmail,
     159             :                                         nsAutoCString& aEncodedEmail,
     160             :                                         uint32_t* aIndexOfAt);
     161             : };
     162             : 
     163             : // input type=password
     164           0 : class PasswordInputType : public SingleLineTextInputTypeBase
     165             : {
     166             : public:
     167             :   static InputType*
     168           0 :   Create(mozilla::dom::HTMLInputElement* aInputElement, void* aMemory)
     169             :   {
     170           0 :     return new (aMemory) PasswordInputType(aInputElement);
     171             :   }
     172             : 
     173             : private:
     174           0 :   explicit PasswordInputType(mozilla::dom::HTMLInputElement* aInputElement)
     175           0 :     : SingleLineTextInputTypeBase(aInputElement)
     176           0 :   {}
     177             : };
     178             : 
     179             : #endif /* SingleLineTextInputTypes_h__ */

Generated by: LCOV version 1.13