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

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

Issue 2312293003: [CSSTypedOM] Computed StylePropertyMap use ComputedStyle for Lengths (Closed)
Patch Set: rebase Created 4 years, 2 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 10119b93c457f564d4f171a0ca185c30e8d66811..85b91cf06c4faa3fa1978f3ac49952d446f307f6 100644
--- a/third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp
+++ b/third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp
@@ -5,17 +5,88 @@
#include "core/css/cssom/ComputedStylePropertyMap.h"
#include "core/css/CSSComputedStyleDeclaration.h"
+#include "core/css/cssom/CSSCalcLength.h"
+#include "core/css/cssom/CSSKeywordValue.h"
+#include "core/css/cssom/CSSSimpleLength.h"
#include "core/css/cssom/StyleValueFactory.h"
+#include "core/dom/PseudoElement.h"
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->isElementNode()) {
+ if (PseudoElement* element =
+ toElement(m_node)->pseudoElement(m_node->getPseudoId()))
+ return element;
+ }
+ return m_node;
+}
+
CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(
CSSPropertyID propertyID) {
- const CSSValue* cssValue =
- m_computedStyleDeclaration->getPropertyCSSValueInternal(propertyID);
- if (!cssValue)
- return CSSStyleValueVector();
- return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue);
+ Node* node = this->node();
+ Document& document = node->document();
+ // TODO(rjwright): This style recalc is copied from
+ // CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID), which also
+ // does a "force
+ // full layout" step. Need to work out if I need to do that too.
+ document.updateStyleAndLayoutTreeForNode(node);
+ // TODO(rjwright): Do I need this?
+ node = this->node();
+ const ComputedStyle* style = node->ensureComputedStyle(node->getPseudoId());
+
+ CSSStyleValueVector styleValueVector;
+ CSSStyleValue* styleValue = nullptr;
+ switch (propertyID) {
+ 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;
+ default:
+ break;
+ }
+
+ if (styleValue) {
+ styleValueVector.append(styleValue);
+ }
+ return styleValueVector;
}
CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(

Powered by Google App Engine
This is Rietveld 408576698