| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "wtf/text/WTFString.h" | 44 #include "wtf/text/WTFString.h" |
| 45 | 45 |
| 46 namespace WebCore { | 46 namespace WebCore { |
| 47 | 47 |
| 48 using namespace HTMLNames; | 48 using namespace HTMLNames; |
| 49 | 49 |
| 50 static const int timeDefaultStep = 60; | 50 static const int timeDefaultStep = 60; |
| 51 static const int timeDefaultStepBase = 0; | 51 static const int timeDefaultStepBase = 0; |
| 52 static const int timeStepScaleFactor = 1000; | 52 static const int timeStepScaleFactor = 1000; |
| 53 | 53 |
| 54 TimeInputType::TimeInputType(HTMLInputElement* element) | 54 TimeInputType::TimeInputType(HTMLInputElement& element) |
| 55 : BaseTimeInputType(element) | 55 : BaseTimeInputType(element) |
| 56 { | 56 { |
| 57 } | 57 } |
| 58 | 58 |
| 59 PassRefPtr<InputType> TimeInputType::create(HTMLInputElement* element) | 59 PassRefPtr<InputType> TimeInputType::create(HTMLInputElement& element) |
| 60 { | 60 { |
| 61 return adoptRef(new TimeInputType(element)); | 61 return adoptRef(new TimeInputType(element)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void TimeInputType::countUsage() | 64 void TimeInputType::countUsage() |
| 65 { | 65 { |
| 66 observeFeatureIfVisible(UseCounter::InputTypeTime); | 66 observeFeatureIfVisible(UseCounter::InputTypeTime); |
| 67 } | 67 } |
| 68 | 68 |
| 69 const AtomicString& TimeInputType::formControlType() const | 69 const AtomicString& TimeInputType::formControlType() const |
| (...skipping 18 matching lines...) Expand all Loading... |
| 88 date.setMillisecondsSinceMidnight(current); | 88 date.setMillisecondsSinceMidnight(current); |
| 89 double milliseconds = date.millisecondsSinceEpoch(); | 89 double milliseconds = date.millisecondsSinceEpoch(); |
| 90 ASSERT(std::isfinite(milliseconds)); | 90 ASSERT(std::isfinite(milliseconds)); |
| 91 return Decimal::fromDouble(milliseconds); | 91 return Decimal::fromDouble(milliseconds); |
| 92 } | 92 } |
| 93 | 93 |
| 94 StepRange TimeInputType::createStepRange(AnyStepHandling anyStepHandling) const | 94 StepRange TimeInputType::createStepRange(AnyStepHandling anyStepHandling) const |
| 95 { | 95 { |
| 96 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (time
DefaultStep, timeDefaultStepBase, timeStepScaleFactor, StepRange::ScaledStepValu
eShouldBeInteger)); | 96 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (time
DefaultStep, timeDefaultStepBase, timeStepScaleFactor, StepRange::ScaledStepValu
eShouldBeInteger)); |
| 97 | 97 |
| 98 const Decimal stepBase = parseToNumber(element()->fastGetAttribute(minAttr),
0); | 98 const Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr),
0); |
| 99 const Decimal minimum = parseToNumber(element()->fastGetAttribute(minAttr),
Decimal::fromDouble(DateComponents::minimumTime())); | 99 const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), D
ecimal::fromDouble(DateComponents::minimumTime())); |
| 100 const Decimal maximum = parseToNumber(element()->fastGetAttribute(maxAttr),
Decimal::fromDouble(DateComponents::maximumTime())); | 100 const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), D
ecimal::fromDouble(DateComponents::maximumTime())); |
| 101 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription,
element()->fastGetAttribute(stepAttr)); | 101 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription,
element().fastGetAttribute(stepAttr)); |
| 102 return StepRange(stepBase, minimum, maximum, step, stepDescription); | 102 return StepRange(stepBase, minimum, maximum, step, stepDescription); |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool TimeInputType::parseToDateComponentsInternal(const String& string, DateComp
onents* out) const | 105 bool TimeInputType::parseToDateComponentsInternal(const String& string, DateComp
onents* out) const |
| 106 { | 106 { |
| 107 ASSERT(out); | 107 ASSERT(out); |
| 108 unsigned end; | 108 unsigned end; |
| 109 return out->parseTime(string, 0, end) && end == string.length(); | 109 return out->parseTime(string, 0, end) && end == string.length(); |
| 110 } | 110 } |
| 111 | 111 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 123 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) | 123 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) |
| 124 | 124 |
| 125 String TimeInputType::localizeValue(const String& proposedValue) const | 125 String TimeInputType::localizeValue(const String& proposedValue) const |
| 126 { | 126 { |
| 127 DateComponents date; | 127 DateComponents date; |
| 128 if (!parseToDateComponents(proposedValue, &date)) | 128 if (!parseToDateComponents(proposedValue, &date)) |
| 129 return proposedValue; | 129 return proposedValue; |
| 130 | 130 |
| 131 Locale::FormatType formatType = shouldHaveSecondField(date) ? Locale::Format
TypeMedium : Locale::FormatTypeShort; | 131 Locale::FormatType formatType = shouldHaveSecondField(date) ? Locale::Format
TypeMedium : Locale::FormatTypeShort; |
| 132 | 132 |
| 133 String localized = element()->locale().formatDateTime(date, formatType); | 133 String localized = element().locale().formatDateTime(date, formatType); |
| 134 return localized.isEmpty() ? proposedValue : localized; | 134 return localized.isEmpty() ? proposedValue : localized; |
| 135 } | 135 } |
| 136 | 136 |
| 137 String TimeInputType::formatDateTimeFieldsState(const DateTimeFieldsState& dateT
imeFieldsState) const | 137 String TimeInputType::formatDateTimeFieldsState(const DateTimeFieldsState& dateT
imeFieldsState) const |
| 138 { | 138 { |
| 139 if (!dateTimeFieldsState.hasHour() || !dateTimeFieldsState.hasMinute() || !d
ateTimeFieldsState.hasAMPM()) | 139 if (!dateTimeFieldsState.hasHour() || !dateTimeFieldsState.hasMinute() || !d
ateTimeFieldsState.hasAMPM()) |
| 140 return emptyString(); | 140 return emptyString(); |
| 141 if (dateTimeFieldsState.hasMillisecond() && dateTimeFieldsState.millisecond(
)) { | 141 if (dateTimeFieldsState.hasMillisecond() && dateTimeFieldsState.millisecond(
)) { |
| 142 return String::format("%02u:%02u:%02u.%03u", | 142 return String::format("%02u:%02u:%02u.%03u", |
| 143 dateTimeFieldsState.hour23(), | 143 dateTimeFieldsState.hour23(), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 156 | 156 |
| 157 void TimeInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters&
layoutParameters, const DateComponents& date) const | 157 void TimeInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters&
layoutParameters, const DateComponents& date) const |
| 158 { | 158 { |
| 159 if (shouldHaveSecondField(date)) { | 159 if (shouldHaveSecondField(date)) { |
| 160 layoutParameters.dateTimeFormat = layoutParameters.locale.timeFormat(); | 160 layoutParameters.dateTimeFormat = layoutParameters.locale.timeFormat(); |
| 161 layoutParameters.fallbackDateTimeFormat = "HH:mm:ss"; | 161 layoutParameters.fallbackDateTimeFormat = "HH:mm:ss"; |
| 162 } else { | 162 } else { |
| 163 layoutParameters.dateTimeFormat = layoutParameters.locale.shortTimeForma
t(); | 163 layoutParameters.dateTimeFormat = layoutParameters.locale.shortTimeForma
t(); |
| 164 layoutParameters.fallbackDateTimeFormat = "HH:mm"; | 164 layoutParameters.fallbackDateTimeFormat = "HH:mm"; |
| 165 } | 165 } |
| 166 if (!parseToDateComponents(element()->fastGetAttribute(minAttr), &layoutPara
meters.minimum)) | 166 if (!parseToDateComponents(element().fastGetAttribute(minAttr), &layoutParam
eters.minimum)) |
| 167 layoutParameters.minimum = DateComponents(); | 167 layoutParameters.minimum = DateComponents(); |
| 168 if (!parseToDateComponents(element()->fastGetAttribute(maxAttr), &layoutPara
meters.maximum)) | 168 if (!parseToDateComponents(element().fastGetAttribute(maxAttr), &layoutParam
eters.maximum)) |
| 169 layoutParameters.maximum = DateComponents(); | 169 layoutParameters.maximum = DateComponents(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool TimeInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, boo
l hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const | 172 bool TimeInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, boo
l hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const |
| 173 { | 173 { |
| 174 return hasHour && hasMinute && hasAMPM; | 174 return hasHour && hasMinute && hasAMPM; |
| 175 } | 175 } |
| 176 #endif | 176 #endif |
| 177 | 177 |
| 178 } // namespace WebCore | 178 } // namespace WebCore |
| OLD | NEW |