07864df8748fd6c5d44e5628707be8982a166969
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / RuntimeCSSEnabled.cpp
1 /*
2  * Copyright (C) 2013 Adobe Systems Incorporated. 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  *
8  * 1. Redistributions of source code must retain the above
9  *    copyright notice, this list of conditions and the following
10  *    disclaimer.
11  * 2. Redistributions in binary form must reproduce the above
12  *    copyright notice, this list of conditions and the following
13  *    disclaimer in the documentation and/or other materials
14  *    provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27  * OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include "config.h"
31 #include "core/css/RuntimeCSSEnabled.h"
32
33 #include "RuntimeEnabledFeatures.h"
34
35 namespace WebCore {
36
37 // FIXME: We should use a real BitVector class instead!
38 typedef Vector<bool> BoolVector;
39
40 static void setCSSPropertiesEnabled(CSSPropertyID* properties, size_t length, bool featureFlag)
41 {
42     for (size_t i = 0; i < length; i++)
43         RuntimeCSSEnabled::setCSSPropertyEnabled(properties[i], featureFlag);
44 }
45
46 static void setPropertySwitchesFromRuntimeFeatures()
47 {
48     CSSPropertyID exclusionProperties[] = {
49         CSSPropertyWebkitWrapFlow,
50         CSSPropertyWebkitWrapThrough,
51     };
52     setCSSPropertiesEnabled(exclusionProperties, WTF_ARRAY_LENGTH(exclusionProperties), RuntimeEnabledFeatures::cssExclusionsEnabled());
53     CSSPropertyID shapeProperties[] = {
54         CSSPropertyShapeMargin,
55         CSSPropertyShapePadding,
56         CSSPropertyShapeImageThreshold,
57         CSSPropertyShapeOutside,
58     };
59     setCSSPropertiesEnabled(shapeProperties, WTF_ARRAY_LENGTH(shapeProperties), RuntimeEnabledFeatures::cssShapesEnabled());
60     CSSPropertyID css3TextDecorationProperties[] = {
61         CSSPropertyTextDecorationColor,
62         CSSPropertyTextDecorationLine,
63         CSSPropertyTextDecorationStyle,
64         CSSPropertyTextUnderlinePosition,
65     };
66     setCSSPropertiesEnabled(css3TextDecorationProperties, WTF_ARRAY_LENGTH(css3TextDecorationProperties), RuntimeEnabledFeatures::css3TextDecorationsEnabled());
67     CSSPropertyID css3TextProperties[] = {
68         CSSPropertyTextAlignLast,
69         CSSPropertyTextJustify,
70     };
71     setCSSPropertiesEnabled(css3TextProperties, WTF_ARRAY_LENGTH(css3TextProperties), RuntimeEnabledFeatures::css3TextEnabled());
72     CSSPropertyID cssGridLayoutProperties[] = {
73         CSSPropertyGridAutoColumns,
74         CSSPropertyGridAutoRows,
75         CSSPropertyGridTemplateColumns,
76         CSSPropertyGridTemplateRows,
77         CSSPropertyGridColumnStart,
78         CSSPropertyGridColumnEnd,
79         CSSPropertyGridRowStart,
80         CSSPropertyGridRowEnd,
81         CSSPropertyGridColumn,
82         CSSPropertyGridRow,
83         CSSPropertyGridArea,
84         CSSPropertyGridAutoFlow,
85         CSSPropertyGridTemplateAreas,
86         CSSPropertyJustifySelf
87     };
88     setCSSPropertiesEnabled(cssGridLayoutProperties, WTF_ARRAY_LENGTH(cssGridLayoutProperties), RuntimeEnabledFeatures::cssGridLayoutEnabled());
89     CSSPropertyID cssObjectFitPositionProperties[] = {
90         CSSPropertyObjectFit,
91         CSSPropertyObjectPosition
92     };
93     setCSSPropertiesEnabled(cssObjectFitPositionProperties, WTF_ARRAY_LENGTH(cssObjectFitPositionProperties), RuntimeEnabledFeatures::objectFitPositionEnabled());
94
95     CSSPropertyID animationProperties[] = {
96         CSSPropertyAnimation,
97         CSSPropertyAnimationName,
98         CSSPropertyAnimationDuration,
99         CSSPropertyAnimationTimingFunction,
100         CSSPropertyAnimationDelay,
101         CSSPropertyAnimationIterationCount,
102         CSSPropertyAnimationDirection,
103         CSSPropertyAnimationFillMode,
104         CSSPropertyAnimationPlayState
105     };
106     setCSSPropertiesEnabled(animationProperties, WTF_ARRAY_LENGTH(animationProperties), RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled());
107
108     CSSPropertyID transformProperties[] = {
109         CSSPropertyBackfaceVisibility,
110         CSSPropertyPerspective,
111         CSSPropertyPerspectiveOrigin,
112         CSSPropertyTransform,
113         CSSPropertyTransformOrigin,
114         CSSPropertyTransformStyle
115     };
116     setCSSPropertiesEnabled(transformProperties, WTF_ARRAY_LENGTH(transformProperties), RuntimeEnabledFeatures::cssTransformsUnprefixedEnabled());
117
118     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyMixBlendMode, RuntimeEnabledFeatures::cssCompositingEnabled());
119     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyIsolation, RuntimeEnabledFeatures::cssCompositingEnabled());
120     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyTouchAction, RuntimeEnabledFeatures::cssTouchActionEnabled());
121     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyTouchActionDelay, RuntimeEnabledFeatures::cssTouchActionDelayEnabled());
122     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyPaintOrder, RuntimeEnabledFeatures::svgPaintOrderEnabled());
123     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyMaskSourceType, RuntimeEnabledFeatures::cssMaskSourceTypeEnabled());
124     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyColumnFill, RuntimeEnabledFeatures::regionBasedColumnsEnabled());
125     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyScrollBehavior, RuntimeEnabledFeatures::cssomSmoothScrollEnabled());
126     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyWillChange, RuntimeEnabledFeatures::cssWillChangeEnabled());
127
128     // InternalCallback is an implementation detail, rather than an experimental feature, and should never be exposed to the web.
129     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyInternalCallback, false);
130 }
131
132 static BoolVector& propertySwitches()
133 {
134     static BoolVector* switches = 0;
135     if (!switches) {
136         switches = new BoolVector;
137         switches->fill(true, numCSSProperties);
138         setPropertySwitchesFromRuntimeFeatures();
139     }
140     return *switches;
141 }
142
143 size_t indexForProperty(CSSPropertyID propertyId)
144 {
145     RELEASE_ASSERT(propertyId >= firstCSSProperty && propertyId <= lastCSSProperty);
146     // Values all start at 0. Vector RELEASE_ASSERTS will catch if we're ever wrong.
147     return static_cast<size_t>(propertyId - firstCSSProperty);
148 }
149
150 bool RuntimeCSSEnabled::isCSSPropertyEnabled(CSSPropertyID propertyId)
151 {
152     // Internal properties shouldn't be exposed to the web
153     // so they are considered to be always disabled.
154     if (isInternalProperty(propertyId))
155         return false;
156
157     return propertySwitches()[indexForProperty(propertyId)];
158 }
159
160 void RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyID propertyId, bool enable)
161 {
162     propertySwitches()[indexForProperty(propertyId)] = enable;
163 }
164
165 void RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(const CSSPropertyID* properties, size_t propertyCount, Vector<CSSPropertyID>& outVector)
166 {
167     for (unsigned i = 0; i < propertyCount; i++) {
168         CSSPropertyID property = properties[i];
169         if (RuntimeCSSEnabled::isCSSPropertyEnabled(property))
170             outVector.append(property);
171     }
172 }
173
174 } // namespace WebCore