Commit 93697187 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

Eliminate PseudoStyleForElementInternal

This CL merges the function PseudoStyleForElementInternal with its
non-internal wrapper PseudoStyleForElement.

This is a step towards unifying the two very similar codepaths of
StyleForElement and PseudoStyleForElement.

There should be no behavior change.

Change-Id: Iad0dfd59c8081de5ec68bbc5120e4cf28eee7954
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317960
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: default avatarOriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#792003}
parent 1ea01017
...@@ -1015,14 +1015,22 @@ CompositorKeyframeValue* StyleResolver::CreateCompositorKeyframeValueSnapshot( ...@@ -1015,14 +1015,22 @@ CompositorKeyframeValue* StyleResolver::CreateCompositorKeyframeValueSnapshot(
return CompositorKeyframeValueFactory::Create(property, *state.Style()); return CompositorKeyframeValueFactory::Create(property, *state.Style());
} }
bool StyleResolver::PseudoStyleForElementInternal( scoped_refptr<ComputedStyle> StyleResolver::PseudoStyleForElement(
Element& element, Element* element,
const PseudoElementStyleRequest& pseudo_style_request, const PseudoElementStyleRequest& pseudo_style_request,
StyleResolverState& state) { const ComputedStyle* parent_style,
const ComputedStyle* parent_layout_object_style) {
DCHECK(parent_style);
if (!element)
return nullptr;
StyleResolverState state(
GetDocument(), *element, pseudo_style_request.pseudo_id,
pseudo_style_request.type, parent_style, parent_layout_object_style);
DCHECK(GetDocument().GetFrame()); DCHECK(GetDocument().GetFrame());
DCHECK(GetDocument().GetSettings()); DCHECK(GetDocument().GetSettings());
DCHECK(pseudo_style_request.pseudo_id != kPseudoIdFirstLineInherited); DCHECK(pseudo_style_request.pseudo_id != kPseudoIdFirstLineInherited);
DCHECK(state.ParentStyle());
SelectorFilterParentScope::EnsureParentStackIsPushed(); SelectorFilterParentScope::EnsureParentStackIsPushed();
...@@ -1036,9 +1044,9 @@ bool StyleResolver::PseudoStyleForElementInternal( ...@@ -1036,9 +1044,9 @@ bool StyleResolver::PseudoStyleForElementInternal(
STACK_UNINITIALIZED StyleCascade cascade(state); STACK_UNINITIALIZED StyleCascade cascade(state);
if (ShouldComputeBaseComputedStyle(animation_base_computed_style)) { if (ShouldComputeBaseComputedStyle(animation_base_computed_style)) {
if (pseudo_style_request.AllowsInheritance(state.ParentStyle())) { if (pseudo_style_request.AllowsInheritance(parent_style)) {
scoped_refptr<ComputedStyle> style = ComputedStyle::Create(); scoped_refptr<ComputedStyle> style = ComputedStyle::Create();
style->InheritFrom(*state.ParentStyle()); style->InheritFrom(*parent_style);
state.SetStyle(std::move(style)); state.SetStyle(std::move(style));
} else { } else {
// ::backdrop inherits from initial styles. All other pseudo elements // ::backdrop inherits from initial styles. All other pseudo elements
...@@ -1059,11 +1067,11 @@ bool StyleResolver::PseudoStyleForElementInternal( ...@@ -1059,11 +1067,11 @@ bool StyleResolver::PseudoStyleForElementInternal(
GetDocument().GetStyleEngine().EnsureUAStyleForPseudoElement( GetDocument().GetStyleEngine().EnsureUAStyleForPseudoElement(
pseudo_style_request.pseudo_id); pseudo_style_request.pseudo_id);
MatchUARules(state.GetElement(), collector); MatchUARules(*element, collector);
// TODO(obrufau): support styling nested pseudo-elements // TODO(obrufau): support styling nested pseudo-elements
if (!element.IsPseudoElement()) { if (!element->IsPseudoElement()) {
MatchUserRules(collector); MatchUserRules(collector);
MatchAuthorRules(state.GetElement(), collector); MatchAuthorRules(*element, collector);
} }
if (tracker_) if (tracker_)
...@@ -1071,7 +1079,9 @@ bool StyleResolver::PseudoStyleForElementInternal( ...@@ -1071,7 +1079,9 @@ bool StyleResolver::PseudoStyleForElementInternal(
if (!collector.MatchedResult().HasMatchedProperties()) { if (!collector.MatchedResult().HasMatchedProperties()) {
StyleAdjuster::AdjustComputedStyle(state, nullptr); StyleAdjuster::AdjustComputedStyle(state, nullptr);
return false; if (pseudo_style_request.type == PseudoElementStyleRequest::kForRenderer)
return nullptr;
return state.TakeStyle();
} }
CascadeAndApplyMatchedProperties(state, cascade); CascadeAndApplyMatchedProperties(state, cascade);
...@@ -1108,34 +1118,12 @@ bool StyleResolver::PseudoStyleForElementInternal( ...@@ -1108,34 +1118,12 @@ bool StyleResolver::PseudoStyleForElementInternal(
if (state.Style()->HasGlyphRelativeUnits()) if (state.Style()->HasGlyphRelativeUnits())
UseCounter::Count(GetDocument(), WebFeature::kHasGlyphRelativeUnits); UseCounter::Count(GetDocument(), WebFeature::kHasGlyphRelativeUnits);
return true;
}
scoped_refptr<ComputedStyle> StyleResolver::PseudoStyleForElement(
Element* element,
const PseudoElementStyleRequest& pseudo_style_request,
const ComputedStyle* parent_style,
const ComputedStyle* parent_layout_object_style) {
DCHECK(parent_style);
if (!element)
return nullptr;
StyleResolverState state(
GetDocument(), *element, pseudo_style_request.pseudo_id,
pseudo_style_request.type, parent_style, parent_layout_object_style);
if (!PseudoStyleForElementInternal(*element, pseudo_style_request, state)) {
if (pseudo_style_request.type == PseudoElementStyleRequest::kForRenderer)
return nullptr;
return state.TakeStyle();
}
if (PseudoElement* pseudo_element = if (PseudoElement* pseudo_element =
element->GetPseudoElement(pseudo_style_request.pseudo_id)) { element->GetPseudoElement(pseudo_style_request.pseudo_id)) {
SetAnimationUpdateIfNeeded(state, *pseudo_element); SetAnimationUpdateIfNeeded(state, *pseudo_element);
state.LoadPendingResources(); state.LoadPendingResources();
} }
// Now return the style.
return state.TakeStyle(); return state.TakeStyle();
} }
......
...@@ -243,10 +243,6 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> { ...@@ -243,10 +243,6 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> {
void ApplyCallbackSelectors(StyleResolverState&); void ApplyCallbackSelectors(StyleResolverState&);
bool PseudoStyleForElementInternal(Element&,
const PseudoElementStyleRequest&,
StyleResolverState&);
bool HasAuthorBorder(const StyleResolverState&); bool HasAuthorBorder(const StyleResolverState&);
Document& GetDocument() const { return *document_; } Document& GetDocument() const { return *document_; }
bool WasViewportResized() const { return was_viewport_resized_; } bool WasViewportResized() const { return was_viewport_resized_; }
......
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