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

Side by Side Diff: third_party/WebKit/Source/core/style/StyleVariableData.cpp

Issue 2366313006: CSS Properties and Values API: Support non-inherited custom properties (Closed)
Patch Set: use de morgan's law 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/style/StyleVariableData.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/style/StyleVariableData.h"
6
7 #include "core/style/DataEquivalency.h"
8
9 namespace blink {
10
11 bool StyleVariableData::operator==(const StyleVariableData& other) const
12 {
13 // It's technically possible for divergent roots to be value-equal,
14 // but unlikely. This equality operator is used for optimization purposes
15 // so it's OK to be occasionally wrong.
16 // TODO(shanestephens): Rename this to something that indicates it may not
17 // always return equality.
18 if (m_root != other.m_root)
19 return false;
20
21 if (m_data.size() != other.m_data.size())
22 return false;
23
24 for (const auto& iter : m_data) {
25 RefPtr<CSSVariableData> otherData = other.m_data.get(iter.key);
26 if (!dataEquivalent(iter.value, otherData))
27 return false;
28 }
29
30 return true;
31 }
32
33 StyleVariableData::StyleVariableData(StyleVariableData& other)
34 {
35 if (!other.m_root) {
36 m_root = &other;
37 } else {
38 m_data = other.m_data;
39 m_registeredData = other.m_registeredData;
40 m_root = other.m_root;
41 }
42 }
43
44 CSSVariableData* StyleVariableData::getVariable(const AtomicString& name) const
45 {
46 auto result = m_data.find(name);
47 if (result == m_data.end() && m_root)
48 return m_root->getVariable(name);
49 if (result == m_data.end())
50 return nullptr;
51 return result->value.get();
52 }
53
54 void StyleVariableData::setRegisteredInheritedProperty(const AtomicString& name, const CSSValue* parsedValue)
55 {
56 m_registeredData.set(name, const_cast<CSSValue*>(parsedValue));
57 }
58
59 void StyleVariableData::removeVariable(const AtomicString& name)
60 {
61 m_data.set(name, nullptr);
62 auto iterator = m_registeredData.find(name);
63 if (iterator != m_registeredData.end())
64 iterator->value = nullptr;
65 }
66
67 std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> StyleVariableDat a::getVariables() const
68 {
69 std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> result;
70 if (m_root) {
71 result.reset(new HashMap<AtomicString, RefPtr<CSSVariableData>>(m_root-> m_data));
72 for (auto it = m_data.begin(); it != m_data.end(); ++it)
73 result->set(it->key, it->value);
74 } else {
75 result.reset(new HashMap<AtomicString, RefPtr<CSSVariableData>>(m_data)) ;
76 }
77 return result;
78 }
79
80 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/style/StyleVariableData.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698