OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/style/StyleVariableData.h" | 5 #include "core/style/StyleInheritedVariables.h" |
6 | 6 |
7 #include "core/style/DataEquivalency.h" | 7 #include "core/style/DataEquivalency.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 bool StyleVariableData::operator==(const StyleVariableData& other) const | 11 bool StyleInheritedVariables::operator==(const StyleInheritedVariables& other) c
onst |
12 { | 12 { |
13 // It's technically possible for divergent roots to be value-equal, | 13 // It's technically possible for divergent roots to be value-equal, |
14 // but unlikely. This equality operator is used for optimization purposes | 14 // but unlikely. This equality operator is used for optimization purposes |
15 // so it's OK to be occasionally wrong. | 15 // so it's OK to be occasionally wrong. |
16 // TODO(shanestephens): Rename this to something that indicates it may not | 16 // TODO(shanestephens): Rename this to something that indicates it may not |
17 // always return equality. | 17 // always return equality. |
18 if (m_root != other.m_root) | 18 if (m_root != other.m_root) |
19 return false; | 19 return false; |
20 | 20 |
21 if (m_data.size() != other.m_data.size()) | 21 if (m_data.size() != other.m_data.size()) |
22 return false; | 22 return false; |
23 | 23 |
24 for (const auto& iter : m_data) { | 24 for (const auto& iter : m_data) { |
25 RefPtr<CSSVariableData> otherData = other.m_data.get(iter.key); | 25 RefPtr<CSSVariableData> otherData = other.m_data.get(iter.key); |
26 if (!dataEquivalent(iter.value, otherData)) | 26 if (!dataEquivalent(iter.value, otherData)) |
27 return false; | 27 return false; |
28 } | 28 } |
29 | 29 |
30 return true; | 30 return true; |
31 } | 31 } |
32 | 32 |
33 StyleVariableData::StyleVariableData(StyleVariableData& other) | 33 StyleInheritedVariables::StyleInheritedVariables(StyleInheritedVariables& other) |
34 { | 34 { |
35 if (!other.m_root) { | 35 if (!other.m_root) { |
36 m_root = &other; | 36 m_root = &other; |
37 } else { | 37 } else { |
38 m_data = other.m_data; | 38 m_data = other.m_data; |
39 m_registeredData = other.m_registeredData; | 39 m_registeredData = other.m_registeredData; |
40 m_root = other.m_root; | 40 m_root = other.m_root; |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 CSSVariableData* StyleVariableData::getVariable(const AtomicString& name) const | 44 CSSVariableData* StyleInheritedVariables::getVariable(const AtomicString& name)
const |
45 { | 45 { |
46 auto result = m_data.find(name); | 46 auto result = m_data.find(name); |
47 if (result == m_data.end() && m_root) | 47 if (result == m_data.end() && m_root) |
48 return m_root->getVariable(name); | 48 return m_root->getVariable(name); |
49 if (result == m_data.end()) | 49 if (result == m_data.end()) |
50 return nullptr; | 50 return nullptr; |
51 return result->value.get(); | 51 return result->value.get(); |
52 } | 52 } |
53 | 53 |
54 void StyleVariableData::setRegisteredInheritedProperty(const AtomicString& name,
const CSSValue* parsedValue) | 54 void StyleInheritedVariables::setRegisteredVariable(const AtomicString& name, co
nst CSSValue* parsedValue) |
55 { | 55 { |
56 m_registeredData.set(name, const_cast<CSSValue*>(parsedValue)); | 56 m_registeredData.set(name, const_cast<CSSValue*>(parsedValue)); |
57 } | 57 } |
58 | 58 |
59 void StyleVariableData::removeVariable(const AtomicString& name) | 59 CSSValue* StyleInheritedVariables::registeredVariable(const AtomicString& name)
const |
| 60 { |
| 61 auto result = m_registeredData.find(name); |
| 62 if (result != m_registeredData.end()) |
| 63 return result->value.get(); |
| 64 if (m_root) |
| 65 return m_root->registeredVariable(name); |
| 66 return nullptr; |
| 67 } |
| 68 |
| 69 void StyleInheritedVariables::removeVariable(const AtomicString& name) |
60 { | 70 { |
61 m_data.set(name, nullptr); | 71 m_data.set(name, nullptr); |
62 auto iterator = m_registeredData.find(name); | 72 auto iterator = m_registeredData.find(name); |
63 if (iterator != m_registeredData.end()) | 73 if (iterator != m_registeredData.end()) |
64 iterator->value = nullptr; | 74 iterator->value = nullptr; |
65 } | 75 } |
66 | 76 |
67 std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> StyleVariableDat
a::getVariables() const | 77 std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> StyleInheritedVa
riables::getVariables() const |
68 { | 78 { |
69 std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> result; | 79 std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> result; |
70 if (m_root) { | 80 if (m_root) { |
71 result.reset(new HashMap<AtomicString, RefPtr<CSSVariableData>>(m_root->
m_data)); | 81 result.reset(new HashMap<AtomicString, RefPtr<CSSVariableData>>(m_root->
m_data)); |
72 for (auto it = m_data.begin(); it != m_data.end(); ++it) | 82 for (auto it = m_data.begin(); it != m_data.end(); ++it) |
73 result->set(it->key, it->value); | 83 result->set(it->key, it->value); |
74 } else { | 84 } else { |
75 result.reset(new HashMap<AtomicString, RefPtr<CSSVariableData>>(m_data))
; | 85 result.reset(new HashMap<AtomicString, RefPtr<CSSVariableData>>(m_data))
; |
76 } | 86 } |
77 return result; | 87 return result; |
78 } | 88 } |
79 | 89 |
80 } // namespace blink | 90 } // namespace blink |
OLD | NEW |