LCOV - code coverage report
Current view: directory - content/html/content/src - nsHTMLInputElement.h (source / functions) Found Hit Coverage
Test: app.info Lines: 39 10 25.6 %
Date: 2012-06-02 Functions: 107 8 7.5 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Communicator client code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Pierre Phaneuf <pp@ludusdesign.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsHTMLInputElement_h__
      40                 : #define nsHTMLInputElement_h__
      41                 : 
      42                 : #include "nsGenericHTMLElement.h"
      43                 : #include "nsImageLoadingContent.h"
      44                 : #include "nsIDOMHTMLInputElement.h"
      45                 : #include "nsITextControlElement.h"
      46                 : #include "nsIPhonetic.h"
      47                 : #include "nsIDOMNSEditableElement.h"
      48                 : #include "nsTextEditorState.h"
      49                 : #include "nsCOMPtr.h"
      50                 : #include "nsIConstraintValidation.h"
      51                 : #include "nsDOMFile.h"
      52                 : #include "nsHTMLFormElement.h" // for ShouldShowInvalidUI()
      53                 : #include "nsIFile.h"
      54                 : 
      55                 : class nsDOMFileList;
      56                 : class nsIRadioGroupContainer;
      57                 : class nsIRadioGroupVisitor;
      58                 : class nsIRadioVisitor;
      59                 : 
      60               2 : class UploadLastDir MOZ_FINAL : public nsIObserver, public nsSupportsWeakReference {
      61                 : public:
      62                 :   NS_DECL_ISUPPORTS
      63                 :   NS_DECL_NSIOBSERVER
      64                 : 
      65                 :   /**
      66                 :    * Fetch the last used directory for this location from the content
      67                 :    * pref service, if it is available.
      68                 :    *
      69                 :    * @param aURI URI of the current page
      70                 :    * @param aFile path to the last used directory
      71                 :    */
      72                 :   nsresult FetchLastUsedDirectory(nsIURI* aURI, nsILocalFile** aFile);
      73                 : 
      74                 :   /**
      75                 :    * Store the last used directory for this location using the
      76                 :    * content pref service, if it is available
      77                 :    * @param aURI URI of the current page
      78                 :    * @param aFile file chosen by the user - the path to the parent of this
      79                 :    *        file will be stored
      80                 :    */
      81                 :   nsresult StoreLastUsedDirectory(nsIURI* aURI, nsILocalFile* aFile);
      82                 : };
      83                 : 
      84                 : class nsHTMLInputElement : public nsGenericHTMLFormElement,
      85                 :                            public nsImageLoadingContent,
      86                 :                            public nsIDOMHTMLInputElement,
      87                 :                            public nsITextControlElement,
      88                 :                            public nsIPhonetic,
      89                 :                            public nsIDOMNSEditableElement,
      90                 :                            public nsIConstraintValidation
      91                 : {
      92                 : public:
      93                 :   using nsIConstraintValidation::GetValidationMessage;
      94                 : 
      95                 :   nsHTMLInputElement(already_AddRefed<nsINodeInfo> aNodeInfo,
      96                 :                      mozilla::dom::FromParser aFromParser);
      97                 :   virtual ~nsHTMLInputElement();
      98                 : 
      99                 :   // nsISupports
     100                 :   NS_DECL_ISUPPORTS_INHERITED
     101                 : 
     102                 :   // nsIDOMNode
     103               0 :   NS_FORWARD_NSIDOMNODE(nsGenericHTMLFormElement::)
     104                 : 
     105                 :   // nsIDOMElement
     106               0 :   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFormElement::)
     107                 : 
     108                 :   // nsIDOMHTMLElement
     109               0 :   NS_FORWARD_NSIDOMHTMLELEMENT_BASIC(nsGenericHTMLFormElement::)
     110                 :   NS_SCRIPTABLE NS_IMETHOD Click();
     111                 :   NS_SCRIPTABLE NS_IMETHOD GetTabIndex(PRInt32* aTabIndex);
     112                 :   NS_SCRIPTABLE NS_IMETHOD SetTabIndex(PRInt32 aTabIndex);
     113                 :   NS_SCRIPTABLE NS_IMETHOD Focus();
     114               0 :   NS_SCRIPTABLE NS_IMETHOD GetDraggable(bool* aDraggable) {
     115               0 :     return nsGenericHTMLFormElement::GetDraggable(aDraggable);
     116                 :   }
     117               0 :   NS_SCRIPTABLE NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) {
     118               0 :     return nsGenericHTMLFormElement::GetInnerHTML(aInnerHTML);
     119                 :   }
     120               0 :   NS_SCRIPTABLE NS_IMETHOD SetInnerHTML(const nsAString& aInnerHTML) {
     121               0 :     return nsGenericHTMLFormElement::SetInnerHTML(aInnerHTML);
     122                 :   }
     123                 : 
     124                 :   // nsIDOMHTMLInputElement
     125                 :   NS_DECL_NSIDOMHTMLINPUTELEMENT
     126                 : 
     127                 :   // nsIPhonetic
     128                 :   NS_DECL_NSIPHONETIC
     129                 : 
     130                 :   // nsIDOMNSEditableElement
     131               0 :   NS_IMETHOD GetEditor(nsIEditor** aEditor)
     132                 :   {
     133               0 :     return nsGenericHTMLElement::GetEditor(aEditor);
     134                 :   }
     135                 : 
     136                 :   NS_IMETHOD SetUserInput(const nsAString& aInput);
     137                 : 
     138                 :   // Overriden nsIFormControl methods
     139              12 :   NS_IMETHOD_(PRUint32) GetType() const { return mType; }
     140                 :   NS_IMETHOD Reset();
     141                 :   NS_IMETHOD SubmitNamesValues(nsFormSubmission* aFormSubmission);
     142                 :   NS_IMETHOD SaveState();
     143                 :   virtual bool RestoreState(nsPresState* aState);
     144                 :   virtual bool AllowDrop();
     145                 : 
     146                 :   virtual void FieldSetDisabledChanged(bool aNotify);
     147                 : 
     148                 :   // nsIContent
     149                 :   virtual bool IsHTMLFocusable(bool aWithMouse, bool *aIsFocusable, PRInt32 *aTabIndex);
     150                 : 
     151                 :   virtual bool ParseAttribute(PRInt32 aNamespaceID,
     152                 :                                 nsIAtom* aAttribute,
     153                 :                                 const nsAString& aValue,
     154                 :                                 nsAttrValue& aResult);
     155                 :   virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
     156                 :                                               PRInt32 aModType) const;
     157                 :   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
     158                 :   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
     159                 : 
     160                 :   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
     161                 :   virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
     162                 : 
     163                 :   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
     164                 :                               nsIContent* aBindingParent,
     165                 :                               bool aCompileEventHandlers);
     166                 :   virtual void UnbindFromTree(bool aDeep = true,
     167                 :                               bool aNullParent = true);
     168                 : 
     169                 :   virtual void DoneCreatingElement();
     170                 : 
     171                 :   virtual nsEventStates IntrinsicState() const;
     172                 : 
     173                 :   // nsITextControlElement
     174                 :   NS_IMETHOD SetValueChanged(bool aValueChanged);
     175                 :   NS_IMETHOD_(bool) IsSingleLineTextControl() const;
     176                 :   NS_IMETHOD_(bool) IsTextArea() const;
     177                 :   NS_IMETHOD_(bool) IsPlainTextControl() const;
     178                 :   NS_IMETHOD_(bool) IsPasswordTextControl() const;
     179                 :   NS_IMETHOD_(PRInt32) GetCols();
     180                 :   NS_IMETHOD_(PRInt32) GetWrapCols();
     181                 :   NS_IMETHOD_(PRInt32) GetRows();
     182                 :   NS_IMETHOD_(void) GetDefaultValueFromContent(nsAString& aValue);
     183                 :   NS_IMETHOD_(bool) ValueChanged() const;
     184                 :   NS_IMETHOD_(void) GetTextEditorValue(nsAString& aValue, bool aIgnoreWrap) const;
     185                 :   NS_IMETHOD_(void) SetTextEditorValue(const nsAString& aValue, bool aUserInput);
     186                 :   NS_IMETHOD_(nsIEditor*) GetTextEditor();
     187                 :   NS_IMETHOD_(nsISelectionController*) GetSelectionController();
     188                 :   NS_IMETHOD_(nsFrameSelection*) GetConstFrameSelection();
     189                 :   NS_IMETHOD BindToFrame(nsTextControlFrame* aFrame);
     190                 :   NS_IMETHOD_(void) UnbindFromFrame(nsTextControlFrame* aFrame);
     191                 :   NS_IMETHOD CreateEditor();
     192                 :   NS_IMETHOD_(nsIContent*) GetRootEditorNode();
     193                 :   NS_IMETHOD_(nsIContent*) CreatePlaceholderNode();
     194                 :   NS_IMETHOD_(nsIContent*) GetPlaceholderNode();
     195                 :   NS_IMETHOD_(void) UpdatePlaceholderText(bool aNotify);
     196                 :   NS_IMETHOD_(void) SetPlaceholderClass(bool aVisible, bool aNotify);
     197                 :   NS_IMETHOD_(void) InitializeKeyboardEventListeners();
     198                 :   NS_IMETHOD_(void) OnValueChanged(bool aNotify);
     199                 :   NS_IMETHOD_(bool) HasCachedSelection();
     200                 : 
     201                 :   void GetDisplayFileName(nsAString& aFileName) const;
     202                 :   const nsCOMArray<nsIDOMFile>& GetFiles() const;
     203                 :   void SetFiles(const nsCOMArray<nsIDOMFile>& aFiles, bool aSetValueChanged);
     204                 :   void SetFiles(nsIDOMFileList* aFiles, bool aSetValueChanged);
     205                 : 
     206                 :   void SetCheckedChangedInternal(bool aCheckedChanged);
     207               0 :   bool GetCheckedChanged() const {
     208               0 :     return mCheckedChanged;
     209                 :   }
     210                 :   void AddedToRadioGroup();
     211                 :   void WillRemoveFromRadioGroup();
     212                 : 
     213                 :  /**
     214                 :    * Helper function returning the currently selected button in the radio group.
     215                 :    * Returning null if the element is not a button or if there is no selectied
     216                 :    * button in the group.
     217                 :    *
     218                 :    * @return the selected button (or null).
     219                 :    */
     220                 :   already_AddRefed<nsIDOMHTMLInputElement> GetSelectedRadioButton();
     221                 : 
     222                 :   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
     223                 : 
     224                 :   NS_IMETHOD FireAsyncClickHandler();
     225                 : 
     226               1 :   virtual void UpdateEditableState(bool aNotify)
     227                 :   {
     228               1 :     return UpdateEditableFormControlState(aNotify);
     229                 :   }
     230                 : 
     231            1466 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLInputElement,
     232                 :                                            nsGenericHTMLFormElement)
     233                 : 
     234                 :   static UploadLastDir* gUploadLastDir;
     235                 :   // create and destroy the static UploadLastDir object for remembering
     236                 :   // which directory was last used on a site-by-site basis
     237                 :   static void InitUploadLastDir();
     238                 :   static void DestroyUploadLastDir();
     239                 : 
     240                 :   void MaybeLoadImage();
     241                 : 
     242                 :   virtual nsXPCClassInfo* GetClassInfo();
     243                 : 
     244               0 :   static nsHTMLInputElement* FromContent(nsIContent *aContent)
     245                 :   {
     246               0 :     if (aContent->NodeInfo()->Equals(nsGkAtoms::input, kNameSpaceID_XHTML))
     247               0 :       return static_cast<nsHTMLInputElement*>(aContent);
     248               0 :     return NULL;
     249                 :   }
     250                 : 
     251                 :   // nsIConstraintValidation
     252                 :   bool     IsTooLong();
     253                 :   bool     IsValueMissing() const;
     254                 :   bool     HasTypeMismatch() const;
     255                 :   bool     HasPatternMismatch() const;
     256                 :   void     UpdateTooLongValidityState();
     257                 :   void     UpdateValueMissingValidityState();
     258                 :   void     UpdateTypeMismatchValidityState();
     259                 :   void     UpdatePatternMismatchValidityState();
     260                 :   void     UpdateAllValidityStates(bool aNotify);
     261                 :   void     UpdateBarredFromConstraintValidation();
     262                 :   nsresult GetValidationMessage(nsAString& aValidationMessage,
     263                 :                                 ValidityStateType aType);
     264                 :   /**
     265                 :    * Update the value missing validity state for radio elements when they have
     266                 :    * a group.
     267                 :    *
     268                 :    * @param aIgnoreSelf Whether the required attribute and the checked state
     269                 :    * of the current radio should be ignored.
     270                 :    * @note This method shouldn't be called if the radio elemnet hasn't a group.
     271                 :    */
     272                 :   void     UpdateValueMissingValidityStateForRadio(bool aIgnoreSelf);
     273                 : 
     274                 :   /**
     275                 :    * Returns the filter which should be used for the file picker according to
     276                 :    * the accept attribute value.
     277                 :    *
     278                 :    * See:
     279                 :    * http://dev.w3.org/html5/spec/forms.html#attr-input-accept
     280                 :    *
     281                 :    * @return Filter to use on the file picker with AppendFilters, 0 if none.
     282                 :    *
     283                 :    * @note You should not call this function if the element has no @accept.
     284                 :    * @note This will only filter for one type of file. If more than one filter
     285                 :    * is specified by the accept attribute they will *all* be ignored.
     286                 :    */
     287                 :   PRInt32 GetFilterFromAccept();
     288                 : 
     289                 :   /**
     290                 :    * The form might need to request an update of the UI bits
     291                 :    * (BF_CAN_SHOW_INVALID_UI and BF_CAN_SHOW_VALID_UI) when an invalid form
     292                 :    * submission is tried.
     293                 :    *
     294                 :    * @param aIsFocused Whether the element is currently focused.
     295                 :    *
     296                 :    * @note The caller is responsible to call ContentStatesChanged.
     297                 :    */
     298                 :   void UpdateValidityUIBits(bool aIsFocused);
     299                 : 
     300               0 :   bool DefaultChecked() const {
     301               0 :     return HasAttr(kNameSpaceID_None, nsGkAtoms::checked);
     302                 :   }
     303                 : 
     304                 : protected:
     305                 :   // Pull IsSingleLineTextControl into our scope, otherwise it'd be hidden
     306                 :   // by the nsITextControlElement version.
     307                 :   using nsGenericHTMLFormElement::IsSingleLineTextControl;
     308                 : 
     309                 :   /**
     310                 :    * The ValueModeType specifies how the value IDL attribute should behave.
     311                 :    *
     312                 :    * See: http://dev.w3.org/html5/spec/forms.html#dom-input-value
     313                 :    */
     314                 :   enum ValueModeType
     315                 :   {
     316                 :     // On getting, returns the value.
     317                 :     // On setting, sets value.
     318                 :     VALUE_MODE_VALUE,
     319                 :     // On getting, returns the value if present or the empty string.
     320                 :     // On setting, sets the value.
     321                 :     VALUE_MODE_DEFAULT,
     322                 :     // On getting, returns the value if present or "on".
     323                 :     // On setting, sets the value.
     324                 :     VALUE_MODE_DEFAULT_ON,
     325                 :     // On getting, returns "C:\fakepath\" followed by the file name of the
     326                 :     // first file of the selected files if any.
     327                 :     // On setting the empty string, empties the selected files list, otherwise
     328                 :     // throw the INVALID_STATE_ERR exception.
     329                 :     VALUE_MODE_FILENAME
     330                 :   };
     331                 : 
     332                 :   /**
     333                 :    * This helper method returns true if aValue is a valid email address.
     334                 :    * This is following the HTML5 specification:
     335                 :    * http://dev.w3.org/html5/spec/forms.html#valid-e-mail-address
     336                 :    *
     337                 :    * @param aValue  the email address to check.
     338                 :    * @result        whether the given string is a valid email address.
     339                 :    */
     340                 :   static bool IsValidEmailAddress(const nsAString& aValue);
     341                 : 
     342                 :   /**
     343                 :    * This helper method returns true if aValue is a valid email address list.
     344                 :    * Email address list is a list of email address separated by comas (,) which
     345                 :    * can be surrounded by space charecters.
     346                 :    * This is following the HTML5 specification:
     347                 :    * http://dev.w3.org/html5/spec/forms.html#valid-e-mail-address-list
     348                 :    *
     349                 :    * @param aValue  the email address list to check.
     350                 :    * @result        whether the given string is a valid email address list.
     351                 :    */
     352                 :   static bool IsValidEmailAddressList(const nsAString& aValue);
     353                 : 
     354                 :   // Helper method
     355                 :   nsresult SetValueInternal(const nsAString& aValue,
     356                 :                             bool aUserInput,
     357                 :                             bool aSetValueChanged);
     358                 : 
     359                 :   nsresult GetValueInternal(nsAString& aValue) const;
     360                 : 
     361                 :   /**
     362                 :    * Returns whether the current value is the empty string.
     363                 :    *
     364                 :    * @return whether the current value is the empty string.
     365                 :    */
     366                 :   bool IsValueEmpty() const;
     367                 : 
     368               0 :   void ClearFiles(bool aSetValueChanged) {
     369               0 :     nsCOMArray<nsIDOMFile> files;
     370               0 :     SetFiles(files, aSetValueChanged);
     371               0 :   }
     372                 : 
     373                 :   nsresult SetIndeterminateInternal(bool aValue,
     374                 :                                     bool aShouldInvalidate);
     375                 : 
     376                 :   nsresult GetSelectionRange(PRInt32* aSelectionStart, PRInt32* aSelectionEnd);
     377                 : 
     378                 :   /**
     379                 :    * Called when an attribute is about to be changed
     380                 :    */
     381                 :   virtual nsresult BeforeSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     382                 :                                  const nsAttrValueOrString* aValue,
     383                 :                                  bool aNotify);
     384                 :   /**
     385                 :    * Called when an attribute has just been changed
     386                 :    */
     387                 :   virtual nsresult AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     388                 :                                 const nsAttrValue* aValue, bool aNotify);
     389                 : 
     390                 :   /**
     391                 :    * Dispatch a select event. Returns true if the event was not cancelled.
     392                 :    */
     393                 :   bool DispatchSelectEvent(nsPresContext* aPresContext);
     394                 : 
     395                 :   void SelectAll(nsPresContext* aPresContext);
     396                 :   bool IsImage() const
     397                 :   {
     398                 :     return AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
     399                 :                        nsGkAtoms::image, eIgnoreCase);
     400                 :   }
     401                 : 
     402                 :   /**
     403                 :    * Visit the group of radio buttons this radio belongs to
     404                 :    * @param aVisitor the visitor to visit with
     405                 :    */
     406                 :   nsresult VisitGroup(nsIRadioVisitor* aVisitor, bool aFlushContent);
     407                 : 
     408                 :   /**
     409                 :    * Do all the work that |SetChecked| does (radio button handling, etc.), but
     410                 :    * take an |aNotify| parameter.
     411                 :    */
     412                 :   nsresult DoSetChecked(bool aValue, bool aNotify, bool aSetValueChanged);
     413                 : 
     414                 :   /**
     415                 :    * Do all the work that |SetCheckedChanged| does (radio button handling,
     416                 :    * etc.), but take an |aNotify| parameter that lets it avoid flushing content
     417                 :    * when it can.
     418                 :    */
     419                 :   void DoSetCheckedChanged(bool aCheckedChanged, bool aNotify);
     420                 : 
     421                 :   /**
     422                 :    * Actually set checked and notify the frame of the change.
     423                 :    * @param aValue the value of checked to set
     424                 :    */
     425                 :   void SetCheckedInternal(bool aValue, bool aNotify);
     426                 : 
     427                 :   nsresult RadioSetChecked(bool aNotify);
     428                 :   void SetCheckedChanged(bool aCheckedChanged);
     429                 : 
     430                 :   /**
     431                 :    * MaybeSubmitForm looks for a submit input or a single text control
     432                 :    * and submits the form if either is present.
     433                 :    */
     434                 :   nsresult MaybeSubmitForm(nsPresContext* aPresContext);
     435                 : 
     436                 :   /**
     437                 :    * Update mFileList with the currently selected file.
     438                 :    */
     439                 :   nsresult UpdateFileList();
     440                 : 
     441                 :   /**
     442                 :    * Called after calling one of the SetFiles() functions.
     443                 :    */
     444                 :   void AfterSetFiles(bool aSetValueChanged);
     445                 : 
     446                 :   /**
     447                 :    * Determine whether the editor needs to be initialized explicitly for
     448                 :    * a particular event.
     449                 :    */
     450                 :   bool NeedToInitializeEditorForEvent(nsEventChainPreVisitor& aVisitor) const;
     451                 : 
     452                 :   /**
     453                 :    * Get the value mode of the element, depending of the type.
     454                 :    */
     455                 :   ValueModeType GetValueMode() const;
     456                 : 
     457                 :   /**
     458                 :    * Get the mutable state of the element.
     459                 :    * When the element isn't mutable (immutable), the value or checkedness
     460                 :    * should not be changed by the user.
     461                 :    *
     462                 :    * See: http://dev.w3.org/html5/spec/forms.html#concept-input-mutable
     463                 :    */
     464                 :   bool IsMutable() const;
     465                 : 
     466                 :   /**
     467                 :    * Returns if the readonly attribute applies for the current type.
     468                 :    */
     469                 :   bool DoesReadOnlyApply() const;
     470                 : 
     471                 :   /**
     472                 :    * Returns if the required attribute applies for the current type.
     473                 :    */
     474                 :   bool DoesRequiredApply() const;
     475                 : 
     476                 :   /**
     477                 :    * Returns if the pattern attribute applies for the current type.
     478                 :    */
     479                 :   bool DoesPatternApply() const;
     480                 : 
     481                 :   /**
     482                 :    * Returns if the maxlength attribute applies for the current type.
     483                 :    */
     484               0 :   bool MaxLengthApplies() const { return IsSingleLineTextControl(false, mType); }
     485                 : 
     486                 :   void FreeData();
     487                 :   nsTextEditorState *GetEditorState() const;
     488                 : 
     489                 :   /**
     490                 :    * Manages the internal data storage across type changes.
     491                 :    */
     492                 :   void HandleTypeChange(PRUint8 aNewType);
     493                 : 
     494                 :   /**
     495                 :    * Sanitize the value of the element depending of its current type.
     496                 :    * See: http://www.whatwg.org/specs/web-apps/current-work/#value-sanitization-algorithm
     497                 :    */
     498                 :   void SanitizeValue(nsAString& aValue);
     499                 : 
     500                 :   /**
     501                 :    * Returns whether the placeholder attribute applies for the current type.
     502                 :    */
     503               7 :   bool PlaceholderApplies() const { return IsSingleLineTextControl(false, mType); }
     504                 : 
     505                 :   /**
     506                 :    * Set the current default value to the value of the input element.
     507                 :    * @note You should not call this method if GetValueMode() doesn't return
     508                 :    * VALUE_MODE_VALUE.
     509                 :    */
     510                 :   nsresult SetDefaultValueAsValue();
     511                 : 
     512                 :   /**
     513                 :    * Return if an element should have a specific validity UI
     514                 :    * (with :-moz-ui-invalid and :-moz-ui-valid pseudo-classes).
     515                 :    *
     516                 :    * @return Whether the elemnet should have a validity UI.
     517                 :    */
     518               5 :   bool ShouldShowValidityUI() const {
     519                 :     /**
     520                 :      * Always show the validity UI if the form has already tried to be submitted
     521                 :      * but was invalid.
     522                 :      *
     523                 :      * Otherwise, show the validity UI if the element's value has been changed.
     524                 :      */
     525               5 :     if (mForm && mForm->HasEverTriedInvalidSubmit()) {
     526               0 :       return true;
     527                 :     }
     528                 : 
     529               5 :     switch (GetValueMode()) {
     530                 :       case VALUE_MODE_DEFAULT:
     531               0 :         return true;
     532                 :       case VALUE_MODE_DEFAULT_ON:
     533               0 :         return GetCheckedChanged();
     534                 :       case VALUE_MODE_VALUE:
     535                 :       case VALUE_MODE_FILENAME:
     536               5 :         return mValueChanged;
     537                 :       default:
     538               0 :         NS_NOTREACHED("We should not be there: there are no other modes.");
     539               0 :         return false;
     540                 :     }
     541                 :   }
     542                 : 
     543                 :   /**
     544                 :    * Returns the radio group container if the element has one, null otherwise.
     545                 :    * The radio group container will be the form owner if there is one.
     546                 :    * The current document otherwise.
     547                 :    * @return the radio group container if the element has one, null otherwise.
     548                 :    */
     549                 :   nsIRadioGroupContainer* GetRadioGroupContainer() const;
     550                 : 
     551                 :   nsCOMPtr<nsIControllers> mControllers;
     552                 : 
     553                 :   /*
     554                 :    * In mInputData, the mState field is used if IsSingleLineTextControl returns
     555                 :    * true and mValue is used otherwise.  We have to be careful when handling it
     556                 :    * on a type change.
     557                 :    *
     558                 :    * Accessing the mState member should be done using the GetEditorState function,
     559                 :    * which returns null if the state is not present.
     560                 :    */
     561                 :   union InputData {
     562                 :     /**
     563                 :      * The current value of the input if it has been changed from the default
     564                 :      */
     565                 :     char*                    mValue;
     566                 :     /**
     567                 :      * The state of the text editor associated with the text/password input
     568                 :      */
     569                 :     nsTextEditorState*       mState;
     570                 :   } mInputData;
     571                 :   /**
     572                 :    * The value of the input if it is a file input. This is the list of filenames
     573                 :    * used when uploading a file. It is vital that this is kept separate from
     574                 :    * mValue so that it won't be possible to 'leak' the value from a text-input
     575                 :    * to a file-input. Additionally, the logic for this value is kept as simple
     576                 :    * as possible to avoid accidental errors where the wrong filename is used.
     577                 :    * Therefor the list of filenames is always owned by this member, never by
     578                 :    * the frame. Whenever the frame wants to change the filename it has to call
     579                 :    * SetFileNames to update this member.
     580                 :    */
     581                 :   nsCOMArray<nsIDOMFile>   mFiles;
     582                 : 
     583                 :   nsRefPtr<nsDOMFileList>  mFileList;
     584                 : 
     585                 :   nsString mStaticDocFileList;
     586                 : 
     587                 :   /**
     588                 :    * The type of this input (<input type=...>) as an integer.
     589                 :    * @see nsIFormControl.h (specifically NS_FORM_INPUT_*)
     590                 :    */
     591                 :   PRUint8                  mType;
     592                 :   bool                     mDisabledChanged     : 1;
     593                 :   bool                     mValueChanged        : 1;
     594                 :   bool                     mCheckedChanged      : 1;
     595                 :   bool                     mChecked             : 1;
     596                 :   bool                     mHandlingSelectEvent : 1;
     597                 :   bool                     mShouldInitChecked   : 1;
     598                 :   bool                     mParserCreating      : 1;
     599                 :   bool                     mInInternalActivate  : 1;
     600                 :   bool                     mCheckedIsToggled    : 1;
     601                 :   bool                     mIndeterminate       : 1;
     602                 :   bool                     mInhibitRestoration  : 1;
     603                 :   bool                     mCanShowValidUI      : 1;
     604                 :   bool                     mCanShowInvalidUI    : 1;
     605                 : };
     606                 : 
     607                 : #endif

Generated by: LCOV version 1.7