Commit 1a09a153 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

Improve cosmetics in StyleResolver after CSSCascade flag removal

A few not-so-related changes:

 - No need to use pointers to StyleCascade anymore, since it now
   always exists.
 - Rename ApplyAnimatedStandardProperties to ApplyAnimatedStyle,
   since that name definitely does not make sense anymore. (Both
   standard and custom properties are now applied here, unlike the
   non-CSSCascade branch).
 - Rename ApplyBaseComputedStyle to ApplyBaseStyle, for "symmetry" with
   ApplyAnimatedStyle. (It doesn't make sense to a "apply" a "computed
   style" anyway: the computed style is the output of the process, not
   the input).
 - Forward declare StyleCascade in style_resolver.h, and reorder
   list of forward declarations. (style_cascade.h is now not included
   in any other header, which is nice).

Change-Id: I0db1c9f3dec3e06100009848bbedaece509e5874
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298007Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790090}
parent b4462270
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#include "third_party/blink/renderer/core/css/resolver/selector_filter_parent_scope.h" #include "third_party/blink/renderer/core/css/resolver/selector_filter_parent_scope.h"
#include "third_party/blink/renderer/core/css/resolver/style_adjuster.h" #include "third_party/blink/renderer/core/css/resolver/style_adjuster.h"
#include "third_party/blink/renderer/core/css/resolver/style_builder_converter.h" #include "third_party/blink/renderer/core/css/resolver/style_builder_converter.h"
#include "third_party/blink/renderer/core/css/resolver/style_cascade.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver_state.h" #include "third_party/blink/renderer/core/css/resolver/style_resolver_state.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver_stats.h" #include "third_party/blink/renderer/core/css/resolver/style_resolver_stats.h"
#include "third_party/blink/renderer/core/css/resolver/style_rule_usage_tracker.h" #include "third_party/blink/renderer/core/css/resolver/style_rule_usage_tracker.h"
...@@ -162,10 +163,9 @@ bool ValidateBaseComputedStyle(const ComputedStyle* base_computed_style, ...@@ -162,10 +163,9 @@ bool ValidateBaseComputedStyle(const ComputedStyle* base_computed_style,
// is used. This is because we don't want the computation of the base to // is used. This is because we don't want the computation of the base to
// populate the cascade, as they are supposed to be empty when the optimization // populate the cascade, as they are supposed to be empty when the optimization
// is in use. This is to match the behavior of non-DCHECK builds. // is in use. This is to match the behavior of non-DCHECK builds.
void MaybeResetCascade(StyleCascade* cascade) { void MaybeResetCascade(StyleCascade& cascade) {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
if (cascade) cascade.Reset();
cascade->Reset();
#endif // DCHECK_IS_ON() #endif // DCHECK_IS_ON()
} }
...@@ -785,7 +785,7 @@ static const ComputedStyle* CachedAnimationBaseComputedStyle( ...@@ -785,7 +785,7 @@ static const ComputedStyle* CachedAnimationBaseComputedStyle(
} }
static void UpdateAnimationBaseComputedStyle(StyleResolverState& state, static void UpdateAnimationBaseComputedStyle(StyleResolverState& state,
StyleCascade* cascade, StyleCascade& cascade,
bool forced_update) { bool forced_update) {
if (!state.GetAnimatingElement()) if (!state.GetAnimatingElement())
return; return;
...@@ -803,8 +803,7 @@ static void UpdateAnimationBaseComputedStyle(StyleResolverState& state, ...@@ -803,8 +803,7 @@ static void UpdateAnimationBaseComputedStyle(StyleResolverState& state,
return; return;
} }
std::unique_ptr<CSSBitset> important_set = std::unique_ptr<CSSBitset> important_set = cascade.GetImportantSet();
(cascade ? cascade->GetImportantSet() : nullptr);
element_animations->UpdateBaseComputedStyle(state.Style(), element_animations->UpdateBaseComputedStyle(state.Style(),
std::move(important_set)); std::move(important_set));
} }
...@@ -834,13 +833,11 @@ scoped_refptr<ComputedStyle> StyleResolver::StyleForElement( ...@@ -834,13 +833,11 @@ scoped_refptr<ComputedStyle> StyleResolver::StyleForElement(
matching_behavior == kMatchAllRules; matching_behavior == kMatchAllRules;
STACK_UNINITIALIZED StyleCascade cascade(state); STACK_UNINITIALIZED StyleCascade cascade(state);
StyleCascade* cascade_ptr = &cascade;
ApplyBaseComputedStyle(element, state, cascade_ptr, ApplyBaseStyle(element, state, cascade, cascade.MutableMatchResult(),
cascade.MutableMatchResult(), matching_behavior, matching_behavior, can_cache_animation_base_computed_style);
can_cache_animation_base_computed_style);
if (ApplyAnimatedStandardProperties(state, cascade_ptr)) { if (ApplyAnimatedStyle(state, cascade)) {
INCREMENT_STYLE_STATS_COUNTER(GetDocument().GetStyleEngine(), INCREMENT_STYLE_STATS_COUNTER(GetDocument().GetStyleEngine(),
styles_animated, 1); styles_animated, 1);
StyleAdjuster::AdjustComputedStyle(state, element); StyleAdjuster::AdjustComputedStyle(state, element);
...@@ -916,10 +913,10 @@ void StyleResolver::InitStyleAndApplyInheritance(Element& element, ...@@ -916,10 +913,10 @@ void StyleResolver::InitStyleAndApplyInheritance(Element& element,
} }
} }
void StyleResolver::ApplyBaseComputedStyle( void StyleResolver::ApplyBaseStyle(
Element* element, Element* element,
StyleResolverState& state, StyleResolverState& state,
StyleCascade* cascade, StyleCascade& cascade,
MatchResult& match_result, MatchResult& match_result,
RuleMatchingBehavior matching_behavior, RuleMatchingBehavior matching_behavior,
bool can_cache_animation_base_computed_style) { bool can_cache_animation_base_computed_style) {
...@@ -939,8 +936,8 @@ void StyleResolver::ApplyBaseComputedStyle( ...@@ -939,8 +936,8 @@ void StyleResolver::ApplyBaseComputedStyle(
// get a higher priority. // get a higher priority.
// //
// TODO(crbug.com/1046753): Remove this when canvastext is supported. // TODO(crbug.com/1046753): Remove this when canvastext is supported.
if (element == state.GetDocument().documentElement() && cascade) { if (element == state.GetDocument().documentElement()) {
cascade->MutableMatchResult().AddMatchedProperties( cascade.MutableMatchResult().AddMatchedProperties(
DocumentElementUserAgentDeclarations()); DocumentElementUserAgentDeclarations());
} }
...@@ -984,8 +981,7 @@ void StyleResolver::ApplyBaseComputedStyle( ...@@ -984,8 +981,7 @@ void StyleResolver::ApplyBaseComputedStyle(
if (state.HasDirAutoAttribute()) if (state.HasDirAutoAttribute())
state.Style()->SetSelfOrAncestorHasDirAutoAttribute(true); state.Style()->SetSelfOrAncestorHasDirAutoAttribute(true);
DCHECK(cascade); CascadeAndApplyMatchedProperties(state, cascade);
CascadeAndApplyMatchedProperties(state, *cascade);
ApplyCallbackSelectors(state); ApplyCallbackSelectors(state);
...@@ -1054,7 +1050,6 @@ bool StyleResolver::PseudoStyleForElementInternal( ...@@ -1054,7 +1050,6 @@ bool StyleResolver::PseudoStyleForElementInternal(
// user agent rules, don't waste time walking those rules. // user agent rules, don't waste time walking those rules.
STACK_UNINITIALIZED StyleCascade cascade(state); STACK_UNINITIALIZED StyleCascade cascade(state);
StyleCascade* cascade_ptr = &cascade;
if (ShouldComputeBaseComputedStyle(animation_base_computed_style)) { if (ShouldComputeBaseComputedStyle(animation_base_computed_style)) {
if (pseudo_style_request.AllowsInheritance(state.ParentStyle())) { if (pseudo_style_request.AllowsInheritance(state.ParentStyle())) {
...@@ -1114,10 +1109,10 @@ bool StyleResolver::PseudoStyleForElementInternal( ...@@ -1114,10 +1109,10 @@ bool StyleResolver::PseudoStyleForElementInternal(
if (animation_base_computed_style) { if (animation_base_computed_style) {
state.SetStyle(ComputedStyle::Clone(*animation_base_computed_style)); state.SetStyle(ComputedStyle::Clone(*animation_base_computed_style));
state.Style()->SetStyleType(pseudo_style_request.pseudo_id); state.Style()->SetStyleType(pseudo_style_request.pseudo_id);
MaybeResetCascade(cascade_ptr); MaybeResetCascade(cascade);
} }
if (ApplyAnimatedStandardProperties(state, cascade_ptr)) if (ApplyAnimatedStyle(state, cascade))
StyleAdjuster::AdjustComputedStyle(state, nullptr); StyleAdjuster::AdjustComputedStyle(state, nullptr);
GetDocument().GetStyleEngine().IncStyleForElementCount(); GetDocument().GetStyleEngine().IncStyleForElementCount();
...@@ -1313,9 +1308,8 @@ void StyleResolver::CollectPseudoRulesForElement( ...@@ -1313,9 +1308,8 @@ void StyleResolver::CollectPseudoRulesForElement(
} }
} }
bool StyleResolver::ApplyAnimatedStandardProperties( bool StyleResolver::ApplyAnimatedStyle(StyleResolverState& state,
StyleResolverState& state, StyleCascade& cascade) {
StyleCascade* cascade) {
Element& element = state.GetElement(); Element& element = state.GetElement();
// The animating element may be this element, the pseudo element we are // The animating element may be this element, the pseudo element we are
...@@ -1361,11 +1355,10 @@ bool StyleResolver::ApplyAnimatedStandardProperties( ...@@ -1361,11 +1355,10 @@ bool StyleResolver::ApplyAnimatedStandardProperties(
const ActiveInterpolationsMap& custom_transitions = const ActiveInterpolationsMap& custom_transitions =
state.AnimationUpdate().ActiveInterpolationsForCustomTransitions(); state.AnimationUpdate().ActiveInterpolationsForCustomTransitions();
DCHECK(cascade); cascade.AddInterpolations(&standard_animations, CascadeOrigin::kAnimation);
cascade->AddInterpolations(&standard_animations, CascadeOrigin::kAnimation); cascade.AddInterpolations(&standard_transitions, CascadeOrigin::kTransition);
cascade->AddInterpolations(&standard_transitions, CascadeOrigin::kTransition); cascade.AddInterpolations(&custom_animations, CascadeOrigin::kAnimation);
cascade->AddInterpolations(&custom_animations, CascadeOrigin::kAnimation); cascade.AddInterpolations(&custom_transitions, CascadeOrigin::kTransition);
cascade->AddInterpolations(&custom_transitions, CascadeOrigin::kTransition);
CascadeFilter filter; CascadeFilter filter;
if (IsForcedColorsModeEnabled(state)) if (IsForcedColorsModeEnabled(state))
...@@ -1374,7 +1367,7 @@ bool StyleResolver::ApplyAnimatedStandardProperties( ...@@ -1374,7 +1367,7 @@ bool StyleResolver::ApplyAnimatedStandardProperties(
filter = filter.Add(CSSProperty::kValidForMarker, false); filter = filter.Add(CSSProperty::kValidForMarker, false);
filter = filter.Add(CSSProperty::kAnimation, true); filter = filter.Add(CSSProperty::kAnimation, true);
cascade->Apply(filter); cascade.Apply(filter);
// Start loading resources used by animations. // Start loading resources used by animations.
state.LoadPendingResources(); state.LoadPendingResources();
...@@ -1604,8 +1597,8 @@ scoped_refptr<ComputedStyle> StyleResolver::StyleForInterpolations( ...@@ -1604,8 +1597,8 @@ scoped_refptr<ComputedStyle> StyleResolver::StyleForInterpolations(
StyleResolverState state(GetDocument(), element); StyleResolverState state(GetDocument(), element);
STACK_UNINITIALIZED StyleCascade cascade(state); STACK_UNINITIALIZED StyleCascade cascade(state);
ApplyBaseComputedStyle(&element, state, &cascade, ApplyBaseStyle(&element, state, cascade, cascade.MutableMatchResult(),
cascade.MutableMatchResult(), kMatchAllRules, true); kMatchAllRules, true);
ApplyInterpolations(state, cascade, interpolations); ApplyInterpolations(state, cascade, interpolations);
return state.TakeStyle(); return state.TakeStyle();
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "third_party/blink/renderer/core/css/resolver/css_property_priority.h" #include "third_party/blink/renderer/core/css/resolver/css_property_priority.h"
#include "third_party/blink/renderer/core/css/resolver/matched_properties_cache.h" #include "third_party/blink/renderer/core/css/resolver/matched_properties_cache.h"
#include "third_party/blink/renderer/core/css/resolver/style_builder.h" #include "third_party/blink/renderer/core/css/resolver/style_builder.h"
#include "third_party/blink/renderer/core/css/resolver/style_cascade.h"
#include "third_party/blink/renderer/core/css/selector_checker.h" #include "third_party/blink/renderer/core/css/selector_checker.h"
#include "third_party/blink/renderer/core/css/selector_filter.h" #include "third_party/blink/renderer/core/css/selector_filter.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
...@@ -43,16 +42,17 @@ ...@@ -43,16 +42,17 @@
namespace blink { namespace blink {
class CSSValue;
class CompositorKeyframeValue; class CompositorKeyframeValue;
class CSSPropertyValueSet;
class CSSValue;
class Document; class Document;
class Element; class Element;
class Interpolation; class Interpolation;
class MatchResult; class MatchResult;
class PropertyHandle;
class RuleSet; class RuleSet;
class CSSPropertyValueSet; class StyleCascade;
class StyleRuleUsageTracker; class StyleRuleUsageTracker;
class PropertyHandle;
enum RuleMatchingBehavior { kMatchAllRules, kMatchAllRulesExcludingSMIL }; enum RuleMatchingBehavior { kMatchAllRules, kMatchAllRulesExcludingSMIL };
enum ApplyMask { kApplyMaskRegular = 1 << 0, kApplyMaskVisited = 1 << 1 }; enum ApplyMask { kApplyMaskRegular = 1 << 0, kApplyMaskVisited = 1 << 1 };
...@@ -158,12 +158,12 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> { ...@@ -158,12 +158,12 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> {
private: private:
void InitStyleAndApplyInheritance(Element& element, void InitStyleAndApplyInheritance(Element& element,
StyleResolverState& state); StyleResolverState& state);
void ApplyBaseComputedStyle(Element* element, void ApplyBaseStyle(Element* element,
StyleResolverState& state, StyleResolverState& state,
StyleCascade* cascade, StyleCascade& cascade,
MatchResult& match_result, MatchResult& match_result,
RuleMatchingBehavior matching_behavior, RuleMatchingBehavior matching_behavior,
bool can_cache_animation_base_computed_style); bool can_cache_animation_base_computed_style);
void ApplyInterpolations(StyleResolverState& state, void ApplyInterpolations(StyleResolverState& state,
StyleCascade& cascade, StyleCascade& cascade,
ActiveInterpolationsMap& interpolations); ActiveInterpolationsMap& interpolations);
...@@ -239,8 +239,7 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> { ...@@ -239,8 +239,7 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> {
void CalculateAnimationUpdate(StyleResolverState&); void CalculateAnimationUpdate(StyleResolverState&);
bool ApplyAnimatedStandardProperties(StyleResolverState&, bool ApplyAnimatedStyle(StyleResolverState&, StyleCascade&);
StyleCascade* cascade = nullptr);
void ApplyCallbackSelectors(StyleResolverState&); void ApplyCallbackSelectors(StyleResolverState&);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "third_party/blink/renderer/core/css/parser/css_parser.h" #include "third_party/blink/renderer/core/css/parser/css_parser.h"
#include "third_party/blink/renderer/core/css/properties/css_property_ref.h" #include "third_party/blink/renderer/core/css/properties/css_property_ref.h"
#include "third_party/blink/renderer/core/css/property_registry.h" #include "third_party/blink/renderer/core/css/property_registry.h"
#include "third_party/blink/renderer/core/css/resolver/style_cascade.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver_state.h" #include "third_party/blink/renderer/core/css/resolver/style_resolver_state.h"
#include "third_party/blink/renderer/core/css/style_engine.h" #include "third_party/blink/renderer/core/css/style_engine.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
......
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