Changeset 130477 in webkit


Ignore:
Timestamp:
Oct 5, 2012 12:35:58 AM (11 years ago)
Author:
tkent@chromium.org
Message:

Fix sub-field width to the maximum width of a placeholder and the maximum value
https://bugs.webkit.org/show_bug.cgi?id=98481

Reviewed by Hajime Morita.

Source/WebCore:

We can't assume a placeholder text is shorter than the width of
digits. The placeholder string for the year field of
input[type=week] is "----", but input[type=date] will have a
localized string for it.

We should set the 'width' CSS property to the maximum of the
placeholder width and the maximum value width in order to prevent
the field width from growing/narrowing.

Before this patch, we secured four digits space for a year field,
and allowed the field to grow its width when a larger year is
set. After this patch, we don't allow it to grow because the
'width' property is set to the maximum width.

Update week-multiple-fields-appearance-basic.html, and the
following tests are affected.

  • fast/forms/week-multiple-fields/week-multiple-fields-appearance-pseudo-classes.html
  • fast/forms/week-multiple-fields/week-multiple-fields-appearance-pseudo-elements.html
  • fast/forms/week-multiple-fields/week-multiple-fields-appearance-style.html
  • html/shadow/DateTimeNumericFieldElement.cpp:

(WebCore::DateTimeNumericFieldElement::DateTimeNumericFieldElement):
Enable customStyleForRenderer.
(WebCore::DateTimeNumericFieldElement::customStyleForRenderer):
Added. The code is similar to DateTimeSymbolicFieldElement::customStyleForRenderer().
(WebCore::DateTimeNumericFieldElement::formatValue):
Made a function with the code in value(). This is used in
customStyleForRenderer() and value().
(WebCore::DateTimeNumericFieldElement::value): Use formatValue().

  • html/shadow/DateTimeNumericFieldElement.h:

(DateTimeNumericFieldElement): Declare new functions.

LayoutTests:

