- Revision
- 293673
- Author
- z...@igalia.com
- Date
- 2022-05-02 12:12:06 -0700 (Mon, 02 May 2022)
Log Message
[selection] Set correct selection range for TEXTAREA when updating default value
https://bugs.webkit.org/show_bug.cgi?id=237525
Reviewed by Chris Dumez.
LayoutTests/imported/w3c:
* web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-extra-expected.txt:
Source/WebCore:
Updating defaultValue should keep selectionStart/End. We need clamp them if the new value is shorter than the
selectionStart/End. This change is to be in line with [1] & [2].
[1] https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element:dom-textarea-defaultvalue-2
[2] https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#textFieldSelection:concept-textarea/input-relevant-value
Part of this change is an import of Chromium CL at
https://github.com/chromium/chromium/commit/bb27a500d07f8b3c567e84857a40c3ce42fa454a
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::childrenChanged):
(WebCore::HTMLTextAreaElement::setValueCommon):
* html/HTMLTextFormControlElement.h:
Modified Paths
Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (293672 => 293673)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2022-05-02 19:01:44 UTC (rev 293672)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2022-05-02 19:12:06 UTC (rev 293673)
@@ -1,3 +1,12 @@
+2022-05-02 Ziran Sun <z...@igalia.com>
+
+ [selection] Set correct selection range for TEXTAREA when updating default value
+ https://bugs.webkit.org/show_bug.cgi?id=237525
+
+ Reviewed by Chris Dumez.
+
+ * web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-extra-expected.txt:
+
2022-05-02 Oriol Brufau <obru...@igalia.com>
[cssom] Enumerate all logical longhands in the computed style
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-extra-expected.txt (293672 => 293673)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-extra-expected.txt 2022-05-02 19:01:44 UTC (rev 293672)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-extra-expected.txt 2022-05-02 19:12:06 UTC (rev 293673)
@@ -5,7 +5,7 @@
PASS Adding children to a textarea should NOT move selection{Start,End} to the end
PASS Removing children from a textarea should NOT update selection{Start,End}
PASS Setting the same value (with different newlines) in a textarea should NOT update selection{Start,End}
-FAIL Removing child nodes in non-dirty textarea should make selection{Start,End} 0 assert_equals: selectionStart after node removal expected 0 but got 3
+PASS Removing child nodes in non-dirty textarea should make selection{Start,End} 0
PASS Setting value to a shorter string than defaultValue should correct the cursor position
PASS Shortening value by turning the input type into 'url' should correct selection{Start,End}
FAIL Shortening value by turning the input type into 'color' and back to 'text' should correct selection{Start,End} assert_equals: expected 0 but got 9
Modified: trunk/Source/WebCore/ChangeLog (293672 => 293673)
--- trunk/Source/WebCore/ChangeLog 2022-05-02 19:01:44 UTC (rev 293672)
+++ trunk/Source/WebCore/ChangeLog 2022-05-02 19:12:06 UTC (rev 293673)
@@ -1,3 +1,24 @@
+2022-05-02 Ziran Sun <z...@igalia.com>
+
+ [selection] Set correct selection range for TEXTAREA when updating default value
+ https://bugs.webkit.org/show_bug.cgi?id=237525
+
+ Reviewed by Chris Dumez.
+
+ Updating defaultValue should keep selectionStart/End. We need clamp them if the new value is shorter than the
+ selectionStart/End. This change is to be in line with [1] & [2].
+
+ [1] https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element:dom-textarea-defaultvalue-2
+ [2] https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#textFieldSelection:concept-textarea/input-relevant-value
+
+ Part of this change is an import of Chromium CL at
+ https://github.com/chromium/chromium/commit/bb27a500d07f8b3c567e84857a40c3ce42fa454a
+
+ * html/HTMLTextAreaElement.cpp:
+ (WebCore::HTMLTextAreaElement::childrenChanged):
+ (WebCore::HTMLTextAreaElement::setValueCommon):
+ * html/HTMLTextFormControlElement.h:
+
2022-05-02 Fujii Hironori <hironori.fu...@sony.com>
HTML Parser: Wrong column number in CR-LF line ending style (DOS EOL style) HTML files
Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (293672 => 293673)
--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp 2022-05-02 19:01:44 UTC (rev 293672)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp 2022-05-02 19:12:06 UTC (rev 293673)
@@ -136,7 +136,7 @@
if (m_isDirty)
setInnerTextValue(value());
else
- setNonDirtyValue(defaultValue(), TextControlSetValueSelection::DoNotSet);
+ setNonDirtyValue(defaultValue(), TextControlSetValueSelection::Clamp);
}
bool HTMLTextAreaElement::hasPresentationalHintsForAttribute(const QualifiedName& name) const
@@ -401,6 +401,10 @@
if (normalizedValue == value())
return;
+ bool shouldClamp = selection == TextControlSetValueSelection::Clamp;
+ auto selectionStartValue = shouldClamp ? computeSelectionStart() : 0;
+ auto selectionEndValue = shouldClamp ? computeSelectionEnd() : 0;
+
m_value = normalizedValue;
setInnerTextValue(String { m_value });
setLastChangeWasNotUserEdit();
@@ -408,15 +412,15 @@
invalidateStyleForSubtree();
setFormControlValueMatchesRenderer(true);
- if (document().focusedElement() == this) {
- unsigned endOfString = m_value.length();
+ auto endOfString = m_value.length();
+ if (document().focusedElement() == this)
setSelectionRange(endOfString, endOfString);
- } else if (selection == TextControlSetValueSelection::SetSelectionToEnd) {
+ else if (selection == TextControlSetValueSelection::SetSelectionToEnd) {
// We don't change text selection here but need to update caret to
// the end of the text value except for initialize.
- unsigned endOfString = m_value.length();
cacheSelection(endOfString, endOfString, SelectionHasNoDirection);
- }
+ } else if (shouldClamp)
+ cacheSelection(std::min(endOfString, selectionStartValue), std::min(endOfString, selectionEndValue), SelectionHasNoDirection);
setTextAsOfLastFormControlChangeEvent(normalizedValue);
}
Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.h (293672 => 293673)
--- trunk/Source/WebCore/html/HTMLTextFormControlElement.h 2022-05-02 19:01:44 UTC (rev 293672)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.h 2022-05-02 19:12:06 UTC (rev 293673)
@@ -39,7 +39,7 @@
enum class AutoFillButtonType : uint8_t { None, Credentials, Contacts, StrongPassword, CreditCard };
enum TextFieldSelectionDirection { SelectionHasNoDirection, SelectionHasForwardDirection, SelectionHasBackwardDirection };
enum TextFieldEventBehavior { DispatchNoEvent, DispatchChangeEvent, DispatchInputAndChangeEvent };
-enum TextControlSetValueSelection { SetSelectionToEnd, DoNotSet };
+enum TextControlSetValueSelection { SetSelectionToEnd, Clamp, DoNotSet };
class HTMLTextFormControlElement : public HTMLFormControlElementWithState {
WTF_MAKE_ISO_ALLOCATED(HTMLTextFormControlElement);
@@ -123,6 +123,9 @@
void restoreCachedSelection(SelectionRevealMode, const AXTextStateChangeIntent& = AXTextStateChangeIntent());
bool hasCachedSelection() const { return m_hasCachedSelection; }
+ unsigned computeSelectionStart() const;
+ unsigned computeSelectionEnd() const;
+
virtual void subtreeHasChanged() = 0;
void setLastChangeWasNotUserEdit() { m_lastChangeWasUserEdit = false; }
@@ -139,8 +142,6 @@
bool isTextFormControlElement() const final { return true; }
- unsigned computeSelectionStart() const;
- unsigned computeSelectionEnd() const;
TextFieldSelectionDirection computeSelectionDirection() const;
void dispatchFocusEvent(RefPtr<Element>&& oldFocusedElement, const FocusOptions&) final;