haikuwebkit/LayoutTests/fast/forms/input-text-autofocus.html

39 lines
780 B
HTML
Raw Permalink Normal View History

autofocus of text input should not select text https://bugs.webkit.org/show_bug.cgi?id=218585 <rdar://problem/60130704> Reviewed by Wenson Hsieh. Source/WebCore: Test: fast/forms/input-text-autofocus.html * dom/Document.h: * history/CachedPage.cpp: (WebCore::CachedPage::restore): * html/HTMLInputElement.h: * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::updateFocusAppearance): (WebCore::HTMLInputElement::setDefaultSelectionAfterFocus): (WebCore::HTMLInputElement::runPostTypeUpdateTasks): (WebCore::HTMLInputElement::didAttachRenderers): * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::updateFocusAppearance): * html/InputType.cpp: (WebCore::InputType::accessKeyAction): * page/EventHandler.cpp: (WebCore::EventHandler::dispatchMouseEvent): * page/FocusController.cpp: (WebCore::FocusController::advanceFocusInDocumentOrder): (WebCore::FocusController::advanceFocusDirectionallyInContainer): Slightly rework `SelectionRestorationMode` to replace `SetDefault` with two new values: - `PlaceCaretAtStart` puts the caret at the start, regardless of any cached selection - `SelectAll` selects all text, regardless of any cached selection (existing behavior) In order to preserve existing behavior, the default `Restore` will have the same effect as `SelectAll` if there is no cached selection (and is renamed to `RestoreOrSelectAll` as such). * dom/Element.h: * dom/Element.cpp: (WebCore::Element::focus): * html/HTMLLabelElement.h: * html/HTMLLabelElement.cpp: (WebCore::HTMLLabelElement::focus): * html/HTMLLegendElement.h: * html/HTMLLegendElement.cpp: (WebCore::HTMLLegendElement::focus): Replace the `bool restorePreviousSelection` with `SelectionRestorationMode` since that's what it's eventually used for anyways. This also allows for more flexibility in behavior, such as callers using the new `SelectionRestorationMode` values. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::didAttachRenderers): Change to `PlaceCaretAtStart` to match other browsers. Source/WebKit: * WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::restoreSelectionInFocusedEditableElement): Slightly rework `SelectionRestorationMode` to replace `SetDefault` with two new values: - `PlaceCaretAtStart` puts the caret at the start, regardless of any cached selection - `SelectAll` selects all text, regardless of any cached selection (existing behavior) In order to preserve existing behavior, the default `Restore` will have the same effect as `SelectAll` if there is no cached selection (and is renamed to `RestoreOrSelectAll` as such). LayoutTests: * fast/forms/input-text-autofocus.html: Added. * fast/forms/input-text-autofocus-expected.txt: Added. * fast/forms/input-first-letter-edit.html: * fast/forms/input-first-letter-edit-expected.html: Canonical link: https://commits.webkit.org/231378@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269587 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-11-09 19:08:31 +00:00
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="../../resources/ui-helper.js"></script>
</head>
<body>
<input id="input" type="text" value="foo" autofocus>
<script>
// iOS places the caret at the end of the input field.
if (window.internals)
internals.settings.setEditingBehavior("mac");
description("Test for &lt;input autofocus&gt;");
jsTestIsAsync = true;
inputFocusCount = 0;
input.addEventListener("focus", (event) => {
++inputFocusCount;
});
requestAnimationFrame(() => {
shouldBe("inputFocusCount", "1");
shouldBe("input.selectionStart", "0");
shouldBe("input.selectionEnd", "0");
finishJSTest();
});
</script>
<script src="../../../../resources/js-test-post.js"></script>
</body>
</html>