Support invalidation for :in-range/:out-of-range
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 May 2022 15:15:06 +0000 (15:15 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 May 2022 15:15:06 +0000 (15:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=238902
<rdar://91718746>

Reviewed by Alan Bujtas.

* LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/input-pseudo-classes-in-has-expected.txt:

* Source/WebCore/html/InputType.cpp:
(WebCore::InputType::setValue):

No need to invalidate style unconditionally on value change anymore.
Use Style::PseudoClassChangeInvalidation for :in-range invalidation.

* Source/WebCore/html/SearchInputType.cpp:
(WebCore::SearchInputType::setValue):

Search cancel button style depends on emptiness of the value so invalidate that specifically.

* Source/WebCore/html/SearchInputType.h:

link: https://commits.webkit.org/250839@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294613 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/imported/w3c/web-platform-tests/css/selectors/invalidation/input-pseudo-classes-in-has-expected.txt
Source/WebCore/html/InputType.cpp
Source/WebCore/html/SearchInputType.cpp
Source/WebCore/html/SearchInputType.h

index c1fd829d048a12cdc1345d14168d28a5e3fadd89..7ba21fdf01e4fff2851e5bb8a8f9f64ff5005efb 100644 (file)
@@ -7,6 +7,6 @@ PASS :read-only invalidation
 PASS :valid invalidation
 FAIL :default invalidation with input[type=radio] assert_equals: ancestor should be lightblue expected "rgb(173, 216, 230)" but got "rgb(0, 0, 0)"
 PASS :required invalidation
-FAIL :out-of-range invalidation assert_equals: ancestor should be darkgreen expected "rgb(0, 100, 0)" but got "rgb(0, 0, 0)"
+PASS :out-of-range invalidation
 PASS :placeholder-shown invalidation
 
index 85846c193f25c873f46338236db0bf6af2f5c8b7..c97c8863ef3c20526b4e56da552c83dca80f20dc 100644 (file)
@@ -59,6 +59,7 @@
 #include "NumberInputType.h"
 #include "Page.h"
 #include "PasswordInputType.h"
+#include "PseudoClassChangeInvalidation.h"
 #include "RadioInputType.h"
 #include "RangeInputType.h"
 #include "RenderElement.h"
@@ -794,10 +795,25 @@ bool InputType::storesValueSeparateFromAttribute()
 void InputType::setValue(const String& sanitizedValue, bool valueChanged, TextFieldEventBehavior eventBehavior, TextControlSetValueSelection)
 {
     ASSERT(element());
-    element()->setValueInternal(sanitizedValue, eventBehavior);
-    if (!valueChanged)
+    if (!valueChanged) {
+        element()->setValueInternal(sanitizedValue, eventBehavior);
         return;
-    element()->invalidateStyleForSubtree();
+    }
+
+    bool wasInRange = isInRange(element()->value());
+    bool inRange = isInRange(sanitizedValue);
+
+    bool dummy;
+    auto oldDirection = element()->directionalityIfhasDirAutoAttribute(dummy);
+
+    std::optional<Style::PseudoClassChangeInvalidation> styleInvalidation;
+    if (wasInRange != inRange)
+        emplace(styleInvalidation, *element(), { { CSSSelector::PseudoClassInRange, inRange }, { CSSSelector::PseudoClassOutOfRange, !inRange } });
+
+    element()->setValueInternal(sanitizedValue, eventBehavior);
+
+    if (oldDirection != element()->directionalityIfhasDirAutoAttribute(dummy))
+        element()->invalidateStyleInternal();
 
     switch (eventBehavior) {
     case DispatchChangeEvent:
index 6e5b1e7fbe72bbd31bb98457e02ecd4c6a47de5f..b6d1df49055ba487e3562fc3061140cf2ab422d0 100644 (file)
@@ -219,4 +219,14 @@ float SearchInputType::decorationWidth() const
     return width;
 }
 
+void SearchInputType::setValue(const String& sanitizedValue, bool valueChanged, TextFieldEventBehavior eventBehavior, TextControlSetValueSelection selection)
+{
+    bool emptinessChanged = valueChanged && sanitizedValue.isEmpty() != element()->value().isEmpty();
+
+    BaseTextInputType::setValue(sanitizedValue, valueChanged, eventBehavior, selection);
+
+    if (m_cancelButton && emptinessChanged)
+        m_cancelButton->invalidateStyleInternal();
+}
+
 } // namespace WebCore
index fbe539824223fee7fab66451c219aba7cc0e98f5..c12dd25e89655b0639238ef4ba34076b25692235 100644 (file)
@@ -59,6 +59,7 @@ private:
     void didSetValueByUserEdit() final;
     bool sizeShouldIncludeDecoration(int defaultSize, int& preferredSize) const final;
     float decorationWidth() const final;
+    void setValue(const String&, bool valueChanged, TextFieldEventBehavior, TextControlSetValueSelection) final;
 
     void searchEventTimerFired();
     bool searchEventsShouldBeDispatched() const;