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

Side by Side Diff: Source/web/DateTimeChooserImpl.cpp

Issue 62083004: Transfer date/time value to the chooser as a double (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@datetime3
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « Source/platform/DateTimeChooserClient.h ('k') | Source/web/ExternalDateTimeChooser.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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (!m_popup) 74 if (!m_popup)
75 return; 75 return;
76 m_chromeClient->closePagePopup(m_popup); 76 m_chromeClient->closePagePopup(m_popup);
77 } 77 }
78 78
79 WebCore::IntSize DateTimeChooserImpl::contentSize() 79 WebCore::IntSize DateTimeChooserImpl::contentSize()
80 { 80 {
81 return WebCore::IntSize(0, 0); 81 return WebCore::IntSize(0, 0);
82 } 82 }
83 83
84 static String valueToDateTimeString(double value, AtomicString type)
85 {
86 WebCore::DateComponents components;
87 if (type == WebCore::InputTypeNames::date)
88 components.setMillisecondsSinceEpochForDate(value);
89 else if (type == WebCore::InputTypeNames::datetime_local)
90 components.setMillisecondsSinceEpochForDateTimeLocal(value);
91 else if (type == WebCore::InputTypeNames::month)
92 components.setMonthsSinceEpoch(value);
93 else if (type == WebCore::InputTypeNames::time)
94 components.setMillisecondsSinceMidnight(value);
95 else if (type == WebCore::InputTypeNames::week)
96 components.setMillisecondsSinceEpochForWeek(value);
97 else
98 ASSERT_NOT_REACHED();
99 return components.type() == WebCore::DateComponents::Invalid ? String() : co mponents.toString();
100 }
101
84 void DateTimeChooserImpl::writeDocument(WebCore::DocumentWriter& writer) 102 void DateTimeChooserImpl::writeDocument(WebCore::DocumentWriter& writer)
85 { 103 {
86 WebCore::DateComponents minDate;
87 WebCore::DateComponents maxDate;
88 if (m_parameters.type == WebCore::InputTypeNames::month) {
89 minDate.setMonthsSinceEpoch(m_parameters.minimum);
90 maxDate.setMonthsSinceEpoch(m_parameters.maximum);
91 } else if (m_parameters.type == WebCore::InputTypeNames::week) {
92 minDate.setMillisecondsSinceEpochForWeek(m_parameters.minimum);
93 maxDate.setMillisecondsSinceEpochForWeek(m_parameters.maximum);
94 } else {
95 minDate.setMillisecondsSinceEpochForDate(m_parameters.minimum);
96 maxDate.setMillisecondsSinceEpochForDate(m_parameters.maximum);
97 }
98 String stepString = String::number(m_parameters.step); 104 String stepString = String::number(m_parameters.step);
99 String stepBaseString = String::number(m_parameters.stepBase, 11, WTF::Trunc ateTrailingZeros); 105 String stepBaseString = String::number(m_parameters.stepBase, 11, WTF::Trunc ateTrailingZeros);
100 IntRect anchorRectInScreen = m_chromeClient->rootViewToScreen(m_parameters.a nchorRectInRootView); 106 IntRect anchorRectInScreen = m_chromeClient->rootViewToScreen(m_parameters.a nchorRectInRootView);
101 String todayLabelString; 107 String todayLabelString;
102 String otherDateLabelString; 108 String otherDateLabelString;
103 if (m_parameters.type == WebCore::InputTypeNames::month) { 109 if (m_parameters.type == WebCore::InputTypeNames::month) {
104 todayLabelString = locale().queryString(WebLocalizedString::ThisMonthBut tonLabel); 110 todayLabelString = locale().queryString(WebLocalizedString::ThisMonthBut tonLabel);
105 otherDateLabelString = locale().queryString(WebLocalizedString::OtherMon thLabel); 111 otherDateLabelString = locale().queryString(WebLocalizedString::OtherMon thLabel);
106 } else if (m_parameters.type == WebCore::InputTypeNames::week) { 112 } else if (m_parameters.type == WebCore::InputTypeNames::week) {
107 todayLabelString = locale().queryString(WebLocalizedString::ThisWeekButt onLabel); 113 todayLabelString = locale().queryString(WebLocalizedString::ThisWeekButt onLabel);
108 otherDateLabelString = locale().queryString(WebLocalizedString::OtherWee kLabel); 114 otherDateLabelString = locale().queryString(WebLocalizedString::OtherWee kLabel);
109 } else { 115 } else {
110 todayLabelString = locale().queryString(WebLocalizedString::CalendarToda y); 116 todayLabelString = locale().queryString(WebLocalizedString::CalendarToda y);
111 otherDateLabelString = locale().queryString(WebLocalizedString::OtherDat eLabel); 117 otherDateLabelString = locale().queryString(WebLocalizedString::OtherDat eLabel);
112 } 118 }
113 119
114 addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", writer); 120 addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", writer);
115 writer.addData(pickerCommonCss, sizeof(pickerCommonCss)); 121 writer.addData(pickerCommonCss, sizeof(pickerCommonCss));
116 writer.addData(pickerButtonCss, sizeof(pickerButtonCss)); 122 writer.addData(pickerButtonCss, sizeof(pickerButtonCss));
117 writer.addData(suggestionPickerCss, sizeof(suggestionPickerCss)); 123 writer.addData(suggestionPickerCss, sizeof(suggestionPickerCss));
118 writer.addData(calendarPickerCss, sizeof(calendarPickerCss)); 124 writer.addData(calendarPickerCss, sizeof(calendarPickerCss));
119 addString("</style></head><body><div id=main>Loading...</div><script>\n" 125 addString("</style></head><body><div id=main>Loading...</div><script>\n"
120 "window.dialogArguments = {\n", writer); 126 "window.dialogArguments = {\n", writer);
121 addProperty("anchorRectInScreen", anchorRectInScreen, writer); 127 addProperty("anchorRectInScreen", anchorRectInScreen, writer);
122 addProperty("min", minDate.toString(), writer); 128 addProperty("min", valueToDateTimeString(m_parameters.minimum, m_parameters. type), writer);
123 addProperty("max", maxDate.toString(), writer); 129 addProperty("max", valueToDateTimeString(m_parameters.maximum, m_parameters. type), writer);
124 addProperty("step", stepString, writer); 130 addProperty("step", stepString, writer);
125 addProperty("stepBase", stepBaseString, writer); 131 addProperty("stepBase", stepBaseString, writer);
126 addProperty("required", m_parameters.required, writer); 132 addProperty("required", m_parameters.required, writer);
127 addProperty("currentValue", m_parameters.currentValue, writer); 133 addProperty("currentValue", valueToDateTimeString(m_parameters.doubleValue, m_parameters.type), writer);
128 addProperty("locale", m_parameters.locale.string(), writer); 134 addProperty("locale", m_parameters.locale.string(), writer);
129 addProperty("todayLabel", todayLabelString, writer); 135 addProperty("todayLabel", todayLabelString, writer);
130 addProperty("clearLabel", locale().queryString(WebLocalizedString::CalendarC lear), writer); 136 addProperty("clearLabel", locale().queryString(WebLocalizedString::CalendarC lear), writer);
131 addProperty("weekLabel", locale().queryString(WebLocalizedString::WeekNumber Label), writer); 137 addProperty("weekLabel", locale().queryString(WebLocalizedString::WeekNumber Label), writer);
132 addProperty("weekStartDay", m_locale->firstDayOfWeek(), writer); 138 addProperty("weekStartDay", m_locale->firstDayOfWeek(), writer);
133 addProperty("shortMonthLabels", m_locale->shortMonthLabels(), writer); 139 addProperty("shortMonthLabels", m_locale->shortMonthLabels(), writer);
134 addProperty("dayLabels", m_locale->weekDayShortLabels(), writer); 140 addProperty("dayLabels", m_locale->weekDayShortLabels(), writer);
135 addProperty("isLocaleRTL", m_locale->isRTL(), writer); 141 addProperty("isLocaleRTL", m_locale->isRTL(), writer);
136 addProperty("isRTL", m_parameters.isAnchorElementRTL, writer); 142 addProperty("isRTL", m_parameters.isAnchorElementRTL, writer);
137 addProperty("mode", m_parameters.type.string(), writer); 143 addProperty("mode", m_parameters.type.string(), writer);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 void DateTimeChooserImpl::didClosePopup() 185 void DateTimeChooserImpl::didClosePopup()
180 { 186 {
181 ASSERT(m_client); 187 ASSERT(m_client);
182 m_popup = 0; 188 m_popup = 0;
183 m_client->didEndChooser(); 189 m_client->didEndChooser();
184 } 190 }
185 191
186 } // namespace blink 192 } // namespace blink
187 193
188 #endif // ENABLE(INPUT_MULTIPLE_FIELDS_UI) 194 #endif // ENABLE(INPUT_MULTIPLE_FIELDS_UI)
OLDNEW
« no previous file with comments | « Source/platform/DateTimeChooserClient.h ('k') | Source/web/ExternalDateTimeChooser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698