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

Side by Side Diff: third_party/WebKit/Source/core/css/cssom/CSSRotation.cpp

Issue 2039093003: [Typed OM] Implement CSSValue->CSSRotation conversion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/Source/core/css/cssom/CSSRotation.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 return value.isPrimitiveValue() && toCSSPrimitiveValue(value).isNumber();
17 }
18
19 CSSRotation* fromCSSRotate(const CSSFunctionValue& value)
20 {
21 DCHECK_EQ(value.length(), 1UL);
22 return CSSRotation::create(toCSSPrimitiveValue(value.item(0)).computeDegrees ());
23 }
24
25 CSSRotation* fromCSSRotate3d(const CSSFunctionValue& value)
26 {
27 DCHECK_EQ(value.length(), 4UL);
28 DCHECK(isNumberValue(value.item(0)));
29 DCHECK(isNumberValue(value.item(1)));
30 DCHECK(isNumberValue(value.item(2)));
31 // computeDegrees asserts that value.item(3) is an angle.
32
33 double x = toCSSPrimitiveValue(value.item(0)).getDoubleValue();
34 double y = toCSSPrimitiveValue(value.item(1)).getDoubleValue();
35 double z = toCSSPrimitiveValue(value.item(2)).getDoubleValue();
36 double angle = toCSSPrimitiveValue(value.item(3)).computeDegrees();
37 return CSSRotation::create(x, y, z, angle);
38 }
39
40 CSSRotation* fromCSSRotateXYZ(const CSSFunctionValue& value)
41 {
42 DCHECK_EQ(value.length(), 1UL);
43 double angle = toCSSPrimitiveValue(value.item(0)).computeDegrees();
44
45 switch (value.functionType()) {
46 case CSSValueRotateX:
47 return CSSRotation::create(1, 0, 0, angle);
48 case CSSValueRotateY:
49 return CSSRotation::create(0, 1, 0, angle);
50 case CSSValueRotateZ:
51 return CSSRotation::create(0, 0, 1, angle);
52 default:
53 NOTREACHED();
54 return nullptr;
55 }
56 }
57
58 } // namespace
59
60 CSSRotation* CSSRotation::fromCSSValue(const CSSFunctionValue& value)
61 {
62 switch (value.functionType()) {
63 case CSSValueRotate:
64 return fromCSSRotate(value);
65 case CSSValueRotate3d:
66 return fromCSSRotate3d(value);
67 case CSSValueRotateX:
68 case CSSValueRotateY:
69 case CSSValueRotateZ:
70 return fromCSSRotateXYZ(value);
71 default:
72 NOTREACHED();
73 return nullptr;
74 }
75 }
76
11 CSSFunctionValue* CSSRotation::toCSSValue() const 77 CSSFunctionValue* CSSRotation::toCSSValue() const
12 { 78 {
13 CSSFunctionValue* result = CSSFunctionValue::create(m_is2D ? CSSValueRotate : CSSValueRotate3d); 79 CSSFunctionValue* result = CSSFunctionValue::create(m_is2D ? CSSValueRotate : CSSValueRotate3d);
14 if (!m_is2D) { 80 if (!m_is2D) {
15 result->append(*CSSPrimitiveValue::create(m_x, CSSPrimitiveValue::UnitTy pe::Number)); 81 result->append(*CSSPrimitiveValue::create(m_x, CSSPrimitiveValue::UnitTy pe::Number));
16 result->append(*CSSPrimitiveValue::create(m_y, CSSPrimitiveValue::UnitTy pe::Number)); 82 result->append(*CSSPrimitiveValue::create(m_y, CSSPrimitiveValue::UnitTy pe::Number));
17 result->append(*CSSPrimitiveValue::create(m_z, CSSPrimitiveValue::UnitTy pe::Number)); 83 result->append(*CSSPrimitiveValue::create(m_z, CSSPrimitiveValue::UnitTy pe::Number));
18 } 84 }
19 result->append(*CSSPrimitiveValue::create(m_angle, CSSPrimitiveValue::UnitTy pe::Degrees)); 85 result->append(*CSSPrimitiveValue::create(m_angle, CSSPrimitiveValue::UnitTy pe::Degrees));
20 return result; 86 return result;
21 } 87 }
22 88
23 } // namespace blink 89 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/cssom/CSSRotation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698