OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/css/cssom/CSSRotation.h" | 5 #include "core/css/cssom/CSSRotation.h" |
6 | 6 |
7 #include "core/css/CSSFunctionValue.h" | |
7 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
8 | 9 |
9 namespace blink { | 10 namespace blink { |
10 | 11 |
12 namespace { | |
13 | |
14 bool isNumberValue(const CSSValue& value) | |
15 { | |
16 if (!value.isPrimitiveValue()) | |
Timothy Loh
2016/06/27 05:10:04
fwiw I think it'd clearer if this is just
return
meade_UTC10
2016/06/27 17:19:41
Done.
| |
17 return false; | |
18 return toCSSPrimitiveValue(value).isNumber(); | |
19 } | |
20 | |
21 CSSRotation* fromCSSRotate(const CSSFunctionValue& value) | |
22 { | |
23 DCHECK_EQ(value.length(), 1UL); | |
24 return CSSRotation::create(toCSSPrimitiveValue(value.item(0)).computeDegrees ()); | |
25 } | |
26 | |
27 CSSRotation* fromCSSRotate3d(const CSSFunctionValue& value) | |
28 { | |
29 DCHECK_EQ(value.length(), 4UL); | |
30 if (!isNumberValue(value.item(0)) | |
Timothy Loh
2016/06/27 05:10:04
DCHECKs for these too. I think none of these conve
meade_UTC10
2016/06/27 17:19:41
Done.
| |
31 || !isNumberValue(value.item(1)) | |
32 || !isNumberValue(value.item(2))) { | |
33 // computeDegrees asserts that value.item(3) is an angle. | |
34 return nullptr; | |
35 } | |
36 double x = toCSSPrimitiveValue(value.item(0)).getDoubleValue(); | |
37 double y = toCSSPrimitiveValue(value.item(1)).getDoubleValue(); | |
38 double z = toCSSPrimitiveValue(value.item(2)).getDoubleValue(); | |
39 double angle = toCSSPrimitiveValue(value.item(3)).computeDegrees(); | |
40 return CSSRotation::create(x, y, z, angle); | |
41 } | |
42 | |
43 CSSRotation* fromCSSRotateXYZ(const CSSFunctionValue& value) | |
44 { | |
45 DCHECK_EQ(value.length(), 1UL); | |
46 double angle = toCSSPrimitiveValue(value.item(0)).computeDegrees(); | |
47 | |
48 switch (value.functionType()) { | |
49 case CSSValueRotateX: | |
50 return CSSRotation::create(1, 0, 0, angle); | |
51 case CSSValueRotateY: | |
52 return CSSRotation::create(0, 1, 0, angle); | |
53 case CSSValueRotateZ: | |
54 return CSSRotation::create(0, 0, 1, angle); | |
55 default: | |
Timothy Loh
2016/06/27 05:10:04
NOT_REACHED()
meade_UTC10
2016/06/27 17:19:41
Done.
| |
56 return nullptr; | |
57 } | |
58 } | |
59 | |
60 } // namespace | |
61 | |
62 CSSRotation* CSSRotation::fromCSSValue(const CSSFunctionValue& value) | |
63 { | |
64 switch (value.functionType()) { | |
65 case CSSValueRotate: | |
66 return fromCSSRotate(value); | |
67 case CSSValueRotate3d: | |
68 return fromCSSRotate3d(value); | |
69 case CSSValueRotateX: | |
70 case CSSValueRotateY: | |
71 case CSSValueRotateZ: | |
72 return fromCSSRotateXYZ(value); | |
73 default: | |
74 return nullptr; | |
Timothy Loh
2016/06/27 05:10:04
NOT_REACHED()
meade_UTC10
2016/06/27 17:19:41
Done.
| |
75 } | |
76 } | |
77 | |
11 CSSFunctionValue* CSSRotation::toCSSValue() const | 78 CSSFunctionValue* CSSRotation::toCSSValue() const |
12 { | 79 { |
13 CSSFunctionValue* result = CSSFunctionValue::create(m_is2D ? CSSValueRotate : CSSValueRotate3d); | 80 CSSFunctionValue* result = CSSFunctionValue::create(m_is2D ? CSSValueRotate : CSSValueRotate3d); |
14 if (!m_is2D) { | 81 if (!m_is2D) { |
15 result->append(*CSSPrimitiveValue::create(m_x, CSSPrimitiveValue::UnitTy pe::Number)); | 82 result->append(*CSSPrimitiveValue::create(m_x, CSSPrimitiveValue::UnitTy pe::Number)); |
16 result->append(*CSSPrimitiveValue::create(m_y, CSSPrimitiveValue::UnitTy pe::Number)); | 83 result->append(*CSSPrimitiveValue::create(m_y, CSSPrimitiveValue::UnitTy pe::Number)); |
17 result->append(*CSSPrimitiveValue::create(m_z, CSSPrimitiveValue::UnitTy pe::Number)); | 84 result->append(*CSSPrimitiveValue::create(m_z, CSSPrimitiveValue::UnitTy pe::Number)); |
18 } | 85 } |
19 result->append(*CSSPrimitiveValue::create(m_angle, CSSPrimitiveValue::UnitTy pe::Degrees)); | 86 result->append(*CSSPrimitiveValue::create(m_angle, CSSPrimitiveValue::UnitTy pe::Degrees)); |
20 return result; | 87 return result; |
21 } | 88 } |
22 | 89 |
23 } // namespace blink | 90 } // namespace blink |
OLD | NEW |