Upstream version 5.34.104.0
[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         CSSPropertyShapeInside,
58         CSSPropertyShapeOutside,
59     };
60     setCSSPropertiesEnabled(shapeProperties, WTF_ARRAY_LENGTH(shapeProperties), RuntimeEnabledFeatures::cssShapesEnabled());
61     CSSPropertyID css3TextDecorationProperties[] = {
62         CSSPropertyTextDecorationColor,
63         CSSPropertyTextDecorationLine,
64         CSSPropertyTextDecorationStyle,
65         CSSPropertyTextUnderlinePosition,
66     };
67     setCSSPropertiesEnabled(css3TextDecorationProperties, WTF_ARRAY_LENGTH(css3TextDecorationProperties), RuntimeEnabledFeatures::css3TextDecorationsEnabled());
68     CSSPropertyID css3TextProperties[] = {
69         CSSPropertyTextAlignLast,
70         CSSPropertyTextJustify,
71     };
72     setCSSPropertiesEnabled(css3TextProperties, WTF_ARRAY_LENGTH(css3TextProperties), RuntimeEnabledFeatures::css3TextEnabled());
73     CSSPropertyID cssGridLayoutProperties[] = {
74         CSSPropertyGridAutoColumns,
75         CSSPropertyGridAutoRows,
76         CSSPropertyGridTemplateColumns,
77         CSSPropertyGridTemplateRows,
78         CSSPropertyGridColumnStart,
79         CSSPropertyGridColumnEnd,
80         CSSPropertyGridRowStart,
81         CSSPropertyGridRowEnd,
82         CSSPropertyGridColumn,
83         CSSPropertyGridRow,
84         CSSPropertyGridArea,
85         CSSPropertyGridAutoFlow,
86         CSSPropertyGridTemplateAreas,
87         CSSPropertyJustifySelf
88     };
89     setCSSPropertiesEnabled(cssGridLayoutProperties, WTF_ARRAY_LENGTH(cssGridLayoutProperties), RuntimeEnabledFeatures::cssGridLayoutEnabled());
90     CSSPropertyID cssObjectFitPositionProperties[] = {
91         CSSPropertyObjectFit,
92         CSSPropertyObjectPosition
93     };
94     setCSSPropertiesEnabled(cssObjectFitPositionProperties, WTF_ARRAY_LENGTH(cssObjectFitPositionProperties), RuntimeEnabledFeatures::objectFitPositionEnabled());
95
96     CSSPropertyID animationProperties[] = {
97         CSSPropertyAnimation,
98         CSSPropertyAnimationName,
99         CSSPropertyAnimationDuration,
100         CSSPropertyAnimationTimingFunction,
101         CSSPropertyAnimationDelay,
102         CSSPropertyAnimationIterationCount,
103         CSSPropertyAnimationDirection,
104         CSSPropertyAnimationFillMode,
105         CSSPropertyAnimationPlayState
106     };
107     setCSSPropertiesEnabled(animationProperties, WTF_ARRAY_LENGTH(animationProperties), RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled());
108
109     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyBackgroundBlendMode, RuntimeEnabledFeatures::cssCompositingEnabled());
110     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyMixBlendMode, RuntimeEnabledFeatures::cssCompositingEnabled());
111     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyIsolation, RuntimeEnabledFeatures::cssCompositingEnabled());
112     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyTouchAction, RuntimeEnabledFeatures::cssTouchActionEnabled());
113     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyTouchActionDelay, RuntimeEnabledFeatures::cssTouchActionDelayEnabled());
114     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyPaintOrder, RuntimeEnabledFeatures::svgPaintOrderEnabled());
115     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyMaskSourceType, RuntimeEnabledFeatures::cssMaskSourceTypeEnabled());
116     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyColumnFill, RuntimeEnabledFeatures::regionBasedColumnsEnabled());
117     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyScrollBehavior, RuntimeEnabledFeatures::cssomSmoothScrollEnabled());
118
119     // InternalCallback is an implementation detail, rather than an experimental feature, and should never be exposed to the web.
120     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyInternalCallback, false);
121 }
122
123 static BoolVector& propertySwitches()
124 {
125     static BoolVector* switches = 0;
126     if (!switches) {
127         switches = new BoolVector;
128         switches->fill(true, numCSSProperties);
129         setPropertySwitchesFromRuntimeFeatures();
130     }
131     return *switches;
132 }
133
134 size_t indexForProperty(CSSPropertyID propertyId)
135 {
136     RELEASE_ASSERT(propertyId >= firstCSSProperty && propertyId <= lastCSSProperty);
137     // Values all start at 0. Vector RELEASE_ASSERTS will catch if we're ever wrong.
138     return static_cast<size_t>(propertyId - firstCSSProperty);
139 }
140
141 bool RuntimeCSSEnabled::isCSSPropertyEnabled(CSSPropertyID propertyId)
142 {
143     // Internal properties shouldn't be exposed to the web
144     // so they are considered to be always disabled.
145     if (isInternalProperty(propertyId))
146         return false;
147
148     return propertySwitches()[indexForProperty(propertyId)];
149 }
150
151 void RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyID propertyId, bool enable)
152 {
153     propertySwitches()[indexForProperty(propertyId)] = enable;
154 }
155
156 void RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(const CSSPropertyID* properties, size_t propertyCount, Vector<CSSPropertyID>& outVector)
157 {
158     for (unsigned i = 0; i < propertyCount; i++) {
159         CSSPropertyID property = properties[i];
160         if (RuntimeCSSEnabled::isCSSPropertyEnabled(property))
161             outVector.append(property);
162     }
163 }
164
165 } // namespace WebCore