Title: [291609] trunk
Revision
291609
Author
z...@igalia.com
Date
2022-03-22 02:43:25 -0700 (Tue, 22 Mar 2022)

Log Message

[selection] Change form's selection attribute to unsigned long
https://bugs.webkit.org/show_bug.cgi?id=237951

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

Update test expectations as more sub-tests are now passing.
* web-platform-tests/html/semantics/forms/textfieldselection/selection-expected.txt:
* web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-expected.txt:
* web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange-expected.txt:

Source/WebCore:

We should change the type of attribute "selectionStart" and "selectionEnd"
from long to unsigned long. Also "start" and "end" parameters in function
selectionRange() need to be changed correspondingly.

This change is in line with Chromium CL at
https://github.com/chromium/chromium/commit/b6ff6db1c5683b5e564a72b0941ad504b410d1af

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::setDefaultSelectionAfterFocus):
(WebCore::HTMLInputElement::selectionStartForBindings const):
(WebCore::HTMLInputElement::setSelectionStartForBindings):
(WebCore::HTMLInputElement::selectionEndForBindings const):
(WebCore::HTMLInputElement::setSelectionEndForBindings):
(WebCore::HTMLInputElement::setSelectionRangeForBindings):
* html/HTMLInputElement.h:
* html/HTMLInputElement.idl:
* html/HTMLTextAreaElement.idl:
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::handleBeforeTextInsertedEvent):
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::HTMLTextFormControlElement):
(WebCore::HTMLTextFormControlElement::setSelectionStart):
(WebCore::HTMLTextFormControlElement::setSelectionEnd):
(WebCore::HTMLTextFormControlElement::select):
(WebCore::HTMLTextFormControlElement::setSelectionRange):
(WebCore::HTMLTextFormControlElement::selectionStart const):
(WebCore::HTMLTextFormControlElement::computeSelectionStart const):
(WebCore::HTMLTextFormControlElement::selectionEnd const):
(WebCore::HTMLTextFormControlElement::computeSelectionEnd const):
* html/HTMLTextFormControlElement.h:
(WebCore::HTMLTextFormControlElement::cacheSelection):
(WebCore::HTMLTextFormControlElement::hasCachedSelection const):

LayoutTests:

Update test accordingly. This is inline with Chromium.

Note that for selection-start-end-readonly.html, two sub-tests
are now failing. This is the right behaviour since the test assumes
types for selectionStart and selectionEnd as "int". We could modify the
test and make the type as unsigned. Interestingly the test script's
format is strange and it seems having "return" for each line. Simply updating
some lines on the test scripts causes errors when applying the patch. We have
decided to address this test in a separate patch (maybe remove the file and added
a new one with proper format).

* fast/forms/input-appearance-selection.html:
* fast/forms/selection-functions-expected.txt:
* fast/forms/selection-start-end-readonly-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (291608 => 291609)


--- trunk/LayoutTests/ChangeLog	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/LayoutTests/ChangeLog	2022-03-22 09:43:25 UTC (rev 291609)
@@ -1,3 +1,25 @@
+2022-03-22  Ziran Sun  <z...@igalia.com>
+
+        [selection] Change form's selection attribute to unsigned long
+        https://bugs.webkit.org/show_bug.cgi?id=237951
+
+        Reviewed by Chris Dumez.
+
+        Update test accordingly. This is inline with Chromium.
+
+        Note that for selection-start-end-readonly.html, two sub-tests
+        are now failing. This is the right behaviour since the test assumes
+        types for selectionStart and selectionEnd as "int". We could modify the
+        test and make the type as unsigned. Interestingly the test script's
+        format is strange and it seems having "return" for each line. Simply updating
+        some lines on the test scripts causes errors when applying the patch. We have
+        decided to address this test in a separate patch (maybe remove the file and added
+        a new one with proper format).
+        
+        * fast/forms/input-appearance-selection.html:
+        * fast/forms/selection-functions-expected.txt:
+        * fast/forms/selection-start-end-readonly-expected.txt:
+
 2022-03-21  Said Abou-Hallawa  <s...@apple.com>
 
         [GPU Process] Make GraphicsContextState keep track of changes till they are applied

Modified: trunk/LayoutTests/fast/forms/input-appearance-selection.html (291608 => 291609)


