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

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: crbug.com/466536 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..923604f9b6093f157ea25f8a4d05c22c115fca19
--- /dev/null
+++ b/Source/core/animation/ImageSliceStyleInterpolation.cpp
@@ -0,0 +1,99 @@
+// 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/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;
+}
+
+// PassDecompositionResult is required because the Windows compiler fails to call the OwnPtr(OwnPtr&&) constructor.
+struct PassDecompositionResult {
+ PassOwnPtrWillBeRawPtr<InterpolableValue> interpolableValue;
+ ImageSliceStyleInterpolation::Metadata metadata;
+};
+
+struct DecompositionResult {
+ DecompositionResult(const PassDecompositionResult& o)
+ : interpolableValue(o.interpolableValue)
+ , metadata(o.metadata)
+ { }
+ OwnPtrWillBeRawPtr<InterpolableValue> interpolableValue;
+ ImageSliceStyleInterpolation::Metadata metadata;
+};
+
+static PassDecompositionResult decompose(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
+ && quad.right()->isPercentage() == isPercentage);
+ return PassDecompositionResult {
+ interpolableList.release(),
+ ImageSliceStyleInterpolation::Metadata {isPercentage, value.m_fill},
+ };
+}
+
+static PassRefPtr<CSSBorderImageSliceValue> compose(const InterpolableValue& value, const ImageSliceStyleInterpolation::Metadata& metadata)
+{
+ const InterpolableList& interpolableList = toInterpolableList(value);
+ CSSPrimitiveValue::UnitType type = metadata.isPercentage ? CSSPrimitiveValue::CSS_PERCENTAGE : CSSPrimitiveValue::CSS_NUMBER;
+ RefPtrWillBeRawPtr<Quad> quad = Quad::create();
+ quad->setTop(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(interpolableList.get(0))->value(), 0), type));
+ quad->setRight(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(interpolableList.get(1))->value(), 0), type));
+ quad->setBottom(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(interpolableList.get(2))->value(), 0), type));
+ quad->setLeft(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(interpolableList.get(3))->value(), 0), type));
+ return CSSBorderImageSliceValue::create(CSSPrimitiveValue::create(quad.release()), metadata.fill);
+}
+
+PassRefPtrWillBeRawPtr<ImageSliceStyleInterpolation> ImageSliceStyleInterpolation::maybeCreate(const CSSValue& start, const CSSValue& end, CSSPropertyID property)
+{
+ if (!start.isBorderImageSliceValue() || !end.isBorderImageSliceValue())
+ return nullptr;
+
+ DecompositionResult startDecompose = decompose(toCSSBorderImageSliceValue(start));
+ DecompositionResult endDecompose = decompose(toCSSBorderImageSliceValue(end));
+ if (!(startDecompose.metadata == endDecompose.metadata))
+ return nullptr;
+
+ return adoptRefWillBeNoop(new ImageSliceStyleInterpolation(
+ startDecompose.interpolableValue.release(),
+ endDecompose.interpolableValue.release(),
+ property,
+ startDecompose.metadata
+ ));
+}
+
+void ImageSliceStyleInterpolation::apply(StyleResolverState& state) const
+{
+ StyleBuilder::applyProperty(m_id, state, compose(*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