| Differences between
and this patch
- a/LayoutTests/ChangeLog +28 lines
Lines 1-3 a/LayoutTests/ChangeLog_sec1
1
2009-07-15  Michelangelo De Simone  <micdesim@gmail.com>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        https://bugs.webkit.org/show_bug.cgi?id=25551
6
        Test suite for the required attribute and the valueMissing flag,
7
        part of the HTML5 sec. Forms.
8
        http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#attr-input-required
9
10
        * fast/forms/ValidityState-valueMissing-001-expected.txt: Added.
11
        * fast/forms/ValidityState-valueMissing-001.html: Added.
12
        * fast/forms/ValidityState-valueMissing-002-expected.txt: Added.
13
        * fast/forms/ValidityState-valueMissing-002.html: Added.
14
        * fast/forms/ValidityState-valueMissing-003-expected.txt: Added.
15
        * fast/forms/ValidityState-valueMissing-003.html: Added.
16
        * fast/forms/ValidityState-valueMissing-004-expected.txt: Added.
17
        * fast/forms/ValidityState-valueMissing-004.html: Added.
18
        * fast/forms/ValidityState-valueMissing-005-expected.txt: Added.
19
        * fast/forms/ValidityState-valueMissing-005.html: Added.
20
        * fast/forms/ValidityState-valueMissing-006-expected.txt: Added.
21
        * fast/forms/ValidityState-valueMissing-006.html: Added.
22
        * fast/forms/ValidityState-valueMissing-007-expected.txt: Added.
23
        * fast/forms/ValidityState-valueMissing-007.html: Added.
24
        * fast/forms/required-attribute-001-expected.txt: Added.
25
        * fast/forms/required-attribute-001.html: Added.
26
        * fast/forms/required-attribute-002-expected.txt: Added.
27
        * fast/forms/required-attribute-002.html: Added.
28
1
2009-07-15  Yuzo Fujishima  <yuzo@google.com>
29
2009-07-15  Yuzo Fujishima  <yuzo@google.com>
2
30
3
        Reviewed by Darin Adler.
31
        Reviewed by Darin Adler.
- a/LayoutTests/fast/forms/ValidityState-valueMissing-001-expected.txt +4 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-001-expected.txt_sec1
1
There're two form control elements below, both required and blank: validity.valueMissing should be true in both cases.
2
3
 
4
SUCCESS
- a/LayoutTests/fast/forms/ValidityState-valueMissing-001.html +27 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-001.html_sec1
1
<html>
2
<head>
3
<title>required and basic valueMissing</title>
4
<script language="JavaScript" type="text/javascript">
5
    function log(message) {
6
        document.getElementById("console").innerHTML += "<li>"+message+"</li>";
7
    }
8
9
    function test() {
10
        if (window.layoutTestController)
11
            layoutTestController.dumpAsText();
12
13
        v = document.getElementsByName("victim");
14
15
        log((v[0].validity.valueMissing && v[1].validity.valueMissing) ? "SUCCESS" : "FAILURE");
16
    }
17
</script>
18
</head>
19
<body onload="test()">
20
<p>There're two form control elements below, both required and blank:
21
validity.valueMissing should be true in both cases.</p>
22
<input name="victim" required/>
23
<textarea name="victim" required></textarea>
24
<hr>
25
<ol id="console"></ol>
26
</body>
27
</html>
- a/LayoutTests/fast/forms/ValidityState-valueMissing-002-expected.txt +4 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-002-expected.txt_sec1
1
There're two form control elements below, both required and filled: validity.valueMissing should be false in both cases.
2
3
 
4
SUCCESS
- a/LayoutTests/fast/forms/ValidityState-valueMissing-002.html +27 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-002.html_sec1
1
<html>
2
<head>
3
<title>required and basic valueMissing 2</title>
4
<script language="JavaScript" type="text/javascript">
5
    function log(message) {
6
        document.getElementById("console").innerHTML += "<li>"+message+"</li>";
7
    }
