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 #include "wtf/text/WTFString.h" | 41 #include "wtf/text/WTFString.h" |
42 | 42 |
43 namespace WebCore { | 43 namespace WebCore { |
44 | 44 |
45 using namespace HTMLNames; | 45 using namespace HTMLNames; |
46 | 46 |
47 static const int weekDefaultStepBase = -259200000; // The first day of 1970-W01. | 47 static const int weekDefaultStepBase = -259200000; // The first day of 1970-W01. |
48 static const int weekDefaultStep = 1; | 48 static const int weekDefaultStep = 1; |
49 static const int weekStepScaleFactor = 604800000; | 49 static const int weekStepScaleFactor = 604800000; |
50 | 50 |
51 PassRefPtr<InputType> WeekInputType::create(HTMLInputElement* element) | 51 PassRefPtr<InputType> WeekInputType::create(HTMLInputElement& element) |
52 { | 52 { |
53 return adoptRef(new WeekInputType(element)); | 53 return adoptRef(new WeekInputType(element)); |
54 } | 54 } |
55 | 55 |
56 void WeekInputType::countUsage() | 56 void WeekInputType::countUsage() |
57 { | 57 { |
58 observeFeatureIfVisible(UseCounter::InputTypeWeek); | 58 observeFeatureIfVisible(UseCounter::InputTypeWeek); |
59 } | 59 } |
60 | 60 |
61 const AtomicString& WeekInputType::formControlType() const | 61 const AtomicString& WeekInputType::formControlType() const |
62 { | 62 { |
63 return InputTypeNames::week(); | 63 return InputTypeNames::week(); |
64 } | 64 } |
65 | 65 |
66 DateComponents::Type WeekInputType::dateType() const | 66 DateComponents::Type WeekInputType::dateType() const |
67 { | 67 { |
68 return DateComponents::Week; | 68 return DateComponents::Week; |
69 } | 69 } |
70 | 70 |
71 StepRange WeekInputType::createStepRange(AnyStepHandling anyStepHandling) const | 71 StepRange WeekInputType::createStepRange(AnyStepHandling anyStepHandling) const |
72 { | 72 { |
73 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (week
DefaultStep, weekDefaultStepBase, weekStepScaleFactor, StepRange::ParsedStepValu
eShouldBeInteger)); | 73 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (week
DefaultStep, weekDefaultStepBase, weekStepScaleFactor, StepRange::ParsedStepValu
eShouldBeInteger)); |
74 | 74 |
75 const Decimal stepBase = parseToNumber(element()->fastGetAttribute(minAttr),
weekDefaultStepBase); | 75 const Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr),
weekDefaultStepBase); |
76 const Decimal minimum = parseToNumber(element()->fastGetAttribute(minAttr),
Decimal::fromDouble(DateComponents::minimumWeek())); | 76 const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), D
ecimal::fromDouble(DateComponents::minimumWeek())); |
77 const Decimal maximum = parseToNumber(element()->fastGetAttribute(maxAttr),
Decimal::fromDouble(DateComponents::maximumWeek())); | 77 const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), D
ecimal::fromDouble(DateComponents::maximumWeek())); |
78 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription,
element()->fastGetAttribute(stepAttr)); | 78 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription,
element().fastGetAttribute(stepAttr)); |
79 return StepRange(stepBase, minimum, maximum, step, stepDescription); | 79 return StepRange(stepBase, minimum, maximum, step, stepDescription); |
80 } | 80 } |
81 | 81 |
82 bool WeekInputType::parseToDateComponentsInternal(const String& string, DateComp
onents* out) const | 82 bool WeekInputType::parseToDateComponentsInternal(const String& string, DateComp
onents* out) const |
83 { | 83 { |
84 ASSERT(out); | 84 ASSERT(out); |
85 unsigned end; | 85 unsigned end; |
86 return out->parseWeek(string, 0, end) && end == string.length(); | 86 return out->parseWeek(string, 0, end) && end == string.length(); |
87 } | 87 } |
88 | 88 |
(...skipping 14 matching lines...) Expand all Loading... |
103 { | 103 { |
104 if (!dateTimeFieldsState.hasYear() || !dateTimeFieldsState.hasWeekOfYear()) | 104 if (!dateTimeFieldsState.hasYear() || !dateTimeFieldsState.hasWeekOfYear()) |
105 return emptyString(); | 105 return emptyString(); |
106 return String::format("%04u-W%02u", dateTimeFieldsState.year(), dateTimeFiel
dsState.weekOfYear()); | 106 return String::format("%04u-W%02u", dateTimeFieldsState.year(), dateTimeFiel
dsState.weekOfYear()); |
107 } | 107 } |
108 | 108 |
109 void WeekInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters&
layoutParameters, const DateComponents&) const | 109 void WeekInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters&
layoutParameters, const DateComponents&) const |
110 { | 110 { |
111 layoutParameters.dateTimeFormat = locale().weekFormatInLDML(); | 111 layoutParameters.dateTimeFormat = locale().weekFormatInLDML(); |
112 layoutParameters.fallbackDateTimeFormat = "yyyy-'W'ww"; | 112 layoutParameters.fallbackDateTimeFormat = "yyyy-'W'ww"; |
113 if (!parseToDateComponents(element()->fastGetAttribute(minAttr), &layoutPara
meters.minimum)) | 113 if (!parseToDateComponents(element().fastGetAttribute(minAttr), &layoutParam
eters.minimum)) |
114 layoutParameters.minimum = DateComponents(); | 114 layoutParameters.minimum = DateComponents(); |
115 if (!parseToDateComponents(element()->fastGetAttribute(maxAttr), &layoutPara
meters.maximum)) | 115 if (!parseToDateComponents(element().fastGetAttribute(maxAttr), &layoutParam
eters.maximum)) |
116 layoutParameters.maximum = DateComponents(); | 116 layoutParameters.maximum = DateComponents(); |
117 layoutParameters.placeholderForYear = "----"; | 117 layoutParameters.placeholderForYear = "----"; |
118 } | 118 } |
119 | 119 |
120 bool WeekInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, boo
l hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const | 120 bool WeekInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, boo
l hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const |
121 { | 121 { |
122 return hasYear && hasWeek; | 122 return hasYear && hasWeek; |
123 } | 123 } |
124 #endif | 124 #endif |
125 | 125 |
126 } // namespace WebCore | 126 } // namespace WebCore |
OLD | NEW |