• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1.  Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  * 2.  Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16  * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24 
25 #ifndef CSSStyleApplyProperty_h
26 #define CSSStyleApplyProperty_h
27 
28 #include "CSSPropertyNames.h"
29 #include <wtf/PassRefPtr.h>
30 #include <wtf/RefCounted.h>
31 
32 namespace WebCore {
33 
34 class CSSStyleSelector;
35 class CSSValue;
36 class ApplyPropertyBase {
37     WTF_MAKE_NONCOPYABLE(ApplyPropertyBase);
38     WTF_MAKE_FAST_ALLOCATED;
39 public:
ApplyPropertyBase()40     ApplyPropertyBase() { }
~ApplyPropertyBase()41     virtual ~ApplyPropertyBase() { }
42     virtual void applyInheritValue(CSSStyleSelector*) const = 0;
43     virtual void applyInitialValue(CSSStyleSelector*) const = 0;
44     virtual void applyValue(CSSStyleSelector*, CSSValue*) const = 0;
45 };
46 
47 class CSSStyleApplyProperty {
48     WTF_MAKE_NONCOPYABLE(CSSStyleApplyProperty);
49 public:
50     static const CSSStyleApplyProperty& sharedCSSStyleApplyProperty();
51 
applyInheritValue(CSSPropertyID property,CSSStyleSelector * selector)52     void applyInheritValue(CSSPropertyID property, CSSStyleSelector* selector) const
53     {
54         ASSERT(implements(property));
55         propertyValue(property)->applyInheritValue(selector);
56     }
57 
applyInitialValue(CSSPropertyID property,CSSStyleSelector * selector)58     void applyInitialValue(CSSPropertyID property, CSSStyleSelector* selector) const
59     {
60         ASSERT(implements(property));
61         propertyValue(property)->applyInitialValue(selector);
62     }
63 
applyValue(CSSPropertyID property,CSSStyleSelector * selector,CSSValue * value)64     void applyValue(CSSPropertyID property, CSSStyleSelector* selector, CSSValue* value) const
65     {
66         ASSERT(implements(property));
67         propertyValue(property)->applyValue(selector, value);
68     }
69 
implements(CSSPropertyID property)70     bool implements(CSSPropertyID property) const
71     {
72         return propertyValue(property);
73     }
74 
75 private:
76     CSSStyleApplyProperty();
index(CSSPropertyID property)77     static int index(CSSPropertyID property)
78     {
79         return property - firstCSSProperty;
80     }
81 
valid(CSSPropertyID property)82     static bool valid(CSSPropertyID property)
83     {
84         int i = index(property);
85         return i >= 0 && i < numCSSProperties;
86     }
87 
setPropertyValue(CSSPropertyID property,ApplyPropertyBase * value)88     void setPropertyValue(CSSPropertyID property, ApplyPropertyBase* value)
89     {
90         ASSERT(valid(property));
91         m_propertyMap[index(property)] = value;
92     }
93 
setPropertyValue(CSSPropertyID newProperty,CSSPropertyID equivalentProperty)94     void setPropertyValue(CSSPropertyID newProperty, CSSPropertyID equivalentProperty)
95     {
96         ASSERT(valid(newProperty));
97         ASSERT(valid(equivalentProperty));
98         m_propertyMap[index(newProperty)] = m_propertyMap[index(equivalentProperty)];
99     }
100 
propertyValue(CSSPropertyID property)101     ApplyPropertyBase* propertyValue(CSSPropertyID property) const
102     {
103         ASSERT(valid(property));
104         return m_propertyMap[index(property)];
105     }
106 
107     ApplyPropertyBase* m_propertyMap[numCSSProperties];
108 };
109 
110 }
111 
112 #endif // CSSStyleApplyProperty_h
113