Title: [266114] trunk/Source/WebCore
Revision
266114
Author
[email protected]
Date
2020-08-25 08:29:10 -0700 (Tue, 25 Aug 2020)

Log Message

Use more enum classes in DateComponents
https://bugs.webkit.org/show_bug.cgi?id=215544

Patch by Rob Buis <[email protected]> on 2020-08-25
Reviewed by Sam Weinig.

Make Type and SecondFormat enum classes since this is more readable
and allows us to have less includes in header files.

* html/BaseDateAndTimeInputType.cpp:
(WebCore::BaseDateAndTimeInputType::serializeWithComponents const):
* html/DateInputType.cpp:
(WebCore::DateInputType::dateType const):
* html/DateInputType.h:
* html/DateTimeLocalInputType.cpp:
(WebCore::DateTimeLocalInputType::dateType const):
* html/DateTimeLocalInputType.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::dateType const):
* html/HTMLInputElement.h:
* html/InputType.cpp:
(WebCore::InputType::dateType const):
* html/InputType.h:
* html/MonthInputType.cpp:
(WebCore::MonthInputType::dateType const):
* html/MonthInputType.h:
* html/TimeInputType.cpp:
(WebCore::TimeInputType::dateType const):
* html/TimeInputType.h:
* html/WeekInputType.cpp:
(WebCore::WeekInputType::dateType const):
* html/WeekInputType.h:
* platform/DateComponents.cpp:
(WebCore::DateComponents::parseMonth):
(WebCore::DateComponents::parseDate):
(WebCore::DateComponents::parseWeek):
(WebCore::DateComponents::parseTime):
(WebCore::DateComponents::parseDateTimeLocal):
(WebCore::DateComponents::setMillisecondsSinceEpochForDate):
(WebCore::DateComponents::setMillisecondsSinceEpochForDateTimeLocal):
(WebCore::DateComponents::setMillisecondsSinceEpochForMonth):
(WebCore::DateComponents::setMillisecondsSinceMidnight):
(WebCore::DateComponents::setMonthsSinceEpoch):
(WebCore::DateComponents::setMillisecondsSinceEpochForWeek):
(WebCore::DateComponents::millisecondsSinceEpochForTime const):
(WebCore::DateComponents::millisecondsSinceEpoch const):
(WebCore::DateComponents::monthsSinceEpoch const):
(WebCore::DateComponents::toStringForTime const):
(WebCore::DateComponents::toString const):
* platform/DateComponents.h:
(WebCore::DateComponents::DateComponents):
(WebCore::DateComponents::type const):
* platform/text/PlatformLocale.cpp:
(WebCore::Locale::formatDateTime):
* platform/text/PlatformLocale.h:
* platform/text/cocoa/LocaleCocoa.mm:
(WebCore::LocaleCocoa::formatDateTime):
* platform/text/ios/LocalizedDateCache.h:
* platform/text/ios/LocalizedDateCache.mm:
(WebCore::LocalizedDateCache::formatterForDateType):
(WebCore::LocalizedDateCache::maximumWidthForDateType):
(WebCore::LocalizedDateCache::createFormatterForType):
(WebCore::LocalizedDateCache::calculateMaximumWidth):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (266113 => 266114)