--- trunk/LayoutTests/fast/forms/input-appearance-selection.html	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/LayoutTests/fast/forms/input-appearance-selection.html	2022-03-22 09:43:25 UTC (rev 291609)
@@ -11,8 +11,8 @@
     testSelectionRange(4, 10, 3, 3, 3, testField, results);
     testSelectionEnd(5, 2, 2, 2, testField, results);
     testSelectionRange(6, 5, 4, 4, 4, testField, results);
-    testSelectionRange(7, -5, -4, 0, 0, testField, results);
-    testSelectionRange(8, -5, 80, 0, 20, testField, results);
+    testSelectionRange(7, -5, -4, 20, 20, testField, results);
+    testSelectionRange(8, -5, 80, 20, 20, testField, results);
     testSelectionRange(9, 3, 12, 3, 12, testField, results);
 
 }

Modified: trunk/LayoutTests/fast/forms/selection-functions-expected.txt (291608 => 291609)


--- trunk/LayoutTests/fast/forms/selection-functions-expected.txt	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/LayoutTests/fast/forms/selection-functions-expected.txt	2022-03-22 09:43:25 UTC (rev 291609)
@@ -6,7 +6,7 @@
 ===textarea===
 setSelectionRange():
 3, 7
-0, 5
+5, 5
 42, 48
 2, 2
 
@@ -13,21 +13,21 @@
 selectionStart:
 3, 3
 7, 7
-0, 7
 48, 48
+48, 48
 3, 48
 
 selectionEnd:
 3, 5
 2, 2
-0, 0
-0, 48
+2, 48
+2, 48
 7, 7
 
 ===input===
 setSelectionRange():
 3, 7
-0, 5
+5, 5
 42, 48
 2, 2
 
@@ -34,15 +34,15 @@
 selectionStart:
 3, 3
 7, 7
-0, 7
 48, 48
+48, 48
 3, 48
 
 selectionEnd:
 3, 5
 2, 2
-0, 0
-0, 48
+2, 48
+2, 48
 7, 7
 
 ===button===

Modified: trunk/LayoutTests/fast/forms/selection-start-end-readonly-expected.txt (291608 => 291609)


--- trunk/LayoutTests/fast/forms/selection-start-end-readonly-expected.txt	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/LayoutTests/fast/forms/selection-start-end-readonly-expected.txt	2022-03-22 09:43:25 UTC (rev 291609)
@@ -18,7 +18,7 @@
 PASS element.selectionEnd is 5
 PASS element.selectionStart is 0
 PASS element.selectionEnd is 0
-PASS element.selectionStart is 0
+FAIL element.selectionStart should be 0 but it is 10
 PASS element.selectionEnd is 10
 PASS element.selectionStart is 0
 PASS element.selectionEnd is 10
@@ -32,7 +32,7 @@
 PASS element.selectionEnd is 5
 PASS element.selectionStart is 0
 PASS element.selectionEnd is 0
-PASS element.selectionStart is 0
+FAIL element.selectionStart should be 0 but it is 10
 PASS element.selectionEnd is 10
 PASS successfullyParsed is true
 

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (291608 => 291609)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-03-22 09:43:25 UTC (rev 291609)
@@ -1,3 +1,15 @@
+2022-03-22  Ziran Sun  <z...@igalia.com>
+
+        [selection] Change form's selection attribute to unsigned long
+        https://bugs.webkit.org/show_bug.cgi?id=237951
+
+        Reviewed by Chris Dumez.
+
+        Update test expectations as more sub-tests are now passing.
+        * web-platform-tests/html/semantics/forms/textfieldselection/selection-expected.txt:
+        * web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-expected.txt:
+        * web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange-expected.txt:
+
 2022-03-21  Alex Christensen  <achristen...@webkit.org>
 
         Implement CSSNumericValue.mul, div, add, sub, max, and min

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-expected.txt (291608 => 291609)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-expected.txt	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-expected.txt	2022-03-22 09:43:25 UTC (rev 291609)
@@ -13,4 +13,8 @@
 FAIL test SelectionEnd offset for textarea that is  not appended assert_equals: SelectionEnd offset without selection in textarea-not-appended expected 10 but got 0
 PASS test SelectionDirection for input
 PASS test SelectionDirection for textarea
