| 1 | /* |
| 2 | * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
| 3 | * Copyright (C) 2004, 2005, 2006 Apple Inc. |
| 4 | * Copyright (C) 2013 Intel Corporation. All rights reserved. |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this library; see the file COPYING.LIB. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | |
| 22 | #pragma once |
| 23 | |
| 24 | #include "CSSPropertyNames.h" |
| 25 | #include "CSSValue.h" |
| 26 | #include "WritingMode.h" |
| 27 | #include <wtf/RefPtr.h> |
| 28 | |
| 29 | namespace WebCore { |
| 30 | |
| 31 | struct StylePropertyMetadata { |
| 32 | StylePropertyMetadata(CSSPropertyID propertyID, bool isSetFromShorthand, int indexInShorthandsVector, bool important, bool implicit, bool inherited) |
| 33 | : m_propertyID(propertyID) |
| 34 | , m_isSetFromShorthand(isSetFromShorthand) |
| 35 | , m_indexInShorthandsVector(indexInShorthandsVector) |
| 36 | , m_important(important) |
| 37 | , m_implicit(implicit) |
| 38 | , m_inherited(inherited) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | CSSPropertyID shorthandID() const; |
| 43 | |
| 44 | bool operator==(const StylePropertyMetadata& other) const |
| 45 | { |
| 46 | return m_propertyID == other.m_propertyID |
| 47 | && m_isSetFromShorthand == other.m_isSetFromShorthand |
| 48 | && m_indexInShorthandsVector == other.m_indexInShorthandsVector |
| 49 | && m_important == other.m_important |
| 50 | && m_implicit == other.m_implicit |
| 51 | && m_inherited == other.m_inherited; |
| 52 | } |
| 53 | |
| 54 | uint16_t m_propertyID : 10; |
| 55 | uint16_t m_isSetFromShorthand : 1; |
| 56 | uint16_t m_indexInShorthandsVector : 2; // If this property was set as part of an ambiguous shorthand, gives the index in the shorthands vector. |
| 57 | uint16_t m_important : 1; |
| 58 | uint16_t m_implicit : 1; // Whether or not the property was set implicitly as the result of a shorthand. |
| 59 | uint16_t m_inherited : 1; |
| 60 | }; |
| 61 | |
| 62 | class CSSProperty { |
| 63 | public: |
| 64 | CSSProperty(CSSPropertyID propertyID, RefPtr<CSSValue>&& value, bool important = false, bool isSetFromShorthand = false, int indexInShorthandsVector = 0, bool implicit = false) |
| 65 | : m_metadata(propertyID, isSetFromShorthand, indexInShorthandsVector, important, implicit, isInheritedProperty(propertyID)) |
| 66 | , m_value(WTFMove(value)) |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | CSSPropertyID id() const { return static_cast<CSSPropertyID>(m_metadata.m_propertyID); } |
| 71 | bool isSetFromShorthand() const { return m_metadata.m_isSetFromShorthand; }; |
| 72 | CSSPropertyID shorthandID() const { return m_metadata.shorthandID(); }; |
| 73 | bool isImportant() const { return m_metadata.m_important; } |
| 74 | |
| 75 | CSSValue* value() const { return m_value.get(); } |
| 76 | |
| 77 | void wrapValueInCommaSeparatedList(); |
| 78 | |
| 79 | static CSSPropertyID resolveDirectionAwareProperty(CSSPropertyID, TextDirection, WritingMode); |
| 80 | static bool isInheritedProperty(CSSPropertyID); |
| 81 | static Vector<String> aliasesForProperty(CSSPropertyID); |
| 82 | static bool isDirectionAwareProperty(CSSPropertyID); |
| 83 | static bool isDescriptorOnly(CSSPropertyID); |
| 84 | |
| 85 | const StylePropertyMetadata& metadata() const { return m_metadata; } |
| 86 | |
| 87 | bool operator==(const CSSProperty& other) const |
| 88 | { |
| 89 | if (!(m_metadata == other.m_metadata)) |
| 90 | return false; |
| 91 | |
| 92 | if (!m_value && !other.m_value) |
| 93 | return true; |
| 94 | |
| 95 | if (!m_value || !other.m_value) |
| 96 | return false; |
| 97 | |
| 98 | return m_value->equals(*other.m_value); |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | StylePropertyMetadata m_metadata; |
| 103 | RefPtr<CSSValue> m_value; |
| 104 | }; |
| 105 | |
| 106 | typedef Vector<CSSProperty, 256> ParsedPropertyVector; |
| 107 | |
| 108 | } // namespace WebCore |
| 109 | |
| 110 | namespace WTF { |
| 111 | template <> struct VectorTraits<WebCore::CSSProperty> : VectorTraitsBase<false, WebCore::CSSProperty> { |
| 112 | static const bool canInitializeWithMemset = true; |
| 113 | static const bool canMoveWithMemcpy = true; |
| 114 | }; |
| 115 | } |
| 116 | |