| 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 #ifndef StyleVariableData_h | 5 #ifndef StyleVariableData_h |
| 6 #define StyleVariableData_h | 6 #define StyleVariableData_h |
| 7 | 7 |
| 8 #include "core/css/CSSVariableData.h" | 8 #include "core/css/CSSVariableData.h" |
| 9 #include "wtf/Forward.h" | 9 #include "wtf/Forward.h" |
| 10 #include "wtf/HashMap.h" | 10 #include "wtf/HashMap.h" |
| 11 #include "wtf/RefCounted.h" | 11 #include "wtf/RefCounted.h" |
| 12 #include "wtf/text/AtomicStringHash.h" | 12 #include "wtf/text/AtomicStringHash.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 class StyleVariableData : public RefCounted<StyleVariableData> { | 16 class StyleVariableData : public RefCounted<StyleVariableData> { |
| 17 public: | 17 public: |
| 18 static PassRefPtr<StyleVariableData> create() { return adoptRef(new StyleVar
iableData()); } | 18 static PassRefPtr<StyleVariableData> create() { return adoptRef(new StyleVar
iableData()); } |
| 19 PassRefPtr<StyleVariableData> copy() const { return adoptRef(new StyleVariab
leData(*this)); } | 19 |
| 20 PassRefPtr<StyleVariableData> copy() { return adoptRef(new StyleVariableData
(*this)); } |
| 20 | 21 |
| 21 bool operator==(const StyleVariableData& other) const; | 22 bool operator==(const StyleVariableData& other) const; |
| 22 bool operator!=(const StyleVariableData& other) const { return !(*this == ot
her); } | 23 bool operator!=(const StyleVariableData& other) const { return !(*this == ot
her); } |
| 23 | 24 |
| 24 void setVariable(const AtomicString& name, PassRefPtr<CSSVariableData> value
) { m_data.set(name, value); } | 25 void setVariable(const AtomicString& name, PassRefPtr<CSSVariableData> value
) { m_data.set(name, value); } |
| 25 CSSVariableData* getVariable(const AtomicString& name) const { return m_data
.get(name); } | 26 CSSVariableData* getVariable(const AtomicString& name) const; |
| 26 void removeVariable(const AtomicString& name) { return m_data.remove(name);
} | 27 void removeVariable(const AtomicString& name) { return setVariable(name, nul
lptr); } |
| 27 | 28 |
| 28 // This map will contain null pointers if variables are invalid due to | 29 // This map will contain null pointers if variables are invalid due to |
| 29 // cycles or referencing invalid variables without using a fallback. | 30 // cycles or referencing invalid variables without using a fallback. |
| 30 const HashMap<AtomicString, RefPtr<CSSVariableData>>* getVariables() const {
return &m_data; } | 31 // Note that this method is slow as a new map is constructed. |
| 32 std::unique_ptr<HashMap<AtomicString, RefPtr<CSSVariableData>>> getVariables
() const; |
| 31 private: | 33 private: |
| 32 StyleVariableData() = default; | 34 StyleVariableData() |
| 33 StyleVariableData(const StyleVariableData& other) : RefCounted<StyleVariable
Data>(), m_data(other.m_data) { } | 35 : m_root(nullptr) |
| 36 { } |
| 37 StyleVariableData(StyleVariableData& other); |
| 34 | 38 |
| 35 friend class CSSVariableResolver; | 39 friend class CSSVariableResolver; |
| 36 | 40 |
| 37 HashMap<AtomicString, RefPtr<CSSVariableData>> m_data; | 41 HashMap<AtomicString, RefPtr<CSSVariableData>> m_data; |
| 42 RefPtr<StyleVariableData> m_root; |
| 38 }; | 43 }; |
| 39 | 44 |
| 40 } // namespace blink | 45 } // namespace blink |
| 41 | 46 |
| 42 #endif // StyleVariableData_h | 47 #endif // StyleVariableData_h |
| OLD | NEW |