8
9
    function test() {
10
        if (window.layoutTestController)
11
            layoutTestController.dumpAsText();
12
13
        v = document.getElementsByName("victim");
14
15
        log((!v[0].validity.valueMissing && !v[1].validity.valueMissing) ? "SUCCESS" : "FAILURE");
16
    }
17
</script>
18
</head>
19
<body onload="test()">
20
<p>There're two form control elements below, both required and filled:
21
validity.valueMissing should be false in both cases.</p>
22
<input name="victim" value="something" required/>
23
<textarea name="victim" required>something</textarea>
24
<hr>
25
<ol id="console"></ol>
26
</body>
27
</html>
- a/LayoutTests/fast/forms/ValidityState-valueMissing-003-expected.txt +4 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-003-expected.txt_sec1
1
There're two disabled form control elements below, both required and filled: validity.valueMissing should be false in both cases.
2
3
 
4
SUCCESS
- a/LayoutTests/fast/forms/ValidityState-valueMissing-003.html +27 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-003.html_sec1
1
<html>
2
<head>
3
<title>required and valueMissing on disabled elements</title>
4
<script language="JavaScript" type="text/javascript">
5
    function log(message) {
6
        document.getElementById("console").innerHTML += "<li>"+message+"</li>";
7
    }
8
9
    function test() {
10
        if (window.layoutTestController)
11
            layoutTestController.dumpAsText();
12
13
        v = document.getElementsByName("victim");
14
15
        log((!v[0].validity.valueMissing && !v[1].validity.valueMissing) ? "SUCCESS" : "FAILURE");
16
    }
17
</script>
18
</head>
19
<body onload="test()">
20
<p>There're two disabled form control elements below, both required and filled:
21
validity.valueMissing should be false in both cases.</p>
22
<input name="victim" disabled required />
23
<textarea name="victim" disabled required></textarea>
24
<hr>
25
<ol id="console"></ol>
26
</body>
27
</html>
- a/LayoutTests/fast/forms/ValidityState-valueMissing-004-expected.txt +4 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-004-expected.txt_sec1
1
There're two readonly form control elements below, both required and filled: validity.valueMissing should be false in both cases.
2
3
 
4
SUCCESS
- a/LayoutTests/fast/forms/ValidityState-valueMissing-004.html +27 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-004.html_sec1
1
<html>
2
<head>
3
<title>required and valueMissing on readonly elements</title>
4
<script language="JavaScript" type="text/javascript">
5
    function log(message) {
6
        document.getElementById("console").innerHTML += "<li>"+message+"</li>";
7
    }
8
9
    function test() {
10
        if (window.layoutTestController)
11
            layoutTestController.dumpAsText();
12
13
        v = document.getElementsByName("victim");
14
15
        log((!v[0].validity.valueMissing && !v[1].validity.valueMissing) ? "SUCCESS" : "FAILURE");
16
    }
17
</script>
18
</head>
19
<body onload="test()">
20
<p>There're two readonly form control elements below, both required and filled:
21
validity.valueMissing should be false in both cases.</p>
22
<input name="victim" readonly required />
23
<textarea name="victim" readonly required></textarea>
24
<hr>
25
<ol id="console"></ol>
26
</body>
27
</html>
- a/LayoutTests/fast/forms/ValidityState-valueMissing-005-expected.txt +9 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-005-expected.txt_sec1
1
There're plenty of form control elements below, each one of them is unaccepted: validity.valueMissing should be always false.
2
3
    
4
SUCCESS
5
SUCCESS
6
SUCCESS
7
SUCCESS
8
SUCCESS
9
SUCCESS
- a/LayoutTests/fast/forms/ValidityState-valueMissing-005.html +32 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-005.html_sec1
1
<html>
2
<head>
3
<title>required and valueMissing on unaccepted input types</title>
4
<script language="JavaScript" type="text/javascript">
5
    function log(message) {
6
        document.getElementById("console").innerHTML += "<li>"+message+"</li>";
7
    }
