Commit ad615d33 authored by JunHo Seo's avatar JunHo Seo Committed by Commit Bot

Snav: Start candidate search in the focused element's container

Problem:
Imagine the focused element F "scrolled out" = hidden outside
of its container C's viewable area. In this case spatnav would
start its search for focus candidates up at the document root
and therefor miss (possibly nearby) candidates in C.

Solution:
Let AdvanceFocusDirectionallyInContainer() use the currently
focused element F's container C as its starting rectangle unless
F is an HTMLAreaElement. For HTMLAreaElement the search starts in
the HTMLAreaElement's image.

Bug: 763206
Change-Id: I4b721e92bf47ff5361d6f0fa8b70805eb0b485c2
Reviewed-on: https://chromium-review.googlesource.com/826345Reviewed-by: default avatarHugo Holgersson <hugoh@vewd.com>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524743}
parent 030eb3e7
.
PASS successfullyParsed is true
TEST COMPLETE
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "3"
PASS gFocusedDocument.activeElement.getAttribute("id") is "3"
PASS gFocusedDocument.activeElement.getAttribute("id") is "3"
PASS gFocusedDocument.activeElement.getAttribute("id") is "3"
PASS gFocusedDocument.activeElement.getAttribute("id") is "4"
PASS gFocusedDocument.activeElement.getAttribute("id") is "5"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "2"
PASS gFocusedDocument.activeElement.getAttribute("id") is "1"
......
......@@ -33,11 +33,20 @@
<script type="application/javascript">
var resultMap = [
["Down", "1"],
["Down", "1"],
["Down", "1"],
["Down", "1"],
["Down", "2"],
["Down", "2"],
["Down", "3"],
["Right", "3"],
["Right", "3"],
["Right", "3"],
["Right", "4"],
["Down", "5"],
["Up", "2"],
["Up", "2"],
["Up", "2"],
["Up", "2"],
["Up", "1"],
......@@ -77,11 +86,18 @@
<div class="scroll">
<a id="1" href="a"><img src="resources/green.png" width=30px height=35px></a>
<div></div>
<img src="resources/green.png" width=200px height=200px>
<img src="resources/green.png" width=200px height=280px>
<div></div>
<a id="2" href="a"><img src="resources/green.png" width=30px height=30px></a>.
<a id="2" href="a"><img src="resources/green.png" width=30px height=30px></a>
</div>
<a id="3" href="a"><img src="resources/green.png" width=30px height=30px></a>
<div class="scroll">
<a id="3" href="a"><img src="resources/green.png" width=30px height=35px></a>
<a id="4" href="a" style="margin-left: 400px"><img src="resources/green.png" width=30px height=35px></a>
</div>
<a id="5" href="a"><img src="resources/green.png" width=30px height=30px></a>
<div id="console"></div>
<div>This test tests that a div with css overflow:auto will scroll to reveal its focusable elements</div>
</body>
......
......@@ -1483,21 +1483,20 @@ bool FocusController::AdvanceFocusDirectionally(WebFocusType type) {
LayoutRect starting_rect;
if (focused_element) {
if (!HasOffscreenRect(focused_element)) {
container = ScrollableEnclosingBoxOrParentFrameForNodeInDirection(
type, focused_element);
starting_rect = NodeRectInAbsoluteCoordinates(focused_element,
true /* ignore border */);
} else if (auto* area = ToHTMLAreaElementOrNull(*focused_element)) {
if (area->ImageElement()) {
container = ScrollableEnclosingBoxOrParentFrameForNodeInDirection(
type, area->ImageElement());
focused_element = area->ImageElement();
starting_rect = VirtualRectForAreaElementAndDirection(*area, type);
}
}
container = ScrollableEnclosingBoxOrParentFrameForNodeInDirection(
type, focused_element);
}
bool consumed = false;
do {
while (!consumed && container) {
consumed =
AdvanceFocusDirectionallyInContainer(container, starting_rect, type);
starting_rect =
......@@ -1506,7 +1505,7 @@ bool FocusController::AdvanceFocusDirectionally(WebFocusType type) {
ScrollableEnclosingBoxOrParentFrameForNodeInDirection(type, container);
if (container && container->IsDocumentNode())
ToDocument(container)->UpdateStyleAndLayoutIgnorePendingStylesheets();
} while (!consumed && container);
}
return consumed;
}
......
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