Bug 635554 (1/2) - Keep track of whether an input element has a range applying. r=sicking

--HG--
extra : rebase_source : b1f577c5acaa70da105352e4d682f608cf938010
This commit is contained in:
Mounir Lamouri 2012-06-22 11:41:32 +02:00
Родитель 5362c65903
Коммит 0ac84a9cf1
2 изменённых файлов: 41 добавлений и 0 удалений

Просмотреть файл

@ -525,6 +525,7 @@ nsHTMLInputElement::nsHTMLInputElement(already_AddRefed<nsINodeInfo> aNodeInfo,
, mInhibitRestoration(aFromParser & FROM_PARSER_FRAGMENT)
, mCanShowValidUI(true)
, mCanShowInvalidUI(true)
, mHasRange(false)
{
mInputData.mState = new nsTextEditorState(this);
@ -814,8 +815,10 @@ nsHTMLInputElement::AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
} else if (aName == nsGkAtoms::multiple) {
UpdateTypeMismatchValidityState();
} else if (aName == nsGkAtoms::max) {
UpdateHasRange();
UpdateRangeOverflowValidityState();
} else if (aName == nsGkAtoms::min) {
UpdateHasRange();
UpdateRangeUnderflowValidityState();
}
@ -2453,6 +2456,8 @@ nsHTMLInputElement::HandleTypeChange(PRUint8 aNewType)
}
}
UpdateHasRange();
// Do not notify, it will be done after if needed.
UpdateAllValidityStates(false);
}
@ -4499,3 +4504,33 @@ nsHTMLInputElement::UpdateValidityUIBits(bool aIsFocused)
}
}
void
nsHTMLInputElement::UpdateHasRange()
{
mHasRange = false;
if (mType != NS_FORM_INPUT_NUMBER) {
return;
}
// <input type=number> has a range if min or max is a valid float number.
nsAutoString tmpStr;
if (GetAttr(kNameSpaceID_None, nsGkAtoms::min, tmpStr)) {
PRInt32 ec;
tmpStr.ToDouble(&ec);
if (NS_SUCCEEDED(ec)) {
mHasRange = true;
return;
}
}
if (GetAttr(kNameSpaceID_None, nsGkAtoms::max, tmpStr)) {
PRInt32 ec;
tmpStr.ToDouble(&ec);
if (NS_SUCCEEDED(ec)) {
mHasRange = true;
return;
}
}
}

Просмотреть файл

@ -550,6 +550,11 @@ protected:
*/
double GetValueAsDouble() const;
/**
* Update the HAS_RANGE bit field value.
*/
void UpdateHasRange();
nsCOMPtr<nsIControllers> mControllers;
/*
@ -613,6 +618,7 @@ protected:
bool mInhibitRestoration : 1;
bool mCanShowValidUI : 1;
bool mCanShowInvalidUI : 1;
bool mHasRange : 1;
private:
struct nsFilePickerFilter {