Commit 08b2ce18 authored by pkasting@chromium.org's avatar pkasting@chromium.org

WebCore: https://bugs.webkit.org/show_bug.cgi?id=27458

Support for the :default CSS pseudoclass, as per HTML5 spec.
http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#selector-default

Patch by Michelangelo De Simone <micdesim@gmail.com> on 2009-08-12
Reviewed by Darin Adler.

Tests: fast/css/pseudo-default-001.html
       fast/css/pseudo-default-002.html
       fast/css/pseudo-default-003.html
       fast/css/pseudo-default-004.html

* css/CSSSelector.cpp:
(WebCore::CSSSelector::extractPseudoType): pseudoDefault
* css/CSSSelector.h:
(WebCore::CSSSelector::):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::canShareStyleWithElement): sharing stuff is
aware that only one default button can be present in a form
(WebCore::CSSStyleSelector::SelectorChecker::checkOneSelector): applies
the :default CSS pseudoclass
* dom/Element.h:
(WebCore::Element::isDefaultButtonForForm): new method to determine
whether a FormControl is a default button for a given form
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::isDefaultButtonForForm): ditto
* html/HTMLFormControlElement.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::defaultButton): extracts the default button
from the form
* html/HTMLFormElement.h:

LayoutTests: https://bugs.webkit.org/show_bug.cgi?id=27458
Test suite for the :default CSS pseudoclass.

Patch by Michelangelo De Simone <micdesim@gmail.com> on 2009-08-12
Reviewed by Darin Adler.

