| 1 | /* |
| 2 | * Copyright (C) 2015 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2012 Google Inc. All rights reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include "CSSCustomPropertyValue.h" |
| 25 | #include "CSSVariableReferenceValue.h" |
| 26 | #include <wtf/Forward.h> |
| 27 | #include <wtf/HashMap.h> |
| 28 | #include <wtf/RefCounted.h> |
| 29 | #include <wtf/RefPtr.h> |
| 30 | #include <wtf/text/AtomicStringHash.h> |
| 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | class StyleCustomPropertyData : public RefCounted<StyleCustomPropertyData> { |
| 35 | public: |
| 36 | static Ref<StyleCustomPropertyData> create() { return adoptRef(*new StyleCustomPropertyData); } |
| 37 | Ref<StyleCustomPropertyData> copy() const { return adoptRef(*new StyleCustomPropertyData(*this)); } |
| 38 | |
| 39 | bool operator==(const StyleCustomPropertyData& other) const |
| 40 | { |
| 41 | if (values.size() != other.values.size()) |
| 42 | return false; |
| 43 | |
| 44 | for (auto& entry : values) { |
| 45 | auto otherEntry = other.values.find(entry.key); |
| 46 | if (otherEntry == other.values.end() || !entry.value->equals(*otherEntry->value)) |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | |
| 53 | bool operator!=(const StyleCustomPropertyData& other) const { return !(*this == other); } |
| 54 | |
| 55 | void setCustomPropertyValue(const AtomicString& name, Ref<CSSCustomPropertyValue>&& value) |
| 56 | { |
| 57 | values.set(name, WTFMove(value)); |
| 58 | } |
| 59 | |
| 60 | CustomPropertyValueMap values; |
| 61 | |
| 62 | private: |
| 63 | StyleCustomPropertyData() = default; |
| 64 | StyleCustomPropertyData(const StyleCustomPropertyData& other) |
| 65 | : RefCounted<StyleCustomPropertyData>() |
| 66 | , values(other.values) |
| 67 | { } |
| 68 | }; |
| 69 | |
| 70 | } // namespace WebCore |
| 71 | |