Changeset 112839 in webkit


Ignore:
Timestamp:
Apr 2, 2012 2:05:32 AM (12 years ago)
Author:
tkent@chromium.org
Message:

Add a calendar picker indicator to date-type input fields
https://bugs.webkit.org/show_bug.cgi?id=80478

Reviewed by Hajime Morita.

Source/WebCore:

Add an indicator to date-type controls. The bahevior change is enclosed
with ENABLE_CALENDAR_PICKER.

  • Remove spin buttons from date-type controls.

It's not so helpful if we have a calendar picker. We introduce
TextFieldInputType::shouldHaveSpinButton().

  • Add CalendarPickerElement.

This is added into a shadow tree of a date-type control. It uses
RenderDetailsMarker.

We're going to add click handler and so on to CalendarPickerElement.

Test: fast/forms/date/date-appearance.html

  • WebCore.gypi: Add CalendarPickerElement.{cpp,h}
  • css/html.css:

(input::-webkit-calendar-picker-indicator):

  • html/DateInputType.cpp:

(WebCore::DateInputType::createShadowSubtree): Insert CalendarPickerElement.
(WebCore::DateInputType::needsContainer):
Alwyas return true because we have an extra decoration element.
(WebCore::DateInputType::shouldHaveSpinButton):
Always return false to disable spin button.

  • html/DateInputType.h:

(DateInputType): Add declarations.

  • html/TextFieldInputType.cpp:

(WebCore::TextFieldInputType::shouldHaveSpinButton):
(WebCore::TextFieldInputType::createShadowSubtree): Move some code to shouldHaveSpinButton().

  • html/TextFieldInputType.h:

(TextFieldInputType): Add a declartion.

  • html/shadow/CalendarPickerElement.cpp:

(WebCore::CalendarPickerElement::CalendarPickerElement):
(WebCore::CalendarPickerElement::create):
(WebCore::CalendarPickerElement::createRenderer): Creates RenderDetailsMarker.

  • html/shadow/CalendarPickerElement.h: Added.
  • rendering/RenderDetailsMarker.cpp:

(WebCore::RenderDetailsMarker::isOpen): Always show a down arrow if this is in <input>.

  • rendering/RenderDetailsMarker.h:

Source/WebKit/chromium:

  • features.gypi: Enable CALENDAR_PICKER for non-Android platforms. This

doesn't affect any bahevior because INPUT_TYPE_DATE is disabled.

LayoutTests:

  • fast/forms/date/date-appearance.html: Added.
  • platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.png: Added.
  • platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.txt: Added.
