Chromium Code Reviews| Index: third_party/WebKit/Source/core/animation/animatable/AnimatablePath.cpp |
| diff --git a/third_party/WebKit/Source/core/animation/animatable/AnimatablePath.cpp b/third_party/WebKit/Source/core/animation/animatable/AnimatablePath.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..71b56c4461edcaa6375d7315cbee9ac8d84602ef |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/animation/animatable/AnimatablePath.cpp |
| @@ -0,0 +1,62 @@ |
| +// 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/animatable/AnimatablePath.h" |
| + |
| +#include "core/svg/SVGPathBlender.h" |
| +#include "core/svg/SVGPathByteStreamBuilder.h" |
| +#include "core/svg/SVGPathByteStreamSource.h" |
| +#include "core/svg/SVGPathUtilities.h" |
| + |
| +namespace blink { |
| + |
| +bool AnimatablePath::usesDefaultInterpolationWith(const AnimatableValue* value) const |
| +{ |
| + // Default interpolation is used if the paths have different lengths, |
| + // or the paths have a segment with different types (ignoring "relativeness"). |
| + |
| + SVGPathByteStreamSource fromSource(pathValue()->byteStream()); |
| + SVGPathByteStreamSource toSource(toAnimatablePath(value)->pathValue()->byteStream()); |
| + |
| + while (fromSource.hasMoreData()) { |
| + if (!toSource.hasMoreData()) |
| + return true; |
| + |
| + PathSegmentData fromSeg = fromSource.parseSegment(); |
| + PathSegmentData toSeg = toSource.parseSegment(); |
| + if (fromSeg.command == PathSegUnknown || toSeg.command == PathSegUnknown) |
|
fs
2015/12/15 11:52:52
'PathSegUnknown' should never be stored in an SVGP
Eric Willigers
2015/12/15 22:33:55
Replaced with assert.
|
| + return true; |
| + |
| + if (toAbsolutePathSegType(fromSeg.command) != toAbsolutePathSegType(toSeg.command)) |
| + return true; |
| + } |
| + |
| + return toSource.hasMoreData(); |
| +} |
| + |
| +PassRefPtr<AnimatableValue> AnimatablePath::interpolateTo(const AnimatableValue* value, double fraction) const |
| +{ |
| + if (usesDefaultInterpolationWith(value)) |
| + return defaultInterpolateTo(this, value, fraction); |
| + |
| + OwnPtr<SVGPathByteStream> byteStream; |
| + byteStream = SVGPathByteStream::create(); |
|
fs
2015/12/15 11:52:52
These two lines could be merged.
Eric Willigers
2015/12/15 22:33:55
Done.
|
| + SVGPathByteStreamBuilder builder(*byteStream); |
| + |
| + SVGPathByteStreamSource fromSource(pathValue()->byteStream()); |
| + SVGPathByteStreamSource toSource(toAnimatablePath(value)->pathValue()->byteStream()); |
| + |
| + SVGPathBlender blender(&fromSource, &toSource, &builder); |
| + bool ok = blender.blendAnimatedPath(fraction); |
| + ASSERT_UNUSED(ok, ok); |
| + return AnimatablePath::create(CSSPathValue::create(byteStream.release())); |
| +} |
| + |
| +bool AnimatablePath::equalTo(const AnimatableValue* value) const |
| +{ |
| + return pathValue()->equals(*toAnimatablePath(value)->pathValue()); |
| +} |
| + |
| +} // namespace blink |