Home | History | Annotate | Download | only in css
      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/CSSPropertyMetadata.h"
     26 #include "core/css/CSSValue.h"
     27 #include "platform/RuntimeEnabledFeatures.h"
     28 #include "platform/text/TextDirection.h"
     29 #include "platform/text/WritingMode.h"
     30 #include "wtf/PassRefPtr.h"
     31 #include "wtf/RefPtr.h"
     32 
     33 namespace blink {
     34 
     35 struct StylePropertyMetadata {
     36     StylePropertyMetadata(CSSPropertyID propertyID, bool isSetFromShorthand, int indexInShorthandsVector, bool important, bool implicit, bool inherited)
     37         : m_propertyID(propertyID)
     38         , m_isSetFromShorthand(isSetFromShorthand)
     39         , m_indexInShorthandsVector(indexInShorthandsVector)
     40         , m_important(important)
     41         , m_implicit(implicit)
     42         , m_inherited(inherited)
     43     {
     44     }
     45 
     46     CSSPropertyID shorthandID() const;
     47 
     48     uint16_t m_propertyID : 10;
     49     uint16_t m_isSetFromShorthand : 1;
     50     uint16_t m_indexInShorthandsVector : 2; // If this property was set as part of an ambiguous shorthand, gives the index in the shorthands vector.
     51     uint16_t m_important : 1;
     52     uint16_t m_implicit : 1; // Whether or not the property was set implicitly as the result of a shorthand.
     53     uint16_t m_inherited : 1;
     54 };
     55 
     56 class CSSProperty {
     57     ALLOW_ONLY_INLINE_ALLOCATION();
     58 public:
     59     CSSProperty(CSSPropertyID propertyID, PassRefPtrWillBeRawPtr<CSSValue> value, bool important = false, bool isSetFromShorthand = false, int indexInShorthandsVector = 0, bool implicit = false)
     60         : m_metadata(propertyID, isSetFromShorthand, indexInShorthandsVector, important, implicit, CSSPropertyMetadata::isInheritedProperty(propertyID))
     61         , m_value(value)
     62     {
     63     }
     64 
     65     // FIXME: Remove this.
     66     CSSProperty(StylePropertyMetadata metadata, CSSValue* value)
     67         : m_metadata(metadata)
     68         , m_value(value)
     69     {
     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 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()) {
     96         switch (propId) {
     97         case CSSPropertyAnimation:
     98             return CSSPropertyWebkitAnimation;
     99         case CSSPropertyAnimationDelay:
    100             return CSSPropertyWebkitAnimationDelay;
    101         case CSSPropertyAnimationDirection:
    102             return CSSPropertyWebkitAnimationDirection;
    103         case CSSPropertyAnimationDuration:
    104             return CSSPropertyWebkitAnimationDuration;
    105         case CSSPropertyAnimationFillMode:
    106             return CSSPropertyWebkitAnimationFillMode;
    107         case CSSPropertyAnimationIterationCount:
    108             return CSSPropertyWebkitAnimationIterationCount;
    109         case CSSPropertyAnimationName:
    110             return CSSPropertyWebkitAnimationName;
    111         case CSSPropertyAnimationPlayState:
    112             return CSSPropertyWebkitAnimationPlayState;
    113         case CSSPropertyAnimationTimingFunction:
    114             return CSSPropertyWebkitAnimationTimingFunction;
    115         case CSSPropertyWebkitAnimation:
    116             return CSSPropertyAnimation;
    117         case CSSPropertyWebkitAnimationDelay:
    118             return CSSPropertyAnimationDelay;
    119         case CSSPropertyWebkitAnimationDirection:
    120             return CSSPropertyAnimationDirection;
    121         case CSSPropertyWebkitAnimationDuration:
    122             return CSSPropertyAnimationDuration;
    123         case CSSPropertyWebkitAnimationFillMode:
    124             return CSSPropertyAnimationFillMode;
    125         case CSSPropertyWebkitAnimationIterationCount:
    126             return CSSPropertyAnimationIterationCount;
    127         case CSSPropertyWebkitAnimationName:
    128             return CSSPropertyAnimationName;
    129         case CSSPropertyWebkitAnimationPlayState:
    130             return CSSPropertyAnimationPlayState;
    131         case CSSPropertyWebkitAnimationTimingFunction:
    132             return CSSPropertyAnimationTimingFunction;
    133         default:
    134             break;
    135         }
    136     }
    137 
    138     switch (propId) {
    139     case CSSPropertyTransitionDelay:
    140         return CSSPropertyWebkitTransitionDelay;
    141     case CSSPropertyTransitionDuration:
    142         return CSSPropertyWebkitTransitionDuration;
    143     case CSSPropertyTransitionProperty:
    144         return CSSPropertyWebkitTransitionProperty;
    145     case CSSPropertyTransitionTimingFunction:
    146         return CSSPropertyWebkitTransitionTimingFunction;
    147     case CSSPropertyTransition:
    148         return CSSPropertyWebkitTransition;
    149     case CSSPropertyWebkitTransitionDelay:
    150         return CSSPropertyTransitionDelay;
    151     case CSSPropertyWebkitTransitionDuration:
    152         return CSSPropertyTransitionDuration;
    153     case CSSPropertyWebkitTransitionProperty:
    154         return CSSPropertyTransitionProperty;
    155     case CSSPropertyWebkitTransitionTimingFunction:
    156         return CSSPropertyTransitionTimingFunction;
    157     case CSSPropertyWebkitTransition:
    158         return CSSPropertyTransition;
    159     default:
    160         return propId;
    161     }
    162 }
    163 
    164 } // namespace blink
    165 
    166 WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::CSSProperty);
    167 
    168 #endif // CSSProperty_h
    169