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

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

Issue 2403423002: [CSSTypedOM] Computed StylePropertyMap use ComputedStyle for Lengths (Closed)
Patch Set: remove unnecessary change Created 4 years 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 unified diff | Download patch
OLDNEW
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"
9 #include "core/css/cssom/CSSCalcLength.h"
10 #include "core/css/cssom/CSSKeywordValue.h"
11 #include "core/css/cssom/CSSSimpleLength.h"
12 #include "core/css/cssom/CSSUnsupportedStyleValue.h"
8 #include "core/css/cssom/StyleValueFactory.h" 13 #include "core/css/cssom/StyleValueFactory.h"
14 #include "core/css/resolver/StyleResolver.h"
15 #include "core/dom/PseudoElement.h"
16 #include "core/dom/StyleEngine.h"
9 17
10 namespace blink { 18 namespace blink {
11 19
12 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( 20 namespace {
13 CSSPropertyID propertyID) { 21
14 const CSSValue* cssValue = 22 CSSStyleValue* styleValueForLength(const Length& length) {
15 m_computedStyleDeclaration->getPropertyCSSValueInternal(propertyID); 23 if (length.isAuto()) {
16 if (!cssValue) 24 return CSSKeywordValue::create("auto");
17 return CSSStyleValueVector(); 25 }
18 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); 26 if (length.isFixed()) {
27 return CSSSimpleLength::create(length.pixels(),
28 CSSPrimitiveValue::UnitType::Pixels);
29 }
30 if (length.isPercent()) {
31 return CSSSimpleLength::create(length.percent(),
32 CSSPrimitiveValue::UnitType::Percentage);
33 }
34 if (length.isCalculated()) {
35 return CSSCalcLength::fromLength(length);
36 }
37 NOTREACHED();
38 return nullptr;
39 }
40
41 } // namespace
42
43 Node* ComputedStylePropertyMap::node() const {
44 if (!m_node) {
45 return nullptr;
46 }
47 if (!m_pseudoId) {
48 return m_node;
49 }
50 if (m_node->isElementNode()) {
51 // Seems to only support before, after, backdrop, first-letter. See
52 // PseudoElementData::pseudoElement.
53 if (PseudoElement* element =
54 (toElement(m_node))->pseudoElement(m_pseudoId)) {
55 return element;
56 }
57 }
58 return nullptr;
19 } 59 }
20 60
21 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal( 61 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(
62 CSSPropertyID propertyID) {
63 CSSStyleValueVector styleValueVector;
64
65 Node* node = this->node();
66 if (!node) {
67 return styleValueVector;
68 }
69 if (!node->inActiveDocument()) {
70 return styleValueVector;
71 }
72 node->document().updateStyleAndLayoutTreeForNode(node);
73 node = this->node();
74 if (!node) {
75 return styleValueVector;
76 }
77 // I have copied this from
78 // CSSComputedStyleDeclaration::computeComputedStyle(). I don't know if
79 // there is any use in passing m_pseudoId if node is not already a
80 // PseudoElement, but passing
81 // pseudo_Id when it IS already a PseudoElement leads to disaster.
82 const ComputedStyle* style = node->ensureComputedStyle(
83 node->isPseudoElement() ? PseudoIdNone : m_pseudoId);
84 node = this->node();
85 if (!node) {
86 return styleValueVector;
87 }
88 if (!node->inActiveDocument()) {
89 return styleValueVector;
90 }
91
92 CSSStyleValue* styleValue = nullptr;
93
94 if (!style)
95 return styleValueVector;
96
97 switch (propertyID) {
meade_UTC10 2016/12/08 23:22:15 // TODO(rjwright): Generate this code?
meade_UTC10 2017/01/05 03:43:45 Sorry, I meant just to add a TODO comment...
98 case CSSPropertyLeft:
99 styleValue = styleValueForLength(style->left());
100 break;
101 case CSSPropertyRight:
102 styleValue = styleValueForLength(style->right());
103 break;
104 case CSSPropertyTop:
105 styleValue = styleValueForLength(style->top());
106 break;
107 case CSSPropertyBottom:
108 styleValue = styleValueForLength(style->bottom());
109 break;
110 case CSSPropertyHeight:
111 styleValue = styleValueForLength(style->height());
112 break;
113 case CSSPropertyWidth:
114 styleValue = styleValueForLength(style->width());
115 break;
116 default:
117 // TODO(rjwright): Add a flag argument to
118 // ComputedStyleCSSValyeMapping::get that makes it return
119 // just the raw value off the ComputedStyle, and not zoom adjusted or
120 // anything like that.
121 const CSSValue* value = ComputedStyleCSSValueMapping::get(
122 propertyID, *style, nullptr, node, false);
123 if (value) {
124 styleValue = CSSUnsupportedStyleValue::create(value->cssText());
125 }
126 break;
127 }
128
129 if (styleValue) {
130 styleValueVector.append(styleValue);
131 }
132 return styleValueVector;
133 }
134
135 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(
22 AtomicString customPropertyName) { 136 AtomicString customPropertyName) {
23 const CSSValue* cssValue = 137 const CSSValue* cssValue =
24 m_computedStyleDeclaration->getPropertyCSSValueInternal( 138 m_computedStyleDeclaration->getPropertyCSSValueInternal(
25 customPropertyName); 139 customPropertyName);
26 if (!cssValue) 140 if (!cssValue)
27 return CSSStyleValueVector(); 141 return CSSStyleValueVector();
28 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, 142 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid,
29 *cssValue); 143 *cssValue);
30 } 144 }
31 145
32 Vector<String> ComputedStylePropertyMap::getProperties() { 146 Vector<String> ComputedStylePropertyMap::getProperties() {
33 Vector<String> result; 147 Vector<String> result;
34 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { 148 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) {
35 result.append(m_computedStyleDeclaration->item(i)); 149 result.append(m_computedStyleDeclaration->item(i));
36 } 150 }
37 return result; 151 return result;
38 } 152 }
39 153
40 } // namespace blink 154 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698