:default CSS pseudo-class should match checkboxes+radios with a `checked` attribute
authorbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Jun 2016 21:30:36 +0000 (21:30 +0000)
committerbenjamin@webkit.org <benjamin@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 20 Jun 2016 21:30:36 +0000 (21:30 +0000)
commit87a8de5e4feb0a0cd1b6c2ac9a9ea0d7223991a6
tree39ae03cf783b8ef3d92a2f5b8bf80b4976fd9c0c
parentcb12fc0f3f4238249a4e9c24fc0f299e953e9cf5
:default CSS pseudo-class should match checkboxes+radios with a `checked` attribute
https://bugs.webkit.org/show_bug.cgi?id=156230

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/html/semantics/selectors/pseudo-classes/default-expected.txt:

Source/WebCore:

This patch update the :default pseudo class matching to be closer to the spec:
https://html.spec.whatwg.org/multipage/scripting.html#selector-default

The main remaining difference with the spec is the definition of "default button".
This is an unrelated problem that should be addressed separately.

The implementation was missing support for:
-input elements of type "checkbox" or "radio" with the "checked" attribute defined.
-option elements with the "selected" attribute defined.

The existing support for default button was pretty bad, I fixed that too.
The owner form now has a resetDefaultButton() API. When a Form Associated Element
becomes a submit button or loses that property, the element calls its form
to update the style as needed.

Whenever the submit button changes, 2 elements needs to have their style invalidated:
-The former default button.
-The new default button.
To invalidate the former button, FormElement now caches the computed
default button. When the default button changes, the cached value is invalidated
in addition to the new value.

Computing the new default button takes linear time in the number of form associated element.
To mitigate that, resetDefaultButton() is only called when changes are related
to submit buttons. Since those changes are rare, I don't expect the invalidation
to be a problem.

Tests: fast/css/pseudo-default-basics.html
       fast/selectors/default-style-update.html

* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* css/SelectorCheckerTestFunctions.h:
(WebCore::matchesDefaultPseudoClass):
(WebCore::isDefaultButtonForForm): Deleted.
* cssjit/SelectorCompiler.cpp:
(WebCore::SelectorCompiler::addPseudoClassType):
* dom/Element.cpp:
(WebCore::Element::matchesValidPseudoClass):
(WebCore::Element::matchesInvalidPseudoClass):
(WebCore::Element::matchesDefaultPseudoClass):
* dom/Element.h:
(WebCore::Element::matchesValidPseudoClass): Deleted.
(WebCore::Element::matchesInvalidPseudoClass): Deleted.
(WebCore::Element::isDefaultButtonForForm): Deleted.
* html/HTMLButtonElement.cpp:
(WebCore::HTMLButtonElement::parseAttribute):
(WebCore::HTMLButtonElement::matchesDefaultPseudoClass):
* html/HTMLButtonElement.h:
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::isDefaultButtonForForm): Deleted.
* html/HTMLFormControlElement.h:
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::~HTMLFormElement):
(WebCore::HTMLFormElement::registerFormElement):
(WebCore::HTMLFormElement::removeFormElement):
(WebCore::HTMLFormElement::defaultButton):
(WebCore::HTMLFormElement::resetDefaultButton):
* html/HTMLFormElement.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::updateType):
(WebCore::HTMLInputElement::parseAttribute):
(WebCore::HTMLInputElement::matchesDefaultPseudoClass):
* html/HTMLInputElement.h:
* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::matchesDefaultPseudoClass):
(WebCore::HTMLOptionElement::parseAttribute):
* html/HTMLOptionElement.h:
* style/StyleSharingResolver.cpp:
(WebCore::Style::SharingResolver::canShareStyleWithElement):
(WebCore::Style::canShareStyleWithControl): Deleted.

LayoutTests:

* fast/css/pseudo-default-basics-expected.html: Added.
* fast/css/pseudo-default-basics.html: Added.
* fast/selectors/default-style-update-expected.txt: Added.
* fast/selectors/default-style-update.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202245 268f45cc-cd09-0410-ab3c-d52691b4dbfc
24 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/css/pseudo-default-basics-expected.html [new file with mode: 0644]
LayoutTests/fast/css/pseudo-default-basics.html [new file with mode: 0644]
LayoutTests/fast/selectors/default-style-update-expected.txt [new file with mode: 0644]
LayoutTests/fast/selectors/default-style-update.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/semantics/selectors/pseudo-classes/default-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/css/SelectorChecker.cpp
Source/WebCore/css/SelectorCheckerTestFunctions.h
Source/WebCore/cssjit/SelectorCompiler.cpp
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/html/HTMLButtonElement.cpp
Source/WebCore/html/HTMLButtonElement.h
Source/WebCore/html/HTMLFormControlElement.cpp
Source/WebCore/html/HTMLFormControlElement.h
Source/WebCore/html/HTMLFormElement.cpp
Source/WebCore/html/HTMLFormElement.h
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/HTMLInputElement.h
Source/WebCore/html/HTMLOptionElement.cpp
Source/WebCore/html/HTMLOptionElement.h
Source/WebCore/style/StyleSharingResolver.cpp