Location:
trunk
Files:
4 added
12 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r112835 r112839  
     12012-04-02  Kent Tamura  <tkent@chromium.org>
     2
     3        Add a calendar picker indicator to date-type input fields
     4        https://bugs.webkit.org/show_bug.cgi?id=80478
     5
     6        Reviewed by Hajime Morita.
     7
     8        * fast/forms/date/date-appearance.html: Added.
     9        * platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.png: Added.
     10        * platform/chromium-mac-snowleopard/fast/forms/date/date-appearance-expected.txt: Added.
     11
    1122012-04-02  Philippe Normand  <pnormand@igalia.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r112838 r112839  
     12012-04-02  Kent Tamura  <tkent@chromium.org>
     2
     3        Add a calendar picker indicator to date-type input fields
     4        https://bugs.webkit.org/show_bug.cgi?id=80478
     5
     6        Reviewed by Hajime Morita.
     7
     8        Add an indicator to date-type controls. The bahevior change is enclosed
     9        with ENABLE_CALENDAR_PICKER.
     10
     11        - Remove spin buttons from date-type controls.
     12        It's not so helpful if we have a calendar picker. We introduce
     13        TextFieldInputType::shouldHaveSpinButton().
     14
     15        - Add CalendarPickerElement.
     16        This is added into a shadow tree of a date-type control. It uses
     17        RenderDetailsMarker.
     18
     19        We're going to add click handler and so on to CalendarPickerElement.
     20
     21        Test: fast/forms/date/date-appearance.html
     22
     23        * WebCore.gypi: Add CalendarPickerElement.{cpp,h}
     24        * css/html.css:
     25        (input::-webkit-calendar-picker-indicator):
     26        * html/DateInputType.cpp:
     27        (WebCore::DateInputType::createShadowSubtree): Insert CalendarPickerElement.
     28        (WebCore::DateInputType::needsContainer):
     29        Alwyas return true because we have an extra decoration element.
     30        (WebCore::DateInputType::shouldHaveSpinButton):
     31        Always return false to disable spin button.
     32        * html/DateInputType.h:
     33        (DateInputType): Add declarations.
     34        * html/TextFieldInputType.cpp:
     35        (WebCore::TextFieldInputType::shouldHaveSpinButton):
     36        (WebCore::TextFieldInputType::createShadowSubtree): Move some code to shouldHaveSpinButton().
     37        * html/TextFieldInputType.h:
     38        (TextFieldInputType): Add a declartion.
     39        * html/shadow/CalendarPickerElement.cpp:
     40        (WebCore::CalendarPickerElement::CalendarPickerElement):
     41        (WebCore::CalendarPickerElement::create):
     42        (WebCore::CalendarPickerElement::createRenderer): Creates RenderDetailsMarker.
     43        * html/shadow/CalendarPickerElement.h: Added.
     44        * rendering/RenderDetailsMarker.cpp:
     45        (WebCore::RenderDetailsMarker::isOpen): Always show a down arrow if this is in <input>.
     46        * rendering/RenderDetailsMarker.h:
     47
    1482012-04-02  Andrey Kosyakov  <caseq@chromium.org>
    249
  • trunk/Source/WebCore/WebCore.gypi

    r112834 r112839  
    56985698            'html/parser/XSSAuditor.cpp',
    56995699            'html/parser/XSSAuditor.h',
     5700            'html/shadow/CalendarPickerElement.cpp',
     5701            'html/shadow/CalendarPickerElement.h',
    57005702            'html/shadow/ContentSelectorQuery.cpp',
    57015703            'html/shadow/ContentSelectorQuery.h',
  • trunk/Source/WebCore/css/html.css

    r112658 r112839  
    669669#endif // defined(ENABLE_INPUT_TYPE_COLOR) && ENABLE_INPUT_TYPE_COLOR
    670670
     671#if defined(ENABLE_CALENDAR_PICKER) && ENABLE_CALENDAR_PICKER
     672input::-webkit-calendar-picker-indicator {
     673    display: inline-block;
     674    width: 0.66em;
     675    height: 0.66em;
     676    -webkit-margin-end: 0.2em;
     677}
     678#endif // ENABLE_CALENDAR_PICKER
     679
    671680select {
    672681    -webkit-appearance: menulist;
  • trunk/Source/WebCore/html/DateInputType.cpp

    r96678 r112839  
    3232#include "DateInputType.h"
    3333
     34#include "CalendarPickerElement.h"
    3435#include "DateComponents.h"
    3536#include "HTMLInputElement.h"
     
    99100}
    100101
     102#if ENABLE(CALENDAR_PICKER)
     103void DateInputType::createShadowSubtree()
     104{
     105    BaseDateAndTimeInputType::createShadowSubtree();
     106    containerElement()->insertBefore(CalendarPickerElement::create(element()->document()), innerBlockElement()->nextSibling(), ASSERT_NO_EXCEPTION);
     107}
     108
     109bool DateInputType::needsContainer() const
     110{
     111    return true;
     112}
     113
     114bool DateInputType::shouldHaveSpinButton() const
     115{
     116    return false;
     117}
     118#endif // ENABLE(CALENDAR_PICKER)
     119
    101120} // namespace WebCore
    102121
  • trunk/Source/WebCore/html/DateInputType.h

    r103400 r112839  
    5353    virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const OVERRIDE;
    5454    virtual bool setMillisecondToDateComponents(double, DateComponents*) const OVERRIDE;
     55#if ENABLE(CALENDAR_PICKER)
     56    virtual void createShadowSubtree() OVERRIDE;
     57
     58    // TextFieldInputType functions
     59    virtual bool needsContainer() const OVERRIDE;
     60    virtual bool shouldHaveSpinButton() const OVERRIDE;
     61#endif
    5562};
    5663
  • trunk/Source/WebCore/html/TextFieldInputType.cpp

    r111930 r112839  
    213213}
    214214
     215bool TextFieldInputType::shouldHaveSpinButton() const
     216{
     217    Document* document = element()->document();
     218    RefPtr<RenderTheme> theme = document->page() ? document->page()->theme() : RenderTheme::defaultTheme();
     219    return theme->shouldHaveSpinButton(element());
     220}
     221
    215222void TextFieldInputType::createShadowSubtree()
    216223{
     
    222229
    223230    Document* document = element()->document();
    224     RefPtr<RenderTheme> theme = document->page() ? document->page()->theme() : RenderTheme::defaultTheme();
    225231    ChromeClient* chromeClient = document->page() ? document->page()->chrome()->client() : 0;
    226     bool shouldHaveSpinButton = theme->shouldHaveSpinButton(element());
    227232    bool shouldAddDecorations = chromeClient && chromeClient->willAddTextFieldDecorationsTo(element());
     233    bool shouldHaveSpinButton = this->shouldHaveSpinButton();
    228234    bool createsContainer = shouldHaveSpinButton || needsContainer() || shouldAddDecorations;
    229235
  • trunk/Source/WebCore/html/TextFieldInputType.h

    r108051 r112839  
    6060protected:
    6161    virtual bool needsContainer() const;
     62    virtual bool shouldHaveSpinButton() const;
    6263    virtual void createShadowSubtree() OVERRIDE;
    6364    virtual void destroyShadowSubtree() OVERRIDE;
  • trunk/Source/WebCore/html/shadow/CalendarPickerElement.cpp

    r112838 r112839  
    11/*
    2  * Copyright (C) 2010 Google Inc. All rights reserved.
     2 * Copyright (C) 2012 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929 */
    3030
    31 #ifndef DateInputType_h
    32 #define DateInputType_h
     31#include "config.h"
     32#include "CalendarPickerElement.h"
    3333
    34 #include "BaseDateAndTimeInputType.h"
     34#if ENABLE(CALENDAR_PICKER)
    3535
    36 #if ENABLE(INPUT_TYPE_DATE)
     36#include "HTMLNames.h"
     37#include "RenderDetailsMarker.h"
    3738
    3839namespace WebCore {
    3940
    40 class DateInputType : public BaseDateAndTimeInputType {
    41 public:
    42     static PassOwnPtr<InputType> create(HTMLInputElement*);
     41using namespace HTMLNames;
    4342
    44 private:
    45     DateInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
    46     virtual const AtomicString& formControlType() const OVERRIDE;
    47     virtual DateComponents::Type dateType() const OVERRIDE;
    48     virtual double minimum() const OVERRIDE;
    49     virtual double maximum() const OVERRIDE;
    50     virtual double defaultStep() const OVERRIDE;
    51     virtual double stepScaleFactor() const OVERRIDE;
    52     virtual bool parsedStepValueShouldBeInteger() const OVERRIDE;
    53     virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const OVERRIDE;
    54     virtual bool setMillisecondToDateComponents(double, DateComponents*) const OVERRIDE;
    55 };
     43inline CalendarPickerElement::CalendarPickerElement(Document* document)
     44    : HTMLDivElement(divTag, document)
     45{
     46    setShadowPseudoId("-webkit-calendar-picker-indicator");
     47}
    5648
    57 } // namespace WebCore
     49PassRefPtr<CalendarPickerElement> CalendarPickerElement::create(Document* document)
     50{
     51    return adoptRef(new CalendarPickerElement(document));
     52}
     53
     54RenderObject* CalendarPickerElement::createRenderer(RenderArena* arena, RenderStyle*)
     55{
     56    return new (arena) RenderDetailsMarker(this);
     57}
     58
     59}
    5860
    5961#endif
    60 #endif // DateInputType_h
  • trunk/Source/WebCore/html/shadow/CalendarPickerElement.h

    r112838 r112839  
    11/*
    2  * Copyright (C) 2010 Google Inc. All rights reserved.
     2 * Copyright (C) 2012 Google Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929 */
    3030
    31 #ifndef DateInputType_h
    32 #define DateInputType_h
     31#ifndef CalendarPickerElement_h
     32#define CalendarPickerElement_h
    3333
    34 #include "BaseDateAndTimeInputType.h"
    35 
    36 #if ENABLE(INPUT_TYPE_DATE)
     34#include "HTMLDivElement.h"
    3735
    3836namespace WebCore {
    3937
    40 class DateInputType : public BaseDateAndTimeInputType {
     38class CalendarPickerElement : public HTMLDivElement {
    4139public:
    42     static PassOwnPtr<InputType> create(HTMLInputElement*);
     40    static PassRefPtr<CalendarPickerElement> create(Document*);
    4341
    4442private:
    45     DateInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { }
    46     virtual const AtomicString& formControlType() const OVERRIDE;
    47     virtual DateComponents::Type dateType() const OVERRIDE;
    48     virtual double minimum() const OVERRIDE;
    49     virtual double maximum() const OVERRIDE;
    50     virtual double defaultStep() const OVERRIDE;
    51     virtual double stepScaleFactor() const OVERRIDE;
    52     virtual bool parsedStepValueShouldBeInteger() const OVERRIDE;
    53     virtual bool parseToDateComponentsInternal(const UChar*, unsigned length, DateComponents*) const OVERRIDE;
    54     virtual bool setMillisecondToDateComponents(double, DateComponents*) const OVERRIDE;
     43    CalendarPickerElement(Document*);
     44    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) OVERRIDE;
     45    // FIXME: add click handling.
    5546};
    5647
    57 } // namespace WebCore
    58 
     48}
    5949#endif
    60 #endif // DateInputType_h
  • trunk/Source/WebCore/rendering/RenderDetailsMarker.cpp

    r109192 r112839  
    2222#include "RenderDetailsMarker.h"
    2323
    24 #if ENABLE(DETAILS)
     24#if ENABLE(DETAILS) || ENABLE(CALENDAR_PICKER)
    2525
    2626#include "Element.h"
     
    141141{
    142142    for (RenderObject* renderer = parent(); renderer; renderer = renderer->parent()) {
    143         if (renderer->node() && renderer->node()->hasTagName(detailsTag))
     143        if (!renderer->node())
     144            continue;
     145        if (renderer->node()->hasTagName(detailsTag))
    144146            return !toElement(renderer->node())->getAttribute(openAttr).isNull();
     147        if (renderer->node()->hasTagName(inputTag))
     148            return true;
    145149    }
    146150
  • trunk/Source/WebCore/rendering/RenderDetailsMarker.h

    r109192 r112839  
    2222#define RenderDetailsMarker_h
    2323
    24 #if ENABLE(DETAILS)
     24#if ENABLE(DETAILS) || ENABLE(CALENDAR_PICKER)
    2525
    2626#include "RenderBlock.h"
  • trunk/Source/WebKit/chromium/ChangeLog

    r112834 r112839  
     12012-04-02  Kent Tamura  <tkent@chromium.org>
     2
     3        Add a calendar picker indicator to date-type input fields
     4        https://bugs.webkit.org/show_bug.cgi?id=80478
     5
     6        Reviewed by Hajime Morita.
     7
     8        * features.gypi: Enable CALENDAR_PICKER for non-Android platforms. This
     9        doesn't affect any bahevior because INPUT_TYPE_DATE is disabled.
     10
    1112012-04-02  Adam Barth  <abarth@webkit.org>
    212
  • trunk/Source/WebKit/chromium/features.gypi

    r112658 r112839  
    131131      ['OS=="android"', {
    132132        'feature_defines': [
     133          'ENABLE_CALENDAR_PICKER=0',
    133134          'ENABLE_WEB_AUDIO=0',
    134135        ],
    135136      }, {
    136137        'feature_defines': [
     138          'ENABLE_CALENDAR_PICKER=1',
    137139          'ENABLE_WEB_AUDIO=1',
    138140        ],
Note: See TracChangeset for help on using the changeset viewer.