Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/animation/ImageSliceStyleInterpolation.h" | |
| 7 | |
| 8 #include "core/css/CSSBorderImageSliceValue.h" | |
| 9 #include "core/css/CSSPrimitiveValue.h" | |
| 10 #include "core/css/Rect.h" | |
| 11 #include "core/css/resolver/StyleBuilder.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 bool ImageSliceStyleInterpolation::usesDefaultInterpolation(const CSSValue& star t, const CSSValue& end) | |
| 16 { | |
| 17 if (!start.isBorderImageSliceValue() || !end.isBorderImageSliceValue()) | |
| 18 return true; | |
| 19 const CSSBorderImageSliceValue& startSlice = toCSSBorderImageSliceValue(star t); | |
| 20 const CSSBorderImageSliceValue& endSlice = toCSSBorderImageSliceValue(end); | |
| 21 return startSlice.slices()->top()->isPercentage() != endSlice.slices()->top( )->isPercentage() | |
| 22 || startSlice.m_fill != endSlice.m_fill; | |
| 23 } | |
| 24 | |
| 25 PassRefPtrWillBeRawPtr<ImageSliceStyleInterpolation> ImageSliceStyleInterpolatio n::maybeCreate(const CSSValue& start, const CSSValue& end, CSSPropertyID propert y) | |
| 26 { | |
| 27 if (!start.isBorderImageSliceValue() || !end.isBorderImageSliceValue()) | |
| 28 return nullptr; | |
| 29 | |
| 30 PartitionResult startPartition = partition(toCSSBorderImageSliceValue(start) ); | |
| 31 PartitionResult endPartition = partition(toCSSBorderImageSliceValue(end)); | |
| 32 if (!(startPartition.metadata == endPartition.metadata)) | |
| 33 return nullptr; | |
| 34 | |
| 35 return adoptRefWillBeNoop(new ImageSliceStyleInterpolation( | |
| 36 startPartition.interpolableValue.release(), | |
| 37 endPartition.interpolableValue.release(), | |
| 38 property, | |
| 39 startPartition.metadata | |
| 40 )); | |
| 41 } | |
| 42 | |
| 43 ImageSliceStyleInterpolation::PartitionResult ImageSliceStyleInterpolation::part ition(const CSSBorderImageSliceValue& value) | |
| 44 { | |
| 45 const size_t kQuadSides = 4; | |
| 46 OwnPtrWillBeRawPtr<InterpolableList> interpolableList = InterpolableList::cr eate(kQuadSides); | |
| 47 const Quad& quad = *value.slices(); | |
| 48 interpolableList->set(0, InterpolableNumber::create(quad.top()->getDoubleVal ue())); | |
| 49 interpolableList->set(1, InterpolableNumber::create(quad.right()->getDoubleV alue())); | |
| 50 interpolableList->set(2, InterpolableNumber::create(quad.bottom()->getDouble Value())); | |
| 51 interpolableList->set(3, InterpolableNumber::create(quad.left()->getDoubleVa lue())); | |
| 52 bool isPercentage = quad.top()->isPercentage(); | |
| 53 ASSERT(quad.bottom()->isPercentage() == isPercentage | |
| 54 || quad.left()->isPercentage() == isPercentage | |
|
Eric Willigers
2015/03/11 05:38:09
&&
| |
| 55 || quad.right()->isPercentage() == isPercentage); | |
| 56 return PartitionResult { | |
| 57 interpolableList.release(), | |
| 58 Metadata {isPercentage, value.m_fill}, | |
| 59 }; | |
| 60 } | |
| 61 | |
| 62 static PassRefPtrWillBeRawPtr<Quad> createQuad(const InterpolableList& list, boo l isPercentage) | |
| 63 { | |
| 64 CSSPrimitiveValue::UnitType type = isPercentage ? CSSPrimitiveValue::CSS_PER CENTAGE : CSSPrimitiveValue::CSS_NUMBER; | |
| 65 RefPtrWillBeRawPtr<Quad> quad = Quad::create(); | |
| 66 quad->setTop(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(list.get (0))->value(), 0), type)); | |
| 67 quad->setRight(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(list.g et(1))->value(), 0), type)); | |
| 68 quad->setBottom(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(list. get(2))->value(), 0), type)); | |
| 69 quad->setLeft(CSSPrimitiveValue::create(clampTo(toInterpolableNumber(list.ge t(3))->value(), 0), type)); | |
| 70 return quad.release(); | |
| 71 } | |
| 72 | |
| 73 PassRefPtr<CSSBorderImageSliceValue> ImageSliceStyleInterpolation::combine(const InterpolableValue& value, const ImageSliceStyleInterpolation::Metadata& metadat a) | |
| 74 { | |
| 75 const InterpolableList& interpolableList = toInterpolableList(value); | |
| 76 return CSSBorderImageSliceValue::create(CSSPrimitiveValue::create(createQuad (interpolableList, metadata.isPercentage)), metadata.fill); | |
| 77 } | |
| 78 | |
| 79 void ImageSliceStyleInterpolation::apply(StyleResolverState& state) const | |
| 80 { | |
| 81 StyleBuilder::applyProperty(m_id, state, combine(*m_cachedValue, m_metadata) .get()); | |
| 82 } | |
| 83 | |
| 84 DEFINE_TRACE(ImageSliceStyleInterpolation) | |
| 85 { | |
| 86 StyleInterpolation::trace(visitor); | |
| 87 } | |
| 88 | |
| 89 } // namespace blink | |
| OLD | NEW |