Changeset 114999 in webkit


Ignore:
Timestamp:
Apr 23, 2012 10:57:33 PM (12 years ago)
Author:
tkent@chromium.org
Message:

Show the format indicator in a date field
https://bugs.webkit.org/show_bug.cgi?id=83872

Reviewed by Hajime Morita.

Source/WebCore:

Enable the fixed placeholder feature for the date type, and show
the editable date format as the fixed placeholder.
The format string is created by the following steps.

  1. Obtain a pattern string from ICU http://icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details
  2. Replace a sequence of 'y', 'Y', 'M', or 'd' in the pattern with a natural language string such as "year", "month", or "day".

Test: fast/forms/date/date-fixed-placeholder.html

  • html/DateInputType.cpp:

(WebCore::DateInputType::supportsPlaceholder): Added. Returns true.
(WebCore::DateInputType::usesFixedPlaceholder): Added. Returns true.
(WebCore::DateInputType::fixedPlaceholder):
Added. Calls localizedDateFormatText() provided by LocalizedDate.h.

  • html/DateInputType.h:

(DateInputType): Add declarations of new override functions.

  • platform/LocalizedStrings.h:

(WebCore): Add dateFormat{Year,Month,DayInMonth}Text()

  • platform/text/ICULocale.cpp:

(WebCore::isICUYearSymbol): A function to improve redability.
(WebCore::isICUMonthSymbol): ditto.
(WebCore::isICUDayInMonthSymbol): ditto.
(WebCore::localizeFormat): Step 2 of the above description.
(WebCore::ICULocale::initializeLocalizedDateFormatText):
Step 1 of the above description.
(WebCore::ICULocale::localizedDateFormatText):

  • platform/text/ICULocale.h:

(ICULocale): Add new functions and a data member.

  • platform/text/LocalizedDate.h:

(WebCore): Add localizedDateFormatText().

  • platform/text/LocalizedDateICU.cpp:

(WebCore::localizedDateFormatText):
Just call ICULocale::localizedDateFormatText().

Source/WebKit/chromium:

  • src/LocalizedStrings.cpp:

(WebCore::dateFormatYearText): Added a stub.
(WebCore::dateFormatMonthText): ditto.
(WebCore::dateFormatDayInMonthText): ditto.

LayoutTests:

  • fast/forms/date/date-fixed-placeholder-expected.txt: Added.
  • fast/forms/date/date-fixed-placeholder.html: Added.
  • platform/chromium/test_expectations.txt:

Mark date-appearance.html FAIL because of render dump change.

