| 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 DOMMatrix* matrix = DOMMatrix::Create(); |
| 41 for (size_t i = 0; i < transform_components_.size(); i++) { |
| 42 CSSMatrixComponent* matrixComponent = transform_components_[i]->asMatrix(); |
| 43 if (matrixComponent) { |
| 44 matrix->multiplySelf(matrixComponent->matrix()); |
| 45 } |
| 46 } |
| 47 return matrix; |
| 48 } |
| 49 |
| 37 const CSSValue* CSSTransformValue::ToCSSValue() const { | 50 const CSSValue* CSSTransformValue::ToCSSValue() const { |
| 38 CSSValueList* transform_css_value = CSSValueList::CreateSpaceSeparated(); | 51 CSSValueList* transform_css_value = CSSValueList::CreateSpaceSeparated(); |
| 39 for (size_t i = 0; i < transform_components_.size(); i++) { | 52 for (size_t i = 0; i < transform_components_.size(); i++) { |
| 40 const CSSValue* component = transform_components_[i]->ToCSSValue(); | 53 const CSSValue* component = transform_components_[i]->ToCSSValue(); |
| 41 // TODO(meade): Remove this check once numbers and lengths are rewritten. | 54 // TODO(meade): Remove this check once numbers and lengths are rewritten. |
| 42 if (!component) | 55 if (!component) |
| 43 return nullptr; | 56 return nullptr; |
| 44 transform_css_value->Append(*component); | 57 transform_css_value->Append(*component); |
| 45 } | 58 } |
| 46 return transform_css_value; | 59 return transform_css_value; |
| 47 } | 60 } |
| 48 | 61 |
| 49 } // namespace blink | 62 } // namespace blink |
| OLD | NEW |