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

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

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

Powered by Google App Engine
This is Rietveld 408576698