OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/date_time_formatter.h" | 5 #include "content/renderer/date_time_formatter.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "third_party/WebKit/public/platform/WebCString.h" | 9 #include "third_party/WebKit/public/platform/WebCString.h" |
10 #include "third_party/WebKit/public/web/WebDateTimeChooserParams.h" | 10 #include "third_party/WebKit/public/web/WebDateTimeChooserParams.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 if (!TryPattern(pattern, icu_value)) | 70 if (!TryPattern(pattern, icu_value)) |
71 return last_pattern; | 71 return last_pattern; |
72 last_pattern = pattern; | 72 last_pattern = pattern; |
73 pattern = "HH:mm:ss.SSS"; | 73 pattern = "HH:mm:ss.SSS"; |
74 if (!TryPattern(pattern, icu_value)) | 74 if (!TryPattern(pattern, icu_value)) |
75 return last_pattern; | 75 return last_pattern; |
76 return pattern; | 76 return pattern; |
77 } | 77 } |
78 | 78 |
79 DateTimeFormatter::DateTimeFormatter( | 79 DateTimeFormatter::DateTimeFormatter( |
80 const WebKit::WebDateTimeChooserParams& source) | 80 const blink::WebDateTimeChooserParams& source) |
81 : formatted_string_(source.currentValue.utf8()) { | 81 : formatted_string_(source.currentValue.utf8()) { |
82 CreatePatternMap(); | 82 CreatePatternMap(); |
83 if (source.type == WebKit::WebDateTimeInputTypeTime) | 83 if (source.type == blink::WebDateTimeInputTypeTime) |
84 time_pattern_ = | 84 time_pattern_ = |
85 FindLongestTimePatternWhichMatches(formatted_string_, source.step); | 85 FindLongestTimePatternWhichMatches(formatted_string_, source.step); |
86 ExtractType(source); | 86 ExtractType(source); |
87 if (!ParseValues()) { | 87 if (!ParseValues()) { |
88 type_ = ui::TEXT_INPUT_TYPE_NONE; | 88 type_ = ui::TEXT_INPUT_TYPE_NONE; |
89 ClearAll(); | 89 ClearAll(); |
90 LOG(WARNING) << "Problems parsing input <" << formatted_string_ << ">"; | 90 LOG(WARNING) << "Problems parsing input <" << formatted_string_ << ">"; |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 static_cast<size_t>(formatted_time.length()), | 207 static_cast<size_t>(formatted_time.length()), |
208 &result); | 208 &result); |
209 if (success <= U_ZERO_ERROR) | 209 if (success <= U_ZERO_ERROR) |
210 return result; | 210 return result; |
211 } | 211 } |
212 LOG(WARNING) << "Calendar not created: error " << success; | 212 LOG(WARNING) << "Calendar not created: error " << success; |
213 return std::string(); | 213 return std::string(); |
214 } | 214 } |
215 | 215 |
216 void DateTimeFormatter::ExtractType( | 216 void DateTimeFormatter::ExtractType( |
217 const WebKit::WebDateTimeChooserParams& source) { | 217 const blink::WebDateTimeChooserParams& source) { |
218 switch (source.type) { | 218 switch (source.type) { |
219 case WebKit::WebDateTimeInputTypeDate: | 219 case blink::WebDateTimeInputTypeDate: |
220 type_ = ui::TEXT_INPUT_TYPE_DATE; | 220 type_ = ui::TEXT_INPUT_TYPE_DATE; |
221 break; | 221 break; |
222 case WebKit::WebDateTimeInputTypeDateTime: | 222 case blink::WebDateTimeInputTypeDateTime: |
223 type_ = ui::TEXT_INPUT_TYPE_DATE_TIME; | 223 type_ = ui::TEXT_INPUT_TYPE_DATE_TIME; |
224 break; | 224 break; |
225 case WebKit::WebDateTimeInputTypeDateTimeLocal: | 225 case blink::WebDateTimeInputTypeDateTimeLocal: |
226 type_ = ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL; | 226 type_ = ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL; |
227 break; | 227 break; |
228 case WebKit::WebDateTimeInputTypeMonth: | 228 case blink::WebDateTimeInputTypeMonth: |
229 type_ = ui::TEXT_INPUT_TYPE_MONTH; | 229 type_ = ui::TEXT_INPUT_TYPE_MONTH; |
230 break; | 230 break; |
231 case WebKit::WebDateTimeInputTypeTime: | 231 case blink::WebDateTimeInputTypeTime: |
232 type_ = ui::TEXT_INPUT_TYPE_TIME; | 232 type_ = ui::TEXT_INPUT_TYPE_TIME; |
233 break; | 233 break; |
234 case WebKit::WebDateTimeInputTypeWeek: | 234 case blink::WebDateTimeInputTypeWeek: |
235 type_ = ui::TEXT_INPUT_TYPE_WEEK; | 235 type_ = ui::TEXT_INPUT_TYPE_WEEK; |
236 break; | 236 break; |
237 case WebKit::WebDateTimeInputTypeNone: | 237 case blink::WebDateTimeInputTypeNone: |
238 default: | 238 default: |
239 type_ = ui::TEXT_INPUT_TYPE_NONE; | 239 type_ = ui::TEXT_INPUT_TYPE_NONE; |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 // Not all fields are defined in all configurations and ICU might store | 243 // Not all fields are defined in all configurations and ICU might store |
244 // garbage if success <= U_ZERO_ERROR so the output is sanitized here. | 244 // garbage if success <= U_ZERO_ERROR so the output is sanitized here. |
245 int DateTimeFormatter::ExtractValue( | 245 int DateTimeFormatter::ExtractValue( |
246 const icu::Calendar* calendar, UCalendarDateFields value) const { | 246 const icu::Calendar* calendar, UCalendarDateFields value) const { |
247 UErrorCode success = U_ZERO_ERROR; | 247 UErrorCode success = U_ZERO_ERROR; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 day_ = 0; | 291 day_ = 0; |
292 hour_ = 0; | 292 hour_ = 0; |
293 minute_ = 0; | 293 minute_ = 0; |
294 second_ = 0; | 294 second_ = 0; |
295 milli_ = 0; | 295 milli_ = 0; |
296 week_year_ = 0; | 296 week_year_ = 0; |
297 week_ = 0; | 297 week_ = 0; |
298 } | 298 } |
299 | 299 |
300 } // namespace content | 300 } // namespace content |
OLD | NEW |