+PASS test scrollLeft for input
+PASS test scrollLeft preservation for input
+PASS test container.scrollTop for input
+PASS test container.scrollTop for textarea
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-expected.txt (291608 => 291609)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-expected.txt	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-start-end-expected.txt	2022-03-22 09:43:25 UTC (rev 291609)
@@ -40,8 +40,8 @@
 NOTRUN onselect should fire when selectionEnd is changed on
 PASS Setting selectionStart to a value larger than selectionEnd should increase selectionEnd
 PASS Setting selectionEnd to a value smaller than selectionStart should decrease selectionStart
-FAIL selectionStart edge-case values assert_equals: selectionStart setter on input-appended should convert -1 to 2^32-1 expected 10 but got 0
-FAIL selectionEnd edge-case values assert_equals: selectionEnd setter on input-appended should convert -1 to 2^32-1 expected 10 but got 0
+PASS selectionStart edge-case values
+PASS selectionEnd edge-case values
 PASS selectionStart should be clamped by the current value length
 PASS selectionEnd should be clamped by the current value length
 PASS setSelectionRange should be clamped by the current value length

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange-expected.txt (291608 => 291609)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange-expected.txt	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/textfieldselection-setSelectionRange-expected.txt	2022-03-22 09:43:25 UTC (rev 291609)
@@ -16,8 +16,8 @@
 PASS input direction of setSelectionRange(0,1,"hoge")
 PASS input direction of setSelectionRange(0,1,"BACKWARD")
 PASS input direction of setSelectionRange(0,1)
-FAIL input setSelectionRange(1,-1) assert_equals: element.selectionStart should be 1 expected 1 but got 0
-FAIL input setSelectionRange(-1,1) assert_equals: ECMAScript conversion to unsigned long + if end is less than or equal to start then the start of the selection and the end of the selection must both be placed immediately before the character with offset end expected 1 but got 0
+PASS input setSelectionRange(1,-1)
+PASS input setSelectionRange(-1,1)
 PASS input setSelectionRange("string",1)
 PASS input setSelectionRange(true,1)
 PASS input setSelectionRange([],1)
@@ -25,8 +25,8 @@
 PASS input setSelectionRange(NaN,1)
 PASS input setSelectionRange(null,1)
 PASS input setSelectionRange(undefined,1)
-FAIL input setSelectionRange(Math.pow(2,32) - 2, Math.pow(2,32) - 1) assert_equals: element.selectionStart should be value.length expected 5 but got 0
-FAIL input setSelectionRange(Math.pow(2,31), Math.pow(2,32) - 1) assert_equals: element.selectionStart should be value.length expected 5 but got 0
+PASS input setSelectionRange(Math.pow(2,32) - 2, Math.pow(2,32) - 1)
+PASS input setSelectionRange(Math.pow(2,31), Math.pow(2,32) - 1)
 TIMEOUT input setSelectionRange fires a select event Test timed out
 PASS test of textarea.setSelectionRange
 PASS textarea typeof(input.setSelectionRange)'
@@ -48,6 +48,6 @@
 PASS textarea setSelectionRange(NaN,1)
 PASS textarea setSelectionRange(null,1)
 PASS textarea setSelectionRange(undefined,1)
-FAIL textarea setSelectionRange(Math.pow(2,32) - 2, Math.pow(2,32) - 1) assert_equals: element.selectionStart should be value.length expected 5 but got 0
-FAIL textarea setSelectionRange(Math.pow(2,31), Math.pow(2,32) - 1) assert_equals: element.selectionStart should be value.length expected 5 but got 0
+PASS textarea setSelectionRange(Math.pow(2,32) - 2, Math.pow(2,32) - 1)
+PASS textarea setSelectionRange(Math.pow(2,31), Math.pow(2,32) - 1)
 

Modified: trunk/Source/WebCore/ChangeLog (291608 => 291609)


