Bug 585097 - Add a GetValue() const to nsHTMLInputElement and make some other methods const. r=bz

This commit is contained in:
Mounir Lamouri 2011-03-09 19:25:20 +01:00
parent 01a16652cf
commit 8d00fff243
2 changed files with 22 additions and 23 deletions

View File

@ -723,9 +723,8 @@ nsHTMLInputElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
if (GetValueChanged()) { if (GetValueChanged()) {
// We don't have our default value anymore. Set our value on // We don't have our default value anymore. Set our value on
// the clone. // the clone.
// XXX GetValue should be const
nsAutoString value; nsAutoString value;
const_cast<nsHTMLInputElement*>(this)->GetValue(value); GetValueInternal(value);
// SetValueInternal handles setting the VALUE_CHANGED bit for us // SetValueInternal handles setting the VALUE_CHANGED bit for us
it->SetValueInternal(value, PR_FALSE, PR_TRUE); it->SetValueInternal(value, PR_FALSE, PR_TRUE);
} }
@ -1040,8 +1039,14 @@ nsHTMLInputElement::SetIndeterminate(PRBool aValue)
return SetIndeterminateInternal(aValue, PR_TRUE); return SetIndeterminateInternal(aValue, PR_TRUE);
} }
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLInputElement::GetValue(nsAString& aValue) nsHTMLInputElement::GetValue(nsAString& aValue)
{
return GetValueInternal(aValue);
}
nsresult
nsHTMLInputElement::GetValueInternal(nsAString& aValue) const
{ {
nsTextEditorState* state = GetEditorState(); nsTextEditorState* state = GetEditorState();
if (state) { if (state) {
@ -1377,7 +1382,7 @@ nsHTMLInputElement::SetFiles(const nsCOMArray<nsIDOMFile>& aFiles,
} }
const nsCOMArray<nsIDOMFile>& const nsCOMArray<nsIDOMFile>&
nsHTMLInputElement::GetFiles() nsHTMLInputElement::GetFiles() const
{ {
return mFiles; return mFiles;
} }
@ -3367,15 +3372,8 @@ nsHTMLInputElement::IntrinsicState() const
if (PlaceholderApplies() && HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder) && if (PlaceholderApplies() && HasAttr(kNameSpaceID_None, nsGkAtoms::placeholder) &&
!nsContentUtils::IsFocusedContent((nsIContent*)(this))) { !nsContentUtils::IsFocusedContent((nsIContent*)(this))) {
// TODO: we really need a GetValue(...) const method, see bug 585097
nsTextEditorState* edState = GetEditorState();
nsAutoString value; nsAutoString value;
GetValueInternal(value);
if (edState) {
edState->GetValue(value, PR_TRUE);
} else {
GetAttr(kNameSpaceID_None, nsGkAtoms::value, value);
}
if (value.IsEmpty()) { if (value.IsEmpty()) {
state |= NS_EVENT_STATE_MOZ_PLACEHOLDER; state |= NS_EVENT_STATE_MOZ_PLACEHOLDER;
@ -3815,7 +3813,7 @@ nsHTMLInputElement::IsTooLong()
} }
PRBool PRBool
nsHTMLInputElement::IsValueMissing() nsHTMLInputElement::IsValueMissing() const
{ {
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::required) || if (!HasAttr(kNameSpaceID_None, nsGkAtoms::required) ||
!DoesRequiredApply()) { !DoesRequiredApply()) {
@ -3828,7 +3826,7 @@ nsHTMLInputElement::IsValueMissing()
} }
nsAutoString value; nsAutoString value;
NS_ENSURE_SUCCESS(GetValue(value), PR_FALSE); NS_ENSURE_SUCCESS(GetValueInternal(value), PR_FALSE);
return value.IsEmpty(); return value.IsEmpty();
} }
@ -3848,14 +3846,14 @@ nsHTMLInputElement::IsValueMissing()
} }
PRBool PRBool
nsHTMLInputElement::HasTypeMismatch() nsHTMLInputElement::HasTypeMismatch() const
{ {
if (mType != NS_FORM_INPUT_EMAIL && mType != NS_FORM_INPUT_URL) { if (mType != NS_FORM_INPUT_EMAIL && mType != NS_FORM_INPUT_URL) {
return PR_FALSE; return PR_FALSE;
} }
nsAutoString value; nsAutoString value;
NS_ENSURE_SUCCESS(GetValue(value), PR_FALSE); NS_ENSURE_SUCCESS(GetValueInternal(value), PR_FALSE);
if (value.IsEmpty()) { if (value.IsEmpty()) {
return PR_FALSE; return PR_FALSE;
@ -3887,7 +3885,7 @@ nsHTMLInputElement::HasTypeMismatch()
} }
PRBool PRBool
nsHTMLInputElement::HasPatternMismatch() nsHTMLInputElement::HasPatternMismatch() const
{ {
nsAutoString pattern; nsAutoString pattern;
if (!DoesPatternApply() || if (!DoesPatternApply() ||
@ -3896,7 +3894,7 @@ nsHTMLInputElement::HasPatternMismatch()
} }
nsAutoString value; nsAutoString value;
NS_ENSURE_SUCCESS(GetValue(value), PR_FALSE); NS_ENSURE_SUCCESS(GetValueInternal(value), PR_FALSE);
if (value.IsEmpty()) { if (value.IsEmpty()) {
return PR_FALSE; return PR_FALSE;

View File

@ -214,9 +214,8 @@ public:
NS_IMETHOD_(void) InitializeKeyboardEventListeners(); NS_IMETHOD_(void) InitializeKeyboardEventListeners();
NS_IMETHOD_(void) OnValueChanged(PRBool aNotify); NS_IMETHOD_(void) OnValueChanged(PRBool aNotify);
// nsIFileControlElement
void GetDisplayFileName(nsAString& aFileName) const; void GetDisplayFileName(nsAString& aFileName) const;
const nsCOMArray<nsIDOMFile>& GetFiles(); const nsCOMArray<nsIDOMFile>& GetFiles() const;
void SetFiles(const nsCOMArray<nsIDOMFile>& aFiles, bool aSetValueChanged); void SetFiles(const nsCOMArray<nsIDOMFile>& aFiles, bool aSetValueChanged);
void SetCheckedChangedInternal(PRBool aCheckedChanged); void SetCheckedChangedInternal(PRBool aCheckedChanged);
@ -271,9 +270,9 @@ public:
// nsIConstraintValidation // nsIConstraintValidation
PRBool IsTooLong(); PRBool IsTooLong();
PRBool IsValueMissing(); PRBool IsValueMissing() const;
PRBool HasTypeMismatch(); PRBool HasTypeMismatch() const;
PRBool HasPatternMismatch(); PRBool HasPatternMismatch() const;
void UpdateTooLongValidityState(); void UpdateTooLongValidityState();
void UpdateValueMissingValidityState(); void UpdateValueMissingValidityState();
void UpdateTypeMismatchValidityState(); void UpdateTypeMismatchValidityState();
@ -390,6 +389,8 @@ protected:
PRBool aUserInput, PRBool aUserInput,
PRBool aSetValueChanged); PRBool aSetValueChanged);
nsresult GetValueInternal(nsAString& aValue) const;
void ClearFiles(bool aSetValueChanged) { void ClearFiles(bool aSetValueChanged) {
nsCOMArray<nsIDOMFile> files; nsCOMArray<nsIDOMFile> files;
SetFiles(files, aSetValueChanged); SetFiles(files, aSetValueChanged);