--- trunk/Source/WebCore/ChangeLog	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/ChangeLog	2020-08-25 15:29:10 UTC (rev 266114)
@@ -1,3 +1,68 @@
+2020-08-25  Rob Buis  <[email protected]>
+
+        Use more enum classes in DateComponents
+        https://bugs.webkit.org/show_bug.cgi?id=215544
+
+        Reviewed by Sam Weinig.
+
+        Make Type and SecondFormat enum classes since this is more readable
+        and allows us to have less includes in header files.
+
+        * html/BaseDateAndTimeInputType.cpp:
+        (WebCore::BaseDateAndTimeInputType::serializeWithComponents const):
+        * html/DateInputType.cpp:
+        (WebCore::DateInputType::dateType const):
+        * html/DateInputType.h:
+        * html/DateTimeLocalInputType.cpp:
+        (WebCore::DateTimeLocalInputType::dateType const):
+        * html/DateTimeLocalInputType.h:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::dateType const):
+        * html/HTMLInputElement.h:
+        * html/InputType.cpp:
+        (WebCore::InputType::dateType const):
+        * html/InputType.h:
+        * html/MonthInputType.cpp:
+        (WebCore::MonthInputType::dateType const):
+        * html/MonthInputType.h:
+        * html/TimeInputType.cpp:
+        (WebCore::TimeInputType::dateType const):
+        * html/TimeInputType.h:
+        * html/WeekInputType.cpp:
+        (WebCore::WeekInputType::dateType const):
+        * html/WeekInputType.h:
+        * platform/DateComponents.cpp:
+        (WebCore::DateComponents::parseMonth):
+        (WebCore::DateComponents::parseDate):
+        (WebCore::DateComponents::parseWeek):
+        (WebCore::DateComponents::parseTime):
+        (WebCore::DateComponents::parseDateTimeLocal):
+        (WebCore::DateComponents::setMillisecondsSinceEpochForDate):
+        (WebCore::DateComponents::setMillisecondsSinceEpochForDateTimeLocal):
+        (WebCore::DateComponents::setMillisecondsSinceEpochForMonth):
+        (WebCore::DateComponents::setMillisecondsSinceMidnight):
+        (WebCore::DateComponents::setMonthsSinceEpoch):
+        (WebCore::DateComponents::setMillisecondsSinceEpochForWeek):
+        (WebCore::DateComponents::millisecondsSinceEpochForTime const):
+        (WebCore::DateComponents::millisecondsSinceEpoch const):
+        (WebCore::DateComponents::monthsSinceEpoch const):
+        (WebCore::DateComponents::toStringForTime const):
+        (WebCore::DateComponents::toString const):
+        * platform/DateComponents.h:
+        (WebCore::DateComponents::DateComponents):
+        (WebCore::DateComponents::type const):
+        * platform/text/PlatformLocale.cpp:
+        (WebCore::Locale::formatDateTime):
+        * platform/text/PlatformLocale.h:
+        * platform/text/cocoa/LocaleCocoa.mm:
+        (WebCore::LocaleCocoa::formatDateTime):
+        * platform/text/ios/LocalizedDateCache.h:
+        * platform/text/ios/LocalizedDateCache.mm:
+        (WebCore::LocalizedDateCache::formatterForDateType):
+        (WebCore::LocalizedDateCache::maximumWidthForDateType):
+        (WebCore::LocalizedDateCache::createFormatterForType):
+        (WebCore::LocalizedDateCache::calculateMaximumWidth):
+
 2020-08-25  Carlos Garcia Campos  <[email protected]>
 
         [SOUP] Initialize HSTS storage directory from network session initialization

Modified: trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp (266113 => 266114)


--- trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/BaseDateAndTimeInputType.cpp	2020-08-25 15:29:10 UTC (rev 266114)
@@ -34,6 +34,7 @@
 
 #if ENABLE(DATE_AND_TIME_INPUT_TYPES)
 
+#include "DateComponents.h"
 #include "Decimal.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
@@ -133,13 +134,11 @@
 {
     ASSERT(element());
     Decimal step;
-    if (!element()->getAllowedValueStep(&step))
+    if (!element()->getAllowedValueStep(&step) || step.remainder(msecPerMinute).isZero())
         return date.toString();
-    if (step.remainder(msecPerMinute).isZero())
-        return date.toString(DateComponents::None);
     if (step.remainder(msecPerSecond).isZero())
-        return date.toString(DateComponents::Second);
-    return date.toString(DateComponents::Millisecond);
+        return date.toString(SecondFormat::Second);
+    return date.toString(SecondFormat::Millisecond);
 }
 
 String BaseDateAndTimeInputType::serializeWithMilliseconds(double value) const

Modified: trunk/Source/WebCore/html/BaseDateAndTimeInputType.h (266113 => 266114)


--- trunk/Source/WebCore/html/BaseDateAndTimeInputType.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/BaseDateAndTimeInputType.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -33,11 +33,12 @@
 
 #if ENABLE(DATE_AND_TIME_INPUT_TYPES)
 
-#include "DateComponents.h"
 #include "InputType.h"
 
 namespace WebCore {
 
+class DateComponents;
+
 // A super class of date, datetime, datetime-local, month, time, and week types.
 class BaseDateAndTimeInputType : public InputType {
 protected:

Modified: trunk/Source/WebCore/html/DateInputType.cpp (266113 => 266114)


--- trunk/Source/WebCore/html/DateInputType.cpp	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/DateInputType.cpp	2020-08-25 15:29:10 UTC (rev 266114)
@@ -32,6 +32,7 @@
 #if ENABLE(INPUT_TYPE_DATE)
 #include "DateInputType.h"
 
+#include "DateComponents.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "InputTypeNames.h"
@@ -56,9 +57,9 @@
     return InputTypeNames::date();
 }
 
-DateComponents::Type DateInputType::dateType() const
+DateComponentsType DateInputType::dateType() const
 {
-    return DateComponents::Date;
+    return DateComponentsType::Date;
 }
 
 StepRange DateInputType::createStepRange(AnyStepHandling anyStepHandling) const

Modified: trunk/Source/WebCore/html/DateInputType.h (266113 => 266114)


--- trunk/Source/WebCore/html/DateInputType.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/DateInputType.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -42,7 +42,7 @@
 
 private:
     const AtomString& formControlType() const override;
-    DateComponents::Type dateType() const override;
+    DateComponentsType dateType() const override;
     StepRange createStepRange(AnyStepHandling) const override;
     Optional<DateComponents> parseToDateComponents(const StringView&) const override;
     Optional<DateComponents> setMillisecondToDateComponents(double) const override;

Modified: trunk/Source/WebCore/html/DateTimeLocalInputType.cpp (266113 => 266114)


--- trunk/Source/WebCore/html/DateTimeLocalInputType.cpp	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/DateTimeLocalInputType.cpp	2020-08-25 15:29:10 UTC (rev 266114)
@@ -33,6 +33,7 @@
 
 #if ENABLE(INPUT_TYPE_DATETIMELOCAL)
 
+#include "DateComponents.h"
 #include "Decimal.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
@@ -53,9 +54,9 @@
     return InputTypeNames::datetimelocal();
 }
 
