Skip to content
Permalink
Browse files
Improve <textarea> validation performance
https://bugs.webkit.org/show_bug.cgi?id=248447
rdar://problem/102909909

Reviewed by Ryosuke Niwa.

Added laziness to the HTMLTextAreaElement computation of validity. Also did style
tweaks and minor reorganization of the two text form element classes.

* Source/WebCore/html/FileInputType.cpp: Added include of FileChooser.h.
(WebCore::FileInputType::applyFileChooserSettings): Update to pass reference.

* Source/WebCore/html/FormController.cpp: Added include of FileChooser.h.

* Source/WebCore/html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::capsLockIndicatorElement const): Deleted.
(WebCore::HTMLInputElement::accept const): Deleted.
(WebCore::HTMLInputElement::isInRequiredRadioButtonGroup): Deleted.
(WebCore::HTMLInputElement::setRangeText): Removed unneeded overload and let
the base class version of setRangeText call the virtual one.

* Source/WebCore/html/HTMLInputElement.h: Removed unneeded includes.
Moved the functions for the IDL file to the top of the class, sorted in the
order that matches the IDL. Removed a few unused functions. Made three
public functions private. Tweaked comments.

* Source/WebCore/html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::HTMLTextAreaElement): Removed the tag name argument.
(WebCore::HTMLTextAreaElement::create): Updated to not pass the tag name to the constructor.
(WebCore::HTMLTextAreaElement::formControlType const): Use textareaTag so we don't need a global.
(WebCore::HTMLTextAreaElement::collectPresentationalHintsForAttribute): Moved body of the
shouldWrapText in.
(WebCore::HTMLTextAreaElement::parseAttribute): Moved the bodies of maxLengthAttributeChanged,
and minLengthAttributeChanged in.
(WebCore::HTMLTextAreaElement::maxLengthAttributeChanged): Deleted.
(WebCore::HTMLTextAreaElement::minLengthAttributeChanged): Deleted.
(WebCore::HTMLTextAreaElement::appendFormData): Tweaked coding style.
(WebCore::HTMLTextAreaElement::hasCustomFocusLogic const): Moved to the class definition.
(WebCore::HTMLTextAreaElement::defaultTabIndex const): Ditto.
(WebCore::HTMLTextAreaElement::isKeyboardFocusable const): Ditto.
(WebCore::HTMLTextAreaElement::isMouseFocusable const): Ditto.
(WebCore::HTMLTextAreaElement::handleBeforeTextInsertedEvent const): Call maxLength. Merge in the
sanitizeUserInputValue function.
(WebCore::HTMLTextAreaElement::sanitizeUserInputValue): Deleted.
(WebCore::HTMLTextAreaElement::rendererWillBeDestroyed): Moved to the class definition.
(WebCore::HTMLTextAreaElement::validationMessage const): Call maxLength.
(WebCore::HTMLTextAreaElement::valueMissing const): Pass null string for value, so the value will
be computed lazily. In the overload that takes a StringView, get the value lazily.
(WebCore::HTMLTextAreaElement::tooShort const): Ditto.
(WebCore::HTMLTextAreaElement::tooLong const): Ditto.
(WebCore::HTMLTextAreaElement::isValidValue const): Change type to StringView.
(WebCore::HTMLTextAreaElement::shouldUseInputMethod): Moved to the class definition.
(WebCore::HTMLTextAreaElement::placeholderElement const): Ditto.
(WebCore::HTMLTextAreaElement::matchesReadWritePseudoClass const): Ditto.
(WebCore::HTMLTextAreaElement::willRespondToMouseClickEventsWithEditability const): Ditto.

* Source/WebCore/html/HTMLTextAreaElement.h: Removed unneeded include. Moved the functions for the
IDL file to the top of the class, sorted in the order that matches the IDL. Removed some functions.
Moved some function bodies here. Use StringView more often.

* Source/WebCore/html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::setRangeText): Take StringView.

* Source/WebCore/html/HTMLTextFormControlElement.h: Changed setRangeText to take a StringView.
Also made the single argument form non-virtual.

* Source/WebCore/html/InputType.h:
(WebCore::InputType::capsLockIndicatorElement const): Deleted.
* Source/WebCore/html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::capsLockIndicatorElement const): Deleted.
* Source/WebCore/html/TextFieldInputType.h: Deleted capsLockIndicatorElement.

* Source/WebCore/loader/EmptyClients.cpp: Deleted unneeded includes.
* Source/WebCore/page/Chrome.cpp: Ditto.