8
9
    function test() {
10
        if (window.layoutTestController)
11
            layoutTestController.dumpAsText();
12
13
        v = document.getElementsByName("victim");
14
15
        for (i = 0; i < v.length; i++)
16
            log(!v[i].validity.valueMissing ? "SUCCESS" : "FAILURE");
17
    }
18
</script>
19
</head>
20
<body onload="test()">
21
<p>There're plenty of form control elements below, each one of them is unaccepted:
22
validity.valueMissing should be always false.</p>
23
<input name="victim" type="hidden" required />
24
<input name="victim" type="range" required />
25
<input name="victim" type="image" required />
26
<input name="victim" type="reset" required />
27
<input name="victim" type="button" required />
28
<input name="victim" type="submit" required />
29
<hr>
30
<ol id="console"></ol>
31
</body>
32
</html>
- a/LayoutTests/fast/forms/ValidityState-valueMissing-006-expected.txt +4 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-006-expected.txt_sec1
1
There're two checkboxes below, both are required, only one is checked.
2
3
 
4
SUCCESS
- a/LayoutTests/fast/forms/ValidityState-valueMissing-006.html +26 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-006.html_sec1
1
<html>
2
<head>
3
<title>required and valueMissing on checkboxes</title>
4
<script language="JavaScript" type="text/javascript">
5
    function log(message) {
6
        document.getElementById("console").innerHTML += "<li>"+message+"</li>";
7
    }
8
9
    function test() {
10
        if (window.layoutTestController)
11
            layoutTestController.dumpAsText();
12
13
        v = document.getElementsByName("victim");
14
15
        log(!v[0].validity.valueMissing && v[1].validity.valueMissing ? "SUCCESS" : "FAILURE");
16
    }
17
</script>
18
</head>
19
<body onload="test()">
20
<p>There're two checkboxes below, both are required, only one is checked.</p>
21
<input name="victim" type="checkbox" required checked/>
22
<input name="victim" type="checkbox" required />
23
<hr>
24
<ol id="console"></ol>
25
</body>
26
</html>
- a/LayoutTests/fast/forms/ValidityState-valueMissing-007-expected.txt +4 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-007-expected.txt_sec1
1
There're two radio buttons below with the same name, only one is required, the other one is checked.
2
3
 
4
SUCCESS
- a/LayoutTests/fast/forms/ValidityState-valueMissing-007.html +27 lines
Line 0 a/LayoutTests/fast/forms/ValidityState-valueMissing-007.html_sec1
1
<html>
2
<head>
3
<title>required and valueMissing on radio</title>
4
<script language="JavaScript" type="text/javascript">
5
    function log(message) {
6
        document.getElementById("console").innerHTML += "<li>"+message+"</li>";
7
    }
8
9
    function test() {
10
        if (window.layoutTestController)
11
            layoutTestController.dumpAsText();
12
13
        v = document.getElementsByName("victim");
14
15
        log(!v[0].validity.valueMissing ? "SUCCESS" : "FAILURE");
16
    }
17
</script>
18
</head>
19
<body onload="test()">
20
<p>There're two radio buttons below with the same name, only one is required, 
21
the other one is checked.</p>
22
<input name="victim" type="radio" required/>
23
<input name="victim" type="radio" checked/>
24
<hr>
25
<ol id="console"></ol>
26
</body>
27
</html>
- a/LayoutTests/fast/forms/required-attribute-001-expected.txt +4 lines
Line 0 a/LayoutTests/fast/forms/required-attribute-001-expected.txt_sec1
1
There're two form control elements below, both required.
2
3
 
4
SUCCESS
- a/LayoutTests/fast/forms/required-attribute-001.html +26 lines
Line 0 a/LayoutTests/fast/forms/required-attribute-001.html_sec1
1
<html>
2
<head>
3
<title>required attribute presence test</title>
4
<script language="JavaScript" type="text/javascript">
5
    function log(message) {
6
        document.getElementById("console").innerHTML += "<li>"+message+"</li>";
7
    }
