Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: Source/WebCore/html/shadow/DateTimeEditElement.cpp

Issue 11420033: Merge 134390 - Unable to set valid time value to input[type=time] with user interaction in some cas… (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1312/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp ('k') | Source/WebCore/platform/Decimal.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/WebCore/html/shadow/DateTimeEditElement.cpp
===================================================================
--- Source/WebCore/html/shadow/DateTimeEditElement.cpp (revision 134891)
+++ Source/WebCore/html/shadow/DateTimeEditElement.cpp (working copy)
@@ -56,6 +56,7 @@
private:
bool needMillisecondField() const;
+ bool shouldHourFieldReadOnly() const;
bool shouldMillisecondFieldReadOnly() const;
bool shouldMinuteFieldReadOnly() const;
bool shouldSecondFieldReadOnly() const;
@@ -102,21 +103,45 @@
m_editElement.addField(DateTimeDayFieldElement::create(document, m_editElement, m_parameters.placeholderForDay));
return;
- case DateTimeFormat::FieldTypeHour11:
- m_editElement.addField(DateTimeHourFieldElement::create(document, m_editElement, 0, 11));
+ case DateTimeFormat::FieldTypeHour11: {
+ RefPtr<DateTimeFieldElement> field = DateTimeHourFieldElement::create(document, m_editElement, 0, 11);
+ m_editElement.addField(field);
+ if (shouldHourFieldReadOnly()) {
+ field->setValueAsDate(m_dateValue);
+ field->setReadOnly();
+ }
return;
+ }
- case DateTimeFormat::FieldTypeHour12:
- m_editElement.addField(DateTimeHourFieldElement::create(document, m_editElement, 1, 12));
+ case DateTimeFormat::FieldTypeHour12: {
+ RefPtr<DateTimeFieldElement> field = DateTimeHourFieldElement::create(document, m_editElement, 1, 12);
+ m_editElement.addField(field);
+ if (shouldHourFieldReadOnly()) {
+ field->setValueAsDate(m_dateValue);
+ field->setReadOnly();
+ }
return;
+ }
- case DateTimeFormat::FieldTypeHour23:
- m_editElement.addField(DateTimeHourFieldElement::create(document, m_editElement, 0, 23));
+ case DateTimeFormat::FieldTypeHour23: {
+ RefPtr<DateTimeFieldElement> field = DateTimeHourFieldElement::create(document, m_editElement, 0, 23);
+ m_editElement.addField(field);
+ if (shouldHourFieldReadOnly()) {
+ field->setValueAsDate(m_dateValue);
+ field->setReadOnly();
+ }
return;
+ }
- case DateTimeFormat::FieldTypeHour24:
- m_editElement.addField(DateTimeHourFieldElement::create(document, m_editElement, 1, 24));
+ case DateTimeFormat::FieldTypeHour24: {
+ RefPtr<DateTimeFieldElement> field = DateTimeHourFieldElement::create(document, m_editElement, 1, 24);
+ m_editElement.addField(field);
+ if (shouldHourFieldReadOnly()) {
+ field->setValueAsDate(m_dateValue);
+ field->setReadOnly();
+ }
return;
+ }
case DateTimeFormat::FieldTypeMinute: {
RefPtr<DateTimeNumericFieldElement> field = DateTimeMinuteFieldElement::create(document, m_editElement);
@@ -158,9 +183,15 @@
}
return;
- case DateTimeFormat::FieldTypePeriod:
- m_editElement.addField(DateTimeAMPMFieldElement::create(document, m_editElement, m_parameters.locale.timeAMPMLabels()));
+ case DateTimeFormat::FieldTypePeriod: {
+ RefPtr<DateTimeFieldElement> field = DateTimeAMPMFieldElement::create(document, m_editElement, m_parameters.locale.timeAMPMLabels());
+ m_editElement.addField(field);
+ if (shouldHourFieldReadOnly()) {
+ field->setValueAsDate(m_dateValue);
+ field->setReadOnly();
+ }
return;
+ }
case DateTimeFormat::FieldTypeSecond: {
RefPtr<DateTimeNumericFieldElement> field = DateTimeSecondFieldElement::create(document, m_editElement);
@@ -221,19 +252,31 @@
}
}
+bool DateTimeEditBuilder::shouldHourFieldReadOnly() const
+{
+ const Decimal decimalMsPerDay(static_cast<int>(msPerDay));
+ Decimal hourPartOfMinimum = (stepRange().minimum().abs().remainder(decimalMsPerDay) / static_cast<int>(msPerHour)).floor();
+ return hourPartOfMinimum == m_dateValue.hour() && stepRange().step().remainder(decimalMsPerDay).isZero();
+}
+
bool DateTimeEditBuilder::shouldMillisecondFieldReadOnly() const
{
- return !m_dateValue.millisecond() && stepRange().step().remainder(static_cast<int>(msPerSecond)).isZero();
+ const Decimal decimalMsPerSecond(static_cast<int>(msPerSecond));
+ return stepRange().minimum().abs().remainder(decimalMsPerSecond) == m_dateValue.millisecond() && stepRange().step().remainder(decimalMsPerSecond).isZero();
}
bool DateTimeEditBuilder::shouldMinuteFieldReadOnly() const
{
- return !m_dateValue.minute() && stepRange().step().remainder(static_cast<int>(msPerHour)).isZero();
+ const Decimal decimalMsPerHour(static_cast<int>(msPerHour));
+ Decimal minutePartOfMinimum = (stepRange().minimum().abs().remainder(decimalMsPerHour) / static_cast<int>(msPerMinute)).floor();
+ return minutePartOfMinimum == m_dateValue.minute() && stepRange().step().remainder(decimalMsPerHour).isZero();
}
bool DateTimeEditBuilder::shouldSecondFieldReadOnly() const
{
- return !m_dateValue.second() && stepRange().step().remainder(static_cast<int>(msPerMinute)).isZero();
+ const Decimal decimalMsPerMinute(static_cast<int>(msPerMinute));
+ Decimal secondPartOfMinimum = (stepRange().minimum().abs().remainder(decimalMsPerMinute) / static_cast<int>(msPerSecond)).floor();
+ return secondPartOfMinimum == m_dateValue.second() && stepRange().step().remainder(decimalMsPerMinute).isZero();
}
void DateTimeEditBuilder::visitLiteral(const String& text)
« no previous file with comments | « Source/WebCore/html/BaseMultipleFieldsDateAndTimeInputType.cpp ('k') | Source/WebCore/platform/Decimal.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698