| 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/CSSFunctionValue.h" |
| 8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 bool IsNumberValue(const CSSValue& value) { | 14 bool IsNumberValue(const CSSValue& value) { |
| 15 return value.IsPrimitiveValue() && ToCSSPrimitiveValue(value).IsNumber(); | 15 return value.IsPrimitiveValue() && ToCSSPrimitiveValue(value).IsNumber(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 CSSRotation* FromCSSRotate(const CSSFunctionValue& value) { | 18 CSSRotation* FromCSSRotate(const CSSFunctionValue& value) { |
| 19 DCHECK_EQ(value.length(), 1UL); | 19 DCHECK_EQ(value.length(), 1UL); |
| 20 const CSSPrimitiveValue& primitive_value = ToCSSPrimitiveValue(value.Item(0)); | 20 const CSSPrimitiveValue& primitive_value = ToCSSPrimitiveValue(value.Item(0)); |
| 21 if (primitive_value.IsCalculated() || !primitive_value.IsAngle()) | 21 if (primitive_value.IsCalculated() || !primitive_value.IsAngle()) |
| 22 return nullptr; | 22 return nullptr; |
| 23 return CSSRotation::Create(CSSAngleValue::FromCSSValue(primitive_value)); | 23 return CSSRotation::Create(CSSNumericValue::FromCSSValue(primitive_value)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 CSSRotation* FromCSSRotate3d(const CSSFunctionValue& value) { | 26 CSSRotation* FromCSSRotate3d(const CSSFunctionValue& value) { |
| 27 DCHECK_EQ(value.length(), 4UL); | 27 DCHECK_EQ(value.length(), 4UL); |
| 28 DCHECK(IsNumberValue(value.Item(0))); | 28 DCHECK(IsNumberValue(value.Item(0))); |
| 29 DCHECK(IsNumberValue(value.Item(1))); | 29 DCHECK(IsNumberValue(value.Item(1))); |
| 30 DCHECK(IsNumberValue(value.Item(2))); | 30 DCHECK(IsNumberValue(value.Item(2))); |
| 31 const CSSPrimitiveValue& angle = ToCSSPrimitiveValue(value.Item(3)); | 31 const CSSPrimitiveValue& angle = ToCSSPrimitiveValue(value.Item(3)); |
| 32 if (angle.IsCalculated() || !angle.IsAngle()) | 32 if (angle.IsCalculated() || !angle.IsAngle()) |
| 33 return nullptr; | 33 return nullptr; |
| 34 | 34 |
| 35 double x = ToCSSPrimitiveValue(value.Item(0)).GetDoubleValue(); | 35 double x = ToCSSPrimitiveValue(value.Item(0)).GetDoubleValue(); |
| 36 double y = ToCSSPrimitiveValue(value.Item(1)).GetDoubleValue(); | 36 double y = ToCSSPrimitiveValue(value.Item(1)).GetDoubleValue(); |
| 37 double z = ToCSSPrimitiveValue(value.Item(2)).GetDoubleValue(); | 37 double z = ToCSSPrimitiveValue(value.Item(2)).GetDoubleValue(); |
| 38 | 38 |
| 39 return CSSRotation::Create(x, y, z, CSSAngleValue::FromCSSValue(angle)); | 39 return CSSRotation::Create(x, y, z, CSSNumericValue::FromCSSValue(angle)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 CSSRotation* FromCSSRotateXYZ(const CSSFunctionValue& value) { | 42 CSSRotation* FromCSSRotateXYZ(const CSSFunctionValue& value) { |
| 43 DCHECK_EQ(value.length(), 1UL); | 43 DCHECK_EQ(value.length(), 1UL); |
| 44 const CSSPrimitiveValue& primitive_value = ToCSSPrimitiveValue(value.Item(0)); | 44 const CSSPrimitiveValue& primitive_value = ToCSSPrimitiveValue(value.Item(0)); |
| 45 if (primitive_value.IsCalculated()) | 45 if (primitive_value.IsCalculated()) |
| 46 return nullptr; | 46 return nullptr; |
| 47 CSSAngleValue* angle = CSSAngleValue::FromCSSValue(primitive_value); | 47 CSSNumericValue* angle = CSSNumericValue::FromCSSValue(primitive_value); |
| 48 switch (value.FunctionType()) { | 48 switch (value.FunctionType()) { |
| 49 case CSSValueRotateX: | 49 case CSSValueRotateX: |
| 50 return CSSRotation::Create(1, 0, 0, angle); | 50 return CSSRotation::Create(1, 0, 0, angle); |
| 51 case CSSValueRotateY: | 51 case CSSValueRotateY: |
| 52 return CSSRotation::Create(0, 1, 0, angle); | 52 return CSSRotation::Create(0, 1, 0, angle); |
| 53 case CSSValueRotateZ: | 53 case CSSValueRotateZ: |
| 54 return CSSRotation::Create(0, 0, 1, angle); | 54 return CSSRotation::Create(0, 0, 1, angle); |
| 55 default: | 55 default: |
| 56 NOTREACHED(); | 56 NOTREACHED(); |
| 57 return nullptr; | 57 return nullptr; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 70 case CSSValueRotateY: | 70 case CSSValueRotateY: |
| 71 case CSSValueRotateZ: | 71 case CSSValueRotateZ: |
| 72 return FromCSSRotateXYZ(value); | 72 return FromCSSRotateXYZ(value); |
| 73 default: | 73 default: |
| 74 NOTREACHED(); | 74 NOTREACHED(); |
| 75 return nullptr; | 75 return nullptr; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 CSSFunctionValue* CSSRotation::ToCSSValue() const { | 79 CSSFunctionValue* CSSRotation::ToCSSValue() const { |
| 80 CSSFunctionValue* result = | 80 return nullptr; |
| 81 CSSFunctionValue::Create(is2d_ ? CSSValueRotate : CSSValueRotate3d); | 81 // TODO(meade): Re-implement this when we finish rewriting number/length |
| 82 if (!is2d_) { | 82 // types. |
| 83 result->Append( | 83 // CSSFunctionValue* result = |
| 84 *CSSPrimitiveValue::Create(x_, CSSPrimitiveValue::UnitType::kNumber)); | 84 // CSSFunctionValue::Create(is2d_ ? CSSValueRotate : CSSValueRotate3d); |
| 85 result->Append( | 85 // if (!is2d_) { |
| 86 *CSSPrimitiveValue::Create(y_, CSSPrimitiveValue::UnitType::kNumber)); | 86 // result->Append( |
| 87 result->Append( | 87 // *CSSPrimitiveValue::Create(x_, CSSPrimitiveValue::UnitType::kNumber)); |
| 88 *CSSPrimitiveValue::Create(z_, CSSPrimitiveValue::UnitType::kNumber)); | 88 // result->Append( |
| 89 } | 89 // *CSSPrimitiveValue::Create(y_, CSSPrimitiveValue::UnitType::kNumber)); |
| 90 result->Append(*CSSPrimitiveValue::Create(angle_->Value(), angle_->Unit())); | 90 // result->Append( |
| 91 return result; | 91 // *CSSPrimitiveValue::Create(z_, CSSPrimitiveValue::UnitType::kNumber)); |
| 92 // } |
| 93 // result->Append(*CSSPrimitiveValue::Create(angle_->Value(), |
| 94 // angle_->Unit())); |
| 95 // return result; |
| 92 } | 96 } |
| 93 | 97 |
| 94 } // namespace blink | 98 } // namespace blink |
| OLD | NEW |