| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 static const int msecPerMinute = 60 * 1000; | 48 static const int msecPerMinute = 60 * 1000; |
| 49 static const int msecPerSecond = 1000; | 49 static const int msecPerSecond = 1000; |
| 50 | 50 |
| 51 double BaseDateAndTimeInputType::valueAsDate() const | 51 double BaseDateAndTimeInputType::valueAsDate() const |
| 52 { | 52 { |
| 53 return valueAsDouble(); | 53 return valueAsDouble(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void BaseDateAndTimeInputType::setValueAsDate(double value, ExceptionState&) con
st | 56 void BaseDateAndTimeInputType::setValueAsDate(double value, ExceptionState&) con
st |
| 57 { | 57 { |
| 58 element()->setValue(serializeWithMilliseconds(value)); | 58 element().setValue(serializeWithMilliseconds(value)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 double BaseDateAndTimeInputType::valueAsDouble() const | 61 double BaseDateAndTimeInputType::valueAsDouble() const |
| 62 { | 62 { |
| 63 const Decimal value = parseToNumber(element()->value(), Decimal::nan()); | 63 const Decimal value = parseToNumber(element().value(), Decimal::nan()); |
| 64 return value.isFinite() ? value.toDouble() : DateComponents::invalidMillisec
onds(); | 64 return value.isFinite() ? value.toDouble() : DateComponents::invalidMillisec
onds(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void BaseDateAndTimeInputType::setValueAsDecimal(const Decimal& newValue, TextFi
eldEventBehavior eventBehavior, ExceptionState&) const | 67 void BaseDateAndTimeInputType::setValueAsDecimal(const Decimal& newValue, TextFi
eldEventBehavior eventBehavior, ExceptionState&) const |
| 68 { | 68 { |
| 69 element()->setValue(serialize(newValue), eventBehavior); | 69 element().setValue(serialize(newValue), eventBehavior); |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool BaseDateAndTimeInputType::typeMismatchFor(const String& value) const | 72 bool BaseDateAndTimeInputType::typeMismatchFor(const String& value) const |
| 73 { | 73 { |
| 74 return !value.isEmpty() && !parseToDateComponents(value, 0); | 74 return !value.isEmpty() && !parseToDateComponents(value, 0); |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool BaseDateAndTimeInputType::typeMismatch() const | 77 bool BaseDateAndTimeInputType::typeMismatch() const |
| 78 { | 78 { |
| 79 return typeMismatchFor(element()->value()); | 79 return typeMismatchFor(element().value()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 String BaseDateAndTimeInputType::rangeOverflowText(const Decimal& maximum) const | 82 String BaseDateAndTimeInputType::rangeOverflowText(const Decimal& maximum) const |
| 83 { | 83 { |
| 84 return locale().queryString(WebLocalizedString::ValidationRangeOverflowDateT
ime, localizeValue(serialize(maximum))); | 84 return locale().queryString(WebLocalizedString::ValidationRangeOverflowDateT
ime, localizeValue(serialize(maximum))); |
| 85 } | 85 } |
| 86 | 86 |
| 87 String BaseDateAndTimeInputType::rangeUnderflowText(const Decimal& minimum) cons
t | 87 String BaseDateAndTimeInputType::rangeUnderflowText(const Decimal& minimum) cons
t |
| 88 { | 88 { |
| 89 return locale().queryString(WebLocalizedString::ValidationRangeUnderflowDate
Time, localizeValue(serialize(minimum))); | 89 return locale().queryString(WebLocalizedString::ValidationRangeUnderflowDate
Time, localizeValue(serialize(minimum))); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 return String(); | 129 return String(); |
| 130 DateComponents date; | 130 DateComponents date; |
| 131 if (!setMillisecondToDateComponents(value.toDouble(), &date)) | 131 if (!setMillisecondToDateComponents(value.toDouble(), &date)) |
| 132 return String(); | 132 return String(); |
| 133 return serializeWithComponents(date); | 133 return serializeWithComponents(date); |
| 134 } | 134 } |
| 135 | 135 |
| 136 String BaseDateAndTimeInputType::serializeWithComponents(const DateComponents& d
ate) const | 136 String BaseDateAndTimeInputType::serializeWithComponents(const DateComponents& d
ate) const |
| 137 { | 137 { |
| 138 Decimal step; | 138 Decimal step; |
| 139 if (!element()->getAllowedValueStep(&step)) | 139 if (!element().getAllowedValueStep(&step)) |
| 140 return date.toString(); | 140 return date.toString(); |
| 141 if (step.remainder(msecPerMinute).isZero()) | 141 if (step.remainder(msecPerMinute).isZero()) |
| 142 return date.toString(DateComponents::None); | 142 return date.toString(DateComponents::None); |
| 143 if (step.remainder(msecPerSecond).isZero()) | 143 if (step.remainder(msecPerSecond).isZero()) |
| 144 return date.toString(DateComponents::Second); | 144 return date.toString(DateComponents::Second); |
| 145 return date.toString(DateComponents::Millisecond); | 145 return date.toString(DateComponents::Millisecond); |
| 146 } | 146 } |
| 147 | 147 |
| 148 String BaseDateAndTimeInputType::serializeWithMilliseconds(double value) const | 148 String BaseDateAndTimeInputType::serializeWithMilliseconds(double value) const |
| 149 { | 149 { |
| 150 return serialize(Decimal::fromDouble(value)); | 150 return serialize(Decimal::fromDouble(value)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 String BaseDateAndTimeInputType::localizeValue(const String& proposedValue) cons
t | 153 String BaseDateAndTimeInputType::localizeValue(const String& proposedValue) cons
t |
| 154 { | 154 { |
| 155 DateComponents date; | 155 DateComponents date; |
| 156 if (!parseToDateComponents(proposedValue, &date)) | 156 if (!parseToDateComponents(proposedValue, &date)) |
| 157 return proposedValue; | 157 return proposedValue; |
| 158 | 158 |
| 159 String localized = element()->locale().formatDateTime(date); | 159 String localized = element().locale().formatDateTime(date); |
| 160 return localized.isEmpty() ? proposedValue : localized; | 160 return localized.isEmpty() ? proposedValue : localized; |
| 161 } | 161 } |
| 162 | 162 |
| 163 String BaseDateAndTimeInputType::visibleValue() const | 163 String BaseDateAndTimeInputType::visibleValue() const |
| 164 { | 164 { |
| 165 return localizeValue(element()->value()); | 165 return localizeValue(element().value()); |
| 166 } | 166 } |
| 167 | 167 |
| 168 String BaseDateAndTimeInputType::sanitizeValue(const String& proposedValue) cons
t | 168 String BaseDateAndTimeInputType::sanitizeValue(const String& proposedValue) cons
t |
| 169 { | 169 { |
| 170 return typeMismatchFor(proposedValue) ? emptyString() : proposedValue; | 170 return typeMismatchFor(proposedValue) ? emptyString() : proposedValue; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool BaseDateAndTimeInputType::supportsReadOnly() const | 173 bool BaseDateAndTimeInputType::supportsReadOnly() const |
| 174 { | 174 { |
| 175 return true; | 175 return true; |
| 176 } | 176 } |
| 177 | 177 |
| 178 bool BaseDateAndTimeInputType::shouldRespectListAttribute() | 178 bool BaseDateAndTimeInputType::shouldRespectListAttribute() |
| 179 { | 179 { |
| 180 return InputType::themeSupportsDataListUI(this); | 180 return InputType::themeSupportsDataListUI(this); |
| 181 } | 181 } |
| 182 | 182 |
| 183 bool BaseDateAndTimeInputType::valueMissing(const String& value) const | 183 bool BaseDateAndTimeInputType::valueMissing(const String& value) const |
| 184 { | 184 { |
| 185 return element()->isRequired() && value.isEmpty(); | 185 return element().isRequired() && value.isEmpty(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 bool BaseDateAndTimeInputType::shouldShowFocusRingOnMouseFocus() const | 188 bool BaseDateAndTimeInputType::shouldShowFocusRingOnMouseFocus() const |
| 189 { | 189 { |
| 190 return true; | 190 return true; |
| 191 } | 191 } |
| 192 | 192 |
| 193 } // namespace WebCore | 193 } // namespace WebCore |
| OLD | NEW |