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

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

Issue 2695093007: [Typed CSSOM] Get computed values for custom properties
Patch Set: Fix unregistered props and registered but unset props 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..2453daa3bf748deda425f6de97c8adb1e3506470 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"
#include "core/css/cssom/CSSCalcLength.h"
#include "core/css/cssom/CSSKeywordValue.h"
#include "core/css/cssom/CSSNumberValue.h"
@@ -59,28 +60,17 @@ 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;
-
+const ComputedStyle* ComputedStylePropertyMap::updateStyle() const {
Node* node = this->node();
if (!node || !node->inActiveDocument()) {
- return styleValueVector;
+ return nullptr;
}
// Update style before getting the value for the property
node->document().updateStyleAndLayoutTreeForNode(node);
node = this->node();
if (!node) {
- return styleValueVector;
+ return nullptr;
}
// I have copied this from
// CSSComputedStyleDeclaration::computeComputedStyle(). I don't know if there
@@ -90,11 +80,27 @@ CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(
node->isPseudoElement() ? PseudoIdNone : m_pseudoId);
node = this->node();
if (!node || !node->inActiveDocument() || !style) {
- return styleValueVector;
+ return nullptr;
}
+ return style;
+}
- CSSStyleValue* styleValue = 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;
+ const ComputedStyle* style = this->updateStyle();
+ if (!style)
+ return styleValueVector;
+ CSSStyleValue* styleValue = nullptr;
switch (propertyID) {
// TODO(rjwright): Generate this code.
case CSSPropertyLeft:
@@ -141,7 +147,7 @@ CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(
// For properties not yet handled above, fall back to using resolved
// style.
const CSSValue* value = ComputedStyleCSSValueMapping::get(
- propertyID, *style, nullptr, node, false);
+ propertyID, *style, nullptr, this->node(), false);
if (value) {
return StyleValueFactory::cssValueToStyleValueVector(propertyID,
*value);
@@ -156,13 +162,18 @@ CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(
}
CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(
- AtomicString customPropertyName) {
- const CSSValue* cssValue =
- m_computedStyleDeclaration->getPropertyCSSValue(customPropertyName);
- if (!cssValue)
+ AtomicString customPropertyName,
+ ExceptionState& exceptionState) {
+ const ComputedStyle* style = this->updateStyle();
+ if (!style) {
+ return CSSStyleValueVector();
+ }
+ const CSSValue* value = ComputedStyleCSSValueMapping::get(
+ customPropertyName, *style, m_node->document().propertyRegistry());
+ if (!value) {
return CSSStyleValueVector();
- return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid,
- *cssValue);
+ }
+ return StyleValueFactory::cssValueToStyleValueVector(*value);
}
Vector<String> ComputedStylePropertyMap::getProperties() {

Powered by Google App Engine
This is Rietveld 408576698