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" | 8 #include "core/css/ComputedStyleCSSValueMapping.h" |
| 9 #include "core/css/PropertyRegistry.h" | |
| 9 #include "core/css/cssom/CSSCalcLength.h" | 10 #include "core/css/cssom/CSSCalcLength.h" |
| 10 #include "core/css/cssom/CSSKeywordValue.h" | 11 #include "core/css/cssom/CSSKeywordValue.h" |
| 11 #include "core/css/cssom/CSSNumberValue.h" | 12 #include "core/css/cssom/CSSNumberValue.h" |
| 12 #include "core/css/cssom/CSSSimpleLength.h" | 13 #include "core/css/cssom/CSSSimpleLength.h" |
| 13 #include "core/css/cssom/CSSUnsupportedStyleValue.h" | 14 #include "core/css/cssom/CSSUnsupportedStyleValue.h" |
| 14 #include "core/css/cssom/StyleValueFactory.h" | 15 #include "core/css/cssom/StyleValueFactory.h" |
| 15 #include "core/css/resolver/StyleResolver.h" | 16 #include "core/css/resolver/StyleResolver.h" |
| 16 #include "core/dom/PseudoElement.h" | 17 #include "core/dom/PseudoElement.h" |
| 17 #include "core/dom/StyleEngine.h" | 18 #include "core/dom/StyleEngine.h" |
| 18 | 19 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 // Seems to only support before, after, backdrop, first-letter. See | 53 // Seems to only support before, after, backdrop, first-letter. See |
| 53 // PseudoElementData::pseudoElement. | 54 // PseudoElementData::pseudoElement. |
| 54 if (PseudoElement* element = | 55 if (PseudoElement* element = |
| 55 (toElement(m_node))->pseudoElement(m_pseudoId)) { | 56 (toElement(m_node))->pseudoElement(m_pseudoId)) { |
| 56 return element; | 57 return element; |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 return nullptr; | 60 return nullptr; |
| 60 } | 61 } |
| 61 | 62 |
| 62 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( | 63 const ComputedStyle* ComputedStylePropertyMap::updateStyle() const { |
| 63 CSSPropertyID propertyID) { | |
| 64 CSSStyleValueVector styleValueVector; | |
| 65 | |
| 66 Node* node = this->node(); | 64 Node* node = this->node(); |
| 67 if (!node || !node->inActiveDocument()) { | 65 if (!node || !node->inActiveDocument()) { |
| 68 return styleValueVector; | 66 return nullptr; |
| 69 } | 67 } |
| 70 node->document().updateStyleAndLayoutTreeForNode(node); | 68 node->document().updateStyleAndLayoutTreeForNode(node); |
| 71 node = this->node(); | 69 node = this->node(); |
| 72 if (!node) { | 70 if (!node) { |
| 73 return styleValueVector; | 71 return nullptr; |
| 74 } | 72 } |
| 75 // I have copied this from | 73 // I have copied this from |
| 76 // CSSComputedStyleDeclaration::computeComputedStyle(). I don't know if | 74 // CSSComputedStyleDeclaration::computeComputedStyle(). I don't know if |
| 77 // there is any use in passing m_pseudoId if node is not already a | 75 // there is any use in passing m_pseudoId if node is not already a |
| 78 // PseudoElement, but passing | 76 // PseudoElement, but passing |
| 79 // pseudo_Id when it IS already a PseudoElement leads to disaster. | 77 // pseudo_Id when it IS already a PseudoElement leads to disaster. |
| 80 const ComputedStyle* style = node->ensureComputedStyle( | 78 const ComputedStyle* style = node->ensureComputedStyle( |
| 81 node->isPseudoElement() ? PseudoIdNone : m_pseudoId); | 79 node->isPseudoElement() ? PseudoIdNone : m_pseudoId); |
| 82 node = this->node(); | 80 node = this->node(); |
| 83 if (!node || !node->inActiveDocument() || !style) { | 81 if (!node || !node->inActiveDocument() || !style) { |
| 82 return nullptr; | |
| 83 } | |
| 84 return style; | |
| 85 } | |
| 86 | |
| 87 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( | |
| 88 CSSPropertyID propertyID) { | |
| 89 CSSStyleValueVector styleValueVector; | |
| 90 const ComputedStyle* style = this->updateStyle(); | |
|
alancutter (OOO until 2018)
2017/02/24 05:57:21
No need for "this->" where it's not ambiguous. Sty
| |
| 91 if (!style) | |
| 84 return styleValueVector; | 92 return styleValueVector; |
| 85 } | |
| 86 | 93 |
| 87 CSSStyleValue* styleValue = nullptr; | 94 CSSStyleValue* styleValue = nullptr; |
| 88 | |
| 89 switch (propertyID) { | 95 switch (propertyID) { |
| 90 // TODO(rjwright): Generate this code. | 96 // TODO(rjwright): Generate this code. |
| 91 case CSSPropertyLeft: | 97 case CSSPropertyLeft: |
| 92 styleValue = styleValueForLength(style->left()); | 98 styleValue = styleValueForLength(style->left()); |
| 93 break; | 99 break; |
| 94 case CSSPropertyRight: | 100 case CSSPropertyRight: |
| 95 styleValue = styleValueForLength(style->right()); | 101 styleValue = styleValueForLength(style->right()); |
| 96 break; | 102 break; |
| 97 case CSSPropertyTop: | 103 case CSSPropertyTop: |
| 98 styleValue = styleValueForLength(style->top()); | 104 styleValue = styleValueForLength(style->top()); |
| 99 break; | 105 break; |
| 100 case CSSPropertyBottom: | 106 case CSSPropertyBottom: |
| 101 styleValue = styleValueForLength(style->bottom()); | 107 styleValue = styleValueForLength(style->bottom()); |
| 102 break; | 108 break; |
| 103 case CSSPropertyHeight: | 109 case CSSPropertyHeight: |
| 104 styleValue = styleValueForLength(style->height()); | 110 styleValue = styleValueForLength(style->height()); |
| 105 break; | 111 break; |
| 106 case CSSPropertyWidth: | 112 case CSSPropertyWidth: |
| 107 styleValue = styleValueForLength(style->width()); | 113 styleValue = styleValueForLength(style->width()); |
| 108 break; | 114 break; |
|
alancutter (OOO until 2018)
2017/02/24 05:57:21
FYI there's a LengthPropertyFunctions class with a
| |
| 109 case CSSPropertyLineHeight: { | 115 case CSSPropertyLineHeight: { |
| 110 // LineHeight is represented as a Length in ComputedStyle, even though it | 116 // LineHeight is represented as a Length in ComputedStyle, even though it |
| 111 // can be a number or the "normal" keyword. "normal" is encoded as a | 117 // can be a number or the "normal" keyword. "normal" is encoded as a |
| 112 // negative percent, and numbers (which must be positive) are encoded as | 118 // negative percent, and numbers (which must be positive) are encoded as |
| 113 // percents. | 119 // percents. |
| 114 Length lineHeight = style->lineHeight(); | 120 Length lineHeight = style->lineHeight(); |
| 115 if (lineHeight.isNegative()) { | 121 if (lineHeight.isNegative()) { |
| 116 styleValue = CSSKeywordValue::create("normal"); | 122 styleValue = CSSKeywordValue::create("normal"); |
| 117 break; | 123 break; |
| 118 } | 124 } |
| 119 if (lineHeight.isPercent()) { | 125 if (lineHeight.isPercent()) { |
| 120 styleValue = CSSNumberValue::create(lineHeight.percent()); | 126 styleValue = CSSNumberValue::create(lineHeight.percent()); |
| 121 break; | 127 break; |
| 122 } | 128 } |
| 123 if (lineHeight.isFixed()) { | 129 if (lineHeight.isFixed()) { |
| 124 styleValue = CSSSimpleLength::create( | 130 styleValue = CSSSimpleLength::create( |
| 125 lineHeight.pixels(), CSSPrimitiveValue::UnitType::Pixels); | 131 lineHeight.pixels(), CSSPrimitiveValue::UnitType::Pixels); |
| 126 break; | 132 break; |
| 127 } | 133 } |
| 128 NOTREACHED(); | 134 NOTREACHED(); |
| 129 break; | 135 break; |
| 130 } | 136 } |
| 131 default: | 137 default: |
| 132 // TODO(rjwright): Add a flag argument to | |
| 133 // ComputedStyleCSSValyeMapping::get that makes it return | |
| 134 // just the raw value off the ComputedStyle, and not zoom adjusted or | |
| 135 // anything like that. | |
| 136 const CSSValue* value = ComputedStyleCSSValueMapping::get( | 138 const CSSValue* value = ComputedStyleCSSValueMapping::get( |
| 137 propertyID, *style, nullptr, node, false); | 139 propertyID, *style, nullptr, this->node(), false); |
|
alancutter (OOO until 2018)
2017/02/24 05:57:21
I don't think it's necessary to pass in the node h
| |
| 138 if (value) { | 140 if (value) { |
| 139 return StyleValueFactory::cssValueToStyleValueVector(propertyID, | 141 return StyleValueFactory::cssValueToStyleValueVector(propertyID, |
| 140 *value); | 142 *value); |
| 141 } | 143 } |
| 142 break; | 144 break; |
| 143 } | 145 } |
| 144 | 146 |
| 145 if (styleValue) { | 147 if (styleValue) { |
| 146 styleValueVector.push_back(styleValue); | 148 styleValueVector.push_back(styleValue); |
| 147 } | 149 } |
| 148 return styleValueVector; | 150 return styleValueVector; |
| 149 } | 151 } |
| 150 | 152 |
| 151 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( | 153 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( |
| 152 AtomicString customPropertyName) { | 154 AtomicString customPropertyName, |
| 153 const CSSValue* cssValue = | 155 ExceptionState& exceptionState) { |
| 154 m_computedStyleDeclaration->getPropertyCSSValue(customPropertyName); | 156 const ComputedStyle* style = this->updateStyle(); |
| 157 if (!style) | |
| 158 return CSSStyleValueVector(); | |
| 159 const PropertyRegistration* registration = | |
| 160 m_node->document().propertyRegistry()->registration(customPropertyName); | |
|
alancutter (OOO until 2018)
2017/02/24 05:57:21
The property registry is nullptr in stable Chrome.
| |
| 161 if (!registration) | |
| 162 return CSSStyleValueVector(); | |
| 163 const CSSValue* cssValue = style->getRegisteredVariable( | |
| 164 customPropertyName, registration->inherits()); | |
| 155 if (!cssValue) | 165 if (!cssValue) |
| 156 return CSSStyleValueVector(); | 166 return CSSStyleValueVector(); |
| 157 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, | 167 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, |
|
alancutter (OOO until 2018)
2017/02/24 05:57:21
No need to pass in CSSPropertyInvalid here, there'
| |
| 158 *cssValue); | 168 *cssValue); |
| 159 } | 169 } |
| 160 | 170 |
| 161 Vector<String> ComputedStylePropertyMap::getProperties() { | 171 Vector<String> ComputedStylePropertyMap::getProperties() { |
| 162 Vector<String> result; | 172 Vector<String> result; |
| 163 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { | 173 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { |
| 164 result.push_back(m_computedStyleDeclaration->item(i)); | 174 result.push_back(m_computedStyleDeclaration->item(i)); |
| 165 } | 175 } |
| 166 return result; | 176 return result; |
| 167 } | 177 } |
| 168 | 178 |
| 169 } // namespace blink | 179 } // namespace blink |
| OLD | NEW |