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/ComputedStyleCSSValueMapping.h" | |
| 9 #include "core/css/cssom/CSSCalcLength.h" | |
| 10 #include "core/css/cssom/CSSKeywordValue.h" | |
| 11 #include "core/css/cssom/CSSSimpleLength.h" | |
| 12 #include "core/css/cssom/CSSUnsupportedStyleValue.h" | |
| 8 #include "core/css/cssom/StyleValueFactory.h" | 13 #include "core/css/cssom/StyleValueFactory.h" |
| 14 #include "core/css/resolver/StyleResolver.h" | |
| 15 #include "core/dom/PseudoElement.h" | |
| 16 #include "core/dom/StyleEngine.h" | |
| 9 | 17 |
| 10 namespace blink { | 18 namespace blink { |
| 11 | 19 |
| 20 namespace { | |
| 21 | |
| 22 CSSStyleValue* styleValueForLength(const Length& length) { | |
|
sashab
2017/01/09 02:19:04
const CSSStyleValue&
Make return nullptr at end j
| |
| 23 if (length.isAuto()) { | |
| 24 return CSSKeywordValue::create("auto"); | |
| 25 } | |
| 26 if (length.isFixed()) { | |
| 27 return CSSSimpleLength::create(length.pixels(), | |
| 28 CSSPrimitiveValue::UnitType::Pixels); | |
| 29 } | |
| 30 if (length.isPercent()) { | |
| 31 return CSSSimpleLength::create(length.percent(), | |
| 32 CSSPrimitiveValue::UnitType::Percentage); | |
| 33 } | |
| 34 if (length.isCalculated()) { | |
| 35 return CSSCalcLength::fromLength(length); | |
| 36 } | |
| 37 NOTREACHED(); | |
| 38 return nullptr; | |
| 39 } | |
| 40 | |
| 41 } // namespace | |
| 42 | |
| 43 Node* ComputedStylePropertyMap::node() const { | |
|
sashab
2017/01/09 02:19:04
const Node*
| |
| 44 if (!m_node) { | |
| 45 return nullptr; | |
| 46 } | |
| 47 if (!m_pseudoId) { | |
| 48 return m_node; | |
| 49 } | |
| 50 if (m_node->isElementNode()) { | |
| 51 // Seems to only support before, after, backdrop, first-letter. See | |
| 52 // PseudoElementData::pseudoElement. | |
| 53 if (PseudoElement* element = | |
| 54 (toElement(m_node))->pseudoElement(m_pseudoId)) { | |
| 55 return element; | |
| 56 } | |
| 57 } | |
| 58 return nullptr; | |
| 59 } | |
| 60 | |
| 12 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( | 61 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( |
| 13 CSSPropertyID propertyID) { | 62 CSSPropertyID propertyID) { |
| 14 const CSSValue* cssValue = | 63 CSSStyleValueVector styleValueVector; |
| 15 m_computedStyleDeclaration->getPropertyCSSValueInternal(propertyID); | 64 |
| 16 if (!cssValue) | 65 Node* node = this->node(); |
| 17 return CSSStyleValueVector(); | 66 if (!node) { |
| 18 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); | 67 return styleValueVector; |
| 68 } | |
| 69 if (!node->inActiveDocument()) { | |
|
sashab
2017/01/09 02:19:04
Make above if statement if (!node || !node->inActi
| |
| 70 return styleValueVector; | |
| 71 } | |
| 72 node->document().updateStyleAndLayoutTreeForNode(node); | |
| 73 node = this->node(); | |
| 74 if (!node) { | |
| 75 return styleValueVector; | |
| 76 } | |
| 77 // I have copied this from | |
| 78 // CSSComputedStyleDeclaration::computeComputedStyle(). I don't know if | |
| 79 // there is any use in passing m_pseudoId if node is not already a | |
| 80 // PseudoElement, but passing | |
| 81 // pseudo_Id when it IS already a PseudoElement leads to disaster. | |
| 82 const ComputedStyle* style = node->ensureComputedStyle( | |
| 83 node->isPseudoElement() ? PseudoIdNone : m_pseudoId); | |
| 84 node = this->node(); | |
| 85 if (!node) { | |
| 86 return styleValueVector; | |
| 87 } | |
| 88 if (!node->inActiveDocument()) { | |
|
sashab
2017/01/09 02:19:04
Make above if-statement ||
| |
| 89 return styleValueVector; | |
| 90 } | |
| 91 | |
| 92 CSSStyleValue* styleValue = nullptr; | |
| 93 | |
| 94 if (!style) | |
|
sashab
2017/01/09 02:19:04
Move this into above if statement too
| |
| 95 return styleValueVector; | |
| 96 | |
| 97 switch (propertyID) { | |
| 98 // TODO(rjwright): Generate this code. | |
| 99 case CSSPropertyLeft: | |
| 100 styleValue = styleValueForLength(style->left()); | |
| 101 break; | |
| 102 case CSSPropertyRight: | |
| 103 styleValue = styleValueForLength(style->right()); | |
| 104 break; | |
| 105 case CSSPropertyTop: | |
| 106 styleValue = styleValueForLength(style->top()); | |
| 107 break; | |
| 108 case CSSPropertyBottom: | |
| 109 styleValue = styleValueForLength(style->bottom()); | |
| 110 break; | |
| 111 case CSSPropertyHeight: | |
| 112 styleValue = styleValueForLength(style->height()); | |
| 113 break; | |
| 114 case CSSPropertyWidth: | |
| 115 styleValue = styleValueForLength(style->width()); | |
| 116 break; | |
| 117 default: | |
| 118 // TODO(rjwright): Add a flag argument to | |
| 119 // ComputedStyleCSSValyeMapping::get that makes it return | |
| 120 // just the raw value off the ComputedStyle, and not zoom adjusted or | |
| 121 // anything like that. | |
| 122 const CSSValue* value = ComputedStyleCSSValueMapping::get( | |
| 123 propertyID, *style, nullptr, node, false); | |
| 124 if (value) { | |
| 125 styleValue = CSSUnsupportedStyleValue::create(value->cssText()); | |
| 126 } | |
| 127 break; | |
| 128 } | |
| 129 | |
| 130 if (styleValue) { | |
| 131 styleValueVector.append(styleValue); | |
| 132 } | |
| 133 return styleValueVector; | |
| 19 } | 134 } |
| 20 | 135 |
| 21 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( | 136 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( |
| 22 AtomicString customPropertyName) { | 137 AtomicString customPropertyName) { |
| 23 const CSSValue* cssValue = | 138 const CSSValue* cssValue = |
| 24 m_computedStyleDeclaration->getPropertyCSSValueInternal( | 139 m_computedStyleDeclaration->getPropertyCSSValue(customPropertyName); |
| 25 customPropertyName); | |
| 26 if (!cssValue) | 140 if (!cssValue) |
| 27 return CSSStyleValueVector(); | 141 return CSSStyleValueVector(); |
| 28 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, | 142 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, |
| 29 *cssValue); | 143 *cssValue); |
| 30 } | 144 } |
| 31 | 145 |
| 32 Vector<String> ComputedStylePropertyMap::getProperties() { | 146 Vector<String> ComputedStylePropertyMap::getProperties() { |
| 33 Vector<String> result; | 147 Vector<String> result; |
| 34 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { | 148 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { |
| 35 result.append(m_computedStyleDeclaration->item(i)); | 149 result.append(m_computedStyleDeclaration->item(i)); |
| 36 } | 150 } |
| 37 return result; | 151 return result; |
| 38 } | 152 } |
| 39 | 153 |
| 40 } // namespace blink | 154 } // namespace blink |
| OLD | NEW |