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) | |
| 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 { |
| 14 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(propertyID); | 35 Document& document = m_node->document(); |
| 15 if (!cssValue) | 36 // TODO(rjwright): This style recalc is copied from |
| 16 return CSSStyleValueVector(); | 37 // CSSComputedStyleDeclaration::getPropertyValue, which also does a bunch of other stuff. |
| 17 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); | 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 if (!styleValue) { | |
|
meade_UTC10
2016/09/22 05:34:35
I think it's clearer, and you can save a level of
rjwright
2016/09/23 04:50:04
Done.
But I'm kinda unsure about our decision to
| |
| 61 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSVal ueInternal(propertyID); | |
| 62 if (cssValue) { | |
| 63 return StyleValueFactory::unsupportedCSSValue(*cssValue); | |
| 64 } | |
| 65 return styleValueVector; | |
| 66 } | |
| 67 styleValueVector.append(styleValue); | |
| 68 return styleValueVector; | |
| 18 } | 69 } |
| 19 | 70 |
| 20 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(AtomicString custom PropertyName) | 71 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(AtomicString custom PropertyName) |
| 21 { | 72 { |
| 22 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(customPropertyName); | 73 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(customPropertyName); |
| 23 if (!cssValue) | 74 if (!cssValue) |
| 24 return CSSStyleValueVector(); | 75 return CSSStyleValueVector(); |
| 25 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, *cs sValue); | 76 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, *cs sValue); |
| 26 } | 77 } |
| 27 | 78 |
| 28 Vector<String> ComputedStylePropertyMap::getProperties() | 79 Vector<String> ComputedStylePropertyMap::getProperties() |
| 29 { | 80 { |
| 30 Vector<String> result; | 81 Vector<String> result; |
| 31 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { | 82 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { |
| 32 result.append(m_computedStyleDeclaration->item(i)); | 83 result.append(m_computedStyleDeclaration->item(i)); |
| 33 } | 84 } |
| 34 return result; | 85 return result; |
| 35 } | 86 } |
| 36 | 87 |
| 37 } // namespace blink | 88 } // namespace blink |
| OLD | NEW |