Title: [293948] trunk/Source
Revision
293948
Author
[email protected]
Date
2022-05-07 10:34:11 -0700 (Sat, 07 May 2022)

Log Message

Modernize / Optimize HTMLInputElement a bit
https://bugs.webkit.org/show_bug.cgi?id=240194

Reviewed by Darin Adler.

* Source/WebCore/html/ColorInputType.h:
* Source/WebCore/html/FileInputType.cpp:
(WebCore::FileInputType::firstElementPathForInputValue const):
(WebCore::FileInputType::files): Deleted.
(WebCore::FileInputType::canSetValue): Deleted.
(WebCore::FileInputType::getTypeSpecificValue): Deleted.
* Source/WebCore/html/FileInputType.h:
* Source/WebCore/html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::HTMLInputElement):
(WebCore::HTMLInputElement::endEditing):
(WebCore::HTMLInputElement::updateType):
(WebCore::HTMLInputElement::accessKeyAction):
(WebCore::HTMLInputElement::initializeInputType):
(WebCore::HTMLInputElement::parseAttribute):
(WebCore::HTMLInputElement::finishParsingChildren):
(WebCore::HTMLInputElement::appendFormData):
(WebCore::HTMLInputElement::reset):
(WebCore::HTMLInputElement::setChecked):
(WebCore::HTMLInputElement::setIndeterminate):
(WebCore::HTMLInputElement::value const):
(WebCore::HTMLInputElement::valueWithDefault const):
(WebCore::HTMLInputElement::setValue):
(WebCore::HTMLInputElement::defaultEventHandler):
(WebCore::HTMLInputElement::acceptMIMETypes const):
(WebCore::HTMLInputElement::acceptFileExtensions const):
(WebCore::HTMLInputElement::setShowAutoFillButton):
(WebCore::HTMLInputElement::files):
(WebCore::HTMLInputElement::setFiles):
(WebCore::HTMLInputElement::onSearch):
(WebCore::HTMLInputElement::prepareForDocumentSuspension):
(WebCore::HTMLInputElement::valueAsColor const):
(WebCore::HTMLInputElement::selectColor):
(WebCore::HTMLInputElement::suggestedColors const):
(WebCore::HTMLInputElement::dataList const):
(WebCore::HTMLInputElement::updateValueIfNeeded):
(WebCore::HTMLInputElement::isInRequiredRadioButtonGroup):
(WebCore::HTMLInputElement::radioButtonGroup const):
(WebCore::HTMLInputElement::checkedRadioButtonForGroup const):
(WebCore::HTMLInputElement::size const): Deleted.
(WebCore::HTMLInputElement::setValueForUser): Deleted.
(WebCore::HTMLInputElement::acceptMIMETypes): Deleted.
(WebCore::HTMLInputElement::acceptFileExtensions): Deleted.
(WebCore::HTMLInputElement::canReceiveDroppedFiles const): Deleted.
* Source/WebCore/html/HTMLInputElement.h:
(WebCore::HTMLInputElement::size const):
(WebCore::HTMLInputElement::setValueForUser):
(WebCore::HTMLInputElement::hasDirtyValue const):
(WebCore::HTMLInputElement::hasAutoFillStrongPasswordButton const):
(WebCore::HTMLInputElement::canReceiveDroppedFiles const):
* Source/WebCore/html/InputType.cpp:
(WebCore::InputType::files): Deleted.
(WebCore::InputType::setFiles): Deleted.
(WebCore::InputType::getTypeSpecificValue): Deleted.
(WebCore::InputType::canSetValue): Deleted.
(WebCore::InputType::valueAsColor const): Deleted.
(WebCore::InputType::selectColor): Deleted.
(WebCore::InputType::suggestedColors const): Deleted.
* Source/WebCore/html/InputType.h:
(WebCore::InputType::supportsValidation const):
(WebCore::InputType::InputType):
(WebCore::InputType::canHaveTypeSpecificValue const): Deleted.

Canonical link: https://commits.webkit.org/250394@main

Modified Paths

Diff

Modified: trunk/Source/WTF/wtf/RefPtr.h (293947 => 293948)


--- trunk/Source/WTF/wtf/RefPtr.h	2022-05-07 05:27:43 UTC (rev 293947)
+++ trunk/Source/WTF/wtf/RefPtr.h	2022-05-07 17:34:11 UTC (rev 293948)
@@ -116,6 +116,9 @@
     typename PtrTraits::StorageType m_ptr;
 };
 
+// Template deduction guide.
+template<typename X, typename Y> RefPtr(Ref<X, Y>&&) -> RefPtr<X, Y, DefaultRefDerefTraits<X>>;
+
 template<typename T, typename U, typename V>
 template<typename X, typename Y>
 inline RefPtr<T, U, V>::RefPtr(Ref<X, Y>&& reference)

Modified: trunk/Source/WebCore/html/ColorInputType.h (293947 => 293948)


--- trunk/Source/WebCore/html/ColorInputType.h	2022-05-07 05:27:43 UTC (rev 293947)
+++ trunk/Source/WebCore/html/ColorInputType.h	2022-05-07 17:34:11 UTC (rev 293948)
@@ -48,14 +48,19 @@
         ASSERT(needsShadowSubtree());
     }
 
+    Vector<Color> suggestedColors() const;
+    Color valueAsColor() const;
+    void selectColor(StringView);
+
     virtual ~ColorInputType();
     bool typeMismatchFor(const String&) const final;
 
+    void detach() final;
+
 private:
     void didChooseColor(const Color&) final;
     void didEndChooser() final;
     IntRect elementRectRelativeToRootView() const final;
