Changeset 72884 in webkit
- Timestamp:
- Nov 29, 2010 10:11:08 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r72853 r72884 1 2010-11-29 Dai Mikurube <dmikurube@google.com> 2 3 Reviewed by Kent Tamura. 4 5 when empty, clicking "down" on outer-spin-button returns "max value" 6 https://bugs.webkit.org/show_bug.cgi?id=45491 7 8 It is required to calculate UTC/DST offsets to retrieve the current local milliseconds for 9 date/time type inputs. WTF::currentTimeMS() returns a UTC time, and WTF::getLocalTime() 10 returns a struct tm, not milliseconds. 11 12 Calculating milliseconds from a struct tm is not simple since timegm() cannot be used in all 13 environments. This calculation is already done in calculateUTCOffset(), and complicated. 14 Duplicating this complicated calculation is unreasonable because of maintainability. 15 To achieve this without duplication, we must call calculate{UTC|DST}Offset in some way. 16 17 * JavaScriptCore.exp: 18 * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: 19 * wtf/DateMath.cpp: Changed calculateUTCOffset() and calculateDSTOffset() to external functions. 20 (WTF::calculateUTCOffset): 21 (WTF::calculateDSTOffset): 22 * wtf/DateMath.h: 23 1 24 2010-11-29 Chris Rogers <crogers@google.com> 2 25 -
trunk/JavaScriptCore/JavaScriptCore.exp
r72477 r72884 405 405 __ZN3WTF17equalIgnoringCaseEPNS_10StringImplEPKc 406 406 __ZN3WTF17equalIgnoringCaseEPNS_10StringImplES1_ 407 __ZN3WTF18calculateDSTOffsetEdd 408 __ZN3WTF18calculateUTCOffsetEv 407 409 __ZN3WTF18charactersToDoubleEPKtmPb 408 410 __ZN3WTF18dateToDaysFrom1970Eiii -
trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def
r72134 r72884 60 60 ?bufferLengthForStringDecimal@DecimalNumber@WTF@@QBEIXZ 61 61 ?calculatedFunctionName@DebuggerCallFrame@JSC@@QBE?AVUString@2@XZ 62 ?calculateUTCOffset@WTF@@YAHXZ 63 ?calculateDSTOffset@WTF@@YANNN@Z 62 64 ?call@JSC@@YA?AVJSValue@1@PAVExecState@1@V21@W4CallType@1@ABTCallData@1@1ABVArgList@1@@Z 63 65 ?callOnMainThread@WTF@@YAXP6AXPAX@Z0@Z -
trunk/JavaScriptCore/wtf/DateMath.cpp
r70427 r72884 380 380 } 381 381 382 staticint32_t calculateUTCOffset()382 int32_t calculateUTCOffset() 383 383 { 384 384 #if PLATFORM(BREWMP) … … 450 450 451 451 // Get the DST offset, given a time in UTC 452 staticdouble calculateDSTOffset(double ms, double utcOffset)452 double calculateDSTOffset(double ms, double utcOffset) 453 453 { 454 454 // On Mac OS X, the call to localtime (see calculateDSTOffsetSimple) will return historically accurate -
trunk/JavaScriptCore/wtf/DateMath.h
r69920 r72884 85 85 int dayInMonthFromDayInYear(int dayInYear, bool leapYear); 86 86 87 // Returns offset milliseconds for UTC and DST. 88 int32_t calculateUTCOffset(); 89 double calculateDSTOffset(double ms, double utcOffset); 90 87 91 } // namespace WTF 88 92 … … 93 97 using WTF::monthFromDayInYear; 94 98 using WTF::msPerDay; 99 using WTF::msPerMinute; 95 100 using WTF::msPerSecond; 96 101 using WTF::msToYear; 97 102 using WTF::secondsPerMinute; 98 103 using WTF::parseDateFromNullTerminatedCharacters; 104 using WTF::calculateUTCOffset; 105 using WTF::calculateDSTOffset; 99 106 100 107 #if USE(JSC) -
trunk/LayoutTests/ChangeLog
r72883 r72884 1 2010-11-29 Dai Mikurube <dmikurube@google.com> 2 3 Reviewed by Kent Tamura. 4 5 when empty, clicking "down" on outer-spin-button returns "max value" 6 https://bugs.webkit.org/show_bug.cgi?id=45491 7 8 * fast/forms/input-stepup-stepdown-from-renderer-expected.txt: Added. 9 * fast/forms/input-stepup-stepdown-from-renderer.html: Added. 10 * fast/forms/script-tests/input-stepup-stepdown-from-renderer.js: Added. 11 (): 12 (setInputAttributes): 13 (stepUp): 14 (stepDown): 15 (stepUpExplicitBounds): 16 (stepDownExplicitBounds): 17 1 18 2010-11-29 Ojan Vafai <ojan@chromium.org> 2 19 -
trunk/WebCore/ChangeLog
r72876 r72884 1 2010-11-29 Dai Mikurube <dmikurube@google.com> 2 3 Reviewed by Kent Tamura. 4 5 when empty, clicking "down" on outer-spin-button returns "max value" 6 https://bugs.webkit.org/show_bug.cgi?id=45491 7 8 Modified stepping-up/down from renderer 9 - to clamp steps, 10 - to handle empty values (described below), and 11 - to apply them for range type inputs. 12 13 Stepping-up/down for empty values are handled "the empty as 0." 14 For example : 15 * If 0 is in-range, and matches to step value 16 "down" -> -step 17 "up" -> +step 18 If -step or +step is out of range, new value should be 0. 19 20 * If 0 is smaller than the minimum value 21 "down" -> the minimum value 22 "up" -> the minimum value 23 24 * If 0 is larger than the maximum value 25 "down" -> the maximum value 26 "up" -> the maximum value 27 28 * If 0 is in-range, but not matched to step value 29 "down" -> smaler matched value nearest to 0. 30 e.g. <input type=number min=-100 step=3> -> -1 31 "up" -> larger matched value nearest to 0. 32 e.g. <input type=number min=-100 step=3> -> 2 33 34 As for date/datetime-local/month/time/week types, the empty is assumed as "current local date/time". 35 As for datetime type, the empty is assumed as "current date/time in UTC". 36 37 As for range input types, changed stepping from renderer to use stepUpFromRenderer(). 38 It was calculated with stepUp() from RangeInputType::handleKeydownEvent(). 39 40 Test: fast/forms/input-stepup-stepdown-from-renderer.html 41 42 * html/BaseDateAndTimeInputType.cpp: 43 (WebCore::BaseDateAndTimeInputType::defaultValueForStepUp): Added defaultValueForStepUp() which returns the current local time 44 * html/BaseDateAndTimeInputType.h: 45 * html/DateTimeInputType.cpp: 46 (WebCore::DateTimeInputType::defaultValueForStepUp): Added defaultValueForStepUp() which returns the current UTC time 47 * html/DateTimeInputType.h: 48 * html/HTMLInputElement.cpp: 49 (WebCore::HTMLInputElement::stepUpFromRenderer): Modified it to clamp steps, support empty values and support range type inputs 50 * html/HTMLInputElement.h: 51 (WebCore::HTMLInputElement::isRangeControl): 52 * html/InputType.cpp: 53 (WebCore::InputType::defaultValueForStepUp): Added defaultValueForStepUp() which returns 0 54 * html/InputType.h: 55 * html/MonthInputType.cpp: 56 (WebCore::MonthInputType::defaultValueForStepUp): Added defaultValueForStepUp() which returns the current local month 57 * html/MonthInputType.h: 58 * html/RangeInputType.cpp: 59 (WebCore::RangeInputType::handleKeydownEvent): Added comments and modified it to use stepUpFromRenderer() 60 * html/TimeInputType.cpp: 61 (WebCore::TimeInputType::defaultValueForStepUp): Added defaultValueForStepUp() which returns the current local time 62 * html/TimeInputType.h: 63 * 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. 64 1 65 2010-11-29 Adam Barth <abarth@webkit.org> 2 66 -
trunk/WebCore/html/BaseDateAndTimeInputType.cpp
r72059 r72884 36 36 #include "HTMLNames.h" 37 37 #include <limits> 38 #include <wtf/CurrentTime.h> 39 #include <wtf/DateMath.h> 38 40 #include <wtf/MathExtras.h> 39 41 #include <wtf/PassOwnPtr.h> … … 90 92 double doubleValue = parseToDouble(value, nan); 91 93 return isfinite(doubleValue) && doubleValue > maximum(); 94 } 95 96 double BaseDateAndTimeInputType::defaultValueForStepUp() const 97 { 98 double ms = currentTimeMS(); 99 double utcOffset = calculateUTCOffset(); 100 double dstOffset = calculateDSTOffset(ms, utcOffset); 101 int offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute); 102 return ms + (offset * msPerMinute); 92 103 } 93 104 -
trunk/WebCore/html/BaseDateAndTimeInputType.h
r72059 r72884 56 56 virtual bool rangeUnderflow(const String&) const; 57 57 virtual bool rangeOverflow(const String&) const; 58 virtual double defaultValueForStepUp() const; 58 59 virtual bool stepMismatch(const String&, double) const; 59 60 virtual double stepBase() const; -
trunk/WebCore/html/DateTimeInputType.cpp
r69378 r72884 35 35 #include "HTMLInputElement.h" 36 36 #include "HTMLNames.h" 37 #include <wtf/CurrentTime.h> 37 38 #include <wtf/PassOwnPtr.h> 38 39 … … 52 53 { 53 54 return InputTypeNames::datetime(); 55 } 56 57 double DateTimeInputType::defaultValueForStepUp() const 58 { 59 return currentTimeMS(); 54 60 } 55 61 -
trunk/WebCore/html/DateTimeInputType.h
r69378 r72884 43 43 DateTimeInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { } 44 44 virtual const AtomicString& formControlType() const; 45 virtual double defaultValueForStepUp() const; 45 46 virtual double minimum() const; 46 47 virtual double maximum() const; -
trunk/WebCore/html/HTMLInputElement.cpp
r72780 r72884 1860 1860 { 1861 1861 // The differences from stepUp()/stepDown(): 1862 // If the current value is not a number, the value will be 1863 // - The value should be the minimum value if n > 0 1864 // - The value should be the maximum value if n < 0 1862 // 1863 // Difference 1: the current value 1864 // If the current value is not a number, including empty, the current value is assumed as 0. 1865 // * If 0 is in-range, and matches to step value 1866 // - The value should be the +step if n > 0 1867 // - The value should be the -step if n < 0 1868 // If -step or +step is out of range, new value should be 0. 1869 // * If 0 is smaller than the minimum value 1870 // - The value should be the minimum value for any n 1871 // * If 0 is larger than the maximum value 1872 // - The value should be the maximum value for any n 1873 // * If 0 is in-range, but not matched to step value 1874 // - The value should be the larger matched value nearest to 0 if n > 0 1875 // e.g. <input type=number min=-100 step=3> -> 2 1876 // - The value should be the smaler matched value nearest to 0 if n < 0 1877 // e.g. <input type=number min=-100 step=3> -> -1 1878 // As for date/datetime-local/month/time/week types, the current value is assumed as "the current local date/time". 1879 // As for datetime type, the current value is assumed as "the current date/time in UTC". 1865 1880 // If the current value is smaller than the minimum value: 1866 1881 // - The value should be the minimum value if n > 0 … … 1869 1884 // - The value should be the maximum value if n < 0 1870 1885 // - Nothing should happen if n > 0 1871 1872 ASSERT(hasSpinButton()); 1873 if (!hasSpinButton()) 1886 // 1887 // Difference 2: clamping steps 1888 // If the current value is not matched to step value: 1889 // - The value should be the larger matched value nearest to 0 if n > 0 1890 // e.g. <input type=number value=3 min=-100 step=3> -> 5 1891 // - The value should be the smaler matched value nearest to 0 if n < 0 1892 // e.g. <input type=number value=3 min=-100 step=3> -> 2 1893 // 1894 // n is assumed as -n if step < 0. 1895 1896 ASSERT(hasSpinButton() || m_inputType->isRangeControl()); 1897 if (!hasSpinButton() && !m_inputType->isRangeControl()) 1874 1898 return; 1875 1899 ASSERT(n); … … 1877 1901 return; 1878 1902 1903 unsigned stepDecimalPlaces, baseDecimalPlaces; 1904 double step, base; 1905 // The value will be the default value after stepping for <input value=(empty/invalid) step="any" /> 1906 // FIXME: Not any changes after stepping, even if it is an invalid value, may be better. 1907 // (e.g. Stepping-up for <input type="number" value="foo" step="any" /> => "foo") 1908 if (equalIgnoringCase(getAttribute(stepAttr), "any")) 1909 step = 0; 1910 else if (!getAllowedValueStepWithDecimalPlaces(&step, &stepDecimalPlaces)) 1911 return; 1912 base = m_inputType->stepBaseWithDecimalPlaces(&baseDecimalPlaces); 1913 baseDecimalPlaces = min(baseDecimalPlaces, 16u); 1914 1915 int sign; 1916 if (step > 0) 1917 sign = n; 1918 else if (step < 0) 1919 sign = -n; 1920 else 1921 sign = 0; 1922 1879 1923 const double nan = numeric_limits<double>::quiet_NaN(); 1880 1924 String currentStringValue = value(); 1881 1925 double current = m_inputType->parseToDouble(currentStringValue, nan); 1882 if (!isfinite(current) || (n > 0 && current < m_inputType->minimum()) || (n < 0 && current > m_inputType->maximum())) 1883 setValue(m_inputType->serialize(n > 0 ? m_inputType->minimum() : m_inputType->maximum())); 1926 if (!isfinite(current)) { 1927 ExceptionCode ec; 1928 current = m_inputType->defaultValueForStepUp(); 1929 setValueAsNumber(current, ec); 1930 } 1931 if ((sign > 0 && current < m_inputType->minimum()) || (sign < 0 && current > m_inputType->maximum())) 1932 setValue(m_inputType->serialize(sign > 0 ? m_inputType->minimum() : m_inputType->maximum())); 1884 1933 else { 1885 1934 ExceptionCode ec; 1886 stepUp(n, ec); 1935 if (stepMismatch(currentStringValue)) { 1936 ASSERT(step); 1937 double newValue; 1938 double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, baseDecimalPlaces))); 1939 1940 if (sign < 0) 1941 newValue = round((base + floor((current - base) / step) * step) * scale) / scale; 1942 else if (sign > 0) 1943 newValue = round((base + ceil((current - base) / step) * step) * scale) / scale; 1944 else 1945 newValue = current; 1946 1947 if (newValue < m_inputType->minimum()) 1948 newValue = m_inputType->minimum(); 1949 if (newValue > m_inputType->maximum()) 1950 newValue = m_inputType->maximum(); 1951 1952 setValueAsNumber(newValue, ec); 1953 current = newValue; 1954 if (n > 1) 1955 applyStep(n - 1, ec); 1956 else if (n < -1) 1957 applyStep(n + 1, ec); 1958 } else 1959 applyStep(n, ec); 1887 1960 } 1888 1961 … … 1890 1963 if (renderer() && renderer()->isTextField()) 1891 1964 toRenderTextControl(renderer())->setChangedSinceLastChangeEvent(true); 1892 dispatchEvent(Event::create(eventNames().inputEvent, true, false)); 1965 if (m_inputType->isRangeControl()) 1966 dispatchFormControlChangeEvent(); 1967 else 1968 dispatchEvent(Event::create(eventNames().inputEvent, true, false)); 1893 1969 } 1894 1970 } -
trunk/WebCore/html/HTMLInputElement.h
r72591 r72884 28 28 #include "HTMLFormElement.h" 29 29 #include "InputElement.h" 30 #include "InputType.h" 30 31 #include <wtf/OwnPtr.h> 31 32 -
trunk/WebCore/html/InputType.cpp
r72363 r72884 126 126 } 127 127 128 bool InputType::isRangeControl() const 129 { 130 return false; 131 } 132 128 133 bool InputType::saveFormControlState(String& result) const 129 134 { … … 214 219 } 215 220 221 double InputType::defaultValueForStepUp() const 222 { 223 return 0; 224 } 225 216 226 double InputType::minimum() const 217 227 { -
trunk/WebCore/html/InputType.h
r72363 r72884 61 61 virtual bool isTextField() const; 62 62 virtual bool isTextType() const; 63 virtual bool isRangeControl() const; 63 64 virtual const AtomicString& formControlType() const = 0; 64 65 … … 90 91 virtual bool rangeUnderflow(const String&) const; 91 92 virtual bool rangeOverflow(const String&) const; 93 virtual double defaultValueForStepUp() const; 92 94 virtual double minimum() const; 93 95 virtual double maximum() const; -
trunk/WebCore/html/MonthInputType.cpp
r69378 r72884 35 35 #include "HTMLInputElement.h" 36 36 #include "HTMLNames.h" 37 #include <wtf/CurrentTime.h> 38 #include <wtf/DateMath.h> 37 39 #include <wtf/MathExtras.h> 38 40 #include <wtf/PassOwnPtr.h> … … 73 75 } 74 76 element()->setValue(date.toString()); 77 } 78 79 double MonthInputType::defaultValueForStepUp() const 80 { 81 double current = currentTimeMS(); 82 double utcOffset = calculateUTCOffset(); 83 double dstOffset = calculateDSTOffset(current, utcOffset); 84 int offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute); 85 current += offset * msPerMinute; 86 87 DateComponents date; 88 date.setMillisecondsSinceEpochForMonth(current); 89 double months = date.monthsSinceEpoch(); 90 ASSERT(isfinite(months)); 91 return months; 75 92 } 76 93 -
trunk/WebCore/html/MonthInputType.h
r69378 r72884 46 46 virtual void setValueAsDate(double, ExceptionCode&) const; 47 47 virtual double parseToDouble(const String&, double) const; 48 virtual double defaultValueForStepUp() const; 48 49 virtual double minimum() const; 49 50 virtual double maximum() const; -
trunk/WebCore/html/RangeInputType.cpp
r72059 r72884 54 54 { 55 55 return adoptPtr(new RangeInputType(element)); 56 } 57 58 bool RangeInputType::isRangeControl() const 59 { 60 return true; 56 61 } 57 62 … … 144 149 double current = parseToDouble(element()->value(), numeric_limits<double>::quiet_NaN()); 145 150 ASSERT(isfinite(current)); 151 // Stepping-up and -down for step="any" are special cases for type="range" from renderer for convenient. 152 // No stepping normally for step="any". They cannot be handled by stepUp()/stepDown()/stepUpFromRenderer(). 153 // So calculating values stepped-up or -down here. 146 154 double newValue; 147 155 if (key == "Up" || key == "Right") { … … 160 168 } else { 161 169 int stepMagnification = (key == "Up" || key == "Right") ? 1 : -1; 162 String lastStringValue = element()->value(); 163 element()->stepUp(stepMagnification, ec); 164 if (lastStringValue != element()->value()) 165 element()->dispatchFormControlChangeEvent(); 170 // Reasonable stepping-up/-down by stepUpFromRenderer() unless step="any" 171 element()->stepUpFromRenderer(stepMagnification); 166 172 } 167 173 event->setDefaultHandled(); -
trunk/WebCore/html/RangeInputType.h
r72059 r72884 42 42 private: 43 43 RangeInputType(HTMLInputElement* element) : InputType(element) { } 44 virtual bool isRangeControl() const; 44 45 virtual const AtomicString& formControlType() const; 45 46 virtual double valueAsNumber() const; -
trunk/WebCore/html/TimeInputType.cpp
r69378 r72884 35 35 #include "HTMLInputElement.h" 36 36 #include "HTMLNames.h" 37 #include <wtf/CurrentTime.h> 38 #include <wtf/DateMath.h> 37 39 #include <wtf/PassOwnPtr.h> 38 40 … … 52 54 { 53 55 return InputTypeNames::time(); 56 } 57 58 double TimeInputType::defaultValueForStepUp() const 59 { 60 double current = currentTimeMS(); 61 double utcOffset = calculateUTCOffset(); 62 double dstOffset = calculateDSTOffset(current, utcOffset); 63 int offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute); 64 current += offset * msPerMinute; 65 66 DateComponents date; 67 date.setMillisecondsSinceMidnight(current); 68 double milliseconds = date.millisecondsSinceEpoch(); 69 ASSERT(isfinite(milliseconds)); 70 return milliseconds; 54 71 } 55 72 -
trunk/WebCore/html/TimeInputType.h
r69378 r72884 43 43 TimeInputType(HTMLInputElement* element) : BaseDateAndTimeInputType(element) { } 44 44 virtual const AtomicString& formControlType() const; 45 virtual double defaultValueForStepUp() const; 45 46 virtual double minimum() const; 46 47 virtual double maximum() const;
Note: See TracChangeset
for help on using the changeset viewer.