-DateComponents::Type DateTimeLocalInputType::dateType() const
+DateComponentsType DateTimeLocalInputType::dateType() const
 {
-    return DateComponents::DateTimeLocal;
+    return DateComponentsType::DateTimeLocal;
 }
 
 double DateTimeLocalInputType::valueAsDate() const

Modified: trunk/Source/WebCore/html/DateTimeLocalInputType.h (266113 => 266114)


--- trunk/Source/WebCore/html/DateTimeLocalInputType.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/DateTimeLocalInputType.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -42,7 +42,7 @@
 
 private:
     const AtomString& formControlType() const final;
-    DateComponents::Type dateType() const final;
+    DateComponentsType dateType() const final;
     double valueAsDate() const final;
     ExceptionOr<void> setValueAsDate(double) const final;
     StepRange createStepRange(AnyStepHandling) const final;

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (266113 => 266114)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2020-08-25 15:29:10 UTC (rev 266114)
@@ -36,6 +36,7 @@
 #include "CSSValuePool.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
+#include "DateComponents.h"
 #include "DateTimeChooser.h"
 #include "DateTimeChooserParameters.h"
 #include "Document.h"
@@ -1676,7 +1677,7 @@
     return m_inputType->isSteppable();
 }
 
-DateComponents::Type HTMLInputElement::dateType() const
+DateComponentsType HTMLInputElement::dateType() const
 {
     return m_inputType->dateType();
 }

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (266113 => 266114)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -24,7 +24,6 @@
 
 #pragma once
 
-#include "DateComponents.h"
 #include "FileChooser.h"
 #include "HTMLTextFormControlElement.h"
 #include <memory>
@@ -53,6 +52,7 @@
 };
 
 enum class AnyStepHandling : bool;
+enum class DateComponentsType : uint8_t;
 
 class HTMLInputElement : public HTMLTextFormControlElement {
     WTF_MAKE_ISO_ALLOCATED(HTMLInputElement);
@@ -130,7 +130,7 @@
     WEBCORE_EXPORT bool isTimeField() const;
     WEBCORE_EXPORT bool isWeekField() const;
 
-    DateComponents::Type dateType() const;
+    DateComponentsType dateType() const;
 
     HTMLElement* containerElement() const;
     

Modified: trunk/Source/WebCore/html/InputType.cpp (266113 => 266114)


--- trunk/Source/WebCore/html/InputType.cpp	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/InputType.cpp	2020-08-25 15:29:10 UTC (rev 266114)
@@ -523,9 +523,9 @@
     return String();
 }
 
-DateComponents::Type InputType::dateType() const
+DateComponentsType InputType::dateType() const
 {
-    return DateComponents::Invalid;
+    return DateComponentsType::Invalid;
 }
 
 void InputType::dispatchSimulatedClickIfActive(KeyboardEvent& event) const

Modified: trunk/Source/WebCore/html/InputType.h (266113 => 266114)


--- trunk/Source/WebCore/html/InputType.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/InputType.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -40,10 +40,6 @@
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 
-#if PLATFORM(IOS_FAMILY)
-#include "DateComponents.h"
-#endif
-
 namespace WebCore {
 
 class BeforeTextInsertedEvent;
@@ -67,6 +63,7 @@
 struct InputElementClickState;
 
 enum class AnyStepHandling : bool;
+enum class DateComponentsType : uint8_t;
 
 // An InputType object represents the type-specific part of an HTMLInputElement.
 // Do not expose instances of InputType and classes derived from it to classes
@@ -305,7 +302,7 @@
     virtual bool receiveDroppedFiles(const DragData&);
 #endif
 
-    virtual DateComponents::Type dateType() const;
+    virtual DateComponentsType dateType() const;
 
     virtual String displayString() const;
 

Modified: trunk/Source/WebCore/html/MonthInputType.cpp (266113 => 266114)


--- trunk/Source/WebCore/html/MonthInputType.cpp	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/MonthInputType.cpp	2020-08-25 15:29:10 UTC (rev 266114)
@@ -32,6 +32,7 @@
 #if ENABLE(INPUT_TYPE_MONTH)
 #include "MonthInputType.h"
 
+#include "DateComponents.h"
 #include "Decimal.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
@@ -55,9 +56,9 @@
     return InputTypeNames::month();
 }
 
-DateComponents::Type MonthInputType::dateType() const
+DateComponentsType MonthInputType::dateType() const
 {
-    return DateComponents::Month;
+    return DateComponentsType::Month;
 }
 
 double MonthInputType::valueAsDate() const

Modified: trunk/Source/WebCore/html/MonthInputType.h (266113 => 266114)


--- trunk/Source/WebCore/html/MonthInputType.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/MonthInputType.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -42,7 +42,7 @@
 
 private:
     const AtomString& formControlType() const override;
-    DateComponents::Type dateType() const override;
+    DateComponentsType dateType() const override;
     double valueAsDate() const override;
     String serializeWithMilliseconds(double) const override;
     Decimal parseToNumber(const String&, const Decimal&) const override;

Modified: trunk/Source/WebCore/html/TimeInputType.cpp (266113 => 266114)


--- trunk/Source/WebCore/html/TimeInputType.cpp	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/TimeInputType.cpp	2020-08-25 15:29:10 UTC (rev 266114)
@@ -32,6 +32,7 @@
 #if ENABLE(INPUT_TYPE_TIME)
 #include "TimeInputType.h"
 
+#include "DateComponents.h"
 #include "Decimal.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
@@ -59,9 +60,9 @@
     return InputTypeNames::time();
 }
 
-DateComponents::Type TimeInputType::dateType() const
+DateComponentsType TimeInputType::dateType() const
 {
-    return DateComponents::Time;
+    return DateComponentsType::Time;
 }
 
 Decimal TimeInputType::defaultValueForStepUp() const

Modified: trunk/Source/WebCore/html/TimeInputType.h (266113 => 266114)


--- trunk/Source/WebCore/html/TimeInputType.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/TimeInputType.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -42,7 +42,7 @@
 
 private:
     const AtomString& formControlType() const override;
-    DateComponents::Type dateType() const override;
+    DateComponentsType dateType() const override;
     Decimal defaultValueForStepUp() const override;
     StepRange createStepRange(AnyStepHandling) const override;
     Optional<DateComponents> parseToDateComponents(const StringView&) const override;

Modified: trunk/Source/WebCore/html/WeekInputType.cpp (266113 => 266114)


--- trunk/Source/WebCore/html/WeekInputType.cpp	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/WeekInputType.cpp	2020-08-25 15:29:10 UTC (rev 266114)
@@ -32,6 +32,7 @@
 #if ENABLE(INPUT_TYPE_WEEK)
 #include "WeekInputType.h"
 
+#include "DateComponents.h"
 #include "Decimal.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
@@ -52,9 +53,9 @@
     return InputTypeNames::week();
 }
 
-DateComponents::Type WeekInputType::dateType() const
+DateComponentsType WeekInputType::dateType() const
 {
-    return DateComponents::Week;
+    return DateComponentsType::Week;
 }
 
 StepRange WeekInputType::createStepRange(AnyStepHandling anyStepHandling) const

Modified: trunk/Source/WebCore/html/WeekInputType.h (266113 => 266114)


--- trunk/Source/WebCore/html/WeekInputType.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/html/WeekInputType.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -42,7 +42,7 @@
 
 private:
     const AtomString& formControlType() const override;
-    DateComponents::Type dateType() const override;
+    DateComponentsType dateType() const override;
     StepRange createStepRange(AnyStepHandling) const override;
     Optional<DateComponents> parseToDateComponents(const StringView&) const override;
     Optional<DateComponents> setMillisecondToDateComponents(double) const override;

Modified: trunk/Source/WebCore/platform/DateComponents.cpp (266113 => 266114)


--- trunk/Source/WebCore/platform/DateComponents.cpp	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/platform/DateComponents.cpp	2020-08-25 15:29:10 UTC (rev 266114)
@@ -398,7 +398,7 @@
         return false;
 
     m_month = *month;
-    m_type = Month;
+    m_type = DateComponentsType::Month;
     return true;
 }
 
@@ -418,7 +418,7 @@
         return false;
 
     m_monthDay = *day;
-    m_type = Date;
+    m_type = DateComponentsType::Date;
     return true;
 }
 
@@ -440,7 +440,7 @@
         return false;
 
     m_week = *week;
-    m_type = Week;
+    m_type = DateComponentsType::Week;
     return true;
 }
 
@@ -500,7 +500,7 @@
     m_minute = *minute;
     m_second = second.valueOr(0);
     m_millisecond = millisecond.valueOr(0);
-    m_type = Time;
+    m_type = DateComponentsType::Time;
     return true;
 }
 
