Changeset 72884 in webkit for trunk/JavaScriptCore/wtf/DateMath.h


Ignore:
Timestamp:
Nov 29, 2010, 10:11:08 PM (15 years ago)
Author:
[email protected]
Message:

2010-11-29 Dai Mikurube <[email protected]>

Reviewed by Kent Tamura.

when empty, clicking "down" on outer-spin-button returns "max value"
https://bugs.webkit.org/show_bug.cgi?id=45491

It is required to calculate UTC/DST offsets to retrieve the current local milliseconds for
date/time type inputs. WTF::currentTimeMS() returns a UTC time, and WTF::getLocalTime()
returns a struct tm, not milliseconds.

Calculating milliseconds from a struct tm is not simple since timegm() cannot be used in all
environments. This calculation is already done in calculateUTCOffset(), and complicated.
Duplicating this complicated calculation is unreasonable because of maintainability.
To achieve this without duplication, we must call calculate{UTC|DST}Offset in some way.

  • JavaScriptCore.exp:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
  • wtf/DateMath.cpp: Changed calculateUTCOffset() and calculateDSTOffset() to external functions. (WTF::calculateUTCOffset): (WTF::calculateDSTOffset):
  • wtf/DateMath.h:

2010-11-29 Dai Mikurube <[email protected]>

Reviewed by Kent Tamura.

when empty, clicking "down" on outer-spin-button returns "max value"
https://bugs.webkit.org/show_bug.cgi?id=45491

  • fast/forms/input-stepup-stepdown-from-renderer-expected.txt: Added.
  • fast/forms/input-stepup-stepdown-from-renderer.html: Added.
  • fast/forms/script-tests/input-stepup-stepdown-from-renderer.js: Added. (): (setInputAttributes): (stepUp): (stepDown): (stepUpExplicitBounds): (stepDownExplicitBounds):

2010-11-29 Dai Mikurube <[email protected]>

Reviewed by Kent Tamura.

when empty, clicking "down" on outer-spin-button returns "max value"
https://bugs.webkit.org/show_bug.cgi?id=45491

Modified stepping-up/down from renderer

  • to clamp steps,
  • to handle empty values (described below), and
  • to apply them for range type inputs.

Stepping-up/down for empty values are handled "the empty as 0."
For example :

  • If 0 is in-range, and matches to step value "down" -> -step "up" -> +step If -step or +step is out of range, new value should be 0.
  • If 0 is smaller than the minimum value "down" -> the minimum value "up" -> the minimum value
  • If 0 is larger than the maximum value "down" -> the maximum value "up" -> the maximum value
  • If 0 is in-range, but not matched to step value "down" -> smaler matched value nearest to 0.

e.g. <input type=number min=-100 step=3> -> -1

"up" -> larger matched value nearest to 0.

e.g. <input type=number min=-100 step=3> -> 2

As for date/datetime-local/month/time/week types, the empty is assumed as "current local date/time".
As for datetime type, the empty is assumed as "current date/time in UTC".

As for range input types, changed stepping from renderer to use stepUpFromRenderer().
It was calculated with stepUp() from RangeInputType::handleKeydownEvent().

Test: fast/forms/input-stepup-stepdown-from-renderer.html

  • html/BaseDateAndTimeInputType.cpp: (WebCore::BaseDateAndTimeInputType::defaultValueForStepUp): Added defaultValueForStepUp() which returns the current local time
  • html/BaseDateAndTimeInputType.h:
  • html/DateTimeInputType.cpp: (WebCore::DateTimeInputType::defaultValueForStepUp): Added defaultValueForStepUp() which returns the current UTC time
  • html/DateTimeInputType.h:
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::stepUpFromRenderer): Modified it to clamp steps, support empty values and support range type inputs
  • html/HTMLInputElement.h: (WebCore::HTMLInputElement::isRangeControl):
  • html/InputType.cpp: (WebCore::InputType::defaultValueForStepUp): Added defaultValueForStepUp() which returns 0
  • html/InputType.h:
  • html/MonthInputType.cpp: (WebCore::MonthInputType::defaultValueForStepUp): Added defaultValueForStepUp() which returns the current local month
  • html/MonthInputType.h:
  • html/RangeInputType.cpp: (WebCore::RangeInputType::handleKeydownEvent): Added comments and modified it to use stepUpFromRenderer()
  • html/TimeInputType.cpp: (WebCore::TimeInputType::defaultValueForStepUp): Added defaultValueForStepUp() which returns the current local time
  • html/TimeInputType.h:
  • manual-tests/input-type-datetime-default-value.html: Added manual tests for default values of date/time inputs since they are "the current local/UTC time", which cannot be tested automatically.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/DateMath.h

    r69920 r72884  
    8585int dayInMonthFromDayInYear(int dayInYear, bool leapYear);
    8686
     87// Returns offset milliseconds for UTC and DST.
     88int32_t calculateUTCOffset();
     89double calculateDSTOffset(double ms, double utcOffset);
     90
    8791} // namespace WTF
    8892
     
    9397using WTF::monthFromDayInYear;
    9498using WTF::msPerDay;
     99using WTF::msPerMinute;
    95100using WTF::msPerSecond;
    96101using WTF::msToYear;
    97102using WTF::secondsPerMinute;
    98103using WTF::parseDateFromNullTerminatedCharacters;
     104using WTF::calculateUTCOffset;
     105using WTF::calculateDSTOffset;
    99106
    100107#if USE(JSC)
Note: See TracChangeset for help on using the changeset viewer.