8
9
    function test() {
10
        if (window.layoutTestController)
11
            layoutTestController.dumpAsText();
12
13
        v = document.getElementsByName("victim");
14
15
        log((v[0].required && v[1].required) ? "SUCCESS" : "FAILURE");
16
    }
17
</script>
18
</head>
19
<body onload="test()">
20
<p>There're two form control elements below, both required.</p>
21
<input name="victim" required />
22
<textarea name="victim" required></textarea>
23
<hr>
24
<ol id="console"></ol>
25
</body>
26
</html>
- a/LayoutTests/fast/forms/required-attribute-002-expected.txt +4 lines
Line 0 a/LayoutTests/fast/forms/required-attribute-002-expected.txt_sec1
1
There're two form control elements below, both optional. Once loaded they're set as required.
2
3
 
4
SUCCESS
- a/LayoutTests/fast/forms/required-attribute-002.html +33 lines
Line 0 a/LayoutTests/fast/forms/required-attribute-002.html_sec1
1
<html>
2
<head>
3
<title>required attribute JS set</title>
4
<script language="JavaScript" type="text/javascript">
5
    function log(message) {
6
        document.getElementById("console").innerHTML += "<li>"+message+"</li>";
7
    }
8
9
    function test() {
10
        if (window.layoutTestController)
11
            layoutTestController.dumpAsText();
12
13
        v = document.getElementsByName("victim");
14
15
        if (v[0].required == false && v[1].required == false) {
16
            v[0].required = true;
17
            v[1].required = true;
18
            log ((v[0].required && v[1].required) ? "SUCCESS" : "FAILURE");
19
        }
20
        else
21
            log("FAILURE");
22
    }
23
</script>
24
</head>
25
<body onload="test()">
26
<p>There're two form control elements below, both optional. Once loaded they're
27
set as required.</p>
28
<input name="victim" />
29
<textarea name="victim"></textarea>
30
<hr>
31
<ol id="console"></ol>
32
</body>
33
</html>
- a/WebCore/ChangeLog +33 lines
Lines 1-3 a/WebCore/ChangeLog_sec1
1
2009-07-15  Michelangelo De Simone  <micdesim@gmail.com>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        https://bugs.webkit.org/show_bug.cgi?id=25551
6
        Added support for the "required" attribute and the valueMissing flag
7
        to the ValidityState object, both part of HTML5 sec. Forms specs.
8
        http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#attr-input-required
9
10
        Tests: fast/forms/ValidityState-valueMissing-001.html
11
               fast/forms/ValidityState-valueMissing-002.html
12
               fast/forms/ValidityState-valueMissing-003.html
13
               fast/forms/ValidityState-valueMissing-004.html
14
               fast/forms/ValidityState-valueMissing-005.html
15
               fast/forms/ValidityState-valueMissing-006.html
16
               fast/forms/ValidityState-valueMissing-007.html
17
               fast/forms/required-attribute-001.html
18
               fast/forms/required-attribute-002.html
19
20
        * html/HTMLAttributeNames.in: added required attribute
21
        * html/HTMLFormControlElement.cpp:
22
        (WebCore::HTMLFormControlElement::required): requiredAttr getter
23
        (WebCore::HTMLFormControlElement::setRequired): requiredAttr setter
24
        * html/HTMLFormControlElement.h: requiredAttr get/setter definition
25
        * html/HTMLInputElement.idl: required attribute
26
        * html/HTMLTextAreaElement.idl: required attribute
27
        * html/ValidityState.cpp:
28
        (WebCore::ValidityState::isControlRequired): checks to determine
29
        whether or not honour required attribute
30
        (WebCore::ValidityState::valueMissing): checks to determine whether or
31
        not the control suffers from being missed
32
        * html/ValidityState.h: method definitions
