Commit b1cadc00 authored by Rune Lillesveen's avatar Rune Lillesveen Committed by Commit Bot

Don't force pseudo element recalc based on pseudo element dirtiness.

If we need to recalculate style for a pseudo element, we forced it
through the StyleRecalcChange passed in, even if the only reason was
that the pseudo element itself was style dirty. The problem with that is
that it would look like an ancestor change made the recalc necessary. If
an ancestor change made it necessary we could not use the optimized base
computed style path for style recalc.

Make sure we only translate kUpdatePseudoElements into kRecalcChildren
and still benefit from base computed style if the incoming
StyleRecalcChange propagation is kNo.

Bug: 988834
Change-Id: Ib2efcd6a932623bfec6226512eb3692418c84928
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1738559Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Commit-Queue: Rune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684390}
parent 7d16814f
......@@ -108,6 +108,8 @@ class CORE_EXPORT ElementAnimations
// CSSAnimations checks if a style change is due to animation.
friend class CSSAnimations;
DISALLOW_COPY_AND_ASSIGN(ElementAnimations);
FRIEND_TEST_ALL_PREFIXES(StyleEngineTest, PseudoElementBaseComputedStyle);
};
} // namespace blink
......
......@@ -11,6 +11,7 @@
#include "third_party/blink/public/common/css/preferred_color_scheme.h"
#include "third_party/blink/public/platform/web_float_rect.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/core/animation/element_animations.h"
#include "third_party/blink/renderer/core/css/css_font_selector.h"
#include "third_party/blink/renderer/core/css/css_rule_list.h"
#include "third_party/blink/renderer/core/css/css_style_rule.h"
......@@ -2028,4 +2029,45 @@ TEST_F(StyleEngineTest, ColorSchemeBaseBackgroundChange) {
EXPECT_EQ(Color::kBlack, GetDocument().View()->BaseBackgroundColor());
}
TEST_F(StyleEngineTest, PseudoElementBaseComputedStyle) {
GetDocument().body()->SetInnerHTMLFromString(R"HTML(
<style>
@keyframes anim {
from { background-color: white }
to { background-color: blue }
}
#anim::before {
content:"";
animation: anim 1s;
}
</style>
<div id="anim"></div>
)HTML");
UpdateAllLifecyclePhases();
auto* anim_element = GetDocument().getElementById("anim");
auto* before = anim_element->GetPseudoElement(kPseudoIdBefore);
auto* animations = before->GetElementAnimations();
ASSERT_TRUE(animations);
before->SetNeedsAnimationStyleRecalc();
UpdateAllLifecyclePhases();
scoped_refptr<ComputedStyle> base_computed_style =
animations->base_computed_style_;
EXPECT_TRUE(base_computed_style);
before->SetNeedsAnimationStyleRecalc();
UpdateAllLifecyclePhases();
EXPECT_TRUE(animations->base_computed_style_);
#if !DCHECK_IS_ON()
// When DCHECK is enabled, BaseComputedStyle() returns null and we repeatedly
// create new instances which means the pointers will be different here.
EXPECT_EQ(base_computed_style, animations->base_computed_style_);
#endif
}
} // namespace blink
......@@ -41,6 +41,11 @@ class StyleRecalcChange {
return {RecalcDescendants() ? kRecalcDescendants : kNo, reattach_,
calc_invisible_};
}
StyleRecalcChange ForPseudoElement() const {
if (propagate_ == kUpdatePseudoElements)
return {kRecalcChildren, reattach_, calc_invisible_};
return *this;
}
StyleRecalcChange EnsureAtLeast(Propagate propagate) const {
if (propagate > propagate_)
return {propagate, reattach_, calc_invisible_};
......
......@@ -4541,7 +4541,7 @@ void Element::UpdatePseudoElement(PseudoId pseudo_id,
if (change.ShouldUpdatePseudoElement(*element)) {
if (CanGeneratePseudoElement(pseudo_id)) {
element->RecalcStyle(change.ForChildren().ForceRecalcDescendants());
element->RecalcStyle(change.ForPseudoElement());
if (!element->NeedsReattachLayoutTree())
return;
if (PseudoElementLayoutObjectIsNeeded(element->GetComputedStyle()))
......
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