@@ -518,7 +518,7 @@
     if (!withinHTMLDateLimits(m_year, m_month, m_monthDay, m_hour, m_minute, m_second, m_millisecond))
         return false;
 
-    m_type = DateTimeLocal;
+    m_type = DateComponentsType::DateTimeLocal;
     return true;
 }
 
@@ -600,7 +600,7 @@
 
 bool DateComponents::setMillisecondsSinceEpochForDate(double ms)
 {
-    m_type = Invalid;
+    m_type = DateComponentsType::Invalid;
     if (!std::isfinite(ms))
         return false;
     if (!setMillisecondsSinceEpochForDateInternal(round(ms)))
@@ -607,13 +607,13 @@
         return false;
     if (!withinHTMLDateLimits(m_year, m_month, m_monthDay))
         return false;
-    m_type = Date;
+    m_type = DateComponentsType::Date;
     return true;
 }
 
 bool DateComponents::setMillisecondsSinceEpochForDateTimeLocal(double ms)
 {
-    m_type = Invalid;
+    m_type = DateComponentsType::Invalid;
     if (!std::isfinite(ms))
         return false;
     ms = round(ms);
@@ -622,13 +622,13 @@
         return false;
     if (!withinHTMLDateLimits(m_year, m_month, m_monthDay, m_hour, m_minute, m_second, m_millisecond))
         return false;
-    m_type = DateTimeLocal;
+    m_type = DateComponentsType::DateTimeLocal;
     return true;
 }
 
 bool DateComponents::setMillisecondsSinceEpochForMonth(double ms)
 {
-    m_type = Invalid;
+    m_type = DateComponentsType::Invalid;
     if (!std::isfinite(ms))
         return false;
     if (!setMillisecondsSinceEpochForDateInternal(round(ms)))
@@ -635,17 +635,17 @@
         return false;
     if (!withinHTMLDateLimits(m_year, m_month))
         return false;
-    m_type = Month;
+    m_type = DateComponentsType::Month;
     return true;
 }
 
 bool DateComponents::setMillisecondsSinceMidnight(double ms)
 {
-    m_type = Invalid;
+    m_type = DateComponentsType::Invalid;
     if (!std::isfinite(ms))
         return false;
     setMillisecondsSinceMidnightInternal(positiveFmod(round(ms), msPerDay));
-    m_type = Time;
+    m_type = DateComponentsType::Time;
     return true;
 }
 
@@ -664,7 +664,7 @@
         return false;
     m_year = year;
     m_month = month;
-    m_type = Month;
+    m_type = DateComponentsType::Month;
     return true;
 }
 
@@ -680,7 +680,7 @@
 
 bool DateComponents::setMillisecondsSinceEpochForWeek(double ms)
 {
-    m_type = Invalid;
+    m_type = DateComponentsType::Invalid;
     if (!std::isfinite(ms))
         return false;
     ms = round(ms);
@@ -706,13 +706,13 @@
         if (m_year > maximumYear || (m_year == maximumYear && m_week > maximumWeekInMaximumYear))
             return false;
     }
-    m_type = Week;
+    m_type = DateComponentsType::Week;
     return true;
 }
 
 double DateComponents::millisecondsSinceEpochForTime() const
 {
-    ASSERT(m_type == Time || m_type == DateTimeLocal);
+    ASSERT(m_type == DateComponentsType::Time || m_type == DateComponentsType::DateTimeLocal);
     return ((m_hour * minutesPerHour + m_minute) * secondsPerMinute + m_second) * msPerSecond + m_millisecond;
 }
 
