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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 WTF_MAKE_NONCOPYABLE(DateTimeEditBuilder); 49 WTF_MAKE_NONCOPYABLE(DateTimeEditBuilder);
50 50
51 public: 51 public:
52 // The argument objects must be alive until this object dies. 52 // The argument objects must be alive until this object dies.
53 DateTimeEditBuilder(DateTimeEditElement&, const DateTimeEditElement::LayoutP arameters&, const DateComponents&); 53 DateTimeEditBuilder(DateTimeEditElement&, const DateTimeEditElement::LayoutP arameters&, const DateComponents&);
54 54
55 bool build(const String&); 55 bool build(const String&);
56 56
57 private: 57 private:
58 bool needMillisecondField() const; 58 bool needMillisecondField() const;
59 bool shouldHourFieldReadOnly() const;
59 bool shouldMillisecondFieldReadOnly() const; 60 bool shouldMillisecondFieldReadOnly() const;
60 bool shouldMinuteFieldReadOnly() const; 61 bool shouldMinuteFieldReadOnly() const;
61 bool shouldSecondFieldReadOnly() const; 62 bool shouldSecondFieldReadOnly() const;
62 inline const StepRange& stepRange() const { return m_parameters.stepRange; } 63 inline const StepRange& stepRange() const { return m_parameters.stepRange; }
63 64
64 // DateTimeFormat::TokenHandler functions. 65 // DateTimeFormat::TokenHandler functions.
65 virtual void visitField(DateTimeFormat::FieldType, int) OVERRIDE FINAL; 66 virtual void visitField(DateTimeFormat::FieldType, int) OVERRIDE FINAL;
66 virtual void visitLiteral(const String&) OVERRIDE FINAL; 67 virtual void visitLiteral(const String&) OVERRIDE FINAL;
67 68
68 DateTimeEditElement& m_editElement; 69 DateTimeEditElement& m_editElement;
(...skipping 26 matching lines...) Expand all
95 const int countForAbbreviatedMonth = 3; 96 const int countForAbbreviatedMonth = 3;
96 const int countForFullMonth = 4; 97 const int countForFullMonth = 4;
97 const int countForNarrowMonth = 5; 98 const int countForNarrowMonth = 5;
98 Document* const document = m_editElement.document(); 99 Document* const document = m_editElement.document();
99 100
100 switch (fieldType) { 101 switch (fieldType) {
101 case DateTimeFormat::FieldTypeDayOfMonth: 102 case DateTimeFormat::FieldTypeDayOfMonth:
102 m_editElement.addField(DateTimeDayFieldElement::create(document, m_editE lement, m_parameters.placeholderForDay)); 103 m_editElement.addField(DateTimeDayFieldElement::create(document, m_editE lement, m_parameters.placeholderForDay));
103 return; 104 return;
104 105
105 case DateTimeFormat::FieldTypeHour11: 106 case DateTimeFormat::FieldTypeHour11: {
106 m_editElement.addField(DateTimeHourFieldElement::create(document, m_edit Element, 0, 11)); 107 RefPtr<DateTimeFieldElement> field = DateTimeHourFieldElement::create(do cument, m_editElement, 0, 11);
108 m_editElement.addField(field);
109 if (shouldHourFieldReadOnly()) {
110 field->setValueAsDate(m_dateValue);
111 field->setReadOnly();
112 }
107 return; 113 return;
114 }
108 115
109 case DateTimeFormat::FieldTypeHour12: 116 case DateTimeFormat::FieldTypeHour12: {
110 m_editElement.addField(DateTimeHourFieldElement::create(document, m_edit Element, 1, 12)); 117 RefPtr<DateTimeFieldElement> field = DateTimeHourFieldElement::create(do cument, m_editElement, 1, 12);
118 m_editElement.addField(field);
119 if (shouldHourFieldReadOnly()) {
120 field->setValueAsDate(m_dateValue);
121 field->setReadOnly();
122 }
111 return; 123 return;
124 }
112 125
113 case DateTimeFormat::FieldTypeHour23: 126 case DateTimeFormat::FieldTypeHour23: {
114 m_editElement.addField(DateTimeHourFieldElement::create(document, m_edit Element, 0, 23)); 127 RefPtr<DateTimeFieldElement> field = DateTimeHourFieldElement::create(do cument, m_editElement, 0, 23);
128 m_editElement.addField(field);
129 if (shouldHourFieldReadOnly()) {
130 field->setValueAsDate(m_dateValue);
131 field->setReadOnly();
132 }
115 return; 133 return;
134 }
116 135
117 case DateTimeFormat::FieldTypeHour24: 136 case DateTimeFormat::FieldTypeHour24: {
118 m_editElement.addField(DateTimeHourFieldElement::create(document, m_edit Element, 1, 24)); 137 RefPtr<DateTimeFieldElement> field = DateTimeHourFieldElement::create(do cument, m_editElement, 1, 24);
138 m_editElement.addField(field);
139 if (shouldHourFieldReadOnly()) {
140 field->setValueAsDate(m_dateValue);
141 field->setReadOnly();
142 }
119 return; 143 return;
144 }
120 145
121 case DateTimeFormat::FieldTypeMinute: { 146 case DateTimeFormat::FieldTypeMinute: {
122 RefPtr<DateTimeNumericFieldElement> field = DateTimeMinuteFieldElement:: create(document, m_editElement); 147 RefPtr<DateTimeNumericFieldElement> field = DateTimeMinuteFieldElement:: create(document, m_editElement);
123 m_editElement.addField(field); 148 m_editElement.addField(field);
124 if (shouldMinuteFieldReadOnly()) { 149 if (shouldMinuteFieldReadOnly()) {
125 field->setValueAsDate(m_dateValue); 150 field->setValueAsDate(m_dateValue);
126 field->setReadOnly(); 151 field->setReadOnly();
127 } 152 }
128 return; 153 return;
129 } 154 }
(...skipping 21 matching lines...) Expand all
151 break; 176 break;
152 case countForFullMonth: 177 case countForFullMonth:
153 m_editElement.addField(DateTimeSymbolicMonthFieldElement::create(doc ument, m_editElement, m_parameters.locale.standAloneMonthLabels())); 178 m_editElement.addField(DateTimeSymbolicMonthFieldElement::create(doc ument, m_editElement, m_parameters.locale.standAloneMonthLabels()));
154 break; 179 break;
155 default: 180 default:
156 m_editElement.addField(DateTimeMonthFieldElement::create(document, m _editElement, m_parameters.placeholderForMonth)); 181 m_editElement.addField(DateTimeMonthFieldElement::create(document, m _editElement, m_parameters.placeholderForMonth));
157 break; 182 break;
158 } 183 }
159 return; 184 return;
160 185
161 case DateTimeFormat::FieldTypePeriod: 186 case DateTimeFormat::FieldTypePeriod: {
162 m_editElement.addField(DateTimeAMPMFieldElement::create(document, m_edit Element, m_parameters.locale.timeAMPMLabels())); 187 RefPtr<DateTimeFieldElement> field = DateTimeAMPMFieldElement::create(do cument, m_editElement, m_parameters.locale.timeAMPMLabels());
188 m_editElement.addField(field);
189 if (shouldHourFieldReadOnly()) {
190 field->setValueAsDate(m_dateValue);
191 field->setReadOnly();
192 }
163 return; 193 return;
194 }
164 195
165 case DateTimeFormat::FieldTypeSecond: { 196 case DateTimeFormat::FieldTypeSecond: {
166 RefPtr<DateTimeNumericFieldElement> field = DateTimeSecondFieldElement:: create(document, m_editElement); 197 RefPtr<DateTimeNumericFieldElement> field = DateTimeSecondFieldElement:: create(document, m_editElement);
167 m_editElement.addField(field); 198 m_editElement.addField(field);
168 if (shouldSecondFieldReadOnly()) { 199 if (shouldSecondFieldReadOnly()) {
169 field->setValueAsDate(m_dateValue); 200 field->setValueAsDate(m_dateValue);
170 field->setReadOnly(); 201 field->setReadOnly();
171 } 202 }
172 203
173 if (needMillisecondField()) { 204 if (needMillisecondField()) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 yearParams.placeholder = m_parameters.placeholderForYear; 245 yearParams.placeholder = m_parameters.placeholderForYear;
215 m_editElement.addField(DateTimeYearFieldElement::create(document, m_edit Element, yearParams)); 246 m_editElement.addField(DateTimeYearFieldElement::create(document, m_edit Element, yearParams));
216 return; 247 return;
217 } 248 }
218 249
219 default: 250 default:
220 return; 251 return;
221 } 252 }
222 } 253 }
223 254
255 bool DateTimeEditBuilder::shouldHourFieldReadOnly() const
256 {
257 const Decimal decimalMsPerDay(static_cast<int>(msPerDay));
258 Decimal hourPartOfMinimum = (stepRange().minimum().abs().remainder(decimalMs PerDay) / static_cast<int>(msPerHour)).floor();
259 return hourPartOfMinimum == m_dateValue.hour() && stepRange().step().remaind er(decimalMsPerDay).isZero();
260 }
261
224 bool DateTimeEditBuilder::shouldMillisecondFieldReadOnly() const 262 bool DateTimeEditBuilder::shouldMillisecondFieldReadOnly() const
225 { 263 {
226 return !m_dateValue.millisecond() && stepRange().step().remainder(static_cas t<int>(msPerSecond)).isZero(); 264 const Decimal decimalMsPerSecond(static_cast<int>(msPerSecond));
265 return stepRange().minimum().abs().remainder(decimalMsPerSecond) == m_dateVa lue.millisecond() && stepRange().step().remainder(decimalMsPerSecond).isZero();
227 } 266 }
228 267
229 bool DateTimeEditBuilder::shouldMinuteFieldReadOnly() const 268 bool DateTimeEditBuilder::shouldMinuteFieldReadOnly() const
230 { 269 {
231 return !m_dateValue.minute() && stepRange().step().remainder(static_cast<int >(msPerHour)).isZero(); 270 const Decimal decimalMsPerHour(static_cast<int>(msPerHour));
271 Decimal minutePartOfMinimum = (stepRange().minimum().abs().remainder(decimal MsPerHour) / static_cast<int>(msPerMinute)).floor();
272 return minutePartOfMinimum == m_dateValue.minute() && stepRange().step().rem ainder(decimalMsPerHour).isZero();
232 } 273 }
233 274
234 bool DateTimeEditBuilder::shouldSecondFieldReadOnly() const 275 bool DateTimeEditBuilder::shouldSecondFieldReadOnly() const
235 { 276 {
236 return !m_dateValue.second() && stepRange().step().remainder(static_cast<int >(msPerMinute)).isZero(); 277 const Decimal decimalMsPerMinute(static_cast<int>(msPerMinute));
278 Decimal secondPartOfMinimum = (stepRange().minimum().abs().remainder(decimal MsPerMinute) / static_cast<int>(msPerSecond)).floor();
279 return secondPartOfMinimum == m_dateValue.second() && stepRange().step().rem ainder(decimalMsPerMinute).isZero();
237 } 280 }
238 281
239 void DateTimeEditBuilder::visitLiteral(const String& text) 282 void DateTimeEditBuilder::visitLiteral(const String& text)
240 { 283 {
241 DEFINE_STATIC_LOCAL(AtomicString, textPseudoId, ("-webkit-datetime-edit-text ", AtomicString::ConstructFromLiteral)); 284 DEFINE_STATIC_LOCAL(AtomicString, textPseudoId, ("-webkit-datetime-edit-text ", AtomicString::ConstructFromLiteral));
242 ASSERT(text.length()); 285 ASSERT(text.length());
243 RefPtr<HTMLDivElement> element = HTMLDivElement::create(m_editElement.docume nt()); 286 RefPtr<HTMLDivElement> element = HTMLDivElement::create(m_editElement.docume nt());
244 element->setShadowPseudoId(textPseudoId); 287 element->setShadowPseudoId(textPseudoId);
245 element->appendChild(Text::create(m_editElement.document(), text)); 288 element->appendChild(Text::create(m_editElement.document(), text));
246 m_editElement.appendChild(element); 289 m_editElement.appendChild(element);
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 { 560 {
518 DateTimeFieldsState dateTimeFieldsState; 561 DateTimeFieldsState dateTimeFieldsState;
519 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) 562 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex)
520 m_fields[fieldIndex]->populateDateTimeFieldsState(dateTimeFieldsState); 563 m_fields[fieldIndex]->populateDateTimeFieldsState(dateTimeFieldsState);
521 return dateTimeFieldsState; 564 return dateTimeFieldsState;
522 } 565 }
523 566
524 } // namespace WebCore 567 } // namespace WebCore
525 568
526 #endif 569 #endif
OLDNEW
« 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