From 8d00fff243a5c718cfa2cddd28118eb216217236 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Wed, 9 Mar 2011 19:25:20 +0100 Subject: [PATCH] Bug 585097 - Add a GetValue() const to nsHTMLInputElement and make some other methods const. r=bz --- .../html/content/src/nsHTMLInputElement.cpp | 34 +++++++++---------- content/html/content/src/nsHTMLInputElement.h | 11 +++--- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index 6ba95978f02..69af1185561 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -723,9 +723,8 @@ nsHTMLInputElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const 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(this)->GetValue(value); + GetValueInternal(value); // SetValueInternal handles setting the VALUE_CHANGED bit for us it->SetValueInternal(value, PR_FALSE, PR_TRUE); } @@ -1040,8 +1039,14 @@ nsHTMLInputElement::SetIndeterminate(PRBool aValue) return SetIndeterminateInternal(aValue, PR_TRUE); } -NS_IMETHODIMP +NS_IMETHODIMP nsHTMLInputElement::GetValue(nsAString& aValue) +{ + return GetValueInternal(aValue); +} + +nsresult +nsHTMLInputElement::GetValueInternal(nsAString& aValue) const { nsTextEditorState* state = GetEditorState(); if (state) { @@ -1377,7 +1382,7 @@ nsHTMLInputElement::SetFiles(const nsCOMArray& aFiles, } const nsCOMArray& -nsHTMLInputElement::GetFiles() +nsHTMLInputElement::GetFiles() const { return mFiles; } @@ -3367,15 +3372,8 @@ nsHTMLInputElement::IntrinsicState() const if (PlaceholderApplies() && HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder) && !nsContentUtils::IsFocusedContent((nsIContent*)(this))) { - // TODO: we really need a GetValue(...) const method, see bug 585097 - nsTextEditorState* edState = GetEditorState(); nsAutoString value; - - if (edState) { - edState->GetValue(value, PR_TRUE); - } else { - GetAttr(kNameSpaceID_None, nsGkAtoms::value, value); - } + GetValueInternal(value); if (value.IsEmpty()) { state |= NS_EVENT_STATE_MOZ_PLACEHOLDER; @@ -3815,7 +3813,7 @@ nsHTMLInputElement::IsTooLong() } PRBool -nsHTMLInputElement::IsValueMissing() +nsHTMLInputElement::IsValueMissing() const { if (!HasAttr(kNameSpaceID_None, nsGkAtoms::required) || !DoesRequiredApply()) { @@ -3828,7 +3826,7 @@ nsHTMLInputElement::IsValueMissing() } nsAutoString value; - NS_ENSURE_SUCCESS(GetValue(value), PR_FALSE); + NS_ENSURE_SUCCESS(GetValueInternal(value), PR_FALSE); return value.IsEmpty(); } @@ -3848,14 +3846,14 @@ nsHTMLInputElement::IsValueMissing() } PRBool -nsHTMLInputElement::HasTypeMismatch() +nsHTMLInputElement::HasTypeMismatch() const { if (mType != NS_FORM_INPUT_EMAIL && mType != NS_FORM_INPUT_URL) { return PR_FALSE; } nsAutoString value; - NS_ENSURE_SUCCESS(GetValue(value), PR_FALSE); + NS_ENSURE_SUCCESS(GetValueInternal(value), PR_FALSE); if (value.IsEmpty()) { return PR_FALSE; @@ -3887,7 +3885,7 @@ nsHTMLInputElement::HasTypeMismatch() } PRBool -nsHTMLInputElement::HasPatternMismatch() +nsHTMLInputElement::HasPatternMismatch() const { nsAutoString pattern; if (!DoesPatternApply() || @@ -3896,7 +3894,7 @@ nsHTMLInputElement::HasPatternMismatch() } nsAutoString value; - NS_ENSURE_SUCCESS(GetValue(value), PR_FALSE); + NS_ENSURE_SUCCESS(GetValueInternal(value), PR_FALSE); if (value.IsEmpty()) { return PR_FALSE; diff --git a/content/html/content/src/nsHTMLInputElement.h b/content/html/content/src/nsHTMLInputElement.h index 2ec3be60071..d23b0d21b99 100644 --- a/content/html/content/src/nsHTMLInputElement.h +++ b/content/html/content/src/nsHTMLInputElement.h @@ -214,9 +214,8 @@ public: NS_IMETHOD_(void) InitializeKeyboardEventListeners(); NS_IMETHOD_(void) OnValueChanged(PRBool aNotify); - // nsIFileControlElement void GetDisplayFileName(nsAString& aFileName) const; - const nsCOMArray& GetFiles(); + const nsCOMArray& GetFiles() const; void SetFiles(const nsCOMArray& aFiles, bool aSetValueChanged); void SetCheckedChangedInternal(PRBool aCheckedChanged); @@ -271,9 +270,9 @@ public: // nsIConstraintValidation PRBool IsTooLong(); - PRBool IsValueMissing(); - PRBool HasTypeMismatch(); - PRBool HasPatternMismatch(); + PRBool IsValueMissing() const; + PRBool HasTypeMismatch() const; + PRBool HasPatternMismatch() const; void UpdateTooLongValidityState(); void UpdateValueMissingValidityState(); void UpdateTypeMismatchValidityState(); @@ -390,6 +389,8 @@ protected: PRBool aUserInput, PRBool aSetValueChanged); + nsresult GetValueInternal(nsAString& aValue) const; + void ClearFiles(bool aSetValueChanged) { nsCOMArray files; SetFiles(files, aSetValueChanged);