OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/css/cssom/CSSAngleValue.h" | |
6 | |
7 #include "bindings/core/v8/ExceptionState.h" | |
8 #include "core/css/CSSPrimitiveValue.h" | |
9 #include "platform/wtf/MathExtras.h" | |
10 | |
11 namespace blink { | |
12 | |
13 CSSAngleValue* CSSAngleValue::Create(double value, | |
14 CSSPrimitiveValue::UnitType unit) { | |
15 DCHECK(CSSPrimitiveValue::IsAngle(unit)); | |
16 return new CSSAngleValue(value, unit); | |
17 } | |
18 | |
19 CSSAngleValue* CSSAngleValue::Create(double value, const String& unit) { | |
20 CSSPrimitiveValue::UnitType primitive_unit = | |
21 CSSPrimitiveValue::StringToUnitType(unit); | |
22 return Create(value, primitive_unit); | |
23 } | |
24 | |
25 CSSAngleValue* CSSAngleValue::FromCSSValue(const CSSPrimitiveValue& value) { | |
26 DCHECK(value.IsAngle()); | |
27 if (value.IsCalculated()) | |
28 return nullptr; | |
29 return new CSSAngleValue(value.GetDoubleValue(), | |
30 value.TypeWithCalcResolved()); | |
31 } | |
32 | |
33 double CSSAngleValue::degrees() const { | |
34 switch (unit_) { | |
35 case CSSPrimitiveValue::UnitType::kDegrees: | |
36 return value_; | |
37 case CSSPrimitiveValue::UnitType::kRadians: | |
38 return rad2deg(value_); | |
39 case CSSPrimitiveValue::UnitType::kGradians: | |
40 return grad2deg(value_); | |
41 case CSSPrimitiveValue::UnitType::kTurns: | |
42 return turn2deg(value_); | |
43 default: | |
44 NOTREACHED(); | |
45 return 0; | |
46 } | |
47 } | |
48 | |
49 double CSSAngleValue::radians() const { | |
50 return deg2rad(degrees()); | |
51 } | |
52 | |
53 double CSSAngleValue::gradians() const { | |
54 return deg2grad(degrees()); | |
55 } | |
56 | |
57 double CSSAngleValue::turns() const { | |
58 return deg2turn(degrees()); | |
59 } | |
60 | |
61 CSSValue* CSSAngleValue::ToCSSValue() const { | |
62 return CSSPrimitiveValue::Create(value_, unit_); | |
63 } | |
64 | |
65 } // namespace blink | |
OLD | NEW |