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

Make InterpolationValue.non_interpolable_value const

This also eliminated the last caller to LengthInterpolationFunctions::
Composite (out of necessity), hence the two ::Composite* functions
were unified.

Bug: 981024
Change-Id: I197ad0fd246d7aabff08b326e1ee3d9e4520ee35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1722941
Commit-Queue: Anders Hartvoll Ruud <andruud@chromium.org>
Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682684}
parent 03cfb02f
......@@ -14,12 +14,13 @@ namespace blink {
class BasicShapeNonInterpolableValue : public NonInterpolableValue {
public:
static scoped_refptr<NonInterpolableValue> Create(
static scoped_refptr<const NonInterpolableValue> Create(
BasicShape::ShapeType type) {
return base::AdoptRef(new BasicShapeNonInterpolableValue(type));
}
static scoped_refptr<NonInterpolableValue> CreatePolygon(WindRule wind_rule,
wtf_size_t size) {
static scoped_refptr<const NonInterpolableValue> CreatePolygon(
WindRule wind_rule,
wtf_size_t size) {
return base::AdoptRef(new BasicShapeNonInterpolableValue(wind_rule, size));
}
......
......@@ -47,8 +47,8 @@ const BasicShape* GetBasicShape(const CSSProperty& property,
class UnderlyingCompatibilityChecker
: public CSSInterpolationType::CSSConversionChecker {
public:
UnderlyingCompatibilityChecker(
scoped_refptr<NonInterpolableValue> underlying_non_interpolable_value)
UnderlyingCompatibilityChecker(scoped_refptr<const NonInterpolableValue>
underlying_non_interpolable_value)
: underlying_non_interpolable_value_(
std::move(underlying_non_interpolable_value)) {}
......@@ -60,7 +60,7 @@ class UnderlyingCompatibilityChecker
*underlying.non_interpolable_value);
}
scoped_refptr<NonInterpolableValue> underlying_non_interpolable_value_;
scoped_refptr<const NonInterpolableValue> underlying_non_interpolable_value_;
};
class InheritedShapeChecker
......
......@@ -224,7 +224,7 @@ InterpolationValue ConvertBorderImageAutoSide() {
InterpolationValue ConvertBorderImageLengthBox(const BorderImageLengthBox& box,
double zoom) {
auto list = std::make_unique<InterpolableList>(kSideIndexCount);
Vector<scoped_refptr<NonInterpolableValue>> non_interpolable_values(
Vector<scoped_refptr<const NonInterpolableValue>> non_interpolable_values(
kSideIndexCount);
const BorderImageLength* sides[kSideIndexCount] = {};
sides[kSideTop] = &box.Top();
......@@ -254,7 +254,7 @@ void CompositeSide(UnderlyingValue& underlying_value,
underlying_fraction, interpolable_value);
break;
case SideType::kLength:
LengthInterpolationFunctions::CompositeUnderlying(
LengthInterpolationFunctions::Composite(
underlying_value, underlying_fraction, interpolable_value,
non_interpolable_value);
break;
......@@ -313,7 +313,7 @@ InterpolationValue CSSBorderImageLengthBoxInterpolationType::MaybeConvertValue(
return nullptr;
auto list = std::make_unique<InterpolableList>(kSideIndexCount);
Vector<scoped_refptr<NonInterpolableValue>> non_interpolable_values(
Vector<scoped_refptr<const NonInterpolableValue>> non_interpolable_values(
kSideIndexCount);
const CSSValue* sides[kSideIndexCount] = {};
sides[kSideTop] = quad->Top();
......
......@@ -53,7 +53,7 @@ class UnderlyingFilterListChecker
: public CSSInterpolationType::CSSConversionChecker {
public:
UnderlyingFilterListChecker(
scoped_refptr<NonInterpolableList> non_interpolable_list)
scoped_refptr<const NonInterpolableList> non_interpolable_list)
: non_interpolable_list_(std::move(non_interpolable_list)) {}
bool IsValid(const StyleResolverState&,
......@@ -73,7 +73,7 @@ class UnderlyingFilterListChecker
}
private:
scoped_refptr<NonInterpolableList> non_interpolable_list_;
scoped_refptr<const NonInterpolableList> non_interpolable_list_;
};
class InheritedFilterListChecker
......@@ -101,7 +101,8 @@ InterpolationValue ConvertFilterList(const FilterOperations& filter_operations,
double zoom) {
wtf_size_t length = filter_operations.size();
auto interpolable_list = std::make_unique<InterpolableList>(length);
Vector<scoped_refptr<NonInterpolableValue>> non_interpolable_values(length);
Vector<scoped_refptr<const NonInterpolableValue>> non_interpolable_values(
length);
for (wtf_size_t i = 0; i < length; i++) {
InterpolationValue filter_result =
filter_interpolation_functions::MaybeConvertFilter(
......@@ -164,7 +165,8 @@ InterpolationValue CSSFilterListInterpolationType::MaybeConvertValue(
const auto& list = To<CSSValueList>(value);
wtf_size_t length = list.length();
auto interpolable_list = std::make_unique<InterpolableList>(length);
Vector<scoped_refptr<NonInterpolableValue>> non_interpolable_values(length);
Vector<scoped_refptr<const NonInterpolableValue>> non_interpolable_values(
length);
for (wtf_size_t i = 0; i < length; i++) {
InterpolationValue item_result =
filter_interpolation_functions::MaybeConvertCSSFilter(list.Item(i));
......@@ -188,9 +190,9 @@ CSSFilterListInterpolationType::MaybeConvertStandardPropertyUnderlyingValue(
PairwiseInterpolationValue CSSFilterListInterpolationType::MaybeMergeSingles(
InterpolationValue&& start,
InterpolationValue&& end) const {
NonInterpolableList& start_non_interpolable_list =
const NonInterpolableList& start_non_interpolable_list =
ToNonInterpolableList(*start.non_interpolable_value);
NonInterpolableList& end_non_interpolable_list =
const NonInterpolableList& end_non_interpolable_list =
ToNonInterpolableList(*end.non_interpolable_value);
wtf_size_t start_length = start_non_interpolable_list.length();
wtf_size_t end_length = end_non_interpolable_list.length();
......@@ -284,9 +286,8 @@ void CSSFilterListInterpolationType::Composite(
}
underlying_value_owner.MutableValue().interpolable_value =
std::move(extended_interpolable_list);
// const_cast to take a ref.
underlying_value_owner.MutableValue().non_interpolable_value =
const_cast<NonInterpolableValue*>(value.non_interpolable_value.get());
value.non_interpolable_value;
}
void CSSFilterListInterpolationType::ApplyStandardPropertyValue(
......
......@@ -50,8 +50,8 @@ class CSSImageNonInterpolableValue : public NonInterpolableValue {
}
static scoped_refptr<CSSImageNonInterpolableValue> Merge(
scoped_refptr<NonInterpolableValue> start,
scoped_refptr<NonInterpolableValue> end);
scoped_refptr<const NonInterpolableValue> start,
scoped_refptr<const NonInterpolableValue> end);
CSSValue* Crossfade(double progress) const {
if (is_single_ || progress <= 0)
......@@ -82,8 +82,8 @@ DEFINE_NON_INTERPOLABLE_VALUE_TYPE(CSSImageNonInterpolableValue);
DEFINE_NON_INTERPOLABLE_VALUE_TYPE_CASTS(CSSImageNonInterpolableValue);
scoped_refptr<CSSImageNonInterpolableValue> CSSImageNonInterpolableValue::Merge(
scoped_refptr<NonInterpolableValue> start,
scoped_refptr<NonInterpolableValue> end) {
scoped_refptr<const NonInterpolableValue> start,
scoped_refptr<const NonInterpolableValue> end) {
const CSSImageNonInterpolableValue& start_image_pair =
ToCSSImageNonInterpolableValue(*start);
const CSSImageNonInterpolableValue& end_image_pair =
......
......@@ -119,7 +119,8 @@ InterpolationValue CSSImageListInterpolationType::MaybeConvertValue(
const wtf_size_t length = value_list.length();
auto interpolable_list = std::make_unique<InterpolableList>(length);
Vector<scoped_refptr<NonInterpolableValue>> non_interpolable_values(length);
Vector<scoped_refptr<const NonInterpolableValue>> non_interpolable_values(
length);
for (wtf_size_t i = 0; i < length; i++) {
InterpolationValue component =
CSSImageInterpolationType::MaybeConvertCSSValue(value_list.Item(i),
......
......@@ -133,10 +133,8 @@ void CSSLengthInterpolationType::Composite(
double underlying_fraction,
const InterpolationValue& value,
double interpolation_fraction) const {
InterpolationValue& underlying = underlying_value_owner.MutableValue();
LengthInterpolationFunctions::Composite(
underlying.interpolable_value, underlying.non_interpolable_value,
underlying_fraction, *value.interpolable_value,
underlying_value_owner, underlying_fraction, *value.interpolable_value,
value.non_interpolable_value.get());
}
......
......@@ -145,7 +145,7 @@ void CSSLengthListInterpolationType::Composite(
ListInterpolationFunctions::LengthMatchingStrategy::kLowestCommonMultiple,
WTF::BindRepeating(
LengthInterpolationFunctions::NonInterpolableValuesAreCompatible),
WTF::BindRepeating(LengthInterpolationFunctions::CompositeUnderlying));
WTF::BindRepeating(LengthInterpolationFunctions::Composite));
}
void CSSLengthListInterpolationType::ApplyStandardPropertyValue(
......
......@@ -78,7 +78,7 @@ class CSSRotateNonInterpolableValue : public NonInterpolableValue {
scoped_refptr<CSSRotateNonInterpolableValue> Composite(
const CSSRotateNonInterpolableValue& other,
double other_progress) {
double other_progress) const {
DCHECK(is_single_ && !is_start_additive_);
if (other.is_single_) {
DCHECK_EQ(other_progress, 0);
......@@ -241,7 +241,7 @@ void CSSRotateInterpolationType::Composite(
double underlying_fraction,
const InterpolationValue& value,
double interpolation_fraction) const {
CSSRotateNonInterpolableValue& underlying_non_interpolable_value =
const CSSRotateNonInterpolableValue& underlying_non_interpolable_value =
ToCSSRotateNonInterpolableValue(
*underlying_value_owner.Value().non_interpolable_value);
const CSSRotateNonInterpolableValue& non_interpolable_value =
......
......@@ -39,7 +39,7 @@ struct IndentMode {
class CSSTextIndentNonInterpolableValue : public NonInterpolableValue {
public:
static scoped_refptr<CSSTextIndentNonInterpolableValue> Create(
scoped_refptr<NonInterpolableValue> length_non_interpolable_value,
scoped_refptr<const NonInterpolableValue> length_non_interpolable_value,
const IndentMode& mode) {
return base::AdoptRef(new CSSTextIndentNonInterpolableValue(
std::move(length_non_interpolable_value), mode));
......@@ -48,28 +48,64 @@ class CSSTextIndentNonInterpolableValue : public NonInterpolableValue {
const NonInterpolableValue* LengthNonInterpolableValue() const {
return length_non_interpolable_value_.get();
}
scoped_refptr<NonInterpolableValue>& LengthNonInterpolableValue() {
return length_non_interpolable_value_;
}
const IndentMode& Mode() const { return mode_; }
DECLARE_NON_INTERPOLABLE_VALUE_TYPE();
private:
CSSTextIndentNonInterpolableValue(
scoped_refptr<NonInterpolableValue> length_non_interpolable_value,
scoped_refptr<const NonInterpolableValue> length_non_interpolable_value,
const IndentMode& mode)
: length_non_interpolable_value_(
std::move(length_non_interpolable_value)),
mode_(mode) {}
scoped_refptr<NonInterpolableValue> length_non_interpolable_value_;
scoped_refptr<const NonInterpolableValue> length_non_interpolable_value_;
const IndentMode mode_;
};
DEFINE_NON_INTERPOLABLE_VALUE_TYPE(CSSTextIndentNonInterpolableValue);
DEFINE_NON_INTERPOLABLE_VALUE_TYPE_CASTS(CSSTextIndentNonInterpolableValue);
// A wrapper for the UnderlyingValue passed to
// CSSTextIndentInterpolationType::Composite which can be forwarded to
// LengthInterpolationFunctions::Composite.
//
// If LengthInterpolationFunctions::Composite calls SetNonInterpolableValue with
// a new NonInterpolableValue, this class wraps it in a new
// CSSTextIndentNonInterpolableValue before being set on the inner
// UnderlyingValue.
class UnderlyingTextIndentAsLengthValue : public UnderlyingValue {
STACK_ALLOCATED();
public:
UnderlyingTextIndentAsLengthValue(UnderlyingValue& inner_underlying_value,
IndentMode mode)
: inner_underlying_value_(inner_underlying_value), mode_(mode) {}
InterpolableValue& MutableInterpolableValue() final {
return inner_underlying_value_.MutableInterpolableValue();
}
const NonInterpolableValue* GetNonInterpolableValue() const final {
const auto& text_indent_non_interpolable_value =
ToCSSTextIndentNonInterpolableValue(
*inner_underlying_value_.GetNonInterpolableValue());
return text_indent_non_interpolable_value.LengthNonInterpolableValue();
}
void SetNonInterpolableValue(
scoped_refptr<const NonInterpolableValue> non_interpolable_value) final {
inner_underlying_value_.SetNonInterpolableValue(
CSSTextIndentNonInterpolableValue::Create(
std::move(non_interpolable_value), mode_));
}
private:
UnderlyingValue& inner_underlying_value_;
const IndentMode mode_;
};
namespace {
class UnderlyingIndentModeChecker
......@@ -186,9 +222,9 @@ CSSTextIndentInterpolationType::MaybeConvertStandardPropertyUnderlyingValue(
PairwiseInterpolationValue CSSTextIndentInterpolationType::MaybeMergeSingles(
InterpolationValue&& start,
InterpolationValue&& end) const {
CSSTextIndentNonInterpolableValue& start_non_interpolable_value =
const CSSTextIndentNonInterpolableValue& start_non_interpolable_value =
ToCSSTextIndentNonInterpolableValue(*start.non_interpolable_value);
CSSTextIndentNonInterpolableValue& end_non_interpolable_value =
const CSSTextIndentNonInterpolableValue& end_non_interpolable_value =
ToCSSTextIndentNonInterpolableValue(*end.non_interpolable_value);
if (start_non_interpolable_value.Mode() != end_non_interpolable_value.Mode())
......@@ -226,12 +262,12 @@ void CSSTextIndentInterpolationType::Composite(
return;
}
UnderlyingTextIndentAsLengthValue underlying_text_indent_as_length(
underlying_value_owner, mode);
LengthInterpolationFunctions::Composite(
underlying_value_owner.MutableValue().interpolable_value,
ToCSSTextIndentNonInterpolableValue(
*underlying_value_owner.MutableValue().non_interpolable_value)
.LengthNonInterpolableValue(),
underlying_fraction, *value.interpolable_value,
underlying_text_indent_as_length, underlying_fraction,
*value.interpolable_value,
non_interpolable_value.LengthNonInterpolableValue());
}
......
......@@ -39,9 +39,9 @@ class CSSTransformNonInterpolableValue : public NonInterpolableValue {
}
static scoped_refptr<CSSTransformNonInterpolableValue> Create(
CSSTransformNonInterpolableValue&& start,
const CSSTransformNonInterpolableValue& start,
double start_fraction,
CSSTransformNonInterpolableValue&& end,
const CSSTransformNonInterpolableValue& end,
double end_fraction) {
return base::AdoptRef(new CSSTransformNonInterpolableValue(
false, start.GetInterpolatedTransform(start_fraction),
......@@ -51,7 +51,7 @@ class CSSTransformNonInterpolableValue : public NonInterpolableValue {
scoped_refptr<CSSTransformNonInterpolableValue> Composite(
const CSSTransformNonInterpolableValue& other,
double other_progress) {
double other_progress) const {
DCHECK(!IsAdditive());
if (other.is_single_) {
DCHECK_EQ(other_progress, 0);
......@@ -107,7 +107,7 @@ class CSSTransformNonInterpolableValue : public NonInterpolableValue {
Vector<scoped_refptr<TransformOperation>> Concat(
const TransformOperations& a,
const TransformOperations& b) {
const TransformOperations& b) const {
Vector<scoped_refptr<TransformOperation>> result;
result.ReserveCapacity(a.size() + b.size());
result.AppendVector(a.Operations());
......@@ -247,7 +247,7 @@ void CSSTransformInterpolationType::Composite(
double underlying_fraction,
const InterpolationValue& value,
double interpolation_fraction) const {
CSSTransformNonInterpolableValue& underlying_non_interpolable_value =
const CSSTransformNonInterpolableValue& underlying_non_interpolable_value =
ToCSSTransformNonInterpolableValue(
*underlying_value_owner.Value().non_interpolable_value);
const CSSTransformNonInterpolableValue& non_interpolable_value =
......
......@@ -20,7 +20,7 @@ class FilterNonInterpolableValue : public NonInterpolableValue {
public:
static scoped_refptr<FilterNonInterpolableValue> Create(
FilterOperation::OperationType type,
scoped_refptr<NonInterpolableValue> type_non_interpolable_value) {
scoped_refptr<const NonInterpolableValue> type_non_interpolable_value) {
return base::AdoptRef(new FilterNonInterpolableValue(
type, std::move(type_non_interpolable_value)));
}
......@@ -35,12 +35,12 @@ class FilterNonInterpolableValue : public NonInterpolableValue {
private:
FilterNonInterpolableValue(
FilterOperation::OperationType type,
scoped_refptr<NonInterpolableValue> type_non_interpolable_value)
scoped_refptr<const NonInterpolableValue> type_non_interpolable_value)
: type_(type),
type_non_interpolable_value_(std::move(type_non_interpolable_value)) {}
const FilterOperation::OperationType type_;
scoped_refptr<NonInterpolableValue> type_non_interpolable_value_;
scoped_refptr<const NonInterpolableValue> type_non_interpolable_value_;
};
DEFINE_NON_INTERPOLABLE_VALUE_TYPE(FilterNonInterpolableValue);
......
......@@ -20,7 +20,8 @@ struct InterpolationValue {
explicit InterpolationValue(
std::unique_ptr<InterpolableValue> interpolable_value,
scoped_refptr<NonInterpolableValue> non_interpolable_value = nullptr)
scoped_refptr<const NonInterpolableValue> non_interpolable_value =
nullptr)
: interpolable_value(std::move(interpolable_value)),
non_interpolable_value(std::move(non_interpolable_value)) {}
......@@ -49,7 +50,7 @@ struct InterpolationValue {
}
std::unique_ptr<InterpolableValue> interpolable_value;
scoped_refptr<NonInterpolableValue> non_interpolable_value;
scoped_refptr<const NonInterpolableValue> non_interpolable_value;
};
} // namespace blink
......
......@@ -143,18 +143,6 @@ bool LengthInterpolationFunctions::HasPercentage(
}
void LengthInterpolationFunctions::Composite(
std::unique_ptr<InterpolableValue>& underlying_interpolable_value,
scoped_refptr<NonInterpolableValue>& underlying_non_interpolable_value,
double underlying_fraction,
const InterpolableValue& interpolable_value,
const NonInterpolableValue* non_interpolable_value) {
underlying_interpolable_value->ScaleAndAdd(underlying_fraction,
interpolable_value);
underlying_non_interpolable_value = CSSLengthNonInterpolableValue::Merge(
underlying_non_interpolable_value.get(), non_interpolable_value);
}
void LengthInterpolationFunctions::CompositeUnderlying(
UnderlyingValue& underlying_value,
double underlying_fraction,
const InterpolableValue& interpolable_value,
......
......@@ -32,16 +32,10 @@ class LengthInterpolationFunctions {
static bool NonInterpolableValuesAreCompatible(const NonInterpolableValue*,
const NonInterpolableValue*);
static bool HasPercentage(const NonInterpolableValue*);
// TODO(andruud): Unify these Composite* functions.
static void Composite(std::unique_ptr<InterpolableValue>&,
scoped_refptr<NonInterpolableValue>&,
static void Composite(UnderlyingValue&,
double underlying_fraction,
const InterpolableValue&,
const NonInterpolableValue*);
static void CompositeUnderlying(UnderlyingValue&,
double underlying_fraction,
const InterpolableValue&,
const NonInterpolableValue*);
static Length CreateLength(const InterpolableValue&,
const NonInterpolableValue*,
const CSSToLengthConversionData&,
......
......@@ -40,7 +40,7 @@ class UnderlyingItemValue : public UnderlyingValue {
.Get(index_);
}
void SetNonInterpolableValue(
scoped_refptr<NonInterpolableValue> non_interpolable_value) final {
scoped_refptr<const NonInterpolableValue> non_interpolable_value) final {
builder_.Set(index_, std::move(non_interpolable_value));
}
......@@ -156,16 +156,16 @@ PairwiseInterpolationValue ListInterpolationFunctions::MaybeMergeSingles(
std::make_unique<InterpolableList>(final_length);
auto result_end_interpolable_list =
std::make_unique<InterpolableList>(final_length);
Vector<scoped_refptr<NonInterpolableValue>> result_non_interpolable_values(
final_length);
Vector<scoped_refptr<const NonInterpolableValue>>
result_non_interpolable_values(final_length);
InterpolableList& start_interpolable_list =
ToInterpolableList(*start.interpolable_value);
InterpolableList& end_interpolable_list =
ToInterpolableList(*end.interpolable_value);
NonInterpolableList& start_non_interpolable_list =
const NonInterpolableList& start_non_interpolable_list =
ToNonInterpolableList(*start.non_interpolable_value);
NonInterpolableList& end_non_interpolable_list =
const NonInterpolableList& end_non_interpolable_list =
ToNonInterpolableList(*end.non_interpolable_value);
for (wtf_size_t i = 0; i < final_length; i++) {
......@@ -217,7 +217,7 @@ PairwiseInterpolationValue ListInterpolationFunctions::MaybeMergeSingles(
static void RepeatToLength(InterpolationValue& value, wtf_size_t length) {
InterpolableList& interpolable_list =
ToInterpolableList(*value.interpolable_value);
NonInterpolableList& non_interpolable_list =
const NonInterpolableList& non_interpolable_list =
ToNonInterpolableList(*value.non_interpolable_value);
wtf_size_t current_length = interpolable_list.length();
DCHECK_GT(current_length, 0U);
......@@ -225,7 +225,7 @@ static void RepeatToLength(InterpolationValue& value, wtf_size_t length) {
return;
DCHECK_LT(current_length, length);
auto new_interpolable_list = std::make_unique<InterpolableList>(length);
Vector<scoped_refptr<NonInterpolableValue>> new_non_interpolable_values(
Vector<scoped_refptr<const NonInterpolableValue>> new_non_interpolable_values(
length);
for (wtf_size_t i = length; i-- > 0;) {
new_interpolable_list->Set(
......@@ -246,18 +246,18 @@ static void PadToSameLength(InterpolationValue& value,
const InterpolationValue& length_value) {
InterpolableList& interpolable_list =
ToInterpolableList(*value.interpolable_value);
NonInterpolableList& non_interpolable_list =
const NonInterpolableList& non_interpolable_list =
ToNonInterpolableList(*value.non_interpolable_value);
const wtf_size_t current_length = interpolable_list.length();
InterpolableList& target_interpolable_list =
ToInterpolableList(*length_value.interpolable_value);
NonInterpolableList& target_non_interpolable_list =
const NonInterpolableList& target_non_interpolable_list =
ToNonInterpolableList(*length_value.non_interpolable_value);
const wtf_size_t target_length = target_interpolable_list.length();
DCHECK_LT(current_length, target_length);
auto new_interpolable_list =
std::make_unique<InterpolableList>(target_length);
Vector<scoped_refptr<NonInterpolableValue>> new_non_interpolable_values(
Vector<scoped_refptr<const NonInterpolableValue>> new_non_interpolable_values(
target_length);
wtf_size_t index = 0;
for (; index < current_length; index++) {
......@@ -353,11 +353,7 @@ void ListInterpolationFunctions::Composite(
if (underlying_length < final_length) {
RepeatToLength(underlying_value, final_length);
}
NonInterpolableList& underlying_non_interpolable_list =
ToNonInterpolableList(*underlying_value.non_interpolable_value);
NonInterpolableList::AutoBuilder builder(underlying_value_owner,
underlying_non_interpolable_list);
NonInterpolableList::AutoBuilder builder(underlying_value_owner);
for (wtf_size_t i = 0; i < final_length; i++) {
UnderlyingItemValue underlying_item(underlying_value_owner, builder, i);
......@@ -376,11 +372,8 @@ void ListInterpolationFunctions::Composite(
}
InterpolableList& underlying_interpolable_list =
ToInterpolableList(*underlying_value.interpolable_value);
NonInterpolableList& underlying_non_interpolable_list =
ToNonInterpolableList(*underlying_value.non_interpolable_value);
NonInterpolableList::AutoBuilder builder(underlying_value_owner,
underlying_non_interpolable_list);
NonInterpolableList::AutoBuilder builder(underlying_value_owner);
for (wtf_size_t i = 0; i < value_length; i++) {
UnderlyingItemValue underlying_item(underlying_value_owner, builder, i);
......@@ -394,11 +387,8 @@ void ListInterpolationFunctions::Composite(
}
}
NonInterpolableList::AutoBuilder::AutoBuilder(
UnderlyingValue& underlying_value,
NonInterpolableList& underlying_non_interpolable_list)
: underlying_value_(underlying_value),
underlying_non_interpolable_list_(underlying_non_interpolable_list) {
NonInterpolableList::AutoBuilder::AutoBuilder(UnderlyingValue& underlying_value)
: underlying_value_(underlying_value) {
DCHECK(underlying_value.GetNonInterpolableValue());
DCHECK(IsNonInterpolableList(underlying_value_.GetNonInterpolableValue()));
}
......@@ -417,12 +407,14 @@ NonInterpolableList::AutoBuilder::~AutoBuilder() {
void NonInterpolableList::AutoBuilder::Set(
wtf_size_t index,
scoped_refptr<NonInterpolableValue> non_interpolable_value) {
scoped_refptr<const NonInterpolableValue> non_interpolable_value) {
// Copy list on first call to Set.
if (!list_.size()) {
wtf_size_t underlying_length = underlying_non_interpolable_list_.length();
const auto& non_interpolable_list =
ToNonInterpolableList(*underlying_value_.GetNonInterpolableValue());
wtf_size_t underlying_length = non_interpolable_list.length();
for (wtf_size_t i = 0; i < underlying_length; ++i)
list_.push_back(underlying_non_interpolable_list_.Get(i));
list_.push_back(non_interpolable_list.Get(i));
}
DCHECK_LT(index, list_.size());
......
......@@ -74,7 +74,7 @@ class CORE_EXPORT NonInterpolableList : public NonInterpolableValue {
return base::AdoptRef(new NonInterpolableList());
}
static scoped_refptr<NonInterpolableList> Create(
Vector<scoped_refptr<NonInterpolableValue>>&& list) {
Vector<scoped_refptr<const NonInterpolableValue>>&& list) {
return base::AdoptRef(new NonInterpolableList(std::move(list)));
}
......@@ -82,7 +82,6 @@ class CORE_EXPORT NonInterpolableList : public NonInterpolableValue {
const NonInterpolableValue* Get(wtf_size_t index) const {
return list_[index].get();
}
NonInterpolableValue* Get(wtf_size_t index) { return list_[index].get(); }
// This class can update the NonInterpolableList of an UnderlyingValue with
// a series of mutations. The actual update of the list is delayed until the
......@@ -94,27 +93,24 @@ class CORE_EXPORT NonInterpolableList : public NonInterpolableValue {
public:
// The UnderlyingValue provided here is assumed to contain a
// non-nullptr NonInterpolableList.
//
// TODO(andruud): Remove NonInterpolableList& param.
AutoBuilder(UnderlyingValue&, NonInterpolableList&);
AutoBuilder(UnderlyingValue&);
~AutoBuilder();
void Set(wtf_size_t index, scoped_refptr<NonInterpolableValue>);
void Set(wtf_size_t index, scoped_refptr<const NonInterpolableValue>);
private:
UnderlyingValue& underlying_value_;
NonInterpolableList& underlying_non_interpolable_list_;
Vector<scoped_refptr<NonInterpolableValue>> list_;
Vector<scoped_refptr<const NonInterpolableValue>> list_;
};
DECLARE_NON_INTERPOLABLE_VALUE_TYPE();
private:
NonInterpolableList() = default;
NonInterpolableList(Vector<scoped_refptr<NonInterpolableValue>>&& list)
NonInterpolableList(Vector<scoped_refptr<const NonInterpolableValue>>&& list)
: list_(list) {}
Vector<scoped_refptr<NonInterpolableValue>> list_;
Vector<scoped_refptr<const NonInterpolableValue>> list_;
};
DEFINE_NON_INTERPOLABLE_VALUE_TYPE_CASTS(NonInterpolableList);
......@@ -126,7 +122,8 @@ InterpolationValue ListInterpolationFunctions::CreateList(
if (length == 0)
return CreateEmptyList();
auto interpolable_list = std::make_unique<InterpolableList>(length);
Vector<scoped_refptr<NonInterpolableValue>> non_interpolable_values(length);
Vector<scoped_refptr<const NonInterpolableValue>> non_interpolable_values(
length);
for (wtf_size_t i = 0; i < length; i++) {
InterpolationValue item = create_item(i);
if (!item)
......
......@@ -60,7 +60,7 @@ class TestUnderlyingValue : public UnderlyingValue {
}
void SetNonInterpolableValue(
scoped_refptr<NonInterpolableValue> non_interpolable_value) final {
scoped_refptr<const NonInterpolableValue> non_interpolable_value) final {
interpolation_value_.non_interpolable_value = non_interpolable_value;
}
......@@ -254,7 +254,7 @@ TEST(ListInterpolationFunctionsTest, BuilderNoModify) {
{
TestUnderlyingValue underlying_value(list);
NonInterpolableList::AutoBuilder builder(underlying_value, before);
NonInterpolableList::AutoBuilder builder(underlying_value);
}
auto& after = ToNonInterpolableList(*list.non_interpolable_value);
......@@ -272,7 +272,7 @@ TEST(ListInterpolationFunctionsTest, BuilderModifyFirst) {
{
TestUnderlyingValue underlying_value(list);
NonInterpolableList::AutoBuilder builder(underlying_value, before);
NonInterpolableList::AutoBuilder builder(underlying_value);
builder.Set(0, TestNonInterpolableValue::Create(4));
}
......@@ -291,7 +291,7 @@ TEST(ListInterpolationFunctionsTest, BuilderModifyMiddle) {
{
TestUnderlyingValue underlying_value(list);
NonInterpolableList::AutoBuilder builder(underlying_value, before);
NonInterpolableList::AutoBuilder builder(underlying_value);
builder.Set(1, TestNonInterpolableValue::Create(4));
}
......@@ -310,7 +310,7 @@ TEST(ListInterpolationFunctionsTest, BuilderModifyLast) {
{
TestUnderlyingValue underlying_value(list);
NonInterpolableList::AutoBuilder builder(underlying_value, before);
NonInterpolableList::AutoBuilder builder(underlying_value);
builder.Set(2, TestNonInterpolableValue::Create(4));
}
......@@ -329,7 +329,7 @@ TEST(ListInterpolationFunctionsTest, BuilderModifyAll) {
{
TestUnderlyingValue underlying_value(list);
NonInterpolableList::AutoBuilder builder(underlying_value, before);
NonInterpolableList::AutoBuilder builder(underlying_value);
builder.Set(0, TestNonInterpolableValue::Create(4));
builder.Set(1, TestNonInterpolableValue::Create(5));
builder.Set(2, TestNonInterpolableValue::Create(6));
......@@ -350,7 +350,7 @@ TEST(ListInterpolationFunctionsTest, BuilderModifyReverse) {
{
TestUnderlyingValue underlying_value(list);
NonInterpolableList::AutoBuilder builder(underlying_value, before);
NonInterpolableList::AutoBuilder builder(underlying_value);
builder.Set(3, TestNonInterpolableValue::Create(6));
builder.Set(1, TestNonInterpolableValue::Create(7));
}
......@@ -372,7 +372,7 @@ TEST(ListInterpolationFunctionsTest, BuilderModifyListWithOneItem) {
{
TestUnderlyingValue underlying_value(list);
NonInterpolableList::AutoBuilder builder(underlying_value, before);
NonInterpolableList::AutoBuilder builder(underlying_value);
builder.Set(0, TestNonInterpolableValue::Create(4));
}
......
......@@ -20,7 +20,8 @@ struct PairwiseInterpolationValue {
PairwiseInterpolationValue(
std::unique_ptr<InterpolableValue> start_interpolable_value,
std::unique_ptr<InterpolableValue> end_interpolable_value,
scoped_refptr<NonInterpolableValue> non_interpolable_value = nullptr)
scoped_refptr<const NonInterpolableValue> non_interpolable_value =
nullptr)
: start_interpolable_value(std::move(start_interpolable_value)),
end_interpolable_value(std::move(end_interpolable_value)),
non_interpolable_value(std::move(non_interpolable_value)) {}
......@@ -36,7 +37,7 @@ struct PairwiseInterpolationValue {
std::unique_ptr<InterpolableValue> start_interpolable_value;
std::unique_ptr<InterpolableValue> end_interpolable_value;
scoped_refptr<NonInterpolableValue> non_interpolable_value;
scoped_refptr<const NonInterpolableValue> non_interpolable_value;
};
} // namespace blink
......
......@@ -48,7 +48,7 @@ class PairwisePrimitiveInterpolation : public PrimitiveInterpolation {
const InterpolationType& type,
std::unique_ptr<InterpolableValue> start,
std::unique_ptr<InterpolableValue> end,
scoped_refptr<NonInterpolableValue> non_interpolable_value)
scoped_refptr<const NonInterpolableValue> non_interpolable_value)
: type_(type),
start_(std::move(start)),
end_(std::move(end)),
......@@ -86,7 +86,7 @@ class PairwisePrimitiveInterpolation : public PrimitiveInterpolation {
const InterpolationType& type_;
std::unique_ptr<InterpolableValue> start_;
std::unique_ptr<InterpolableValue> end_;
scoped_refptr<NonInterpolableValue> non_interpolable_value_;
scoped_refptr<const NonInterpolableValue> non_interpolable_value_;
};
// Represents a pair of incompatible keyframes that fall back to 50% flip
......
......@@ -19,7 +19,7 @@ class CSSSizeNonInterpolableValue : public NonInterpolableValue {
}
static scoped_refptr<CSSSizeNonInterpolableValue> Create(
scoped_refptr<NonInterpolableValue> length_non_interpolable_value) {
scoped_refptr<const NonInterpolableValue> length_non_interpolable_value) {
return base::AdoptRef(new CSSSizeNonInterpolableValue(
std::move(length_non_interpolable_value)));
}
......@@ -44,13 +44,13 @@ class CSSSizeNonInterpolableValue : public NonInterpolableValue {
}
CSSSizeNonInterpolableValue(
scoped_refptr<NonInterpolableValue> length_non_interpolable_value)
scoped_refptr<const NonInterpolableValue> length_non_interpolable_value)
: keyword_(CSSValueID::kInvalid),
length_non_interpolable_value_(
std::move(length_non_interpolable_value)) {}
CSSValueID keyword_;
scoped_refptr<NonInterpolableValue> length_non_interpolable_value_;
scoped_refptr<const NonInterpolableValue> length_non_interpolable_value_;
};
DEFINE_NON_INTERPOLABLE_VALUE_TYPE(CSSSizeNonInterpolableValue);
......@@ -58,12 +58,11 @@ DEFINE_NON_INTERPOLABLE_VALUE_TYPE_CASTS(CSSSizeNonInterpolableValue);
// A wrapper for the UnderlyingValue passed to
// SizeInterpolationFunctions::Composite which can be forwarded to
// LengthInterpolationFunctions::CompositeUnderlying.
// LengthInterpolationFunctions::Composite.
//
// If LengthInterpolationFunctions::CompositeUnderlying calls
// SetNonInterpolableValue with a new NonInterpolableValue, this class
// wraps it in a new CSSSizeNonInterpolableValue before being set on the inner
// UnderlyingValue.
// If LengthInterpolationFunctions::Composite calls SetNonInterpolableValue with
// a new NonInterpolableValue, this class wraps it in a new
// CSSSizeNonInterpolableValue before being set on the inner UnderlyingValue.
class UnderlyingSizeAsLengthValue : public UnderlyingValue {
STACK_ALLOCATED();
......@@ -82,7 +81,7 @@ class UnderlyingSizeAsLengthValue : public UnderlyingValue {
}
void SetNonInterpolableValue(
scoped_refptr<NonInterpolableValue> non_interpolable_value) final {
scoped_refptr<const NonInterpolableValue> non_interpolable_value) final {
inner_underlying_value_.SetNonInterpolableValue(
CSSSizeNonInterpolableValue::Create(std::move(non_interpolable_value)));
}
......@@ -197,7 +196,7 @@ void SizeInterpolationFunctions::Composite(
if (size_non_interpolable_value.IsKeyword())
return;
UnderlyingSizeAsLengthValue underlying_size_as_length(underlying_value);
LengthInterpolationFunctions::CompositeUnderlying(
LengthInterpolationFunctions::Composite(
underlying_size_as_length, underlying_fraction, interpolable_value,
size_non_interpolable_value.LengthNonInterpolableValue());
}
......
......@@ -34,8 +34,8 @@ const InterpolableValue& TransitionInterpolation::CurrentInterpolableValue()
return *cached_interpolable_value_;
}
NonInterpolableValue* TransitionInterpolation::CurrentNonInterpolableValue()
const {
const NonInterpolableValue*
TransitionInterpolation::CurrentNonInterpolableValue() const {
if (cached_fraction_ == 0) {
return start_.non_interpolable_value.get();
}
......
......@@ -95,7 +95,7 @@ class CORE_EXPORT TransitionInterpolation : public Interpolation {
private:
const InterpolableValue& CurrentInterpolableValue() const;
NonInterpolableValue* CurrentNonInterpolableValue() const;
const NonInterpolableValue* CurrentNonInterpolableValue() const;
const PropertyHandle property_;
const InterpolationType& type_;
......
......@@ -22,10 +22,10 @@ class TypedInterpolationValue {
USING_FAST_MALLOC(TypedInterpolationValue);
public:
TypedInterpolationValue(
const InterpolationType& type,
std::unique_ptr<InterpolableValue> interpolable_value,
scoped_refptr<NonInterpolableValue> non_interpolable_value = nullptr)
TypedInterpolationValue(const InterpolationType& type,
std::unique_ptr<InterpolableValue> interpolable_value,
scoped_refptr<const NonInterpolableValue>
non_interpolable_value = nullptr)
: type_(type),
value_(std::move(interpolable_value),
std::move(non_interpolable_value)) {
......
......@@ -29,7 +29,8 @@ class CORE_EXPORT UnderlyingValue {
// The NonInterpolableValue part of the underlying value may not be mutated,
// hence there is no MutableNonInterpolableValue function. However, the
// NonInterpolableValue part may be replaced entirely with this function.
virtual void SetNonInterpolableValue(scoped_refptr<NonInterpolableValue>) = 0;
virtual void SetNonInterpolableValue(
scoped_refptr<const NonInterpolableValue>) = 0;
};
} // namespace blink
......
......@@ -24,7 +24,7 @@ const NonInterpolableValue* UnderlyingValueOwner::GetNonInterpolableValue()
}
void UnderlyingValueOwner::SetNonInterpolableValue(
scoped_refptr<NonInterpolableValue> non_interpolable_value) {
scoped_refptr<const NonInterpolableValue> non_interpolable_value) {
MutableValue().non_interpolable_value = non_interpolable_value;
}
......
......@@ -34,7 +34,7 @@ class CORE_EXPORT UnderlyingValueOwner : public UnderlyingValue {
// UnderlyingValue
InterpolableValue& MutableInterpolableValue() final;
const NonInterpolableValue* GetNonInterpolableValue() const final;
void SetNonInterpolableValue(scoped_refptr<NonInterpolableValue>) final;
void SetNonInterpolableValue(scoped_refptr<const NonInterpolableValue>) final;
const InterpolationType& GetType() const {
DCHECK(type_);
......
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