forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
walmart.com/wallet focuses phone number field when attempting to add …
…a credit card https://bugs.webkit.org/show_bug.cgi?id=284630 rdar://139075809 Reviewed by Ryosuke Niwa. Setting the selection should not focus unless there is an existing selection. This matches other browsers while preserving the principle that focus & selection must be in sync (by neither focusing or selecting). Notably, these APIs now have this behavior: - element.setSelectionRange() - element.selectionStart/selectionEnd setters - element.setRangeText() These APIs preserve the old behavior by focusing the text controls before selecting: - element.select() - accessibility APIs Here is the relevant Blink commits for the corresponding change there: chromium/chromium@5300153 In order to limit the risk of breakage in older macOS/iOS apps, this behavior is put behind a linked-on-or-after check. * LayoutTests/editing/async-clipboard/resources/async-clipboard-helpers.js: (async writeToClipboardUsingDataTransfer): * LayoutTests/editing/deleting/5290534.html: * LayoutTests/editing/inserting/4960120-1.html: * LayoutTests/editing/inserting/insert-text-into-text-field.html: * LayoutTests/editing/pasteboard/data-transfer-get-data-on-drop-plain-text.html: * LayoutTests/editing/pasteboard/data-transfer-get-data-on-paste-plain-text.html: * LayoutTests/editing/pasteboard/drag-drop-input-textarea.html: * LayoutTests/editing/pasteboard/drag-drop-url-text.html: * LayoutTests/editing/pasteboard/pasting-tabs.html: * LayoutTests/editing/selection/4975120.html: * LayoutTests/editing/selection/5497643-expected.txt: * LayoutTests/editing/selection/5497643.html: * LayoutTests/editing/selection/delete-selection-with-disconnected-extent.html: * LayoutTests/editing/selection/delete-word-granularity-text-control.html: * LayoutTests/editing/selection/deleteFromDocument-shadow-tree-crash.html: * LayoutTests/editing/selection/select-iframe-focusin-document-crash.html: * LayoutTests/editing/selection/selection-setSelectionRange-frameselection-expected.txt: Added. * LayoutTests/editing/selection/selection-setSelectionRange-frameselection.html: Added. * LayoutTests/editing/selection/setting-selection-does-not-focus-unless-selected-expected.txt: Added. * LayoutTests/editing/selection/setting-selection-does-not-focus-unless-selected.html: Added. * LayoutTests/editing/selection/shrink-selection-after-shift-pagedown.html: * LayoutTests/fast/css/content/content-on-focus-change.html: * LayoutTests/fast/events/context-no-deselect.html: * LayoutTests/fast/forms/datalist/datalist-idTargetChanged-crash.html: * LayoutTests/fast/forms/input-appearance-selection.html: * LayoutTests/fast/forms/input-delete.html: * LayoutTests/fast/forms/input-placeholder-visibility-2-expected.html: * LayoutTests/fast/forms/paste-into-textarea.html: * LayoutTests/fast/forms/textarea-arrow-navigation.html: * LayoutTests/fast/rendering/render-compositor-null-layer-crash.html: * LayoutTests/fast/text-extraction/basic-text-extraction.html: * LayoutTests/fast/text/out-of-flow-line-break-crash.html: * LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/textarea-scroll-selection-expected.txt: * LayoutTests/resources/accessibility-helper.js: * Source/WTF/wtf/cocoa/RuntimeApplicationChecksCocoa.h: * Source/WebCore/accessibility/AccessibilityRenderObject.cpp: (WebCore::AccessibilityRenderObject::setSelectedTextRange): (WebCore::AccessibilityRenderObject::setSelectedVisiblePositionRange const): * Source/WebCore/html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::select): (WebCore::HTMLTextFormControlElement::setSelectionRange): Canonical link: https://commits.webkit.org/287851@main
- Loading branch information
Showing
38 changed files
with
186 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
LayoutTests/editing/selection/selection-setSelectionRange-frameselection-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
PASS setSelectionRange() should not update FrameSelection if the target element is not focused. | ||
PASS setRangeText() should not update FrameSelection if the target element is not focused. | ||
|
38 changes: 38 additions & 0 deletions
38
LayoutTests/editing/selection/selection-setSelectionRange-frameselection.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
<script src="../../resources/testharness.js"></script> | ||
<script src="../../resources/testharnessreport.js"></script> | ||
<input id="notFocused" value="foo"> | ||
<input id="focused" value="a"> | ||
<script> | ||
test(() => { | ||
var notFocused = document.getElementById('notFocused'); | ||
var focused = document.getElementById('focused'); | ||
var selection = window.getSelection(); | ||
selection.removeAllRanges(); | ||
focused.focus(); | ||
|
||
var originalAnchorNode = selection.anchorNode; | ||
var originalAnchorOffset = selection.anchorOffset; | ||
notFocused.setSelectionRange(3, 3); | ||
assert_equals(selection.anchorNode, originalAnchorNode); | ||
assert_equals(selection.anchorOffset, originalAnchorOffset); | ||
}, 'setSelectionRange() should not update FrameSelection if the target element is not focused.'); | ||
|
||
test(() => { | ||
var notFocused = document.getElementById('notFocused'); | ||
var focused = document.getElementById('focused'); | ||
var selection = window.getSelection(); | ||
selection.removeAllRanges(); | ||
focused.focus(); | ||
|
||
var originalAnchorNode = selection.anchorNode; | ||
var originalAnchorOffset = selection.anchorOffset; | ||
notFocused.setRangeText('barrr', 0, 3, 'select'); | ||
assert_equals(selection.anchorNode, originalAnchorNode); | ||
assert_equals(selection.anchorOffset, originalAnchorOffset); | ||
}, 'setRangeText() should not update FrameSelection if the target element is not focused.'); | ||
</script> | ||
</body> | ||
</html> |
8 changes: 8 additions & 0 deletions
8
LayoutTests/editing/selection/setting-selection-does-not-focus-unless-selected-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Setting selection through APIs does not focus unless selection is inside the text control. | ||
|
||
|
||
|
||
PASS setSelectionRange does not focus unless selection is inside the text control. | ||
PASS selectionStart/selectionEnd does not focus unless selection is inside the text control. | ||
PASS setRangeText does not focus unless selection is inside the text control. | ||
|
69 changes: 69 additions & 0 deletions
69
LayoutTests/editing/selection/setting-selection-does-not-focus-unless-selected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Setting selection through APIs does not focus unless selection is inside the text control.</title> | ||
</head> | ||
<body> | ||
<p>Setting selection through APIs does not focus unless selection is inside the text control.</p> | ||
<input id="input" value="XXXXXXXX"> | ||
<textarea id="textarea">XXXXXXXX</textarea> | ||
<script src="../../resources/testharness.js"></script> | ||
<script src="../../resources/testharnessreport.js"></script> | ||
<script> | ||
function testSetSelectionRange(element, expectFocus) { | ||
const selection = window.getSelection(); | ||
selection.removeAllRanges(); | ||
element.setSelectionRange(null, null); | ||
assert_equals(document.activeElement == element, expectFocus, `Element is should ${!expectFocus ? "not " : ""}be focused`); | ||
assert_equals(element.selectionStart, 0, "selectionStart is correctly set"); | ||
assert_equals(element.selectionStart, 0, "selectionEnd is correctly set"); | ||
element.setSelectionRange(2, 4); | ||
assert_equals(document.activeElement == element, expectFocus, `Element is should ${!expectFocus ? "not " : ""}be focused`); | ||
assert_equals(element.selectionStart, 2, "selectionStart is correctly set"); | ||
assert_equals(element.selectionEnd, 4, "selectionEnd is correctly set"); | ||
} | ||
function testSelectionStartEnd(element, expectFocus) { | ||
element.selectionStart = 3; | ||
element.selectionEnd = 5; | ||
assert_equals(document.activeElement == element, expectFocus, `Element is should ${!expectFocus ? "not " : ""}be focused`); | ||
assert_equals(element.selectionStart, 3, "selectionStart is correctly set"); | ||
assert_equals(element.selectionEnd, 5, "selectionEnd is correctly set"); | ||
} | ||
|
||
function testSetRangeText(element, expectFocus) { | ||
element.setRangeText('barrr', 0, 3, 'select'); | ||
assert_equals(document.activeElement == element, expectFocus, `Element is should ${!expectFocus ? "not " : ""}be focused`); | ||
} | ||
|
||
test(t => { | ||
t.add_cleanup(() => { input.blur(); textarea.blur(); getSelection().removeAllRanges(); }); | ||
testSetSelectionRange(input, false); | ||
testSetSelectionRange(textarea, false); | ||
input.focus(); | ||
testSetSelectionRange(input, true); | ||
textarea.focus(); | ||
testSetSelectionRange(textarea, true); | ||
}, "setSelectionRange does not focus unless selection is inside the text control."); | ||
|
||
test(t => { | ||
t.add_cleanup(() => { input.blur(); textarea.blur(); getSelection().removeAllRanges(); }); | ||
testSelectionStartEnd(input, false); | ||
testSelectionStartEnd(textarea, false); | ||
input.focus(); | ||
testSelectionStartEnd(input, true); | ||
textarea.focus(); | ||
testSelectionStartEnd(textarea, true); | ||
}, "selectionStart/selectionEnd does not focus unless selection is inside the text control."); | ||
|
||
test(t => { | ||
t.add_cleanup(() => { input.blur(); textarea.blur(); getSelection().removeAllRanges(); }); | ||
testSetRangeText(input, false); | ||
testSetRangeText(textarea, false); | ||
input.focus(); | ||
testSetRangeText(input, true); | ||
textarea.focus(); | ||
testSetRangeText(textarea, true); | ||
}, "setRangeText does not focus unless selection is inside the text control."); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
} | ||
|
||
onload = () => { | ||
inputElement.focus(); | ||
inputElement.setRangeText("foo"); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...form-tests/html/interaction/focus/processing-model/textarea-scroll-selection-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
|
||
FAIL programatic focus() scrolls selection into view including ancestors assert_not_equals: Should've scrolled ancestor to show the selection got disallowed value 0 | ||
PASS programatic focus() scrolls selection into view including ancestors | ||
|
Oops, something went wrong.