Bug 610436 - Add an inline GetValueChanged() in nsHTMLInputElement. r=bz a=bsmedberg
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 24 Nov 2010 00:53:06 +0100
changeset 58149 50dda7cdd3e88588ad9b33fc367c6da6ec7ce5dc
parent 58148 a3fabf61118eb10deff968dd22cc9aa7a8399e4a
child 58150 41e7b8cbd271f7ab01a72479c84c678077127f32
push id17175
push usermlamouri@mozilla.com
push dateWed, 24 Nov 2010 10:15:50 +0000
treeherdermozilla-central@7f5cd850578e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, bsmedberg
bugs610436
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 610436 - Add an inline GetValueChanged() in nsHTMLInputElement. r=bz a=bsmedberg
content/html/content/src/nsHTMLInputElement.cpp
content/html/content/src/nsHTMLInputElement.h
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -716,17 +716,17 @@ nsHTMLInputElement::Clone(nsINodeInfo *a
 
   switch (mType) {
     case NS_FORM_INPUT_EMAIL:
     case NS_FORM_INPUT_SEARCH:
     case NS_FORM_INPUT_TEXT:
     case NS_FORM_INPUT_PASSWORD:
     case NS_FORM_INPUT_TEL:
     case NS_FORM_INPUT_URL:
-      if (GET_BOOLBIT(mBitField, BF_VALUE_CHANGED)) {
+      if (GetValueChanged()) {
         // We don't have our default value anymore.  Set our value on
         // the clone.
         // XXX GetValue should be const
         nsAutoString value;
         const_cast<nsHTMLInputElement*>(this)->GetValue(value);
         // SetValueInternal handles setting the VALUE_CHANGED bit for us
         it->SetValueInternal(value, PR_FALSE, PR_TRUE);
       }
@@ -817,18 +817,17 @@ nsHTMLInputElement::AfterSetAttr(PRInt32
       AddedToRadioGroup();
     }
 
     // If @value is changed and BF_VALUE_CHANGED is false, @value is the value
     // of the element so, if the value of the element is different than @value,
     // we have to re-set it. This is only the case when GetValueMode() returns
     // VALUE_MODE_VALUE.
     if (aName == nsGkAtoms::value &&
-        !GET_BOOLBIT(mBitField, BF_VALUE_CHANGED) &&
-        GetValueMode() == VALUE_MODE_VALUE) {
+        !GetValueChanged() && GetValueMode() == VALUE_MODE_VALUE) {
       SetDefaultValueAsValue();
     }
 
     //
     // Checked must be set no matter what type of control it is, since
     // GetChecked() must reflect the new value
     if (aName == nsGkAtoms::checked &&
         !GET_BOOLBIT(mBitField, BF_CHECKED_CHANGED)) {
@@ -1433,17 +1432,17 @@ nsHTMLInputElement::SetValueInternal(con
   return nsGenericHTMLFormElement::SetAttr(kNameSpaceID_None,
                                            nsGkAtoms::value, aValue,
                                            PR_TRUE);
 }
 
 NS_IMETHODIMP
 nsHTMLInputElement::SetValueChanged(PRBool aValueChanged)
 {
-  PRBool valueChangedBefore = GET_BOOLBIT(mBitField, BF_VALUE_CHANGED);
+  PRBool valueChangedBefore = GetValueChanged();
 
   SET_BOOLBIT(mBitField, BF_VALUE_CHANGED, aValueChanged);
 
   if (!aValueChanged) {
     if (!IsSingleLineTextControl(PR_FALSE)) {
       FreeData();
     }
   }
@@ -1501,23 +1500,16 @@ nsHTMLInputElement::SetCheckedChangedInt
     if (document) {
       mozAutoDocUpdate upd(document, UPDATE_CONTENT_STATE, aNotify);
       document->ContentStatesChanged(this, nsnull,
                                      NS_EVENT_STATE_MOZ_UI_INVALID);
     }
   }
 }
 
-
-PRBool
-nsHTMLInputElement::GetCheckedChanged() const
-{
-  return GET_BOOLBIT(mBitField, BF_CHECKED_CHANGED);
-}
-
 NS_IMETHODIMP
 nsHTMLInputElement::SetChecked(PRBool aChecked)
 {
   return DoSetChecked(aChecked, PR_TRUE, PR_TRUE);
 }
 
 nsresult
 nsHTMLInputElement::DoSetChecked(PRBool aChecked, PRBool aNotify,
@@ -3194,17 +3186,17 @@ nsHTMLInputElement::SaveState()
       break;
     case NS_FORM_INPUT_EMAIL:
     case NS_FORM_INPUT_SEARCH:
     case NS_FORM_INPUT_TEXT:
     case NS_FORM_INPUT_TEL:
     case NS_FORM_INPUT_URL:
     case NS_FORM_INPUT_HIDDEN:
       {
-        if (GET_BOOLBIT(mBitField, BF_VALUE_CHANGED)) {
+        if (GetValueChanged()) {
           inputState = new nsHTMLInputElementState();
           if (!inputState) {
             return NS_ERROR_OUT_OF_MEMORY;
           }
 
           nsAutoString value;
           GetValue(value);
           rv = nsLinebreakConverter::ConvertStringLineBreaks(
@@ -3756,17 +3748,17 @@ nsHTMLInputElement::SetCustomValidity(co
   return NS_OK;
 }
 
 PRBool
 nsHTMLInputElement::IsTooLong()
 {
   if (!MaxLengthApplies() ||
       !HasAttr(kNameSpaceID_None, nsGkAtoms::maxlength) ||
-      !GET_BOOLBIT(mBitField, BF_VALUE_CHANGED)) {
+      !GetValueChanged()) {
     return PR_FALSE;
   }
 
   PRInt32 maxLength = -1;
   GetMaxLength(&maxLength);
 
   // Maxlength of -1 means parsing error.
   if (maxLength == -1) {
@@ -4400,17 +4392,17 @@ nsHTMLInputElement::GetDefaultValueFromC
       SanitizeValue(aValue);
     }
   }
 }
 
 NS_IMETHODIMP_(PRBool)
 nsHTMLInputElement::ValueChanged() const
 {
-  return GET_BOOLBIT(mBitField, BF_VALUE_CHANGED);
+  return GetValueChanged();
 }
 
 NS_IMETHODIMP_(void)
 nsHTMLInputElement::GetTextEditorValue(nsAString& aValue,
                                        PRBool aIgnoreWrap) const
 {
   nsTextEditorState *state = GetEditorState();
   if (state) {
--- a/content/html/content/src/nsHTMLInputElement.h
+++ b/content/html/content/src/nsHTMLInputElement.h
@@ -215,17 +215,19 @@ public:
   NS_IMETHOD_(void) OnValueChanged(PRBool aNotify);
 
   // nsIFileControlElement
   void GetDisplayFileName(nsAString& aFileName) const;
   const nsCOMArray<nsIDOMFile>& GetFiles();
   void SetFiles(const nsCOMArray<nsIDOMFile>& aFiles, bool aSetValueChanged);
 
   void SetCheckedChangedInternal(PRBool aCheckedChanged, PRBool aNotify);
-  PRBool GetCheckedChanged() const;
+  PRBool GetCheckedChanged() const {
+    return GET_BOOLBIT(mBitField, BF_CHECKED_CHANGED);
+  }
   void AddedToRadioGroup(PRBool aNotify = PR_TRUE);
   void WillRemoveFromRadioGroup();
   /**
    * Get the radio group container for this button (form or document)
    * @return the radio group container (or null if no form or document)
    */
   virtual already_AddRefed<nsIRadioGroupContainer> GetRadioGroupContainer();
 
@@ -530,16 +532,24 @@ protected:
   /**
    * Set the current default value to the value of the input element.
    * @note You should not call this method if GetValueMode() doesn't return
    * VALUE_MODE_VALUE.
    */
   nsresult SetDefaultValueAsValue();
 
   /**
+   * Returns whether the value has been changed since the element has been created.
+   * @return Whether the value has been changed since the element has been created.
+   */
+  PRBool GetValueChanged() const {
+    return GET_BOOLBIT(mBitField, BF_VALUE_CHANGED);
+  }
+
+  /**
    * Return if an invalid element should have a specific UI for being invalid
    * (with :-moz-ui-invalid pseudo-class.
    *
    * @return Whether the invalid elemnet should have a UI for being invalid.
    * @note The caller has to be sure the element is invalid before calling.
    */
   bool ShouldShowInvalidUI() const {
     NS_ASSERTION(!IsValid(), "You should not call ShouldShowInvalidUI if the "
@@ -560,17 +570,17 @@ protected:
 
     switch (GetValueMode()) {
       case VALUE_MODE_DEFAULT:
         return true;
       case VALUE_MODE_DEFAULT_ON:
         return GetCheckedChanged();
       case VALUE_MODE_VALUE:
       case VALUE_MODE_FILENAME:
-        return GET_BOOLBIT(mBitField, BF_VALUE_CHANGED);
+        return GetValueChanged();
       default:
         NS_NOTREACHED("We should not be there: there are no other modes.");
         return false;
     }
   }
 
   nsCOMPtr<nsIControllers> mControllers;