-    Vector<Color> suggestedColors() const final;
     bool isMouseFocusable() const final;
     bool isKeyboardFocusable(KeyboardEvent*) const final;
     bool isPresentingAttachedView() const final;
@@ -69,12 +74,9 @@
     void handleDOMActivateEvent(Event&) final;
     void showPicker() final;
     bool allowsShowPickerAcrossFrames() final;
-    void detach() final;
     void elementDidBlur() final;
     bool shouldRespectListAttribute() final;
     bool shouldResetOnDocumentActivation() final;
-    Color valueAsColor() const final;
-    void selectColor(StringView) final;
 
     void endColorChooser();
     void updateColorSwatch();

Modified: trunk/Source/WebCore/html/FileInputType.cpp (293947 => 293948)


--- trunk/Source/WebCore/html/FileInputType.cpp	2022-05-07 05:27:43 UTC (rev 293947)
+++ trunk/Source/WebCore/html/FileInputType.cpp	2022-05-07 17:34:11 UTC (rev 293948)
@@ -234,27 +234,11 @@
     return false;
 }
 
-FileList* FileInputType::files()
+String FileInputType::firstElementPathForInputValue() const
 {
-    return m_fileList.ptr();
-}
+    if (m_fileList->isEmpty())
+        return { };
 
-bool FileInputType::canSetValue(const String& value)
-{
-    // For security reasons, we don't allow setting the filename, but we do allow clearing it.
-    // The HTML5 spec (as of the 10/24/08 working draft) says that the value attribute isn't
-    // applicable to the file upload control at all, but for now we are keeping this behavior
-    // to avoid breaking existing websites that may be relying on this.
-    return value.isEmpty();
-}
-
-bool FileInputType::getTypeSpecificValue(String& value)
-{
-    if (m_fileList->isEmpty()) {
-        value = { };
-        return true;
-    }
-
     // HTML5 tells us that we're supposed to use this goofy value for
     // file input controls. Historically, browsers revealed the real
     // file path, but that's a privacy problem. Code on the web
@@ -261,8 +245,7 @@
     // decided to try to parse the value by looking for backslashes
     // (because that's what Windows file paths use). To be compatible
     // with that code, we make up a fake path for the file.
-    value = makeString("C:\\fakepath\\", m_fileList->file(0).name());
-    return true;
+    return makeString("C:\\fakepath\\", m_fileList->file(0).name());
 }
 
 void FileInputType::setValue(const String&, bool, TextFieldEventBehavior, TextControlSetValueSelection)

Modified: trunk/Source/WebCore/html/FileInputType.h (293947 => 293948)


--- trunk/Source/WebCore/html/FileInputType.h	2022-05-07 05:27:43 UTC (rev 293947)
+++ trunk/Source/WebCore/html/FileInputType.h	2022-05-07 17:34:11 UTC (rev 293948)
@@ -50,6 +50,10 @@
     explicit FileInputType(HTMLInputElement&);
     virtual ~FileInputType();
 
+    String firstElementPathForInputValue() const; // Checked first, before internal storage or the value attribute.
+    FileList& files() { return m_fileList; }
+    void setFiles(RefPtr<FileList>&&, WasSetByJavaScript);
+
     static Vector<FileChooserFileInfo> filesFromFormControlState(const FormControlState&);
     bool canSetStringValue() const final;
     bool valueMissing(const String&) const final;
@@ -62,13 +66,9 @@
     String valueMissingText() const final;
     void handleDOMActivateEvent(Event&) final;
     RenderPtr<RenderElement> createInputRenderer(RenderStyle&&) final;
-    FileList* files() final;
-    void setFiles(RefPtr<FileList>&&, WasSetByJavaScript) final;
     enum class RequestIcon { Yes, No };
     void setFiles(RefPtr<FileList>&&, RequestIcon, WasSetByJavaScript);
     String displayString() const final;
-    bool canSetValue(const String&) final;
-    bool getTypeSpecificValue(String&) final; // Checked first, before internal storage or the value attribute.
     void setValue(const String&, bool valueChanged, TextFieldEventBehavior, TextControlSetValueSelection) final;
     void showPicker() final;
     bool allowsShowPickerAcrossFrames() final;

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (293947 => 293948)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2022-05-07 05:27:43 UTC (rev 293947)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2022-05-07 17:34:11 UTC (rev 293948)
@@ -36,6 +36,7 @@
 #include "CSSValuePool.h"
 #include "Chrome.h"
 #include "ChromeClient.h"
+#include "ColorInputType.h"
 #include "DOMWindow.h"
 #include "DateComponents.h"
 #include "DateTimeChooser.h"
@@ -101,48 +102,15 @@
 };
 #endif
 
-// FIXME: According to HTML4, the length attribute's value can be arbitrarily
-// large. However, due to https://bugs.webkit.org/show_bug.cgi?id=14536 things
-// get rather sluggish when a text field has a larger number of characters than
-// this, even when just clicking in the text field.
-const unsigned HTMLInputElement::maxEffectiveLength = 524288;
-const int defaultSize = 20;
-const int maxSavedResults = 256;
+static constexpr int maxSavedResults = 256;
 
 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document& document, HTMLFormElement* form, bool createdByParser)
     : HTMLTextFormControlElement(tagName, document, form)
-    , m_size(defaultSize)
-    , m_isChecked(false)
-    , m_dirtyCheckednessFlag(false)
-    , m_isIndeterminate(false)
-    , m_hasType(false)
-    , m_isActivatedSubmit(false)
-    , m_autocomplete(Uninitialized)
-    , m_isAutoFilled(false)
-    , m_isAutoFilledAndViewable(false)
-    , m_isAutoFilledAndObscured(false)
-    , m_autoFillButtonType(static_cast<uint8_t>(AutoFillButtonType::None))
-    , m_lastAutoFillButtonType(static_cast<uint8_t>(AutoFillButtonType::None))
-    , m_isAutoFillAvailable(false)
-#if ENABLE(DATALIST_ELEMENT)
-    , m_hasNonEmptyList(false)
-#endif
-    , m_stateRestored(false)
     , m_parsingInProgress(createdByParser)