--- trunk/Source/WebCore/ChangeLog	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/Source/WebCore/ChangeLog	2022-03-22 09:43:25 UTC (rev 291609)
@@ -1,3 +1,43 @@
+2022-03-22  Ziran Sun  <z...@igalia.com>
+
+        [selection] Change form's selection attribute to unsigned long
+        https://bugs.webkit.org/show_bug.cgi?id=237951
+
+        Reviewed by Chris Dumez.
+
+        We should change the type of attribute "selectionStart" and "selectionEnd"
+        from long to unsigned long. Also "start" and "end" parameters in function
+        selectionRange() need to be changed correspondingly.
+        
+        This change is in line with Chromium CL at
+        https://github.com/chromium/chromium/commit/b6ff6db1c5683b5e564a72b0941ad504b410d1af
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::setDefaultSelectionAfterFocus):
+        (WebCore::HTMLInputElement::selectionStartForBindings const):
+        (WebCore::HTMLInputElement::setSelectionStartForBindings):
+        (WebCore::HTMLInputElement::selectionEndForBindings const):
+        (WebCore::HTMLInputElement::setSelectionEndForBindings):
+        (WebCore::HTMLInputElement::setSelectionRangeForBindings):
+        * html/HTMLInputElement.h:
+        * html/HTMLInputElement.idl:
+        * html/HTMLTextAreaElement.idl:
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::handleBeforeTextInsertedEvent):
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::HTMLTextFormControlElement):
+        (WebCore::HTMLTextFormControlElement::setSelectionStart):
+        (WebCore::HTMLTextFormControlElement::setSelectionEnd):
+        (WebCore::HTMLTextFormControlElement::select):
+        (WebCore::HTMLTextFormControlElement::setSelectionRange):
+        (WebCore::HTMLTextFormControlElement::selectionStart const):
+        (WebCore::HTMLTextFormControlElement::computeSelectionStart const):
+        (WebCore::HTMLTextFormControlElement::selectionEnd const):
+        (WebCore::HTMLTextFormControlElement::computeSelectionEnd const):
+        * html/HTMLTextFormControlElement.h:
+        (WebCore::HTMLTextFormControlElement::cacheSelection):
+        (WebCore::HTMLTextFormControlElement::hasCachedSelection const):
+
 2022-03-22  Diego Pino Garcia  <dp...@igalia.com>
 
         Unreviewed, fix non-unified build after r291597

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (291608 => 291609)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2022-03-22 09:43:25 UTC (rev 291609)
@@ -492,14 +492,14 @@
 void HTMLInputElement::setDefaultSelectionAfterFocus(SelectionRestorationMode restorationMode, SelectionRevealMode revealMode)
 {
     ASSERT(isTextField());
-    int start = 0;
+    unsigned start = 0;
     auto direction = SelectionHasNoDirection;
     auto* frame = document().frame();
     if (frame && frame->editor().behavior().shouldMoveSelectionToEndWhenFocusingTextInput()) {
-        start = std::numeric_limits<int>::max();
+        start = std::numeric_limits<unsigned>::max();
         direction = SelectionHasForwardDirection;
     }
-    int end = restorationMode == SelectionRestorationMode::PlaceCaretAtStart ? start : std::numeric_limits<int>::max();
+    unsigned end = restorationMode == SelectionRestorationMode::PlaceCaretAtStart ? start : std::numeric_limits<unsigned>::max();
     setSelectionRange(start, end, direction, revealMode, Element::defaultFocusTextStateChangeIntent());
 }
 
@@ -2081,7 +2081,7 @@
         invalidateStyleForSubtreeInternal();
 }
 
-std::optional<int> HTMLInputElement::selectionStartForBindings() const
+std::optional<unsigned> HTMLInputElement::selectionStartForBindings() const
 {
     if (!canHaveSelection() || !m_inputType->supportsSelectionAPI())
         return std::nullopt;
@@ -2089,7 +2089,7 @@
     return selectionStart();
 }
 
-ExceptionOr<void> HTMLInputElement::setSelectionStartForBindings(std::optional<int> start)
+ExceptionOr<void> HTMLInputElement::setSelectionStartForBindings(std::optional<unsigned> start)
 {
     if (!canHaveSelection() || !m_inputType->supportsSelectionAPI())
         return Exception { InvalidStateError, "The input element's type ('" + m_inputType->formControlType() + "') does not support selection." };
@@ -2098,7 +2098,7 @@
     return { };
 }
 
-std::optional<int> HTMLInputElement::selectionEndForBindings() const
+std::optional<unsigned> HTMLInputElement::selectionEndForBindings() const
 {
     if (!canHaveSelection() || !m_inputType->supportsSelectionAPI())
         return std::nullopt;
@@ -2106,7 +2106,7 @@
     return selectionEnd();
 }
 
-ExceptionOr<void> HTMLInputElement::setSelectionEndForBindings(std::optional<int> end)
+ExceptionOr<void> HTMLInputElement::setSelectionEndForBindings(std::optional<unsigned> end)
 {
     if (!canHaveSelection() || !m_inputType->supportsSelectionAPI())
         return Exception { InvalidStateError, "The input element's type ('" + m_inputType->formControlType() + "') does not support selection." };
@@ -2132,7 +2132,7 @@
     return { };
 }
 
