| 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/TransformValue.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/CSSTransformComponent.h" | 8 #include "core/css/cssom/CSSTransformComponent.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class TransformValueIterationSource final : public ValueIterable<CSSTransformCom
ponent*>::IterationSource { | 14 class TransformValueIterationSource final : public ValueIterable<CSSTransformCom
ponent*>::IterationSource { |
| 15 public: | 15 public: |
| 16 explicit TransformValueIterationSource(TransformValue* transformValue) | 16 explicit TransformValueIterationSource(CSSTransformValue* transformValue) |
| 17 : m_transformValue(transformValue) | 17 : m_transformValue(transformValue) |
| 18 { | 18 { |
| 19 } | 19 } |
| 20 | 20 |
| 21 bool next(ScriptState*, CSSTransformComponent*& value, ExceptionState&) over
ride | 21 bool next(ScriptState*, CSSTransformComponent*& value, ExceptionState&) over
ride |
| 22 { | 22 { |
| 23 if (m_index >= m_transformValue->size()) { | 23 if (m_index >= m_transformValue->size()) { |
| 24 return false; | 24 return false; |
| 25 } | 25 } |
| 26 value = m_transformValue->componentAtIndex(m_index); | 26 value = m_transformValue->componentAtIndex(m_index); |
| 27 return true; | 27 return true; |
| 28 } | 28 } |
| 29 | 29 |
| 30 DEFINE_INLINE_VIRTUAL_TRACE() | 30 DEFINE_INLINE_VIRTUAL_TRACE() |
| 31 { | 31 { |
| 32 visitor->trace(m_transformValue); | 32 visitor->trace(m_transformValue); |
| 33 ValueIterable<CSSTransformComponent*>::IterationSource::trace(visitor); | 33 ValueIterable<CSSTransformComponent*>::IterationSource::trace(visitor); |
| 34 } | 34 } |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 const Member<TransformValue> m_transformValue; | 37 const Member<CSSTransformValue> m_transformValue; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 TransformValue* TransformValue::fromCSSValue(const CSSValue& cssValue) | 42 CSSTransformValue* CSSTransformValue::fromCSSValue(const CSSValue& cssValue) |
| 43 { | 43 { |
| 44 if (!cssValue.isValueList()) { | 44 if (!cssValue.isValueList()) { |
| 45 // TODO(meade): Also need to check the separator here if we care. | 45 // TODO(meade): Also need to check the separator here if we care. |
| 46 return nullptr; | 46 return nullptr; |
| 47 } | 47 } |
| 48 HeapVector<Member<CSSTransformComponent>> components; | 48 HeapVector<Member<CSSTransformComponent>> components; |
| 49 for (const CSSValue* value : toCSSValueList(cssValue)) { | 49 for (const CSSValue* value : toCSSValueList(cssValue)) { |
| 50 CSSTransformComponent* component = CSSTransformComponent::fromCSSValue(*
value); | 50 CSSTransformComponent* component = CSSTransformComponent::fromCSSValue(*
value); |
| 51 if (!component) | 51 if (!component) |
| 52 return nullptr; | 52 return nullptr; |
| 53 components.append(component); | 53 components.append(component); |
| 54 } | 54 } |
| 55 return TransformValue::create(components); | 55 return CSSTransformValue::create(components); |
| 56 } | 56 } |
| 57 | 57 |
| 58 ValueIterable<CSSTransformComponent*>::IterationSource* TransformValue::startIte
ration(ScriptState*, ExceptionState&) | 58 ValueIterable<CSSTransformComponent*>::IterationSource* CSSTransformValue::start
Iteration(ScriptState*, ExceptionState&) |
| 59 { | 59 { |
| 60 return new TransformValueIterationSource(this); | 60 return new TransformValueIterationSource(this); |
| 61 } | 61 } |
| 62 | 62 |
| 63 bool TransformValue::is2D() const | 63 bool CSSTransformValue::is2D() const |
| 64 { | 64 { |
| 65 for (size_t i = 0; i < m_transformComponents.size(); i++) { | 65 for (size_t i = 0; i < m_transformComponents.size(); i++) { |
| 66 if (!m_transformComponents[i]->is2DComponent()) { | 66 if (!m_transformComponents[i]->is2DComponent()) { |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 return true; | 70 return true; |
| 71 } | 71 } |
| 72 | 72 |
| 73 CSSValue* TransformValue::toCSSValue() const | 73 CSSValue* CSSTransformValue::toCSSValue() const |
| 74 { | 74 { |
| 75 CSSValueList* transformCSSValue = CSSValueList::createSpaceSeparated(); | 75 CSSValueList* transformCSSValue = CSSValueList::createSpaceSeparated(); |
| 76 for (size_t i = 0; i < m_transformComponents.size(); i++) { | 76 for (size_t i = 0; i < m_transformComponents.size(); i++) { |
| 77 transformCSSValue->append(*m_transformComponents[i]->toCSSValue()); | 77 transformCSSValue->append(*m_transformComponents[i]->toCSSValue()); |
| 78 } | 78 } |
| 79 return transformCSSValue; | 79 return transformCSSValue; |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace blink | 82 } // namespace blink |
| OLD | NEW |