Commit 9d70f389 authored by Yash Khandelwal's avatar Yash Khandelwal Committed by Commit Bot

[TextUrlFragments] Add Tab key handling for Text fragment anchor

Tab key press will now use SetSequentialFocusNavigationStartingPoint to
put focus navigation to the start of selection.

Bug: 1075683
Test: TextFragmentAnchorBrowserTest.TabFocus added
Change-Id: I6611b75d142f6d38792387e8dfd9f41fed418544
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2191336Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarNick Burris <nburris@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Commit-Queue: Yash Khandelwal <yakhande@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#770668}
parent f00260ed
...@@ -450,4 +450,26 @@ IN_PROC_BROWSER_TEST_F(ForceLoadAtTopBrowserTest, TextFragmentAnchorDisabled) { ...@@ -450,4 +450,26 @@ IN_PROC_BROWSER_TEST_F(ForceLoadAtTopBrowserTest, TextFragmentAnchorDisabled) {
EXPECT_TRUE(main_contents->GetMainFrame()->GetView()->IsScrollOffsetAtTop()); EXPECT_TRUE(main_contents->GetMainFrame()->GetView()->IsScrollOffsetAtTop());
} }
// Test that Tab key press puts focus from the start of selection.
IN_PROC_BROWSER_TEST_F(TextFragmentAnchorBrowserTest, TabFocus) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL(
"/scrollable_page_with_anchor.html#:~:text=text"));
WebContents* main_contents = shell()->web_contents();
RenderFrameSubmissionObserver frame_observer(main_contents);
EXPECT_TRUE(NavigateToURL(shell(), url));
WaitForPageLoad(main_contents);
frame_observer.WaitForScrollOffsetAtTop(
/*expected_scroll_offset_at_top=*/false);
DOMMessageQueue msg_queue;
SimulateKeyPress(main_contents, ui::DomKey::TAB, ui::DomCode::TAB,
ui::VKEY_TAB, false, false, false, false);
// Wait for focus to happen.
std::string message;
EXPECT_TRUE(msg_queue.WaitForMessage(&message));
EXPECT_EQ("\"FocusDone2\"", message);
}
} // namespace content } // namespace content
<html>
<head>
<meta name="viewport" content="width=device-width, minimum-scale=1.0">
<script>
document.addEventListener("DOMContentLoaded", function(event) {
document.getElementById("focusableElement1").addEventListener('focus', () => {
window.domAutomationController.send('FocusDone1');
});
document.getElementById("focusableElement2").addEventListener('focus', () => {
window.domAutomationController.send('FocusDone2');
});
});
</script>
<style>
p {
position: absolute;
left: 10000px;
top: 10000px;
}
</style>
</head>
<body>
<p id="text">
<a href="#" id="focusableElement1">Test1</a>
Some text
<a href="#" id="focusableElement2">Test2</a>
</p>
</body>
</html>
...@@ -350,6 +350,12 @@ void TextFragmentAnchor::DidFindMatch( ...@@ -350,6 +350,12 @@ void TextFragmentAnchor::DidFindMatch(
EphemeralRange(ToPositionInDOMTree(range.StartPosition()), EphemeralRange(ToPositionInDOMTree(range.StartPosition()),
ToPositionInDOMTree(range.EndPosition())); ToPositionInDOMTree(range.EndPosition()));
frame_->GetDocument()->Markers().AddTextFragmentMarker(dom_range); frame_->GetDocument()->Markers().AddTextFragmentMarker(dom_range);
// Set the sequential focus navigation to the start of selection.
// Even if this element isn't focusable, "Tab" press will
// start the search to find the next focusable element from this element.
frame_->GetDocument()->SetSequentialFocusNavigationStartingPoint(
range.StartPosition().NodeAsRangeFirstNode());
} }
void TextFragmentAnchor::DidFindAmbiguousMatch() { void TextFragmentAnchor::DidFindAmbiguousMatch() {
......
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