OLD | NEW |
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" | 8 #include "core/css/ComputedStyleCSSValueMapping.h" |
9 #include "core/css/cssom/CSSCalcLength.h" | 9 #include "core/css/cssom/CSSCalcLength.h" |
10 #include "core/css/cssom/CSSKeywordValue.h" | 10 #include "core/css/cssom/CSSKeywordValue.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 | 43 |
44 Node* ComputedStylePropertyMap::GetNode() const { | 44 Node* ComputedStylePropertyMap::GetNode() const { |
45 if (!node_) { | 45 if (!node_) { |
46 return nullptr; | 46 return nullptr; |
47 } | 47 } |
48 if (!pseudo_id_) { | 48 if (!pseudo_id_) { |
49 return node_; | 49 return node_; |
50 } | 50 } |
51 if (node_->IsElementNode()) { | 51 if (node_->IsElementNode()) { |
52 // Seems to only support before, after, backdrop, first-letter. See | 52 // Seems to only support before, after, backdrop, first-letter. See |
53 // PseudoElementData::pseudoElement. | 53 // PseudoElementData::GetPseudoElement. |
54 if (PseudoElement* element = | 54 if (PseudoElement* element = |
55 (ToElement(node_))->GetPseudoElement(pseudo_id_)) { | 55 (ToElement(node_))->GetPseudoElement(pseudo_id_)) { |
56 return element; | 56 return element; |
57 } | 57 } |
58 } | 58 } |
59 return nullptr; | 59 return nullptr; |
60 } | 60 } |
61 | 61 |
62 // ComputedStylePropertyMap::getAllInternal/get should return computed styles | 62 // ComputedStylePropertyMap::GetAllInternal/Get should return computed styles |
63 // (as opposed to resolved styles a la getComputedStyle()). | 63 // (as opposed to resolved styles a la getComputedStyle()). |
64 // | 64 // |
65 // Property values are read from an up-to-date ComputedStyle and converted into | 65 // Property values are read from an up-to-date ComputedStyle and converted into |
66 // CSSStyleValues. This has not been implemented for all properties yet. | 66 // CSSStyleValues. This has not been implemented for all properties yet. |
67 // Unsupported properties fall back to using resolved styles & converting them | 67 // Unsupported properties fall back to using resolved styles & converting them |
68 // to CSSStyleValues via StyleValueFactory. For some types of values, such as | 68 // to CSSStyleValues via StyleValueFactory. For some types of values, such as |
69 // images, the difference between the two is minor. | 69 // images, the difference between the two is minor. |
70 CSSStyleValueVector ComputedStylePropertyMap::GetAllInternal( | 70 CSSStyleValueVector ComputedStylePropertyMap::GetAllInternal( |
71 CSSPropertyID property_id) { | 71 CSSPropertyID property_id) { |
72 CSSStyleValueVector style_value_vector; | 72 CSSStyleValueVector style_value_vector; |
73 | 73 |
74 Node* node = this->GetNode(); | 74 Node* node = this->GetNode(); |
75 if (!node || !node->InActiveDocument()) { | 75 if (!node || !node->InActiveDocument()) { |
76 return style_value_vector; | 76 return style_value_vector; |
77 } | 77 } |
78 | 78 |
79 // Update style before getting the value for the property | 79 // Update style before getting the value for the property |
80 node->GetDocument().UpdateStyleAndLayoutTreeForNode(node); | 80 node->GetDocument().UpdateStyleAndLayoutTreeForNode(node); |
81 node = this->GetNode(); | 81 node = this->GetNode(); |
82 if (!node) { | 82 if (!node) { |
83 return style_value_vector; | 83 return style_value_vector; |
84 } | 84 } |
85 // I have copied this from | 85 // I have copied this from |
86 // CSSComputedStyleDeclaration::computeComputedStyle(). I don't know if there | 86 // CSSComputedStyleDeclaration::ComputeComputedStyle(). I don't know if there |
87 // is any use in passing m_pseudoId if node is not already a PseudoElement, | 87 // is any use in passing pseudo_id_ if node is not already a PseudoElement, |
88 // but passing pseudo_Id when it IS already a PseudoElement leads to disaster. | 88 // but passing pseudo_id_ when it IS already a PseudoElement leads to |
| 89 // disaster. |
89 const ComputedStyle* style = node->EnsureComputedStyle( | 90 const ComputedStyle* style = node->EnsureComputedStyle( |
90 node->IsPseudoElement() ? kPseudoIdNone : pseudo_id_); | 91 node->IsPseudoElement() ? kPseudoIdNone : pseudo_id_); |
91 node = this->GetNode(); | 92 node = this->GetNode(); |
92 if (!node || !node->InActiveDocument() || !style) { | 93 if (!node || !node->InActiveDocument() || !style) { |
93 return style_value_vector; | 94 return style_value_vector; |
94 } | 95 } |
95 | 96 |
96 CSSStyleValue* style_value = nullptr; | 97 CSSStyleValue* style_value = nullptr; |
97 | 98 |
98 switch (property_id) { | 99 switch (property_id) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 Vector<String> ComputedStylePropertyMap::getProperties() { | 169 Vector<String> ComputedStylePropertyMap::getProperties() { |
169 Vector<String> result; | 170 Vector<String> result; |
170 for (CSSPropertyID property_id : | 171 for (CSSPropertyID property_id : |
171 CSSComputedStyleDeclaration::ComputableProperties()) { | 172 CSSComputedStyleDeclaration::ComputableProperties()) { |
172 result.push_back(getPropertyNameString(property_id)); | 173 result.push_back(getPropertyNameString(property_id)); |
173 } | 174 } |
174 return result; | 175 return result; |
175 } | 176 } |
176 | 177 |
177 } // namespace blink | 178 } // namespace blink |
OLD | NEW |