/* * Copyright (C) 2012 Research In Motion Limited. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "config.h" #include "DatePickerClient.h" #include "Document.h" #include "Frame.h" #include "HTMLInputElement.h" #include "PopupPicker.h" #include "WebPage_p.h" #include #include #include #include #include using namespace WebCore; using namespace icu; namespace BlackBerry { namespace WebKit { DEFINE_STATIC_LOCAL(BlackBerry::Platform::LocalizeResource, s_resource, ()); DatePickerClient::DatePickerClient(BlackBerry::Platform::BlackBerryInputType type, const BlackBerry::Platform::String& value, const BlackBerry::Platform::String& min, const BlackBerry::Platform::String& max, double step, WebPagePrivate* webPagePrivate, WebCore::HTMLInputElement* element) : PagePopupClient(webPagePrivate) , m_type(type) , m_element(element) { generateHTML(type, value, min, max, step); } DatePickerClient::~DatePickerClient() { } void DatePickerClient::generateHTML(BlackBerry::Platform::BlackBerryInputType type, const BlackBerry::Platform::String& value, const BlackBerry::Platform::String& min, const BlackBerry::Platform::String& max, double step) { StringBuilder source; String title = ""; source.appendLiteral("\n\n"); source.appendLiteral("\n \n"); m_source = source.toString(); } void DatePickerClient::setValueAndClosePopup(const String& value) { // Popup closed. if (!m_element) return; // We hide caret when we select date input field, restore it when we close date picker. m_element->document()->frame()->selection()->setCaretVisible(true); // Return -1 if user cancel the selection. if (value != "-1") m_element->setValue(value, DispatchChangeEvent); closePopup(); } void DatePickerClient::didClosePopup() { PagePopupClient::didClosePopup(); m_element = 0; } // UDAT_foo are for labels that are meant to be formatted as part of a date. // UDAT_STANDALONE_foo are for labels that are displayed separately from other date components. // For example, UDAT_SHORT_MONTHS in Catalan puts a preposition in front of the month but UDAT_STANDALONE_SHORT_MONTHS does not. const String DatePickerClient::generateDateLabels(UDateFormatSymbolType symbolType) { UErrorCode uerrStatus = U_ZERO_ERROR; DateFormatSymbols dateSymbols = DateFormatSymbols(uerrStatus); // constructor will never fail const UnicodeString* labels = 0; int32_t labelCount = 0; switch (symbolType) { // dateSymbols retain ownership of return values from getFoo calls case UDAT_STANDALONE_MONTHS: labelCount = 12; labels = dateSymbols.getMonths(labelCount, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE); break; case UDAT_STANDALONE_SHORT_MONTHS: labelCount = 12; labels = dateSymbols.getMonths(labelCount, DateFormatSymbols::STANDALONE, DateFormatSymbols::ABBREVIATED); break; case UDAT_SHORT_MONTHS: labelCount = 12; labels = dateSymbols.getMonths(labelCount, DateFormatSymbols::FORMAT, DateFormatSymbols::ABBREVIATED); break; case UDAT_STANDALONE_WEEKDAYS: labelCount = 8; // getWeekdays returns an array where the zeroeth element is empty; the first label is placed in index 1 labels = &(dateSymbols.getWeekdays(labelCount, DateFormatSymbols::STANDALONE, DateFormatSymbols::WIDE))[1]; // skip zeroeth element --labelCount; break; case UDAT_AM_PMS: labelCount = 2; labels = dateSymbols.getAmPmStrings(labelCount); break; default: ASSERT(0); break; } StringBuilder printedLabels; printedLabels.appendLiteral("["); for (int32_t i = 0; i < labelCount; ++i) { String escapedLabel = String(labels[i].getBuffer(), labels[i].length()).replace('\\', "\\\\").replace('\'', "\\'"); // TODO PR 243547: refactor escaping of strings for DatePickerClient and SelectPopupClient printedLabels.append("'" + escapedLabel + "'"); if (i < labelCount - 1) printedLabels.appendLiteral(","); } printedLabels.appendLiteral("]"); return printedLabels.toString(); } } }