Skip to content

Commit

Permalink
[StyleBuilder] Make ComputedStyleBuilder::TakeStyle return const.
Browse files Browse the repository at this point in the history
As above - there should be no behaviour change.

Bug: 1377295
Change-Id: Iacd1dc2678bfc0b5e7dff16805d572015eee80f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4226765
Reviewed-by: Anders Hartvoll Ruud <andruud@chromium.org>
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Robert Flack <flackr@chromium.org>
Reviewed-by: Fernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1103316}
  • Loading branch information
bfgeek authored and Chromium LUCI CQ committed Feb 9, 2023
1 parent a5d1464 commit 6059134
Show file tree
Hide file tree
Showing 48 changed files with 136 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void AnimationUtils::ForEachInterpolatedPropertyValue(
return;

StyleResolver& resolver = target->GetDocument().GetStyleResolver();
scoped_refptr<ComputedStyle> style =
scoped_refptr<const ComputedStyle> style =
resolver.StyleForInterpolations(*target, interpolations);

for (const auto& property : properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ bool FontFaceSetDocument::ResolveFontStyle(const String& font_string,
default_font_description.SetComputedSize(FontFaceSet::kDefaultFontSize);

builder.SetFontDescription(default_font_description);
scoped_refptr<ComputedStyle> style = builder.TakeStyle();
scoped_refptr<const ComputedStyle> style = builder.TakeStyle();

font = GetDocument()->GetStyleEngine().ComputeFont(
*GetDocument()->documentElement(), *style, *parsed_style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CSSPropertyTest : public PageTestBase {
return &set->PropertyAt(0).Value();
}

scoped_refptr<ComputedStyle> ComputedStyleWithValue(
scoped_refptr<const ComputedStyle> ComputedStyleWithValue(
const CSSProperty& property,
const CSSValue& value) {
StyleResolverState state(GetDocument(), *GetDocument().body());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ TEST_F(StyleBuilderTest, GridTemplateAreasApplyOrder) {
nullptr /* StyleRecalcContext */,
StyleRequest(&parent_style));

scoped_refptr<ComputedStyle> style1;
scoped_refptr<ComputedStyle> style2;
scoped_refptr<const ComputedStyle> style1;
scoped_refptr<const ComputedStyle> style2;

// grid-template-areas applied first.
state.SetStyle(parent_style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ class TestCascade {
: state_(document, target ? *target : *document.body()),
cascade_(InitState(state_)) {}

scoped_refptr<ComputedStyle> TakeStyle() { return state_.TakeStyle(); }
scoped_refptr<const ComputedStyle> TakeStyle() { return state_.TakeStyle(); }

StyleResolverState& State() { return state_; }
StyleCascade& InnerCascade() { return cascade_; }

void InheritFrom(scoped_refptr<ComputedStyle> parent) {
void InheritFrom(scoped_refptr<const ComputedStyle> parent) {
state_.SetParentStyle(parent);
state_.StyleBuilder().InheritFrom(*parent);
}
Expand Down Expand Up @@ -231,7 +231,7 @@ class TestCascade {
return state;
}

static scoped_refptr<ComputedStyle> InitialStyle(Document& document) {
static scoped_refptr<const ComputedStyle> InitialStyle(Document& document) {
return document.GetStyleResolver().InitialStyleForElement();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ void StyleResolver::MatchAllRules(StyleResolverState& state,
: element.GetTreeScope());
}

scoped_refptr<ComputedStyle> StyleResolver::StyleForViewport() {
scoped_refptr<const ComputedStyle> StyleResolver::StyleForViewport() {
ComputedStyleBuilder builder = InitialStyleBuilderForElement();

builder.SetZIndex(0);
Expand Down Expand Up @@ -974,7 +974,7 @@ static void IncrementResolvedStyleCounters(const StyleRequest& style_request,
// any other properties or elements. (The exceptions can be found in
// CanReuseBaseComputedStyle().) This is known as the “base computed style
// optimization”.
scoped_refptr<ComputedStyle> StyleResolver::ResolveStyle(
scoped_refptr<const ComputedStyle> StyleResolver::ResolveStyle(
Element* element,
const StyleRecalcContext& style_recalc_context,
const StyleRequest& style_request) {
Expand Down Expand Up @@ -2223,7 +2223,7 @@ FilterOperations StyleResolver::ComputeFilterOperations(
return style->Filter();
}

scoped_refptr<ComputedStyle> StyleResolver::StyleForInterpolations(
scoped_refptr<const ComputedStyle> StyleResolver::StyleForInterpolations(
Element& element,
ActiveInterpolationsMap& interpolations) {
StyleRecalcContext style_recalc_context =
Expand All @@ -2249,7 +2249,7 @@ void StyleResolver::ApplyInterpolations(
cascade.Apply();
}

scoped_refptr<ComputedStyle>
scoped_refptr<const ComputedStyle>
StyleResolver::BeforeChangeStyleForTransitionUpdate(
Element& element,
const ComputedStyle& base_style,
Expand Down
10 changes: 5 additions & 5 deletions third_party/blink/renderer/core/css/resolver/style_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> {
~StyleResolver();
void Dispose();

scoped_refptr<ComputedStyle> ResolveStyle(
scoped_refptr<const ComputedStyle> ResolveStyle(
Element*,
const StyleRecalcContext&,
const StyleRequest& = StyleRequest());
Expand All @@ -80,7 +80,7 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> {
// root element style. In addition to initial values things like zoom, font,
// forced color mode etc. is set.
ComputedStyleBuilder InitialStyleBuilderForElement() const;
scoped_refptr<ComputedStyle> InitialStyleForElement() const {
scoped_refptr<const ComputedStyle> InitialStyleForElement() const {
return InitialStyleBuilderForElement().TakeStyle();
}
float InitialZoom() const;
Expand All @@ -97,7 +97,7 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> {
uint32_t page_index,
const AtomicString& page_name);
scoped_refptr<const ComputedStyle> StyleForText(Text*);
scoped_refptr<ComputedStyle> StyleForViewport();
scoped_refptr<const ComputedStyle> StyleForViewport();
scoped_refptr<const ComputedStyle> StyleForFormattedText(
bool is_text_run,
const ComputedStyle& parent_style,
Expand Down Expand Up @@ -199,7 +199,7 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> {
const Font&,
const CSSValue&);

scoped_refptr<ComputedStyle> StyleForInterpolations(
scoped_refptr<const ComputedStyle> StyleForInterpolations(
Element& element,
ActiveInterpolationsMap& animations);

Expand All @@ -208,7 +208,7 @@ class CORE_EXPORT StyleResolver final : public GarbageCollected<StyleResolver> {
// ticked to the current time. Ticking the animations is required to ensure
// smooth retargeting of transitions.
// https://drafts.csswg.org/css-transitions-1/#before-change-style
scoped_refptr<ComputedStyle> BeforeChangeStyleForTransitionUpdate(
scoped_refptr<const ComputedStyle> BeforeChangeStyleForTransitionUpdate(
Element& element,
const ComputedStyle& base_style,
ActiveInterpolationsMap& transition_interpolations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ bool StyleResolverState::IsInheritedForUnset(
return property.IsInherited() || UsesHighlightPseudoInheritance();
}

scoped_refptr<ComputedStyle> StyleResolverState::TakeStyle() {
scoped_refptr<const ComputedStyle> StyleResolverState::TakeStyle() {
if (had_no_matched_properties_ &&
pseudo_request_type_ == StyleRequest::kForRenderer) {
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class CORE_EXPORT StyleResolverState {
}
ComputedStyleBuilder& StyleBuilder() { return *style_builder_; }
const ComputedStyleBuilder& StyleBuilder() const { return *style_builder_; }
scoped_refptr<ComputedStyle> TakeStyle();
scoped_refptr<const ComputedStyle> TakeStyle();

const CSSToLengthConversionData& CssToLengthConversionData() const {
return css_to_length_conversion_data_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ using animation_test_helpers::CreateSimpleKeyframeEffectForTest;

class StyleResolverTest : public PageTestBase {
protected:
scoped_refptr<ComputedStyle> StyleForId(AtomicString id) {
scoped_refptr<const ComputedStyle> StyleForId(AtomicString id) {
Element* element = GetDocument().getElementById(id);
auto style = GetStyleEngine().GetStyleResolver().ResolveStyle(
element, StyleRecalcContext());
Expand Down Expand Up @@ -576,7 +576,7 @@ TEST_F(StyleResolverTest, NoFetchForHighlightPseudoElements) {
StyleRequest target_text_style_request = pseudo_style_request;
target_text_style_request.pseudo_id = kPseudoIdTargetText;

scoped_refptr<ComputedStyle> target_text_style =
scoped_refptr<const ComputedStyle> target_text_style =
GetDocument().GetStyleResolver().ResolveStyle(GetDocument().body(),
StyleRecalcContext(),
target_text_style_request);
Expand All @@ -585,7 +585,7 @@ TEST_F(StyleResolverTest, NoFetchForHighlightPseudoElements) {
StyleRequest selection_style_style_request = pseudo_style_request;
selection_style_style_request.pseudo_id = kPseudoIdSelection;

scoped_refptr<ComputedStyle> selection_style =
scoped_refptr<const ComputedStyle> selection_style =
GetDocument().GetStyleResolver().ResolveStyle(
GetDocument().body(), StyleRecalcContext(),
selection_style_style_request);
Expand Down Expand Up @@ -1222,7 +1222,7 @@ TEST_F(StyleResolverTest, TextShadowInHighlightPseudoNotCounted1) {
pseudo_style_request.layout_parent_override = element_style;
pseudo_style_request.originating_element_style = element_style;
pseudo_style_request.pseudo_id = kPseudoIdSelection;
scoped_refptr<ComputedStyle> selection_style =
scoped_refptr<const ComputedStyle> selection_style =
GetDocument().GetStyleResolver().ResolveStyle(
target, StyleRecalcContext(), pseudo_style_request);
ASSERT_FALSE(selection_style);
Expand Down Expand Up @@ -1263,7 +1263,7 @@ TEST_F(StyleResolverTest, TextShadowInHighlightPseudoNotCounted2) {
pseudo_style_request.layout_parent_override = element_style;
pseudo_style_request.originating_element_style = element_style;
pseudo_style_request.pseudo_id = kPseudoIdSelection;
scoped_refptr<ComputedStyle> selection_style =
scoped_refptr<const ComputedStyle> selection_style =
GetDocument().GetStyleResolver().ResolveStyle(
target, StyleRecalcContext(), pseudo_style_request);
ASSERT_TRUE(selection_style);
Expand Down Expand Up @@ -1303,7 +1303,7 @@ TEST_F(StyleResolverTest, TextShadowInHighlightPseudotNone) {
pseudo_style_request.layout_parent_override = element_style;
pseudo_style_request.originating_element_style = element_style;
pseudo_style_request.pseudo_id = kPseudoIdSelection;
scoped_refptr<ComputedStyle> selection_style =
scoped_refptr<const ComputedStyle> selection_style =
GetDocument().GetStyleResolver().ResolveStyle(
target, StyleRecalcContext(), pseudo_style_request);
ASSERT_TRUE(selection_style);
Expand Down Expand Up @@ -1340,7 +1340,7 @@ TEST_F(StyleResolverTest, TextShadowInHighlightPseudoNotNone1) {
pseudo_style_request.layout_parent_override = element_style;
pseudo_style_request.originating_element_style = element_style;
pseudo_style_request.pseudo_id = kPseudoIdSelection;
scoped_refptr<ComputedStyle> selection_style =
scoped_refptr<const ComputedStyle> selection_style =
GetDocument().GetStyleResolver().ResolveStyle(
target, StyleRecalcContext(), pseudo_style_request);
ASSERT_TRUE(selection_style);
Expand Down Expand Up @@ -1380,7 +1380,7 @@ TEST_F(StyleResolverTest, TextShadowInHighlightPseudoNotNone2) {
pseudo_style_request.layout_parent_override = element_style;
pseudo_style_request.originating_element_style = element_style;
pseudo_style_request.pseudo_id = kPseudoIdSelection;
scoped_refptr<ComputedStyle> selection_style =
scoped_refptr<const ComputedStyle> selection_style =
GetDocument().GetStyleResolver().ResolveStyle(
target, StyleRecalcContext(), pseudo_style_request);
ASSERT_TRUE(selection_style);
Expand Down
3 changes: 2 additions & 1 deletion third_party/blink/renderer/core/css/style_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3698,7 +3698,8 @@ void StyleEngine::UpdateViewportStyle() {
return;
}

scoped_refptr<ComputedStyle> viewport_style = resolver_->StyleForViewport();
scoped_refptr<const ComputedStyle> viewport_style =
resolver_->StyleForViewport();
if (ComputedStyle::ComputeDifference(
viewport_style.get(), GetDocument().GetLayoutView()->Style()) !=
ComputedStyle::Difference::kEqual) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ void DisplayLockContext::SetRequestedState(EContentVisibility state,
element_.Get());
}

scoped_refptr<ComputedStyle> DisplayLockContext::AdjustElementStyle(
ComputedStyle* style) const {
scoped_refptr<const ComputedStyle> DisplayLockContext::AdjustElementStyle(
const ComputedStyle* style) const {
if (IsAlwaysVisible())
return style;
if (IsLocked()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class CORE_EXPORT DisplayLockContext final
void SetRequestedState(EContentVisibility state,
const AtomicString& toggle_visibility);
// Called by style to adjust the element's style based on the current state.
scoped_refptr<ComputedStyle> AdjustElementStyle(ComputedStyle*) const;
scoped_refptr<const ComputedStyle> AdjustElementStyle(
const ComputedStyle*) const;

// Is called by the intersection observer callback to inform us of the
// intersection state.
Expand Down
3 changes: 2 additions & 1 deletion third_party/blink/renderer/core/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,8 @@ void Document::Initialize() {
DCHECK(!ax_object_cache_ || this != &AXObjectCacheOwner());

UpdateForcedColors();
scoped_refptr<ComputedStyle> style = GetStyleResolver().StyleForViewport();
scoped_refptr<const ComputedStyle> style =
GetStyleResolver().StyleForViewport();
layout_view_ = LayoutObjectFactory::CreateView(*this, *style);
SetLayoutObject(layout_view_);

Expand Down

0 comments on commit 6059134

Please sign in to comment.