Changeset 287551 in webkit
- Timestamp:
- Jan 3, 2022 10:49:55 AM (7 months ago)
- Location:
- trunk
- Files:
-
- 10 edited
- 2 moved
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-pseudo-class-expected.txt (moved) (moved from trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class-expected.txt) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-pseudo-class.html (moved) (moved from trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class.html) (3 diffs)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/html/FormAssociatedElement.cpp (modified) (1 diff)
-
Source/WebCore/html/FormAssociatedElement.h (modified) (1 diff)
-
Source/WebCore/html/HTMLFieldSetElement.cpp (modified) (3 diffs)
-
Source/WebCore/html/HTMLFormControlElement.cpp (modified) (3 diffs)
-
Source/WebCore/html/HTMLFormElement.cpp (modified) (2 diffs)
-
Source/WebCore/html/HTMLInputElement.cpp (modified) (1 diff)
-
Source/WebCore/html/HTMLInputElement.h (modified) (1 diff)
-
Source/WebCore/html/ValidityState.idl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r287550 r287551 1 2022-01-03 Antti Koivisto <antti@apple.com> 2 3 [:has() pseudo-class] Style invalidation for :valid and :invalid 4 https://bugs.webkit.org/show_bug.cgi?id=234815 5 6 Reviewed by Sam Weinig. 7 8 * web-platform-tests/css/selectors/invalidation/has-with-pseudo-class-expected.txt: Renamed from LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class-expected.txt. 9 * web-platform-tests/css/selectors/invalidation/has-with-pseudo-class.html: Renamed from LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-pseudo-class.html. 10 1 11 2022-01-03 Antoine Quint <graouts@webkit.org> 2 12 -
trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-pseudo-class-expected.txt
r287550 r287551 30 30 PASS Set disabled on optgroup, testing subject4 31 31 PASS Unset disabled on optgroup, testing subject4 32 PASS Before setting value of text_input, testing subject 33 PASS Set value of text_input, testing subject 34 PASS Clear value of text_input, testing subject 35 PASS Before setting value of text_input, testing subject2 36 PASS Set value of text_input, testing subject2 37 PASS Clear value of text_input, testing subject2 38 PASS Before setting value of text_input, testing subject3 39 PASS Set value of text_input, testing subject3 40 PASS Clear value of text_input, testing subject3 41 PASS Before setting value of text_input, testing subject4 42 PASS Set value of text_input, testing subject4 43 PASS Clear value of text_input, testing subject4 32 44 -
trunk/LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-pseudo-class.html
r287550 r287551 16 16 main:not(:has(#option:enabled)) :is(#subject3, #subject4) { color: green } 17 17 main:not(:has(#optgroup:enabled)) > #subject3 { color: blue } 18 main:has(#text_input:valid) > #subject { color: yellow } 19 main:not(:has(#text_input:invalid)) > #subject2 { color: yellow } 20 main:has(#form:valid) > #subject3 { color: yellow } 21 main:not(:has(#form:invalid)) > #subject4 { color: yellow } 18 22 </style> 19 23 20 24 <main id=main> 21 <input type=checkbox id=checkbox></input> 22 <select id=select><optgroup id=optgroup><option>a</option><option id=option>b</option></optgroup></select> 25 <form id=form> 26 <input type=checkbox id=checkbox></input> 27 <select id=select><optgroup id=optgroup><option>a</option><option id=option>b</option></optgroup></select> 28 <input id=text_input type=text required></input> 29 </form> 23 30 <div id=subject></div> 24 31 <div id=subject2></div> … … 62 69 } 63 70 71 function testValueChange(input, subject_element, expectedColor) 72 { 73 testColor(`Before setting value of ${input.id}, testing ${subject_element.id}`, subject_element, grey); 74 75 input.value = "value"; 76 testColor(`Set value of ${input.id}, testing ${subject_element.id}`, subject_element, expectedColor); 77 78 input.value = ""; 79 testColor(`Clear value of ${input.id}, testing ${subject_element.id}`, subject_element, grey); 80 } 81 64 82 testPseudoClassChange(checkbox, "checked", subject, red); 65 83 testSelectedChange(option, subject, red); … … 75 93 testPseudoClassChange(optgroup, "disabled", subject4, green); 76 94 95 testValueChange(text_input, subject, yellow); 96 testValueChange(text_input, subject2, yellow); 97 testValueChange(text_input, subject3, yellow); 98 testValueChange(text_input, subject4, yellow); 77 99 </script> -
trunk/Source/WebCore/ChangeLog
r287550 r287551 1 2022-01-03 Antti Koivisto <antti@apple.com> 2 3 [:has() pseudo-class] Style invalidation for :valid and :invalid 4 https://bugs.webkit.org/show_bug.cgi?id=234815 5 6 Reviewed by Sam Weinig. 7 8 Use PseudoClassChangeInvalidation for accurate and :has() supporting style invalidation. 9 10 Test: imported/w3c/web-platform-tests/css/selectors/invalidation/has-with-pseudo-class.html 11 12 * html/FormAssociatedElement.cpp: 13 (WebCore::FormAssociatedElement::computeValidity const): 14 (WebCore::FormAssociatedElement::isValid const): Deleted. 15 * html/FormAssociatedElement.h: 16 * html/HTMLFieldSetElement.cpp: 17 (WebCore::HTMLFieldSetElement::addInvalidDescendant): 18 (WebCore::HTMLFieldSetElement::removeInvalidDescendant): 19 * html/HTMLFormControlElement.cpp: 20 (WebCore::HTMLFormControlElement::updateWillValidateAndValidity): 21 (WebCore::HTMLFormControlElement::isValidFormControlElement const): 22 (WebCore::HTMLFormControlElement::updateValidity): 23 * html/HTMLFormElement.cpp: 24 (WebCore::HTMLFormElement::registerInvalidAssociatedFormControl): 25 (WebCore::HTMLFormElement::removeInvalidAssociatedFormControlIfNeeded): 26 * html/HTMLInputElement.cpp: 27 (WebCore::HTMLInputElement::computeValidity const): 28 (WebCore::HTMLInputElement::isValid const): Deleted. 29 * html/HTMLInputElement.h: 30 * html/ValidityState.idl: 31 1 32 2022-01-03 Antoine Quint <graouts@webkit.org> 2 33 -
trunk/Source/WebCore/html/FormAssociatedElement.cpp
r286321 r287551 254 254 } 255 255 256 bool FormAssociatedElement:: isValid() const256 bool FormAssociatedElement::computeValidity() const 257 257 { 258 258 bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow() -
trunk/Source/WebCore/html/FormAssociatedElement.h
r286447 r287551 86 86 virtual bool valueMissing() const; 87 87 virtual String validationMessage() const; 88 virtual bool isValid() const;88 virtual bool computeValidity() const; 89 89 virtual void setCustomValidity(const String&); 90 90 -
trunk/Source/WebCore/html/HTMLFieldSetElement.cpp
r278919 r287551 33 33 #include "HTMLObjectElement.h" 34 34 #include "NodeRareData.h" 35 #include "PseudoClassChangeInvalidation.h" 35 36 #include "RenderElement.h" 36 37 #include "ScriptDisallowedScope.h" … … 181 182 ASSERT_WITH_MESSAGE(!m_invalidDescendants.contains(invalidFormControlElement), "Updating the fieldset on validity change is not an efficient operation, it should only be done when necessary."); 182 183 184 std::optional<Style::PseudoClassChangeInvalidation> styleInvalidation; 183 185 if (m_invalidDescendants.computesEmpty()) 184 invalidateStyleForSubtree(); 186 styleInvalidation.emplace(*this, std::initializer_list<CSSSelector::PseudoClassType> { CSSSelector::PseudoClassValid, CSSSelector::PseudoClassInvalid }); 187 185 188 m_invalidDescendants.add(invalidFormControlElement); 186 189 } … … 191 194 ASSERT_WITH_MESSAGE(m_invalidDescendants.contains(formControlElement), "Updating the fieldset on validity change is not an efficient operation, it should only be done when necessary."); 192 195 196 std::optional<Style::PseudoClassChangeInvalidation> styleInvalidation; 197 if (m_invalidDescendants.computeSize() == 1) 198 styleInvalidation.emplace(*this, std::initializer_list<CSSSelector::PseudoClassType> { CSSSelector::PseudoClassValid, CSSSelector::PseudoClassInvalid }); 199 193 200 m_invalidDescendants.remove(formControlElement); 194 if (m_invalidDescendants.computesEmpty())195 invalidateStyleForSubtree();196 201 } 197 202 -
trunk/Source/WebCore/html/HTMLFormControlElement.cpp
r287540 r287551 406 406 407 407 updateValidity(); 408 invalidateStyleForSubtree();409 408 410 409 if (!m_willValidate && !wasValid) { … … 504 503 inline bool HTMLFormControlElement::isValidFormControlElement() const 505 504 { 506 // If the following assertion fails, updateValidity() is not called507 // correctly when something which changes validity is updated.508 ASSERT(m_isValid == isValid());509 505 return m_isValid; 510 506 } … … 534 530 535 531 bool willValidate = this->willValidate(); 536 bool wasValid = m_isValid; 537 538 m_isValid = isValid(); 539 540 if (willValidate && m_isValid != wasValid) { 541 // Update style for pseudo classes such as :valid :invalid. 542 invalidateStyleForSubtree(); 543 544 if (!m_isValid) { 545 if (isConnected()) 546 addInvalidElementToAncestorFromInsertionPoint(*this, parentNode()); 547 if (HTMLFormElement* form = this->form()) 548 form->registerInvalidAssociatedFormControl(*this); 549 } else { 550 if (isConnected()) 551 removeInvalidElementToAncestorFromInsertionPoint(*this, parentNode()); 552 if (HTMLFormElement* form = this->form()) 553 form->removeInvalidAssociatedFormControlIfNeeded(*this); 532 bool newIsValid = this->computeValidity(); 533 534 if (newIsValid != m_isValid) { 535 Style::PseudoClassChangeInvalidation styleInvalidation(*this, { CSSSelector::PseudoClassValid, CSSSelector::PseudoClassInvalid }); 536 537 m_isValid = newIsValid; 538 539 if (willValidate) { 540 if (!m_isValid) { 541 if (isConnected()) 542 addInvalidElementToAncestorFromInsertionPoint(*this, parentNode()); 543 if (HTMLFormElement* form = this->form()) 544 form->registerInvalidAssociatedFormControl(*this); 545 } else { 546 if (isConnected()) 547 removeInvalidElementToAncestorFromInsertionPoint(*this, parentNode()); 548 if (HTMLFormElement* form = this->form()) 549 form->removeInvalidAssociatedFormControlIfNeeded(*this); 550 } 554 551 } 555 552 } 556 553 557 // Updates only if this control already has a valid tion message.554 // Updates only if this control already has a validation message. 558 555 if (m_validationMessage && m_validationMessage->isVisible()) { 559 556 // Calls updateVisibleValidationMessage() even if m_isValid is not -
trunk/Source/WebCore/html/HTMLFormElement.cpp
r286447 r287551 667 667 ASSERT(static_cast<const Element&>(formControlElement).matchesInvalidPseudoClass()); 668 668 669 std::optional<Style::PseudoClassChangeInvalidation> styleInvalidation; 669 670 if (m_invalidAssociatedFormControls.computesEmpty()) 670 invalidateStyleForSubtree(); 671 styleInvalidation.emplace(*this, std::initializer_list<CSSSelector::PseudoClassType> { CSSSelector::PseudoClassValid, CSSSelector::PseudoClassInvalid }); 672 671 673 m_invalidAssociatedFormControls.add(const_cast<HTMLFormControlElement&>(formControlElement)); 672 674 } … … 674 676 void HTMLFormElement::removeInvalidAssociatedFormControlIfNeeded(const HTMLFormControlElement& formControlElement) 675 677 { 676 if (m_invalidAssociatedFormControls.remove(formControlElement)) { 677 if (m_invalidAssociatedFormControls.computesEmpty()) 678 invalidateStyleForSubtree(); 679 } 678 if (!m_invalidAssociatedFormControls.contains(formControlElement)) 679 return; 680 681 std::optional<Style::PseudoClassChangeInvalidation> styleInvalidation; 682 if (m_invalidAssociatedFormControls.computeSize() == 1) 683 styleInvalidation.emplace(*this, std::initializer_list<CSSSelector::PseudoClassType> { CSSSelector::PseudoClassValid, CSSSelector::PseudoClassInvalid }); 684 685 m_invalidAssociatedFormControls.remove(formControlElement); 680 686 } 681 687 -
trunk/Source/WebCore/html/HTMLInputElement.cpp
r287363 r287551 392 392 } 393 393 394 bool HTMLInputElement:: isValid() const394 bool HTMLInputElement::computeValidity() const 395 395 { 396 396 String value = this->value(); -
trunk/Source/WebCore/html/HTMLInputElement.h
r286560 r287551 74 74 bool typeMismatch() const final; 75 75 bool valueMissing() const final; 76 bool isValid() const final;76 bool computeValidity() const final; 77 77 WEBCORE_EXPORT String validationMessage() const final; 78 78 -
trunk/Source/WebCore/html/ValidityState.idl
r267813 r287551 35 35 readonly attribute boolean badInput; 36 36 readonly attribute boolean customError; 37 [ImplementedAs= isValid] readonly attribute boolean valid;37 [ImplementedAs=computeValidity] readonly attribute boolean valid; 38 38 };
Note: See TracChangeset
for help on using the changeset viewer.