Changeset 134036 in webkit


Ignore:
Timestamp:
Nov 9, 2012 2:03:11 AM (11 years ago)
Author:
tkent@chromium.org
Message:

Don't use RenderTextControlSingleLine for date/time input types without the multiple-fields UI
https://bugs.webkit.org/show_bug.cgi?id=101722

Reviewed by Hajime Morita.

Because the date/time input types are not textfields, we should not use
RenderTextControlSingleLine, and don't need to create shadow trees for
RenderTextControlSingleLine.

No new tests. Covered by fast/forms/*/*-appearance-*.html.

  • css/html.css:

(input[type="date"]):
It has menulist appeanrace by default, and should be a flexible box to
center the inner text. 10em width is almost same as the default width of
text fields.
(input[type="datetime"]): Ditto.
(input[type="datetime-local"]): Ditto.
(input[type="month"]): Ditto.
(input[type="time"]): Ditto.
(input[type="week"]): Ditto.
(input::-webkit-date-and-time-value):
Added. A style for the inner text block.

  • html/BaseChooserOnlyDateAndTimeInputType.cpp:

(WebCore::BaseChooserOnlyDateAndTimeInputType::createRenderer):
Don't create RenderTextControlSingleLine.
(WebCore::BaseChooserOnlyDateAndTimeInputType::updateInnerTextValue):
Skip TextFieldInputType::updateInnerTextValue.
(WebCore::BaseChooserOnlyDateAndTimeInputType::forwardEvent):
Skip TextFieldInputType::forwardEvent.
(WebCore::BaseChooserOnlyDateAndTimeInputType::createShadowSubtree):
Just add one element to the shadow root.
(WebCore::BaseChooserOnlyDateAndTimeInputType::updateAppearance):
Sets a localized value to the inner text block.
(WebCore::BaseChooserOnlyDateAndTimeInputType::setValue):
Calls updateAppearance if the value is updated.

  • html/BaseChooserOnlyDateAndTimeInputType.h:

(BaseChooserOnlyDateAndTimeInputType): Declare updateAppearance,
createRenderer, updateInnerTextValue, forwardEvent, createShadowSubtree,
and setValue.

  • html/BaseDateAndTimeInputType.h:

(WebCore): Add a FIXME comment.
(BaseDateAndTimeInputType):
Make visibleValue protected. It is used by BaseChooserOnlyDateAndTimeInputType.

  • html/TextFieldInputType.h:

(TextFieldInputType):
Make setValue protected. It is used by BaseChooserOnlyDateAndTimeInputType.

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r134035 r134036  
     12012-11-09  Kent Tamura  <tkent@chromium.org>
     2
     3        Don't use RenderTextControlSingleLine for date/time input types without the multiple-fields UI
     4        https://bugs.webkit.org/show_bug.cgi?id=101722
     5
     6        Reviewed by Hajime Morita.
     7
     8        Because the date/time input types are not textfields, we should not use
     9        RenderTextControlSingleLine, and don't need to create shadow trees for
     10        RenderTextControlSingleLine.
     11
     12        No new tests. Covered by fast/forms/*/*-appearance-*.html.
     13
     14        * css/html.css:
     15        (input[type="date"]):
     16        It has menulist appeanrace by default, and should be a flexible box to
     17        center the inner text. 10em width is almost same as the default width of
     18        text fields.
     19        (input[type="datetime"]): Ditto.
     20        (input[type="datetime-local"]): Ditto.
     21        (input[type="month"]): Ditto.
     22        (input[type="time"]): Ditto.
     23        (input[type="week"]): Ditto.
     24        (input::-webkit-date-and-time-value):
     25        Added. A style for the inner text block.
     26        * html/BaseChooserOnlyDateAndTimeInputType.cpp:
     27        (WebCore::BaseChooserOnlyDateAndTimeInputType::createRenderer):
     28        Don't create RenderTextControlSingleLine.
     29        (WebCore::BaseChooserOnlyDateAndTimeInputType::updateInnerTextValue):
     30        Skip TextFieldInputType::updateInnerTextValue.
     31        (WebCore::BaseChooserOnlyDateAndTimeInputType::forwardEvent):
     32        Skip TextFieldInputType::forwardEvent.
     33        (WebCore::BaseChooserOnlyDateAndTimeInputType::createShadowSubtree):
     34        Just add one element to the shadow root.
     35        (WebCore::BaseChooserOnlyDateAndTimeInputType::updateAppearance):
     36        Sets a localized value to the inner text block.
     37        (WebCore::BaseChooserOnlyDateAndTimeInputType::setValue):
     38        Calls updateAppearance if the value is updated.
     39        * html/BaseChooserOnlyDateAndTimeInputType.h:
     40        (BaseChooserOnlyDateAndTimeInputType): Declare updateAppearance,
     41        createRenderer, updateInnerTextValue, forwardEvent, createShadowSubtree,
     42        and setValue.
     43        * html/BaseDateAndTimeInputType.h:
     44        (WebCore): Add a FIXME comment.
     45        (BaseDateAndTimeInputType):
     46        Make visibleValue protected. It is used by BaseChooserOnlyDateAndTimeInputType.
     47        * html/TextFieldInputType.h:
     48        (TextFieldInputType):
     49        Make setValue protected. It is used by BaseChooserOnlyDateAndTimeInputType.
     50
    1512012-11-09  Vsevolod Vlasov  <vsevik@chromium.org>
    252
  • trunk/Source/WebCore/css/html.css

    r132452 r134036  
    602602    -webkit-margin-start: 2px;
    603603}
     604
     605#else
     606
     607#if defined(ENABLE_INPUT_TYPE_DATE) && ENABLE_INPUT_TYPE_DATE
     608input[type="date"] {
     609    -webkit-align-items: center;
     610    -webkit-appearance: menulist;
     611    display: -webkit-inline-flex;
     612    overflow: hidden;
     613    width: 10em;
     614}
     615#endif
     616#if defined(ENABLE_INPUT_TYPE_DATETIME) && ENABLE_INPUT_TYPE_DATETIME
     617input[type="datetime"] {
     618    -webkit-align-items: center;
     619    -webkit-appearance: menulist;
     620    display: -webkit-inline-flex;
     621    overflow: hidden;
     622    width: 10em;
     623}
     624#endif
     625#if defined(ENABLE_INPUT_TYPE_DATETIMELOCAL) && ENABLE_INPUT_TYPE_DATETIMELOCAL
     626input[type="datetime-local"] {
     627    -webkit-align-items: center;
     628    -webkit-appearance: menulist;
     629    display: -webkit-inline-flex;
     630    overflow: hidden;
     631    width: 10em;
     632}
     633#endif
     634#if defined(ENABLE_INPUT_TYPE_MONTH) && ENABLE_INPUT_TYPE_MONTH
     635input[type="month"] {
     636    -webkit-align-items: center;
     637    -webkit-appearance: menulist;
     638    display: -webkit-inline-flex;
     639    overflow: hidden;
     640    width: 10em;
     641}
     642#endif
     643#if defined(ENABLE_INPUT_TYPE_TIME) && ENABLE_INPUT_TYPE_TIME
     644input[type="time"] {
     645    -webkit-align-items: center;
     646    -webkit-appearance: menulist;
     647    display: -webkit-inline-flex;
     648    overflow: hidden;
     649    width: 10em;
     650}
     651#endif
     652#if defined(ENABLE_INPUT_TYPE_WEEK) && ENABLE_INPUT_TYPE_WEEK
     653input[type="week"] {
     654    -webkit-align-items: center;
     655    -webkit-appearance: menulist;
     656    display: -webkit-inline-flex;
     657    overflow: hidden;
     658    width: 10em;
     659}
     660#endif
     661
     662input::-webkit-date-and-time-value {
     663    margin-left: 4px;
     664}
    604665#endif
    605666
  • trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.cpp

    r133441 r134036  
    3030#include "Chrome.h"
    3131#include "ChromeClient.h"
     32#include "HTMLDivElement.h"
    3233#include "HTMLInputElement.h"
    3334#include "Page.h"
    3435#include "ScriptController.h"
     36#include "ShadowRoot.h"
    3537
    3638namespace WebCore {
     
    5759        return;
    5860    m_dateTimeChooser = chrome->client()->openDateTimeChooser(this, parameters);
     61}
     62
     63RenderObject* BaseChooserOnlyDateAndTimeInputType::createRenderer(RenderArena* arena, RenderStyle* style) const
     64{
     65    // Cancel the override by TextFieldInputType.
     66    // FIXME: Remove this function when we stop inheriting TextFieldInputType.
     67    return InputType::createRenderer(arena, style);
     68}
     69
     70void BaseChooserOnlyDateAndTimeInputType::updateInnerTextValue()
     71{
     72    // Cancel the override by TextFieldInputType.
     73    // FIXME: Remove this function when we stop inheriting TextFieldInputType.
     74}
     75
     76void BaseChooserOnlyDateAndTimeInputType::forwardEvent(Event*)
     77{
     78    // Cancel the override by TextFieldInputType.
     79    // FIXME: Remove this function when we stop inheriting TextFieldInputType.
     80}
     81
     82void BaseChooserOnlyDateAndTimeInputType::createShadowSubtree()
     83{
     84    DEFINE_STATIC_LOCAL(AtomicString, valueContainerPseudo, ("-webkit-date-and-time-value", AtomicString::ConstructFromLiteral));
     85
     86    RefPtr<HTMLDivElement> valueContainer = HTMLDivElement::create(element()->document());
     87    valueContainer->setPseudo(valueContainerPseudo);
     88    element()->userAgentShadowRoot()->appendChild(valueContainer.get());
     89    updateAppearance();
     90}
     91
     92void BaseChooserOnlyDateAndTimeInputType::updateAppearance()
     93{
     94    Node* node = element()->userAgentShadowRoot()->firstChild();
     95    if (!node || !node->isHTMLElement())
     96        return;
     97    String displayValue = visibleValue();
     98    if (displayValue.isEmpty()) {
     99        // Need to put something to keep text baseline.
     100        displayValue = ASCIILiteral(" ");
     101    }
     102    toHTMLElement(node)->setInnerText(displayValue, ASSERT_NO_EXCEPTION);
     103}
     104
     105void BaseChooserOnlyDateAndTimeInputType::setValue(const String& value, bool valueChanged, TextFieldEventBehavior eventBehavior)
     106{
     107    BaseDateAndTimeInputType::setValue(value, valueChanged, eventBehavior);
     108    if (valueChanged)
     109        updateAppearance();
    59110}
    60111
  • trunk/Source/WebCore/html/BaseChooserOnlyDateAndTimeInputType.h

    r133441 r134036  
    4141
    4242private:
     43    void updateAppearance();
    4344    void closeDateTimeChooser();
    4445
    4546    // InputType functions:
     47    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const OVERRIDE;
     48    virtual void updateInnerTextValue() OVERRIDE;
     49    void forwardEvent(Event*) OVERRIDE;
     50    virtual void createShadowSubtree() OVERRIDE;
    4651    virtual void detach() OVERRIDE;
     52    virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) OVERRIDE;
    4753    virtual void handleDOMActivateEvent(Event*) OVERRIDE;
    4854    virtual void handleKeydownEvent(KeyboardEvent*) OVERRIDE;
  • trunk/Source/WebCore/html/BaseDateAndTimeInputType.h

    r133284 r134036  
    4040
    4141// A super class of date, datetime, datetime-local, month, time, and week types.
     42// FIXME: Don't inherit TextFieldInputType. webkit.org/b/100935
    4243class BaseDateAndTimeInputType : public TextFieldInputType {
    4344protected:
     
    5051    String serializeWithComponents(const DateComponents&) const;
    5152    virtual bool setMillisecondToDateComponents(double, DateComponents*) const = 0;
     53    virtual String visibleValue() const OVERRIDE;
    5254
    5355private:
     
    6466    virtual String serializeWithMilliseconds(double) const;
    6567    virtual String localizeValue(const String&) const OVERRIDE;
    66     virtual String visibleValue() const OVERRIDE;
    6768    virtual String convertFromVisibleValue(const String&) const OVERRIDE;
    6869};
  • trunk/Source/WebCore/html/TextFieldInputType.h

    r132291 r134036  
    6666    virtual void readonlyAttributeChanged() OVERRIDE;
    6767    virtual void handleBlurEvent() OVERRIDE;
     68    virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) OVERRIDE;
    6869    virtual void updateInnerTextValue() OVERRIDE;
    6970
     
    7879    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const OVERRIDE;
    7980    virtual bool shouldUseInputMethod() const OVERRIDE;
    80     virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) OVERRIDE;
    8181    virtual String sanitizeValue(const String&) const OVERRIDE;
    8282    virtual bool shouldRespectListAttribute() OVERRIDE;
Note: See TracChangeset for help on using the changeset viewer.