| 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 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 namespace WebCore { | 42 namespace WebCore { |
| 43 | 43 |
| 44 using WebKit::WebLocalizedString; | 44 using WebKit::WebLocalizedString; |
| 45 using namespace HTMLNames; | 45 using namespace HTMLNames; |
| 46 | 46 |
| 47 static const int dateDefaultStep = 1; | 47 static const int dateDefaultStep = 1; |
| 48 static const int dateDefaultStepBase = 0; | 48 static const int dateDefaultStepBase = 0; |
| 49 static const int dateStepScaleFactor = 86400000; | 49 static const int dateStepScaleFactor = 86400000; |
| 50 | 50 |
| 51 inline DateInputType::DateInputType(HTMLInputElement* element) | 51 inline DateInputType::DateInputType(HTMLInputElement& element) |
| 52 : BaseDateInputType(element) | 52 : BaseDateInputType(element) |
| 53 { | 53 { |
| 54 } | 54 } |
| 55 | 55 |
| 56 PassRefPtr<InputType> DateInputType::create(HTMLInputElement* element) | 56 PassRefPtr<InputType> DateInputType::create(HTMLInputElement& element) |
| 57 { | 57 { |
| 58 return adoptRef(new DateInputType(element)); | 58 return adoptRef(new DateInputType(element)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void DateInputType::countUsage() | 61 void DateInputType::countUsage() |
| 62 { | 62 { |
| 63 observeFeatureIfVisible(UseCounter::InputTypeDate); | 63 observeFeatureIfVisible(UseCounter::InputTypeDate); |
| 64 } | 64 } |
| 65 | 65 |
| 66 const AtomicString& DateInputType::formControlType() const | 66 const AtomicString& DateInputType::formControlType() const |
| 67 { | 67 { |
| 68 return InputTypeNames::date(); | 68 return InputTypeNames::date(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 DateComponents::Type DateInputType::dateType() const | 71 DateComponents::Type DateInputType::dateType() const |
| 72 { | 72 { |
| 73 return DateComponents::Date; | 73 return DateComponents::Date; |
| 74 } | 74 } |
| 75 | 75 |
| 76 StepRange DateInputType::createStepRange(AnyStepHandling anyStepHandling) const | 76 StepRange DateInputType::createStepRange(AnyStepHandling anyStepHandling) const |
| 77 { | 77 { |
| 78 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (date
DefaultStep, dateDefaultStepBase, dateStepScaleFactor, StepRange::ParsedStepValu
eShouldBeInteger)); | 78 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (date
DefaultStep, dateDefaultStepBase, dateStepScaleFactor, StepRange::ParsedStepValu
eShouldBeInteger)); |
| 79 | 79 |
| 80 const Decimal stepBase = parseToNumber(element()->fastGetAttribute(minAttr),
0); | 80 const Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr),
0); |
| 81 const Decimal minimum = parseToNumber(element()->fastGetAttribute(minAttr),
Decimal::fromDouble(DateComponents::minimumDate())); | 81 const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), D
ecimal::fromDouble(DateComponents::minimumDate())); |
| 82 const Decimal maximum = parseToNumber(element()->fastGetAttribute(maxAttr),
Decimal::fromDouble(DateComponents::maximumDate())); | 82 const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), D
ecimal::fromDouble(DateComponents::maximumDate())); |
| 83 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription,
element()->fastGetAttribute(stepAttr)); | 83 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription,
element().fastGetAttribute(stepAttr)); |
| 84 return StepRange(stepBase, minimum, maximum, step, stepDescription); | 84 return StepRange(stepBase, minimum, maximum, step, stepDescription); |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool DateInputType::parseToDateComponentsInternal(const String& string, DateComp
onents* out) const | 87 bool DateInputType::parseToDateComponentsInternal(const String& string, DateComp
onents* out) const |
| 88 { | 88 { |
| 89 ASSERT(out); | 89 ASSERT(out); |
| 90 unsigned end; | 90 unsigned end; |
| 91 return out->parseDate(string, 0, end) && end == string.length(); | 91 return out->parseDate(string, 0, end) && end == string.length(); |
| 92 } | 92 } |
| 93 | 93 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 108 if (!dateTimeFieldsState.hasDayOfMonth() || !dateTimeFieldsState.hasMonth()
|| !dateTimeFieldsState.hasYear()) | 108 if (!dateTimeFieldsState.hasDayOfMonth() || !dateTimeFieldsState.hasMonth()
|| !dateTimeFieldsState.hasYear()) |
| 109 return emptyString(); | 109 return emptyString(); |
| 110 | 110 |
| 111 return String::format("%04u-%02u-%02u", dateTimeFieldsState.year(), dateTime
FieldsState.month(), dateTimeFieldsState.dayOfMonth()); | 111 return String::format("%04u-%02u-%02u", dateTimeFieldsState.year(), dateTime
FieldsState.month(), dateTimeFieldsState.dayOfMonth()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void DateInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters&
layoutParameters, const DateComponents& date) const | 114 void DateInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters&
layoutParameters, const DateComponents& date) const |
| 115 { | 115 { |
| 116 layoutParameters.dateTimeFormat = layoutParameters.locale.dateFormat(); | 116 layoutParameters.dateTimeFormat = layoutParameters.locale.dateFormat(); |
| 117 layoutParameters.fallbackDateTimeFormat = "yyyy-MM-dd"; | 117 layoutParameters.fallbackDateTimeFormat = "yyyy-MM-dd"; |
| 118 if (!parseToDateComponents(element()->fastGetAttribute(minAttr), &layoutPara
meters.minimum)) | 118 if (!parseToDateComponents(element().fastGetAttribute(minAttr), &layoutParam
eters.minimum)) |
| 119 layoutParameters.minimum = DateComponents(); | 119 layoutParameters.minimum = DateComponents(); |
| 120 if (!parseToDateComponents(element()->fastGetAttribute(maxAttr), &layoutPara
meters.maximum)) | 120 if (!parseToDateComponents(element().fastGetAttribute(maxAttr), &layoutParam
eters.maximum)) |
| 121 layoutParameters.maximum = DateComponents(); | 121 layoutParameters.maximum = DateComponents(); |
| 122 layoutParameters.placeholderForDay = locale().queryString(WebLocalizedString
::PlaceholderForDayOfMonthField); | 122 layoutParameters.placeholderForDay = locale().queryString(WebLocalizedString
::PlaceholderForDayOfMonthField); |
| 123 layoutParameters.placeholderForMonth = locale().queryString(WebLocalizedStri
ng::PlaceholderForMonthField); | 123 layoutParameters.placeholderForMonth = locale().queryString(WebLocalizedStri
ng::PlaceholderForMonthField); |
| 124 layoutParameters.placeholderForYear = locale().queryString(WebLocalizedStrin
g::PlaceholderForYearField); | 124 layoutParameters.placeholderForYear = locale().queryString(WebLocalizedStrin
g::PlaceholderForYearField); |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool DateInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, boo
l hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const | 127 bool DateInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, boo
l hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const |
| 128 { | 128 { |
| 129 return hasYear && hasMonth && hasDay; | 129 return hasYear && hasMonth && hasDay; |
| 130 } | 130 } |
| 131 #endif | 131 #endif |
| 132 | 132 |
| 133 } // namespace WebCore | 133 } // namespace WebCore |
| OLD | NEW |