Commit 9cde715f authored by tkent's avatar tkent Committed by Commit bot

setSelectionRange() for INPUT and TEXTAREA should not set "none" direction on non-macOS platforms.

setSelectionRange(s, e) unexpectedly called the four-argument version of HTMLTextFormControlElement::setSelectionRange() with SelectionHasNoDirection.
So it set "none" direction without EditingBehavior check.

This CL renames the implementation function of web-exposed setSelectionRange() to
setSelectionRangeForBinding(), and makes its third argument optional so that
seSelectionRange(s, e) calls it.

On non-macOS platforms, two tests in textfieldselection-setSelectionRange.html
correctly fail.

BUG=640861

Review-Url: https://codereview.chromium.org/2274103002
Cr-Commit-Position: refs/heads/master@{#414306}
parent c3300bd4
...@@ -13,7 +13,7 @@ PASS input direction of setSelectionRange(0,1,"forward") ...@@ -13,7 +13,7 @@ PASS input direction of setSelectionRange(0,1,"forward")
FAIL input direction of setSelectionRange(0,1,"none") assert_equals: The direction of the selection must be set to forward if direction is a case-sensitive match for the string "none" expected "none" but got "forward" FAIL input direction of setSelectionRange(0,1,"none") assert_equals: The direction of the selection must be set to forward if direction is a case-sensitive match for the string "none" expected "none" but got "forward"
FAIL input direction of setSelectionRange(0,1,"hoge") assert_equals: otherwise expected "none" but got "forward" FAIL input direction of setSelectionRange(0,1,"hoge") assert_equals: otherwise expected "none" but got "forward"
FAIL input direction of setSelectionRange(0,1,"BACKWARD") assert_equals: selectionDirection should be 'none' expected "none" but got "forward" FAIL input direction of setSelectionRange(0,1,"BACKWARD") assert_equals: selectionDirection should be 'none' expected "none" but got "forward"
PASS input direction of setSelectionRange(0,1) FAIL input direction of setSelectionRange(0,1) assert_equals: if the argument is omitted expected "none" but got "forward"
FAIL input setSelectionRange(1,-1) assert_equals: element.selectionStart should be 1 expected 1 but got 0 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 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("string",1) PASS input setSelectionRange("string",1)
...@@ -36,7 +36,7 @@ PASS textarea direction of setSelectionRange(0,1,"forward") ...@@ -36,7 +36,7 @@ PASS textarea direction of setSelectionRange(0,1,"forward")
FAIL textarea direction of setSelectionRange(0,1,"none") assert_equals: The direction of the selection must be set to forward if direction is a case-sensitive match for the string "none" expected "none" but got "forward" FAIL textarea direction of setSelectionRange(0,1,"none") assert_equals: The direction of the selection must be set to forward if direction is a case-sensitive match for the string "none" expected "none" but got "forward"
FAIL textarea direction of setSelectionRange(0,1,"hoge") assert_equals: otherwise expected "none" but got "forward" FAIL textarea direction of setSelectionRange(0,1,"hoge") assert_equals: otherwise expected "none" but got "forward"
FAIL textarea direction of setSelectionRange(0,1,"BACKWARD") assert_equals: selectionDirection should be 'none' expected "none" but got "forward" FAIL textarea direction of setSelectionRange(0,1,"BACKWARD") assert_equals: selectionDirection should be 'none' expected "none" but got "forward"
PASS textarea direction of setSelectionRange(0,1) FAIL textarea direction of setSelectionRange(0,1) assert_equals: if the argument is omitted expected "none" but got "forward"
PASS textarea setSelectionRange("string",1) PASS textarea setSelectionRange("string",1)
PASS textarea setSelectionRange(true,1) PASS textarea setSelectionRange(true,1)
PASS textarea setSelectionRange([],1) PASS textarea setSelectionRange([],1)
......
...@@ -587,7 +587,7 @@ void HTMLInputElement::setSelectionRangeForBinding(int start, int end, Exception ...@@ -587,7 +587,7 @@ void HTMLInputElement::setSelectionRangeForBinding(int start, int end, Exception
exceptionState.throwDOMException(InvalidStateError, "The input element's type ('" + m_inputType->formControlType() + "') does not support selection."); exceptionState.throwDOMException(InvalidStateError, "The input element's type ('" + m_inputType->formControlType() + "') does not support selection.");
return; return;
} }
HTMLTextFormControlElement::setSelectionRange(start, end); HTMLTextFormControlElement::setSelectionRangeForBinding(start, end);
} }
void HTMLInputElement::setSelectionRangeForBinding(int start, int end, const String& direction, ExceptionState& exceptionState) void HTMLInputElement::setSelectionRangeForBinding(int start, int end, const String& direction, ExceptionState& exceptionState)
...@@ -596,7 +596,7 @@ void HTMLInputElement::setSelectionRangeForBinding(int start, int end, const Str ...@@ -596,7 +596,7 @@ void HTMLInputElement::setSelectionRangeForBinding(int start, int end, const Str
exceptionState.throwDOMException(InvalidStateError, "The input element's type ('" + m_inputType->formControlType() + "') does not support selection."); exceptionState.throwDOMException(InvalidStateError, "The input element's type ('" + m_inputType->formControlType() + "') does not support selection.");
return; return;
} }
HTMLTextFormControlElement::setSelectionRange(start, end, direction); HTMLTextFormControlElement::setSelectionRangeForBinding(start, end, direction);
} }
void HTMLInputElement::accessKeyAction(bool sendMouseEvents) void HTMLInputElement::accessKeyAction(bool sendMouseEvents)
......
...@@ -64,6 +64,7 @@ interface HTMLTextAreaElement : HTMLElement { ...@@ -64,6 +64,7 @@ interface HTMLTextAreaElement : HTMLElement {
optional SelectionMode selectionMode = "preserve"); optional SelectionMode selectionMode = "preserve");
// TODO(foolip): The start and end arguments should be unsigned long and // TODO(foolip): The start and end arguments should be unsigned long and
// should not be optional. // should not be optional.
[ImplementedAs=setSelectionRangeForBinding]
void setSelectionRange([Default=Undefined] optional long start, void setSelectionRange([Default=Undefined] optional long start,
[Default=Undefined] optional long end, [Default=Undefined] optional long end,
optional DOMString direction); optional DOMString direction);
......
...@@ -174,17 +174,17 @@ void HTMLTextFormControlElement::updatePlaceholderVisibility() ...@@ -174,17 +174,17 @@ void HTMLTextFormControlElement::updatePlaceholderVisibility()
void HTMLTextFormControlElement::setSelectionStart(int start) void HTMLTextFormControlElement::setSelectionStart(int start)
{ {
setSelectionRange(start, std::max(start, selectionEnd()), selectionDirection()); setSelectionRangeForBinding(start, std::max(start, selectionEnd()), selectionDirection());
} }
void HTMLTextFormControlElement::setSelectionEnd(int end) void HTMLTextFormControlElement::setSelectionEnd(int end)
{ {
setSelectionRange(std::min(end, selectionStart()), end, selectionDirection()); setSelectionRangeForBinding(std::min(end, selectionStart()), end, selectionDirection());
} }
void HTMLTextFormControlElement::setSelectionDirection(const String& direction) void HTMLTextFormControlElement::setSelectionDirection(const String& direction)
{ {
setSelectionRange(selectionStart(), selectionEnd(), direction); setSelectionRangeForBinding(selectionStart(), selectionEnd(), direction);
} }
void HTMLTextFormControlElement::select(NeedToDispatchSelectEvent eventBehaviour) void HTMLTextFormControlElement::select(NeedToDispatchSelectEvent eventBehaviour)
...@@ -263,7 +263,7 @@ void HTMLTextFormControlElement::setRangeText(const String& replacement, unsigne ...@@ -263,7 +263,7 @@ void HTMLTextFormControlElement::setRangeText(const String& replacement, unsigne
setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirection); setSelectionRange(newSelectionStart, newSelectionEnd, SelectionHasNoDirection);
} }
void HTMLTextFormControlElement::setSelectionRange(int start, int end, const String& directionString) void HTMLTextFormControlElement::setSelectionRangeForBinding(int start, int end, const String& directionString)
{ {
TextFieldSelectionDirection direction = SelectionHasNoDirection; TextFieldSelectionDirection direction = SelectionHasNoDirection;
if (directionString == "forward") if (directionString == "forward")
......
...@@ -70,7 +70,11 @@ public: ...@@ -70,7 +70,11 @@ public:
void select(NeedToDispatchSelectEvent = DispatchSelectEvent); void select(NeedToDispatchSelectEvent = DispatchSelectEvent);
virtual void setRangeText(const String& replacement, ExceptionState&); virtual void setRangeText(const String& replacement, ExceptionState&);
virtual void setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionState&); virtual void setRangeText(const String& replacement, unsigned start, unsigned end, const String& selectionMode, ExceptionState&);
void setSelectionRange(int start, int end, const String& direction); // Web-exposed setSelectionRange() function. This translates "none"
// direction to "forward" if necessary.
void setSelectionRangeForBinding(int start, int end, const String& direction = "none");
// Blink-internal version of setSelectionRange(). This never translates
// "none" direction.
void setSelectionRange(int start, int end, TextFieldSelectionDirection = SelectionHasNoDirection, NeedToDispatchSelectEvent = DispatchSelectEvent); void setSelectionRange(int start, int end, TextFieldSelectionDirection = SelectionHasNoDirection, NeedToDispatchSelectEvent = DispatchSelectEvent);
Range* selection() const; Range* selection() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment