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

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: Sync to HEAD Created 4 years, 6 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 isAngleValue(const CSSValue& value)
15 {
16 if (!value.isPrimitiveValue())
17 return false;
18 return toCSSPrimitiveValue(value).isAngle();
19 }
20
21 bool isNumberValue(const CSSValue& value)
22 {
23 if (!value.isPrimitiveValue())
24 return false;
25 return toCSSPrimitiveValue(value).isNumber();
26 }
27
28 } // namespace
29
30 CSSRotation* CSSRotation::fromCSSValue(const CSSFunctionValue& value)
31 {
32 if (value.functionType() == CSSValueRotate) {
Timothy Loh 2016/06/15 08:36:26 This also needs to support rotatex/y/z, and test f
meade_UTC10 2016/06/23 21:51:44 Done.
33 if (value.length() != 1)
Timothy Loh 2016/06/15 08:36:26 All of these checks should just be assertions beca
meade_UTC10 2016/06/23 21:51:44 Done.
34 return nullptr;
35 if (!isAngleValue(value.item(0)))
36 return nullptr;
37 return CSSRotation::create(toCSSPrimitiveValue(value.item(0)).computeDeg rees());
38 }
39
40 if (value.functionType() == CSSValueRotate3d) {
41 if (value.length() != 4)
42 return nullptr;
43 if (!isNumberValue(value.item(0))
44 || !isNumberValue(value.item(1))
45 || !isNumberValue(value.item(2))
46 || !isAngleValue(value.item(3)))
47 return nullptr;
48 double x = toCSSPrimitiveValue(value.item(0)).getDoubleValue();
49 double y = toCSSPrimitiveValue(value.item(1)).getDoubleValue();
50 double z = toCSSPrimitiveValue(value.item(2)).getDoubleValue();
51 double angle = toCSSPrimitiveValue(value.item(3)).computeDegrees();
52 return CSSRotation::create(x, y, z, angle);
53 }
54
55 return nullptr;
56 }
57
11 CSSFunctionValue* CSSRotation::toCSSValue() const 58 CSSFunctionValue* CSSRotation::toCSSValue() const
12 { 59 {
13 CSSFunctionValue* result = CSSFunctionValue::create(m_is2D ? CSSValueRotate : CSSValueRotate3d); 60 CSSFunctionValue* result = CSSFunctionValue::create(m_is2D ? CSSValueRotate : CSSValueRotate3d);
14 if (!m_is2D) { 61 if (!m_is2D) {
15 result->append(*CSSPrimitiveValue::create(m_x, CSSPrimitiveValue::UnitTy pe::Number)); 62 result->append(*CSSPrimitiveValue::create(m_x, CSSPrimitiveValue::UnitTy pe::Number));
16 result->append(*CSSPrimitiveValue::create(m_y, CSSPrimitiveValue::UnitTy pe::Number)); 63 result->append(*CSSPrimitiveValue::create(m_y, CSSPrimitiveValue::UnitTy pe::Number));
17 result->append(*CSSPrimitiveValue::create(m_z, CSSPrimitiveValue::UnitTy pe::Number)); 64 result->append(*CSSPrimitiveValue::create(m_z, CSSPrimitiveValue::UnitTy pe::Number));
18 } 65 }
19 result->append(*CSSPrimitiveValue::create(m_angle, CSSPrimitiveValue::UnitTy pe::Degrees)); 66 result->append(*CSSPrimitiveValue::create(m_angle, CSSPrimitiveValue::UnitTy pe::Degrees));
20 return result; 67 return result;
21 } 68 }
22 69
23 } // namespace blink 70 } // 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