Commit d01fee62 authored by yosin@chromium.org's avatar yosin@chromium.org

Don't clear selection on focus change except for text form control element

Before this patch, Blink clears selection when focus is changed. This patch
changes to clear selection for text field only. Thus, we keep selection for
content editable.

This patch also updates below tests to follow new behavior introduced by this
patch.

- fast/dom/blur-contenteditable.html
 Render tree dump has a caret.
- fast/layers/scroll-rect-to-visible.html
 Render tree dump has a caret.
- fast/events/selectionchange-user-initiated.html
 One "selectionchange" event from clear selection for content editable has
 been gone.
- /fast/events/selectstart-prevent-selectall.html
 same as above.
- fast/forms/focus-selection-input.html
 One "selectionchange" event from clear selection for caret on LABEL element
 by test step 5 been gone.
- fast/forms/focus-selection-textarea.html
 same as above

BUG=351981
TEST=LayoutTests/editing/selection/keep-selection-after-set-focus.html

Review URL: https://codereview.chromium.org/424973003

git-svn-id: svn://svn.chromium.org/blink/trunk@180228 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 7610004e
......@@ -565,6 +565,9 @@ crbug.com/302529 svg/custom/js-late-clipPath-and-object-creation.svg [ Failure P
crbug.com/255714 [ Linux ] editing/execCommand/switch-list-type-with-orphaned-li.html [ Failure Pass ]
crbug.com/231910 fast/dom/vertical-scrollbar-in-rtl.html [ Failure Pass ]
crbug.com/351981 fast/dom/blur-contenteditable.html [ NeedsRebaseline ]
crbug.com/351981 fast/layers/scroll-rect-to-visible.html [ NeedsRebaseline ]
crbug.com/310323 http/tests/pointer-lock/iframe-sandboxed-allow-pointer-lock.html [ Crash Pass ]
# TODO(enne): rebaseline these and leave them as flaky timeouts
......
Selection should be kept after focus changed.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS selection.anchorNode is sample
PASS selection.anchorOffset is 3
PASS selection.focusNode is sample
PASS selection.focusOffset is 6
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<div id="container">
<p contenteditable id="sample">01234567</p>
<button id="button">This is a button</button>
</div>
<script>
description('Selection should be kept after focus changed.');
var selection = getSelection();
var sample = document.getElementById('sample').firstChild;
selection.collapse(sample, 3);
selection.extend(sample, 6);
document.getElementById('button').focus();
shouldBe('selection.anchorNode', 'sample');
shouldBe('selection.anchorOffset', '3');
shouldBe('selection.focusNode', 'sample');
shouldBe('selection.focusOffset', '6');
document.getElementById('container').outerHTML = '';
</script>
......@@ -14,7 +14,7 @@ PASS: keyup
PASS: selectionchange
PASS: mousedown
PASS: selectionchange
PASS: selectionchange
OPTIONAL: selectionchange
PASS: mouseup
PASS: click
PASS: keydown
......
......@@ -2,7 +2,6 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
This test ensures selectstart event fires when selecting all and script can prevent the selection change.
div: PASS
......
......@@ -16,7 +16,6 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
<input type="text"> focus selection
This test checks whether the selection is restored, cleared, or set to the full range when using different ways to focus a text field. These results all match Mozilla, except test 6, which selects the whole field contents to match all other cases of keyboard focus. When running manually, please follow the steps below. In the test harness, the test runs automatically.
......
......@@ -16,7 +16,6 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
<textarea> focus selection
This test checks whether the selection is restored, cleared, or set to the full range when using different ways to focus a text area. These results all match Mozilla. When running manually, please follow the steps below. In the test harness, the test runs automatically.
......
......@@ -2094,7 +2094,7 @@ void Element::updateFocusAppearance(bool /*restorePreviousSelection*/)
VisibleSelection newSelection = VisibleSelection(firstPositionInOrBeforeNode(this), DOWNSTREAM);
// Passing DoNotSetFocus as this function is called after FocusController::setFocusedElement()
// and we don't want to change the focus to a new Element.
frame->selection().setSelection(newSelection, FrameSelection::DoNotSetFocus);
frame->selection().setSelection(newSelection, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotSetFocus);
frame->selection().revealSelection();
} else if (renderer() && !renderer()->isWidget())
renderer()->scrollRectToVisible(boundingBox());
......
......@@ -665,17 +665,11 @@ static void clearSelectionIfNeeded(LocalFrame* oldFocusedFrame, LocalFrame* newF
if (selectionStartNode == newFocusedNode || selectionStartNode->isDescendantOf(newFocusedNode))
return;
if (selectionStartNode->isInShadowTree() && selectionStartNode->shadowHost() == newFocusedNode)
if (!enclosingTextFormControl(selectionStartNode))
return;
if (Node* mousePressNode = newFocusedFrame->eventHandler().mousePressNode()) {
if (mousePressNode->renderer() && !mousePressNode->canStartSelection()) {
// Don't clear the selection for contentEditable elements, but do
// clear it for input and textarea. See bug 38696.
if (!enclosingTextFormControl(selection.start()))
return;
}
}
if (selectionStartNode->isInShadowTree() && selectionStartNode->shadowHost() == newFocusedNode)
return;
selection.clear();
}
......
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