Changeset 91549 in webkit


Ignore:
Timestamp:
Jul 21, 2011 8:27:30 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

The input[type="number"] with step="any" should not suffer from step mismatch.
https://bugs.webkit.org/show_bug.cgi?id=64858

Patch by Shinya Kawanaka <shinyak@google.com> on 2011-07-21
Reviewed by Kent Tamura.

Source/WebCore:

Added check step="any" not to suffer from step mismatch.

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::applyStep): Added check step="any".
(WebCore::HTMLInputElement::alignValueForStep): Added.

LayoutTests:

Added test cases of input[type="number"] with step="any"

  • fast/forms/input-stepup-stepdown-expected.txt: added the test cases.
  • fast/forms/input-stepup-stepdown-from-renderer-expected.txt: ditto.
  • fast/forms/script-tests/input-stepup-stepdown-from-renderer.js: ditto.
  • fast/forms/script-tests/input-stepup-stepdown.js: ditto.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r91547 r91549  
     12011-07-21  Shinya Kawanaka  <shinyak@google.com>
     2
     3        The input[type="number"] with step="any" should not suffer from step mismatch.
     4        https://bugs.webkit.org/show_bug.cgi?id=64858
     5
     6        Reviewed by Kent Tamura.
     7
     8        Added test cases of input[type="number"] with step="any"
     9
     10        * fast/forms/input-stepup-stepdown-expected.txt: added the test cases.
     11        * fast/forms/input-stepup-stepdown-from-renderer-expected.txt: ditto.
     12        * fast/forms/script-tests/input-stepup-stepdown-from-renderer.js: ditto.
     13        * fast/forms/script-tests/input-stepup-stepdown.js: ditto.
     14
    1152011-07-21  Robin Qiu  <robin.qiu.dev@gmail.com>
    216
  • trunk/LayoutTests/fast/forms/input-stepup-stepdown-expected.txt

    r72377 r91549  
    140140PASS stepUp("0", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
    141141PASS stepDown("0", "any", null) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
     142Step=any corner case
     143PASS stepUpExplicitBounds("0", "100", "any", "1.5", "1") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
     144PASS stepDownExplicitBounds("0", "100", "any", "1.5", "1") threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
    142145Overflow/underflow
    143146PASS stepDown("1", "1", "0") is "0"
  • trunk/LayoutTests/fast/forms/input-stepup-stepdown-from-renderer-expected.txt

    r90385 r91549  
    117117PASS stepUp("0", "any", null) is "1"
    118118PASS stepDown("0", "any", null) is "-1"
     119Step=any corner case
     120PASS stepUpExplicitBounds("0", "100", "any", "1.5", "1") is "2.5"
     121PASS stepDownExplicitBounds("0", "100", "any", "1.5", "1") is "0.5"
    119122Overflow/underflow
    120123PASS stepDown("1", "1", "0") is "0"
  • trunk/LayoutTests/fast/forms/script-tests/input-stepup-stepdown-from-renderer.js

    r90385 r91549  
    200200shouldBe('stepUp("0", "any", null)', '"1"');
    201201shouldBe('stepDown("0", "any", null)', '"-1"');
     202debug('Step=any corner case');
     203shouldBe('stepUpExplicitBounds("0", "100", "any", "1.5", "1")', '"2.5"');
     204shouldBe('stepDownExplicitBounds("0", "100", "any", "1.5", "1")', '"0.5"');
    202205debug('Overflow/underflow');
    203206shouldBe('stepDown("1", "1", "0")', '"0"');
  • trunk/LayoutTests/fast/forms/script-tests/input-stepup-stepdown.js

    r72377 r91549  
    195195shouldThrow('stepUp("0", "any", null)', invalidStateErr);
    196196shouldThrow('stepDown("0", "any", null)', invalidStateErr);
     197debug('Step=any corner case');
     198shouldThrow('stepUpExplicitBounds("0", "100", "any", "1.5", "1")', invalidStateErr);
     199shouldThrow('stepDownExplicitBounds("0", "100", "any", "1.5", "1")', invalidStateErr);
    197200debug('Overflow/underflow');
    198201shouldBe('stepDown("1", "1", "0")', '"0"');
  • trunk/Source/WebCore/ChangeLog

    r91548 r91549  
     12011-07-21  Shinya Kawanaka  <shinyak@google.com>
     2
     3        The input[type="number"] with step="any" should not suffer from step mismatch.
     4        https://bugs.webkit.org/show_bug.cgi?id=64858
     5
     6        Reviewed by Kent Tamura.
     7
     8        Added check step="any" not to suffer from step mismatch.
     9
     10        * html/HTMLInputElement.cpp:
     11        (WebCore::HTMLInputElement::applyStep): Added check step="any".
     12        (WebCore::HTMLInputElement::alignValueForStep): Added.
     13
    1142011-07-21  MORITA Hajime  <morrita@google.com>
    215
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r91404 r91549  
    416416        return;
    417417    }
     418
    418419    double acceptableError = m_inputType->acceptableError(step);
    419420    if (newValue - m_inputType->minimum() < -acceptableError) {
     
    423424    if (newValue < m_inputType->minimum())
    424425        newValue = m_inputType->minimum();
     426
     427    const AtomicString& stepString = fastGetAttribute(stepAttr);
     428    if (!equalIgnoringCase(stepString, "any"))
     429        newValue = alignValueForStep(newValue, step, currentDecimalPlaces, stepDecimalPlaces);
     430
     431    if (newValue - m_inputType->maximum() > acceptableError) {
     432        ec = INVALID_STATE_ERR;
     433        return;
     434    }
     435    if (newValue > m_inputType->maximum())
     436        newValue = m_inputType->maximum();
     437
     438    setValueAsNumber(newValue, ec);
     439
     440    if (AXObjectCache::accessibilityEnabled())
     441         document()->axObjectCache()->postNotification(renderer(), AXObjectCache::AXValueChanged, true);
     442}
     443
     444double HTMLInputElement::alignValueForStep(double newValue, double step, unsigned currentDecimalPlaces, unsigned stepDecimalPlaces)
     445{
     446    if (newValue >= pow(10.0, 21.0))
     447        return newValue;
     448
    425449    unsigned baseDecimalPlaces;
    426450    double base = m_inputType->stepBaseWithDecimalPlaces(&baseDecimalPlaces);
    427451    baseDecimalPlaces = min(baseDecimalPlaces, 16u);
    428     if (newValue < pow(10.0, 21.0)) {
    429       if (stepMismatch(value())) {
    430             double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, currentDecimalPlaces)));
    431             newValue = round(newValue * scale) / scale;
    432         } else {
    433             double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, baseDecimalPlaces)));
    434             newValue = round((base + round((newValue - base) / step) * step) * scale) / scale;
    435         }
    436     }
    437     if (newValue - m_inputType->maximum() > acceptableError) {
    438         ec = INVALID_STATE_ERR;
    439         return;
    440     }
    441     if (newValue > m_inputType->maximum())
    442         newValue = m_inputType->maximum();
    443     setValueAsNumber(newValue, ec);
    444 
    445     if (AXObjectCache::accessibilityEnabled())
    446          document()->axObjectCache()->postNotification(renderer(), AXObjectCache::AXValueChanged, true);
     452    if (stepMismatch(value())) {
     453        double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, currentDecimalPlaces)));
     454        newValue = round(newValue * scale) / scale;
     455    } else {
     456        double scale = pow(10.0, static_cast<double>(max(stepDecimalPlaces, baseDecimalPlaces)));
     457        newValue = round((base + round((newValue - base) / step) * step) * scale) / scale;
     458    }
     459
     460    return newValue;
    447461}
    448462
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r91404 r91549  
    322322    // Helper for stepUp()/stepDown().  Adds step value * count to the current value.
    323323    void applyStep(double count, AnyStepHandling, ExceptionCode&);
     324    double alignValueForStep(double value, double step, unsigned currentDecimalPlaces, unsigned stepDecimalPlaces);
    324325
    325326#if ENABLE(DATALIST)
Note: See TracChangeset for help on using the changeset viewer.