-    , m_valueAttributeWasUpdatedAfterParsing(false)
-    , m_wasModifiedByUser(false)
-    , m_canReceiveDroppedFiles(false)
-#if ENABLE(TOUCH_EVENTS)
-    , m_hasTouchEventHandler(false)
-#endif
-    , m_isSpellcheckDisabledExceptTextReplacement(false)
-    , m_hasPendingUserAgentShadowTreeUpdate(false)
-{
     // m_inputType is lazily created when constructed by the parser to avoid constructing unnecessarily a text inputType,
     // just to destroy them when the |type| attribute gets set by the parser to something else than 'text'.
-    if (!createdByParser)
-        m_inputType = InputType::createText(*this);
-
+    , m_inputType(createdByParser ? nullptr : RefPtr { InputType::createText(*this) })
+{
     ASSERT(hasTagName(inputTag));
     setHasCustomStyleResolveCallbacks();
 }
@@ -501,7 +469,7 @@
     if (!isTextField())
         return;
 
-    if (RefPtr<Frame> frame = document().frame())
+    if (RefPtr frame = document().frame())
         frame->editor().textFieldDidEndEditing(this);
 }
 
@@ -557,10 +525,8 @@
     bool didRespectHeightAndWidth = m_inputType->shouldRespectHeightAndWidthAttributes();
     bool wasSuccessfulSubmitButtonCandidate = m_inputType->canBeSuccessfulSubmitButton();
 
-    if (didStoreValue && !willStoreValue && hasDirtyValue()) {
-        setAttributeWithoutSynchronization(valueAttr, AtomString { m_valueIfDirty });
-        m_valueIfDirty = String();
-    }
+    if (didStoreValue && !willStoreValue && hasDirtyValue())
+        setAttributeWithoutSynchronization(valueAttr, AtomString { std::exchange(m_valueIfDirty, { }) });
 
     m_inputType->destroyShadowSubtree();
     m_inputType->detachFromElement();
@@ -598,8 +564,8 @@
             attributeChanged(alignAttr, nullAtom(), align->value());
     }
 
-    if (form() && wasSuccessfulSubmitButtonCandidate != m_inputType->canBeSuccessfulSubmitButton())
-        form()->resetDefaultButton();
+    if (auto* form = this->form(); form && wasSuccessfulSubmitButtonCandidate != m_inputType->canBeSuccessfulSubmitButton())
+        form->resetDefaultButton();
 
     runPostTypeUpdateTasks();
 
@@ -688,8 +654,7 @@
 
 bool HTMLInputElement::accessKeyAction(bool sendMouseEvents)
 {
-    Ref<InputType> protectedInputType(*m_inputType);
-    return protectedInputType->accessKeyAction(sendMouseEvents);
+    return Ref { *m_inputType }->accessKeyAction(sendMouseEvents);
 }
 
 bool HTMLInputElement::hasPresentationalHintsForAttribute(const QualifiedName& name) const
@@ -731,7 +696,7 @@
     ASSERT(m_parsingInProgress);
     ASSERT(!m_inputType);
 
