- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / CSSProperty.h
1 /*
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
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 #ifndef CSSProperty_h
22 #define CSSProperty_h
23
24 #include "CSSPropertyNames.h"
25 #include "RuntimeEnabledFeatures.h"
26 #include "core/css/CSSValue.h"
27 #include "platform/text/TextDirection.h"
28 #include "platform/text/WritingMode.h"
29 #include "wtf/PassRefPtr.h"
30 #include "wtf/RefPtr.h"
31
32 namespace WebCore {
33
34 struct StylePropertyMetadata {
35     StylePropertyMetadata(CSSPropertyID propertyID, bool isSetFromShorthand, int indexInShorthandsVector, bool important, bool implicit, bool inherited)
36         : m_propertyID(propertyID)
37         , m_isSetFromShorthand(isSetFromShorthand)
38         , m_indexInShorthandsVector(indexInShorthandsVector)
39         , m_important(important)
40         , m_implicit(implicit)
41         , m_inherited(inherited)
42     {
43     }
44
45     CSSPropertyID shorthandID() const;
46
47     uint16_t m_propertyID : 10;
48     uint16_t m_isSetFromShorthand : 1;
49     uint16_t m_indexInShorthandsVector : 2; // If this property was set as part of an ambiguous shorthand, gives the index in the shorthands vector.
50     uint16_t m_important : 1;
51     uint16_t m_implicit : 1; // Whether or not the property was set implicitly as the result of a shorthand.
52     uint16_t m_inherited : 1;
53 };
54
55 class CSSProperty {
56 public:
57     CSSProperty(CSSPropertyID propertyID, PassRefPtr<CSSValue> value, bool important = false, bool isSetFromShorthand = false, int indexInShorthandsVector = 0, bool implicit = false)
58         : m_metadata(propertyID, isSetFromShorthand, indexInShorthandsVector, important, implicit, isInheritedProperty(propertyID))
59         , m_value(value)
60     {
61     ASSERT((propertyID == CSSPropertyVariable) == (m_value && m_value->isVariableValue()));
62     }
63
64     // FIXME: Remove this.
65     CSSProperty(StylePropertyMetadata metadata, CSSValue* value)
66         : m_metadata(metadata)
67         , m_value(value)
68     {
69     ASSERT((metadata.m_propertyID == CSSPropertyVariable) == (m_value && m_value->isVariableValue()));
70     }
71
72     CSSPropertyID id() const { return static_cast<CSSPropertyID>(m_metadata.m_propertyID); }
73     bool isSetFromShorthand() const { return m_metadata.m_isSetFromShorthand; };
74     CSSPropertyID shorthandID() const { return m_metadata.shorthandID(); };
75     bool isImportant() const { return m_metadata.m_important; }
76
77     CSSValue* value() const { return m_value.get(); }
78
79     void wrapValueInCommaSeparatedList();
80
81     static CSSPropertyID resolveDirectionAwareProperty(CSSPropertyID, TextDirection, WritingMode);
82     static bool isInheritedProperty(CSSPropertyID);
83
84     const StylePropertyMetadata& metadata() const { return m_metadata; }
85
86 private:
87     StylePropertyMetadata m_metadata;
88     RefPtr<CSSValue> m_value;
89 };
90
91 inline CSSPropertyID prefixingVariantForPropertyId(CSSPropertyID propId)
92 {
93     if (!RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled() && (propId >= CSSPropertyWebkitAnimation && propId <= CSSPropertyAnimationTimingFunction))
94         return propId;
95
96     CSSPropertyID propertyId = CSSPropertyInvalid;
97     switch (propId) {
98     case CSSPropertyAnimation:
99         propertyId = CSSPropertyWebkitAnimation;
100         break;
101     case CSSPropertyAnimationDelay:
102         propertyId = CSSPropertyWebkitAnimationDelay;
103         break;
104     case CSSPropertyAnimationDirection:
105         propertyId = CSSPropertyWebkitAnimationDirection;
106         break;
107     case CSSPropertyAnimationDuration:
108         propertyId = CSSPropertyWebkitAnimationDuration;
109         break;
110     case CSSPropertyAnimationFillMode:
111         propertyId = CSSPropertyWebkitAnimationFillMode;
112         break;
113     case CSSPropertyAnimationIterationCount:
114         propertyId = CSSPropertyWebkitAnimationIterationCount;
115         break;
116     case CSSPropertyAnimationName:
117         propertyId = CSSPropertyWebkitAnimationName;
118         break;
119     case CSSPropertyAnimationPlayState:
120         propertyId = CSSPropertyWebkitAnimationPlayState;
121         break;
122     case CSSPropertyAnimationTimingFunction:
123         propertyId = CSSPropertyWebkitAnimationTimingFunction;
124         break;
125     case CSSPropertyTransitionDelay:
126         propertyId = CSSPropertyWebkitTransitionDelay;
127         break;
128     case CSSPropertyTransitionDuration:
129         propertyId = CSSPropertyWebkitTransitionDuration;
130         break;
131     case CSSPropertyTransitionProperty:
132         propertyId = CSSPropertyWebkitTransitionProperty;
133         break;
134     case CSSPropertyTransitionTimingFunction:
135         propertyId = CSSPropertyWebkitTransitionTimingFunction;
136         break;
137     case CSSPropertyTransition:
138         propertyId = CSSPropertyWebkitTransition;
139         break;
140     case CSSPropertyWebkitAnimation:
141         propertyId = CSSPropertyAnimation;
142         break;
143     case CSSPropertyWebkitAnimationDelay:
144         propertyId = CSSPropertyAnimationDelay;
145         break;
146     case CSSPropertyWebkitAnimationDirection:
147         propertyId = CSSPropertyAnimationDirection;
148         break;
149     case CSSPropertyWebkitAnimationDuration:
150         propertyId = CSSPropertyAnimationDuration;
151         break;
152     case CSSPropertyWebkitAnimationFillMode:
153         propertyId = CSSPropertyAnimationFillMode;
154         break;
155     case CSSPropertyWebkitAnimationIterationCount:
156         propertyId = CSSPropertyAnimationIterationCount;
157         break;
158     case CSSPropertyWebkitAnimationName:
159         propertyId = CSSPropertyAnimationName;
160         break;
161     case CSSPropertyWebkitAnimationPlayState:
162         propertyId = CSSPropertyAnimationPlayState;
163         break;
164     case CSSPropertyWebkitAnimationTimingFunction:
165         propertyId = CSSPropertyAnimationTimingFunction;
166         break;
167     case CSSPropertyWebkitTransitionDelay:
168         propertyId = CSSPropertyTransitionDelay;
169         break;
170     case CSSPropertyWebkitTransitionDuration:
171         propertyId = CSSPropertyTransitionDuration;
172         break;
173     case CSSPropertyWebkitTransitionProperty:
174         propertyId = CSSPropertyTransitionProperty;
175         break;
176     case CSSPropertyWebkitTransitionTimingFunction:
177         propertyId = CSSPropertyTransitionTimingFunction;
178         break;
179     case CSSPropertyWebkitTransition:
180         propertyId = CSSPropertyTransition;
181         break;
182     default:
183         propertyId = propId;
184         break;
185     }
186     ASSERT(propertyId != CSSPropertyInvalid);
187     return propertyId;
188 }
189
190 } // namespace WebCore
191
192 namespace WTF {
193 template <> struct VectorTraits<WebCore::CSSProperty> : VectorTraitsBase<false, WebCore::CSSProperty> {
194     static const bool canInitializeWithMemset = true;
195     static const bool canMoveWithMemcpy = true;
196 };
197 }
198
199 #endif // CSSProperty_h