Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Enable ability to prevent scrolling in Element.focus()
https://bugs.webkit.org/show_bug.cgi?id=178583 Patch by Rob Buis <rbuis@igalia.com> on 2021-03-22 Reviewed by Simon Fraser. LayoutTests/imported/w3c: Update improved test result. * web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements-expected.txt: Added. * web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html: Added. * web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt: Source/WebCore: Add FocusOptions parameter to the focus method [1] both to the IDL as the C++ side. Change Element.focus to not scroll if FocusOptions.preventScroll is true. Behavior matches Chrome and Firefox. Tests: imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea.html imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html Test: imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-nested-scroll-elements.html * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Headers.cmake: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * dom/Element.cpp: (WebCore::Element::focus): * dom/Element.h: (WebCore::Element::focus): * dom/FocusOptions.h: Copied from Source/WebCore/html/HTMLOrForeignElement.idl. * dom/FocusOptions.idl: Copied from Source/WebCore/html/HTMLOrForeignElement.idl. * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::didAttachRenderers): * html/HTMLLabelElement.cpp: (WebCore::HTMLLabelElement::focus): * html/HTMLLabelElement.h: * html/HTMLLegendElement.cpp: (WebCore::HTMLLegendElement::focus): * html/HTMLLegendElement.h: * html/HTMLOrForeignElement.idl: * html/InputType.cpp: (WebCore::InputType::accessKeyAction): * page/FocusController.cpp: (WebCore::FocusController::advanceFocusInDocumentOrder): (WebCore::FocusController::advanceFocusDirectionallyInContainer): LayoutTests: The test preventScroll-textarea.html now passes on all platforms. * platform/ios-wk2/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt: Removed. * platform/mac-wk1/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/preventScroll-textarea-expected.txt: Removed. Canonical link: https://commits.webkit.org/235610@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@274812 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
a39bd42
commit 6f15b9669d3951f1bfa46d52dab68a2ab168339e
Showing
27 changed files
with
246 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
1_1 | ||
1_2 | ||
1_3 | ||
2_1 | ||
2_2 | ||
2_3 | ||
3_1 | ||
3_2 | ||
3_3 | ||
|
||
PASS focus(options) - preventScroll on nested scroll elements | ||
|
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,62 @@ | ||
<!doctype html> | ||
<title>focus(options) - preventScroll on nested scroll elements</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<style> | ||
.scrollBox { width: 400px; height: 300px; border: 1px solid } | ||
.bigbox { width: 380px; height: 300px; border: 1px solid } | ||
.box { width: 380px; height: 150px; border: 1px solid } | ||
</style> | ||
<div class="scrollBox" style="overflow-y: scroll;"> | ||
<div class="bigbox" id="1" style="overflow-y: scroll;" tabindex=1> | ||
<div class="box" id="1_1" tabindex=1>1_1</div> | ||
<div class="box" id="1_2" tabindex=1>1_2</div> | ||
<div class="box" id="1_3" tabindex=1>1_3</div> | ||
</div> | ||
<div class="bigbox" id="2" style="overflow-y: scroll;" tabindex=1> | ||
<div class="box" id="2_1" tabindex=1>2_1</div> | ||
<div class="box" id="2_2" tabindex=1>2_2</div> | ||
<div class="box" id="2_3" tabindex=1>2_3</div> | ||
</div> | ||
<div class="bigbox" id="3" style="overflow-y: scroll;" tabindex=1> | ||
<div class="box" id="3_1" tabindex=1>3_1</div> | ||
<div class="box" id="3_2" tabindex=1>3_2</div> | ||
<div class="box" id="3_3" tabindex=1>3_3</div> | ||
</div> | ||
</div> | ||
<script> | ||
promise_test(async function(t) { | ||
await new Promise(resolve => window.addEventListener("load", resolve)); | ||
let div2_2 = document.getElementById("2_2"); | ||
div2_2.focus({ preventScroll: true }); | ||
|
||
await new Promise(resolve => { | ||
requestAnimationFrame(() => requestAnimationFrame(resolve)); | ||
}); | ||
|
||
assert_equals(document.activeElement, div2_2, `box 2_2: should have been focused`); | ||
assert_equals(div2_2.scrollTop, 0, "box 2_2: should not have scrolled"); | ||
assert_equals(div2_2.parentNode.scrollTop, 0, "box 2_2: should not have scrolled ancestor"); | ||
|
||
// Reset focus | ||
let div1_1 = document.getElementById("1_1"); | ||
div1_1.focus(); | ||
|
||
await new Promise(resolve => { | ||
requestAnimationFrame(() => requestAnimationFrame(resolve)); | ||
}); | ||
assert_equals(document.activeElement, div1_1, `box 1_1: should have been focused`); | ||
|
||
let div2 = document.getElementById("2"); | ||
div2.focus({ preventScroll: true }); | ||
|
||
await new Promise(resolve => { | ||
requestAnimationFrame(() => requestAnimationFrame(resolve)); | ||
}); | ||
|
||
assert_equals(document.activeElement, div2, `box 2: should have been focused`); | ||
assert_equals(div2.scrollTop, 0, "box 2: should not have scrolled"); | ||
assert_equals(div2_2.scrollTop, 0, "box 2_2: should not have scrolled"); | ||
assert_equals(div2.parentNode.scrollTop, 0, "box 2: should not have scrolled ancestor"); | ||
}); | ||
</script> |
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 preventScroll: true on a textarea element assert_equals: TEXTAREA: Should not have scrolled after a couple event loop ticks expected 0 but got 920 | ||
PASS preventScroll: true on a textarea element | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) 2020 Igalia S.L. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "FocusDirection.h" | ||
|
||
namespace WebCore { | ||
|
||
struct FocusOptions { | ||
SelectionRestorationMode selectionRestorationMode { SelectionRestorationMode::RestoreOrSelectAll }; | ||
FocusDirection direction { FocusDirection::None }; | ||
bool preventScroll { false }; | ||
}; | ||
|
||
} // namespace WebCore |
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,28 @@ | ||
/* | ||
* Copyright (C) 2020 Igalia S.L. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
dictionary FocusOptions { | ||
boolean preventScroll = false; | ||
}; |
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
Oops, something went wrong.