| 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/CSSTranslation.h" | 5 #include "core/css/cssom/CSSTranslation.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "core/css/CSSPrimitiveValue.h" | 8 #include "core/css/CSSPrimitiveValue.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 CSSTranslation* CSSTranslation::create(CSSLengthValue* x, CSSLengthValue* y, CSS
LengthValue* z, ExceptionState& exceptionState) | 12 CSSTranslation* CSSTranslation::create(CSSLengthValue* x, CSSLengthValue* y, CSS
LengthValue* z, ExceptionState& exceptionState) |
| 13 { | 13 { |
| 14 if (z->containsPercent()) { | 14 if (z->containsPercent()) { |
| 15 exceptionState.throwTypeError("CSSTranslation does not support z CSSLeng
thValue with percent units"); | 15 exceptionState.throwTypeError("CSSTranslation does not support z CSSLeng
thValue with percent units"); |
| 16 return nullptr; | 16 return nullptr; |
| 17 } | 17 } |
| 18 return new CSSTranslation(x, y, z); | 18 return new CSSTranslation(x, y, z); |
| 19 } | 19 } |
| 20 | 20 |
| 21 CSSTranslation* CSSTranslation::fromCSSValue(const CSSValue& value) |
| 22 { |
| 23 if (!value.isFunctionValue()) |
| 24 return nullptr; |
| 25 |
| 26 const CSSFunctionValue& cssFunctionValue = toCSSFunctionValue(value); |
| 27 if (cssFunctionValue.length() < 2) |
| 28 return nullptr; |
| 29 |
| 30 CSSLengthValue* x = CSSLengthValue::fromCSSValue(*cssFunctionValue.item(0)); |
| 31 CSSLengthValue* y = CSSLengthValue::fromCSSValue(*cssFunctionValue.item(1)); |
| 32 if (!x || !y) |
| 33 return nullptr; |
| 34 |
| 35 if (cssFunctionValue.functionType() == CSSValueTranslate) { |
| 36 if (cssFunctionValue.length() != 2) |
| 37 return nullptr; |
| 38 return CSSTranslation::create(x, y); |
| 39 } |
| 40 |
| 41 if (cssFunctionValue.functionType() == CSSValueTranslate3d) { |
| 42 if (cssFunctionValue.length() != 3) |
| 43 return nullptr; |
| 44 CSSLengthValue* z = CSSLengthValue::fromCSSValue(*cssFunctionValue.item(
2)); |
| 45 if (!z || z->containsPercent()) |
| 46 return nullptr; |
| 47 return new CSSTranslation(x, y, z); |
| 48 } |
| 49 return nullptr; |
| 50 } |
| 51 |
| 21 CSSFunctionValue* CSSTranslation::toCSSValue() const | 52 CSSFunctionValue* CSSTranslation::toCSSValue() const |
| 22 { | 53 { |
| 23 CSSFunctionValue* result = CSSFunctionValue::create(is2D() ? CSSValueTransla
te : CSSValueTranslate3d); | 54 CSSFunctionValue* result = CSSFunctionValue::create(is2D() ? CSSValueTransla
te : CSSValueTranslate3d); |
| 24 result->append(m_x->toCSSValue()); | 55 result->append(m_x->toCSSValue()); |
| 25 result->append(m_y->toCSSValue()); | 56 result->append(m_y->toCSSValue()); |
| 26 if (!is2D()) | 57 if (!is2D()) |
| 27 result->append(m_z->toCSSValue()); | 58 result->append(m_z->toCSSValue()); |
| 28 return result; | 59 return result; |
| 29 } | 60 } |
| 30 | 61 |
| 31 } // namespace blink | 62 } // namespace blink |
| OLD | NEW |