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 "platform/RuntimeEnabledFeatures.h" 34 #include "wtf/BitArray.h" 35 36 namespace WebCore { 37 38 typedef BitArray<numCSSProperties> CSSPropertySwitches; 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 CSSPropertyShapeImageThreshold, 56 CSSPropertyShapeOutside, 57 }; 58 setCSSPropertiesEnabled(shapeProperties, WTF_ARRAY_LENGTH(shapeProperties), RuntimeEnabledFeatures::cssShapesEnabled()); 59 CSSPropertyID css3TextDecorationProperties[] = { 60 CSSPropertyTextDecorationColor, 61 CSSPropertyTextDecorationLine, 62 CSSPropertyTextDecorationStyle, 63 CSSPropertyTextUnderlinePosition, 64 }; 65 setCSSPropertiesEnabled(css3TextDecorationProperties, WTF_ARRAY_LENGTH(css3TextDecorationProperties), RuntimeEnabledFeatures::css3TextDecorationsEnabled()); 66 CSSPropertyID css3TextProperties[] = { 67 CSSPropertyTextAlignLast, 68 CSSPropertyTextJustify, 69 }; 70 setCSSPropertiesEnabled(css3TextProperties, WTF_ARRAY_LENGTH(css3TextProperties), RuntimeEnabledFeatures::css3TextEnabled()); 71 CSSPropertyID cssGridLayoutProperties[] = { 72 CSSPropertyGridAutoColumns, 73 CSSPropertyGridAutoRows, 74 CSSPropertyGridTemplateColumns, 75 CSSPropertyGridTemplateRows, 76 CSSPropertyGridColumnStart, 77 CSSPropertyGridColumnEnd, 78 CSSPropertyGridRowStart, 79 CSSPropertyGridRowEnd, 80 CSSPropertyGridColumn, 81 CSSPropertyGridRow, 82 CSSPropertyGridArea, 83 CSSPropertyGridAutoFlow, 84 CSSPropertyGridTemplateAreas, 85 CSSPropertyGridTemplate, 86 CSSPropertyGrid, 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 CSSPropertyID transformProperties[] = { 110 CSSPropertyBackfaceVisibility, 111 CSSPropertyPerspective, 112 CSSPropertyPerspectiveOrigin, 113 CSSPropertyTransform, 114 CSSPropertyTransformOrigin, 115 CSSPropertyTransformStyle 116 }; 117 setCSSPropertiesEnabled(transformProperties, WTF_ARRAY_LENGTH(transformProperties), RuntimeEnabledFeatures::cssTransformsUnprefixedEnabled()); 118 119 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyMixBlendMode, RuntimeEnabledFeatures::cssCompositingEnabled()); 120 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyIsolation, RuntimeEnabledFeatures::cssCompositingEnabled()); 121 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyTouchAction, RuntimeEnabledFeatures::cssTouchActionEnabled()); 122 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyTouchActionDelay, RuntimeEnabledFeatures::cssTouchActionDelayEnabled()); 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 CSSPropertySwitches& propertySwitches() 133 { 134 static CSSPropertySwitches* switches = 0; 135 if (!switches) { 136 switches = new CSSPropertySwitches(true); // All bits sets to 1. 137 setPropertySwitchesFromRuntimeFeatures(); 138 } 139 return *switches; 140 } 141 142 size_t indexForProperty(CSSPropertyID propertyId) 143 { 144 RELEASE_ASSERT(propertyId >= firstCSSProperty && propertyId <= lastCSSProperty); 145 // Values all start at 0. BitArray ASSERTS will catch if we're ever wrong. 146 return static_cast<size_t>(propertyId - firstCSSProperty); 147 } 148 149 bool RuntimeCSSEnabled::isCSSPropertyEnabled(CSSPropertyID propertyId) 150 { 151 // Internal properties shouldn't be exposed to the web 152 // so they are considered to be always disabled. 153 if (isInternalProperty(propertyId)) 154 return false; 155 156 return propertySwitches().get(indexForProperty(propertyId)); 157 } 158 159 void RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyID propertyId, bool enable) 160 { 161 size_t propertyIndex = indexForProperty(propertyId); 162 if (enable) 163 propertySwitches().set(propertyIndex); 164 else 165 propertySwitches().clear(propertyIndex); 166 } 167 168 void RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(const CSSPropertyID* properties, size_t propertyCount, Vector<CSSPropertyID>& outVector) 169 { 170 for (unsigned i = 0; i < propertyCount; i++) { 171 CSSPropertyID property = properties[i]; 172 if (RuntimeCSSEnabled::isCSSPropertyEnabled(property)) 173 outVector.append(property); 174 } 175 } 176 177 } // namespace WebCore 178