Bug 1295403 - Implement the step attribute for <input type=week>. r=smaug

This commit is contained in:
Jessica Jong
2016-10-07 15:04:54 +08:00
parent ba5622c71b
commit 67d066b2e9
8 changed files with 258 additions and 26 deletions

View File

@@ -211,7 +211,9 @@ const Decimal HTMLInputElement::kStepScaleFactorDate = Decimal(86400000);
const Decimal HTMLInputElement::kStepScaleFactorNumberRange = Decimal(1);
const Decimal HTMLInputElement::kStepScaleFactorTime = Decimal(1000);
const Decimal HTMLInputElement::kStepScaleFactorMonth = Decimal(1);
const Decimal HTMLInputElement::kStepScaleFactorWeek = Decimal(7 * 86400000);
const Decimal HTMLInputElement::kDefaultStepBase = Decimal(0);
const Decimal HTMLInputElement::kDefaultStepBaseWeek = Decimal(-259200000);
const Decimal HTMLInputElement::kDefaultStep = Decimal(1);
const Decimal HTMLInputElement::kDefaultStepTime = Decimal(60);
const Decimal HTMLInputElement::kStepAny = Decimal(0);
@@ -2381,6 +2383,7 @@ HTMLInputElement::GetStepBase() const
mType == NS_FORM_INPUT_DATE ||
mType == NS_FORM_INPUT_TIME ||
mType == NS_FORM_INPUT_MONTH ||
mType == NS_FORM_INPUT_WEEK ||
mType == NS_FORM_INPUT_RANGE,
"Check that kDefaultStepBase is correct for this new type");
@@ -2401,6 +2404,10 @@ HTMLInputElement::GetStepBase() const
return stepBase;
}
if (mType == NS_FORM_INPUT_WEEK) {
return kDefaultStepBaseWeek;
}
return kDefaultStepBase;
}
@@ -7353,7 +7360,8 @@ HTMLInputElement::GetStep() const
}
// For input type=date, we round the step value to have a rounded day.
if (mType == NS_FORM_INPUT_DATE || mType == NS_FORM_INPUT_MONTH) {
if (mType == NS_FORM_INPUT_DATE || mType == NS_FORM_INPUT_MONTH ||
mType == NS_FORM_INPUT_WEEK) {
step = std::max(step.round(), Decimal(1));
}
@@ -8489,6 +8497,8 @@ HTMLInputElement::GetStepScaleFactor() const
return kStepScaleFactorTime;
case NS_FORM_INPUT_MONTH:
return kStepScaleFactorMonth;
case NS_FORM_INPUT_WEEK:
return kStepScaleFactorWeek;
default:
MOZ_ASSERT(false, "Unrecognized input type");
return Decimal::nan();
@@ -8503,6 +8513,7 @@ HTMLInputElement::GetDefaultStep() const
switch (mType) {
case NS_FORM_INPUT_DATE:
case NS_FORM_INPUT_MONTH:
case NS_FORM_INPUT_WEEK:
case NS_FORM_INPUT_NUMBER:
case NS_FORM_INPUT_RANGE:
return kDefaultStep;