2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
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.
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.
31 #include "core/css/RuntimeCSSEnabled.h"
33 #include "RuntimeEnabledFeatures.h"
37 // FIXME: We should use a real BitVector class instead!
38 typedef Vector<bool> BoolVector;
40 static void setCSSPropertiesEnabled(CSSPropertyID* properties, size_t length, bool featureFlag)
42 for (size_t i = 0; i < length; i++)
43 RuntimeCSSEnabled::setCSSPropertyEnabled(properties[i], featureFlag);
46 static void setPropertySwitchesFromRuntimeFeatures()
48 CSSPropertyID exclusionProperties[] = {
49 CSSPropertyWebkitWrapFlow,
50 CSSPropertyWebkitWrapThrough,
52 setCSSPropertiesEnabled(exclusionProperties, WTF_ARRAY_LENGTH(exclusionProperties), RuntimeEnabledFeatures::cssExclusionsEnabled());
53 CSSPropertyID shapeProperties[] = {
54 CSSPropertyShapeMargin,
55 CSSPropertyShapePadding,
56 CSSPropertyShapeImageThreshold,
57 CSSPropertyShapeOutside,
59 setCSSPropertiesEnabled(shapeProperties, WTF_ARRAY_LENGTH(shapeProperties), RuntimeEnabledFeatures::cssShapesEnabled());
60 CSSPropertyID css3TextDecorationProperties[] = {
61 CSSPropertyTextDecorationColor,
62 CSSPropertyTextDecorationLine,
63 CSSPropertyTextDecorationStyle,
64 CSSPropertyTextUnderlinePosition,
66 setCSSPropertiesEnabled(css3TextDecorationProperties, WTF_ARRAY_LENGTH(css3TextDecorationProperties), RuntimeEnabledFeatures::css3TextDecorationsEnabled());
67 CSSPropertyID css3TextProperties[] = {
68 CSSPropertyTextAlignLast,
69 CSSPropertyTextJustify,
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,
84 CSSPropertyGridAutoFlow,
85 CSSPropertyGridTemplateAreas,
86 CSSPropertyJustifySelf
88 setCSSPropertiesEnabled(cssGridLayoutProperties, WTF_ARRAY_LENGTH(cssGridLayoutProperties), RuntimeEnabledFeatures::cssGridLayoutEnabled());
89 CSSPropertyID cssObjectFitPositionProperties[] = {
91 CSSPropertyObjectPosition
93 setCSSPropertiesEnabled(cssObjectFitPositionProperties, WTF_ARRAY_LENGTH(cssObjectFitPositionProperties), RuntimeEnabledFeatures::objectFitPositionEnabled());
95 CSSPropertyID animationProperties[] = {
97 CSSPropertyAnimationName,
98 CSSPropertyAnimationDuration,
99 CSSPropertyAnimationTimingFunction,
100 CSSPropertyAnimationDelay,
101 CSSPropertyAnimationIterationCount,
102 CSSPropertyAnimationDirection,
103 CSSPropertyAnimationFillMode,
104 CSSPropertyAnimationPlayState
106 setCSSPropertiesEnabled(animationProperties, WTF_ARRAY_LENGTH(animationProperties), RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled());
108 CSSPropertyID transformProperties[] = {
109 CSSPropertyBackfaceVisibility,
110 CSSPropertyPerspective,
111 CSSPropertyPerspectiveOrigin,
112 CSSPropertyTransform,
113 CSSPropertyTransformOrigin,
114 CSSPropertyTransformStyle
116 setCSSPropertiesEnabled(transformProperties, WTF_ARRAY_LENGTH(transformProperties), RuntimeEnabledFeatures::cssTransformsUnprefixedEnabled());
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());
128 // InternalCallback is an implementation detail, rather than an experimental feature, and should never be exposed to the web.
129 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyInternalCallback, false);
132 static BoolVector& propertySwitches()
134 static BoolVector* switches = 0;
136 switches = new BoolVector;
137 switches->fill(true, numCSSProperties);
138 setPropertySwitchesFromRuntimeFeatures();
143 size_t indexForProperty(CSSPropertyID propertyId)
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);
150 bool RuntimeCSSEnabled::isCSSPropertyEnabled(CSSPropertyID propertyId)
152 // Internal properties shouldn't be exposed to the web
153 // so they are considered to be always disabled.
154 if (isInternalProperty(propertyId))
157 return propertySwitches()[indexForProperty(propertyId)];
160 void RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyID propertyId, bool enable)
162 propertySwitches()[indexForProperty(propertyId)] = enable;
165 void RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(const CSSPropertyID* properties, size_t propertyCount, Vector<CSSPropertyID>& outVector)
167 for (unsigned i = 0; i < propertyCount; i++) {
168 CSSPropertyID property = properties[i];
169 if (RuntimeCSSEnabled::isCSSPropertyEnabled(property))
170 outVector.append(property);
174 } // namespace WebCore