X-Git-Url: https://git.webkit.org/?p=WebKit-https.git;a=blobdiff_plain;f=Source%2FWebCore%2Fhtml%2FInputType.cpp;h=c97c8863ef3c20526b4e56da552c83dca80f20dc;hp=85846c193f25c873f46338236db0bf6af2f5c8b7;hb=HEAD;hpb=225e3dda6f57a05d3d9dc5b3f3bb786f778a2ab9 diff --git a/Source/WebCore/html/InputType.cpp b/Source/WebCore/html/InputType.cpp index 85846c193f25..40f4e7435ff4 100644 --- a/Source/WebCore/html/InputType.cpp +++ b/Source/WebCore/html/InputType.cpp @@ -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" @@ -130,6 +131,7 @@ static InputTypeFactoryMap createInputTypeFactoryMap() { nullptr, &InputTypeNames::search, &createInputType }, { nullptr, &InputTypeNames::submit, &createInputType }, { nullptr, &InputTypeNames::telephone, &createInputType }, + { nullptr, &InputTypeNames::text, &createInputType }, #if ENABLE(INPUT_TYPE_TIME) { &Settings::inputTypeTimeEnabled, &InputTypeNames::time, &createInputType }, #endif @@ -137,7 +139,6 @@ static InputTypeFactoryMap createInputTypeFactoryMap() #if ENABLE(INPUT_TYPE_WEEK) { &Settings::inputTypeWeekEnabled, &InputTypeNames::week, &createInputType }, #endif - // No need to register "text" because it is the default type. }; InputTypeFactoryMap map; @@ -146,12 +147,20 @@ static InputTypeFactoryMap createInputTypeFactoryMap() return map; } +static inline std::pair findFactory(const AtomString& typeName) +{ + static NeverDestroyed factoryMap = createInputTypeFactoryMap(); + auto factory = factoryMap.get().get(typeName); + if (UNLIKELY(!factory.second)) + factory = factoryMap.get().get(typeName.convertToASCIILowercase()); + return factory; +} + Ref InputType::create(HTMLInputElement& element, const AtomString& typeName) { if (!typeName.isEmpty()) { - static NeverDestroyed factoryMap = createInputTypeFactoryMap(); - auto&& [conditional, factory] = factoryMap.get().get(typeName.convertToASCIILowercase()); - if (factory && (!conditional || std::invoke(conditional, element.document().settings()))) + auto [conditional, factory] = findFactory(typeName); + if (LIKELY(factory && (!conditional || std::invoke(conditional, element.document().settings())))) return factory(element); } return adoptRef(*new TextInputType(element)); @@ -794,10 +803,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 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: