Home | History | Annotate | Download | only in page
      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/page/RuntimeCSSEnabled.h"
     32 #include "RuntimeEnabledFeatures.h"
     33 #include "wtf/Vector.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 regionProperites[] = {
     49         CSSPropertyWebkitFlowInto,
     50         CSSPropertyWebkitFlowFrom,
     51         CSSPropertyWebkitRegionFragment,
     52         CSSPropertyWebkitRegionBreakAfter,
     53         CSSPropertyWebkitRegionBreakBefore,
     54         CSSPropertyWebkitRegionBreakInside
     55     };
     56     setCSSPropertiesEnabled(regionProperites, WTF_ARRAY_LENGTH(regionProperites), RuntimeEnabledFeatures::cssRegionsEnabled());
     57     CSSPropertyID exclusionProperties[] = {
     58         CSSPropertyWebkitWrapFlow,
     59         CSSPropertyWebkitShapeMargin,
     60         CSSPropertyWebkitShapePadding,
     61         CSSPropertyWebkitWrapThrough,
     62         CSSPropertyWebkitShapeInside,
     63         CSSPropertyWebkitShapeOutside,
     64     };
     65     setCSSPropertiesEnabled(exclusionProperties, WTF_ARRAY_LENGTH(exclusionProperties), RuntimeEnabledFeatures::cssExclusionsEnabled());
     66     CSSPropertyID css3TextDecorationProperties[] = {
     67         CSSPropertyTextDecorationColor,
     68         CSSPropertyTextDecorationLine,
     69         CSSPropertyTextDecorationStyle,
     70     };
     71     setCSSPropertiesEnabled(css3TextDecorationProperties, WTF_ARRAY_LENGTH(css3TextDecorationProperties), RuntimeEnabledFeatures::css3TextDecorationsEnabled());
     72     CSSPropertyID css3TextProperties[] = {
     73         CSSPropertyTextAlignLast,
     74     };
     75     setCSSPropertiesEnabled(css3TextProperties, WTF_ARRAY_LENGTH(css3TextProperties), RuntimeEnabledFeatures::css3TextEnabled());
     76     CSSPropertyID cssGridLayoutProperties[] = {
     77         CSSPropertyGridAutoColumns,
     78         CSSPropertyGridAutoRows,
     79         CSSPropertyGridDefinitionColumns,
     80         CSSPropertyGridDefinitionRows,
     81         CSSPropertyGridColumnStart,
     82         CSSPropertyGridColumnEnd,
     83         CSSPropertyGridRowStart,
     84         CSSPropertyGridRowEnd,
     85         CSSPropertyGridColumn,
     86         CSSPropertyGridRow,
     87         CSSPropertyGridArea,
     88         CSSPropertyGridAutoFlow
     89     };
     90     setCSSPropertiesEnabled(cssGridLayoutProperties, WTF_ARRAY_LENGTH(cssGridLayoutProperties), RuntimeEnabledFeatures::cssGridLayoutEnabled());
     91 
     92     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyBackgroundBlendMode, RuntimeEnabledFeatures::cssCompositingEnabled());
     93     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyMixBlendMode, RuntimeEnabledFeatures::cssCompositingEnabled());
     94     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyTouchAction, RuntimeEnabledFeatures::cssTouchActionEnabled());
     95     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyVariable, RuntimeEnabledFeatures::cssVariablesEnabled());
     96 }
     97 
     98 static BoolVector& propertySwitches()
     99 {
    100     static BoolVector* switches = 0;
    101     if (!switches) {
    102         switches = new BoolVector;
    103         // Accomodate CSSPropertyIDs that fall outside the firstCSSProperty, lastCSSProperty range (eg. CSSPropertyVariable).
    104         switches->fill(true, lastCSSProperty + 1);
    105         setPropertySwitchesFromRuntimeFeatures();
    106     }
    107     return *switches;
    108 }
    109 
    110 size_t indexForProperty(CSSPropertyID propertyId)
    111 {
    112     RELEASE_ASSERT(propertyId >= 0 && propertyId <= lastCSSProperty);
    113     ASSERT(propertyId != CSSPropertyInvalid);
    114     return static_cast<size_t>(propertyId);
    115 }
    116 
    117 bool RuntimeCSSEnabled::isCSSPropertyEnabled(CSSPropertyID propertyId)
    118 {
    119     return propertySwitches()[indexForProperty(propertyId)];
    120 }
    121 
    122 void RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyID propertyId, bool enable)
    123 {
    124     propertySwitches()[indexForProperty(propertyId)] = enable;
    125 }
    126 
    127 void RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(const CSSPropertyID* properties, size_t propertyCount, Vector<CSSPropertyID>& outVector)
    128 {
    129     for (unsigned i = 0; i < propertyCount; i++) {
    130         CSSPropertyID property = properties[i];
    131         if (RuntimeCSSEnabled::isCSSPropertyEnabled(property))
    132             outVector.append(property);
    133     }
    134 }
    135 
    136 } // namespace WebCore
    137