Changeset 288005 in webkit


Ignore:
Timestamp:
Jan 13, 2022 7:14:33 PM (6 months ago)
Author:
Chris Dumez
Message:

Unable to have new lines in HTMLTextArea's placeholder text
https://bugs.webkit.org/show_bug.cgi?id=235205

Reviewed by Wenson Hsieh.

Source/WebCore:

Unlike the placeholder for HTMLInputElement, the placeholder for HTMLTextAreaElement needs
to allow new lines as per:

This aligns our behavior with Blink and Gecko.

No new tests, unskipped existing WPT tests.

  • html/HTMLInputElement.cpp:

(WebCore::HTMLInputElement::placeholder const):

  • html/HTMLInputElement.h:
  • html/HTMLTextAreaElement.cpp:

(WebCore::HTMLTextAreaElement::updatePlaceholderText):

  • html/HTMLTextFormControlElement.cpp:

(WebCore::HTMLTextFormControlElement::strippedPlaceholder const): Deleted.

  • html/HTMLTextFormControlElement.h:
  • html/TextFieldInputType.cpp:

(WebCore::TextFieldInputType::updatePlaceholderText):

LayoutTests:

Unskip WPT tests that are no longer failing.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r288003 r288005  
     12022-01-13  Chris Dumez  <cdumez@apple.com>
     2
     3        Unable to have new lines in HTMLTextArea's placeholder text
     4        https://bugs.webkit.org/show_bug.cgi?id=235205
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Unskip WPT tests that are no longer failing.
     9
     10        * TestExpectations:
     11
    1122022-01-13  Cameron McCormack  <heycam@apple.com>
    213
  • trunk/LayoutTests/TestExpectations

    r287977 r288005  
    752752imported/w3c/web-platform-tests/html/semantics/forms/the-select-element/reset-algorithm-rendering.html [ ImageOnlyFailure ]
    753753imported/w3c/web-platform-tests/html/semantics/forms/the-selectmenu-element/selectmenu-option-arbitrary-content-displayed.tentative.html [ ImageOnlyFailure ]
    754 imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/multiline-placeholder-cr.html [ ImageOnlyFailure ]
    755 imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/multiline-placeholder-crlf.html [ ImageOnlyFailure ]
    756 imported/w3c/web-platform-tests/html/semantics/forms/the-textarea-element/multiline-placeholder.html [ ImageOnlyFailure ]
    757754imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-popup-element/popup-hidden-display.tentative.html [ ImageOnlyFailure ]
    758755imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-popup-element/popup-initiallyopen-display.tentative.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r288004 r288005  
     12022-01-13  Chris Dumez  <cdumez@apple.com>
     2
     3        Unable to have new lines in HTMLTextArea's placeholder text
     4        https://bugs.webkit.org/show_bug.cgi?id=235205
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Unlike the placeholder for HTMLInputElement, the placeholder for HTMLTextAreaElement needs
     9        to allow new lines as per:
     10        - https://html.spec.whatwg.org/multipage/form-elements.html#attr-textarea-placeholder
     11
     12        This aligns our behavior with Blink and Gecko.
     13
     14        No new tests, unskipped existing WPT tests.
     15
     16        * html/HTMLInputElement.cpp:
     17        (WebCore::HTMLInputElement::placeholder const):
     18        * html/HTMLInputElement.h:
     19        * html/HTMLTextAreaElement.cpp:
     20        (WebCore::HTMLTextAreaElement::updatePlaceholderText):
     21        * html/HTMLTextFormControlElement.cpp:
     22        (WebCore::HTMLTextFormControlElement::strippedPlaceholder const): Deleted.
     23        * html/HTMLTextFormControlElement.h:
     24        * html/TextFieldInputType.cpp:
     25        (WebCore::TextFieldInputType::updatePlaceholderText):
     26
    1272022-01-13  Chris Dumez  <cdumez@apple.com>
    228
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r287818 r288005  
    21902190}
    21912191
     2192String HTMLInputElement::placeholder() const
     2193{
     2194    // According to the HTML5 specification, we need to remove CR and LF from
     2195    // the attribute value.
     2196    String attributeValue = attributeWithoutSynchronization(placeholderAttr);
     2197    return attributeValue.removeCharacters([](UChar c) {
     2198        return c == newlineCharacter || c == carriageReturn;
     2199    });
     2200}
     2201
    21922202} // namespace
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r287551 r288005  
    178178    bool hasDirtyValue() const { return !m_valueIfDirty.isNull(); };
    179179
     180    String placeholder() const;
     181
    180182    String sanitizeValue(const String&) const;
    181183
  • trunk/Source/WebCore/html/HTMLTextAreaElement.cpp

    r286447 r288005  
    539539void HTMLTextAreaElement::updatePlaceholderText()
    540540{
    541     String placeholderText = strippedPlaceholder();
     541    auto& placeholderText = attributeWithoutSynchronization(placeholderAttr);
    542542    if (placeholderText.isEmpty()) {
    543543        if (m_placeholder) {
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp

    r287520 r288005  
    132132}
    133133
    134 String HTMLTextFormControlElement::strippedPlaceholder() const
    135 {
    136     // According to the HTML5 specification, we need to remove CR and LF from
    137     // the attribute value.
    138     const AtomString& attributeValue = attributeWithoutSynchronization(placeholderAttr);
    139     if (!attributeValue.contains(newlineCharacter) && !attributeValue.contains(carriageReturn))
    140         return attributeValue;
    141 
    142     StringBuilder stripped;
    143     unsigned length = attributeValue.length();
    144     stripped.reserveCapacity(length);
    145     for (unsigned i = 0; i < length; ++i) {
    146         UChar character = attributeValue[i];
    147         if (character == newlineCharacter || character == carriageReturn)
    148             continue;
    149         stripped.append(character);
    150     }
    151     return stripped.toString();
    152 }
    153 
    154134static bool isNotLineBreak(UChar ch) { return ch != newlineCharacter && ch != carriageReturn; }
    155135
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.h

    r278253 r288005  
    6161    bool isPlaceholderVisible() const { return m_isPlaceholderVisible; }
    6262    virtual bool supportsPlaceholder() const = 0;
    63     String strippedPlaceholder() const;
    6463    virtual HTMLElement* placeholderElement() const = 0;
    6564    void updatePlaceholderVisibility();
  • trunk/Source/WebCore/html/TextFieldInputType.cpp

    r286447 r288005  
    620620        return;
    621621    ASSERT(element());
    622     String placeholderText = element()->strippedPlaceholder();
     622    String placeholderText = element()->placeholder();
    623623    if (placeholderText.isEmpty()) {
    624624        if (m_placeholder) {
Note: See TracChangeset for help on using the changeset viewer.