Skip to content
Permalink
Browse files
Support invalidation for :in-range/:out-of-range
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:

Canonical link: https://commits.webkit.org/250839@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294613 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
anttijk committed May 21, 2022
1 parent 56da44e commit 127ac8eae71ee7450f685df2c671a0d9f0a939ad
Showing 4 changed files with 31 additions and 4 deletions.
@@ -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

@@ -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:
@@ -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
@@ -59,6 +59,7 @@ class SearchInputType final : public BaseTextInputType {
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;

0 comments on commit 127ac8e

Please sign in to comment.