-ExceptionOr<void> HTMLInputElement::setSelectionRangeForBindings(int start, int end, const String& direction)
+ExceptionOr<void> HTMLInputElement::setSelectionRangeForBindings(unsigned start, unsigned end, const String& direction)
 {
     if (!canHaveSelection() || !m_inputType->supportsSelectionAPI())
         return Exception { InvalidStateError, "The input element's type ('" + m_inputType->formControlType() + "') does not support selection." };

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (291608 => 291609)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2022-03-22 09:43:25 UTC (rev 291609)
@@ -344,16 +344,16 @@
     bool shouldTruncateText(const RenderStyle&) const;
     void invalidateStyleOnFocusChangeIfNeeded();
 
-    std::optional<int> selectionStartForBindings() const;
-    ExceptionOr<void> setSelectionStartForBindings(std::optional<int>);
+    std::optional<unsigned> selectionStartForBindings() const;
+    ExceptionOr<void> setSelectionStartForBindings(std::optional<unsigned>);
 
-    std::optional<int> selectionEndForBindings() const;
-    ExceptionOr<void> setSelectionEndForBindings(std::optional<int>);
+    std::optional<unsigned> selectionEndForBindings() const;
+    ExceptionOr<void> setSelectionEndForBindings(std::optional<unsigned>);
 
     ExceptionOr<String> selectionDirectionForBindings() const;
     ExceptionOr<void> setSelectionDirectionForBindings(const String&);
 
-    ExceptionOr<void> setSelectionRangeForBindings(int start, int end, const String& direction);
+    ExceptionOr<void> setSelectionRangeForBindings(unsigned start, unsigned end, const String& direction);
 
     String resultForDialogSubmit() const final;
 

Modified: trunk/Source/WebCore/html/HTMLInputElement.idl (291608 => 291609)


--- trunk/Source/WebCore/html/HTMLInputElement.idl	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/Source/WebCore/html/HTMLInputElement.idl	2022-03-22 09:43:25 UTC (rev 291609)
@@ -77,14 +77,14 @@
     readonly attribute NodeList labels;
 
     undefined select();
-    [ImplementedAs=selectionStartForBindings] attribute long? selectionStart;
-    [ImplementedAs=selectionEndForBindings] attribute long? selectionEnd;
+    [ImplementedAs=selectionStartForBindings] attribute unsigned long? selectionStart;
+    [ImplementedAs=selectionEndForBindings] attribute unsigned long? selectionEnd;
     [ImplementedAs=selectionDirectionForBindings] attribute DOMString? selectionDirection;
 
     undefined setRangeText(DOMString replacement);
     undefined setRangeText(DOMString replacement, unsigned long start, unsigned long end, optional DOMString selectionMode);
 
-    [ImplementedAs=setSelectionRangeForBindings] undefined setSelectionRange(long start, long end, optional DOMString direction);
+    [ImplementedAs=setSelectionRangeForBindings] undefined setSelectionRange(unsigned long start, unsigned long end, optional DOMString direction);
 
     [CEReactions=NotNeeded, Reflect] attribute DOMString align;
     [CEReactions=NotNeeded, Reflect] attribute DOMString useMap;

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.idl (291608 => 291609)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.idl	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.idl	2022-03-22 09:43:25 UTC (rev 291609)
@@ -50,14 +50,14 @@
     readonly attribute NodeList labels;
 
     undefined select();
-    attribute long selectionStart;
-    attribute long selectionEnd;
+    attribute unsigned long selectionStart;
+    attribute unsigned long selectionEnd;
     attribute DOMString selectionDirection;
 
     undefined setRangeText(DOMString replacement);
     undefined setRangeText(DOMString replacement, unsigned long start, unsigned long end, optional DOMString selectionMode);
 
-    undefined setSelectionRange(optional long start = 0, optional long end = 0, optional DOMString direction);
+    undefined setSelectionRange(optional unsigned long start = 0, optional unsigned long end = 0, optional DOMString direction);
 
     [CEReactions=NotNeeded] attribute DOMString autocomplete;
 };

Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp (291608 => 291609)


--- trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2022-03-22 09:43:25 UTC (rev 291609)
@@ -88,8 +88,8 @@
     , m_lastChangeWasUserEdit(false)
     , m_isPlaceholderVisible(false)
     , m_canShowPlaceholder(true)
