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()) {
// 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);
GetValueInternal(value);
// SetValueInternal handles setting the VALUE_CHANGED bit for us
it->SetValueInternal(value, PR_FALSE, PR_TRUE);
}
@ -1042,6 +1041,12 @@ nsHTMLInputElement::SetIndeterminate(PRBool aValue)
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<nsIDOMFile>& aFiles,
}
const nsCOMArray<nsIDOMFile>&
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;

View File

@ -214,9 +214,8 @@ public:
NS_IMETHOD_(void) InitializeKeyboardEventListeners();
NS_IMETHOD_(void) OnValueChanged(PRBool aNotify);
// nsIFileControlElement
void GetDisplayFileName(nsAString& aFileName) const;
const nsCOMArray<nsIDOMFile>& GetFiles();
const nsCOMArray<nsIDOMFile>& GetFiles() const;
void SetFiles(const nsCOMArray<nsIDOMFile>& 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<nsIDOMFile> files;
SetFiles(files, aSetValueChanged);