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/CSSSkew.h" | 5 #include "core/css/cssom/CSSSkew.h" |
6 | 6 |
7 #include "core/css/CSSFunctionValue.h" | 7 #include "core/css/CSSFunctionValue.h" |
8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 #include "core/css/cssom/CSSAngleValue.h" |
9 | 10 |
10 namespace blink { | 11 namespace blink { |
11 | 12 |
| 13 CSSSkew* CSSSkew::fromCSSValue(const CSSFunctionValue& value) { |
| 14 const CSSPrimitiveValue& xValue = toCSSPrimitiveValue(value.item(0)); |
| 15 if (xValue.isCalculated()) { |
| 16 // TODO(meade): Decide what we want to do with calc angles. |
| 17 return nullptr; |
| 18 } |
| 19 DCHECK(xValue.isAngle()); |
| 20 switch (value.functionType()) { |
| 21 case CSSValueSkew: |
| 22 if (value.length() == 2U) { |
| 23 const CSSPrimitiveValue& yValue = toCSSPrimitiveValue(value.item(1)); |
| 24 if (yValue.isCalculated()) { |
| 25 // TODO(meade): Decide what we want to do with calc angles. |
| 26 return nullptr; |
| 27 } |
| 28 DCHECK(yValue.isAngle()); |
| 29 return CSSSkew::create(CSSAngleValue::fromCSSValue(xValue), |
| 30 CSSAngleValue::fromCSSValue(yValue)); |
| 31 } |
| 32 // Else fall through; skew(ax) == skewX(ax). |
| 33 case CSSValueSkewX: |
| 34 DCHECK_EQ(value.length(), 1U); |
| 35 return CSSSkew::create( |
| 36 CSSAngleValue::fromCSSValue(xValue), |
| 37 CSSAngleValue::create(0, CSSPrimitiveValue::UnitType::Degrees)); |
| 38 case CSSValueSkewY: |
| 39 DCHECK_EQ(value.length(), 1U); |
| 40 return CSSSkew::create( |
| 41 CSSAngleValue::create(0, CSSPrimitiveValue::UnitType::Degrees), |
| 42 CSSAngleValue::fromCSSValue(xValue)); |
| 43 default: |
| 44 NOTREACHED(); |
| 45 return nullptr; |
| 46 } |
| 47 } |
| 48 |
12 CSSFunctionValue* CSSSkew::toCSSValue() const { | 49 CSSFunctionValue* CSSSkew::toCSSValue() const { |
13 CSSFunctionValue* result = CSSFunctionValue::create(CSSValueSkew); | 50 CSSFunctionValue* result = CSSFunctionValue::create(CSSValueSkew); |
14 result->append(*CSSPrimitiveValue::create(m_ax->value(), m_ax->unit())); | 51 result->append(*CSSPrimitiveValue::create(m_ax->value(), m_ax->unit())); |
15 result->append(*CSSPrimitiveValue::create(m_ay->value(), m_ay->unit())); | 52 result->append(*CSSPrimitiveValue::create(m_ay->value(), m_ay->unit())); |
16 return result; | 53 return result; |
17 } | 54 } |
18 | 55 |
19 } // namespace blink | 56 } // namespace blink |
OLD | NEW |