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 "platform/RuntimeEnabledFeatures.h"
34 #include "wtf/BitArray.h"
38 typedef BitArray<numCSSProperties> CSSPropertySwitches;
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 css3TextDecorationProperties[] = {
49 CSSPropertyTextDecorationColor,
50 CSSPropertyTextDecorationLine,
51 CSSPropertyTextDecorationStyle,
52 CSSPropertyTextUnderlinePosition,
54 setCSSPropertiesEnabled(css3TextDecorationProperties, WTF_ARRAY_LENGTH(css3TextDecorationProperties), RuntimeEnabledFeatures::css3TextDecorationsEnabled());
55 CSSPropertyID css3TextProperties[] = {
56 CSSPropertyTextAlignLast,
57 CSSPropertyTextJustify,
59 setCSSPropertiesEnabled(css3TextProperties, WTF_ARRAY_LENGTH(css3TextProperties), RuntimeEnabledFeatures::css3TextEnabled());
60 CSSPropertyID cssGridLayoutProperties[] = {
61 CSSPropertyGridAutoColumns,
62 CSSPropertyGridAutoRows,
63 CSSPropertyGridTemplateColumns,
64 CSSPropertyGridTemplateRows,
65 CSSPropertyGridColumnStart,
66 CSSPropertyGridColumnEnd,
67 CSSPropertyGridRowStart,
68 CSSPropertyGridRowEnd,
69 CSSPropertyGridColumn,
72 CSSPropertyGridAutoFlow,
73 CSSPropertyGridTemplateAreas,
74 CSSPropertyGridTemplate,
76 CSSPropertyJustifySelf,
77 CSSPropertyJustifyItems
79 setCSSPropertiesEnabled(cssGridLayoutProperties, WTF_ARRAY_LENGTH(cssGridLayoutProperties), RuntimeEnabledFeatures::cssGridLayoutEnabled());
80 CSSPropertyID cssObjectFitPositionProperties[] = {
82 CSSPropertyObjectPosition
84 setCSSPropertiesEnabled(cssObjectFitPositionProperties, WTF_ARRAY_LENGTH(cssObjectFitPositionProperties), RuntimeEnabledFeatures::objectFitPositionEnabled());
86 CSSPropertyID animationProperties[] = {
88 CSSPropertyAnimationName,
89 CSSPropertyAnimationDuration,
90 CSSPropertyAnimationTimingFunction,
91 CSSPropertyAnimationDelay,
92 CSSPropertyAnimationIterationCount,
93 CSSPropertyAnimationDirection,
94 CSSPropertyAnimationFillMode,
95 CSSPropertyAnimationPlayState
97 setCSSPropertiesEnabled(animationProperties, WTF_ARRAY_LENGTH(animationProperties), RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled());
99 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyMixBlendMode, RuntimeEnabledFeatures::cssCompositingEnabled());
100 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyIsolation, RuntimeEnabledFeatures::cssCompositingEnabled());
101 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyTouchActionDelay, RuntimeEnabledFeatures::cssTouchActionDelayEnabled());
102 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyMaskSourceType, RuntimeEnabledFeatures::cssMaskSourceTypeEnabled());
103 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyColumnFill, RuntimeEnabledFeatures::regionBasedColumnsEnabled());
104 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyScrollBehavior, RuntimeEnabledFeatures::cssomSmoothScrollEnabled());
105 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyWillChange, RuntimeEnabledFeatures::cssWillChangeEnabled());
107 // InternalCallback is an implementation detail, rather than an experimental feature, and should never be exposed to the web.
108 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyInternalCallback, false);
111 static CSSPropertySwitches& propertySwitches()
113 static CSSPropertySwitches* switches = 0;
115 switches = new CSSPropertySwitches(true); // All bits sets to 1.
116 setPropertySwitchesFromRuntimeFeatures();
121 size_t indexForProperty(CSSPropertyID propertyId)
123 RELEASE_ASSERT(propertyId >= firstCSSProperty && propertyId <= lastCSSProperty);
124 // Values all start at 0. BitArray ASSERTS will catch if we're ever wrong.
125 return static_cast<size_t>(propertyId - firstCSSProperty);
128 bool RuntimeCSSEnabled::isCSSPropertyEnabled(CSSPropertyID propertyId)
130 // Internal properties shouldn't be exposed to the web
131 // so they are considered to be always disabled.
132 if (isInternalProperty(propertyId))
135 return propertySwitches().get(indexForProperty(propertyId));
138 void RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyID propertyId, bool enable)
140 size_t propertyIndex = indexForProperty(propertyId);
142 propertySwitches().set(propertyIndex);
144 propertySwitches().clear(propertyIndex);
147 void RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(const CSSPropertyID* properties, size_t propertyCount, Vector<CSSPropertyID>& outVector)
149 for (unsigned i = 0; i < propertyCount; i++) {
150 CSSPropertyID property = properties[i];
151 if (RuntimeCSSEnabled::isCSSPropertyEnabled(property))
152 outVector.append(property);