* Source/WebCore/platform/FileChooser.cpp:
(WebCore::FileChooser::FileChooser): Take a reference.
(WebCore::FileChooser::create): Ditto.

* Source/WebCore/platform/FileChooser.h: Updated for the above.

* Source/WebKitLegacy/mac/DOM/DOMHTMLInputElement.mm:
(-[DOMHTMLInputElement setRangeText:]): Create a String explicitly since the function now
takes a StringView.
(-[DOMHTMLInputElement setRangeText:start🔚selectionMode:]): Ditto.
* Source/WebKitLegacy/mac/DOM/DOMHTMLTextAreaElement.mm:
(-[DOMHTMLTextAreaElement setRangeText:]): Ditto.
(-[DOMHTMLTextAreaElement setRangeText:start🔚selectionMode:]): Ditto.

Canonical link: https://commits.webkit.org/257417@main
  • Loading branch information
darinadler committed Dec 6, 2022
1 parent d531454 commit 95861845546f13626a0ea23d6eab4e513ff6f760
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 298 deletions.
@@ -31,6 +31,7 @@
#include "ElementRareData.h"
#include "Event.h"
#include "File.h"
#include "FileChooser.h"
#include "FileList.h"
#include "FormController.h"
#include "Frame.h"
@@ -343,7 +344,7 @@ void FileInputType::applyFileChooserSettings()
if (m_fileChooser)
m_fileChooser->invalidate();

m_fileChooser = FileChooser::create(this, fileChooserSettings());
m_fileChooser = FileChooser::create(*this, fileChooserSettings());
}

bool FileInputType::allowsDirectories() const
@@ -21,6 +21,7 @@
#include "config.h"
#include "FormController.h"

#include "FileChooser.h"
#include "HTMLFormElement.h"
#include "HTMLInputElement.h"
#include "ScriptDisallowedScope.h"
@@ -95,8 +96,6 @@ static std::optional<FormControlState> consumeSerializedFormControlState(AtomStr

// ----------------------------------------------------------------------------

// ----------------------------------------------------------------------------

class FormController::SavedFormState {
public:
static SavedFormState consumeSerializedState(AtomStringVectorReader&);
@@ -44,6 +44,7 @@
#include "Editor.h"
#include "ElementInlines.h"
#include "EventNames.h"
#include "FileChooser.h"
#include "FileInputType.h"
#include "FileList.h"
#include "FormController.h"
@@ -185,11 +186,6 @@ HTMLElement* HTMLInputElement::innerSpinButtonElement() const
return m_inputType->innerSpinButtonElement();
}

HTMLElement* HTMLInputElement::capsLockIndicatorElement() const
{
return m_inputType->capsLockIndicatorElement();
}

HTMLElement* HTMLInputElement::autoFillButtonElement() const
{
return m_inputType->autoFillButtonElement();
@@ -1345,11 +1341,6 @@ Vector<String> HTMLInputElement::acceptFileExtensions() const
return parseAcceptAttribute(attributeWithoutSynchronization(acceptAttr), isValidFileExtension);
}

String HTMLInputElement::accept() const
{
return attributeWithoutSynchronization(acceptAttr);
}

String HTMLInputElement::alt() const
{
return attributeWithoutSynchronization(altAttr);
@@ -1953,14 +1944,6 @@ MediaCaptureType HTMLInputElement::mediaCaptureType() const
}
#endif

bool HTMLInputElement::isInRequiredRadioButtonGroup()
{
ASSERT(isRadioButton());
if (auto* buttons = radioButtonGroups())
return buttons->isInRequiredGroup(*this);
return false;
}

Vector<Ref<HTMLInputElement>> HTMLInputElement::radioButtonGroup() const
{
if (auto* buttons = radioButtonGroups())
@@ -2053,15 +2036,7 @@ void ListAttributeTargetObserver::idTargetChanged()
}
#endif

ExceptionOr<void> HTMLInputElement::setRangeText(const String& replacement)
{
if (!m_inputType->supportsSelectionAPI())
return Exception { InvalidStateError };

return HTMLTextFormControlElement::setRangeText(replacement);
}

ExceptionOr<void> HTMLInputElement::setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode)
ExceptionOr<void> HTMLInputElement::setRangeText(StringView replacement, unsigned start, unsigned end, const String& selectionMode)
{
if (!m_inputType->supportsSelectionAPI())
return Exception { InvalidStateError };

0 comments on commit 9586184

Please sign in to comment.