Index: third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp |
diff --git a/third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp b/third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp |
index acd16aa1152b366d8b876098739ed4aaeaa3d118..8d3fe3587e345deb4ddb47d1be342b273f541635 100644 |
--- a/third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp |
+++ b/third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp |
@@ -6,6 +6,7 @@ |
#include "core/css/CSSComputedStyleDeclaration.h" |
#include "core/css/ComputedStyleCSSValueMapping.h" |
+#include "core/css/PropertyRegistry.h" |
alancutter (OOO until 2018)
2017/04/05 04:54:09
I don't think this include is required.
|
#include "core/css/cssom/CSSCalcLength.h" |
#include "core/css/cssom/CSSKeywordValue.h" |
#include "core/css/cssom/CSSNumberValue.h" |
@@ -18,36 +19,11 @@ |
namespace blink { |
-namespace { |
- |
-CSSStyleValue* styleValueForLength(const Length& length) { |
- if (length.isAuto()) { |
- return CSSKeywordValue::create("auto"); |
- } |
- if (length.isFixed()) { |
- return CSSSimpleLength::create(length.pixels(), |
- CSSPrimitiveValue::UnitType::Pixels); |
- } |
- if (length.isPercent()) { |
- return CSSSimpleLength::create(length.percent(), |
- CSSPrimitiveValue::UnitType::Percentage); |
- } |
- if (length.isCalculated()) { |
- return CSSCalcLength::fromLength(length); |
- } |
- NOTREACHED(); |
- return nullptr; |
-} |
- |
-} // namespace |
- |
-Node* ComputedStylePropertyMap::node() const { |
- if (!m_node) { |
+Node* ComputedStylePropertyMap::styledNode() const { |
+ if (!m_node) |
return nullptr; |
- } |
- if (!m_pseudoId) { |
+ if (!m_pseudoId) |
return m_node; |
- } |
if (m_node->isElementNode()) { |
// Seems to only support before, after, backdrop, first-letter. See |
// PseudoElementData::pseudoElement. |
@@ -59,110 +35,52 @@ Node* ComputedStylePropertyMap::node() const { |
return nullptr; |
} |
-// ComputedStylePropertyMap::getAllInternal/get should return computed styles |
-// (as opposed to resolved styles a la getComputedStyle()). |
-// |
-// Property values are read from an up-to-date ComputedStyle and converted into |
-// CSSStyleValues. This has not been implemented for all properties yet. |
-// Unsupported properties fall back to using resolved styles & converting them |
-// to CSSStyleValues via StyleValueFactory. For some types of values, such as |
-// images, the difference between the two is minor. |
-CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( |
- CSSPropertyID propertyID) { |
- CSSStyleValueVector styleValueVector; |
- |
- Node* node = this->node(); |
- if (!node || !node->inActiveDocument()) { |
- return styleValueVector; |
- } |
+const ComputedStyle* ComputedStylePropertyMap::updateStyle() const { |
+ Node* node = styledNode(); |
+ if (!node || !node->inActiveDocument()) |
+ return nullptr; |
// Update style before getting the value for the property |
+ // This could cause the node to be blown away. |
alancutter (OOO until 2018)
2017/04/05 04:54:09
Add test case for this. (Set display to none).
|
node->document().updateStyleAndLayoutTreeForNode(node); |
- node = this->node(); |
- if (!node) { |
- return styleValueVector; |
- } |
- // I have copied this from |
- // CSSComputedStyleDeclaration::computeComputedStyle(). I don't know if there |
- // is any use in passing m_pseudoId if node is not already a PseudoElement, |
- // but passing pseudo_Id when it IS already a PseudoElement leads to disaster. |
+ node = styledNode(); |
+ if (!node) |
+ return nullptr; |
+ // This is copied from CSSComputedStyleDeclaration::computeComputedStyle(). |
+ // PseudoIdNone must be used if node() is a PseudoElement. |
const ComputedStyle* style = node->ensureComputedStyle( |
node->isPseudoElement() ? PseudoIdNone : m_pseudoId); |
- node = this->node(); |
- if (!node || !node->inActiveDocument() || !style) { |
- return styleValueVector; |
- } |
- |
- CSSStyleValue* styleValue = nullptr; |
- |
- switch (propertyID) { |
- // TODO(rjwright): Generate this code. |
- case CSSPropertyLeft: |
- styleValue = styleValueForLength(style->left()); |
- break; |
- case CSSPropertyRight: |
- styleValue = styleValueForLength(style->right()); |
- break; |
- case CSSPropertyTop: |
- styleValue = styleValueForLength(style->top()); |
- break; |
- case CSSPropertyBottom: |
- styleValue = styleValueForLength(style->bottom()); |
- break; |
- case CSSPropertyHeight: |
- styleValue = styleValueForLength(style->height()); |
- break; |
- case CSSPropertyWidth: |
- styleValue = styleValueForLength(style->width()); |
- break; |
- case CSSPropertyLineHeight: { |
- // LineHeight is represented as a Length in ComputedStyle, even though it |
- // can be a number or the "normal" keyword. "normal" is encoded as a |
- // negative percent, and numbers (which must be positive) are encoded as |
- // percents. |
- Length lineHeight = style->lineHeight(); |
- if (lineHeight.isNegative()) { |
- styleValue = CSSKeywordValue::create("normal"); |
- break; |
- } |
- if (lineHeight.isPercent()) { |
- styleValue = CSSNumberValue::create(lineHeight.percent()); |
- break; |
- } |
- if (lineHeight.isFixed()) { |
- styleValue = CSSSimpleLength::create( |
- lineHeight.pixels(), CSSPrimitiveValue::UnitType::Pixels); |
- break; |
- } |
- NOTREACHED(); |
- break; |
- } |
- default: |
- // For properties not yet handled above, fall back to using resolved |
- // style. |
- const CSSValue* value = ComputedStyleCSSValueMapping::get( |
- propertyID, *style, nullptr, node, false); |
- if (value) { |
- return StyleValueFactory::cssValueToStyleValueVector(propertyID, |
- *value); |
- } |
- break; |
- } |
+ node = styledNode(); |
+ if (!node || !node->inActiveDocument() || !style) |
+ return nullptr; |
+ return style; |
+} |
- if (styleValue) { |
- styleValueVector.push_back(styleValue); |
- } |
- return styleValueVector; |
+CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( |
+ CSSPropertyID propertyID) { |
+ CSSStyleValueVector styleValueVector; |
+ const ComputedStyle* style = updateStyle(); |
+ if (!style) |
+ return CSSStyleValueVector(); |
+ const CSSValue* cssValue = ComputedStyleCSSValueMapping::get( |
+ propertyID, *style, nullptr /* layoutObject */); |
+ if (!cssValue) |
+ return CSSStyleValueVector(); |
+ return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); |
} |
CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( |
- AtomicString customPropertyName) { |
- const CSSValue* cssValue = |
- m_computedStyleDeclaration->getPropertyCSSValue(customPropertyName); |
+ AtomicString customPropertyName, |
+ ExceptionState& exceptionState) { |
meade_UTC10
2017/04/06 03:47:32
You're not using the exception state - no need to
|
+ const ComputedStyle* style = updateStyle(); |
+ if (!style) |
+ return CSSStyleValueVector(); |
+ // FIXME(rjwright): propertyRegistry is nullptr in stable Chrome. |
alancutter (OOO until 2018)
2017/04/05 04:54:08
I don't think anything will change here, no need f
|
+ const CSSValue* cssValue = ComputedStyleCSSValueMapping::get( |
+ customPropertyName, *style, m_node->document().propertyRegistry()); |
if (!cssValue) |
return CSSStyleValueVector(); |
- return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, |
- *cssValue); |
+ return StyleValueFactory::cssValueToStyleValueVector(*cssValue); |
} |
Vector<String> ComputedStylePropertyMap::getProperties() { |