| 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/CSSPerspective.h" | 5 #include "core/css/cssom/CSSPerspective.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 CSSPerspective* CSSPerspective::Create(CSSNumericValue* length, | 11 CSSPerspective* CSSPerspective::Create(CSSNumericValue* length, |
| 12 ExceptionState& exception_state) { | 12 ExceptionState& exception_state) { |
| 13 if (length->GetType() != CSSStyleValue::StyleValueType::kLengthType) { | 13 if (length->GetType() != CSSStyleValue::StyleValueType::kLengthType) { |
| 14 exception_state.ThrowTypeError("Must pass length to CSSNumericValue"); | 14 exception_state.ThrowTypeError("Must pass length to CSSPerspective"); |
| 15 return nullptr; | 15 return nullptr; |
| 16 } | 16 } |
| 17 if (length->ContainsPercent()) { | 17 if (length->ContainsPercent()) { |
| 18 exception_state.ThrowTypeError( | 18 exception_state.ThrowTypeError( |
| 19 "CSSPerspective does not support CSSNumericValues with percent units"); | 19 "CSSPerspective does not support CSSNumericValues with percent units"); |
| 20 return nullptr; | 20 return nullptr; |
| 21 } | 21 } |
| 22 return new CSSPerspective(length); | 22 return new CSSPerspective(length); |
| 23 } | 23 } |
| 24 | 24 |
| 25 void CSSPerspective::setLength(CSSNumericValue* length, |
| 26 ExceptionState& exception_state) { |
| 27 if (length->GetType() != CSSStyleValue::StyleValueType::kLengthType) { |
| 28 exception_state.ThrowTypeError("Must pass length to CSSPerspective"); |
| 29 return; |
| 30 } |
| 31 if (length->ContainsPercent()) { |
| 32 exception_state.ThrowTypeError( |
| 33 "CSSPerspective does not support CSSNumericValues with percent units"); |
| 34 return; |
| 35 } |
| 36 length_ = length; |
| 37 } |
| 38 |
| 25 CSSPerspective* CSSPerspective::FromCSSValue(const CSSFunctionValue& value) { | 39 CSSPerspective* CSSPerspective::FromCSSValue(const CSSFunctionValue& value) { |
| 26 DCHECK_EQ(value.FunctionType(), CSSValuePerspective); | 40 DCHECK_EQ(value.FunctionType(), CSSValuePerspective); |
| 27 DCHECK_EQ(value.length(), 1U); | 41 DCHECK_EQ(value.length(), 1U); |
| 28 CSSNumericValue* length = | 42 CSSNumericValue* length = |
| 29 CSSNumericValue::FromCSSValue(ToCSSPrimitiveValue(value.Item(0))); | 43 CSSNumericValue::FromCSSValue(ToCSSPrimitiveValue(value.Item(0))); |
| 30 // TODO(meade): This shouldn't happen once CSSNumericValue is fully | 44 // TODO(meade): This shouldn't happen once CSSNumericValue is fully |
| 31 // implemented, so once that happens this check can be removed. | 45 // implemented, so once that happens this check can be removed. |
| 32 if (!length) | 46 if (!length) |
| 33 return nullptr; | 47 return nullptr; |
| 34 DCHECK(!length->ContainsPercent()); | 48 DCHECK(!length->ContainsPercent()); |
| 35 return new CSSPerspective(length); | 49 return new CSSPerspective(length); |
| 36 } | 50 } |
| 37 | 51 |
| 38 CSSFunctionValue* CSSPerspective::ToCSSValue() const { | 52 CSSFunctionValue* CSSPerspective::ToCSSValue() const { |
| 39 CSSFunctionValue* result = CSSFunctionValue::Create(CSSValuePerspective); | 53 CSSFunctionValue* result = CSSFunctionValue::Create(CSSValuePerspective); |
| 40 result->Append(*length_->ToCSSValue()); | 54 result->Append(*length_->ToCSSValue()); |
| 41 return result; | 55 return result; |
| 42 } | 56 } |
| 43 | 57 |
| 44 } // namespace blink | 58 } // namespace blink |
| OLD | NEW |