@@ -719,17 +719,17 @@
 double DateComponents::millisecondsSinceEpoch() const
 {
     switch (m_type) {
-    case Date:
+    case DateComponentsType::Date:
         return dateToDaysFrom1970(m_year, m_month, m_monthDay) * msPerDay;
-    case DateTimeLocal:
+    case DateComponentsType::DateTimeLocal:
         return dateToDaysFrom1970(m_year, m_month, m_monthDay) * msPerDay + millisecondsSinceEpochForTime();
-    case Month:
+    case DateComponentsType::Month:
         return dateToDaysFrom1970(m_year, m_month, 1) * msPerDay;
-    case Time:
+    case DateComponentsType::Time:
         return millisecondsSinceEpochForTime();
-    case Week:
+    case DateComponentsType::Week:
         return (dateToDaysFrom1970(m_year, 0, 1) + offsetTo1stWeekStart(m_year) + (m_week - 1) * 7) * msPerDay;
-    case Invalid:
+    case DateComponentsType::Invalid:
         break;
     }
     ASSERT_NOT_REACHED();
@@ -738,18 +738,18 @@
 
 double DateComponents::monthsSinceEpoch() const
 {
-    ASSERT(m_type == Month);
+    ASSERT(m_type == DateComponentsType::Month);
     return (m_year - 1970) * 12 + m_month;
 }
 
 String DateComponents::toStringForTime(SecondFormat format) const
 {
-    ASSERT(m_type == DateTimeLocal || m_type == Time);
+    ASSERT(m_type == DateComponentsType::DateTimeLocal || m_type == DateComponentsType::Time);
     SecondFormat effectiveFormat = format;
     if (m_millisecond)
-        effectiveFormat = Millisecond;
-    else if (format == None && m_second)
-        effectiveFormat = Second;
+        effectiveFormat = SecondFormat::Millisecond;
+    else if (format == SecondFormat::None && m_second)
+        effectiveFormat = SecondFormat::Second;
 
     switch (effectiveFormat) {
     default:
@@ -757,11 +757,11 @@
 #if !ASSERT_ENABLED
         FALLTHROUGH; // To None.
 #endif
-    case None:
+    case SecondFormat::None:
         return makeString(pad('0', 2, m_hour), ':', pad('0', 2, m_minute));
-    case Second:
+    case SecondFormat::Second:
         return makeString(pad('0', 2, m_hour), ':', pad('0', 2, m_minute), ':', pad('0', 2, m_second));
-    case Millisecond:
+    case SecondFormat::Millisecond:
         return makeString(pad('0', 2, m_hour), ':', pad('0', 2, m_minute), ':', pad('0', 2, m_second), '.', pad('0', 3, m_millisecond));
     }
 }
@@ -769,17 +769,17 @@
 String DateComponents::toString(SecondFormat format) const
 {
     switch (m_type) {
-    case Date:
+    case DateComponentsType::Date:
         return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1), '-', pad('0', 2, m_monthDay));
-    case DateTimeLocal:
+    case DateComponentsType::DateTimeLocal:
         return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1), '-', pad('0', 2, m_monthDay), 'T', toStringForTime(format));
-    case Month:
+    case DateComponentsType::Month:
         return makeString(pad('0', 4, m_year), '-', pad('0', 2, m_month + 1));
-    case Time:
+    case DateComponentsType::Time:
         return toStringForTime(format);
-    case Week:
+    case DateComponentsType::Week:
         return makeString(pad('0', 4, m_year), "-W", pad('0', 2, m_week));
-    case Invalid:
+    case DateComponentsType::Invalid:
         break;
     }
     ASSERT_NOT_REACHED();

Modified: trunk/Source/WebCore/platform/DateComponents.h (266113 => 266114)


