| 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" |
| 9 | 12 |
| 10 namespace blink { | 13 namespace blink { |
| 11 | 14 |
| 15 namespace { |
| 16 |
| 17 CSSStyleValue* styleValueForLength(const Length& length) |
| 18 { |
| 19 if (length.isAuto()) { |
| 20 return CSSKeywordValue::create("auto"); |
| 21 } |
| 22 if (length.isFixed()) { |
| 23 return CSSSimpleLength::create(length.pixels(), CSSPrimitiveValue::UnitT
ype::Pixels); |
| 24 } |
| 25 if (length.isPercent()) { |
| 26 return CSSSimpleLength::create(length.percent(), CSSPrimitiveValue::Unit
Type::Percentage); |
| 27 } |
| 28 if (length.isCalculated()) { |
| 29 return CSSCalcLength::fromLength(length); |
| 30 } |
| 31 NOTREACHED(); |
| 32 return nullptr; |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 12 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(CSSPropertyID prope
rtyID) | 37 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(CSSPropertyID prope
rtyID) |
| 13 { | 38 { |
| 14 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn
ternal(propertyID); | 39 Node* node = m_computedStyleDeclaration->styledNode(); |
| 15 if (!cssValue) | 40 Document& document = node->document(); |
| 16 return CSSStyleValueVector(); | 41 // TODO(rjwright): This style recalc is copied from |
| 17 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); | 42 // CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID), which al
so does a "force |
| 43 // full layout" step. Need to work out if I need to do that too. |
| 44 document.updateStyleAndLayoutTreeForNode(node); |
| 45 const ComputedStyle* style = m_computedStyleDeclaration->computeComputedStyl
e(); |
| 46 |
| 47 CSSStyleValueVector styleValueVector; |
| 48 CSSStyleValue* styleValue = nullptr; |
| 49 switch (propertyID) { |
| 50 case CSSPropertyLeft: |
| 51 styleValue = styleValueForLength(style->left()); |
| 52 case CSSPropertyRight: |
| 53 styleValue = styleValueForLength(style->right()); |
| 54 case CSSPropertyTop: |
| 55 styleValue = styleValueForLength(style->top()); |
| 56 case CSSPropertyBottom: |
| 57 styleValue = styleValueForLength(style->bottom()); |
| 58 case CSSPropertyHeight: |
| 59 styleValue = styleValueForLength(style->height()); |
| 60 case CSSPropertyWidth: |
| 61 styleValue = styleValueForLength(style->width()); |
| 62 default: |
| 63 break; |
| 64 } |
| 65 |
| 66 if (styleValue) { |
| 67 styleValueVector.append(styleValue); |
| 68 } |
| 69 return styleValueVector; |
| 18 } | 70 } |
| 19 | 71 |
| 20 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(AtomicString custom
PropertyName) | 72 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(AtomicString custom
PropertyName) |
| 21 { | 73 { |
| 22 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn
ternal(customPropertyName); | 74 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn
ternal(customPropertyName); |
| 23 if (!cssValue) | 75 if (!cssValue) |
| 24 return CSSStyleValueVector(); | 76 return CSSStyleValueVector(); |
| 25 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, *cs
sValue); | 77 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, *cs
sValue); |
| 26 } | 78 } |
| 27 | 79 |
| 28 Vector<String> ComputedStylePropertyMap::getProperties() | 80 Vector<String> ComputedStylePropertyMap::getProperties() |
| 29 { | 81 { |
| 30 Vector<String> result; | 82 Vector<String> result; |
| 31 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { | 83 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { |
| 32 result.append(m_computedStyleDeclaration->item(i)); | 84 result.append(m_computedStyleDeclaration->item(i)); |
| 33 } | 85 } |
| 34 return result; | 86 return result; |
| 35 } | 87 } |
| 36 | 88 |
| 37 } // namespace blink | 89 } // namespace blink |
| OLD | NEW |