1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26 #ifndef DateTimeFieldElements_h 27 #define DateTimeFieldElements_h 28 29 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 30 #include "core/html/shadow/DateTimeNumericFieldElement.h" 31 #include "core/html/shadow/DateTimeSymbolicFieldElement.h" 32 33 namespace WebCore { 34 35 class DateTimeAMPMFieldElement FINAL : public DateTimeSymbolicFieldElement { 36 WTF_MAKE_NONCOPYABLE(DateTimeAMPMFieldElement); 37 38 public: 39 static PassRefPtr<DateTimeAMPMFieldElement> create(Document&, FieldOwner&, const Vector<String>&); 40 41 private: 42 DateTimeAMPMFieldElement(Document&, FieldOwner&, const Vector<String>&); 43 44 // DateTimeFieldElement functions. 45 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 46 virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL; 47 virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL; 48 }; 49 50 class DateTimeDayFieldElement FINAL : public DateTimeNumericFieldElement { 51 WTF_MAKE_NONCOPYABLE(DateTimeDayFieldElement); 52 53 public: 54 static PassRefPtr<DateTimeDayFieldElement> create(Document&, FieldOwner&, const String& placeholder, const Range&); 55 56 private: 57 DateTimeDayFieldElement(Document&, FieldOwner&, const String& placeholder, const Range&); 58 59 // DateTimeFieldElement functions. 60 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 61 virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL; 62 virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL; 63 }; 64 65 class DateTimeHourFieldElementBase : public DateTimeNumericFieldElement { 66 WTF_MAKE_NONCOPYABLE(DateTimeHourFieldElementBase); 67 68 protected: 69 DateTimeHourFieldElementBase(Document&, FieldOwner&, const Range&, const Range& hardLimits, const Step&); 70 void initialize(); 71 72 private: 73 // DateTimeFieldElement functions. 74 virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL; 75 virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL; 76 }; 77 78 class DateTimeHour11FieldElement FINAL : public DateTimeHourFieldElementBase { 79 WTF_MAKE_NONCOPYABLE(DateTimeHour11FieldElement); 80 81 public: 82 static PassRefPtr<DateTimeHour11FieldElement> create(Document&, FieldOwner&, const Range&, const Step&); 83 84 private: 85 DateTimeHour11FieldElement(Document&, FieldOwner&, const Range& hour23Range, const Step&); 86 87 // DateTimeFieldElement functions. 88 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 89 virtual void setValueAsInteger(int, EventBehavior = DispatchNoEvent) OVERRIDE FINAL; 90 }; 91 92 class DateTimeHour12FieldElement FINAL : public DateTimeHourFieldElementBase { 93 WTF_MAKE_NONCOPYABLE(DateTimeHour12FieldElement); 94 95 public: 96 static PassRefPtr<DateTimeHour12FieldElement> create(Document&, FieldOwner&, const Range&, const Step&); 97 98 private: 99 DateTimeHour12FieldElement(Document&, FieldOwner&, const Range& hour23Range, const Step&); 100 101 // DateTimeFieldElement functions. 102 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 103 virtual void setValueAsInteger(int, EventBehavior = DispatchNoEvent) OVERRIDE FINAL; 104 }; 105 106 class DateTimeHour23FieldElement FINAL : public DateTimeHourFieldElementBase { 107 WTF_MAKE_NONCOPYABLE(DateTimeHour23FieldElement); 108 109 public: 110 static PassRefPtr<DateTimeHour23FieldElement> create(Document&, FieldOwner&, const Range&, const Step&); 111 112 private: 113 DateTimeHour23FieldElement(Document&, FieldOwner&, const Range& hour23Range, const Step&); 114 115 // DateTimeFieldElement functions. 116 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 117 virtual void setValueAsInteger(int, EventBehavior = DispatchNoEvent) OVERRIDE FINAL; 118 }; 119 120 class DateTimeHour24FieldElement FINAL : public DateTimeHourFieldElementBase { 121 WTF_MAKE_NONCOPYABLE(DateTimeHour24FieldElement); 122 123 public: 124 static PassRefPtr<DateTimeHour24FieldElement> create(Document&, FieldOwner&, const Range&, const Step&); 125 126 private: 127 DateTimeHour24FieldElement(Document&, FieldOwner&, const Range& hour23Range, const Step&); 128 129 // DateTimeFieldElement functions. 130 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 131 virtual void setValueAsInteger(int, EventBehavior = DispatchNoEvent) OVERRIDE FINAL; 132 }; 133 134 class DateTimeMillisecondFieldElement FINAL : public DateTimeNumericFieldElement { 135 WTF_MAKE_NONCOPYABLE(DateTimeMillisecondFieldElement); 136 137 public: 138 static PassRefPtr<DateTimeMillisecondFieldElement> create(Document&, FieldOwner&, const Range&, const Step&); 139 140 private: 141 DateTimeMillisecondFieldElement(Document&, FieldOwner&, const Range&, const Step&); 142 143 // DateTimeFieldElement functions. 144 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 145 virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL; 146 virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL; 147 }; 148 149 class DateTimeMinuteFieldElement FINAL : public DateTimeNumericFieldElement { 150 WTF_MAKE_NONCOPYABLE(DateTimeMinuteFieldElement); 151 152 public: 153 static PassRefPtr<DateTimeMinuteFieldElement> create(Document&, FieldOwner&, const Range&, const Step&); 154 155 private: 156 DateTimeMinuteFieldElement(Document&, FieldOwner&, const Range&, const Step&); 157 158 // DateTimeFieldElement functions. 159 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 160 virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL; 161 virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL; 162 }; 163 164 class DateTimeMonthFieldElement FINAL : public DateTimeNumericFieldElement { 165 WTF_MAKE_NONCOPYABLE(DateTimeMonthFieldElement); 166 167 public: 168 static PassRefPtr<DateTimeMonthFieldElement> create(Document&, FieldOwner&, const String& placeholder, const Range&); 169 170 private: 171 DateTimeMonthFieldElement(Document&, FieldOwner&, const String& placeholder, const Range&); 172 173 // DateTimeFieldElement functions. 174 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 175 virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL; 176 virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL; 177 }; 178 179 class DateTimeSecondFieldElement FINAL : public DateTimeNumericFieldElement { 180 WTF_MAKE_NONCOPYABLE(DateTimeSecondFieldElement); 181 182 public: 183 static PassRefPtr<DateTimeSecondFieldElement> create(Document&, FieldOwner&, const Range&, const Step&); 184 185 private: 186 DateTimeSecondFieldElement(Document&, FieldOwner&, const Range&, const Step&); 187 188 // DateTimeFieldElement functions. 189 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 190 virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL; 191 virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL; 192 }; 193 194 class DateTimeSymbolicMonthFieldElement FINAL : public DateTimeSymbolicFieldElement { 195 WTF_MAKE_NONCOPYABLE(DateTimeSymbolicMonthFieldElement); 196 197 public: 198 static PassRefPtr<DateTimeSymbolicMonthFieldElement> create(Document&, FieldOwner&, const Vector<String>&, int minimum, int maximum); 199 200 private: 201 DateTimeSymbolicMonthFieldElement(Document&, FieldOwner&, const Vector<String>&, int minimum, int maximum); 202 203 // DateTimeFieldElement functions. 204 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 205 virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL; 206 virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL; 207 }; 208 209 class DateTimeWeekFieldElement FINAL : public DateTimeNumericFieldElement { 210 WTF_MAKE_NONCOPYABLE(DateTimeWeekFieldElement); 211 212 public: 213 static PassRefPtr<DateTimeWeekFieldElement> create(Document&, FieldOwner&, const Range&); 214 215 private: 216 DateTimeWeekFieldElement(Document&, FieldOwner&, const Range&); 217 218 // DateTimeFieldElement functions. 219 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 220 virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL; 221 virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL; 222 }; 223 224 class DateTimeYearFieldElement FINAL : public DateTimeNumericFieldElement { 225 WTF_MAKE_NONCOPYABLE(DateTimeYearFieldElement); 226 227 public: 228 struct Parameters { 229 int minimumYear; 230 int maximumYear; 231 bool minIsSpecified; 232 bool maxIsSpecified; 233 String placeholder; 234 ParametersParameters235 Parameters() 236 : minimumYear(-1) 237 , maximumYear(-1) 238 , minIsSpecified(false) 239 , maxIsSpecified(false) 240 { 241 } 242 }; 243 244 static PassRefPtr<DateTimeYearFieldElement> create(Document&, FieldOwner&, const Parameters&); 245 246 private: 247 DateTimeYearFieldElement(Document&, FieldOwner&, const Parameters&); 248 249 // DateTimeFieldElement functions. 250 virtual void populateDateTimeFieldsState(DateTimeFieldsState&) OVERRIDE FINAL; 251 virtual void setValueAsDate(const DateComponents&) OVERRIDE FINAL; 252 virtual void setValueAsDateTimeFieldsState(const DateTimeFieldsState&) OVERRIDE FINAL; 253 254 // DateTimeNumericFieldElement functions. 255 virtual int defaultValueForStepDown() const OVERRIDE FINAL; 256 virtual int defaultValueForStepUp() const OVERRIDE FINAL; 257 258 bool m_minIsSpecified; 259 bool m_maxIsSpecified; 260 }; 261 262 } // namespace WebCore 263 264 #endif 265 #endif 266