-    , m_cachedSelectionStart(-1)
-    , m_cachedSelectionEnd(-1)
+    , m_cachedSelectionStart(0)
+    , m_cachedSelectionEnd(0)
 {
 }
 
@@ -195,12 +195,12 @@
     updatePlaceholderVisibility();
 }
 
-void HTMLTextFormControlElement::setSelectionStart(int start)
+void HTMLTextFormControlElement::setSelectionStart(unsigned start)
 {
     setSelectionRange(start, std::max(start, selectionEnd()), selectionDirection());
 }
 
-void HTMLTextFormControlElement::setSelectionEnd(int end)
+void HTMLTextFormControlElement::setSelectionEnd(unsigned end)
 {
     setSelectionRange(std::min(end, selectionStart()), end, selectionDirection());
 }
@@ -212,7 +212,7 @@
 
 void HTMLTextFormControlElement::select(SelectionRevealMode revealMode, const AXTextStateChangeIntent& intent)
 {
-    setSelectionRange(0, std::numeric_limits<int>::max(), SelectionHasNoDirection, revealMode, intent);
+    setSelectionRange(0, std::numeric_limits<unsigned>::max(), SelectionHasNoDirection, revealMode, intent);
 }
 
 String HTMLTextFormControlElement::selectedText() const
@@ -284,7 +284,7 @@
     return { };
 }
 
-void HTMLTextFormControlElement::setSelectionRange(int start, int end, const String& directionString, const AXTextStateChangeIntent& intent)
+void HTMLTextFormControlElement::setSelectionRange(unsigned start, unsigned end, const String& directionString, const AXTextStateChangeIntent& intent)
 {
     TextFieldSelectionDirection direction = SelectionHasNoDirection;
     if (directionString == "forward")
@@ -295,14 +295,15 @@
     return setSelectionRange(start, end, direction, SelectionRevealMode::DoNotReveal, intent);
 }
 
-void HTMLTextFormControlElement::setSelectionRange(int start, int end, TextFieldSelectionDirection direction, SelectionRevealMode revealMode, const AXTextStateChangeIntent& intent)
+void HTMLTextFormControlElement::setSelectionRange(unsigned start, unsigned end, TextFieldSelectionDirection direction, SelectionRevealMode revealMode, const AXTextStateChangeIntent& intent)
 {
     if (!isTextField())
         return;
 
     // Clamps to the current value length.
-    end = std::clamp(end, 0, clampTo<int>(innerTextValue().length()));
-    start = std::clamp(start, 0, end);
+    unsigned innerTextValueLength = innerTextValue().length();
+    end = std::min(end, innerTextValueLength);
+    start = std::min(start, end);
 
     auto innerText = innerTextElementCreatingShadowSubtreeIfNeeded();
     bool hasFocus = document().focusedElement() == this;
@@ -374,7 +375,7 @@
     return position;
 }
 
-int HTMLTextFormControlElement::selectionStart() const
+unsigned HTMLTextFormControlElement::selectionStart() const
 {
     if (!isTextField())
         return 0;
@@ -384,7 +385,7 @@
     return computeSelectionStart();
 }
 
-int HTMLTextFormControlElement::computeSelectionStart() const
+unsigned HTMLTextFormControlElement::computeSelectionStart() const
 {
     ASSERT(isTextField());
     RefPtr<Frame> frame = document().frame();
@@ -394,7 +395,7 @@
     return indexForPosition(frame->selection().selection().start());
 }
 
-int HTMLTextFormControlElement::selectionEnd() const
+unsigned HTMLTextFormControlElement::selectionEnd() const
 {
     if (!isTextField())
         return 0;
@@ -403,7 +404,7 @@
     return computeSelectionEnd();
 }
 
