Chromium Code Reviews| 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 CSSStyleValue* styleValueForLengthProperty(const Length& length) | |
|
meade_UTC10
2016/09/23 05:21:25
nit: just styleValueForLength for brevity? (also y
rjwright
2016/09/23 05:39:29
Done.
| |
| 16 { | |
| 17 if (length.isAuto()) { | |
| 18 return CSSKeywordValue::create("auto"); | |
| 19 } | |
| 20 if (length.isFixed()) { | |
| 21 return CSSSimpleLength::create(length.pixels(), CSSPrimitiveValue::UnitT ype::Pixels); | |
| 22 } | |
| 23 if (length.isPercent()) { | |
| 24 return CSSSimpleLength::create(length.percent(), CSSPrimitiveValue::Unit Type::Percentage); | |
| 25 } | |
| 26 if (length.isCalculated()) { | |
| 27 return CSSCalcLength::fromLength(length); | |
| 28 } | |
| 29 NOTREACHED(); | |
| 30 return nullptr; | |
| 31 } | |
| 32 | |
| 12 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(CSSPropertyID prope rtyID) | 33 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(CSSPropertyID prope rtyID) |
| 13 { | 34 { |
| 35 Document& document = m_node->document(); | |
| 36 // TODO(rjwright): This style recalc is copied from | |
| 37 // CSSComputedStyleDeclaration::getPropertyValue, which also does a bunch of other stuff. | |
| 38 // Need to look back to it and see if I need to do more here. | |
| 39 document.updateStyleAndLayoutTreeForNode(m_node); | |
| 40 const ComputedStyle* style = m_node->ensureComputedStyle(); | |
| 41 CSSStyleValueVector styleValueVector; | |
| 42 CSSStyleValue* styleValue = nullptr; | |
| 43 switch (propertyID) { | |
| 44 case CSSPropertyLeft: | |
| 45 styleValue = styleValueForLengthProperty(style->left()); | |
| 46 case CSSPropertyRight: | |
| 47 styleValue = styleValueForLengthProperty(style->right()); | |
| 48 case CSSPropertyTop: | |
| 49 styleValue = styleValueForLengthProperty(style->top()); | |
| 50 case CSSPropertyBottom: | |
| 51 styleValue = styleValueForLengthProperty(style->bottom()); | |
| 52 case CSSPropertyHeight: | |
| 53 styleValue = styleValueForLengthProperty(style->height()); | |
| 54 case CSSPropertyWidth: { | |
| 55 styleValue = styleValueForLengthProperty(style->width()); | |
| 56 } | |
| 57 default: | |
| 58 break; | |
| 59 } | |
| 60 | |
| 61 if (styleValue) { | |
| 62 styleValueVector.append(styleValue); | |
| 63 return styleValueVector; | |
| 64 } | |
| 14 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(propertyID); | 65 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(propertyID); |
| 15 if (!cssValue) | 66 if (cssValue) { |
| 16 return CSSStyleValueVector(); | 67 return StyleValueFactory::unsupportedCSSValue(*cssValue); |
| 17 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); | 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 |