Location:
trunk
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r114998 r114999  
     12012-04-23  Kent Tamura  <tkent@chromium.org>
     2
     3        Show the format indicator in a date field
     4        https://bugs.webkit.org/show_bug.cgi?id=83872
     5
     6        Reviewed by Hajime Morita.
     7
     8        * fast/forms/date/date-fixed-placeholder-expected.txt: Added.
     9        * fast/forms/date/date-fixed-placeholder.html: Added.
     10        * platform/chromium/test_expectations.txt:
     11        Mark date-appearance.html FAIL because of render dump change.
     12
    1132012-04-23  Dmitry Titov  <dimich@chromium.org>
    214
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r114995 r114999  
    10981098BUGWK29359 : fast/forms/time = PASS FAIL
    10991099BUGWK29359 : fast/forms/week = PASS FAIL
     1100// Need rebaseline
     1101BUGWK83872 : fast/forms/date/date-appearance.html = FAIL
    11001102
    11011103BUGCR78376 : http/tests/media/video-play-stall-seek.html = TIMEOUT
  • trunk/Source/WebCore/ChangeLog

    r114997 r114999  
     12012-04-23  Kent Tamura  <tkent@chromium.org>
     2
     3        Show the format indicator in a date field
     4        https://bugs.webkit.org/show_bug.cgi?id=83872
     5
     6        Reviewed by Hajime Morita.
     7
     8        Enable the fixed placeholder feature for the date type, and show
     9        the editable date format as the fixed placeholder.
     10        The format string is created by the following steps.
     11        1. Obtain a pattern string from ICU
     12          http://icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details
     13        2. Replace a sequence of 'y', 'Y', 'M', or 'd' in the pattern with
     14          a natural language string such as "year", "month", or "day".
     15
     16        Test: fast/forms/date/date-fixed-placeholder.html
     17
     18        * html/DateInputType.cpp:
     19        (WebCore::DateInputType::supportsPlaceholder): Added. Returns true.
     20        (WebCore::DateInputType::usesFixedPlaceholder): Added. Returns true.
     21        (WebCore::DateInputType::fixedPlaceholder):
     22        Added. Calls localizedDateFormatText() provided by LocalizedDate.h.
     23        * html/DateInputType.h:
     24        (DateInputType): Add declarations of new override functions.
     25        * platform/LocalizedStrings.h:
     26        (WebCore): Add dateFormat{Year,Month,DayInMonth}Text()
     27        * platform/text/ICULocale.cpp:
     28        (WebCore::isICUYearSymbol): A function to improve redability.
     29        (WebCore::isICUMonthSymbol): ditto.
     30        (WebCore::isICUDayInMonthSymbol): ditto.
     31        (WebCore::localizeFormat): Step 2 of the above description.
     32        (WebCore::ICULocale::initializeLocalizedDateFormatText):
     33        Step 1 of the above description.
     34        (WebCore::ICULocale::localizedDateFormatText):
     35        * platform/text/ICULocale.h:
     36        (ICULocale): Add new functions and a data member.
     37        * platform/text/LocalizedDate.h:
     38        (WebCore): Add localizedDateFormatText().
     39        * platform/text/LocalizedDateICU.cpp:
     40        (WebCore::localizedDateFormatText):
     41        Just call ICULocale::localizedDateFormatText().
     42
    1432012-04-23  Kentaro Hara  <haraken@chromium.org>
    244
  • trunk/Source/WebCore/html/DateInputType.cpp

    r114092 r114999  
    3636#include "HTMLInputElement.h"
    3737#include "HTMLNames.h"
     38#include "LocalizedDate.h"
    3839#include <wtf/PassOwnPtr.h>
    3940
     
    140141    element()->updateInnerTextValue();
    141142}
     143
     144bool DateInputType::supportsPlaceholder() const
     145{
     146    return true;
     147}
     148
     149bool DateInputType::usesFixedPlaceholder() const
     150{
     151    return true;
     152}
     153
     154String DateInputType::fixedPlaceholder()
     155{
     156    return localizedDateFormatText();
     157}
    142158#endif // ENABLE(CALENDAR_PICKER)
    143159
  • trunk/Source/WebCore/html/DateInputType.h

    r113972 r114999  
    6060    virtual void destroyShadowSubtree() OVERRIDE;
    6161    virtual void handleBlurEvent() OVERRIDE;
     62    virtual bool supportsPlaceholder() const OVERRIDE;
     63    virtual bool usesFixedPlaceholder() const OVERRIDE;
     64    virtual String fixedPlaceholder() OVERRIDE;
    6265
    6366    // TextFieldInputType functions
  • trunk/Source/WebCore/platform/LocalizedStrings.h

    r113166 r114999  
    215215    String calendarTodayText();
    216216    String calendarClearText();
     217    String dateFormatYearText();
     218    String dateFormatMonthText();
     219    String dateFormatDayInMonthText();
    217220#endif
    218221
  • trunk/Source/WebCore/platform/text/ICULocale.cpp

    r114971 r114999  
    3232#include "ICULocale.h"
    3333
     34#include "LocalizedStrings.h"
    3435#include <limits>
    3536#include <wtf/PassOwnPtr.h>
     
    312313
    313314#if ENABLE(CALENDAR_PICKER)
     315static inline bool isICUYearSymbol(UChar letter)
     316{
     317    return letter == 'y' || letter == 'Y';
     318}
     319
     320static inline bool isICUMonthSymbol(UChar letter)
     321{
     322    return letter == 'M';
     323}
     324
     325static inline bool isICUDayInMonthSymbol(UChar letter)
     326{
     327    return letter == 'd';
     328}
     329
     330// Specification of the input:
     331// http://icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details
     332static String localizeFormat(const Vector<UChar>& buffer)
     333{
     334    StringBuilder builder;
     335    UChar lastChar = 0;
     336    bool inQuote = false;
     337    for (unsigned i = 0; i < buffer.size(); ++i) {
     338        if (inQuote) {
     339            if (buffer[i] == '\'') {
     340                inQuote = false;
     341                lastChar = 0;
     342                ASSERT(i);
     343                if (buffer[i - 1] == '\'')
     344                    builder.append('\'');
     345            } else
     346                builder.append(buffer[i]);
     347        } else {
     348            if (isASCIIAlpha(lastChar) && lastChar == buffer[i])
     349                continue;
     350            lastChar = buffer[i];
     351            if (isICUYearSymbol(lastChar)) {
     352                String text = dateFormatYearText();
     353                builder.append(text.isEmpty() ? "Year" : text);
     354            } else if (isICUMonthSymbol(lastChar)) {
     355                String text = dateFormatMonthText();
     356                builder.append(text.isEmpty() ? "Month" : text);
     357            } else if (isICUDayInMonthSymbol(lastChar)) {
     358                String text = dateFormatDayInMonthText();
     359                builder.append(text.isEmpty() ? "Day" : text);
     360            } else if (lastChar == '\'')
     361                inQuote = true;
     362            else
     363                builder.append(lastChar);
     364        }
     365    }
     366    return builder.toString();
     367}
     368
     369void ICULocale::initializeLocalizedDateFormatText()
     370{
     371    if (!m_localizedDateFormatText.isNull())
     372        return;
     373    m_localizedDateFormatText = String("");
     374    if (!initializeShortDateFormat())
     375        return;
     376    UErrorCode status = U_ZERO_ERROR;
     377    int32_t length = udat_toPattern(m_shortDateFormat, TRUE, 0, 0, &status);
     378    if (status != U_BUFFER_OVERFLOW_ERROR)
     379        return;
     380    Vector<UChar> buffer(length);
     381    status = U_ZERO_ERROR;
     382    udat_toPattern(m_shortDateFormat, TRUE, buffer.data(), length, &status);
     383    if (U_FAILURE(status))
     384        return;
     385    m_localizedDateFormatText = localizeFormat(buffer);
     386}
     387
     388String ICULocale::localizedDateFormatText()
     389{
     390    initializeLocalizedDateFormatText();
     391    return m_localizedDateFormatText;
     392}
     393
    314394PassOwnPtr<Vector<String> > ICULocale::createLabelVector(UDateFormatSymbolType type, int32_t startIndex, int32_t size)
    315395{
  • trunk/Source/WebCore/platform/text/ICULocale.h

    r114971 r114999  
    5757    double parseLocalizedDate(const String&);
    5858    String formatLocalizedDate(const DateComponents&);
     59#if ENABLE(CALENDAR_PICKER)
     60    String localizedDateFormatText();
    5961
    60 #if ENABLE(CALENDAR_PICKER)
    6162    // For LocalizedCalendar
    6263    const Vector<String>& monthLabels();
     
    7879
    7980#if ENABLE(CALENDAR_PICKER)
     81    void initializeLocalizedDateFormatText();
    8082    PassOwnPtr<Vector<String> > createLabelVector(UDateFormatSymbolType, int32_t startIndex, int32_t size);
    8183    void initializeCalendar();
     
    100102
    101103#if ENABLE(CALENDAR_PICKER)
     104    String m_localizedDateFormatText;
    102105    OwnPtr<Vector<String> > m_monthLabels;
    103106    OwnPtr<Vector<String> > m_weekDayShortLabels;
  • trunk/Source/WebCore/platform/text/LocalizedDate.h

    r95901 r114999  
    4545String formatLocalizedDate(const DateComponents& dateComponents);
    4646
     47#if ENABLE(CALENDAR_PICKER)
     48String localizedDateFormatText();
     49#endif
    4750} // namespace WebCore
    4851
  • trunk/Source/WebCore/platform/text/LocalizedDateICU.cpp

    r114971 r114999  
    7171}
    7272
     73#if ENABLE(CALENDAR_PICKER)
     74String localizedDateFormatText()
     75{
     76    return ICULocale::currentLocale()->localizedDateFormatText();
    7377}
     78#endif
     79
     80}
  • trunk/Source/WebKit/chromium/ChangeLog

    r114993 r114999  
     12012-04-23  Kent Tamura  <tkent@chromium.org>
     2
     3        Show the format indicator in a date field
     4        https://bugs.webkit.org/show_bug.cgi?id=83872
     5
     6        Reviewed by Hajime Morita.
     7
     8        * src/LocalizedStrings.cpp:
     9        (WebCore::dateFormatYearText): Added a stub.
     10        (WebCore::dateFormatMonthText): ditto.
     11        (WebCore::dateFormatDayInMonthText): ditto.
     12
    1132012-04-23  Michael Nordman  <michaeln@google.com>
    214
  • trunk/Source/WebKit/chromium/src/LocalizedStrings.cpp

    r114186 r114999  
    407407    return query(WebLocalizedString::CalendarClear);
    408408}
     409
     410String dateFormatYearText()
     411{
     412    // FXIME: Implement.
     413    return String();
     414}
     415
     416String dateFormatMonthText()
     417{
     418    // FXIME: Implement.
     419    return String();
     420}
     421
     422String dateFormatDayInMonthText()
     423{
     424    // FXIME: Implement.
     425    return String();
     426}
    409427#endif
    410428
Note: See TracChangeset for help on using the changeset viewer.