Update a test and test expectations.

  • fast/forms/week-multiple-fields/week-multiple-fields-appearance-basic-expected.txt:
  • fast/forms/week-multiple-fields/week-multiple-fields-appearance-basic.html:
  • platform/chromium-mac/fast/forms/week-multiple-fields/week-multiple-fields-appearance-basic-expected.png:
  • platform/chromium-mac/fast/forms/week-multiple-fields/week-multiple-fields-appearance-pseudo-classes-expected.png:
  • platform/chromium-mac/fast/forms/week-multiple-fields/week-multiple-fields-appearance-pseudo-elements-expected.png:
  • platform/chromium-mac/fast/forms/week-multiple-fields/week-multiple-fields-appearance-style-expected.png:
  • platform/chromium/TestExpectations:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r130475 r130477  
     12012-10-04  Kent Tamura  <tkent@chromium.org>
     2
     3        Fix sub-field width to the maximum width of a placeholder and the maximum value
     4        https://bugs.webkit.org/show_bug.cgi?id=98481
     5
     6        Reviewed by Hajime Morita.
     7
     8        Update a test and test expectations.
     9
     10        * fast/forms/week-multiple-fields/week-multiple-fields-appearance-basic-expected.txt:
     11        * fast/forms/week-multiple-fields/week-multiple-fields-appearance-basic.html:
     12        * platform/chromium-mac/fast/forms/week-multiple-fields/week-multiple-fields-appearance-basic-expected.png:
     13        * platform/chromium-mac/fast/forms/week-multiple-fields/week-multiple-fields-appearance-pseudo-classes-expected.png:
     14        * platform/chromium-mac/fast/forms/week-multiple-fields/week-multiple-fields-appearance-pseudo-elements-expected.png:
     15        * platform/chromium-mac/fast/forms/week-multiple-fields/week-multiple-fields-appearance-style-expected.png:
     16        * platform/chromium/TestExpectations:
     17
    1182012-10-05  Kangil Han  <kangil.han@samsung.com>
    219
  • trunk/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-appearance-basic-expected.txt

    r130107 r130477  
    44readonly 
    55RTL 
     6With max 
  • trunk/LayoutTests/fast/forms/week-multiple-fields/week-multiple-fields-appearance-basic.html

    r130107 r130477  
    77    <li>readonly <input type="week" readonly> <input type="week" value="1982-W25" readonly></li>
    88    <li>RTL <input type="week" dir="rtl"> <input type="week" value="1982-W25" dir="rtl"></li>
     9    <li>With max <input type="week" max="9999-W52"> <input type="week" value="1982-W25" max="9999-W52"></li>
    910</ul>
    1011</body>
  • trunk/LayoutTests/platform/chromium/TestExpectations

    r130460 r130477  
    36503650webkit.org/b/98390 platform/chromium/fast/forms/date/date-suggestion-picker-appearance.html [ ImageOnlyFailure Pass ]
    36513651
     3652# Need rebaseline
     3653webkit.org/b/98481 fast/forms/week-multiple-fields/week-multiple-fields-appearance-basic.html [ ImageOnlyFailure Pass ]
     3654webkit.org/b/98481 fast/forms/week-multiple-fields/week-multiple-fields-appearance-pseudo-classes.html [ ImageOnlyFailure Pass ]
     3655webkit.org/b/98481 fast/forms/week-multiple-fields/week-multiple-fields-appearance-pseudo-elements.html [ ImageOnlyFailure Pass ]
     3656webkit.org/b/98481 fast/forms/week-multiple-fields/week-multiple-fields-appearance-style.html [ ImageOnlyFailure Pass ]
     3657
    36523658
    36533659# Numerous failures in software compositing.
  • trunk/Source/WebCore/ChangeLog

    r130476 r130477  
     12012-10-04  Kent Tamura  <tkent@chromium.org>
     2
     3        Fix sub-field width to the maximum width of a placeholder and the maximum value
     4        https://bugs.webkit.org/show_bug.cgi?id=98481
     5
     6        Reviewed by Hajime Morita.
     7
     8        We can't assume a placeholder text is shorter than the width of
     9        digits. The placeholder string for the year field of
     10        input[type=week] is "----", but input[type=date] will have a
     11        localized string for it.
     12
     13        We should set the 'width' CSS property to the maximum of the
     14        placeholder width and the maximum value width in order to prevent
     15        the field width from growing/narrowing.
     16
     17        Before this patch, we secured four digits space for a year field,
     18        and allowed the field to grow its width when a larger year is
     19        set. After this patch, we don't allow it to grow because the
     20        'width' property is set to the maximum width.
     21
     22        Update week-multiple-fields-appearance-basic.html, and the
     23        following tests are affected.
     24        - fast/forms/week-multiple-fields/week-multiple-fields-appearance-pseudo-classes.html
     25        - fast/forms/week-multiple-fields/week-multiple-fields-appearance-pseudo-elements.html
     26        - fast/forms/week-multiple-fields/week-multiple-fields-appearance-style.html
     27
     28        * html/shadow/DateTimeNumericFieldElement.cpp:
     29        (WebCore::DateTimeNumericFieldElement::DateTimeNumericFieldElement):
     30        Enable customStyleForRenderer.
     31        (WebCore::DateTimeNumericFieldElement::customStyleForRenderer):
     32        Added. The code is similar to DateTimeSymbolicFieldElement::customStyleForRenderer().
     33        (WebCore::DateTimeNumericFieldElement::formatValue):
     34        Made a function with the code in value(). This is used in
     35        customStyleForRenderer() and value().
     36        (WebCore::DateTimeNumericFieldElement::value): Use formatValue().
     37        * html/shadow/DateTimeNumericFieldElement.h:
     38        (DateTimeNumericFieldElement): Declare new functions.
     39
    1402012-10-05  Kent Tamura  <tkent@chromium.org>
    241
  • trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp

    r130362 r130477  
    2828#include "DateTimeNumericFieldElement.h"
    2929
     30#include "FontCache.h"
    3031#include "KeyboardEvent.h"
    3132#include "Localizer.h"
     33#include "RenderStyle.h"
     34#include "StyleResolver.h"
     35#include "TextRun.h"
    3236#include <wtf/text/StringBuilder.h>
    3337
     
    6367    , m_hasValue(false)
    6468{
     69    setHasCustomCallbacks();
    6570}
    6671
     
    7075}
    7176
     77PassRefPtr<RenderStyle> DateTimeNumericFieldElement::customStyleForRenderer()
     78{
     79    FontCachePurgePreventer fontCachePurgePreventer;
     80    RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForElement(this);
     81    RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
     82    float maxiumWidth = style->font().width(m_placeholder);
     83    maxiumWidth = std::max(maxiumWidth, style->font().width(formatValue(maximum())));
     84    style->setWidth(Length(maxiumWidth, Fixed));
     85    return style.release();
     86}
     87
    7288int DateTimeNumericFieldElement::defaultValueForStepDown() const
    7389{
     
    84100    m_lastDigitCharTime = 0;
    85101    DateTimeFieldElement::didBlur();
     102}
     103
     104String DateTimeNumericFieldElement::formatValue(int value) const
     105{
     106    Localizer& localizer = localizerForOwner();
     107    if (m_range.maximum > 999)
     108        return localizer.convertToLocalizedNumber(String::format("%04d", value));
     109    if (m_range.maximum > 99)
     110        return localizer.convertToLocalizedNumber(String::format("%03d", value));
     111    return localizer.convertToLocalizedNumber(String::format("%02d", value));
    86112}
    87113
     
    174200String DateTimeNumericFieldElement::value() const
    175201{
    176     if (!m_hasValue)
    177         return emptyString();
    178 
    179     Localizer& localizer = localizerForOwner();
    180     if (m_range.maximum > 999)
    181         return localizer.convertToLocalizedNumber(String::format("%04d", m_value));
    182 
    183     if (m_range.maximum > 99)
    184         return localizer.convertToLocalizedNumber(String::format("%03d", m_value));
    185 
    186     return localizer.convertToLocalizedNumber(String::format("%02d", m_value));
     202    return m_hasValue ? formatValue(m_value) : emptyString();
    187203}
    188204
  • trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.h

    r130362 r130477  
    6969
    7070private:
     71    // Element function.
     72    virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE;
     73
    7174    // DateTimeFieldElement functions.
    7275    virtual void didBlur() OVERRIDE FINAL;
     
    7780    virtual String value() const OVERRIDE FINAL;
    7881
     82    String formatValue(int) const;
    7983    Localizer& localizerForOwner() const;
    8084
Note: See TracChangeset for help on using the changeset viewer.