OLD | NEW |
(Empty) | |
| 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 "RuntimeCSSEnabled.h" |
| 32 #include "RuntimeEnabledFeatures.h" |
| 33 |
| 34 namespace WebCore { |
| 35 |
| 36 // FIXME: We should use a real BitVector class instead! |
| 37 typedef Vector<bool> BitVector; |
| 38 |
| 39 static void setFromFeatureValue(bool featureFlag, CSSPropertyID* properties, siz
e_t length) |
| 40 { |
| 41 for (size_t i = 0; i < length; i++) |
| 42 RuntimeCSSEnabled::setCSSPropertyEnabled(properties[i], featureFlag); |
| 43 } |
| 44 |
| 45 static void setPropertySwitchesFromRuntimeFeatures(BitVector& properties) |
| 46 { |
| 47 #if ENABLE(CSS_REGIONS) |
| 48 CSSPropertyID regionProperites[] = { |
| 49 CSSPropertyWebkitFlowInto, |
| 50 CSSPropertyWebkitFlowFrom, |
| 51 CSSPropertyWebkitRegionOverflow, |
| 52 CSSPropertyWebkitRegionBreakAfter, |
| 53 CSSPropertyWebkitRegionBreakBefore, |
| 54 CSSPropertyWebkitRegionBreakInside |
| 55 }; |
| 56 setFromFeatureValue(RuntimeEnabledFeatures::cssRegionsEnabled(), regionPrope
rites, WTF_ARRAY_LENGTH(regionProperites)); |
| 57 #endif |
| 58 #if ENABLE(CSS_EXCLUSIONS) |
| 59 CSSPropertyID exclusionProperties[] = { |
| 60 CSSPropertyWebkitWrap, |
| 61 CSSPropertyWebkitWrapFlow, |
| 62 CSSPropertyWebkitShapeMargin, |
| 63 CSSPropertyWebkitShapePadding, |
| 64 CSSPropertyWebkitWrapThrough, |
| 65 CSSPropertyWebkitShapeInside, |
| 66 CSSPropertyWebkitShapeOutside, |
| 67 }; |
| 68 setFromFeatureValue(RuntimeEnabledFeatures::cssExclusionsEnabled(), exclusio
nProperties, WTF_ARRAY_LENGTH(exclusionProperties)); |
| 69 #endif |
| 70 #if ENABLE(CSS_COMPOSITING) |
| 71 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyBackgroundBlendMode, Run
timeEnabledFeatures::cssCompositingEnabled()); |
| 72 RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyWebkitBlendMode, Runtime
EnabledFeatures::cssCompositingEnabled()); |
| 73 #endif |
| 74 } |
| 75 |
| 76 static void setValueSwitchesFromRuntimeFeatures(BitVector& values) |
| 77 { |
| 78 // FIXME: Add various runtime-enabled values here. |
| 79 } |
| 80 |
| 81 static BitVector& propertySwitches() |
| 82 { |
| 83 static BitVector* switches = 0; |
| 84 if (!switches) { |
| 85 switches = new BitVector; |
| 86 switches->fill(true, numCSSProperties); |
| 87 setPropertySwitchesFromRuntimeFeatures(*switches); |
| 88 } |
| 89 return *switches; |
| 90 } |
| 91 |
| 92 static BitVector& valueSwitches() |
| 93 { |
| 94 static BitVector* switches = 0; |
| 95 if (!switches) { |
| 96 switches = new BitVector; |
| 97 switches->fill(true, numCSSValueKeywords); |
| 98 setValueSwitchesFromRuntimeFeatures(*switches); |
| 99 } |
| 100 return *switches; |
| 101 } |
| 102 |
| 103 size_t indexForValue(CSSValueID valueId) |
| 104 { |
| 105 // Values all start at 0. Vector RELEASE_ASSERTS will catch if we're ever w
rong. |
| 106 return static_cast<size_t>(valueId); |
| 107 } |
| 108 |
| 109 size_t indexForProperty(CSSPropertyID propertyId) |
| 110 { |
| 111 RELEASE_ASSERT(propertyId >= firstCSSProperty && propertyId <= lastCSSProper
ty); |
| 112 // Values all start at 0. Vector RELEASE_ASSERTS will catch if we're ever w
rong. |
| 113 return static_cast<size_t>(propertyId - firstCSSProperty); |
| 114 } |
| 115 |
| 116 bool RuntimeCSSEnabled::isCSSValueEnabled(CSSValueID valueId) |
| 117 { |
| 118 return valueSwitches()[indexForValue(valueId)]; |
| 119 } |
| 120 |
| 121 void RuntimeCSSEnabled::setCSSValueEnabled(CSSValueID valueId, bool enable) |
| 122 { |
| 123 valueSwitches()[indexForValue(valueId)] = enable; |
| 124 } |
| 125 |
| 126 bool RuntimeCSSEnabled::isCSSPropertyEnabled(CSSPropertyID propertyId) |
| 127 { |
| 128 return propertySwitches()[indexForProperty(propertyId)]; |
| 129 } |
| 130 |
| 131 void RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyID propertyId, bool ena
ble) |
| 132 { |
| 133 propertySwitches()[indexForProperty(propertyId)] = enable; |
| 134 } |
| 135 |
| 136 } // namespace WebCore |
OLD | NEW |