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 "CSSPropertyNames.h"
     25 #include "core/css/CSSValue.h"
     26 #include "core/platform/text/TextDirection.h"
     27 #include "core/platform/text/WritingMode.h"
     28 #include "wtf/PassRefPtr.h"
     29 #include "wtf/RefPtr.h"
     30 
     31 namespace WebCore {
     32 
     33 struct StylePropertyMetadata {
     34     StylePropertyMetadata(CSSPropertyID propertyID, bool isSetFromShorthand, int indexInShorthandsVector, bool important, bool implicit, bool inherited)
     35         : m_propertyID(propertyID)
     36         , m_isSetFromShorthand(isSetFromShorthand)
     37         , m_indexInShorthandsVector(indexInShorthandsVector)
     38         , m_important(important)
     39         , m_implicit(implicit)
     40         , m_inherited(inherited)
     41     {
     42     }
     43 
     44     CSSPropertyID shorthandID() const;
     45 
     46     uint16_t m_propertyID : 10;
     47     uint16_t m_isSetFromShorthand : 1;
     48     uint16_t m_indexInShorthandsVector : 2; // If this property was set as part of an ambiguous shorthand, gives the index in the shorthands vector.
     49     uint16_t m_important : 1;
     50     uint16_t m_implicit : 1; // Whether or not the property was set implicitly as the result of a shorthand.
     51     uint16_t m_inherited : 1;
     52 };
     53 
     54 class CSSProperty {
     55 public:
     56     CSSProperty(CSSPropertyID propertyID, PassRefPtr<CSSValue> value, bool important = false, bool isSetFromShorthand = false, int indexInShorthandsVector = 0, bool implicit = false)
     57         : m_metadata(propertyID, isSetFromShorthand, indexInShorthandsVector, important, implicit, isInheritedProperty(propertyID))
     58         , m_value(value)
     59     {
     60     ASSERT((propertyID == CSSPropertyVariable) == (m_value && m_value->isVariableValue()));
     61     }
     62 
     63     // FIXME: Remove this.
     64     CSSProperty(StylePropertyMetadata metadata, CSSValue* value)
     65         : m_metadata(metadata)
     66         , m_value(value)
     67     {
     68     ASSERT((metadata.m_propertyID == CSSPropertyVariable) == (m_value && m_value->isVariableValue()));
     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 
     83     const StylePropertyMetadata& metadata() const { return m_metadata; }
     84 
     85 private:
     86     StylePropertyMetadata m_metadata;
     87     RefPtr<CSSValue> m_value;
     88 };
     89 
     90 inline CSSPropertyID prefixingVariantForPropertyId(CSSPropertyID propId)
     91 {
     92     CSSPropertyID propertyId = CSSPropertyInvalid;
     93     switch (propId) {
     94     case CSSPropertyTransitionDelay:
     95         propertyId = CSSPropertyWebkitTransitionDelay;
     96         break;
     97     case CSSPropertyTransitionDuration:
     98         propertyId = CSSPropertyWebkitTransitionDuration;
     99         break;
    100     case CSSPropertyTransitionProperty:
    101         propertyId = CSSPropertyWebkitTransitionProperty;
    102         break;
    103     case CSSPropertyTransitionTimingFunction:
    104         propertyId = CSSPropertyWebkitTransitionTimingFunction;
    105         break;
    106     case CSSPropertyTransition:
    107         propertyId = CSSPropertyWebkitTransition;
    108         break;
    109     case CSSPropertyWebkitTransitionDelay:
    110         propertyId = CSSPropertyTransitionDelay;
    111         break;
    112     case CSSPropertyWebkitTransitionDuration:
    113         propertyId = CSSPropertyTransitionDuration;
    114         break;
    115     case CSSPropertyWebkitTransitionProperty:
    116         propertyId = CSSPropertyTransitionProperty;
    117         break;
    118     case CSSPropertyWebkitTransitionTimingFunction:
    119         propertyId = CSSPropertyTransitionTimingFunction;
    120         break;
    121     case CSSPropertyWebkitTransition:
    122         propertyId = CSSPropertyTransition;
    123         break;
    124     default:
    125         propertyId = propId;
    126         break;
    127     }
    128     ASSERT(propertyId != CSSPropertyInvalid);
    129     return propertyId;
    130 }
    131 
    132 } // namespace WebCore
    133 
    134 namespace WTF {
    135 template <> struct VectorTraits<WebCore::CSSProperty> : VectorTraitsBase<false, WebCore::CSSProperty> {
    136     static const bool canInitializeWithMemset = true;
    137     static const bool canMoveWithMemcpy = true;
    138 };
    139 }
    140 
    141 #endif // CSSProperty_h
    142