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

Side by Side Diff: Source/core/html/forms/MonthInputType.cpp

Issue 27746003: Have InputType factories take an HTMLInputElement reference in parameter (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 2 months 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/html/forms/MonthInputType.h ('k') | Source/core/html/forms/NumberInputType.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 monthDefaultStep = 1; 50 static const int monthDefaultStep = 1;
51 static const int monthDefaultStepBase = 0; 51 static const int monthDefaultStepBase = 0;
52 static const int monthStepScaleFactor = 1; 52 static const int monthStepScaleFactor = 1;
53 53
54 PassRefPtr<InputType> MonthInputType::create(HTMLInputElement* element) 54 PassRefPtr<InputType> MonthInputType::create(HTMLInputElement& element)
55 { 55 {
56 return adoptRef(new MonthInputType(element)); 56 return adoptRef(new MonthInputType(element));
57 } 57 }
58 58
59 void MonthInputType::countUsage() 59 void MonthInputType::countUsage()
60 { 60 {
61 observeFeatureIfVisible(UseCounter::InputTypeMonth); 61 observeFeatureIfVisible(UseCounter::InputTypeMonth);
62 } 62 }
63 63
64 const AtomicString& MonthInputType::formControlType() const 64 const AtomicString& MonthInputType::formControlType() const
65 { 65 {
66 return InputTypeNames::month(); 66 return InputTypeNames::month();
67 } 67 }
68 68
69 DateComponents::Type MonthInputType::dateType() const 69 DateComponents::Type MonthInputType::dateType() const
70 { 70 {
71 return DateComponents::Month; 71 return DateComponents::Month;
72 } 72 }
73 73
74 double MonthInputType::valueAsDate() const 74 double MonthInputType::valueAsDate() const
75 { 75 {
76 DateComponents date; 76 DateComponents date;
77 if (!parseToDateComponents(element()->value(), &date)) 77 if (!parseToDateComponents(element().value(), &date))
78 return DateComponents::invalidMilliseconds(); 78 return DateComponents::invalidMilliseconds();
79 double msec = date.millisecondsSinceEpoch(); 79 double msec = date.millisecondsSinceEpoch();
80 ASSERT(std::isfinite(msec)); 80 ASSERT(std::isfinite(msec));
81 return msec; 81 return msec;
82 } 82 }
83 83
84 String MonthInputType::serializeWithMilliseconds(double value) const 84 String MonthInputType::serializeWithMilliseconds(double value) const
85 { 85 {
86 DateComponents date; 86 DateComponents date;
87 if (!date.setMillisecondsSinceEpochForMonth(value)) 87 if (!date.setMillisecondsSinceEpochForMonth(value))
(...skipping 13 matching lines...) Expand all
101 date.setMillisecondsSinceEpochForMonth(current); 101 date.setMillisecondsSinceEpochForMonth(current);
102 double months = date.monthsSinceEpoch(); 102 double months = date.monthsSinceEpoch();
103 ASSERT(std::isfinite(months)); 103 ASSERT(std::isfinite(months));
104 return Decimal::fromDouble(months); 104 return Decimal::fromDouble(months);
105 } 105 }
106 106
107 StepRange MonthInputType::createStepRange(AnyStepHandling anyStepHandling) const 107 StepRange MonthInputType::createStepRange(AnyStepHandling anyStepHandling) const
108 { 108 {
109 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (mont hDefaultStep, monthDefaultStepBase, monthStepScaleFactor, StepRange::ParsedStepV alueShouldBeInteger)); 109 DEFINE_STATIC_LOCAL(const StepRange::StepDescription, stepDescription, (mont hDefaultStep, monthDefaultStepBase, monthStepScaleFactor, StepRange::ParsedStepV alueShouldBeInteger));
110 110
111 const Decimal stepBase = parseToNumber(element()->fastGetAttribute(minAttr), Decimal::fromDouble(monthDefaultStepBase)); 111 const Decimal stepBase = parseToNumber(element().fastGetAttribute(minAttr), Decimal::fromDouble(monthDefaultStepBase));
112 const Decimal minimum = parseToNumber(element()->fastGetAttribute(minAttr), Decimal::fromDouble(DateComponents::minimumMonth())); 112 const Decimal minimum = parseToNumber(element().fastGetAttribute(minAttr), D ecimal::fromDouble(DateComponents::minimumMonth()));
113 const Decimal maximum = parseToNumber(element()->fastGetAttribute(maxAttr), Decimal::fromDouble(DateComponents::maximumMonth())); 113 const Decimal maximum = parseToNumber(element().fastGetAttribute(maxAttr), D ecimal::fromDouble(DateComponents::maximumMonth()));
114 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element()->fastGetAttribute(stepAttr)); 114 const Decimal step = StepRange::parseStep(anyStepHandling, stepDescription, element().fastGetAttribute(stepAttr));
115 return StepRange(stepBase, minimum, maximum, step, stepDescription); 115 return StepRange(stepBase, minimum, maximum, step, stepDescription);
116 } 116 }
117 117
118 Decimal MonthInputType::parseToNumber(const String& src, const Decimal& defaultV alue) const 118 Decimal MonthInputType::parseToNumber(const String& src, const Decimal& defaultV alue) const
119 { 119 {
120 DateComponents date; 120 DateComponents date;
121 if (!parseToDateComponents(src, &date)) 121 if (!parseToDateComponents(src, &date))
122 return defaultValue; 122 return defaultValue;
123 double months = date.monthsSinceEpoch(); 123 double months = date.monthsSinceEpoch();
124 ASSERT(std::isfinite(months)); 124 ASSERT(std::isfinite(months));
(...skipping 23 matching lines...) Expand all
148 { 148 {
149 if (!dateTimeFieldsState.hasMonth() || !dateTimeFieldsState.hasYear()) 149 if (!dateTimeFieldsState.hasMonth() || !dateTimeFieldsState.hasYear())
150 return emptyString(); 150 return emptyString();
151 return String::format("%04u-%02u", dateTimeFieldsState.year(), dateTimeField sState.month()); 151 return String::format("%04u-%02u", dateTimeFieldsState.year(), dateTimeField sState.month());
152 } 152 }
153 153
154 void MonthInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters & layoutParameters, const DateComponents& date) const 154 void MonthInputType::setupLayoutParameters(DateTimeEditElement::LayoutParameters & layoutParameters, const DateComponents& date) const
155 { 155 {
156 layoutParameters.dateTimeFormat = layoutParameters.locale.monthFormat(); 156 layoutParameters.dateTimeFormat = layoutParameters.locale.monthFormat();
157 layoutParameters.fallbackDateTimeFormat = "yyyy-MM"; 157 layoutParameters.fallbackDateTimeFormat = "yyyy-MM";
158 if (!parseToDateComponents(element()->fastGetAttribute(minAttr), &layoutPara meters.minimum)) 158 if (!parseToDateComponents(element().fastGetAttribute(minAttr), &layoutParam eters.minimum))
159 layoutParameters.minimum = DateComponents(); 159 layoutParameters.minimum = DateComponents();
160 if (!parseToDateComponents(element()->fastGetAttribute(maxAttr), &layoutPara meters.maximum)) 160 if (!parseToDateComponents(element().fastGetAttribute(maxAttr), &layoutParam eters.maximum))
161 layoutParameters.maximum = DateComponents(); 161 layoutParameters.maximum = DateComponents();
162 layoutParameters.placeholderForMonth = "--"; 162 layoutParameters.placeholderForMonth = "--";
163 layoutParameters.placeholderForYear = "----"; 163 layoutParameters.placeholderForYear = "----";
164 } 164 }
165 165
166 bool MonthInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bo ol hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const 166 bool MonthInputType::isValidFormat(bool hasYear, bool hasMonth, bool hasWeek, bo ol hasDay, bool hasAMPM, bool hasHour, bool hasMinute, bool hasSecond) const
167 { 167 {
168 return hasYear && hasMonth; 168 return hasYear && hasMonth;
169 } 169 }
170 #endif 170 #endif
171 } // namespace WebCore 171 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/forms/MonthInputType.h ('k') | Source/core/html/forms/NumberInputType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698