-int HTMLTextFormControlElement::computeSelectionEnd() const
+unsigned HTMLTextFormControlElement::computeSelectionEnd() const
 {
     ASSERT(isTextField());
     RefPtr<Frame> frame = document().frame();

Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.h (291608 => 291609)


--- trunk/Source/WebCore/html/HTMLTextFormControlElement.h	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.h	2022-03-22 09:43:25 UTC (rev 291609)
@@ -70,17 +70,17 @@
 
     int indexForVisiblePosition(const VisiblePosition&) const;
     WEBCORE_EXPORT VisiblePosition visiblePositionForIndex(int index) const;
-    WEBCORE_EXPORT int selectionStart() const;
-    WEBCORE_EXPORT int selectionEnd() const;
+    WEBCORE_EXPORT unsigned selectionStart() const;
+    WEBCORE_EXPORT unsigned selectionEnd() const;
     WEBCORE_EXPORT const AtomString& selectionDirection() const;
-    WEBCORE_EXPORT void setSelectionStart(int);
-    WEBCORE_EXPORT void setSelectionEnd(int);
+    WEBCORE_EXPORT void setSelectionStart(unsigned);
+    WEBCORE_EXPORT void setSelectionEnd(unsigned);
     WEBCORE_EXPORT void setSelectionDirection(const String&);
     WEBCORE_EXPORT void select(SelectionRevealMode = SelectionRevealMode::DoNotReveal, const AXTextStateChangeIntent& = AXTextStateChangeIntent());
     WEBCORE_EXPORT virtual ExceptionOr<void> setRangeText(const String& replacement);
     WEBCORE_EXPORT virtual ExceptionOr<void> setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode);
-    void setSelectionRange(int start, int end, const String& direction, const AXTextStateChangeIntent& = AXTextStateChangeIntent());
-    WEBCORE_EXPORT void setSelectionRange(int start, int end, TextFieldSelectionDirection = SelectionHasNoDirection, SelectionRevealMode = SelectionRevealMode::DoNotReveal, const AXTextStateChangeIntent& = AXTextStateChangeIntent());
+    void setSelectionRange(unsigned start, unsigned end, const String& direction, const AXTextStateChangeIntent& = AXTextStateChangeIntent());
+    WEBCORE_EXPORT void setSelectionRange(unsigned start, unsigned end, TextFieldSelectionDirection = SelectionHasNoDirection, SelectionRevealMode = SelectionRevealMode::DoNotReveal, const AXTextStateChangeIntent& = AXTextStateChangeIntent());
 
     std::optional<SimpleRange> selection() const;
     String selectedText() const;
@@ -122,10 +122,11 @@
         m_cachedSelectionStart = start;
         m_cachedSelectionEnd = end;
         m_cachedSelectionDirection = direction;
+        m_hasCachedSelection = true;
     }
 
     void restoreCachedSelection(SelectionRevealMode, const AXTextStateChangeIntent& = AXTextStateChangeIntent());
-    bool hasCachedSelection() const { return m_cachedSelectionStart >= 0; }
+    bool hasCachedSelection() const { return m_hasCachedSelection; }
 
     virtual void subtreeHasChanged() = 0;
 
@@ -143,8 +144,8 @@
 
     bool isTextFormControlElement() const final { return true; }
 
-    int computeSelectionStart() const;
-    int computeSelectionEnd() const;
+    unsigned computeSelectionStart() const;
+    unsigned computeSelectionEnd() const;
     TextFieldSelectionDirection computeSelectionDirection() const;
 
     void dispatchFocusEvent(RefPtr<Element>&& oldFocusedElement, const FocusOptions&) final;
@@ -173,11 +174,13 @@
 
     String m_textAsOfLastFormControlChangeEvent;
 
-    int m_cachedSelectionStart;
-    int m_cachedSelectionEnd;
+    unsigned m_cachedSelectionStart;
+    unsigned m_cachedSelectionEnd;
 
     int m_maxLength { -1 };
     int m_minLength { -1 };
+
+    bool m_hasCachedSelection { false };
 };
 
 WEBCORE_EXPORT HTMLTextFormControlElement* enclosingTextFormControl(const Position&);

Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (291608 => 291609)


--- trunk/Source/WebCore/html/TextFieldInputType.cpp	2022-03-22 08:51:33 UTC (rev 291608)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp	2022-03-22 09:43:25 UTC (rev 291609)
@@ -606,7 +606,7 @@
     unsigned selectionLength = 0;
     if (element()->focused()) {
         ASSERT(enclosingTextFormControl(element()->document().frame()->selection().selection().start()) == element());
-        int selectionStart = element()->selectionStart();
+        unsigned selectionStart = element()->selectionStart();
         ASSERT(selectionStart <= element()->selectionEnd());
         int selectionCodeUnitCount = element()->selectionEnd() - selectionStart;
         selectionLength = selectionCodeUnitCount ? numGraphemeClusters(StringView(innerText).substring(selectionStart, selectionCodeUnitCount)) : 0;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to