Commit 5c1a4cc6 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Chromium LUCI CQ

[@container] Add StyleRecalcContext to RecalcStyle (and friends)

As of this CL a StyleRecalcContext reference can be propagated from
UpdateStyleAndLayoutTreeForContainer to ElementRuleCollector,
although only for regular elements (not pseudo-elements and
other special things).

Bug: 1145970
Change-Id: I79cd317fb8ccfdd2b5d737b0d3c2f2842acf3943
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627313
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843778}
parent 4793c0ef
......@@ -1978,8 +1978,13 @@ void StyleEngine::UpdateStyleAndLayoutTreeForContainer(Element& container) {
base::AutoReset<bool> cq_recalc(&in_container_query_style_recalc_, true);
// TODO(crbug.com/1145970): Populate this context with a
// ContainerQueryEvaluator.
StyleRecalcContext style_recalc_context;
style_recalc_root_.Update(nullptr, &container);
RecalcStyle({StyleRecalcChange::kRecalcContainerQueryDependent});
RecalcStyle({StyleRecalcChange::kRecalcContainerQueryDependent},
style_recalc_context);
if (container.ChildNeedsReattachLayoutTree()) {
DCHECK(layout_tree_rebuild_root_.GetRootNode());
......@@ -1994,13 +1999,14 @@ void StyleEngine::UpdateStyleAndLayoutTreeForContainer(Element& container) {
}
}
void StyleEngine::RecalcStyle(StyleRecalcChange change) {
void StyleEngine::RecalcStyle(StyleRecalcChange change,
const StyleRecalcContext& style_recalc_context) {
DCHECK(GetDocument().documentElement());
Element& root_element = style_recalc_root_.RootElement();
Element* parent = FlatTreeTraversal::ParentElement(root_element);
SelectorFilterRootScope filter_scope(parent);
root_element.RecalcStyle(change);
root_element.RecalcStyle(change, style_recalc_context);
for (ContainerNode* ancestor = root_element.GetStyleRecalcParent(); ancestor;
ancestor = ancestor->GetStyleRecalcParent()) {
......
......@@ -401,7 +401,7 @@ class CORE_EXPORT StyleEngine final : public GarbageCollected<StyleEngine>,
void UpdateStyleAndLayoutTree();
// To be called from layout when container queries change for the container.
void UpdateStyleAndLayoutTreeForContainer(Element& container);
void RecalcStyle() { RecalcStyle({}); }
void RecalcStyle() { RecalcStyle({}, StyleRecalcContext()); }
void ClearEnsuredDescendantStyles(Element& element);
void RebuildLayoutTree();
......@@ -540,7 +540,7 @@ class CORE_EXPORT StyleEngine final : public GarbageCollected<StyleEngine>,
void ViewportDefiningElementDidChange();
void PropagateWritingModeAndDirectionToHTMLRoot();
void RecalcStyle(StyleRecalcChange);
void RecalcStyle(StyleRecalcChange, const StyleRecalcContext&);
Member<Document> document_;
......
......@@ -1344,7 +1344,9 @@ void ContainerNode::SetRestyleFlag(DynamicRestyleFlags mask) {
EnsureRareData().SetRestyleFlag(mask);
}
void ContainerNode::RecalcDescendantStyles(const StyleRecalcChange change) {
void ContainerNode::RecalcDescendantStyles(
const StyleRecalcChange change,
const StyleRecalcContext& style_recalc_context) {
DCHECK(GetDocument().InStyleRecalc());
DCHECK(!NeedsStyleRecalc());
......@@ -1355,7 +1357,7 @@ void ContainerNode::RecalcDescendantStyles(const StyleRecalcChange change) {
child_text_node->RecalcTextStyle(change);
if (auto* child_element = DynamicTo<Element>(child))
child_element->RecalcStyle(change);
child_element->RecalcStyle(change, style_recalc_context);
}
}
......
......@@ -40,6 +40,7 @@ class Element;
class ExceptionState;
class HTMLCollection;
class RadioNodeList;
class StyleRecalcContext;
class WhitespaceAttacher;
using StaticElementList = StaticNodeTypeList<Element>;
......@@ -286,7 +287,8 @@ class CORE_EXPORT ContainerNode : public Node {
Element* changed_element,
Node* node_before_change,
Node* node_after_change);
void RecalcDescendantStyles(const StyleRecalcChange);
void RecalcDescendantStyles(const StyleRecalcChange,
const StyleRecalcContext&);
void RebuildChildrenLayoutTrees(WhitespaceAttacher&);
void RebuildLayoutTreeForChild(Node* child, WhitespaceAttacher&);
......
......@@ -2818,7 +2818,8 @@ void Element::RecalcStyleForTraversalRootAncestor() {
DidRecalcStyle({});
}
void Element::RecalcStyle(const StyleRecalcChange change) {
void Element::RecalcStyle(const StyleRecalcChange change,
const StyleRecalcContext& style_recalc_context) {
DCHECK(InActiveDocument());
DCHECK(GetDocument().InStyleRecalc());
DCHECK(!GetDocument().Lifecycle().InDetach());
......@@ -2829,7 +2830,7 @@ void Element::RecalcStyle(const StyleRecalcChange change) {
StyleRecalcChange child_change = change.ForChildren(*this);
if (change.ShouldRecalcStyleFor(*this)) {
child_change = RecalcOwnStyle(change);
child_change = RecalcOwnStyle(change, style_recalc_context);
if (GetStyleChangeType() == kSubtreeStyleChange)
child_change = child_change.ForceRecalcDescendants();
ClearNeedsStyleRecalc();
......@@ -2876,18 +2877,20 @@ void Element::RecalcStyle(const StyleRecalcChange change) {
if (child_change.TraverseChildren(*this)) {
SelectorFilterParentScope filter_scope(*this);
if (ShadowRoot* root = GetShadowRoot()) {
root->RecalcDescendantStyles(child_change);
root->RecalcDescendantStyles(child_change, style_recalc_context);
// Sad panda. This is only to clear ensured ComputedStyles for elements
// outside the flat tree for getComputedStyle() in the cases where we
// kSubtreeStyleChange. Style invalidation and kLocalStyleChange will
// make sure we clear out-of-date ComputedStyles outside the flat tree
// in Element::EnsureComputedStyle().
if (child_change.RecalcDescendants())
RecalcDescendantStyles(StyleRecalcChange::kClearEnsured);
if (child_change.RecalcDescendants()) {
RecalcDescendantStyles(StyleRecalcChange::kClearEnsured,
style_recalc_context);
}
} else if (auto* slot = ToHTMLSlotElementIfSupportsAssignmentOrNull(this)) {
slot->RecalcStyleForSlotChildren(child_change);
slot->RecalcStyleForSlotChildren(child_change, style_recalc_context);
} else {
RecalcDescendantStyles(child_change);
RecalcDescendantStyles(child_change, style_recalc_context);
}
}
......@@ -2945,7 +2948,9 @@ static const StyleRecalcChange ApplyComputedStyleDiff(
return change.EnsureAtLeast(StyleRecalcChange::kUpdatePseudoElements);
}
StyleRecalcChange Element::RecalcOwnStyle(const StyleRecalcChange change) {
StyleRecalcChange Element::RecalcOwnStyle(
const StyleRecalcChange change,
const StyleRecalcContext& style_recalc_context) {
DCHECK(GetDocument().InStyleRecalc());
if (change.RecalcChildren() && HasRareData() && NeedsStyleRecalc()) {
// This element needs recalc because its parent changed inherited
......@@ -2969,8 +2974,6 @@ StyleRecalcChange Element::RecalcOwnStyle(const StyleRecalcChange change) {
// can simply clone the old ComputedStyle and set these directly.
new_style = PropagateInheritedProperties();
}
// TODO(crbug.com/1145970): Use actual StyleRecalcContext.
StyleRecalcContext style_recalc_context;
if (!new_style)
new_style = StyleForLayoutObject(style_recalc_context);
if (new_style && !ShouldStoreComputedStyle(*new_style))
......@@ -4971,7 +4974,7 @@ void Element::UpdateFirstLetterPseudoElement(StyleUpdatePhase phase) {
if (text_node_changed || remaining_text_layout_object->PreviousSibling() !=
element->GetLayoutObject())
change = change.ForceReattachLayoutTree();
element->RecalcStyle(change);
element->RecalcStyle(change, style_recalc_context);
if (element->NeedsReattachLayoutTree() &&
!PseudoElementLayoutObjectIsNeeded(element->GetComputedStyle(), this)) {
......@@ -4994,7 +4997,9 @@ void Element::UpdatePseudoElement(PseudoId pseudo_id,
if (change.ShouldUpdatePseudoElement(*element)) {
if (CanGeneratePseudoElement(pseudo_id)) {
element->RecalcStyle(change.ForPseudoElement());
// TODO(crbug.com/1145970): Use actual StyleRecalcContext.
StyleRecalcContext style_recalc_context;
element->RecalcStyle(change.ForPseudoElement(), style_recalc_context);
if (!element->NeedsReattachLayoutTree())
return;
if (PseudoElementLayoutObjectIsNeeded(element->GetComputedStyle(), this))
......
......@@ -512,7 +512,7 @@ class CORE_EXPORT Element : public ContainerNode, public Animatable {
virtual LayoutObject* CreateLayoutObject(const ComputedStyle&, LegacyLayout);
virtual bool LayoutObjectIsNeeded(const ComputedStyle&) const;
void RecalcStyle(const StyleRecalcChange);
void RecalcStyle(const StyleRecalcChange, const StyleRecalcContext&);
void RecalcStyleForTraversalRootAncestor();
void RebuildLayoutTreeForTraversalRootAncestor() {
RebuildFirstLetterLayoutTree();
......@@ -1048,7 +1048,8 @@ class CORE_EXPORT Element : public ContainerNode, public Animatable {
// Recalculate the ComputedStyle for this element and return a
// StyleRecalcChange for propagation/traversal into child nodes.
StyleRecalcChange RecalcOwnStyle(const StyleRecalcChange);
StyleRecalcChange RecalcOwnStyle(const StyleRecalcChange,
const StyleRecalcContext&);
void RebuildPseudoElementLayoutTree(PseudoId, WhitespaceAttacher&);
void RebuildFirstLetterLayoutTree();
......
......@@ -470,12 +470,13 @@ void HTMLSlotElement::RemovedFrom(ContainerNode& insertion_point) {
}
void HTMLSlotElement::RecalcStyleForSlotChildren(
const StyleRecalcChange change) {
const StyleRecalcChange change,
const StyleRecalcContext& style_recalc_context) {
for (auto& node : flat_tree_children_) {
if (!change.TraverseChild(*node))
continue;
if (auto* element = DynamicTo<Element>(node.Get()))
element->RecalcStyle(change);
element->RecalcStyle(change, style_recalc_context);
else if (auto* text_node = DynamicTo<Text>(node.Get()))
text_node->RecalcTextStyle(change);
}
......
......@@ -104,7 +104,8 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement {
static AtomicString NormalizeSlotName(const AtomicString&);
void RecalcStyleForSlotChildren(const StyleRecalcChange);
void RecalcStyleForSlotChildren(const StyleRecalcChange,
const StyleRecalcContext&);
// For User-Agent Shadow DOM
static const AtomicString& UserAgentCustomAssignSlotName();
......
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