Changeset 293673 in webkit
- Timestamp:
- May 2, 2022 12:12:06 PM (3 months ago)
- Location:
- trunk
- Files:
-
- 5 edited
-
LayoutTests/imported/w3c/ChangeLog (modified) (1 diff)
-
LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-extra-expected.txt (modified) (1 diff)
-
Source/WebCore/ChangeLog (modified) (1 diff)
-
Source/WebCore/html/HTMLTextAreaElement.cpp (modified) (3 diffs)
-
Source/WebCore/html/HTMLTextFormControlElement.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r293670 r293673 1 2022-05-02 Ziran Sun <zsun@igalia.com> 2 3 [selection] Set correct selection range for TEXTAREA when updating default value 4 https://bugs.webkit.org/show_bug.cgi?id=237525 5 6 Reviewed by Chris Dumez. 7 8 * web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-extra-expected.txt: 9 1 10 2022-05-02 Oriol Brufau <obrufau@igalia.com> 2 11 -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-extra-expected.txt
r291396 r293673 6 6 PASS Removing children from a textarea should NOT update selection{Start,End} 7 7 PASS Setting the same value (with different newlines) in a textarea should NOT update selection{Start,End} 8 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 8 PASS Removing child nodes in non-dirty textarea should make selection{Start,End} 0 9 9 PASS Setting value to a shorter string than defaultValue should correct the cursor position 10 10 PASS Shortening value by turning the input type into 'url' should correct selection{Start,End} -
trunk/Source/WebCore/ChangeLog
r293672 r293673 1 2022-05-02 Ziran Sun <zsun@igalia.com> 2 3 [selection] Set correct selection range for TEXTAREA when updating default value 4 https://bugs.webkit.org/show_bug.cgi?id=237525 5 6 Reviewed by Chris Dumez. 7 8 Updating defaultValue should keep selectionStart/End. We need clamp them if the new value is shorter than the 9 selectionStart/End. This change is to be in line with [1] & [2]. 10 11 [1] https://html.spec.whatwg.org/multipage/form-elements.html#the-textarea-element:dom-textarea-defaultvalue-2 12 [2] https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#textFieldSelection:concept-textarea/input-relevant-value 13 14 Part of this change is an import of Chromium CL at 15 https://github.com/chromium/chromium/commit/bb27a500d07f8b3c567e84857a40c3ce42fa454a 16 17 * html/HTMLTextAreaElement.cpp: 18 (WebCore::HTMLTextAreaElement::childrenChanged): 19 (WebCore::HTMLTextAreaElement::setValueCommon): 20 * html/HTMLTextFormControlElement.h: 21 1 22 2022-05-02 Fujii Hironori <Hironori.Fujii@sony.com> 2 23 -
trunk/Source/WebCore/html/HTMLTextAreaElement.cpp
r293656 r293673 137 137 setInnerTextValue(value()); 138 138 else 139 setNonDirtyValue(defaultValue(), TextControlSetValueSelection::DoNotSet);139 setNonDirtyValue(defaultValue(), TextControlSetValueSelection::Clamp); 140 140 } 141 141 … … 402 402 return; 403 403 404 bool shouldClamp = selection == TextControlSetValueSelection::Clamp; 405 auto selectionStartValue = shouldClamp ? computeSelectionStart() : 0; 406 auto selectionEndValue = shouldClamp ? computeSelectionEnd() : 0; 407 404 408 m_value = normalizedValue; 405 409 setInnerTextValue(String { m_value }); … … 409 413 setFormControlValueMatchesRenderer(true); 410 414 411 if (document().focusedElement() == this) {412 unsigned endOfString = m_value.length();415 auto endOfString = m_value.length(); 416 if (document().focusedElement() == this) 413 417 setSelectionRange(endOfString, endOfString); 414 }else if (selection == TextControlSetValueSelection::SetSelectionToEnd) {418 else if (selection == TextControlSetValueSelection::SetSelectionToEnd) { 415 419 // We don't change text selection here but need to update caret to 416 420 // the end of the text value except for initialize. 417 unsigned endOfString = m_value.length();418 421 cacheSelection(endOfString, endOfString, SelectionHasNoDirection); 419 } 422 } else if (shouldClamp) 423 cacheSelection(std::min(endOfString, selectionStartValue), std::min(endOfString, selectionEndValue), SelectionHasNoDirection); 420 424 421 425 setTextAsOfLastFormControlChangeEvent(normalizedValue); -
trunk/Source/WebCore/html/HTMLTextFormControlElement.h
r293059 r293673 40 40 enum TextFieldSelectionDirection { SelectionHasNoDirection, SelectionHasForwardDirection, SelectionHasBackwardDirection }; 41 41 enum TextFieldEventBehavior { DispatchNoEvent, DispatchChangeEvent, DispatchInputAndChangeEvent }; 42 enum TextControlSetValueSelection { SetSelectionToEnd, DoNotSet };42 enum TextControlSetValueSelection { SetSelectionToEnd, Clamp, DoNotSet }; 43 43 44 44 class HTMLTextFormControlElement : public HTMLFormControlElementWithState { … … 124 124 bool hasCachedSelection() const { return m_hasCachedSelection; } 125 125 126 unsigned computeSelectionStart() const; 127 unsigned computeSelectionEnd() const; 128 126 129 virtual void subtreeHasChanged() = 0; 127 130 … … 140 143 bool isTextFormControlElement() const final { return true; } 141 144 142 unsigned computeSelectionStart() const;143 unsigned computeSelectionEnd() const;144 145 TextFieldSelectionDirection computeSelectionDirection() const; 145 146
Note: See TracChangeset
for help on using the changeset viewer.