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

Unified Diff: Source/core/animation/ImageSliceStyleInterpolation.cpp

Issue 995253002: Web Animations: Split image slice interpolation out of LengthBoxStyleInterpolation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 9 months 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: Source/core/animation/ImageSliceStyleInterpolation.cpp
diff --git a/Source/core/animation/ImageSliceStyleInterpolation.cpp b/Source/core/animation/ImageSliceStyleInterpolation.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..055e7537ef632f76b0143fa646e74b2d9f42be2a
--- /dev/null
+++ b/Source/core/animation/ImageSliceStyleInterpolation.cpp
@@ -0,0 +1,89 @@
+// Copyright 2014 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/ImageSliceStyleInterpolation.h"
+
+#include "core/css/CSSBorderImageSliceValue.h"
+#include "core/css/CSSPrimitiveValue.h"
+#include "core/css/Rect.h"
+#include "core/css/resolver/StyleBuilder.h"
+
+namespace blink {
+
+bool ImageSliceStyleInterpolation::usesDefaultInterpolation(const CSSValue& start, const CSSValue& end)
+{
+ if (!start.isBorderImageSliceValue() || !end.isBorderImageSliceValue())
+ return true;
+ const CSSBorderImageSliceValue& startSlice = toCSSBorderImageSliceValue(start);
+ const CSSBorderImageSliceValue& endSlice = toCSSBorderImageSliceValue(end);
+ return startSlice.slices()->top()->isPercentage() != endSlice.slices()->top()->isPercentage()
+ || startSlice.m_fill != endSlice.m_fill;
+}
+
+PassRefPtrWillBeRawPtr<ImageSliceStyleInterpolation> ImageSliceStyleInterpolation::maybeCreate(const CSSValue& start, const CSSValue& end, CSSPropertyID property)
+{
+ if (!start.isBorderImageSliceValue() || !end.isBorderImageSliceValue())
+ return nullptr;
+
+ PartitionResult startPartition = partition(toCSSBorderImageSliceValue(start));
+ PartitionResult endPartition = partition(toCSSBorderImageSliceValue(end));
+ if (!(startPartition.metadata == endPartition.metadata))
+ return nullptr;
+
+ return adoptRefWillBeNoop(new ImageSliceStyleInterpolation(
+ startPartition.interpolableValue.release(),
+ endPartition.interpolableValue.release(),
+ property,
+ startPartition.metadata
+ ));
+}
+
+ImageSliceStyleInterpolation::PartitionResult ImageSliceStyleInterpolation::partition(const CSSBorderImageSliceValue& value)
+{
+ const size_t kQuadSides = 4;
+ OwnPtrWillBeRawPtr<InterpolableList> interpolableList = InterpolableList::create(kQuadSides);
+ const Quad& quad = *value.slices();
+ interpolableList->set(0, InterpolableNumber::create(quad.top()->getDoubleValue()));
+ interpolableList->set(1, InterpolableNumber::create(quad.right()->getDoubleValue()));
+ interpolableList->set(2, InterpolableNumber::create(quad.bottom()->getDoubleValue()));
+ interpolableList->set(3, InterpolableNumber::create(quad.left()->getDoubleValue()));
+ bool isPercentage = quad.top()->isPercentage();
+ ASSERT(quad.bottom()->isPercentage() == isPercentage
+ || quad.left()->isPercentage() == isPercentage
dstockwell 2015/03/11 05:33:26 did you mean && ?
alancutter (OOO until 2018) 2015/03/11 05:42:41 Done.
+ || quad.right()->isPercentage() == isPercentage);
+ return PartitionResult {
+ interpolableList.release(),
+ Metadata {isPercentage, value.m_fill},
+ };
+}
+
+static PassRefPtrWillBeRawPtr<Quad> createQuad(const InterpolableList& list, bool isPercentage)
+{
+ CSSPrimitiveValue::UnitType type = isPercentage ? CSSPrimitiveValue::CSS_PERCENTAGE : CSSPrimitiveValue::CSS_NUMBER;
+ RefPtrWillBeRawPtr<Quad> quad = Quad::create();
+ quad->setTop(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(list.get(0))->value(), 0), type));
+ quad->setRight(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(list.get(1))->value(), 0), type));
+ quad->setBottom(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(list.get(2))->value(), 0), type));
+ quad->setLeft(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(list.get(3))->value(), 0), type));
+ return quad.release();
+}
+
+PassRefPtr<CSSBorderImageSliceValue> ImageSliceStyleInterpolation::combine(const InterpolableValue& value, const ImageSliceStyleInterpolation::Metadata& metadata)
+{
+ const InterpolableList& interpolableList = toInterpolableList(value);
+ return CSSBorderImageSliceValue::create(CSSPrimitiveValue::create(createQuad(interpolableList, metadata.isPercentage)), metadata.fill);
+}
+
+void ImageSliceStyleInterpolation::apply(StyleResolverState& state) const
+{
+ StyleBuilder::applyProperty(m_id, state, combine(*m_cachedValue, m_metadata).get());
+}
+
+DEFINE_TRACE(ImageSliceStyleInterpolation)
+{
+ StyleInterpolation::trace(visitor);
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/animation/ImageSliceStyleInterpolation.h ('k') | Source/core/animation/LengthBoxStyleInterpolation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698