Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Unified Diff: third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp

Issue 2726733004: [Experimental] Implement some part of custom properties in style maps (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 45c87e95a3e5830d0a2520fd336ad068df4bda63..a8399fb44d01cd5e6c898a9552a0ee076897597d 100644
--- a/third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp
+++ b/third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp
@@ -20,34 +20,24 @@ namespace blink {
namespace {
-CSSStyleValue* styleValueForLength(const Length& length) {
- if (length.isAuto()) {
- return CSSKeywordValue::create("auto");
+String styleValueVectorToString(CSSPropertyID propertyId,
+ const CSSStyleValueVector& vector) {
+ StringBuilder builder;
+ for (unsigned i = 1; i < vector.size(); i++) {
+ // TODO(meade): separator
+ builder.append(',');
+ builder.append(vector[i]->cssText());
meade_UTC10 2017/03/02 00:13:51 Just landed the CL to do this properly: https://co
}
- 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;
+ return builder.toString();
+}
}
-
-} // namespace
Node* ComputedStylePropertyMap::node() const {
- if (!m_node) {
+ 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,116 +49,58 @@ 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;
+ if (!node() || !node()->inActiveDocument())
+ return CSSStyleValueVector();
- Node* node = this->node();
- if (!node || !node->inActiveDocument()) {
- return styleValueVector;
- }
+ // Update style before getting the value for the property.
+ // This could cause the node to be blown away.
+ node()->document().updateStyleAndLayoutTreeForNode(node());
+ if (!node())
+ return CSSStyleValueVector();
- // Update style before getting the value for the property
- 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.
- const ComputedStyle* style = node->ensureComputedStyle(
- node->isPseudoElement() ? PseudoIdNone : m_pseudoId);
- node = this->node();
- if (!node || !node->inActiveDocument() || !style) {
- return styleValueVector;
- }
+ // 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);
- 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;
- }
+ // Passing null for the LayoutObject causes the mapping to return the
+ // computed, rather than the resolved style.
+ const CSSValue* cssValue = ComputedStyleCSSValueMapping::get(
+ propertyID, *style, nullptr /* layoutObject */, node());
- if (styleValue) {
- styleValueVector.push_back(styleValue);
- }
- return styleValueVector;
+ if (!cssValue)
+ return CSSStyleValueVector();
+
+ return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue);
}
CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(
- AtomicString customPropertyName) {
- const CSSValue* cssValue =
- m_computedStyleDeclaration->getPropertyCSSValue(customPropertyName);
+ String customPropertyName) {
meade_UTC10 2017/03/02 00:13:51 Don't worry about the changes of AtomicString -> S
+ // TODO(meade): Do need to update style?
+ const ComputedStyle* style = node()->ensureComputedStyle(
+ node()->isPseudoElement() ? PseudoIdNone : m_pseudoId);
+ // TODO(meade) Let's not intern a bunch of user crap in here and waste memory
+ const CSSValue* cssValue = ComputedStyleCSSValueMapping::get(
+ AtomicString(customPropertyName), *style,
+ m_node->document().propertyRegistry());
if (!cssValue)
return CSSStyleValueVector();
- return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid,
- *cssValue);
+ return StyleValueFactory::cssValueToStyleValueVector(*cssValue);
}
Vector<String> ComputedStylePropertyMap::getProperties() {
Vector<String> result;
- for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) {
- result.push_back(m_computedStyleDeclaration->item(i));
+ const Vector<CSSPropertyID>& properties =
+ CSSComputedStyleDeclaration::computableProperties();
+ for (const CSSPropertyID propertyID : properties) {
+ CSSStyleValueVector vector = getAllInternal(propertyID);
+ if (vector.size() == 1) {
+ result.push_back(vector[0]->cssText());
+ } else {
+ result.push_back(styleValueVectorToString(propertyID, vector));
+ }
}
return result;
}

Powered by Google App Engine
This is Rietveld 408576698