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

Side by Side Diff: Source/core/animation/SVGLengthStyleInterpolation.cpp

Issue 956553004: Use Length for baselineShiftValue in SVGLayoutStyle (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: A few more TEs. Created 5 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/SVGLengthStyleInterpolation.h" 6 #include "core/animation/SVGLengthStyleInterpolation.h"
7 7
8 #include "core/css/resolver/StyleBuilder.h" 8 #include "core/css/resolver/StyleBuilder.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 namespace {
13
14 bool isBaseline(const CSSValue& value)
15 {
16 if (!value.isPrimitiveValue())
17 return false;
18 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
19 return primitiveValue.isValueID() && primitiveValue.getValueID() == CSSValue Baseline;
20 }
21
22 } // namespace
23
24 bool SVGLengthStyleInterpolation::canCreateFrom(const CSSValue& value) 12 bool SVGLengthStyleInterpolation::canCreateFrom(const CSSValue& value)
25 { 13 {
26 if (!value.isPrimitiveValue()) 14 if (!value.isPrimitiveValue())
27 return false; 15 return false;
28 16
29 switch (toCSSPrimitiveValue(value).primitiveType()) { 17 switch (toCSSPrimitiveValue(value).primitiveType()) {
30 case CSSPrimitiveValue::CSS_NUMBER: 18 case CSSPrimitiveValue::CSS_NUMBER:
31 case CSSPrimitiveValue::CSS_PERCENTAGE: 19 case CSSPrimitiveValue::CSS_PERCENTAGE:
32 case CSSPrimitiveValue::CSS_EMS: 20 case CSSPrimitiveValue::CSS_EMS:
33 case CSSPrimitiveValue::CSS_EXS: 21 case CSSPrimitiveValue::CSS_EXS:
34 case CSSPrimitiveValue::CSS_PX: 22 case CSSPrimitiveValue::CSS_PX:
35 case CSSPrimitiveValue::CSS_CM: 23 case CSSPrimitiveValue::CSS_CM:
36 case CSSPrimitiveValue::CSS_MM: 24 case CSSPrimitiveValue::CSS_MM:
37 case CSSPrimitiveValue::CSS_IN: 25 case CSSPrimitiveValue::CSS_IN:
38 case CSSPrimitiveValue::CSS_PT: 26 case CSSPrimitiveValue::CSS_PT:
39 case CSSPrimitiveValue::CSS_PC: 27 case CSSPrimitiveValue::CSS_PC:
40 return true; 28 return true;
41 29
42 default: 30 default:
43 return isBaseline(value); 31 return false;
44 } 32 }
45 } 33 }
46 34
47 PassOwnPtrWillBeRawPtr<InterpolableValue> SVGLengthStyleInterpolation::lengthToI nterpolableValue(const CSSPrimitiveValue& length) 35 PassOwnPtrWillBeRawPtr<InterpolableValue> SVGLengthStyleInterpolation::lengthToI nterpolableValue(const CSSPrimitiveValue& length)
48 { 36 {
49 ASSERT(canCreateFrom(length)); 37 ASSERT(canCreateFrom(length));
50 return InterpolableNumber::create(length.getDoubleValue()); 38 return InterpolableNumber::create(length.getDoubleValue());
51 } 39 }
52 40
53 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> SVGLengthStyleInterpolation::interpola bleValueToLength(const InterpolableValue& interpolableValue, CSSPrimitiveValue:: UnitType type, InterpolationRange range) 41 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> SVGLengthStyleInterpolation::interpola bleValueToLength(const InterpolableValue& interpolableValue, CSSPrimitiveValue:: UnitType type, InterpolationRange range)
54 { 42 {
55 double value = toInterpolableNumber(interpolableValue).value(); 43 double value = toInterpolableNumber(interpolableValue).value();
56 if (range == RangeNonNegative && value < 0) 44 if (range == RangeNonNegative && value < 0)
57 value = 0; 45 value = 0;
58 46
59 return CSSPrimitiveValue::create(value, type); 47 return CSSPrimitiveValue::create(value, type);
60 } 48 }
61 49
62 PassRefPtrWillBeRawPtr<SVGLengthStyleInterpolation> SVGLengthStyleInterpolation: :maybeCreate(const CSSValue& start, const CSSValue& end, CSSPropertyID id, Inter polationRange range) 50 PassRefPtrWillBeRawPtr<SVGLengthStyleInterpolation> SVGLengthStyleInterpolation: :maybeCreate(const CSSValue& start, const CSSValue& end, CSSPropertyID id, Inter polationRange range)
63 { 51 {
64 if (!canCreateFrom(start) || !canCreateFrom(end)) 52 if (!canCreateFrom(start) || !canCreateFrom(end))
65 return nullptr; 53 return nullptr;
66 54
67 RefPtrWillBeRawPtr<CSSPrimitiveValue> zero = CSSPrimitiveValue::create(0, CS SPrimitiveValue::CSS_PX); 55 const CSSPrimitiveValue& primitiveStart = toCSSPrimitiveValue(start);
68 const CSSPrimitiveValue& primitiveStart = 56 const CSSPrimitiveValue& primitiveEnd = toCSSPrimitiveValue(end);
69 isBaseline(start) ? *zero : toCSSPrimitiveValue(start);
70 const CSSPrimitiveValue& primitiveEnd =
71 isBaseline(end) ? *zero : toCSSPrimitiveValue(end);
72 57
73 CSSPrimitiveValue::UnitType type = primitiveStart.primitiveType(); 58 CSSPrimitiveValue::UnitType type = primitiveStart.primitiveType();
74 if (primitiveStart.getDoubleValue() == 0) 59 if (primitiveStart.getDoubleValue() == 0)
75 type = primitiveEnd.primitiveType(); 60 type = primitiveEnd.primitiveType();
76 else if (primitiveEnd.getDoubleValue() != 0 && primitiveEnd.primitiveType() != type) 61 else if (primitiveEnd.getDoubleValue() != 0 && primitiveEnd.primitiveType() != type)
77 return nullptr; 62 return nullptr;
78 63
79 return adoptRefWillBeNoop(new SVGLengthStyleInterpolation(primitiveStart, pr imitiveEnd, id, type, range)); 64 return adoptRefWillBeNoop(new SVGLengthStyleInterpolation(primitiveStart, pr imitiveEnd, id, type, range));
80 } 65 }
81 66
82 SVGLengthStyleInterpolation::SVGLengthStyleInterpolation(const CSSPrimitiveValue & start, const CSSPrimitiveValue& end, CSSPropertyID id, CSSPrimitiveValue::Unit Type type, InterpolationRange range) 67 SVGLengthStyleInterpolation::SVGLengthStyleInterpolation(const CSSPrimitiveValue & start, const CSSPrimitiveValue& end, CSSPropertyID id, CSSPrimitiveValue::Unit Type type, InterpolationRange range)
83 : StyleInterpolation(lengthToInterpolableValue(start), lengthToInterpolableV alue(end), id) 68 : StyleInterpolation(lengthToInterpolableValue(start), lengthToInterpolableV alue(end), id)
84 , m_type(type) 69 , m_type(type)
85 , m_range(range) 70 , m_range(range)
86 { 71 {
87 } 72 }
88 73
89 void SVGLengthStyleInterpolation::apply(StyleResolverState& state) const 74 void SVGLengthStyleInterpolation::apply(StyleResolverState& state) const
90 { 75 {
91 StyleBuilder::applyProperty(m_id, state, interpolableValueToLength(*m_cached Value, m_type, m_range).get()); 76 StyleBuilder::applyProperty(m_id, state, interpolableValueToLength(*m_cached Value, m_type, m_range).get());
92 } 77 }
93 78
94 } 79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698