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/CSSTransformValue.h" | 5 #include "core/css/cssom/CSSTransformValue.h" |
6 | 6 |
7 #include "core/css/CSSValueList.h" | 7 #include "core/css/CSSValueList.h" |
8 #include "core/css/cssom/CSSMatrixComponent.h" | |
8 #include "core/css/cssom/CSSTransformComponent.h" | 9 #include "core/css/cssom/CSSTransformComponent.h" |
10 #include "core/geometry/DOMMatrix.h" | |
9 | 11 |
10 namespace blink { | 12 namespace blink { |
11 | 13 |
12 CSSTransformValue* CSSTransformValue::FromCSSValue(const CSSValue& css_value) { | 14 CSSTransformValue* CSSTransformValue::FromCSSValue(const CSSValue& css_value) { |
13 if (!css_value.IsValueList()) { | 15 if (!css_value.IsValueList()) { |
14 // TODO(meade): Also need to check the separator here if we care. | 16 // TODO(meade): Also need to check the separator here if we care. |
15 return nullptr; | 17 return nullptr; |
16 } | 18 } |
17 HeapVector<Member<CSSTransformComponent>> components; | 19 HeapVector<Member<CSSTransformComponent>> components; |
18 for (const CSSValue* value : ToCSSValueList(css_value)) { | 20 for (const CSSValue* value : ToCSSValueList(css_value)) { |
19 CSSTransformComponent* component = | 21 CSSTransformComponent* component = |
20 CSSTransformComponent::FromCSSValue(*value); | 22 CSSTransformComponent::FromCSSValue(*value); |
21 if (!component) | 23 if (!component) |
22 return nullptr; | 24 return nullptr; |
23 components.push_back(component); | 25 components.push_back(component); |
24 } | 26 } |
25 return CSSTransformValue::Create(components); | 27 return CSSTransformValue::Create(components); |
26 } | 28 } |
27 | 29 |
28 bool CSSTransformValue::is2D() const { | 30 bool CSSTransformValue::is2D() const { |
29 for (size_t i = 0; i < transform_components_.size(); i++) { | 31 for (size_t i = 0; i < transform_components_.size(); i++) { |
30 if (!transform_components_[i]->is2D()) { | 32 if (!transform_components_[i]->is2D()) { |
31 return false; | 33 return false; |
32 } | 34 } |
33 } | 35 } |
34 return true; | 36 return true; |
35 } | 37 } |
36 | 38 |
39 DOMMatrix* CSSTransformValue::toMatrix() const { | |
40 DOMMatrixInit init; | |
41 DOMMatrix* matrix = DOMMatrix::fromMatrix(init, ASSERT_NO_EXCEPTION); | |
zino
2017/06/02 02:31:21
IMHO, we don't need to copy the matrix from DOMMat
Hwanseung Lee
2017/06/02 13:25:51
Done.
| |
42 for (size_t i = 0; i < transform_components_.size(); i++) { | |
43 CSSMatrixComponent* matrixComponent = transform_components_[i]->asMatrix(); | |
44 if (matrixComponent) { | |
45 matrix->multiplySelf(matrixComponent->matrix()); | |
46 } | |
47 } | |
48 return matrix; | |
49 } | |
50 | |
37 const CSSValue* CSSTransformValue::ToCSSValue() const { | 51 const CSSValue* CSSTransformValue::ToCSSValue() const { |
38 CSSValueList* transform_css_value = CSSValueList::CreateSpaceSeparated(); | 52 CSSValueList* transform_css_value = CSSValueList::CreateSpaceSeparated(); |
39 for (size_t i = 0; i < transform_components_.size(); i++) { | 53 for (size_t i = 0; i < transform_components_.size(); i++) { |
40 transform_css_value->Append(*transform_components_[i]->ToCSSValue()); | 54 transform_css_value->Append(*transform_components_[i]->ToCSSValue()); |
41 } | 55 } |
42 return transform_css_value; | 56 return transform_css_value; |
43 } | 57 } |
44 | 58 |
45 } // namespace blink | 59 } // namespace blink |
OLD | NEW |