33
1
2009-07-15  Yuzo Fujishima  <yuzo@google.com>
34
2009-07-15  Yuzo Fujishima  <yuzo@google.com>
2
35
3
        Reviewed by Darin Adler.
36
        Reviewed by Darin Adler.
- a/WebCore/html/HTMLAttributeNames.in +1 lines
Lines 195-200 progress a/WebCore/html/HTMLAttributeNames.in_sec1
195
prompt
195
prompt
196
readonly
196
readonly
197
rel
197
rel
198
required
198
results
199
results
199
rev
200
rev
200
role
201
role
- a/WebCore/html/HTMLFormControlElement.cpp +10 lines
Lines 204-209 void HTMLFormControlElement::setAutofocus(bool b) a/WebCore/html/HTMLFormControlElement.cpp_sec1
204
    setAttribute(autofocusAttr, b ? "autofocus" : 0);
204
    setAttribute(autofocusAttr, b ? "autofocus" : 0);
205
}
205
}
206
206
207
bool HTMLFormControlElement::required() const
208
{
209
    return hasAttribute(requiredAttr);
210
}
211
212
void HTMLFormControlElement::setRequired(bool b)
213
{
214
    setAttribute(requiredAttr, b ? "required" : 0);
215
}
216
207
void HTMLFormControlElement::recalcStyle(StyleChange change)
217
void HTMLFormControlElement::recalcStyle(StyleChange change)
208
{
218
{
209
    HTMLElement::recalcStyle(change);
219
    HTMLElement::recalcStyle(change);
- a/WebCore/html/HTMLFormControlElement.h +3 lines
Lines 74-79 public: a/WebCore/html/HTMLFormControlElement.h_sec1
74
    virtual bool autofocus() const;
74
    virtual bool autofocus() const;
75
    void setAutofocus(bool);
75
    void setAutofocus(bool);
76
76
77
    virtual bool required() const;
78
    void setRequired(bool);
79
77
    virtual void recalcStyle(StyleChange);
80
    virtual void recalcStyle(StyleChange);
78
81
79
    virtual const AtomicString& formControlName() const;
82
    virtual const AtomicString& formControlName() const;
- a/WebCore/html/HTMLInputElement.idl +1 lines
Lines 43-48 module html { a/WebCore/html/HTMLInputElement.idl_sec1
43
                 attribute [ConvertNullToNullString] DOMString name;
43
                 attribute [ConvertNullToNullString] DOMString name;
44
                 attribute DOMString       placeholder;
44
                 attribute DOMString       placeholder;
45
                 attribute boolean         readOnly;
45
                 attribute boolean         readOnly;
46
                 attribute boolean         required;
46
#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C
47
#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C
47
                 attribute [ConvertToString] DOMString size; // DOM level 2 changed this to a long, but our existing API is a string
48
                 attribute [ConvertToString] DOMString size; // DOM level 2 changed this to a long, but our existing API is a string
48
#else
49
#else
- a/WebCore/html/HTMLTextAreaElement.idl +1 lines
Lines 36-41 module html { a/WebCore/html/HTMLTextAreaElement.idl_sec1
36
                 attribute  boolean              autofocus;
36
                 attribute  boolean              autofocus;
37
                 attribute  [ConvertNullToNullString] DOMString            name;
37
                 attribute  [ConvertNullToNullString] DOMString            name;
38
                 attribute  boolean              readOnly;
38
                 attribute  boolean              readOnly;
39
                 attribute  boolean              required;
39
                 attribute  long                 rows;
40
                 attribute  long                 rows;
40
        readonly attribute  DOMString            type;
41
        readonly attribute  DOMString            type;
41
                 attribute  [ConvertNullToNullString] DOMString            value;
42
                 attribute  [ConvertNullToNullString] DOMString            value;
- a/WebCore/html/ValidityState.cpp +71 lines
Lines 22-37 a/WebCore/html/ValidityState.cpp_sec1
22
22
23
#include "config.h"
23
#include "config.h"
24
#include "ValidityState.h"
24
#include "ValidityState.h"
25
#include "Document.h"
25
#include "HTMLFormControlElement.h"
26
#include "HTMLFormControlElement.h"
27
#include "HTMLInputElement.h"
28
#include "HTMLNames.h"
29
#include "HTMLTextAreaElement.h"
26
30
27
namespace WebCore {
31
namespace WebCore {
28
32
33
using namespace HTMLNames;
34
29
ValidityState::ValidityState(HTMLFormControlElement* parent)
35
ValidityState::ValidityState(HTMLFormControlElement* parent)
30
    : m_control(parent)
36
    : m_control(parent)
31
{
37
{
32
    ASSERT(parent);
38
    ASSERT(parent);
33
}
39
}
34
40
41
bool ValidityState::isControlRequired()
42
{
43
    if (!control()->required())
44
        return false;
45
46
    if (control()->hasTagName(inputTag)) {
47
        HTMLInputElement* input = static_cast<HTMLInputElement*>(control());
48
49
        if (input->disabled() || input->readOnly())
50
            return false;
51
52
        switch (input->inputType()) {
53
            case HTMLInputElement::HIDDEN:
54
            case HTMLInputElement::RANGE:
55
            case HTMLInputElement::SUBMIT:
56
            case HTMLInputElement::IMAGE:
57
            case HTMLInputElement::RESET:
58
            case HTMLInputElement::BUTTON:
59
                return false;
60
            default:
61
                return true;
62
        }
63
    }
64
65
    if (control()->hasTagName(textareaTag)) {
66
        HTMLTextAreaElement* textarea = static_cast<HTMLTextAreaElement*>(control());
67
68
        return !textarea->disabled() && !textarea->readOnly();
69
    }
70
71
    return false;
72
}
73
74
bool ValidityState::valueMissing()
75
{
76
    if (!isControlRequired())
77
        return false;
78
79
    if (control()->hasTagName(inputTag)) {
80
        HTMLInputElement* input = static_cast<HTMLInputElement*>(control());
81
82
        switch (input->inputType()) {
83
            case HTMLInputElement::TEXT:
84
            case HTMLInputElement::SEARCH:
85
            case HTMLInputElement::URL:
86
            case HTMLInputElement::TELEPHONE:
87
            case HTMLInputElement::EMAIL:
88
            case HTMLInputElement::PASSWORD:
89
            case HTMLInputElement::NUMBER:
90
                return input->value().isEmpty();
91
            case HTMLInputElement::CHECKBOX:
92
                return !input->checked();
93
            case HTMLInputElement::RADIO:
94
                return !input->document()->checkedRadioButtons().checkedButtonForGroup(input->name());
95
            default:
96
                return false;
97
        }
98
    }
99
100
    if (control()->hasTagName(textareaTag))
101
        return static_cast<HTMLTextAreaElement*>(control())->value().isEmpty();
102
103
    return false;
104
}
105
35
bool ValidityState::valid()
106
bool ValidityState::valid()
36
{
107
{
37
    bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() ||
108
    bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() ||
- a/WebCore/html/ValidityState.h -1 / +5 lines
Lines 39-45 namespace WebCore { a/WebCore/html/ValidityState.h_sec1
39
39
40
        HTMLFormControlElement* control() const { return m_control; }
40
        HTMLFormControlElement* control() const { return m_control; }
41
41
42
        bool valueMissing() { return false; }
42
        // Checks if the control has to honour its required attribute,
43
        // if present.
44
        bool isControlRequired();
45
46
        bool valueMissing();
43
        bool typeMismatch() { return false; }
47
        bool typeMismatch() { return false; }
44
        bool patternMismatch() { return false; }
48
        bool patternMismatch() { return false; }
45
        bool tooLong() { return false; }
49
        bool tooLong() { return false; }

Return to Bug 25551