Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / css / RuntimeCSSEnabled.cpp
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 blink {
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 css3TextDecorationProperties[] = {
49         CSSPropertyTextDecorationColor,
50         CSSPropertyTextDecorationLine,
51         CSSPropertyTextDecorationStyle,
52         CSSPropertyTextUnderlinePosition,
53     };
54     setCSSPropertiesEnabled(css3TextDecorationProperties, WTF_ARRAY_LENGTH(css3TextDecorationProperties), RuntimeEnabledFeatures::css3TextDecorationsEnabled());
55     CSSPropertyID css3TextProperties[] = {
56         CSSPropertyTextAlignLast,
57         CSSPropertyTextJustify,
58     };
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,
70         CSSPropertyGridRow,
71         CSSPropertyGridArea,
72         CSSPropertyGridAutoFlow,
73         CSSPropertyGridTemplateAreas,
74         CSSPropertyGridTemplate,
75         CSSPropertyGrid,
76         CSSPropertyJustifySelf,
77         CSSPropertyJustifyItems
78     };
79     setCSSPropertiesEnabled(cssGridLayoutProperties, WTF_ARRAY_LENGTH(cssGridLayoutProperties), RuntimeEnabledFeatures::cssGridLayoutEnabled());
80     CSSPropertyID cssObjectFitPositionProperties[] = {
81         CSSPropertyObjectFit,
82         CSSPropertyObjectPosition
83     };
84     setCSSPropertiesEnabled(cssObjectFitPositionProperties, WTF_ARRAY_LENGTH(cssObjectFitPositionProperties), RuntimeEnabledFeatures::objectFitPositionEnabled());
85
86     CSSPropertyID animationProperties[] = {
87         CSSPropertyAnimation,
88         CSSPropertyAnimationName,
89         CSSPropertyAnimationDuration,
90         CSSPropertyAnimationTimingFunction,
91         CSSPropertyAnimationDelay,
92         CSSPropertyAnimationIterationCount,
93         CSSPropertyAnimationDirection,
94         CSSPropertyAnimationFillMode,
95         CSSPropertyAnimationPlayState
96     };
97     setCSSPropertiesEnabled(animationProperties, WTF_ARRAY_LENGTH(animationProperties), RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled());
98
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());
106
107     // InternalCallback is an implementation detail, rather than an experimental feature, and should never be exposed to the web.
108     RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyInternalCallback, false);
109 }
110
111 static CSSPropertySwitches& propertySwitches()
112 {
113     static CSSPropertySwitches* switches = 0;
114     if (!switches) {
115         switches = new CSSPropertySwitches(true); // All bits sets to 1.
116         setPropertySwitchesFromRuntimeFeatures();
117     }
118     return *switches;
119 }
120
121 size_t indexForProperty(CSSPropertyID propertyId)
122 {
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);
126 }
127
128 bool RuntimeCSSEnabled::isCSSPropertyEnabled(CSSPropertyID propertyId)
129 {
130     // Internal properties shouldn't be exposed to the web
131     // so they are considered to be always disabled.
132     if (isInternalProperty(propertyId))
133         return false;
134
135     return propertySwitches().get(indexForProperty(propertyId));
136 }
137
138 void RuntimeCSSEnabled::setCSSPropertyEnabled(CSSPropertyID propertyId, bool enable)
139 {
140     size_t propertyIndex = indexForProperty(propertyId);
141     if (enable)
142         propertySwitches().set(propertyIndex);
143     else
144         propertySwitches().clear(propertyIndex);
145 }
146
147 void RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(const CSSPropertyID* properties, size_t propertyCount, Vector<CSSPropertyID>& outVector)
148 {
149     for (unsigned i = 0; i < propertyCount; i++) {
150         CSSPropertyID property = properties[i];
151         if (RuntimeCSSEnabled::isCSSPropertyEnabled(property))
152             outVector.append(property);
153     }
154 }
155
156 } // namespace blink