| Differences between
and this patch
- a/LayoutTests/ChangeLog +17 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2009-10-30  Kent Tamura  <tkent@chromium.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        Add tests for HTMLInputElement::stepUp() and stepDown().
6
        https://bugs.webkit.org/show_bug.cgi?id=27451
7
8
        * fast/forms/input-step-number-expected.txt: Added.
9
        * fast/forms/input-step-number.html: Added.
10
        * fast/forms/input-step-range-expected.txt: Added.
11
        * fast/forms/input-step-range.html: Added.
12
        * fast/forms/input-step-unsupported-expected.txt: Added.
13
        * fast/forms/input-step-unsupported.html: Added.
14
        * fast/forms/script-tests/input-step-number.js: Added.
15
        * fast/forms/script-tests/input-step-range.js: Added.
16
        * fast/forms/script-tests/input-step-unsupported.js: Added.
17
1
2009-10-29  Kent Tamura  <tkent@chromium.org>
18
2009-10-29  Kent Tamura  <tkent@chromium.org>
2
19
3
        Reviewed by NOBODY (OOPS!).
20
        Reviewed by NOBODY (OOPS!).
- a/LayoutTests/fast/forms/input-step-number-expected.txt +46 lines
Line 0 a/LayoutTests/fast/forms/input-step-number-expected.txt_sec1
1
Tests stepDown()/stepUp() for type=number.
2
3
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4
5
6
PASS input.stepDown() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
7
PASS input.stepUp() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
8
PASS input.value is "0"
9
PASS input.value is "0"
10
PASS input.value is "1"
11
PASS input.value is "3"
12
PASS input.value is "2"
13
PASS input.value is "1"
14
PASS input.value is "-1"
15
PASS input.value is "0"
16
PASS input.value is "1"
17
PASS input.value is "2"
18
PASS input.value is "3"
19
PASS input.stepDown() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
20
PASS input.stepUp() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
21
PASS input.value is "0"
22
PASS input.stepDown() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
23
PASS input.stepDown(2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
24
PASS input.value is "1"
25
PASS input.stepDown(2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
26
PASS input.value is "0"
27
PASS input.stepUp() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
28
PASS input.stepUp(2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
29
PASS input.value is "-1"
30
PASS input.stepUp(2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
31
PASS input.value is "3"
32
PASS input.value is "1"
33
PASS input.value is "100"
34
PASS input.value is "10"
35
PASS input.stepUp() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
36
PASS input.value is "1e+308"
37
PASS input.value is "1e+308"
38
PASS input.value is "1"
39
PASS input.value is "2"
40
PASS input.value is "3"
41
PASS input.value is "1"
42
PASS input.value is "0"
43
PASS successfullyParsed is true
44
45
TEST COMPLETE
46
- a/LayoutTests/fast/forms/input-step-number.html +13 lines
Line 0 a/LayoutTests/fast/forms/input-step-number.html_sec1
1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2
<html>
3
<head>
4
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
5
<script src="../../fast/js/resources/js-test-pre.js"></script>
6
</head>
7
<body>
8
<p id="description"></p>
9
<div id="console"></div>
10
<script src="script-tests/input-step-number.js"></script>
11
<script src="../../fast/js/resources/js-test-post.js"></script>
12
</body>
13
</html>
- a/LayoutTests/fast/forms/input-step-range-expected.txt +46 lines
Line 0 a/LayoutTests/fast/forms/input-step-range-expected.txt_sec1
1
Tests stepDown()/stepUp() for type=range.
2
3
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4
5
6
PASS input.stepDown() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
7
PASS input.stepUp() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
8
PASS input.value is "0"
9
PASS input.value is "0"
10
PASS input.value is "1"
11
PASS input.value is "3"
12
PASS input.value is "2"
13
PASS input.value is "1"
14
PASS input.value is "-1"
15
PASS input.value is "0"
16
PASS input.value is "1"
17
PASS input.value is "2"
18
PASS input.value is "3"
19
PASS input.stepDown() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
20
PASS input.stepUp() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
21
PASS input.value is "0"
22
PASS input.stepDown() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
23
PASS input.stepDown(2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
24
PASS input.value is "1"
25
PASS input.stepDown(2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
26
PASS input.value is "0"
27
PASS input.stepUp() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
28
PASS input.stepUp(2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
29
PASS input.value is "-1"
30
PASS input.stepUp(2) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
31
PASS input.value is "3"
32
PASS input.value is "1"
33
PASS input.value is "100"
34
PASS input.value is "10"
35
PASS input.value is "90"
36
PASS input.value is "1e+308"
37
PASS input.value is "1e+308"
38
PASS input.value is "1"
39
PASS input.value is "2"
40
PASS input.value is "3"
41
PASS input.value is "1"
42
PASS input.value is "0"
43
PASS successfullyParsed is true
44
45
TEST COMPLETE
46
- a/LayoutTests/fast/forms/input-step-range.html +13 lines
Line 0 a/LayoutTests/fast/forms/input-step-range.html_sec1
1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2
<html>
3
<head>
4
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
5
<script src="../../fast/js/resources/js-test-pre.js"></script>
6
</head>
7
<body>
8
<p id="description"></p>
9
<div id="console"></div>
10
<script src="script-tests/input-step-range.js"></script>
11
<script src="../../fast/js/resources/js-test-post.js"></script>
12
</body>
13
</html>
- a/LayoutTests/fast/forms/input-step-unsupported-expected.txt +13 lines
Line 0 a/LayoutTests/fast/forms/input-step-unsupported-expected.txt_sec1
1
Tests stepDown()/stepUp() for unsuppoted typpes
2
3
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4
5
6
PASS input.stepDown() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
7
PASS input.stepDown(0) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
8
PASS input.stepUp() threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
9
PASS input.stepUp(0) threw exception Error: INVALID_STATE_ERR: DOM Exception 11.
10
PASS successfullyParsed is true
11
12
TEST COMPLETE
13
- a/LayoutTests/fast/forms/input-step-unsupported.html +13 lines
Line 0 a/LayoutTests/fast/forms/input-step-unsupported.html_sec1
1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2
<html>
3
<head>
4
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
5
<script src="../../fast/js/resources/js-test-pre.js"></script>
6
</head>
7
<body>
8
<p id="description"></p>
9
<div id="console"></div>
10
<script src="script-tests/input-step-unsupported.js"></script>
11
<script src="../../fast/js/resources/js-test-post.js"></script>
12
</body>
13
</html>
- a/LayoutTests/fast/forms/script-tests/input-step-number.js +140 lines
Line 0 a/LayoutTests/fast/forms/script-tests/input-step-number.js_sec1
1
description('Tests stepDown()/stepUp() for type=number.');
2
3
var input = document.createElement('input');
4
input.type = 'number';
5
var invalidStateErr = '"Error: INVALID_STATE_ERR: DOM Exception 11"';
6
7
// The value is unparsable.
8
input.value = '';
9
shouldThrow('input.stepDown()', invalidStateErr);
10
shouldThrow('input.stepUp()', invalidStateErr);
11
12
// Non-number argument
13
input.value = '0';
14
input.stepDown("foo");
15
shouldBe('input.value', '"0"');
16
input.stepUp("foo");
17
shouldBe('input.value', '"0"');
18
19
// Default step value for type=number is 1.
20
input.value = '0';
21
input.stepUp();
22
shouldBe('input.value', '"1"');
23
input.stepUp(2);
24
shouldBe('input.value', '"3"');
25
input.stepUp(-1);
26
shouldBe('input.value', '"2"');
27
input.stepDown();
28
shouldBe('input.value', '"1"');
29
input.stepDown(2);
30
shouldBe('input.value', '"-1"');
31
input.stepDown(-1);
32
shouldBe('input.value', '"0"');
33
// The default value is used for invalid step values.
34
input.value = '0';
35
input.step = 'foo';
36
input.stepUp();
37
shouldBe('input.value', '"1"');
38
input.step = '0';
39
input.stepUp();
40
shouldBe('input.value', '"2"');
41
input.step = '-1';
42
input.stepUp();
43
shouldBe('input.value', '"3"');
44
45
// No step value
46
input.value = '0';
47
input.step = 'any';
48
shouldThrow('input.stepDown()', invalidStateErr);
49
shouldThrow('input.stepUp()', invalidStateErr);
50
51
// Minimum limit
52
input.min = '0';
53
input.step = '1';
54
input.value = '1';
55
input.stepDown();
56
shouldBe('input.value', '"0"');
57
shouldThrow('input.stepDown()', invalidStateErr);
58
input.value = '1';
59
shouldThrow('input.stepDown(2)', invalidStateErr);
60
shouldBe('input.value', '"1"');
61
// Should not be -Infinity.
62
input.value = '1';
63
input.min = '';
64
input.step = '1.7976931348623156e+308';
65
shouldThrow('input.stepDown(2)', invalidStateErr);
66
67
// Maximum limit
68
input.value = '-1';
69
input.min = '';
70
input.max = '0';
71
input.step = '1';
72
input.stepUp();
73
shouldBe('input.value', '"0"');
74
shouldThrow('input.stepUp()', invalidStateErr);
75
input.value = '-1';
76
shouldThrow('input.stepUp(2)', invalidStateErr);
77
shouldBe('input.value', '"-1"');
78
// Should not be Infinity.
79
input.value = '1';
80
input.max = '';
81
input.step = '1.7976931348623156e+308';
82
shouldThrow('input.stepUp(2)', invalidStateErr);
83
84
// stepDown()/stepUp() for stepMismatch values
85
input.value = '0';
86
input.min = '-1';
87
input.step = '2';
88
input.stepUp();
89
shouldBe('input.value', '"3"');
90
input.stepDown();
91
shouldBe('input.value', '"1"');
92
input.value = '9';
93
input.min = '0';
94
input.max = '';
95
input.step = '10';
96
input.stepUp(9);
97
shouldBe('input.value', '"100"');
98
input.value = '19';
99
input.stepDown();
100
shouldBe('input.value', '"10"');
101
// value + step is <= max, but rounded result would be > max.
102
input.value = '89';
103
input.max = '99';
104
shouldThrow('input.stepUp()', invalidStateErr);
105
106
// Huge value and small step
107
input.value = '1e+308';
108
input.min = '';
109
input.max = '';
110
input.step = '1';
111
input.stepUp(999999);
112
shouldBe('input.value', '"1e+308"');
113
input.stepDown(999999);
114
shouldBe('input.value', '"1e+308"');
115
116
// Fractional numbers
117
input.value = '0';
118
input.min = '';
119
input.max = '';
120
input.step = '0.33333333333333333';
121
input.stepUp(3);
122
shouldBe('input.value', '"1"');
123
input.step = '0.1';
124
input.stepUp(10);
125
shouldBe('input.value', '"2"');
126
for (var i = 0; i < 10; i++)
127
    input.stepUp();
128
shouldBe('input.value', '"3"');
129
130
input.value = '0';
131
input.min = '0';
132
input.max = '1';
133
input.step = '0.003921568627450980';
134
input.stepUp(255);
135
shouldBe('input.value', '"1"');
136
for (var i = 0; i < 255; i++)
137
    input.stepDown();
138
shouldBe('input.value', '"0"');
139
140
var successfullyParsed = true;
- a/LayoutTests/fast/forms/script-tests/input-step-range.js +142 lines
Line 0 a/LayoutTests/fast/forms/script-tests/input-step-range.js_sec1
1
description('Tests stepDown()/stepUp() for type=range.');
2
3
var input = document.createElement('input');
4
input.type = 'range';
5
var invalidStateErr = '"Error: INVALID_STATE_ERR: DOM Exception 11"';
6
7
// The value is unparsable.
8
input.value = '';
9
shouldThrow('input.stepDown()', invalidStateErr);
10
shouldThrow('input.stepUp()', invalidStateErr);
11
12
// Non-number argument
13
input.value = '0';
14
input.stepDown("foo");
15
shouldBe('input.value', '"0"');
16
input.stepUp("foo");
17
shouldBe('input.value', '"0"');
18
19
// Default step value for type=range is 1.
20
input.value = '0';
21
input.min = '-100';
22
input.stepUp();
23
shouldBe('input.value', '"1"');
24
input.stepUp(2);
25
shouldBe('input.value', '"3"');
26
input.stepUp(-1);
27
shouldBe('input.value', '"2"');
28
input.stepDown();
29
shouldBe('input.value', '"1"');
30
input.stepDown(2);
31
shouldBe('input.value', '"-1"');
32
input.stepDown(-1);
33
shouldBe('input.value', '"0"');
34
// The default value is used for invalid step values.
35
input.value = '0';
36
input.step = 'foo';
37
input.stepUp();
38
shouldBe('input.value', '"1"');
39
input.step = '0';
40
input.stepUp();
41
shouldBe('input.value', '"2"');
42
input.step = '-1';
43
input.stepUp();
44
shouldBe('input.value', '"3"');
45
46
// No step value
47
input.value = '0';
48
input.step = 'any';
49
shouldThrow('input.stepDown()', invalidStateErr);
50
shouldThrow('input.stepUp()', invalidStateErr);
51
52
// Minimum limit
53
input.min = '0';
54
input.step = '1';
55
input.value = '1';
56
input.stepDown();
57
shouldBe('input.value', '"0"');
58
shouldThrow('input.stepDown()', invalidStateErr);
59
input.value = '1';
60
shouldThrow('input.stepDown(2)', invalidStateErr);
61
shouldBe('input.value', '"1"');
62
// Should not be -Infinity.
63
input.value = '1';
64
input.min = '';
65
input.step = '1.7976931348623156e+308';
66
shouldThrow('input.stepDown(2)', invalidStateErr);
67
68
// Maximum limit
69
input.value = '-1';
70
input.min = '';
71
input.max = '0';
72
input.step = '1';
73
input.stepUp();
74
shouldBe('input.value', '"0"');
75
shouldThrow('input.stepUp()', invalidStateErr);
76
input.value = '-1';
77
shouldThrow('input.stepUp(2)', invalidStateErr);
78
shouldBe('input.value', '"-1"');
79
// Should not be Infinity.
80
input.value = '1';
81
input.max = '';
82
input.step = '1.7976931348623156e+308';
83
shouldThrow('input.stepUp(2)', invalidStateErr);
84
85
// stepDown()/stepUp() for stepMismatch values
86
input.value = '0';
87
input.min = '-1';
88
input.step = '2';
89
input.stepUp();
90
shouldBe('input.value', '"3"');
91
input.stepDown();
92
shouldBe('input.value', '"1"');
93
input.value = '9';
94
input.min = '0';
95
input.max = '';
96
input.step = '10';
97
input.stepUp(9);
98
shouldBe('input.value', '"100"');
99
input.value = '19';
100
input.stepDown();
101
shouldBe('input.value', '"10"');
102
// value + step is <= max, but rounded result would be > max.
103
input.value = '89';
104
input.max = '99';
105
input.stepUp();
106
shouldBe('input.value', '"90"');
107
108
// Huge value and small step
109
input.value = '1e+308';
110
input.min = '0';
111
input.max = '1.1e+308';
112
input.step = '1';
113
input.stepUp(999999);
114
shouldBe('input.value', '"1e+308"');
115
input.stepDown(999999);
116
shouldBe('input.value', '"1e+308"');
117
118
// Fractional numbers
119
input.value = '0';
120
input.min = '';
121
input.max = '';
122
input.step = '0.33333333333333333';
123
input.stepUp(3);
124
shouldBe('input.value', '"1"');
125
input.step = '0.1';
126
input.stepUp(10);
127
shouldBe('input.value', '"2"');
128
for (var i = 0; i < 10; i++)
129
    input.stepUp();
130
shouldBe('input.value', '"3"');
131
132
input.value = '0';
133
input.min = '0';
134
input.max = '1';
135
input.step = '0.003921568627450980';
136
input.stepUp(255);
137
shouldBe('input.value', '"1"');
138
for (var i = 0; i < 255; i++)
139
    input.stepDown();
140
shouldBe('input.value', '"0"');
141
142
var successfullyParsed = true;
- a/LayoutTests/fast/forms/script-tests/input-step-unsupported.js +12 lines
Line 0 a/LayoutTests/fast/forms/script-tests/input-step-unsupported.js_sec1
1
description('Tests stepDown()/stepUp() for unsuppoted typpes');
2
3
var input = document.createElement('input');
4
input.type = 'text';
5
input.step = '3';
6
input.value = '2';
7
shouldThrow('input.stepDown()', '"Error: INVALID_STATE_ERR: DOM Exception 11"');
8
shouldThrow('input.stepDown(0)', '"Error: INVALID_STATE_ERR: DOM Exception 11"');
9
shouldThrow('input.stepUp()', '"Error: INVALID_STATE_ERR: DOM Exception 11"');
10
shouldThrow('input.stepUp(0)', '"Error: INVALID_STATE_ERR: DOM Exception 11"');
11
12
var successfullyParsed = true;
- a/WebCore/ChangeLog +26 lines
Lines 1-3 a/WebCore/ChangeLog_sec1
1
2009-10-30  Kent Tamura  <tkent@chromium.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        Add support for HTMLInputElement::stepUp() and stepDown().
6
        https://bugs.webkit.org/show_bug.cgi?id=27451
7
8
        Tests: fast/forms/input-step-number.html
9
               fast/forms/input-step-range.html
10
               fast/forms/input-step-unsupported.html
11
12
        * bindings/js/JSHTMLInputElementCustom.cpp:
13
        (WebCore::JSHTMLInputElement::stepUp):
14
        (WebCore::JSHTMLInputElement::stepDown):
15
        * bindings/v8/custom/V8CustomBinding.h:
16
        * bindings/v8/custom/V8HTMLInputElementCustom.cpp:
17
        (WebCore::V8Custom::v8HTMLInputElementStepUpCallback):
18
        (WebCore::V8Custom::v8HTMLInputElementStepDownCallback):
19
        * html/HTMLInputElement.cpp:
20
        (WebCore::HTMLInputElement::addForNumber):
21
        (WebCore::HTMLInputElement::stepUp):
22
        (WebCore::HTMLInputElement::stepDown):
23
        (WebCore::HTMLInputElement::doubleToFormString):
24
        * html/HTMLInputElement.h:
25
        * html/HTMLInputElement.idl:
26
1
2009-10-28  Kent Tamura  <tkent@chromium.org>
27
2009-10-28  Kent Tamura  <tkent@chromium.org>
2
28
3
        Reviewed by NOBODY (OOPS!).
29
        Reviewed by NOBODY (OOPS!).
- a/WebCore/bindings/js/JSHTMLInputElementCustom.cpp +34 lines
Lines 116-119 JSValue JSHTMLInputElement::setSelectionRange(ExecState* exec, const ArgList& ar a/WebCore/bindings/js/JSHTMLInputElementCustom.cpp_sec1
116
    return jsUndefined();
116
    return jsUndefined();
117
}
117
}
118
118
119
JSValue JSHTMLInputElement::stepUp(ExecState* exec, const ArgList& args)
120
{
121
    HTMLInputElement* input = static_cast<HTMLInputElement*>(impl());
122
    ExceptionCode ec = 0;
123
    int step;
124
    if (args.size() < 1)
125
        input->stepUp(1, ec);
126
    else {
127
        step = args.at(0).toInt32(exec);
128
        if (exec->hadException())
129
            return jsUndefined();
130
        input->stepUp(step, ec);
131
    }
132
    setDOMException(exec, ec);
133
    return jsUndefined();
134
}
135
136
JSValue JSHTMLInputElement::stepDown(ExecState* exec, const ArgList& args)
137
{
138
    HTMLInputElement* input = static_cast<HTMLInputElement*>(impl());
139
    ExceptionCode ec = 0;
140
    int step;
141
    if (args.size() < 1)
142
        input->stepDown(1, ec);
143
    else {
144
        step = args.at(0).toInt32(exec);
145
        if (exec->hadException())
146
            return jsUndefined();
147
        input->stepDown(step, ec);
148
    }
149
    setDOMException(exec, ec);
150
    return jsUndefined();
151
}
152
119
} // namespace WebCore
153
} // namespace WebCore
- a/WebCore/bindings/v8/custom/V8CustomBinding.h -1 / +2 lines
Lines 283-291 namespace WebCore { a/WebCore/bindings/v8/custom/V8CustomBinding.h_sec1
283
        DECLARE_PROPERTY_ACCESSOR(HTMLOptionsCollectionLength);
283
        DECLARE_PROPERTY_ACCESSOR(HTMLOptionsCollectionLength);
284
284
285
        DECLARE_CALLBACK(HTMLInputElementSetSelectionRange);
285
        DECLARE_CALLBACK(HTMLInputElementSetSelectionRange);
286
287
        DECLARE_PROPERTY_ACCESSOR(HTMLInputElementSelectionStart);
286
        DECLARE_PROPERTY_ACCESSOR(HTMLInputElementSelectionStart);
288
        DECLARE_PROPERTY_ACCESSOR(HTMLInputElementSelectionEnd);
287
        DECLARE_PROPERTY_ACCESSOR(HTMLInputElementSelectionEnd);
288
        DECLARE_CALLBACK(HTMLInputElementStepUp);
289
        DECLARE_CALLBACK(HTMLInputElementStepDown);
289
290
290
        DECLARE_NAMED_ACCESS_CHECK(Location);
291
        DECLARE_NAMED_ACCESS_CHECK(Location);
291
        DECLARE_INDEXED_ACCESS_CHECK(History);
292
        DECLARE_INDEXED_ACCESS_CHECK(History);
- a/WebCore/bindings/v8/custom/V8HTMLInputElementCustom.cpp +40 lines
Lines 106-109 CALLBACK_FUNC_DECL(HTMLInputElementSetSelectionRange) a/WebCore/bindings/v8/custom/V8HTMLInputElementCustom.cpp_sec1
106
    return v8::Undefined();
106
    return v8::Undefined();
107
}
107
}
108
108
109
CALLBACK_FUNC_DECL(HTMLInputElementStepUp)
110
{
111
    INC_STATS("DOM.HTMLInputElement.stepUp");
112
    v8::Handle<v8::Object> holder = args.Holder();
113
    HTMLInputElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLInputElement>(holder);
114
    ExceptionCode ec = 0;
115
    if (args.Length() < 1)
116
        imp->stepUp(1, ec);
117
    else {
118
        v8::TryCatch try_catch;
119
        int step = toInt32(args[0]);
120
        if (try_catch.HasCaught())
121
            return v8::Undefined();
122
        imp->stepUp(step, ec);
123
    }
124
    if (ec)
125
        V8Proxy::setDOMException(ec);
126
    return v8::Undefined();
127
}
128
129
CALLBACK_FUNC_DECL(HTMLInputElementStepDown)
130
{
131
    INC_STATS("DOM.HTMLInputElement.stepDown");
132
    v8::Handle<v8::Object> holder = args.Holder();
133
    HTMLInputElement* imp = V8DOMWrapper::convertDOMWrapperToNode<HTMLInputElement>(holder);
134
    ExceptionCode ec = 0;
135
    if (args.Length() < 1)
136
        imp->stepDown(1, ec);
137
    else {
138
        v8::TryCatch try_catch;
139
        int step = toInt32(args[0]);
140
        if (try_catch.HasCaught())
141
            return v8::Undefined();
142
        imp->stepDown(step, ec);
143
    }
144
    if (ec)
145
        V8Proxy::setDOMException(ec);
146
    return v8::Undefined();
147
}
148
109
} // namespace WebCore
149
} // namespace WebCore
- a/WebCore/html/HTMLInputElement.cpp +81 lines
Lines 62-67 a/WebCore/html/HTMLInputElement.cpp_sec1
62
#include "TextEvent.h"
62
#include "TextEvent.h"
63
#include <wtf/MathExtras.h>
63
#include <wtf/MathExtras.h>
64
#include <wtf/StdLibExtras.h>
64
#include <wtf/StdLibExtras.h>
65
#include <wtf/dtoa.h>
65
66
66
using namespace std;
67
using namespace std;
67
68
Lines 362-367 bool HTMLInputElement::allowedValueStep(double* step) const a/WebCore/html/HTMLInputElement.cpp_sec2
362
    return true;
363
    return true;
363
}
364
}
364
365
366
void HTMLInputElement::addForNumber(double step, double count, ExceptionCode& ec)
367
{
368
    ASSERT(inputType() == NUMBER || inputType() == RANGE);
369
    ASSERT(step > 0);
370
    double current = 0.0;
371
    if (!formStringToDouble(value(), &current)) {
372
        ec = INVALID_STATE_ERR;
373
        return;
374
    }
375
    double newValue = current + step * count;
376
    if (isinf(newValue)) {
377
        ec = INVALID_STATE_ERR;
378
        return;
379
    }
380
    if (inputType() == NUMBER) {
381
        double minimum = 0.0;
382
        if (formStringToDouble(getAttribute(minAttr), &minimum)) {
383
            if (newValue < minimum) {
384
                ec = INVALID_STATE_ERR;
385
                return;
386
            }
387
        }
388
        double n = rint((newValue - minimum) / step);
389
        newValue = minimum + n * step;
390
        double maximum = 0.0;
391
        if (formStringToDouble(getAttribute(maxAttr), &maximum)) {
392
            if (newValue > maximum) {
393
                ec = INVALID_STATE_ERR;
394
                return;
395
            }
396
        }
397
    } else {  // inputType() == RANGE
398
        double minimum = rangeMinimum();
399
        double maximum = rangeMaximum();
400
        if (newValue < minimum || newValue > maximum) {
401
            ec = INVALID_STATE_ERR;
402
            return;
403
        }
404
        double n = rint((newValue - minimum) / step);
405
        newValue = minimum + n * step;
406
        if (newValue > maximum)
407
            newValue = minimum + (n - 1) * step;
408
        ASSERT(newValue >= minimum);
409
        ASSERT(newValue <= maximum);
410
    }
411
    setValue(doubleToFormString(newValue));
412
}
413
414
void HTMLInputElement::stepUp(int n, ExceptionCode& ec)
415
{
416
    double step = 0.0;
417
    if (!allowedValueStep(&step)) {
418
        ec = INVALID_STATE_ERR;
419
        return;
420
    }
421
    // Types other than NUMBER/RANGE should be rejected by allowedValueStep().
422
    ASSERT(inputType() == NUMBER || inputType() == RANGE);
423
    addForNumber(step, n, ec);
424
}
425
426
void HTMLInputElement::stepDown(int n, ExceptionCode& ec)
427
{
428
    double step = 0.0;
429
    if (!allowedValueStep(&step)) {
430
        ec = INVALID_STATE_ERR;
431
        return;
432
    }
433
    // Types other than NUMBER/RANGE should be rejected by allowedValueStep().
434
    ASSERT(inputType() == NUMBER || inputType() == RANGE);
435
    addForNumber(step, -n, ec);
436
}
437
365
static inline CheckedRadioButtons& checkedRadioButtons(const HTMLInputElement *element)
438
static inline CheckedRadioButtons& checkedRadioButtons(const HTMLInputElement *element)
366
{
439
{
367
    if (HTMLFormElement* form = element->form())
440
    if (HTMLFormElement* form = element->form())
Lines 1912-1917 bool HTMLInputElement::willValidate() const a/WebCore/html/HTMLInputElement.cpp_sec3
1912
           inputType() != BUTTON && inputType() != RESET;
1985
           inputType() != BUTTON && inputType() != RESET;
1913
}
1986
}
1914
1987
1988
String HTMLInputElement::doubleToFormString(double num)
1989
{
1990
    // According to HTML5, "the best representation of the number n as a floating
1991
    // point number" is a string produced by applying ToString() to n.
1992
    Vector<UChar> uchars = WTF::ecma262dtoa(num);
1993
    return String(uchars.data(), uchars.size());
1994
}
1995
1915
bool HTMLInputElement::formStringToDouble(const String& src, double* out)
1996
bool HTMLInputElement::formStringToDouble(const String& src, double* out)
1916
{
1997
{
1917
    // See HTML5 2.4.4.3 `Real numbers.'
1998
    // See HTML5 2.4.4.3 `Real numbers.'
- a/WebCore/html/HTMLInputElement.h +9 lines
Lines 106-111 public: a/WebCore/html/HTMLInputElement.h_sec1
106
    bool allowedValueStep(double*) const;
106
    bool allowedValueStep(double*) const;
107
    // For ValidityState.
107
    // For ValidityState.
108
    bool stepMismatch() const;
108
    bool stepMismatch() const;
109
    // Implementations of HTMLInputElement::stepUp() and stepDown().
110
    void stepUp(int, ExceptionCode&);
111
    void stepDown(int, ExceptionCode&);
109
112
110
    bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; }
113
    bool isTextButton() const { return m_type == SUBMIT || m_type == RESET || m_type == BUTTON; }
111
    virtual bool isRadioButton() const { return m_type == RADIO; }
114
    virtual bool isRadioButton() const { return m_type == RADIO; }
Lines 262-267 private: a/WebCore/html/HTMLInputElement.h_sec2
262
265
263
    PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex();
266
    PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex();
264
267
268
    // Helper for stepUp()/stepDown().  Adds step * count to the current number value.
269
    void addForNumber(double step, double count, ExceptionCode&);
270
    // Converts the specified number to a string.  This is an implementation of
271
    // HTML5's "algorithm to convert a number to a string" for NUMBER/RANGE types.
272
    static String doubleToFormString(double);
273
265
#if ENABLE(DATALIST)
274
#if ENABLE(DATALIST)
266
    HTMLDataListElement* dataList() const;
275
    HTMLDataListElement* dataList() const;
267
#endif
276
#endif
- a/WebCore/html/HTMLInputElement.idl -1 / +5 lines
Lines 71-76 module html { a/WebCore/html/HTMLInputElement.idl_sec1
71
        readonly attribute HTMLOptionElement selectedOption;
71
        readonly attribute HTMLOptionElement selectedOption;
72
#endif
72
#endif
73
73
74
        [Custom] void      stepUp(in [Optional] long n)
75
            raises(DOMException);
76
        [Custom] void      stepDown(in [Optional] long n)
77
            raises(DOMException);
78
74
        readonly attribute boolean         willValidate;
79
        readonly attribute boolean         willValidate;
75
        boolean            checkValidity();
80
        boolean            checkValidity();
76
        void               setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error);
81
        void               setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error);
77
- 

Return to Bug 27451