Changeset 267003 in webkit


Ignore:
Timestamp:
Sep 13, 2020 1:32:24 PM (4 years ago)
Author:
Aditya Keerthi
Message:

Consolidate BaseDateAndTimeInputType and BaseChooserOnlyDateAndTimeInputType
https://bugs.webkit.org/show_bug.cgi?id=216414

Reviewed by Devin Rousso.

BaseChooserOnlyDateAndTimeInputType is the only derived class of
BaseDateAndTimeInputType. Furthermore, with the introduction of editable
components, "ChooserOnly" no longer makes sense as a name for the
derived class. Consequently, all logic in BaseChooserOnlyDateAndTimeInputType
was moved into BaseDateAndTimeInputType, and the derived classes of the
"ChooserOnly" type now inherit BaseDateAndTimeInputType.

Also changed some methods from override to final, and made some protected
methods private, where possible.

No new tests, as there is no change in behavior.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • html/BaseChooserOnlyDateAndTimeInputType.cpp: Removed.
  • html/BaseChooserOnlyDateAndTimeInputType.h: Removed.
  • html/BaseDateAndTimeInputType.cpp:

(WebCore::BaseDateAndTimeInputType::DateTimeFormatValidator::visitField):
(WebCore::BaseDateAndTimeInputType::DateTimeFormatValidator::validateFormat):
(WebCore::BaseDateAndTimeInputType::~BaseDateAndTimeInputType):
(WebCore::BaseDateAndTimeInputType::isMouseFocusable const):
(WebCore::BaseDateAndTimeInputType::shouldHaveSecondField const):
(WebCore::BaseDateAndTimeInputType::shouldHaveMillisecondField const):
(WebCore::BaseDateAndTimeInputType::setValue):
(WebCore::BaseDateAndTimeInputType::handleDOMActivateEvent):
(WebCore::BaseDateAndTimeInputType::createShadowSubtree):
(WebCore::BaseDateAndTimeInputType::destroyShadowSubtree):
(WebCore::BaseDateAndTimeInputType::updateInnerTextValue):
(WebCore::BaseDateAndTimeInputType::hasCustomFocusLogic const):
(WebCore::BaseDateAndTimeInputType::attributeChanged):
(WebCore::BaseDateAndTimeInputType::elementDidBlur):
(WebCore::BaseDateAndTimeInputType::detach):
(WebCore::BaseDateAndTimeInputType::isPresentingAttachedView const):
(WebCore::BaseDateAndTimeInputType::handleKeydownEvent):
(WebCore::BaseDateAndTimeInputType::handleKeypressEvent):
(WebCore::BaseDateAndTimeInputType::handleKeyupEvent):
(WebCore::BaseDateAndTimeInputType::handleFocusEvent):
(WebCore::BaseDateAndTimeInputType::accessKeyAction):
(WebCore::BaseDateAndTimeInputType::didBlurFromControl):
(WebCore::BaseDateAndTimeInputType::didChangeValueFromControl):
(WebCore::BaseDateAndTimeInputType::isEditControlOwnerDisabled const):
(WebCore::BaseDateAndTimeInputType::isEditControlOwnerReadOnly const):
(WebCore::BaseDateAndTimeInputType::localeIdentifier const):
(WebCore::BaseDateAndTimeInputType::didChooseValue):
(WebCore::BaseDateAndTimeInputType::didEndChooser):
(WebCore::BaseDateAndTimeInputType::closeDateTimeChooser):

  • html/BaseDateAndTimeInputType.h:
  • html/DateInputType.cpp:

(WebCore::DateInputType::DateInputType):

  • html/DateInputType.h:
  • html/DateTimeLocalInputType.cpp:
  • html/DateTimeLocalInputType.h:
  • html/MonthInputType.h:
  • html/TimeInputType.cpp:

(WebCore::TimeInputType::TimeInputType):

  • html/TimeInputType.h:
  • html/WeekInputType.h:
Location:
trunk/Source/WebCore
Files:
2 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r267002 r267003  
     12020-09-13  Aditya Keerthi  <akeerthi@apple.com>
     2
     3        Consolidate BaseDateAndTimeInputType and BaseChooserOnlyDateAndTimeInputType
     4        https://bugs.webkit.org/show_bug.cgi?id=216414
     5
     6        Reviewed by Devin Rousso.
     7
     8        BaseChooserOnlyDateAndTimeInputType is the only derived class of
     9        BaseDateAndTimeInputType. Furthermore, with the introduction of editable
     10        components, "ChooserOnly" no longer makes sense as a name for the
     11        derived class. Consequently, all logic in BaseChooserOnlyDateAndTimeInputType
     12        was moved into BaseDateAndTimeInputType, and the derived classes of the
     13        "ChooserOnly" type now inherit BaseDateAndTimeInputType.
     14
     15        Also changed some methods from override to final, and made some protected
     16        methods private, where possible.
     17
     18        No new tests, as there is no change in behavior.
     19
     20        * Sources.txt:
     21        * WebCore.xcodeproj/project.pbxproj:
     22        * html/BaseChooserOnlyDateAndTimeInputType.cpp: Removed.
     23        * html/BaseChooserOnlyDateAndTimeInputType.h: Removed.
     24        * html/BaseDateAndTimeInputType.cpp:
     25        (WebCore::BaseDateAndTimeInputType::DateTimeFormatValidator::visitField):
     26        (WebCore::BaseDateAndTimeInputType::DateTimeFormatValidator::validateFormat):
     27        (WebCore::BaseDateAndTimeInputType::~BaseDateAndTimeInputType):
     28        (WebCore::BaseDateAndTimeInputType::isMouseFocusable const):
     29        (WebCore::BaseDateAndTimeInputType::shouldHaveSecondField const):
     30        (WebCore::BaseDateAndTimeInputType::shouldHaveMillisecondField const):
     31        (WebCore::BaseDateAndTimeInputType::setValue):
     32        (WebCore::BaseDateAndTimeInputType::handleDOMActivateEvent):
     33        (WebCore::BaseDateAndTimeInputType::createShadowSubtree):
     34        (WebCore::BaseDateAndTimeInputType::destroyShadowSubtree):
     35        (WebCore::BaseDateAndTimeInputType::updateInnerTextValue):
     36        (WebCore::BaseDateAndTimeInputType::hasCustomFocusLogic const):
     37        (WebCore::BaseDateAndTimeInputType::attributeChanged):
     38        (WebCore::BaseDateAndTimeInputType::elementDidBlur):
     39        (WebCore::BaseDateAndTimeInputType::detach):
     40        (WebCore::BaseDateAndTimeInputType::isPresentingAttachedView const):
     41        (WebCore::BaseDateAndTimeInputType::handleKeydownEvent):
     42        (WebCore::BaseDateAndTimeInputType::handleKeypressEvent):
     43        (WebCore::BaseDateAndTimeInputType::handleKeyupEvent):
     44        (WebCore::BaseDateAndTimeInputType::handleFocusEvent):
     45        (WebCore::BaseDateAndTimeInputType::accessKeyAction):
     46        (WebCore::BaseDateAndTimeInputType::didBlurFromControl):
     47        (WebCore::BaseDateAndTimeInputType::didChangeValueFromControl):
     48        (WebCore::BaseDateAndTimeInputType::isEditControlOwnerDisabled const):
     49        (WebCore::BaseDateAndTimeInputType::isEditControlOwnerReadOnly const):
     50        (WebCore::BaseDateAndTimeInputType::localeIdentifier const):
     51        (WebCore::BaseDateAndTimeInputType::didChooseValue):
     52        (WebCore::BaseDateAndTimeInputType::didEndChooser):
     53        (WebCore::BaseDateAndTimeInputType::closeDateTimeChooser):
     54        * html/BaseDateAndTimeInputType.h:
     55        * html/DateInputType.cpp:
     56        (WebCore::DateInputType::DateInputType):
     57        * html/DateInputType.h:
     58        * html/DateTimeLocalInputType.cpp:
     59        * html/DateTimeLocalInputType.h:
     60        * html/MonthInputType.h:
     61        * html/TimeInputType.cpp:
     62        (WebCore::TimeInputType::TimeInputType):
     63        * html/TimeInputType.h:
     64        * html/WeekInputType.h:
     65
    1662020-09-13  Simon Fraser  <simon.fraser@apple.com>
    267
  • trunk/Source/WebCore/Sources.txt

    r266976 r267003  
    10661066html/BaseButtonInputType.cpp
    10671067html/BaseCheckableInputType.cpp
    1068 html/BaseChooserOnlyDateAndTimeInputType.cpp
    10691068html/BaseClickableWithKeyInputType.cpp
    10701069html/BaseDateAndTimeInputType.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r266977 r267003  
    51905190                F5C041DB0FFCA7CE00839D4A /* HTMLDataListElement.h in Headers */ = {isa = PBXBuildFile; fileRef = F5C041D80FFCA7CE00839D4A /* HTMLDataListElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
    51915191                F5C041E70FFCA96D00839D4A /* JSHTMLDataListElement.h in Headers */ = {isa = PBXBuildFile; fileRef = F5C041E20FFCA96D00839D4A /* JSHTMLDataListElement.h */; };
    5192                 F5E0C65C1643C42C00D6CB69 /* BaseChooserOnlyDateAndTimeInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = F5E0C65A1643C42C00D6CB69 /* BaseChooserOnlyDateAndTimeInputType.h */; };
    51935192                F916C48E0DB510F80076CD83 /* JSXMLHttpRequestProgressEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = F916C48C0DB510F80076CD83 /* JSXMLHttpRequestProgressEvent.h */; };
    51945193                F9F0ED7A0DB50CA200D16DB9 /* XMLHttpRequestProgressEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = F9F0ED770DB50CA200D16DB9 /* XMLHttpRequestProgressEvent.h */; };
     
    1624316242                F5C041E10FFCA96D00839D4A /* JSHTMLDataListElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLDataListElement.cpp; sourceTree = "<group>"; };
    1624416243                F5C041E20FFCA96D00839D4A /* JSHTMLDataListElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLDataListElement.h; sourceTree = "<group>"; };
    16245                 F5E0C6591643C42C00D6CB69 /* BaseChooserOnlyDateAndTimeInputType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BaseChooserOnlyDateAndTimeInputType.cpp; sourceTree = "<group>"; };
    16246                 F5E0C65A1643C42C00D6CB69 /* BaseChooserOnlyDateAndTimeInputType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseChooserOnlyDateAndTimeInputType.h; sourceTree = "<group>"; };
    1624716244                F75A059AF170D8FAA5B8CABE /* MathMLSelectElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLSelectElement.cpp; sourceTree = "<group>"; };
    1624816245                F8216299029F4FB501000131 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = JavaScriptCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
     
    2267222669                                379E61C7126CA5C300B63E8D /* BaseCheckableInputType.cpp */,
    2267322670                                379E61C8126CA5C300B63E8D /* BaseCheckableInputType.h */,
    22674                                 F5E0C6591643C42C00D6CB69 /* BaseChooserOnlyDateAndTimeInputType.cpp */,
    22675                                 F5E0C65A1643C42C00D6CB69 /* BaseChooserOnlyDateAndTimeInputType.h */,
    2267622671                                C33EE5C214FB49610002095A /* BaseClickableWithKeyInputType.cpp */,
    2267722672                                C33EE5C314FB49610002095A /* BaseClickableWithKeyInputType.h */,
     
    3045430449                                379E61CA126CA5C400B63E8D /* BaseButtonInputType.h in Headers */,
    3045530450                                379E61CC126CA5C400B63E8D /* BaseCheckableInputType.h in Headers */,
    30456                                 F5E0C65C1643C42C00D6CB69 /* BaseChooserOnlyDateAndTimeInputType.h in Headers */,
    3045730451                                C33EE5C514FB49610002095A /* BaseClickableWithKeyInputType.h in Headers */,
    3045830452                                F59C96001255B23F000623C0 /* BaseDateAndTimeInputType.h in Headers */,
  • trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp

    r266396 r267003  
    3535#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
    3636
     37#include "BaseClickableWithKeyInputType.h"
     38#include "Chrome.h"
    3739#include "DateComponents.h"
     40#include "DateTimeChooserParameters.h"
    3841#include "Decimal.h"
     42#include "FocusController.h"
     43#include "HTMLDivElement.h"
    3944#include "HTMLInputElement.h"
    4045#include "HTMLNames.h"
    4146#include "KeyboardEvent.h"
     47#include "Page.h"
    4248#include "PlatformLocale.h"
     49#include "Settings.h"
     50#include "ShadowRoot.h"
     51#include "StepRange.h"
     52#include "Text.h"
     53#include "UserGestureIndicator.h"
    4354#include <limits>
    4455#include <wtf/DateMath.h>
     
    5364static const int msecPerSecond = 1000;
    5465
     66void BaseDateAndTimeInputType::DateTimeFormatValidator::visitField(DateTimeFormat::FieldType fieldType, int)
     67{
     68    switch (fieldType) {
     69    case DateTimeFormat::FieldTypeYear:
     70        m_results.add(DateTimeFormatValidationResults::HasYear);
     71        break;
     72
     73    case DateTimeFormat::FieldTypeMonth:
     74    case DateTimeFormat::FieldTypeMonthStandAlone:
     75        m_results.add(DateTimeFormatValidationResults::HasMonth);
     76        break;
     77
     78    case DateTimeFormat::FieldTypeWeekOfYear:
     79        m_results.add(DateTimeFormatValidationResults::HasWeek);
     80        break;
     81
     82    case DateTimeFormat::FieldTypeDayOfMonth:
     83        m_results.add(DateTimeFormatValidationResults::HasDay);
     84        break;
     85
     86    case DateTimeFormat::FieldTypePeriod:
     87        m_results.add(DateTimeFormatValidationResults::HasMeridiem);
     88        break;
     89
     90    case DateTimeFormat::FieldTypeHour11:
     91    case DateTimeFormat::FieldTypeHour12:
     92        m_results.add(DateTimeFormatValidationResults::HasHour);
     93        break;
     94
     95    case DateTimeFormat::FieldTypeHour23:
     96    case DateTimeFormat::FieldTypeHour24:
     97        m_results.add(DateTimeFormatValidationResults::HasHour);
     98        m_results.add(DateTimeFormatValidationResults::HasMeridiem);
     99        break;
     100
     101    case DateTimeFormat::FieldTypeMinute:
     102        m_results.add(DateTimeFormatValidationResults::HasMinute);
     103        break;
     104
     105    case DateTimeFormat::FieldTypeSecond:
     106        m_results.add(DateTimeFormatValidationResults::HasSecond);
     107        break;
     108
     109    default:
     110        break;
     111    }
     112}
     113
     114bool BaseDateAndTimeInputType::DateTimeFormatValidator::validateFormat(const String& format, const BaseDateAndTimeInputType& inputType)
     115{
     116    if (!DateTimeFormat::parse(format, *this))
     117        return false;
     118    return inputType.isValidFormat(m_results);
     119}
     120
     121BaseDateAndTimeInputType::~BaseDateAndTimeInputType()
     122{
     123    closeDateTimeChooser();
     124}
     125
    55126double BaseDateAndTimeInputType::valueAsDate() const
    56127{
     
    100171{
    101172    return true;
    102 }
    103 
    104 void BaseDateAndTimeInputType::attributeChanged(const QualifiedName& name)
    105 {
    106     if (name == maxAttr || name == minAttr) {
    107         if (auto* element = this->element())
    108             element->invalidateStyleForSubtree();
    109     }
    110     InputType::attributeChanged(name);
    111173}
    112174
     
    191253}
    192254
     255bool BaseDateAndTimeInputType::isMouseFocusable() const
     256{
     257    ASSERT(element());
     258    return element()->isTextFormControlFocusable();
     259}
     260
     261bool BaseDateAndTimeInputType::shouldHaveSecondField(const DateComponents& date) const
     262{
     263    if (date.second())
     264        return true;
     265
     266    auto stepRange = createStepRange(AnyStepHandling::Default);
     267    return !stepRange.minimum().remainder(msecPerMinute).isZero()
     268        || !stepRange.step().remainder(msecPerMinute).isZero();
     269}
     270
     271bool BaseDateAndTimeInputType::shouldHaveMillisecondField(const DateComponents& date) const
     272{
     273    if (date.millisecond())
     274        return true;
     275
     276    auto stepRange = createStepRange(AnyStepHandling::Default);
     277    return !stepRange.minimum().remainder(msecPerSecond).isZero()
     278        || !stepRange.step().remainder(msecPerSecond).isZero();
     279}
     280
     281void BaseDateAndTimeInputType::setValue(const String& value, bool valueChanged, TextFieldEventBehavior eventBehavior)
     282{
     283    InputType::setValue(value, valueChanged, eventBehavior);
     284    if (valueChanged)
     285        updateInnerTextValue();
     286}
     287
     288void BaseDateAndTimeInputType::handleDOMActivateEvent(Event&)
     289{
     290    ASSERT(element());
     291    if (element()->isDisabledOrReadOnly() || !element()->renderer() || !UserGestureIndicator::processingUserGesture())
     292        return;
     293
     294    if (m_dateTimeChooser)
     295        return;
     296    if (!element()->document().page())
     297        return;
     298
     299    DateTimeChooserParameters parameters;
     300    if (!element()->setupDateTimeChooserParameters(parameters))
     301        return;
     302
     303    if (auto chrome = this->chrome()) {
     304        m_dateTimeChooser = chrome->createDateTimeChooser(*this);
     305        if (m_dateTimeChooser)
     306            m_dateTimeChooser->showChooser(parameters);
     307    }
     308}
     309
     310void BaseDateAndTimeInputType::createShadowSubtree()
     311{
     312    ASSERT(element());
     313
     314    auto& element = *this->element();
     315    auto& document = element.document();
     316
     317    if (document.settings().dateTimeInputsEditableComponentsEnabled()) {
     318        m_dateTimeEditElement = DateTimeEditElement::create(document, *this);
     319        element.userAgentShadowRoot()->appendChild(*m_dateTimeEditElement);
     320    } else {
     321        static MainThreadNeverDestroyed<const AtomString> valueContainerPseudo("-webkit-date-and-time-value", AtomString::ConstructFromLiteral);
     322        auto valueContainer = HTMLDivElement::create(document);
     323        valueContainer->setPseudo(valueContainerPseudo);
     324        element.userAgentShadowRoot()->appendChild(valueContainer);
     325    }
     326    updateInnerTextValue();
     327}
     328
     329void BaseDateAndTimeInputType::destroyShadowSubtree()
     330{
     331    InputType::destroyShadowSubtree();
     332    m_dateTimeEditElement = nullptr;
     333}
     334
     335void BaseDateAndTimeInputType::updateInnerTextValue()
     336{
     337    ASSERT(element());
     338    if (!m_dateTimeEditElement) {
     339        auto node = element()->userAgentShadowRoot()->firstChild();
     340        if (!is<HTMLElement>(node))
     341            return;
     342        auto displayValue = visibleValue();
     343        if (displayValue.isEmpty()) {
     344            // Need to put something to keep text baseline.
     345            displayValue = " "_s;
     346        }
     347        downcast<HTMLElement>(*node).setInnerText(displayValue);
     348        return;
     349    }
     350
     351    DateTimeEditElement::LayoutParameters layoutParameters(element()->locale());
     352
     353    auto date = parseToDateComponents(element()->value());
     354    if (date)
     355        setupLayoutParameters(layoutParameters, *date);
     356    else {
     357        if (auto dateForLayout = setMillisecondToDateComponents(createStepRange(AnyStepHandling::Default).minimum().toDouble()))
     358            setupLayoutParameters(layoutParameters, *dateForLayout);
     359        else
     360            setupLayoutParameters(layoutParameters, DateComponents());
     361    }
     362
     363    if (!DateTimeFormatValidator().validateFormat(layoutParameters.dateTimeFormat, *this))
     364        layoutParameters.dateTimeFormat = layoutParameters.fallbackDateTimeFormat;
     365
     366    if (date)
     367        m_dateTimeEditElement->setValueAsDate(layoutParameters, *date);
     368    else
     369        m_dateTimeEditElement->setEmptyValue(layoutParameters);
     370}
     371
     372bool BaseDateAndTimeInputType::hasCustomFocusLogic() const
     373{
     374    if (m_dateTimeEditElement)
     375        return false;
     376    return InputType::hasCustomFocusLogic();
     377}
     378
     379void BaseDateAndTimeInputType::attributeChanged(const QualifiedName& name)
     380{
     381    if (name == maxAttr || name == minAttr) {
     382        if (auto* element = this->element())
     383            element->invalidateStyleForSubtree();
     384    } else if (name == valueAttr) {
     385        if (auto* element = this->element()) {
     386            if (!element->hasDirtyValue())
     387                updateInnerTextValue();
     388        }
     389    } else if (name == stepAttr && m_dateTimeEditElement)
     390        updateInnerTextValue();
     391
     392    InputType::attributeChanged(name);
     393}
     394
     395void BaseDateAndTimeInputType::elementDidBlur()
     396{
     397    closeDateTimeChooser();
     398}
     399
     400void BaseDateAndTimeInputType::detach()
     401{
     402    closeDateTimeChooser();
     403}
     404
     405bool BaseDateAndTimeInputType::isPresentingAttachedView() const
     406{
     407    return !!m_dateTimeChooser;
     408}
     409
     410auto BaseDateAndTimeInputType::handleKeydownEvent(KeyboardEvent& event) -> ShouldCallBaseEventHandler
     411{
     412    ASSERT(element());
     413    return BaseClickableWithKeyInputType::handleKeydownEvent(*element(), event);
     414}
     415
     416void BaseDateAndTimeInputType::handleKeypressEvent(KeyboardEvent& event)
     417{
     418    ASSERT(element());
     419    BaseClickableWithKeyInputType::handleKeypressEvent(*element(), event);
     420}
     421
     422void BaseDateAndTimeInputType::handleKeyupEvent(KeyboardEvent& event)
     423{
     424    BaseClickableWithKeyInputType::handleKeyupEvent(*this, event);
     425}
     426
     427void BaseDateAndTimeInputType::handleFocusEvent(Node* oldFocusedNode, FocusDirection direction)
     428{
     429    if (!m_dateTimeEditElement) {
     430        InputType::handleFocusEvent(oldFocusedNode, direction);
     431        return;
     432    }
     433
     434    // If the element contains editable components, the element itself should not
     435    // be focused. Instead, one of it's children should receive focus.
     436
     437    if (direction == FocusDirectionBackward) {
     438        // If the element received focus when going backwards, advance the focus one more time
     439        // so that this element no longer has focus. In this case, one of the children should
     440        // not be focused as the element is losing focus entirely.
     441        if (auto* page = element()->document().page())
     442            page->focusController().advanceFocus(direction, 0);
     443    } else {
     444        // If the element received focus in any other direction, transfer focus to the first focusable child.
     445        m_dateTimeEditElement->focusByOwner();
     446    }
     447}
     448
     449bool BaseDateAndTimeInputType::accessKeyAction(bool sendMouseEvents)
     450{
     451    InputType::accessKeyAction(sendMouseEvents);
     452    ASSERT(element());
     453    return BaseClickableWithKeyInputType::accessKeyAction(*element(), sendMouseEvents);
     454}
     455
     456void BaseDateAndTimeInputType::didBlurFromControl()
     457{
     458    closeDateTimeChooser();
     459}
     460
     461void BaseDateAndTimeInputType::didChangeValueFromControl()
     462{
     463    String value = sanitizeValue(m_dateTimeEditElement->value());
     464    InputType::setValue(value, value != element()->value(), DispatchInputAndChangeEvent);
     465
     466    DateTimeChooserParameters parameters;
     467    if (!element()->setupDateTimeChooserParameters(parameters))
     468        return;
     469
     470    if (m_dateTimeChooser)
     471        m_dateTimeChooser->showChooser(parameters);
     472}
     473
     474bool BaseDateAndTimeInputType::isEditControlOwnerDisabled() const
     475{
     476    ASSERT(element());
     477    return element()->isDisabledFormControl();
     478}
     479
     480bool BaseDateAndTimeInputType::isEditControlOwnerReadOnly() const
     481{
     482    ASSERT(element());
     483    return element()->isReadOnly();
     484}
     485
     486AtomString BaseDateAndTimeInputType::localeIdentifier() const
     487{
     488    ASSERT(element());
     489    return element()->computeInheritedLanguage();
     490}
     491
     492void BaseDateAndTimeInputType::didChooseValue(StringView value)
     493{
     494    ASSERT(element());
     495    element()->setValue(value.toString(), DispatchInputAndChangeEvent);
     496}
     497
     498void BaseDateAndTimeInputType::didEndChooser()
     499{
     500    m_dateTimeChooser = nullptr;
     501}
     502
     503void BaseDateAndTimeInputType::closeDateTimeChooser()
     504{
     505    if (m_dateTimeChooser)
     506        m_dateTimeChooser->endChooser();
     507}
     508
    193509} // namespace WebCore
    194510#endif
  • trunk/Source/WebCore/html/BaseDateAndTimeInputType.h

    r266779 r267003  
    3434#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
    3535
     36#include "DateTimeChooser.h"
     37#include "DateTimeChooserClient.h"
     38#include "DateTimeEditElement.h"
     39#include "DateTimeFormat.h"
    3640#include "InputType.h"
     41#include <wtf/OptionSet.h>
    3742
    3843namespace WebCore {
     
    4146
    4247// A super class of date, datetime, datetime-local, month, time, and week types.
    43 class BaseDateAndTimeInputType : public InputType {
     48class BaseDateAndTimeInputType : public InputType, private DateTimeChooserClient, private DateTimeEditElement::EditControlOwner {
    4449protected:
     50    enum class DateTimeFormatValidationResults : uint8_t {
     51        HasYear = 1 << 0,
     52        HasMonth = 1 << 1,
     53        HasWeek = 1 << 2,
     54        HasDay = 1 << 3,
     55        HasHour = 1 << 4,
     56        HasMinute = 1 << 5,
     57        HasSecond = 1 << 6,
     58        HasMeridiem = 1 << 7,
     59    };
     60
    4561    BaseDateAndTimeInputType(HTMLInputElement& element) : InputType(element) { }
     62    ~BaseDateAndTimeInputType();
    4663
    4764    Decimal parseToNumber(const String&, const Decimal&) const override;
    48     String sanitizeValue(const String&) const override;
    4965    String serialize(const Decimal&) const override;
    5066    String serializeWithComponents(const DateComponents&) const;
    51     String visibleValue() const override;
    52     void attributeChanged(const QualifiedName&) override;
    53     bool isKeyboardFocusable(KeyboardEvent*) const override;
     67
     68    bool shouldHaveSecondField(const DateComponents&) const;
     69    bool shouldHaveMillisecondField(const DateComponents&) const;
     70
     71private:
     72    class DateTimeFormatValidator final : public DateTimeFormat::TokenHandler {
     73    public:
     74        DateTimeFormatValidator() { }
     75
     76        void visitField(DateTimeFormat::FieldType, int);
     77        void visitLiteral(const String&) { }
     78
     79        bool validateFormat(const String& format, const BaseDateAndTimeInputType&);
     80
     81    private:
     82        OptionSet<DateTimeFormatValidationResults> m_results;
     83    };
    5484
    5585    virtual Optional<DateComponents> parseToDateComponents(const StringView&) const = 0;
    5686    virtual Optional<DateComponents> setMillisecondToDateComponents(double) const = 0;
     87    virtual void setupLayoutParameters(DateTimeEditElement::LayoutParameters&, const DateComponents&) const = 0;
     88    virtual bool isValidFormat(OptionSet<DateTimeFormatValidationResults>) const = 0;
     89    virtual String serializeWithMilliseconds(double) const;
    5790
    58 private:
     91    // InputType functions:
     92    String visibleValue() const final;
     93    String sanitizeValue(const String&) const final;
     94    void setValue(const String&, bool valueChanged, TextFieldEventBehavior) final;
    5995    double valueAsDate() const override;
    6096    ExceptionOr<void> setValueAsDate(double) const override;
    61     double valueAsDouble() const override;
    62     ExceptionOr<void> setValueAsDecimal(const Decimal&, TextFieldEventBehavior) const override;
    63     bool typeMismatchFor(const String&) const override;
    64     bool typeMismatch() const override;
    65     bool valueMissing(const String&) const override;
     97    double valueAsDouble() const final;
     98    ExceptionOr<void> setValueAsDecimal(const Decimal&, TextFieldEventBehavior) const final;
     99    bool typeMismatchFor(const String&) const final;
     100    bool typeMismatch() const final;
     101    bool valueMissing(const String&) const final;
    66102    Decimal defaultValueForStepUp() const override;
    67     bool isSteppable() const override;
    68     virtual String serializeWithMilliseconds(double) const;
    69     String localizeValue(const String&) const override;
    70     bool supportsReadOnly() const override;
    71     bool shouldRespectListAttribute() override;
     103    bool isSteppable() const final;
     104    String localizeValue(const String&) const final;
     105    bool supportsReadOnly() const final;
     106    bool shouldRespectListAttribute() final;
     107    bool isKeyboardFocusable(KeyboardEvent*) const final;
     108    bool isMouseFocusable() const final;
     109
     110    void handleDOMActivateEvent(Event&) override;
     111    void createShadowSubtree() final;
     112    void destroyShadowSubtree() final;
     113    void updateInnerTextValue() final;
     114    bool hasCustomFocusLogic() const final;
     115    void attributeChanged(const QualifiedName&) final;
     116    bool isPresentingAttachedView() const final;
     117    void elementDidBlur() final;
     118    void detach() final;
     119
     120    ShouldCallBaseEventHandler handleKeydownEvent(KeyboardEvent&) override;
     121    void handleKeypressEvent(KeyboardEvent&) override;
     122    void handleKeyupEvent(KeyboardEvent&) override;
     123    void handleFocusEvent(Node* oldFocusedNode, FocusDirection) final;
     124    bool accessKeyAction(bool sendMouseEvents) override;
     125
     126    // DateTimeEditElement::EditControlOwner functions:
     127    void didBlurFromControl() final;
     128    void didChangeValueFromControl() final;
     129    bool isEditControlOwnerDisabled() const final;
     130    bool isEditControlOwnerReadOnly() const final;
     131    AtomString localeIdentifier() const final;
     132
     133    // DateTimeChooserClient functions:
     134    void didChooseValue(StringView) final;
     135    void didEndChooser() final;
     136
     137    void closeDateTimeChooser();
     138
     139    std::unique_ptr<DateTimeChooser> m_dateTimeChooser;
     140    RefPtr<DateTimeEditElement> m_dateTimeEditElement;
    72141};
    73142
  • trunk/Source/WebCore/html/DateInputType.cpp

    r266779 r267003  
    5151
    5252DateInputType::DateInputType(HTMLInputElement& element)
    53     : BaseChooserOnlyDateAndTimeInputType(element)
     53    : BaseDateAndTimeInputType(element)
    5454{
    5555}
  • trunk/Source/WebCore/html/DateInputType.h

    r266779 r267003  
    3333#if ENABLE(INPUT_TYPE_DATE)
    3434
    35 #include "BaseChooserOnlyDateAndTimeInputType.h"
     35#include "BaseDateAndTimeInputType.h"
    3636
    3737namespace WebCore {
    3838
    39 class DateInputType final : public BaseChooserOnlyDateAndTimeInputType {
     39class DateInputType final : public BaseDateAndTimeInputType {
    4040public:
    4141    explicit DateInputType(HTMLInputElement&);
  • trunk/Source/WebCore/html/DateTimeLocalInputType.cpp

    r266830 r267003  
    3535
    3636#include "DateComponents.h"
     37#include "DateTimeFieldsState.h"
    3738#include "Decimal.h"
    3839#include "HTMLInputElement.h"
    3940#include "HTMLNames.h"
    4041#include "InputTypeNames.h"
     42#include "PlatformLocale.h"
    4143#include "StepRange.h"
    4244
  • trunk/Source/WebCore/html/DateTimeLocalInputType.h

    r266779 r267003  
    3333#if ENABLE(INPUT_TYPE_DATETIMELOCAL)
    3434
    35 #include "BaseChooserOnlyDateAndTimeInputType.h"
     35#include "BaseDateAndTimeInputType.h"
    3636
    3737namespace WebCore {
    3838
    39 class DateTimeLocalInputType final : public BaseChooserOnlyDateAndTimeInputType {
     39class DateTimeLocalInputType final : public BaseDateAndTimeInputType {
    4040public:
    41     explicit DateTimeLocalInputType(HTMLInputElement& element) : BaseChooserOnlyDateAndTimeInputType(element) { }
     41    explicit DateTimeLocalInputType(HTMLInputElement& element)
     42        : BaseDateAndTimeInputType(element)
     43    {
     44    }
    4245
    4346private:
  • trunk/Source/WebCore/html/MonthInputType.h

    r266779 r267003  
    3333#if ENABLE(INPUT_TYPE_MONTH)
    3434
    35 #include "BaseChooserOnlyDateAndTimeInputType.h"
     35#include "BaseDateAndTimeInputType.h"
    3636
    3737namespace WebCore {
    3838
    39 class MonthInputType final : public BaseChooserOnlyDateAndTimeInputType {
     39class MonthInputType final : public BaseDateAndTimeInputType {
    4040public:
    41     explicit MonthInputType(HTMLInputElement& element) : BaseChooserOnlyDateAndTimeInputType(element) { }
     41    explicit MonthInputType(HTMLInputElement& element)
     42        : BaseDateAndTimeInputType(element)
     43    {
     44    }
    4245
    4346private:
  • trunk/Source/WebCore/html/TimeInputType.cpp

    r266830 r267003  
    5454
    5555TimeInputType::TimeInputType(HTMLInputElement& element)
    56     : BaseChooserOnlyDateAndTimeInputType(element)
     56    : BaseDateAndTimeInputType(element)
    5757{
    5858}
  • trunk/Source/WebCore/html/TimeInputType.h

    r266779 r267003  
    3333#if ENABLE(INPUT_TYPE_TIME)
    3434
    35 #include "BaseChooserOnlyDateAndTimeInputType.h"
     35#include "BaseDateAndTimeInputType.h"
    3636
    3737namespace WebCore {
    3838
    39 class TimeInputType final : public BaseChooserOnlyDateAndTimeInputType {
     39class TimeInputType final : public BaseDateAndTimeInputType {
    4040public:
    4141    explicit TimeInputType(HTMLInputElement&);
  • trunk/Source/WebCore/html/WeekInputType.h

    r266779 r267003  
    3333#if ENABLE(INPUT_TYPE_WEEK)
    3434
    35 #include "BaseChooserOnlyDateAndTimeInputType.h"
     35#include "BaseDateAndTimeInputType.h"
    3636
    3737namespace WebCore {
    3838
    39 class WeekInputType final : public BaseChooserOnlyDateAndTimeInputType {
     39class WeekInputType final : public BaseDateAndTimeInputType {
    4040public:
    41     explicit WeekInputType(HTMLInputElement& element) : BaseChooserOnlyDateAndTimeInputType(element) { }
     41    explicit WeekInputType(HTMLInputElement& element)
     42        : BaseDateAndTimeInputType(element)
     43    {
     44    }
    4245
    4346private:
Note: See TracChangeset for help on using the changeset viewer.