Commit 179784a6 authored by Rakina Zata Amni's avatar Rakina Zata Amni Committed by Commit Bot

[DL]: Add NearestLockedInclusiveAncestor to DisplayLockUtilities

This CL adds a new function, NearestLockedInclusiveAncestor, to
DisplayLockUtilties, so that it can be reused in multiple places
(example: https://chromium-review.googlesource.com/c/chromium/src/+/1528123/2/third_party/blink/renderer/core/inspector/inspector_highlight.cc#291)

Bug: 882663
Change-Id: Ia7408f10635f7304cebee483c14773c626d6bec3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1528126Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Commit-Queue: Rakina Zata Amni <rakina@chromium.org>
Cr-Commit-Position: refs/heads/master@{#642361}
parent 28137134
......@@ -48,6 +48,7 @@
#include "third_party/blink/renderer/core/css/style_change_reason.h"
#include "third_party/blink/renderer/core/css/style_environment_variables.h"
#include "third_party/blink/renderer/core/css/style_sheet_contents.h"
#include "third_party/blink/renderer/core/display_lock/display_lock_utilities.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/element_traversal.h"
#include "third_party/blink/renderer/core/dom/flat_tree_traversal.h"
......@@ -1575,30 +1576,16 @@ void StyleEngine::MarkForWhitespaceReattachment() {
for (auto element : whitespace_reattach_set_) {
if (element->NeedsReattachLayoutTree() || !element->GetLayoutObject())
continue;
if (RuntimeEnabledFeatures::DisplayLockingEnabled() &&
GetDocument().LockedDisplayLockCount() > 0) {
// This element might be located inside a display locked subtree, so we
// might mark it for ReattachLayoutTree later on instead.
// TODO(crbug.com/924550): Once we figure out a more efficient way to
// determine whether we're inside a locked subtree or not, change this.
bool is_in_locked_subtree = false;
for (const Node& ancestor :
FlatTreeTraversal::InclusiveAncestorsOf(*element)) {
if (!ancestor.IsElementNode())
continue;
if (auto* context = ToElement(ancestor).GetDisplayLockContext()) {
if (!context->IsLocked())
continue;
is_in_locked_subtree = true;
context->AddToWhitespaceReattachSet(*element);
break;
}
}
if (is_in_locked_subtree)
continue;
if (Element* locked_ancestor =
DisplayLockUtilities::NearestLockedInclusiveAncestor(*element)) {
locked_ancestor->GetDisplayLockContext()->AddToWhitespaceReattachSet(
*element);
continue;
}
DCHECK(!element->NeedsStyleRecalc());
DCHECK(!element->ChildNeedsStyleRecalc());
}
if (Node* first_child = LayoutTreeBuilderTraversal::FirstChild(*element))
first_child->MarkAncestorsWithChildNeedsReattachLayoutTree();
}
......
......@@ -80,4 +80,23 @@ DisplayLockUtilities::ScopedChainForcedUpdate::ScopedChainForcedUpdate(
}
}
Element* DisplayLockUtilities::NearestLockedInclusiveAncestor(
const Node& node) {
if (!RuntimeEnabledFeatures::DisplayLockingEnabled() ||
node.GetDocument().LockedDisplayLockCount() == 0) {
return nullptr;
}
// TODO(crbug.com/924550): Once we figure out a more efficient way to
// determine whether we're inside a locked subtree or not, change this.
for (Node& ancestor : FlatTreeTraversal::InclusiveAncestorsOf(node)) {
if (!ancestor.IsElementNode())
continue;
if (auto* context = ToElement(ancestor).GetDisplayLockContext()) {
if (context->IsLocked())
return &ToElement(ancestor);
}
}
return nullptr;
}
} // namespace blink
......@@ -42,6 +42,9 @@ class CORE_EXPORT DisplayLockUtilities {
// activatable-locked).
static const HeapVector<Member<Element>> ActivatableLockedInclusiveAncestors(
Element& element);
// Returns the nearest inclusive ancestor of |node| that is display locked.
static Element* NearestLockedInclusiveAncestor(const Node& node);
};
} // namespace blink
......
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