Commit c1f3da8b authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

DL: Update style & layout in IsFocusableStyle for elements in locked subtrees

Previously we used StyleForElement which is wrong. We should update
style to get the up-to-date style value with the correct inheritance etc
and also need to update layout because some things in accessibility
code requires the layout to be clean (just updating the style & layout
tree from IsFocusableStyle might dirty the layout).

Bug: 1002416
Change-Id: I7b891cde8861cdcb3c79f43b8fa48f13c163dda0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1846215
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704063}
parent 961d1f7c
......@@ -549,17 +549,11 @@ bool Element::IsFocusableStyle() const {
EVisibility::kVisible;
}
// Get the style from |StyleResolver::StyleForElement()| if we're in a
// display-locked subtree, because it isn't included in the normal style
// updates. This will calculate the style without causing other side effects,
// unlike triggering a forced style.layout recalc..
if (DisplayLockUtilities::NearestLockedExclusiveAncestor(*this)) {
scoped_refptr<ComputedStyle> style =
GetDocument().EnsureStyleResolver().StyleForElement(
const_cast<Element*>(this));
return style->Display() != EDisplay::kNone &&
style->Visibility() == EVisibility::kVisible;
}
// Update style if we're in a display-locked subtree, because it isn't
// included in the normal style updates. We also need to update the layout
// here because some callers expect the layout stays clean.
if (DisplayLockUtilities::NearestLockedExclusiveAncestor(*this))
GetDocument().UpdateStyleAndLayoutForNode(this);
if (IsInsideInvisibleSubtree()) {
const ComputedStyle* style =
......
<!doctype HTML>
<html>
<meta charset="utf8">
<title>Display Locking: focus on styled element</title>
<link rel="author" title="Rakina Zata Amni" href="mailto:rakina@chromium.org">
<link rel="help" href="https://github.com/WICG/display-locking">
<!--
Focus on a div whose parent (also in a locked subtree) has updated style/layout.
-->
<div id="container">
<div id="displayNoneParent">
<div id="focusable" tabIndex="0">
focusable thing
</div>
</div>
</div>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../resources/utils.js"></script>
<script>
promise_test((t) => {
const acquirePromise = setInvisibleActivatable(container);
return new Promise((resolve, reject) => {
acquirePromise.then(() => {
container.onbeforeactivate = reject;
displayNoneParent.style.display = "none";
focusable.focus();
t.step(() => assert_not_equals(document.activeElement, focusable));
resolve();
});
});
}, "Trying to focus on an element in a locked subtree that's not visible anymore won't work");
</script>
</html>
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