1 /* 2 * (C) 1999-2003 Lars Knoll (knoll (at) 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 "core/CSSPropertyNames.h" 25 #include "core/css/CSSValue.h" 26 #include "platform/RuntimeEnabledFeatures.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 ALLOW_ONLY_INLINE_ALLOCATION(); 57 public: 58 CSSProperty(CSSPropertyID propertyID, PassRefPtrWillBeRawPtr<CSSValue> value, bool important = false, bool isSetFromShorthand = false, int indexInShorthandsVector = 0, bool implicit = false) 59 : m_metadata(propertyID, isSetFromShorthand, indexInShorthandsVector, important, implicit, isInheritedProperty(propertyID)) 60 , m_value(value) 61 { 62 } 63 64 // FIXME: Remove this. 65 CSSProperty(StylePropertyMetadata metadata, CSSValue* value) 66 : m_metadata(metadata) 67 , m_value(value) 68 { 69 } 70 71 CSSPropertyID id() const { return static_cast<CSSPropertyID>(m_metadata.m_propertyID); } 72 bool isSetFromShorthand() const { return m_metadata.m_isSetFromShorthand; }; 73 CSSPropertyID shorthandID() const { return m_metadata.shorthandID(); }; 74 bool isImportant() const { return m_metadata.m_important; } 75 76 CSSValue* value() const { return m_value.get(); } 77 78 void wrapValueInCommaSeparatedList(); 79 80 static CSSPropertyID resolveDirectionAwareProperty(CSSPropertyID, TextDirection, WritingMode); 81 static bool isInheritedProperty(CSSPropertyID); 82 static bool isAffectedByAllProperty(CSSPropertyID); 83 84 const StylePropertyMetadata& metadata() const { return m_metadata; } 85 86 void trace(Visitor* visitor) { visitor->trace(m_value); } 87 88 private: 89 StylePropertyMetadata m_metadata; 90 RefPtrWillBeMember<CSSValue> m_value; 91 }; 92 93 inline CSSPropertyID prefixingVariantForPropertyId(CSSPropertyID propId) 94 { 95 if (!RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled() && (propId >= CSSPropertyWebkitAnimation && propId <= CSSPropertyAnimationTimingFunction)) 96 return propId; 97 98 CSSPropertyID propertyId = CSSPropertyInvalid; 99 switch (propId) { 100 case CSSPropertyAnimation: 101 propertyId = CSSPropertyWebkitAnimation; 102 break; 103 case CSSPropertyAnimationDelay: 104 propertyId = CSSPropertyWebkitAnimationDelay; 105 break; 106 case CSSPropertyAnimationDirection: 107 propertyId = CSSPropertyWebkitAnimationDirection; 108 break; 109 case CSSPropertyAnimationDuration: 110 propertyId = CSSPropertyWebkitAnimationDuration; 111 break; 112 case CSSPropertyAnimationFillMode: 113 propertyId = CSSPropertyWebkitAnimationFillMode; 114 break; 115 case CSSPropertyAnimationIterationCount: 116 propertyId = CSSPropertyWebkitAnimationIterationCount; 117 break; 118 case CSSPropertyAnimationName: 119 propertyId = CSSPropertyWebkitAnimationName; 120 break; 121 case CSSPropertyAnimationPlayState: 122 propertyId = CSSPropertyWebkitAnimationPlayState; 123 break; 124 case CSSPropertyAnimationTimingFunction: 125 propertyId = CSSPropertyWebkitAnimationTimingFunction; 126 break; 127 case CSSPropertyTransitionDelay: 128 propertyId = CSSPropertyWebkitTransitionDelay; 129 break; 130 case CSSPropertyTransitionDuration: 131 propertyId = CSSPropertyWebkitTransitionDuration; 132 break; 133 case CSSPropertyTransitionProperty: 134 propertyId = CSSPropertyWebkitTransitionProperty; 135 break; 136 case CSSPropertyTransitionTimingFunction: 137 propertyId = CSSPropertyWebkitTransitionTimingFunction; 138 break; 139 case CSSPropertyTransition: 140 propertyId = CSSPropertyWebkitTransition; 141 break; 142 case CSSPropertyWebkitAnimation: 143 propertyId = CSSPropertyAnimation; 144 break; 145 case CSSPropertyWebkitAnimationDelay: 146 propertyId = CSSPropertyAnimationDelay; 147 break; 148 case CSSPropertyWebkitAnimationDirection: 149 propertyId = CSSPropertyAnimationDirection; 150 break; 151 case CSSPropertyWebkitAnimationDuration: 152 propertyId = CSSPropertyAnimationDuration; 153 break; 154 case CSSPropertyWebkitAnimationFillMode: 155 propertyId = CSSPropertyAnimationFillMode; 156 break; 157 case CSSPropertyWebkitAnimationIterationCount: 158 propertyId = CSSPropertyAnimationIterationCount; 159 break; 160 case CSSPropertyWebkitAnimationName: 161 propertyId = CSSPropertyAnimationName; 162 break; 163 case CSSPropertyWebkitAnimationPlayState: 164 propertyId = CSSPropertyAnimationPlayState; 165 break; 166 case CSSPropertyWebkitAnimationTimingFunction: 167 propertyId = CSSPropertyAnimationTimingFunction; 168 break; 169 case CSSPropertyWebkitTransitionDelay: 170 propertyId = CSSPropertyTransitionDelay; 171 break; 172 case CSSPropertyWebkitTransitionDuration: 173 propertyId = CSSPropertyTransitionDuration; 174 break; 175 case CSSPropertyWebkitTransitionProperty: 176 propertyId = CSSPropertyTransitionProperty; 177 break; 178 case CSSPropertyWebkitTransitionTimingFunction: 179 propertyId = CSSPropertyTransitionTimingFunction; 180 break; 181 case CSSPropertyWebkitTransition: 182 propertyId = CSSPropertyTransition; 183 break; 184 default: 185 propertyId = propId; 186 break; 187 } 188 ASSERT(propertyId != CSSPropertyInvalid); 189 return propertyId; 190 } 191 192 } // namespace WebCore 193 194 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(WebCore::CSSProperty); 195 196 #endif // CSSProperty_h 197