--- trunk/Source/WebCore/platform/DateComponents.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/platform/DateComponents.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -36,6 +36,21 @@
 
 namespace WebCore {
 
+enum class SecondFormat : uint8_t {
+    None, // Suppress the second part and the millisecond part if they are 0.
+    Second, // Always show the second part, and suppress the millisecond part if it is 0.
+    Millisecond // Always show the second part and the millisecond part.
+};
+
+enum class DateComponentsType : uint8_t {
+    Invalid,
+    Date,
+    DateTimeLocal,
+    Month,
+    Time,
+    Week,
+};
+
 // A DateComponents instance represents one of the following date and time combinations:
 // * Month type: year-month
 // * Date type: year-month-day
@@ -53,19 +68,10 @@
         , m_month(0)
         , m_year(0)
         , m_week(0)
-        , m_type(Invalid)
+        , m_type(DateComponentsType::Invalid)
     {
     }
 
-    enum Type {
-        Invalid,
-        Date,
-        DateTimeLocal,
-        Month,
-        Time,
-        Week,
-    };
-
     int millisecond() const { return m_millisecond; }
     int second() const { return m_second; }
     int minute() const { return m_minute; }
@@ -74,17 +80,11 @@
     int month() const { return m_month; }
     int fullYear() const { return m_year; }
     int week() const { return m_week; }
-    Type type() const { return m_type; }
+    DateComponentsType type() const { return m_type; }
 
-    enum SecondFormat {
-        None, // Suppress the second part and the millisecond part if they are 0.
-        Second, // Always show the second part, and suppress the millisecond part if it is 0.
-        Millisecond // Always show the second part and the millisecond part.
-    };
-
     // Returns an ISO 8601 representation for this instance.
     // The format argument is valid for DateTimeLocal and Time types.
-    String toString(SecondFormat = None) const;
+    String toString(SecondFormat = SecondFormat::None) const;
 
     // Sets year and month.
     static Optional<DateComponents> fromParsingMonth(StringView);
@@ -193,7 +193,7 @@
     int m_year; //  1582 -
     int m_week; // 1 - 53
 
-    Type m_type;
+    DateComponentsType m_type;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/text/PlatformLocale.cpp (266113 => 266114)


--- trunk/Source/WebCore/platform/text/PlatformLocale.cpp	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/platform/text/PlatformLocale.cpp	2020-08-25 15:29:10 UTC (rev 266114)
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "PlatformLocale.h"
 
+#include "DateComponents.h"
 #include "DateTimeFormat.h"
 #include "LocalizedStrings.h"
 #include <wtf/text/StringBuilder.h>
@@ -327,27 +328,27 @@
 #if ENABLE(DATE_AND_TIME_INPUT_TYPES)
 String Locale::formatDateTime(const DateComponents& date, FormatType formatType)
 {
-    if (date.type() == DateComponents::Invalid)
+    if (date.type() == DateComponentsType::Invalid)
         return String();
 
     DateTimeStringBuilder builder(*this, date);
     switch (date.type()) {
-    case DateComponents::Time:
+    case DateComponentsType::Time:
         builder.build(formatType == FormatTypeShort ? shortTimeFormat() : timeFormat());
         break;
-    case DateComponents::Date:
+    case DateComponentsType::Date:
         builder.build(dateFormat());
         break;
-    case DateComponents::Month:
+    case DateComponentsType::Month:
         builder.build(formatType == FormatTypeShort ? shortMonthFormat() : monthFormat());
         break;
-    case DateComponents::Week:    
+    case DateComponentsType::Week:    
         // FIXME: Add support for formatting weeks.
         break;
-    case DateComponents::DateTimeLocal:
+    case DateComponentsType::DateTimeLocal:
         builder.build(formatType == FormatTypeShort ? dateTimeFormatWithoutSeconds() : dateTimeFormatWithSeconds());
         break;
-    case DateComponents::Invalid:
+    case DateComponentsType::Invalid:
         ASSERT_NOT_REACHED();
         break;
     }

Modified: trunk/Source/WebCore/platform/text/PlatformLocale.h (266113 => 266114)


--- trunk/Source/WebCore/platform/text/PlatformLocale.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/platform/text/PlatformLocale.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -26,12 +26,13 @@
 #ifndef PlatformLocale_h
 #define PlatformLocale_h
 
-#include "DateComponents.h"
 #include <wtf/Language.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
+class DateComponents;
+
 #if PLATFORM(IOS_FAMILY)
 class FontCascade;
 #endif

Modified: trunk/Source/WebCore/platform/text/cocoa/LocaleCocoa.mm (266113 => 266114)


--- trunk/Source/WebCore/platform/text/cocoa/LocaleCocoa.mm	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/platform/text/cocoa/LocaleCocoa.mm	2020-08-25 15:29:10 UTC (rev 266114)
@@ -31,6 +31,7 @@
 #import "config.h"
 #import "LocaleCocoa.h"
 
+#import "DateComponents.h"
 #import "LocalizedStrings.h"
 #import <Foundation/NSDateFormatter.h>
 #import <Foundation/NSLocale.h>
@@ -106,11 +107,11 @@
 String LocaleCocoa::formatDateTime(const DateComponents& dateComponents, FormatType)
 {
     double msec = dateComponents.millisecondsSinceEpoch();
-    DateComponents::Type type = dateComponents.type();
+    DateComponentsType type = dateComponents.type();
 
     // "week" type not supported.
-    ASSERT(type != DateComponents::Invalid);
-    if (type == DateComponents::Week)
+    ASSERT(type != DateComponentsType::Invalid);
+    if (type == DateComponentsType::Week)
         return String();
 
     // Incoming msec value is milliseconds since 1970-01-01 00:00:00 UTC. The 1970 epoch.

Modified: trunk/Source/WebCore/platform/text/ios/LocalizedDateCache.h (266113 => 266114)


--- trunk/Source/WebCore/platform/text/ios/LocalizedDateCache.h	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/platform/text/ios/LocalizedDateCache.h	2020-08-25 15:29:10 UTC (rev 266114)
@@ -25,7 +25,6 @@
 
 #pragma once
 
-#include "DateComponents.h"
 #include "FontCascade.h"
 #include <wtf/HashMap.h>
 #include <wtf/RetainPtr.h>
@@ -32,6 +31,8 @@
 
 namespace WebCore {
     
+enum class DateComponentsType : uint8_t;
+
 class MeasureTextClient {
 public:
     virtual float measureText(const String&) const = 0;
@@ -40,8 +41,8 @@
 
 class LocalizedDateCache {
 public:
-    NSDateFormatter *formatterForDateType(DateComponents::Type);
-    float maximumWidthForDateType(DateComponents::Type, const FontCascade&, const MeasureTextClient&);
+    NSDateFormatter *formatterForDateType(DateComponentsType);
+    float maximumWidthForDateType(DateComponentsType, const FontCascade&, const MeasureTextClient&);
     void localeChanged();
 
 private:
@@ -48,10 +49,10 @@
     LocalizedDateCache();
     ~LocalizedDateCache();
 
-    NSDateFormatter *createFormatterForType(DateComponents::Type);
-    float calculateMaximumWidth(DateComponents::Type, const MeasureTextClient&);
+    NSDateFormatter *createFormatterForType(DateComponentsType);
+    float calculateMaximumWidth(DateComponentsType, const MeasureTextClient&);
 
-    // Using int instead of DateComponents::Type for the key because the enum
+    // Using int instead of DateComponentsType for the key because the enum
     // does not have a default hash and hash traits. Usage of the maps
     // casts the DateComponents::Type into an int as the key.
     typedef HashMap<int, RetainPtr<NSDateFormatter>> DateTypeFormatterMap;

Modified: trunk/Source/WebCore/platform/text/ios/LocalizedDateCache.mm (266113 => 266114)


--- trunk/Source/WebCore/platform/text/ios/LocalizedDateCache.mm	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/platform/text/ios/LocalizedDateCache.mm	2020-08-25 15:29:10 UTC (rev 266114)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "LocalizedDateCache.h"
 
+#import "DateComponents.h"
 #import "FontCascade.h"
 #import <CoreFoundation/CFNotificationCenter.h>
 #import <math.h>
@@ -69,7 +70,7 @@
     m_formatterMap.clear();
 }
 
-NSDateFormatter *LocalizedDateCache::formatterForDateType(DateComponents::Type type)
+NSDateFormatter *LocalizedDateCache::formatterForDateType(DateComponentsType type)
 {
     int key = static_cast<int>(type);
     if (m_formatterMap.contains(key))
@@ -80,7 +81,7 @@
     return dateFormatter;
 }
 
-float LocalizedDateCache::maximumWidthForDateType(DateComponents::Type type, const FontCascade& font, const MeasureTextClient& measurer)
+float LocalizedDateCache::maximumWidthForDateType(DateComponentsType type, const FontCascade& font, const MeasureTextClient& measurer)
 {
     int key = static_cast<int>(type);
     if (m_font == font) {
@@ -96,7 +97,7 @@
     return calculatedMaximum;
 }
 
-NSDateFormatter *LocalizedDateCache::createFormatterForType(DateComponents::Type type)
+NSDateFormatter *LocalizedDateCache::createFormatterForType(DateComponentsType type)
 {
     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
     NSLocale *currentLocale = [NSLocale currentLocale];
@@ -103,29 +104,29 @@
     [dateFormatter setLocale:currentLocale];
 
     switch (type) {
-    case DateComponents::Invalid:
+    case DateComponentsType::Invalid:
         ASSERT_NOT_REACHED();
         break;
-    case DateComponents::Date:
+    case DateComponentsType::Date:
         [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
         [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
         [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
         break;
-    case DateComponents::DateTimeLocal:
+    case DateComponentsType::DateTimeLocal:
         [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
         [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
         [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
         break;
-    case DateComponents::Month:
+    case DateComponentsType::Month:
         [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
         [dateFormatter setDateFormat:[NSDateFormatter dateFormatFromTemplate:@"MMMMyyyy" options:0 locale:currentLocale]];
         break;
-    case DateComponents::Time:
+    case DateComponentsType::Time:
         [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
         [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
         [dateFormatter setDateStyle:NSDateFormatterNoStyle];
         break;
-    case DateComponents::Week:
+    case DateComponentsType::Week:
         ASSERT_NOT_REACHED();
         break;
     }
@@ -135,7 +136,7 @@
 
 // NOTE: This does not check for the widest day of the week.
 // We assume no formatter option shows that information.
-float LocalizedDateCache::calculateMaximumWidth(DateComponents::Type type, const MeasureTextClient& measurer)
+float LocalizedDateCache::calculateMaximumWidth(DateComponentsType type, const MeasureTextClient& measurer)
 {
     float maximumWidth = 0;
 
@@ -160,9 +161,9 @@
 
     // For each month (in the Gregorian Calendar), format a date and measure its length.
     NSUInteger totalMonthsToTest = 1;
-    if (type == DateComponents::Date
-        || type == DateComponents::DateTimeLocal
-        || type == DateComponents::Month)
+    if (type == DateComponentsType::Date
+        || type == DateComponentsType::DateTimeLocal
+        || type == DateComponentsType::Month)
         totalMonthsToTest = numberOfGregorianMonths;
     for (NSUInteger i = 0; i < totalMonthsToTest; ++i) {
         [components.get() setMonth:(i + 1)];

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (266113 => 266114)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2020-08-25 15:29:05 UTC (rev 266113)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2020-08-25 15:29:10 UTC (rev 266114)
@@ -612,8 +612,8 @@
         return;
 
     // Don't adjust for unsupported date input types.
-    DateComponents::Type dateType = inputElement.dateType();
-    if (dateType == DateComponents::Invalid || dateType == DateComponents::Week)
+    DateComponentsType dateType = inputElement.dateType();
+    if (dateType == DateComponentsType::Invalid || dateType == DateComponentsType::Week)
         return;
 
     // Enforce the width and set the box-sizing to content-box to not conflict with the padding.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to