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 "CSSValue.h"
26#include "RenderStyleConstants.h"
27#include "TextDirection.h"
28#include "WritingMode.h"
29#include <wtf/PassRefPtr.h>
30#include <wtf/RefPtr.h>
31
32namespace WebCore {
33
34union StylePropertyMetadata {
35    StylePropertyMetadata(CSSPropertyID propertyID, CSSPropertyID shorthandID, bool important, bool implicit, bool inherited)
36        : m_propertyID(propertyID)
37        , m_shorthandID(shorthandID)
38        , m_important(important)
39        , m_implicit(implicit)
40        , m_inherited(inherited)
41    {
42    }
43
44    unsigned m_bits;
45    struct {
46        unsigned m_propertyID : 14;
47        unsigned m_shorthandID : 14; // If this property was set as part of a shorthand, gives the shorthand.
48        unsigned m_important : 1;
49        unsigned m_implicit : 1; // Whether or not the property was set implicitly as the result of a shorthand.
50        unsigned m_inherited : 1;
51    };
52};
53
54class CSSProperty {
55public:
56    CSSProperty(CSSPropertyID propertyID, PassRefPtr<CSSValue> value, bool important = false, CSSPropertyID shorthandID = CSSPropertyInvalid, bool implicit = false)
57        : m_metadata(propertyID, shorthandID, important, implicit, isInheritedProperty(propertyID))
58        , m_value(value)
59    {
60#if ENABLE(CSS_VARIABLES)
61    ASSERT((propertyID == CSSPropertyVariable) == (m_value && m_value->isVariableValue()));
62#endif
63    }
64
65    // FIXME: Remove this.
66    CSSProperty(StylePropertyMetadata metadata, CSSValue* value)
67        : m_metadata(metadata)
68        , m_value(value)
69    {
70#if ENABLE(CSS_VARIABLES)
71    ASSERT((metadata.m_propertyID == CSSPropertyVariable) == (m_value && m_value->isVariableValue()));
72#endif
73    }
74
75    CSSPropertyID id() const { return static_cast<CSSPropertyID>(m_metadata.m_propertyID); }
76    CSSPropertyID shorthandID() const { return static_cast<CSSPropertyID>(m_metadata.m_shorthandID); }
77    bool isImportant() const { return m_metadata.m_important; }
78
79    CSSValue* value() const { return m_value.get(); }
80
81    void wrapValueInCommaSeparatedList();
82
83    static CSSPropertyID resolveDirectionAwareProperty(CSSPropertyID, TextDirection, WritingMode);
84    static bool isInheritedProperty(CSSPropertyID);
85
86    StylePropertyMetadata metadata() const { return m_metadata; }
87
88private:
89    StylePropertyMetadata m_metadata;
90    RefPtr<CSSValue> m_value;
91};
92
93inline CSSPropertyID prefixingVariantForPropertyId(CSSPropertyID propId)
94{
95    CSSPropertyID propertyId = CSSPropertyInvalid;
96    switch (propId) {
97    case CSSPropertyTransitionDelay:
98        propertyId = CSSPropertyWebkitTransitionDelay;
99        break;
100    case CSSPropertyTransitionDuration:
101        propertyId = CSSPropertyWebkitTransitionDuration;
102        break;
103    case CSSPropertyTransitionProperty:
104        propertyId = CSSPropertyWebkitTransitionProperty;
105        break;
106    case CSSPropertyTransitionTimingFunction:
107        propertyId = CSSPropertyWebkitTransitionTimingFunction;
108        break;
109    case CSSPropertyTransition:
110        propertyId = CSSPropertyWebkitTransition;
111        break;
112    case CSSPropertyWebkitTransitionDelay:
113        propertyId = CSSPropertyTransitionDelay;
114        break;
115    case CSSPropertyWebkitTransitionDuration:
116        propertyId = CSSPropertyTransitionDuration;
117        break;
118    case CSSPropertyWebkitTransitionProperty:
119        propertyId = CSSPropertyTransitionProperty;
120        break;
121    case CSSPropertyWebkitTransitionTimingFunction:
122        propertyId = CSSPropertyTransitionTimingFunction;
123        break;
124    case CSSPropertyWebkitTransition:
125        propertyId = CSSPropertyTransition;
126        break;
127    default:
128        propertyId = propId;
129        break;
130    }
131    ASSERT(propertyId != CSSPropertyInvalid);
132    return propertyId;
133}
134
135} // namespace WebCore
136
137namespace WTF {
138template <> struct VectorTraits<WebCore::CSSProperty> : VectorTraitsBase<false, WebCore::CSSProperty> {
139    static const bool canInitializeWithMemset = true;
140    static const bool canMoveWithMemcpy = true;
141};
142}
143
144#endif // CSSProperty_h
145