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* styleValueForLength(const Length& length) | |
|
meade_UTC10
2016/09/27 04:41:39
Nit: It's conventional to put pure methods like th
rjwright
2016/09/28 01:38:24
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. | |
|
meade_UTC10
2016/09/27 04:41:39
Did you end up asking anyone about this?
rjwright
2016/09/28 01:38:24
No. I'm not sure who to ask. I was planning to jus
meade_UTC10
2016/09/28 01:51:32
No strong opinions - but we may be able to ask Bug
| |
| 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 = styleValueForLength(style->left()); | |
| 46 case CSSPropertyRight: | |
| 47 styleValue = styleValueForLength(style->right()); | |
| 48 case CSSPropertyTop: | |
| 49 styleValue = styleValueForLength(style->top()); | |
| 50 case CSSPropertyBottom: | |
| 51 styleValue = styleValueForLength(style->bottom()); | |
| 52 case CSSPropertyHeight: | |
| 53 styleValue = styleValueForLength(style->height()); | |
| 54 case CSSPropertyWidth: { | |
| 55 styleValue = styleValueForLength(style->width()); | |
| 56 } | |
| 57 default: | |
| 58 break; | |
| 59 } | |
| 60 | |
| 61 if (styleValue) { | |
| 62 styleValueVector.append(styleValue); | |
| 63 return styleValueVector; | |
| 64 } | |
| 65 // Note: this is just a stopgap to make prototyping easier. cssValue represe nts a resolved | |
| 66 // style, not a computed style; so the cssText in the unsupportedCSSValue wo n't necessarily | |
| 67 // match the typed CSSStyleValue that will eventually be returned here. | |
| 14 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(propertyID); | 68 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(propertyID); |
| 15 if (!cssValue) | 69 if (cssValue) { |
| 16 return CSSStyleValueVector(); | 70 return StyleValueFactory::unsupportedCSSValue(*cssValue); |
|
meade_UTC10
2016/09/27 04:41:39
We're going to get rid of UnsupportedCSSValue afte
rjwright
2016/09/28 01:38:24
Done.
| |
| 17 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); | 71 } |
| 72 return styleValueVector; | |
| 18 } | 73 } |
| 19 | 74 |
| 20 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(AtomicString custom PropertyName) | 75 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(AtomicString custom PropertyName) |
| 21 { | 76 { |
| 22 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(customPropertyName); | 77 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(customPropertyName); |
| 23 if (!cssValue) | 78 if (!cssValue) |
| 24 return CSSStyleValueVector(); | 79 return CSSStyleValueVector(); |
| 25 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, *cs sValue); | 80 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, *cs sValue); |
| 26 } | 81 } |
| 27 | 82 |
| 28 Vector<String> ComputedStylePropertyMap::getProperties() | 83 Vector<String> ComputedStylePropertyMap::getProperties() |
| 29 { | 84 { |
| 30 Vector<String> result; | 85 Vector<String> result; |
| 31 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { | 86 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { |
| 32 result.append(m_computedStyleDeclaration->item(i)); | 87 result.append(m_computedStyleDeclaration->item(i)); |
| 33 } | 88 } |
| 34 return result; | 89 return result; |
| 35 } | 90 } |
| 36 | 91 |
| 37 } // namespace blink | 92 } // namespace blink |
| OLD | NEW |