-    const AtomString& type = attributeWithoutSynchronization(typeAttr);
+    auto& type = attributeWithoutSynchronization(typeAttr);
     if (type.isNull()) {
         m_inputType = InputType::createText(*this);
         updateWillValidateAndValidity();
@@ -749,7 +714,7 @@
 void HTMLInputElement::parseAttribute(const QualifiedName& name, const AtomString& value)
 {
     ASSERT(m_inputType);
-    Ref<InputType> protectedInputType(*m_inputType);
+    Ref protectedInputType { *m_inputType };
 
     if (name == nameAttr) {
         removeFromRadioButtonGroup();
@@ -856,9 +821,8 @@
     ASSERT(m_inputType);
     HTMLTextFormControlElement::finishParsingChildren();
     if (!m_stateRestored) {
-        bool checked = hasAttributeWithoutSynchronization(checkedAttr);
-        if (checked)
-            setChecked(checked);
+        if (hasAttributeWithoutSynchronization(checkedAttr))
+            setChecked(true);
         m_dirtyCheckednessFlag = false;
     }
 }
@@ -941,7 +905,7 @@
 
 bool HTMLInputElement::appendFormData(DOMFormData& formData)
 {
-    Ref<InputType> protectedInputType(*m_inputType);
+    Ref protectedInputType { *m_inputType };
     return m_inputType->isFormDataAppendable() && m_inputType->appendFormData(formData);
 }
 
@@ -948,7 +912,7 @@
 void HTMLInputElement::reset()
 {
     if (m_inputType->storesValueSeparateFromAttribute())
-        setValue(String());
+        setValue({ });
 
     setAutoFilled(false);
     setAutoFilledAndViewable(false);
@@ -980,17 +944,17 @@
 
     m_isChecked = isChecked;
 
-    if (RadioButtonGroups* buttons = radioButtonGroups())
+    if (auto* buttons = radioButtonGroups())
         buttons->updateCheckedState(*this);
-    if (renderer() && renderer()->style().hasEffectiveAppearance())
-        renderer()->theme().stateChanged(*renderer(), ControlStates::States::Checked);
+    if (auto* renderer = this->renderer(); renderer && renderer->style().hasEffectiveAppearance())
+        renderer->theme().stateChanged(*renderer, ControlStates::States::Checked);
     updateValidity();
 
     // Ideally we'd do this from the render tree (matching
     // RenderTextView), but it's not possible to do it at the moment
     // because of the way the code is structured.
-    if (renderer()) {
-        if (AXObjectCache* cache = renderer()->document().existingAXObjectCache())
+    if (auto* renderer = this->renderer()) {
+        if (auto* cache = renderer->document().existingAXObjectCache())
             cache->checkedStateChanged(this);
     }
 }
@@ -1003,15 +967,10 @@
     Style::PseudoClassChangeInvalidation indeterminateInvalidation(*this, CSSSelector::PseudoClassIndeterminate, newValue);
     m_isIndeterminate = newValue;
 
-    if (renderer() && renderer()->style().hasEffectiveAppearance())
-        renderer()->theme().stateChanged(*renderer(), ControlStates::States::Checked);
+    if (auto* renderer = this->renderer(); renderer && renderer->style().hasEffectiveAppearance())
+        renderer->theme().stateChanged(*renderer, ControlStates::States::Checked);
 }
 
-unsigned HTMLInputElement::size() const
-{
-    return m_size;
-}
-
 bool HTMLInputElement::sizeShouldIncludeDecoration(int& preferredSize) const
 {
     return m_inputType->sizeShouldIncludeDecoration(defaultSize, preferredSize);
@@ -1041,18 +1000,16 @@
 
 String HTMLInputElement::value() const
 {
-    String value;
-    if (m_inputType->canHaveTypeSpecificValue() && m_inputType->getTypeSpecificValue(value))
-        return value;
+    if (auto* fileInput = dynamicDowncast<FileInputType>(*m_inputType))
+        return fileInput->firstElementPathForInputValue();
 
-    value = m_valueIfDirty;
-    if (!value.isNull())
-        return value;
+    if (!m_valueIfDirty.isNull())
+        return m_valueIfDirty;
 
-    auto& valueString = attributeWithoutSynchronization(valueAttr);
-    value = sanitizeValue(valueString);
-    if (!value.isNull())
-        return value;
+    if (auto& valueString = attributeWithoutSynchronization(valueAttr); !valueString.isNull()) {
+        if (auto sanitizedValue = sanitizeValue(valueString); !sanitizedValue.isNull())
+            return sanitizedValue;
+    }
 
     return m_inputType->fallbackValue();
 }
@@ -1059,35 +1016,25 @@
 
 String HTMLInputElement::valueWithDefault() const
 {
-    String value = this->value();
-    if (!value.isNull())
+    if (auto value = this->value(); !value.isNull())
         return value;
 
     return m_inputType->defaultValue();
 }
 
-void HTMLInputElement::setValueForUser(const String& value)
-{
-    // Call setValue and make it send a change event.
-    setValue(value, DispatchChangeEvent);
-}
-
 ExceptionOr<void> HTMLInputElement::setValue(const String& value, TextFieldEventBehavior eventBehavior, TextControlSetValueSelection selection)
 {
     if (isFileUpload() && !value.isEmpty())
         return Exception { InvalidStateError };
 
-    if (!m_inputType->canSetValue(value))
-        return { };
-
-    Ref<HTMLInputElement> protectedThis(*this);
+    Ref protectedThis { *this };
     EventQueueScope scope;
-    String sanitizedValue = sanitizeValue(value);
+    auto sanitizedValue = sanitizeValue(value);
     bool valueChanged = sanitizedValue != this->value();
 
     setLastChangeWasNotUserEdit();
     setFormControlValueMatchesRenderer(false);
-    m_inputType->setValue(sanitizedValue, valueChanged, eventBehavior, selection);
+    m_inputType->setValue(WTFMove(sanitizedValue), valueChanged, eventBehavior, selection);
 
     bool wasModifiedProgrammatically = eventBehavior == DispatchNoEvent;
     if (wasModifiedProgrammatically) {
@@ -1191,22 +1138,22 @@
 
 void HTMLInputElement::defaultEventHandler(Event& event)
 {
-    if (is<MouseEvent>(event) && event.type() == eventNames().clickEvent && downcast<MouseEvent>(event).button() == LeftButton) {
-        m_inputType->handleClickEvent(downcast<MouseEvent>(event));
-        if (event.defaultHandled())
+    if (auto* mouseEvent = dynamicDowncast<MouseEvent>(event); mouseEvent && mouseEvent->type() == eventNames().clickEvent && mouseEvent->button() == LeftButton) {
+        m_inputType->handleClickEvent(*mouseEvent);
+        if (mouseEvent->defaultHandled())
             return;
     }
 
 #if ENABLE(TOUCH_EVENTS)
-    if (is<TouchEvent>(event)) {
-        m_inputType->handleTouchEvent(downcast<TouchEvent>(event));
+    if (auto* touchEvent = dynamicDowncast<TouchEvent>(event)) {
+        m_inputType->handleTouchEvent(*touchEvent);
         if (event.defaultHandled())
             return;
     }
 #endif
 
-    if (is<KeyboardEvent>(event) && event.type() == eventNames().keydownEvent) {
-        auto shouldCallBaseEventHandler = m_inputType->handleKeydownEvent(downcast<KeyboardEvent>(event));
+    if (auto* keyboardEvent = dynamicDowncast<KeyboardEvent>(event); keyboardEvent && keyboardEvent->type() == eventNames().keydownEvent) {
+        auto shouldCallBaseEventHandler = m_inputType->handleKeydownEvent(*keyboardEvent);
         if (event.defaultHandled() || shouldCallBaseEventHandler == InputType::ShouldCallBaseEventHandler::No)
             return;
     }
@@ -1232,15 +1179,14 @@
 
     // Use key press event here since sending simulated mouse events
     // on key down blocks the proper sending of the key press event.
-    if (is<KeyboardEvent>(event)) {
-        KeyboardEvent& keyboardEvent = downcast<KeyboardEvent>(event);
-        if (keyboardEvent.type() == eventNames().keypressEvent) {
-            m_inputType->handleKeypressEvent(keyboardEvent);
-            if (keyboardEvent.defaultHandled())
+    if (auto* keyboardEvent = dynamicDowncast<KeyboardEvent>(event)) {
+        if (keyboardEvent->type() == eventNames().keypressEvent) {
+            m_inputType->handleKeypressEvent(*keyboardEvent);
+            if (keyboardEvent->defaultHandled())
                 return;
-        } else if (keyboardEvent.type() == eventNames().keyupEvent) {
-            m_inputType->handleKeyupEvent(keyboardEvent);
-            if (keyboardEvent.defaultHandled())
+        } else if (keyboardEvent->type() == eventNames().keyupEvent) {
+            m_inputType->handleKeyupEvent(*keyboardEvent);
+            if (keyboardEvent->defaultHandled())
                 return;
         }
     }
@@ -1263,12 +1209,12 @@
         return;
     }
 
-    if (is<BeforeTextInsertedEvent>(event))
-        m_inputType->handleBeforeTextInsertedEvent(downcast<BeforeTextInsertedEvent>(event));
+    if (auto* beforeTextInsertedEvent = dynamicDowncast<BeforeTextInsertedEvent>(event); beforeTextInsertedEvent)
+        m_inputType->handleBeforeTextInsertedEvent(*beforeTextInsertedEvent);
 
-    if (is<MouseEvent>(event) && event.type() == eventNames().mousedownEvent) {
-        m_inputType->handleMouseDownEvent(downcast<MouseEvent>(event));
-        if (event.defaultHandled())
+    if (auto* mouseEvent = dynamicDowncast<MouseEvent>(event); mouseEvent && mouseEvent->type() == eventNames().mousedownEvent) {
+        m_inputType->handleMouseDownEvent(*mouseEvent);
+        if (mouseEvent->defaultHandled())
             return;
     }
 
@@ -1365,12 +1311,12 @@
     return types;
 }
 
-Vector<String> HTMLInputElement::acceptMIMETypes()
+Vector<String> HTMLInputElement::acceptMIMETypes() const
 {
     return parseAcceptAttribute(attributeWithoutSynchronization(acceptAttr), isValidMIMEType);
 }
 
-Vector<String> HTMLInputElement::acceptFileExtensions()
+Vector<String> HTMLInputElement::acceptFileExtensions() const
 {
     return parseAcceptAttribute(attributeWithoutSynchronization(acceptAttr), isValidFileExtension);
 }
@@ -1438,7 +1384,7 @@
 
 void HTMLInputElement::setShowAutoFillButton(AutoFillButtonType autoFillButtonType)
 {
-    if (static_cast<uint8_t>(autoFillButtonType) == m_autoFillButtonType)
+    if (autoFillButtonType == this->autoFillButtonType())
         return;
 
     m_lastAutoFillButtonType = m_autoFillButtonType;
@@ -1450,12 +1396,15 @@
 
 FileList* HTMLInputElement::files()
 {
-    return m_inputType->files();
+    if (auto* fileInputType = dynamicDowncast<FileInputType>(*m_inputType))
+        return &fileInputType->files();
+    return nullptr;
 }
 
 void HTMLInputElement::setFiles(RefPtr<FileList>&& files, WasSetByJavaScript wasSetByJavaScript)
 {
-    m_inputType->setFiles(WTFMove(files), wasSetByJavaScript);
+    if (auto* fileInputType = dynamicDowncast<FileInputType>(*m_inputType))
+        fileInputType->setFiles(WTFMove(files), wasSetByJavaScript);
 }
 
 #if ENABLE(DRAG_SUPPORT)
@@ -1475,11 +1424,6 @@
     return m_inputType->displayString();
 }
 
-bool HTMLInputElement::canReceiveDroppedFiles() const
-{
-    return m_canReceiveDroppedFiles;
-}
-
 void HTMLInputElement::setCanReceiveDroppedFiles(bool canReceiveDroppedFiles)
 {
     if (m_canReceiveDroppedFiles == canReceiveDroppedFiles)
@@ -1564,11 +1508,11 @@
 {
     // The type of the input element could have changed during event handling. If we are no longer
     // a search field, don't try to do search things.
-    if (!isSearchField())
+    auto* searchInputType = dynamicDowncast<SearchInputType>(*m_inputType);
+    if (!searchInputType)
         return;
 
-    if (m_inputType)
-        downcast<SearchInputType>(*m_inputType.get()).stopSearchEventTimer();
+    searchInputType->stopSearchEventTimer();
     dispatchEvent(Event::create(eventNames().searchEvent, Event::CanBubble::Yes, Event::IsCancelable::No));
 }
 
@@ -1590,13 +1534,10 @@
 #if ENABLE(INPUT_TYPE_COLOR)
 void HTMLInputElement::prepareForDocumentSuspension()
 {
-    if (!isColorControl())
-        return;
     m_inputType->detach();
 }
 #endif // ENABLE(INPUT_TYPE_COLOR)
 
-
 void HTMLInputElement::willChangeForm()
 {
     removeFromRadioButtonGroup();
@@ -1701,17 +1642,30 @@
 
 Color HTMLInputElement::valueAsColor() const
 {
-    return m_inputType->valueAsColor();
+#if ENABLE(INPUT_TYPE_COLOR)
+    if (auto* colorInputType = dynamicDowncast<ColorInputType>(*m_inputType))
+        return colorInputType->valueAsColor();
+#endif
+    return Color::transparentBlack;
 }
 
 void HTMLInputElement::selectColor(StringView color)
 {
-    m_inputType->selectColor(color);
+#if ENABLE(INPUT_TYPE_COLOR)
+    if (auto* colorInputType = dynamicDowncast<ColorInputType>(*m_inputType))
+        colorInputType->selectColor(color);
+#else
+    UNUSED_PARAM(color);
+#endif
 }
 
 Vector<Color> HTMLInputElement::suggestedColors() const
 {
-    return m_inputType->suggestedColors();
+#if ENABLE(INPUT_TYPE_COLOR)
+    if (auto* colorInputType = dynamicDowncast<ColorInputType>(*m_inputType))
+        return colorInputType->suggestedColors();
+#endif
+    return { };
 }
 
 #if ENABLE(DATALIST_ELEMENT)
@@ -1723,17 +1677,10 @@
 
 RefPtr<HTMLDataListElement> HTMLInputElement::dataList() const
 {
-    if (!m_hasNonEmptyList)
+    if (!m_hasNonEmptyList || !m_inputType->shouldRespectListAttribute())
         return nullptr;
 
-    if (!m_inputType->shouldRespectListAttribute())
-        return nullptr;
-
-    RefPtr<Element> element = treeScope().getElementById(attributeWithoutSynchronization(listAttr));
-    if (!is<HTMLDataListElement>(element))
-        return nullptr;
-
-    return downcast<HTMLDataListElement>(element.get());
+    return dynamicDowncast<HTMLDataListElement>(treeScope().getElementById(attributeWithoutSynchronization(listAttr)));
 }
 
 void HTMLInputElement::resetListAttributeTargetObserver()
@@ -1934,7 +1881,7 @@
 
 void HTMLInputElement::updateValueIfNeeded()
 {
-    String newValue = sanitizeValue(m_valueIfDirty);
+    auto newValue = sanitizeValue(m_valueIfDirty);
     ASSERT(!m_valueIfDirty.isNull() || newValue.isNull());
     if (newValue != m_valueIfDirty)
         setValue(newValue);
@@ -1982,7 +1929,7 @@
 bool HTMLInputElement::isInRequiredRadioButtonGroup()
 {
     ASSERT(isRadioButton());
-    if (RadioButtonGroups* buttons = radioButtonGroups())
+    if (auto* buttons = radioButtonGroups())
         return buttons->isInRequiredGroup(*this);
     return false;
 }
@@ -1989,10 +1936,9 @@
 
 Vector<Ref<HTMLInputElement>> HTMLInputElement::radioButtonGroup() const
 {
-    RadioButtonGroups* buttons = radioButtonGroups();
-    if (!buttons)
-        return { };
-    return buttons->groupMembers(*this);
+    if (auto* buttons = radioButtonGroups())
+        return buttons->groupMembers(*this);
+    return { };
 }
 
 RefPtr<HTMLInputElement> HTMLInputElement::checkedRadioButtonForGroup() const
@@ -2003,7 +1949,7 @@
         return const_cast<HTMLInputElement*>(this);
 
     auto& name = this->name();
-    if (RadioButtonGroups* buttons = radioButtonGroups())
+    if (auto* buttons = radioButtonGroups())
         return buttons->checkedButtonForGroup(name);
 
     if (name.isEmpty())

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (293947 => 293948)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2022-05-07 05:27:43 UTC (rev 293947)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2022-05-07 17:34:11 UTC (rev 293948)
@@ -96,11 +96,8 @@
 
     bool isPresentingAttachedView() const;
 
-    // stepUp()/stepDown() for user-interaction.
-    bool isSteppable() const;
-
+    bool isSteppable() const; // stepUp()/stepDown() for user-interaction.
     bool isTextButton() const;
-
     bool isRadioButton() const;
     WEBCORE_EXPORT bool isTextField() const final;
     WEBCORE_EXPORT bool isSearchField() const;
@@ -108,17 +105,14 @@
     WEBCORE_EXPORT bool isPasswordField() const;
     bool isCheckbox() const;
     bool isRangeControl() const;
-
 #if ENABLE(INPUT_TYPE_COLOR)
     WEBCORE_EXPORT bool isColorControl() const;
 #endif
-
     // FIXME: It's highly likely that any call site calling this function should instead
     // be using a different one. Many input elements behave like text fields, and in addition
     // any unknown input type is treated as text. Consider, for example, isTextField or
     // isTextField && !isPasswordField.
     WEBCORE_EXPORT bool isText() const;
-
     WEBCORE_EXPORT bool isEmailField() const;
     WEBCORE_EXPORT bool isFileUpload() const;
     bool isImageButton() const;
@@ -164,7 +158,7 @@
     bool matchesIndeterminatePseudoClass() const final;
     bool shouldAppearIndeterminate() const final;
 
-    WEBCORE_EXPORT unsigned size() const;
+    unsigned size() const { return m_size; }
     bool sizeShouldIncludeDecoration(int& preferredSize) const;
     float decorationWidth() const;
 
@@ -172,11 +166,11 @@
 
     WEBCORE_EXPORT String value() const final;
     WEBCORE_EXPORT ExceptionOr<void> setValue(const String&, TextFieldEventBehavior = DispatchNoEvent, TextControlSetValueSelection = TextControlSetValueSelection::SetSelectionToEnd) final;
-    WEBCORE_EXPORT void setValueForUser(const String&);
+    void setValueForUser(const String& value) { setValue(value, DispatchChangeEvent); }
     // Checks if the specified string would be a valid value.
     // We should not call this for types with no string value such as CHECKBOX and RADIO.
     bool isValidValue(const String&) const;
-    bool hasDirtyValue() const { return !m_valueIfDirty.isNull(); };
+    bool hasDirtyValue() const { return !m_valueIfDirty.isNull(); }
 
     String placeholder() const;
 
@@ -226,8 +220,8 @@
     WEBCORE_EXPORT const AtomString& defaultValue() const;
     WEBCORE_EXPORT void setDefaultValue(const AtomString&);
 
-    Vector<String> acceptMIMETypes();
-    Vector<String> acceptFileExtensions();
+    Vector<String> acceptMIMETypes() const;
+    Vector<String> acceptFileExtensions() const;
     String accept() const;
     WEBCORE_EXPORT String alt() const;
 
@@ -239,27 +233,22 @@
 
     WEBCORE_EXPORT bool multiple() const;
 
+    // AutoFill.
     bool isAutoFilled() const { return m_isAutoFilled; }
     WEBCORE_EXPORT void setAutoFilled(bool = true);
-
     bool isAutoFilledAndViewable() const { return m_isAutoFilledAndViewable; }
     WEBCORE_EXPORT void setAutoFilledAndViewable(bool = true);
-
     bool isAutoFilledAndObscured() const { return m_isAutoFilledAndObscured; }
     WEBCORE_EXPORT void setAutoFilledAndObscured(bool = true);
-
     AutoFillButtonType lastAutoFillButtonType() const { return static_cast<AutoFillButtonType>(m_lastAutoFillButtonType); }
     AutoFillButtonType autoFillButtonType() const { return static_cast<AutoFillButtonType>(m_autoFillButtonType); }
     WEBCORE_EXPORT void setShowAutoFillButton(AutoFillButtonType);
-
     bool hasAutoFillStrongPasswordButton() const  { return autoFillButtonType() == AutoFillButtonType::StrongPassword; }
-
     bool isAutoFillAvailable() const { return m_isAutoFillAvailable; }
     void setAutoFillAvailable(bool autoFillAvailable) { m_isAutoFillAvailable = autoFillAvailable; }
 
     WEBCORE_EXPORT FileList* files();
     WEBCORE_EXPORT void setFiles(RefPtr<FileList>&&, WasSetByJavaScript = WasSetByJavaScript::No);
-
     FileList* filesForBindings() { return files(); }
     void setFilesForBindings(RefPtr<FileList>&& fileList) { return setFiles(WTFMove(fileList), WasSetByJavaScript::Yes); }
 
@@ -273,7 +262,7 @@
 
     // These functions are used for rendering the input active during a
     // drag-and-drop operation.
-    bool canReceiveDroppedFiles() const;
+    bool canReceiveDroppedFiles() const { return m_canReceiveDroppedFiles; }
     void setCanReceiveDroppedFiles(bool);
 
     void addSearchResult();
@@ -313,7 +302,11 @@
     MediaCaptureType mediaCaptureType() const;
 #endif
 
-    static const unsigned maxEffectiveLength;
+    // FIXME: According to HTML4, the length attribute's value can be arbitrarily
+    // large. However, due to https://bugs.webkit.org/show_bug.cgi?id=14536 things
+    // get rather sluggish when a text field has a larger number of characters than
+    // this, even when just clicking in the text field.
+    static constexpr unsigned maxEffectiveLength = 524288;
 
     WEBCORE_EXPORT unsigned height() const;
     WEBCORE_EXPORT unsigned width() const;
@@ -370,6 +363,7 @@
 
 private:
     enum AutoCompleteSetting { Uninitialized, On, Off };
+    static constexpr int defaultSize = 20;
 
     void willChangeForm() final;
     void didChangeForm() final;
@@ -472,33 +466,33 @@
 
     AtomString m_name;
     String m_valueIfDirty;
-    unsigned m_size;
+    unsigned m_size { defaultSize };
     short m_maxResults { -1 };
-    bool m_isChecked : 1;
-    bool m_dirtyCheckednessFlag : 1;
-    bool m_isIndeterminate : 1;
-    bool m_hasType : 1;
-    bool m_isActivatedSubmit : 1;
-    unsigned m_autocomplete : 2; // AutoCompleteSetting
-    bool m_isAutoFilled : 1;
-    bool m_isAutoFilledAndViewable : 1;
-    bool m_isAutoFilledAndObscured : 1;
-    unsigned m_autoFillButtonType : 3; // AutoFillButtonType
-    unsigned m_lastAutoFillButtonType : 3; // AutoFillButtonType
-    bool m_isAutoFillAvailable : 1;
+    bool m_isChecked : 1 { false };
+    bool m_dirtyCheckednessFlag : 1 { false };
+    bool m_isIndeterminate : 1 { false };
+    bool m_hasType : 1 { false };
+    bool m_isActivatedSubmit : 1 { false };
+    unsigned m_autocomplete : 2 { Uninitialized }; // AutoCompleteSetting
+    bool m_isAutoFilled : 1 { false };
+    bool m_isAutoFilledAndViewable : 1 { false };
+    bool m_isAutoFilledAndObscured : 1 { false };
+    unsigned m_autoFillButtonType : 3 { static_cast<uint8_t>(AutoFillButtonType::None) }; // AutoFillButtonType
+    unsigned m_lastAutoFillButtonType : 3 { static_cast<uint8_t>(AutoFillButtonType::None) }; // AutoFillButtonType
+    bool m_isAutoFillAvailable : 1 { false };
 #if ENABLE(DATALIST_ELEMENT)
-    bool m_hasNonEmptyList : 1;
+    bool m_hasNonEmptyList : 1 { false };
 #endif
-    bool m_stateRestored : 1;
+    bool m_stateRestored : 1 { false };
     bool m_parsingInProgress : 1;
-    bool m_valueAttributeWasUpdatedAfterParsing : 1;
-    bool m_wasModifiedByUser : 1;
-    bool m_canReceiveDroppedFiles : 1;
+    bool m_valueAttributeWasUpdatedAfterParsing : 1 { false };
+    bool m_wasModifiedByUser : 1 { false };
+    bool m_canReceiveDroppedFiles : 1 { false };
 #if ENABLE(TOUCH_EVENTS)
-    bool m_hasTouchEventHandler : 1;
+    bool m_hasTouchEventHandler : 1 { false };
 #endif
-    bool m_isSpellcheckDisabledExceptTextReplacement : 1;
-    bool m_hasPendingUserAgentShadowTreeUpdate : 1;
+    bool m_isSpellcheckDisabledExceptTextReplacement : 1 { false };
+    bool m_hasPendingUserAgentShadowTreeUpdate : 1 { false };
     RefPtr<InputType> m_inputType;
     // The ImageLoader must be owned by this element because the loader code assumes
     // that it lives as long as its owning element lives. If we move the loader into

Modified: trunk/Source/WebCore/html/InputType.cpp (293947 => 293948)


--- trunk/Source/WebCore/html/InputType.cpp	2022-05-07 05:27:43 UTC (rev 293947)
+++ trunk/Source/WebCore/html/InputType.cpp	2022-05-07 17:34:11 UTC (rev 293948)
@@ -771,20 +771,6 @@
     return true;
 }
 
-FileList* InputType::files()
-{
-    return nullptr;
-}
-
-void InputType::setFiles(RefPtr<FileList>&&, WasSetByJavaScript)
-{
-}
-
-bool InputType::getTypeSpecificValue(String&)
-{
-    return false;
-}
-
 String InputType::fallbackValue() const
 {
     return String();
@@ -832,11 +818,6 @@
     }
 }
 
-bool InputType::canSetValue(const String&)
-{
-    return true;
-}
-
 void InputType::willDispatchClick(InputElementClickState&)
 {
 }
@@ -1184,20 +1165,6 @@
     }
 }
 
-Color InputType::valueAsColor() const
-{
-    return Color::transparentBlack;
-}
-
-void InputType::selectColor(StringView)
-{
-}
-
-Vector<Color> InputType::suggestedColors() const
-{
-    return { };
-}
-
 RefPtr<TextControlInnerTextElement> InputType::innerTextElement() const
 {
     return nullptr;

Modified: trunk/Source/WebCore/html/InputType.h (293947 => 293948)


--- trunk/Source/WebCore/html/InputType.h	2022-05-07 05:27:43 UTC (rev 293947)
+++ trunk/Source/WebCore/html/InputType.h	2022-05-07 17:34:11 UTC (rev 293948)
@@ -202,7 +202,6 @@
     bool isCheckable() const { return checkableTypes.contains(m_type); }
     bool isSteppable() const { return steppableTypes.contains(m_type); }
     bool supportsValidation() const { return !nonValidatingTypes.contains(m_type); }
-    bool canHaveTypeSpecificValue() const { return isFileUpload(); }
 
     Type type() const { return m_type; }
 
@@ -222,7 +221,6 @@
 
     // DOM property functions.
 
-    virtual bool getTypeSpecificValue(String&); // Checked first, before internal storage or the value attribute.
     virtual String fallbackValue() const; // Checked last, if both internal storage and value attribute are missing.
     virtual String defaultValue() const; // Checked after even fallbackValue, only when the valueWithDefault function is called.
     virtual WallTime valueAsDate() const;
@@ -280,7 +278,7 @@
     virtual bool allowsShowPickerAcrossFrames();
     virtual void showPicker();
 
-    enum ShouldCallBaseEventHandler { No, Yes };
+    enum ShouldCallBaseEventHandler : bool { No, Yes };
     virtual ShouldCallBaseEventHandler handleKeydownEvent(KeyboardEvent&);
 
     virtual void handleKeypressEvent(KeyboardEvent&);
@@ -342,11 +340,8 @@
     virtual void attach();
     virtual void detach();
     virtual bool shouldRespectAlignAttribute();
-    virtual FileList* files();
-    virtual void setFiles(RefPtr<FileList>&&, WasSetByJavaScript);
     virtual Icon* icon() const;
     virtual bool shouldSendChangeEventAfterCheckedChanged();
-    virtual bool canSetValue(const String&);
     virtual bool storesValueSeparateFromAttribute();
     virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior, TextControlSetValueSelection);
     virtual bool shouldResetOnDocumentActivation();
@@ -367,9 +362,6 @@
     virtual bool shouldAppearIndeterminate() const;
     virtual bool isPresentingAttachedView() const;
     virtual bool supportsSelectionAPI() const;
-    virtual Color valueAsColor() const;
-    virtual void selectColor(StringView);
-    virtual Vector<Color> suggestedColors() const;
 #if ENABLE(DATALIST_ELEMENT)
     virtual bool isFocusingWithDataListDropdown() const { return false; };
 #endif
@@ -411,9 +403,12 @@
     virtual String resultForDialogSubmit() const;
 
 protected:
-    explicit InputType(Type type, HTMLInputElement& element)
+    InputType(Type type, HTMLInputElement& element)
         : m_type(type)
-        , m_element(element) { }
+        , m_element(element)
+    {
+    }
+
     HTMLInputElement* element() const { return m_element.get(); }
     Chrome* chrome() const;
     Decimal parseToNumberOrNaN(const String&) const;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to