| 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/ComputedStylePropertyMap.h" | 5 #include "core/css/cssom/ComputedStylePropertyMap.h" |
| 6 | 6 |
| 7 #include "core/css/CSSComputedStyleDeclaration.h" | 7 #include "core/css/CSSComputedStyleDeclaration.h" |
| 8 #include "core/css/cssom/CSSCalcLength.h" |
| 9 #include "core/css/cssom/CSSKeywordValue.h" |
| 10 #include "core/css/cssom/CSSSimpleLength.h" |
| 8 #include "core/css/cssom/StyleValueFactory.h" | 11 #include "core/css/cssom/StyleValueFactory.h" |
| 12 #include "core/dom/PseudoElement.h" |
| 9 | 13 |
| 10 namespace blink { | 14 namespace blink { |
| 11 | 15 |
| 12 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( | 16 namespace { |
| 13 CSSPropertyID propertyID) { | 17 |
| 14 const CSSValue* cssValue = | 18 CSSStyleValue* styleValueForLength(const Length& length) { |
| 15 m_computedStyleDeclaration->getPropertyCSSValueInternal(propertyID); | 19 if (length.isAuto()) { |
| 16 if (!cssValue) | 20 return CSSKeywordValue::create("auto"); |
| 17 return CSSStyleValueVector(); | 21 } |
| 18 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); | 22 if (length.isFixed()) { |
| 23 return CSSSimpleLength::create(length.pixels(), |
| 24 CSSPrimitiveValue::UnitType::Pixels); |
| 25 } |
| 26 if (length.isPercent()) { |
| 27 return CSSSimpleLength::create(length.percent(), |
| 28 CSSPrimitiveValue::UnitType::Percentage); |
| 29 } |
| 30 if (length.isCalculated()) { |
| 31 return CSSCalcLength::fromLength(length); |
| 32 } |
| 33 NOTREACHED(); |
| 34 return nullptr; |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
| 39 Node* ComputedStylePropertyMap::node() const { |
| 40 if (m_node->isElementNode()) { |
| 41 if (PseudoElement* element = |
| 42 toElement(m_node)->pseudoElement(m_node->getPseudoId())) |
| 43 return element; |
| 44 } |
| 45 return m_node; |
| 19 } | 46 } |
| 20 | 47 |
| 21 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( | 48 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( |
| 49 CSSPropertyID propertyID) { |
| 50 Node* node = this->node(); |
| 51 Document& document = node->document(); |
| 52 // TODO(rjwright): This style recalc is copied from |
| 53 // CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID), which also |
| 54 // does a "force |
| 55 // full layout" step. Need to work out if I need to do that too. |
| 56 document.updateStyleAndLayoutTreeForNode(node); |
| 57 // TODO(rjwright): Do I need this? |
| 58 node = this->node(); |
| 59 const ComputedStyle* style = node->ensureComputedStyle(node->getPseudoId()); |
| 60 |
| 61 CSSStyleValueVector styleValueVector; |
| 62 CSSStyleValue* styleValue = nullptr; |
| 63 switch (propertyID) { |
| 64 case CSSPropertyLeft: |
| 65 styleValue = styleValueForLength(style->left()); |
| 66 break; |
| 67 case CSSPropertyRight: |
| 68 styleValue = styleValueForLength(style->right()); |
| 69 break; |
| 70 case CSSPropertyTop: |
| 71 styleValue = styleValueForLength(style->top()); |
| 72 break; |
| 73 case CSSPropertyBottom: |
| 74 styleValue = styleValueForLength(style->bottom()); |
| 75 break; |
| 76 case CSSPropertyHeight: |
| 77 styleValue = styleValueForLength(style->height()); |
| 78 break; |
| 79 case CSSPropertyWidth: |
| 80 styleValue = styleValueForLength(style->width()); |
| 81 break; |
| 82 default: |
| 83 break; |
| 84 } |
| 85 |
| 86 if (styleValue) { |
| 87 styleValueVector.append(styleValue); |
| 88 } |
| 89 return styleValueVector; |
| 90 } |
| 91 |
| 92 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( |
| 22 AtomicString customPropertyName) { | 93 AtomicString customPropertyName) { |
| 23 const CSSValue* cssValue = | 94 const CSSValue* cssValue = |
| 24 m_computedStyleDeclaration->getPropertyCSSValueInternal( | 95 m_computedStyleDeclaration->getPropertyCSSValueInternal( |
| 25 customPropertyName); | 96 customPropertyName); |
| 26 if (!cssValue) | 97 if (!cssValue) |
| 27 return CSSStyleValueVector(); | 98 return CSSStyleValueVector(); |
| 28 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, | 99 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, |
| 29 *cssValue); | 100 *cssValue); |
| 30 } | 101 } |
| 31 | 102 |
| 32 Vector<String> ComputedStylePropertyMap::getProperties() { | 103 Vector<String> ComputedStylePropertyMap::getProperties() { |
| 33 Vector<String> result; | 104 Vector<String> result; |
| 34 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { | 105 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { |
| 35 result.append(m_computedStyleDeclaration->item(i)); | 106 result.append(m_computedStyleDeclaration->item(i)); |
| 36 } | 107 } |
| 37 return result; | 108 return result; |
| 38 } | 109 } |
| 39 | 110 |
| 40 } // namespace blink | 111 } // namespace blink |
| OLD | NEW |