OLD | NEW |
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 25 matching lines...) Expand all Loading... |
36 #include "core/frame/FrameView.h" | 36 #include "core/frame/FrameView.h" |
37 #include "core/rendering/RenderTheme.h" | 37 #include "core/rendering/RenderTheme.h" |
38 #include "platform/DateComponents.h" | 38 #include "platform/DateComponents.h" |
39 #include "platform/DateTimeChooserClient.h" | 39 #include "platform/DateTimeChooserClient.h" |
40 #include "platform/Language.h" | 40 #include "platform/Language.h" |
41 #include "platform/text/PlatformLocale.h" | 41 #include "platform/text/PlatformLocale.h" |
42 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
43 #include "web/ChromeClientImpl.h" | 43 #include "web/ChromeClientImpl.h" |
44 #include "web/WebViewImpl.h" | 44 #include "web/WebViewImpl.h" |
45 | 45 |
46 using namespace blink; | |
47 | |
48 namespace blink { | 46 namespace blink { |
49 | 47 |
50 DateTimeChooserImpl::DateTimeChooserImpl(ChromeClientImpl* chromeClient, blink::
DateTimeChooserClient* client, const blink::DateTimeChooserParameters& parameter
s) | 48 DateTimeChooserImpl::DateTimeChooserImpl(ChromeClientImpl* chromeClient, DateTim
eChooserClient* client, const DateTimeChooserParameters& parameters) |
51 : m_chromeClient(chromeClient) | 49 : m_chromeClient(chromeClient) |
52 , m_client(client) | 50 , m_client(client) |
53 , m_popup(0) | 51 , m_popup(0) |
54 , m_parameters(parameters) | 52 , m_parameters(parameters) |
55 , m_locale(blink::Locale::create(parameters.locale)) | 53 , m_locale(Locale::create(parameters.locale)) |
56 { | 54 { |
57 ASSERT(m_chromeClient); | 55 ASSERT(m_chromeClient); |
58 ASSERT(m_client); | 56 ASSERT(m_client); |
59 m_popup = m_chromeClient->openPagePopup(this, m_parameters.anchorRectInRootV
iew); | 57 m_popup = m_chromeClient->openPagePopup(this, m_parameters.anchorRectInRootV
iew); |
60 } | 58 } |
61 | 59 |
62 PassRefPtrWillBeRawPtr<DateTimeChooserImpl> DateTimeChooserImpl::create(ChromeCl
ientImpl* chromeClient, blink::DateTimeChooserClient* client, const blink::DateT
imeChooserParameters& parameters) | 60 PassRefPtrWillBeRawPtr<DateTimeChooserImpl> DateTimeChooserImpl::create(ChromeCl
ientImpl* chromeClient, DateTimeChooserClient* client, const DateTimeChooserPara
meters& parameters) |
63 { | 61 { |
64 return adoptRefWillBeNoop(new DateTimeChooserImpl(chromeClient, client, para
meters)); | 62 return adoptRefWillBeNoop(new DateTimeChooserImpl(chromeClient, client, para
meters)); |
65 } | 63 } |
66 | 64 |
67 DateTimeChooserImpl::~DateTimeChooserImpl() | 65 DateTimeChooserImpl::~DateTimeChooserImpl() |
68 { | 66 { |
69 } | 67 } |
70 | 68 |
71 void DateTimeChooserImpl::endChooser() | 69 void DateTimeChooserImpl::endChooser() |
72 { | 70 { |
73 if (!m_popup) | 71 if (!m_popup) |
74 return; | 72 return; |
75 m_chromeClient->closePagePopup(m_popup); | 73 m_chromeClient->closePagePopup(m_popup); |
76 } | 74 } |
77 | 75 |
78 blink::IntSize DateTimeChooserImpl::contentSize() | 76 IntSize DateTimeChooserImpl::contentSize() |
79 { | 77 { |
80 return blink::IntSize(0, 0); | 78 return IntSize(0, 0); |
81 } | 79 } |
82 | 80 |
83 static String valueToDateTimeString(double value, AtomicString type) | 81 static String valueToDateTimeString(double value, AtomicString type) |
84 { | 82 { |
85 blink::DateComponents components; | 83 DateComponents components; |
86 if (type == blink::InputTypeNames::date) | 84 if (type == InputTypeNames::date) |
87 components.setMillisecondsSinceEpochForDate(value); | 85 components.setMillisecondsSinceEpochForDate(value); |
88 else if (type == blink::InputTypeNames::datetime_local) | 86 else if (type == InputTypeNames::datetime_local) |
89 components.setMillisecondsSinceEpochForDateTimeLocal(value); | 87 components.setMillisecondsSinceEpochForDateTimeLocal(value); |
90 else if (type == blink::InputTypeNames::month) | 88 else if (type == InputTypeNames::month) |
91 components.setMonthsSinceEpoch(value); | 89 components.setMonthsSinceEpoch(value); |
92 else if (type == blink::InputTypeNames::time) | 90 else if (type == InputTypeNames::time) |
93 components.setMillisecondsSinceMidnight(value); | 91 components.setMillisecondsSinceMidnight(value); |
94 else if (type == blink::InputTypeNames::week) | 92 else if (type == InputTypeNames::week) |
95 components.setMillisecondsSinceEpochForWeek(value); | 93 components.setMillisecondsSinceEpochForWeek(value); |
96 else | 94 else |
97 ASSERT_NOT_REACHED(); | 95 ASSERT_NOT_REACHED(); |
98 return components.type() == blink::DateComponents::Invalid ? String() : comp
onents.toString(); | 96 return components.type() == DateComponents::Invalid ? String() : components.
toString(); |
99 } | 97 } |
100 | 98 |
101 void DateTimeChooserImpl::writeDocument(blink::SharedBuffer* data) | 99 void DateTimeChooserImpl::writeDocument(SharedBuffer* data) |
102 { | 100 { |
103 String stepString = String::number(m_parameters.step); | 101 String stepString = String::number(m_parameters.step); |
104 String stepBaseString = String::number(m_parameters.stepBase, 11, WTF::Trunc
ateTrailingZeros); | 102 String stepBaseString = String::number(m_parameters.stepBase, 11, WTF::Trunc
ateTrailingZeros); |
105 IntRect anchorRectInScreen = m_chromeClient->rootViewToScreen(m_parameters.a
nchorRectInRootView); | 103 IntRect anchorRectInScreen = m_chromeClient->rootViewToScreen(m_parameters.a
nchorRectInRootView); |
106 String todayLabelString; | 104 String todayLabelString; |
107 String otherDateLabelString; | 105 String otherDateLabelString; |
108 if (m_parameters.type == blink::InputTypeNames::month) { | 106 if (m_parameters.type == InputTypeNames::month) { |
109 todayLabelString = locale().queryString(WebLocalizedString::ThisMonthBut
tonLabel); | 107 todayLabelString = locale().queryString(WebLocalizedString::ThisMonthBut
tonLabel); |
110 otherDateLabelString = locale().queryString(WebLocalizedString::OtherMon
thLabel); | 108 otherDateLabelString = locale().queryString(WebLocalizedString::OtherMon
thLabel); |
111 } else if (m_parameters.type == blink::InputTypeNames::week) { | 109 } else if (m_parameters.type == InputTypeNames::week) { |
112 todayLabelString = locale().queryString(WebLocalizedString::ThisWeekButt
onLabel); | 110 todayLabelString = locale().queryString(WebLocalizedString::ThisWeekButt
onLabel); |
113 otherDateLabelString = locale().queryString(WebLocalizedString::OtherWee
kLabel); | 111 otherDateLabelString = locale().queryString(WebLocalizedString::OtherWee
kLabel); |
114 } else { | 112 } else { |
115 todayLabelString = locale().queryString(WebLocalizedString::CalendarToda
y); | 113 todayLabelString = locale().queryString(WebLocalizedString::CalendarToda
y); |
116 otherDateLabelString = locale().queryString(WebLocalizedString::OtherDat
eLabel); | 114 otherDateLabelString = locale().queryString(WebLocalizedString::OtherDat
eLabel); |
117 } | 115 } |
118 | 116 |
119 addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", data); | 117 addString("<!DOCTYPE html><head><meta charset='UTF-8'><style>\n", data); |
120 data->append(blink::Platform::current()->loadResource("pickerCommon.css")); | 118 data->append(Platform::current()->loadResource("pickerCommon.css")); |
121 data->append(blink::Platform::current()->loadResource("pickerButton.css")); | 119 data->append(Platform::current()->loadResource("pickerButton.css")); |
122 data->append(blink::Platform::current()->loadResource("suggestionPicker.css"
)); | 120 data->append(Platform::current()->loadResource("suggestionPicker.css")); |
123 data->append(blink::Platform::current()->loadResource("calendarPicker.css"))
; | 121 data->append(Platform::current()->loadResource("calendarPicker.css")); |
124 addString("</style></head><body><div id=main>Loading...</div><script>\n" | 122 addString("</style></head><body><div id=main>Loading...</div><script>\n" |
125 "window.dialogArguments = {\n", data); | 123 "window.dialogArguments = {\n", data); |
126 addProperty("anchorRectInScreen", anchorRectInScreen, data); | 124 addProperty("anchorRectInScreen", anchorRectInScreen, data); |
127 addProperty("min", valueToDateTimeString(m_parameters.minimum, m_parameters.
type), data); | 125 addProperty("min", valueToDateTimeString(m_parameters.minimum, m_parameters.
type), data); |
128 addProperty("max", valueToDateTimeString(m_parameters.maximum, m_parameters.
type), data); | 126 addProperty("max", valueToDateTimeString(m_parameters.maximum, m_parameters.
type), data); |
129 addProperty("step", stepString, data); | 127 addProperty("step", stepString, data); |
130 addProperty("stepBase", stepBaseString, data); | 128 addProperty("stepBase", stepBaseString, data); |
131 addProperty("required", m_parameters.required, data); | 129 addProperty("required", m_parameters.required, data); |
132 addProperty("currentValue", valueToDateTimeString(m_parameters.doubleValue,
m_parameters.type), data); | 130 addProperty("currentValue", valueToDateTimeString(m_parameters.doubleValue,
m_parameters.type), data); |
133 addProperty("locale", m_parameters.locale.string(), data); | 131 addProperty("locale", m_parameters.locale.string(), data); |
(...skipping 12 matching lines...) Expand all Loading... |
146 Vector<String> suggestionLabels; | 144 Vector<String> suggestionLabels; |
147 for (unsigned i = 0; i < m_parameters.suggestions.size(); i++) { | 145 for (unsigned i = 0; i < m_parameters.suggestions.size(); i++) { |
148 suggestionValues.append(valueToDateTimeString(m_parameters.suggestio
ns[i].value, m_parameters.type)); | 146 suggestionValues.append(valueToDateTimeString(m_parameters.suggestio
ns[i].value, m_parameters.type)); |
149 localizedSuggestionValues.append(m_parameters.suggestions[i].localiz
edValue); | 147 localizedSuggestionValues.append(m_parameters.suggestions[i].localiz
edValue); |
150 suggestionLabels.append(m_parameters.suggestions[i].label); | 148 suggestionLabels.append(m_parameters.suggestions[i].label); |
151 } | 149 } |
152 addProperty("suggestionValues", suggestionValues, data); | 150 addProperty("suggestionValues", suggestionValues, data); |
153 addProperty("localizedSuggestionValues", localizedSuggestionValues, data
); | 151 addProperty("localizedSuggestionValues", localizedSuggestionValues, data
); |
154 addProperty("suggestionLabels", suggestionLabels, data); | 152 addProperty("suggestionLabels", suggestionLabels, data); |
155 addProperty("inputWidth", static_cast<unsigned>(m_parameters.anchorRectI
nRootView.width()), data); | 153 addProperty("inputWidth", static_cast<unsigned>(m_parameters.anchorRectI
nRootView.width()), data); |
156 addProperty("showOtherDateEntry", blink::RenderTheme::theme().supportsCa
lendarPicker(m_parameters.type), data); | 154 addProperty("showOtherDateEntry", RenderTheme::theme().supportsCalendarP
icker(m_parameters.type), data); |
157 addProperty("otherDateLabel", otherDateLabelString, data); | 155 addProperty("otherDateLabel", otherDateLabelString, data); |
158 addProperty("suggestionHighlightColor", blink::RenderTheme::theme().acti
veListBoxSelectionBackgroundColor().serialized(), data); | 156 addProperty("suggestionHighlightColor", RenderTheme::theme().activeListB
oxSelectionBackgroundColor().serialized(), data); |
159 addProperty("suggestionHighlightTextColor", blink::RenderTheme::theme().
activeListBoxSelectionForegroundColor().serialized(), data); | 157 addProperty("suggestionHighlightTextColor", RenderTheme::theme().activeL
istBoxSelectionForegroundColor().serialized(), data); |
160 } | 158 } |
161 addString("}\n", data); | 159 addString("}\n", data); |
162 | 160 |
163 data->append(blink::Platform::current()->loadResource("pickerCommon.js")); | 161 data->append(Platform::current()->loadResource("pickerCommon.js")); |
164 data->append(blink::Platform::current()->loadResource("suggestionPicker.js")
); | 162 data->append(Platform::current()->loadResource("suggestionPicker.js")); |
165 data->append(blink::Platform::current()->loadResource("calendarPicker.js")); | 163 data->append(Platform::current()->loadResource("calendarPicker.js")); |
166 addString("</script></body>\n", data); | 164 addString("</script></body>\n", data); |
167 } | 165 } |
168 | 166 |
169 blink::Locale& DateTimeChooserImpl::locale() | 167 Locale& DateTimeChooserImpl::locale() |
170 { | 168 { |
171 return *m_locale; | 169 return *m_locale; |
172 } | 170 } |
173 | 171 |
174 void DateTimeChooserImpl::setValueAndClosePopup(int numValue, const String& stri
ngValue) | 172 void DateTimeChooserImpl::setValueAndClosePopup(int numValue, const String& stri
ngValue) |
175 { | 173 { |
176 RefPtrWillBeRawPtr<DateTimeChooserImpl> protector(this); | 174 RefPtrWillBeRawPtr<DateTimeChooserImpl> protector(this); |
177 if (numValue >= 0) | 175 if (numValue >= 0) |
178 setValue(stringValue); | 176 setValue(stringValue); |
179 endChooser(); | 177 endChooser(); |
(...skipping 18 matching lines...) Expand all Loading... |
198 | 196 |
199 void DateTimeChooserImpl::trace(Visitor* visitor) | 197 void DateTimeChooserImpl::trace(Visitor* visitor) |
200 { | 198 { |
201 visitor->trace(m_client); | 199 visitor->trace(m_client); |
202 DateTimeChooser::trace(visitor); | 200 DateTimeChooser::trace(visitor); |
203 } | 201 } |
204 | 202 |
205 } // namespace blink | 203 } // namespace blink |
206 | 204 |
207 #endif // ENABLE(INPUT_MULTIPLE_FIELDS_UI) | 205 #endif // ENABLE(INPUT_MULTIPLE_FIELDS_UI) |
OLD | NEW |