Skip to content

Commit

Permalink
[@container] Refactor StyleRecalcChange flags
Browse files Browse the repository at this point in the history
This in preparation of adding yet another flag.

There should be no behavior change.

Bug: 1145970
Change-Id: Ifb722195670819fbde651f9299bb50ad282c9229
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2953186
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#891621}
  • Loading branch information
andruud authored and Chromium LUCI CQ committed Jun 11, 2021
1 parent 69457f5 commit eb5c85d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 45 deletions.
34 changes: 15 additions & 19 deletions third_party/blink/renderer/core/css/style_recalc.cc
Expand Up @@ -56,32 +56,28 @@ bool StyleRecalcChange::ShouldUpdatePseudoElement(
pseudo_element.ComputedStyleRef().DependsOnContainerQueries();
}

StyleRecalcChange::ContainerQueryDependentFlag
StyleRecalcChange::ContainerQueryDependentFlagForChildren(
StyleRecalcChange::Flags StyleRecalcChange::FlagsForChildren(
const Element& element) const {
// kRecalc[Descendant]ContainerQueryDependent means we are at the container
// root for a container query recalc.
if (propagate_ == kRecalcContainerQueryDependent)
return kRecalcContainer;
return flags_ | kRecalcContainer;
if (propagate_ == kRecalcDescendantContainerQueryDependent)
return kRecalcDescendantContainers;
return flags_ | kRecalcDescendantContainers;

switch (container_query_dependent_flag_) {
case kNoContainerRecalc:
return kNoContainerRecalc;
case kRecalcContainer: {
// Don't traverse into children if we hit a descendant container while
// recalculating container queries. If the queries for this container also
// changes, we will enter another container query recalc for this subtree
// from layout.
const ComputedStyle* old_style = element.GetComputedStyle();
if (old_style && old_style->IsContainerForContainerQueries())
return kNoContainerRecalc;
return kRecalcContainer;
}
case kRecalcDescendantContainers:
return kRecalcDescendantContainers;
Flags result = flags_;

if ((result & kRecalcContainerFlags) == kRecalcContainer) {
// Don't traverse into children if we hit a descendant container while
// recalculating container queries. If the queries for this container also
// changes, we will enter another container query recalc for this subtree
// from layout.
const ComputedStyle* old_style = element.GetComputedStyle();
if (old_style && old_style->IsContainerForContainerQueries())
result &= ~kRecalcContainer;
}

return result;
}

StyleRecalcContext StyleRecalcContext::FromAncestors(Element& element) {
Expand Down
50 changes: 24 additions & 26 deletions third_party/blink/renderer/core/css/style_recalc.h
Expand Up @@ -18,15 +18,21 @@ class PseudoElement;
// attachment during the style recalc phase.
class StyleRecalcChange {
private:
enum ContainerQueryDependentFlag {
kNoContainerRecalc,
enum Flag {
kNoFlags = 0,
// Recalc container query dependent elements within this container,
// but not in nested containers.
kRecalcContainer,
kRecalcContainer = 1 << 0,
// Recalc container query dependent elements within this container,
// and also in nested containers.
kRecalcDescendantContainers,
kRecalcDescendantContainers = 1 << 1,
// If set, need to reattach layout tree.
kReattach = 1 << 2,
};
using Flags = uint8_t;

static const Flags kRecalcContainerFlags =
kRecalcContainer | kRecalcDescendantContainers;

public:
enum Propagate {
Expand Down Expand Up @@ -60,27 +66,27 @@ class StyleRecalcChange {
StyleRecalcChange(Propagate propagate) : propagate_(propagate) {}

StyleRecalcChange ForChildren(const Element& element) const {
return {RecalcDescendants() ? kRecalcDescendants : kNo, reattach_,
ContainerQueryDependentFlagForChildren(element)};
return {RecalcDescendants() ? kRecalcDescendants : kNo,
FlagsForChildren(element)};
}
StyleRecalcChange ForPseudoElement() const {
if (propagate_ == kUpdatePseudoElements)
return {kRecalcChildren, reattach_, container_query_dependent_flag_};
return {kRecalcChildren, flags_};
return *this;
}
StyleRecalcChange EnsureAtLeast(Propagate propagate) const {
if (propagate > propagate_)
return {propagate, reattach_, container_query_dependent_flag_};
return {propagate_, reattach_, container_query_dependent_flag_};
return {propagate, flags_};
return {propagate_, flags_};
}
StyleRecalcChange ForceRecalcDescendants() const {
return {kRecalcDescendants, reattach_, container_query_dependent_flag_};
return {kRecalcDescendants, flags_};
}
StyleRecalcChange ForceReattachLayoutTree() const {
return {propagate_, true, container_query_dependent_flag_};
return {propagate_, flags_ | kReattach};
}

bool ReattachLayoutTree() const { return reattach_; }
bool ReattachLayoutTree() const { return flags_ & kReattach; }
bool RecalcChildren() const { return propagate_ > kUpdatePseudoElements; }
bool RecalcDescendants() const { return propagate_ == kRecalcDescendants; }
bool UpdatePseudoElements() const { return propagate_ != kNo; }
Expand All @@ -92,26 +98,18 @@ class StyleRecalcChange {
bool ShouldUpdatePseudoElement(const PseudoElement&) const;

private:
StyleRecalcChange(Propagate propagate,
bool reattach,
ContainerQueryDependentFlag container_query_dependent_flag)
: propagate_(propagate),
reattach_(reattach),
container_query_dependent_flag_(container_query_dependent_flag) {}
StyleRecalcChange(Propagate propagate, Flags flags)
: propagate_(propagate), flags_(flags) {}

bool RecalcContainerQueryDependent() const {
return container_query_dependent_flag_ != kNoContainerRecalc;
return flags_ & kRecalcContainerFlags;
}
ContainerQueryDependentFlag ContainerQueryDependentFlagForChildren(
const Element&) const;
Flags FlagsForChildren(const Element&) const;

// To what extent do we need to update style for children.
Propagate propagate_ = kNo;
// Need to reattach layout tree if true.
bool reattach_ = false;
// Force recalc of elements depending on container queries.
ContainerQueryDependentFlag container_query_dependent_flag_ =
kNoContainerRecalc;
// See StyleRecalc::Flag.
Flags flags_ = kNoFlags;
};

// StyleRecalcContext is an object that is passed on the stack during
Expand Down

0 comments on commit eb5c85d

Please sign in to comment.