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 #include "core/css/cssom/CSSNumericValue.h" | 9 #include "core/css/cssom/CSSNumericValue.h" |
10 #include "core/css/cssom/CSSStyleValue.h" | 10 #include "core/css/cssom/CSSStyleValue.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
14 CSSTranslation* CSSTranslation::Create(CSSNumericValue* x, | 14 CSSTranslation* CSSTranslation::Create(CSSNumericValue* x, |
15 CSSNumericValue* y, | 15 CSSNumericValue* y, |
| 16 ExceptionState& exception_state) { |
| 17 if ((x->GetType() != CSSStyleValue::StyleValueType::kLengthType && |
| 18 x->GetType() != CSSStyleValue::StyleValueType::kPercentType) || |
| 19 (y->GetType() != CSSStyleValue::StyleValueType::kLengthType && |
| 20 y->GetType() != CSSStyleValue::StyleValueType::kPercentType)) { |
| 21 exception_state.ThrowTypeError( |
| 22 "Must pass length or percentage to X and Y of CSSTranslation"); |
| 23 return nullptr; |
| 24 } |
| 25 return new CSSTranslation( |
| 26 x, y, CSSUnitValue::Create(0, CSSPrimitiveValue::UnitType::kPixels), |
| 27 true /* is2D */); |
| 28 } |
| 29 |
| 30 CSSTranslation* CSSTranslation::Create(CSSNumericValue* x, |
| 31 CSSNumericValue* y, |
16 CSSNumericValue* z, | 32 CSSNumericValue* z, |
17 ExceptionState& exception_state) { | 33 ExceptionState& exception_state) { |
18 if ((x->GetType() != CSSStyleValue::StyleValueType::kLengthType && | 34 if ((x->GetType() != CSSStyleValue::StyleValueType::kLengthType && |
19 x->GetType() != CSSStyleValue::StyleValueType::kPercentType) || | 35 x->GetType() != CSSStyleValue::StyleValueType::kPercentType) || |
20 (y->GetType() != CSSStyleValue::StyleValueType::kLengthType && | 36 (y->GetType() != CSSStyleValue::StyleValueType::kLengthType && |
21 y->GetType() != CSSStyleValue::StyleValueType::kPercentType)) { | 37 y->GetType() != CSSStyleValue::StyleValueType::kPercentType)) { |
22 exception_state.ThrowTypeError( | 38 exception_state.ThrowTypeError( |
23 "Must pass length or percentage to X and Y of CSSTranslation"); | 39 "Must pass length or percentage to X and Y of CSSTranslation"); |
24 return nullptr; | 40 return nullptr; |
25 } | 41 } |
26 if (z && z->GetType() != CSSStyleValue::StyleValueType::kLengthType) { | 42 if (z && z->GetType() != CSSStyleValue::StyleValueType::kLengthType) { |
27 exception_state.ThrowTypeError("Must pass length to Z of CSSTranslation"); | 43 exception_state.ThrowTypeError("Must pass length to Z of CSSTranslation"); |
28 return nullptr; | 44 return nullptr; |
29 } | 45 } |
30 if (z && z->ContainsPercent()) { | 46 if (z && z->ContainsPercent()) { |
31 exception_state.ThrowTypeError( | 47 exception_state.ThrowTypeError( |
32 "CSSTranslation does not support z CSSNumericValue with percent units"); | 48 "CSSTranslation does not support z CSSNumericValue with percent units"); |
33 return nullptr; | 49 return nullptr; |
34 } | 50 } |
35 return new CSSTranslation(x, y, z); | 51 return new CSSTranslation(x, y, z, false /* is2D */); |
36 } | 52 } |
37 | 53 |
38 void CSSTranslation::setX(CSSNumericValue* x, ExceptionState& exception_state) { | 54 void CSSTranslation::setX(CSSNumericValue* x, ExceptionState& exception_state) { |
39 if (x->GetType() != CSSStyleValue::StyleValueType::kLengthType && | 55 if (x->GetType() != CSSStyleValue::StyleValueType::kLengthType && |
40 x->GetType() != CSSStyleValue::StyleValueType::kPercentType) { | 56 x->GetType() != CSSStyleValue::StyleValueType::kPercentType) { |
41 exception_state.ThrowTypeError( | 57 exception_state.ThrowTypeError( |
42 "Must pass length or percentage to X of CSSTranslation"); | 58 "Must pass length or percentage to X of CSSTranslation"); |
43 return; | 59 return; |
44 } | 60 } |
45 x_ = x; | 61 x_ = x; |
(...skipping 17 matching lines...) Expand all Loading... |
63 if (z && z->ContainsPercent()) { | 79 if (z && z->ContainsPercent()) { |
64 exception_state.ThrowTypeError( | 80 exception_state.ThrowTypeError( |
65 "CSSTranslation does not support z CSSNumericValue with percent units"); | 81 "CSSTranslation does not support z CSSNumericValue with percent units"); |
66 return; | 82 return; |
67 } | 83 } |
68 z_ = z; | 84 z_ = z; |
69 } | 85 } |
70 | 86 |
71 CSSFunctionValue* CSSTranslation::ToCSSValue() const { | 87 CSSFunctionValue* CSSTranslation::ToCSSValue() const { |
72 CSSFunctionValue* result = CSSFunctionValue::Create( | 88 CSSFunctionValue* result = CSSFunctionValue::Create( |
73 Is2D() ? CSSValueTranslate : CSSValueTranslate3d); | 89 is2D() ? CSSValueTranslate : CSSValueTranslate3d); |
74 result->Append(*x_->ToCSSValue()); | 90 result->Append(*x_->ToCSSValue()); |
75 result->Append(*y_->ToCSSValue()); | 91 result->Append(*y_->ToCSSValue()); |
76 if (!Is2D()) | 92 if (!is2D()) |
77 result->Append(*z_->ToCSSValue()); | 93 result->Append(*z_->ToCSSValue()); |
78 return result; | 94 return result; |
79 } | 95 } |
80 | 96 |
81 } // namespace blink | 97 } // namespace blink |
OLD | NEW |