Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/animation/ShadowStyleInterpolation.h" | 6 #include "core/animation/ShadowStyleInterpolation.h" |
| 7 | 7 |
| 8 #include "core/animation/ColorStyleInterpolation.h" | 8 #include "core/animation/ColorStyleInterpolation.h" |
| 9 #include "core/animation/LengthStyleInterpolation.h" | 9 #include "core/animation/LengthStyleInterpolation.h" |
| 10 #include "core/css/CSSPrimitiveValue.h" | 10 #include "core/css/CSSPrimitiveValue.h" |
| 11 #include "core/css/CSSValuePool.h" | 11 #include "core/css/CSSValuePool.h" |
| 12 #include "core/css/resolver/StyleBuilder.h" | 12 #include "core/css/resolver/StyleBuilder.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 bool ShadowStyleInterpolation::canCreateFrom(const CSSValue& value) | 16 bool ShadowStyleInterpolation::canCreateFrom(const CSSValue& start, const CSSVal ue& end) |
| 17 { | 17 { |
| 18 return value.isShadowValue(); | 18 if (start.isShadowValue() || end.isShadowValue()) { |
|
samli
2015/01/23 03:23:36
Should be &&
evemj (not active)
2015/01/28 00:41:14
Done.
| |
| 19 return toCSSShadowValue(start).style == toCSSShadowValue(end).style; | |
| 20 } | |
| 21 return false; | |
|
samli
2015/01/23 03:23:36
Just simplify to "return start.isShadowValue() &&
evemj (not active)
2015/01/28 00:41:14
Done.
| |
| 19 } | 22 } |
| 20 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::shadowToInte rpolableValue(const CSSValue& value) | 23 |
| 24 | |
| 25 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::toInterpolab leValue(const CSSValue& value, NonInterpolableType& nonInterpolableData) | |
| 21 { | 26 { |
| 22 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(6); | 27 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(5); |
| 23 const CSSShadowValue* shadowValue = toCSSShadowValue(&value); | 28 const CSSShadowValue* shadowValue = toCSSShadowValue(&value); |
| 24 ASSERT(shadowValue); | 29 ASSERT(shadowValue); |
| 25 | 30 |
| 26 result->set(0, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa lue->x)); | 31 if (shadowValue->x && LengthStyleInterpolation::canCreateFrom(*shadowValue-> x)) |
| 27 result->set(1, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa lue->y)); | 32 result->set(0, LengthStyleInterpolation::lengthToInterpolableValue(*shad owValue->x)); |
| 28 result->set(2, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa lue->blur)); | 33 else |
| 29 result->set(3, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa lue->spread)); | 34 result->set(0, InterpolableBool::create(false)); |
| 30 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(*shadowValu e->color)); | 35 if (shadowValue->y && LengthStyleInterpolation::canCreateFrom(*shadowValue-> y)) |
| 36 result->set(1, LengthStyleInterpolation::lengthToInterpolableValue(*shad owValue->y)); | |
| 37 else | |
| 38 result->set(1, InterpolableBool::create(false)); | |
| 39 if (shadowValue->blur && LengthStyleInterpolation::canCreateFrom(*shadowValu e->blur)) | |
| 40 result->set(2, LengthStyleInterpolation::lengthToInterpolableValue(*shad owValue->blur)); | |
| 41 else | |
| 42 result->set(2, InterpolableBool::create(false)); | |
| 43 if (shadowValue->spread && LengthStyleInterpolation::canCreateFrom(*shadowVa lue->spread)) | |
| 44 result->set(3, LengthStyleInterpolation::lengthToInterpolableValue(*shad owValue->spread)); | |
| 45 else | |
| 46 result->set(3, InterpolableBool::create(false)); | |
| 47 if (shadowValue->color && ColorStyleInterpolation::canCreateFrom(*shadowValu e->color)) | |
| 48 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(*shadow Value->color)); | |
| 49 else | |
| 50 result->set(4, InterpolableBool::create(false)); | |
|
samli
2015/01/23 03:23:36
This is messy and hard to read.
A possible soluti
evemj (not active)
2015/01/28 00:41:14
Done.
| |
| 51 if (shadowValue->style) | |
| 52 nonInterpolableData = (shadowValue->style->getValueID() == CSSValueInset ); | |
| 31 | 53 |
| 32 return result.release(); | 54 return result.release(); |
| 33 } | 55 } |
| 34 | 56 |
| 35 PassRefPtrWillBeRawPtr<CSSValue> ShadowStyleInterpolation::interpolableValueToSh adow(InterpolableValue* value, bool styleFlag) | 57 PassRefPtrWillBeRawPtr<CSSValue> ShadowStyleInterpolation::fromInterpolableValue (const InterpolableValue& value, NonInterpolableType nonInterpolableData, Interp olationRange range = RangeAll) |
| 36 { | 58 { |
| 37 InterpolableList* shadow = toInterpolableList(value); | 59 const InterpolableList* shadow = toInterpolableList(&value); |
| 38 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = LengthStyleInterpolation::interpol ableValueToLength(shadow->get(0), RangeNonNegative); | 60 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = (!shadow->get(0)->isBool()) ? Leng thStyleInterpolation::interpolableValueToLength(*shadow->get(0), |
| 39 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = LengthStyleInterpolation::interpol ableValueToLength(shadow->get(1), RangeNonNegative); | 61 RangeAll) : nullptr; |
| 40 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = LengthStyleInterpolation::inter polableValueToLength(shadow->get(2), RangeNonNegative); | 62 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = (!shadow->get(1)->isBool()) ? Leng thStyleInterpolation::interpolableValueToLength(*shadow->get(1), |
| 41 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = LengthStyleInterpolation::int erpolableValueToLength(shadow->get(3), RangeNonNegative); | 63 RangeAll) : nullptr; |
| 42 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = ColorStyleInterpolation::inter polableValueToColor(*(shadow->get(4))); | 64 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = (!shadow->get(2)->isBool()) ? L engthStyleInterpolation::interpolableValueToLength(*shadow->get(2), |
| 43 | 65 RangeNonNegative) : nullptr; |
| 44 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = styleFlag ? CSSPrimitiveValue: :createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier(CSSValueN one); | 66 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = (!shadow->get(3)->isBool()) ? LengthStyleInterpolation::interpolableValueToLength(*shadow->get(3), |
| 67 RangeAll) : nullptr; | |
|
samli
2015/01/23 03:23:36
I think the same would work for these 4 values
evemj (not active)
2015/01/28 00:41:14
Done.
| |
| 68 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = (!shadow->get(4)->isBool()) ? ColorStyleInterpolation::interpolableValueToColor(*shadow->get(4)) : nullptr; | |
| 69 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nonInterpolableData ? CSSPrimi tiveValue::createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier (CSSValueNone); | |
| 45 | 70 |
| 46 RefPtrWillBeRawPtr<CSSShadowValue> result = CSSShadowValue::create(x, y, blu r, spread, style, color); | 71 RefPtrWillBeRawPtr<CSSShadowValue> result = CSSShadowValue::create(x, y, blu r, spread, style, color); |
| 47 return result.release(); | 72 return result.release(); |
| 48 } | 73 } |
| 49 | 74 |
| 50 PassRefPtrWillBeRawPtr<ShadowStyleInterpolation> ShadowStyleInterpolation::maybe CreateFromShadow(const CSSValue& start, const CSSValue& end, CSSPropertyID id) | 75 bool ShadowStyleInterpolation::usesDefaultStyleInterpolation(const CSSValue& sta rt, const CSSValue& end) |
| 51 { | 76 { |
| 52 if (canCreateFrom(start) && canCreateFrom(end)) { | 77 if (start.isValueList() && end.isValueList()) { |
|
samli
2015/01/23 03:23:36
Do we need to check they are the same length as we
evemj (not active)
2015/01/28 00:41:14
Done.
| |
| 53 if (toCSSShadowValue(start).style == toCSSShadowValue(end).style) { | 78 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
| 54 bool styleFlag = (toCSSShadowValue(start).style->getValueID() == CSS ValueInset) ? true : false; | 79 if (canCreateFrom(*toCSSValueList(start).item(i), *toCSSValueList(en d).item(i))) |
|
samli
2015/01/23 03:23:36
Shouldn't this be a "!canCreateFrom()"?
evemj (not active)
2015/01/28 00:41:13
Done.
| |
| 55 return ShadowStyleInterpolation::create(start, end, id, styleFlag); | 80 return true; |
| 81 } | |
| 56 } | 82 } |
| 57 } | 83 return false; |
| 58 return nullptr; | |
| 59 } | 84 } |
| 60 | 85 |
| 61 | 86 } // namespace blink |
|
jadeg
2015/01/21 05:36:34
Newline!!!
| |
| 62 void ShadowStyleInterpolation::apply(StyleResolverState& state) const | |
| 63 { | |
| 64 StyleBuilder::applyProperty(m_id, state, interpolableValueToShadow(m_cachedV alue.get(), m_styleFlag).get()); | |
| 65 } | |
| 66 | |
| 67 void ShadowStyleInterpolation::trace(Visitor* visitor) | |
| 68 { | |
| 69 StyleInterpolation::trace(visitor); | |
| 70 } | |
| 71 | |
| 72 } | |
| OLD | NEW |