Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(987)

Unified Diff: third_party/WebKit/Source/core/animation/SVGNumberListInterpolationType.cpp

Issue 1410343009: [WIP] Web Animations: Migrate SVG number list interpolation to interpolation types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/animation/SVGNumberListInterpolationType.cpp
diff --git a/third_party/WebKit/Source/core/animation/SVGNumberListInterpolationType.cpp b/third_party/WebKit/Source/core/animation/SVGNumberListInterpolationType.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c8a7c511c66416cd4b1885462bee1c3fdd7fc123
--- /dev/null
+++ b/third_party/WebKit/Source/core/animation/SVGNumberListInterpolationType.cpp
@@ -0,0 +1,74 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/animation/SVGNumberListInterpolationType.h"
+
+#include "core/animation/InterpolationEnvironment.h"
+#include "core/svg/SVGNumberList.h"
+#include "core/svg/properties/SVGAnimatedProperty.h"
+
+namespace blink {
+
+PassOwnPtr<InterpolationValue> SVGNumberListInterpolationType::maybeConvertNeutral() const
+{
+ return InterpolationValue::create(*this, InterpolableList::create(0));
+}
+
+PassOwnPtr<InterpolationValue> SVGNumberListInterpolationType::maybeConvertSVGValue(const SVGPropertyBase& svgValue) const
+{
+ if (svgValue.type() != AnimatedNumberList)
+ return nullptr;
+ const SVGNumberList& svgList = static_cast<const SVGNumberList&>(svgValue);
+ OwnPtr<InterpolableList> result = InterpolableList::create(svgList.length());
+ for (size_t i = 0; i < svgList.length(); i++)
+ result->set(i, InterpolableNumber::create(svgList.at(i)->value()));
+ return InterpolationValue::create(*this, result.release());
+}
+
+PassOwnPtr<InterpolationValue> SVGNumberListInterpolationType::maybeConvertUnderlyingValue(const InterpolationEnvironment& environment) const
+{
+ return maybeConvertSVGValue(environment.svgBaseValue());
+}
+
+RefPtrWillBeRawPtr<SVGPropertyBase> SVGNumberListInterpolationType::appliedSVGValue(const InterpolableValue& interpolableValue, const NonInterpolableValue*) const
+{
+ RefPtrWillBeRawPtr<SVGNumberList> result = SVGNumberList::create();
+ const InterpolableList& list = toInterpolableList(interpolableValue);
+ for (size_t i = 0; i < list.length(); ++i)
+ result->append(SVGNumber::create(toInterpolableNumber(list.get(i))->value()));
+ return result.release();
+}
+
+PassOwnPtr<InterpolableList> padWithZeroes(PassOwnPtr<InterpolableValue> listValue, size_t paddedLength)
+{
+ ASSERT(listValue && listValue->isList());
+ InterpolableList& list = toInterpolableList(*listValue);
+ OwnPtr<InterpolableList> result = InterpolableList::create(paddedLength);
+ for (size_t i = 0; i < list.length(); ++i)
+ result->set(i, list.getMutable(i).release());
+ for (size_t i = list.length(); i < paddedLength; ++i)
+ result->set(i, InterpolableNumber::create(0));
+
+ return result.release();
+}
+
+PassOwnPtr<PairwisePrimitiveInterpolation> SVGNumberListInterpolationType::mergeSingleConversions(InterpolationValue& startValue, InterpolationValue& endValue) const
+{
+ OwnPtr<InterpolableValue> start = startValue.mutableComponent().interpolableValue.release();
+ OwnPtr<InterpolableValue> end = endValue.mutableComponent().interpolableValue.release();
+
+ size_t startLength = toInterpolableList(*start).length();
+ size_t endLength = toInterpolableList(*end).length();
+ if (startLength < endLength)
+ start = padWithZeroes(start.release(), endLength);
+ if (endLength < startLength)
+ end = padWithZeroes(end.release(), startLength);
+
+ RELEASE_ASSERT(toInterpolableList(*start).length() == toInterpolableList(*end).length());
+
+ return PairwisePrimitiveInterpolation::create(*this, start.release(), end.release(), nullptr);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698