* fast/css/pseudo-default-001-expected.txt: Added.
* fast/css/pseudo-default-001.html: Added.
* fast/css/pseudo-default-002-expected.txt: Added.
* fast/css/pseudo-default-002.html: Added.
* fast/css/pseudo-default-003-expected.txt: Added.
* fast/css/pseudo-default-003.html: Added.
* fast/css/pseudo-default-004-expected.txt: Added.
* fast/css/pseudo-default-004.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@47155 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f189b702
2009-08-12 Michelangelo De Simone <micdesim@gmail.com>
Reviewed by Darin Adler.
https://bugs.webkit.org/show_bug.cgi?id=27458
Test suite for the :default CSS pseudoclass.
* fast/css/pseudo-default-001-expected.txt: Added.
* fast/css/pseudo-default-001.html: Added.
* fast/css/pseudo-default-002-expected.txt: Added.
* fast/css/pseudo-default-002.html: Added.
* fast/css/pseudo-default-003-expected.txt: Added.
* fast/css/pseudo-default-003.html: Added.
* fast/css/pseudo-default-004-expected.txt: Added.
* fast/css/pseudo-default-004.html: Added.
2009-08-12 Eric Seidel <eric@webkit.org>
No review, just fixing line-endings.
......
This test performs a simple check for the :default CSS selector.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color') is 'rgb(0, 255, 0)'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
<style>
input:default { background: lime; }
button:default { background: lime; }
input { background: red; }
button { background: red; }
</style>
</head>
<body>
<p id="description"></p>
<form method="get">
<input name="victim" type="submit" value="Submit" />
</form>
<div id="console"></div>
<script>
description("This test performs a simple check for the :default CSS selector.");
v = document.getElementsByName("victim");
for (i = 0; i < v.length; i++)
shouldBe("document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color')", "'rgb(0, 255, 0)'");
var successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
This test performs a check for the :default CSS selector on multiple submit buttons.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Submit
PASS document.defaultView.getComputedStyle(v[0], null).getPropertyValue('background-color') is 'rgb(0, 255, 0)'
PASS document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color') is 'rgb(255, 0, 0)'
PASS document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color') is 'rgb(255, 0, 0)'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
<style>
input { background: red; }
button { background: red; }
:default { background: lime; }
</style>
</head>
<body>
<p id="description"></p>
<form method="get">
<input name="victim" type="submit" value="Submit" />
<input name="victim" type="submit" value="Submit"/>
<button name="victim" type="submit"/>Submit</button>
</form>
<div id="console"></div>
<script>
description("This test performs a check for the :default CSS selector on multiple submit buttons.");
v = document.getElementsByName("victim");
shouldBe("document.defaultView.getComputedStyle(v[0], null).getPropertyValue('background-color')", "'rgb(0, 255, 0)'");
for (i = 1; i < v.length; i++)
shouldBe("document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color')", "'rgb(255, 0, 0)'");
var successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
This test performs a check for the :default CSS selector on multiple submit buttons, part 2.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Submit
PASS document.defaultView.getComputedStyle(v[0], null).getPropertyValue('background-color') is 'rgb(0, 255, 0)'
PASS document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color') is 'rgb(255, 0, 0)'
PASS document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color') is 'rgb(255, 0, 0)'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
<style>
input { background: red; }
button { background: red; }
:default { background: lime; }
</style>
</head>
<body>
<p id="description"></p>
<form method="get">
<button name="victim" type="submit"/>Submit</button>
<input name="victim" type="submit" value="Submit" />
<input name="victim" type="submit" value="Submit"/>
</form>
<div id="console"></div>
<script>
description("This test performs a check for the :default CSS selector on multiple submit buttons, part 2.");
v = document.getElementsByName("victim");
shouldBe("document.defaultView.getComputedStyle(v[0], null).getPropertyValue('background-color')", "'rgb(0, 255, 0)'");
for (i = 1; i < v.length; i++)
shouldBe("document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color')", "'rgb(255, 0, 0)'");
var successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
This test performs a simple check for the :default CSS selector: it shouldn't be applied.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Not a submit
PASS document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color') is 'rgb(0, 255, 0)'
PASS document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color') is 'rgb(0, 255, 0)'
PASS document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color') is 'rgb(0, 255, 0)'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../js/resources/js-test-style.css">
<script src="../js/resources/js-test-pre.js"></script>
<style>
input { background: lime; }
button { background: lime; }
:default { background: red; }
</style>
</head>
<body>
<p id="description"></p>
<form method="get">
<input name="victim" type="button" value="Not a submit" />
<input name="victim" type="button" value="Not a submit"/>
<button name="victim" type="button"/>Not a submit</button>
</form>
<div id="console"></div>
<script>
description("This test performs a simple check for the :default CSS selector: it shouldn't be applied.");
v = document.getElementsByName("victim");
for (i = 0; i < v.length; i++)
shouldBe("document.defaultView.getComputedStyle(v[i], null).getPropertyValue('background-color')", "'rgb(0, 255, 0)'");
var successfullyParsed = true;
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
2009-08-12 Michelangelo De Simone <micdesim@gmail.com>
Reviewed by Darin Adler.
https://bugs.webkit.org/show_bug.cgi?id=27458
Support for the :default CSS pseudoclass, as per HTML5 spec.
http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#selector-default
Tests: fast/css/pseudo-default-001.html
fast/css/pseudo-default-002.html
fast/css/pseudo-default-003.html
fast/css/pseudo-default-004.html
* css/CSSSelector.cpp:
(WebCore::CSSSelector::extractPseudoType): pseudoDefault
* css/CSSSelector.h:
(WebCore::CSSSelector::):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::canShareStyleWithElement): sharing stuff is
aware that only one default button can be present in a form
(WebCore::CSSStyleSelector::SelectorChecker::checkOneSelector): applies
the :default CSS pseudoclass
* dom/Element.h:
(WebCore::Element::isDefaultButtonForForm): new method to determine
whether a FormControl is a default button for a given form
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::isDefaultButtonForForm): ditto
* html/HTMLFormControlElement.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::defaultButton): extracts the default button
from the form
* html/HTMLFormElement.h:
2009-08-12 David Levin <levin@chromium.org>
No review, rolling out r47106.
......@@ -77,6 +77,7 @@ void CSSSelector::extractPseudoType() const
DEFINE_STATIC_LOCAL(AtomicString, before, ("before"));
DEFINE_STATIC_LOCAL(AtomicString, checked, ("checked"));
DEFINE_STATIC_LOCAL(AtomicString, fileUploadButton, ("-webkit-file-upload-button"));
DEFINE_STATIC_LOCAL(AtomicString, defaultString, ("default"));
DEFINE_STATIC_LOCAL(AtomicString, disabled, ("disabled"));
DEFINE_STATIC_LOCAL(AtomicString, readOnly, ("read-only"));
DEFINE_STATIC_LOCAL(AtomicString, readWrite, ("read-write"));
......@@ -170,7 +171,9 @@ void CSSSelector::extractPseudoType() const
else if (m_value == fileUploadButton) {
m_pseudoType = PseudoFileUploadButton;
element = true;
} else if (m_value == disabled)
} else if (m_value == defaultString)
m_pseudoType = PseudoDefault;
else if (m_value == disabled)
m_pseudoType = PseudoDisabled;
else if (m_value == readOnly)
m_pseudoType = PseudoReadOnly;
......
......@@ -126,6 +126,7 @@ namespace WebCore {
PseudoChecked,
PseudoEnabled,
PseudoFullPageMedia,
PseudoDefault,
PseudoDisabled,
PseudoInputPlaceholder,
PseudoOptional,
......
......@@ -995,6 +995,9 @@ bool CSSStyleSelector::canShareStyleWithElement(Node* n)
if (s->isEnabledFormControl() != m_element->isEnabledFormControl())
return false;
if (s->isDefaultButtonForForm() != m_element->isDefaultButtonForForm())
return false;
}
if (style->transitions() || style->animations())
......@@ -2358,6 +2361,8 @@ bool CSSStyleSelector::SelectorChecker::checkOneSelector(CSSSelector* sel, Eleme
case CSSSelector::PseudoFullPageMedia:
return e && e->document() && e->document()->isMediaDocument();
break;
case CSSSelector::PseudoDefault:
return e && e->isDefaultButtonForForm();
case CSSSelector::PseudoDisabled:
if (e && e->isFormControlElement()) {
InputElement* inputElement = toInputElement(e);
......
......@@ -214,6 +214,7 @@ public:
virtual bool isTextFormControl() const { return false; }
virtual bool isOptionalFormControl() const { return false; }
virtual bool isRequiredFormControl() const { return false; }
virtual bool isDefaultButtonForForm() const { return false; }
virtual bool formControlValueMatchesRenderer() const { return false; }
virtual void setFormControlValueMatchesRenderer(bool) { }
......
......@@ -294,6 +294,11 @@ HTMLFormElement* HTMLFormControlElement::virtualForm() const
return m_form;
}
bool HTMLFormControlElement::isDefaultButtonForForm() const
{
return isSuccessfulSubmitButton() && m_form && m_form->defaultButton() == this;
}
void HTMLFormControlElement::removeFromForm()
{
if (!m_form)
......
......@@ -117,6 +117,7 @@ protected:
private:
virtual HTMLFormElement* virtualForm() const;
virtual bool isDefaultButtonForForm() const;
HTMLFormElement* m_form;
RefPtr<ValidityState> m_validityState;
......
......@@ -577,6 +577,17 @@ void HTMLFormElement::setTarget(const String &value)
setAttribute(targetAttr, value);
}
HTMLFormControlElement* HTMLFormElement::defaultButton() const
{
for (unsigned i = 0; i < formElements.size(); ++i) {
HTMLFormControlElement* control = formElements[i];
if (control->isSuccessfulSubmitButton())
return control;
}
return 0;
}
PassRefPtr<HTMLFormControlElement> HTMLFormElement::elementForAlias(const AtomicString& alias)
{
if (alias.isEmpty() || !m_elementAliases)
......
......@@ -107,6 +107,8 @@ public:
virtual String target() const;
void setTarget(const String&);
HTMLFormControlElement* defaultButton() const;
PassRefPtr<HTMLFormControlElement> elementForAlias(const AtomicString&);
void addElementAlias(HTMLFormControlElement*, const AtomicString& alias);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment