Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: Source/core/css/CSSComputedStyleDeclaration.cpp

Issue 14324009: Add support for disabling CSS Properties at runtime (Closed) Base URL: http://src.chromium.org/blink/trunk/Source/
Patch Set: Runtime guard more uses of CSSPropertyID, per Elliot's request. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/CSSComputedStyleDeclaration.h ('k') | Source/core/css/CSSParser.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004 Zack Rusin <zack@kde.org> 2 * Copyright (C) 2004 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2011 Sencha, Inc. All rights reserved. 6 * Copyright (C) 2011 Sencha, Inc. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "PseudoElement.h" 48 #include "PseudoElement.h"
49 #include "Rect.h" 49 #include "Rect.h"
50 #include "ShadowValue.h" 50 #include "ShadowValue.h"
51 #include "StylePropertySet.h" 51 #include "StylePropertySet.h"
52 #include "StylePropertyShorthand.h" 52 #include "StylePropertyShorthand.h"
53 #include "StyleResolver.h" 53 #include "StyleResolver.h"
54 #include "WebCoreMemoryInstrumentation.h" 54 #include "WebCoreMemoryInstrumentation.h"
55 #include "WebKitCSSTransformValue.h" 55 #include "WebKitCSSTransformValue.h"
56 #include "WebKitFontFamilyNames.h" 56 #include "WebKitFontFamilyNames.h"
57 #include "core/page/animation/AnimationController.h" 57 #include "core/page/animation/AnimationController.h"
58 #include "core/page/RuntimeCSSEnabled.h"
58 #include "core/platform/graphics/FontFeatureSettings.h" 59 #include "core/platform/graphics/FontFeatureSettings.h"
59 #include "core/rendering/RenderBox.h" 60 #include "core/rendering/RenderBox.h"
60 #include "core/rendering/RenderView.h" 61 #include "core/rendering/RenderView.h"
61 #include "core/rendering/style/BasicShapes.h" 62 #include "core/rendering/style/BasicShapes.h"
62 #include "core/rendering/style/ContentData.h" 63 #include "core/rendering/style/ContentData.h"
63 #include "core/rendering/style/CounterContent.h" 64 #include "core/rendering/style/CounterContent.h"
64 #include "core/rendering/style/CursorList.h" 65 #include "core/rendering/style/CursorList.h"
65 #include "core/rendering/style/RenderStyle.h" 66 #include "core/rendering/style/RenderStyle.h"
66 #include "core/rendering/style/StyleInheritedData.h" 67 #include "core/rendering/style/StyleInheritedData.h"
67 #include <wtf/text/StringBuilder.h> 68 #include <wtf/text/StringBuilder.h>
68 69
69 #if ENABLE(CSS_EXCLUSIONS) 70 #if ENABLE(CSS_EXCLUSIONS)
70 #include "core/rendering/style/ExclusionShapeValue.h" 71 #include "core/rendering/style/ExclusionShapeValue.h"
71 #endif 72 #endif
72 73
73 #include "WebKitCSSArrayFunctionValue.h" 74 #include "WebKitCSSArrayFunctionValue.h"
74 #include "WebKitCSSMixFunctionValue.h" 75 #include "WebKitCSSMixFunctionValue.h"
75 #include "core/platform/graphics/filters/custom/CustomFilterArrayParameter.h" 76 #include "core/platform/graphics/filters/custom/CustomFilterArrayParameter.h"
76 #include "core/platform/graphics/filters/custom/CustomFilterNumberParameter.h" 77 #include "core/platform/graphics/filters/custom/CustomFilterNumberParameter.h"
77 #include "core/platform/graphics/filters/custom/CustomFilterOperation.h" 78 #include "core/platform/graphics/filters/custom/CustomFilterOperation.h"
78 #include "core/platform/graphics/filters/custom/CustomFilterParameter.h" 79 #include "core/platform/graphics/filters/custom/CustomFilterParameter.h"
79 #include "core/platform/graphics/filters/custom/CustomFilterTransformParameter.h " 80 #include "core/platform/graphics/filters/custom/CustomFilterTransformParameter.h "
80 81
81 #include "WebKitCSSFilterValue.h" 82 #include "WebKitCSSFilterValue.h"
82 #include "core/rendering/style/StyleCustomFilterProgram.h" 83 #include "core/rendering/style/StyleCustomFilterProgram.h"
83 84
84 namespace WebCore { 85 namespace WebCore {
85 86
86 // List of all properties we know how to compute, omitting shorthands. 87 // List of all properties we know how to compute, omitting shorthands.
87 static const CSSPropertyID computedProperties[] = { 88 // NOTE: Do not use this list, use computableProperties() instead
89 // to respect runtime enabling of CSS properties.
90 static const CSSPropertyID staticComputableProperties[] = {
88 CSSPropertyBackgroundAttachment, 91 CSSPropertyBackgroundAttachment,
89 #if ENABLE(CSS_COMPOSITING) 92 #if ENABLE(CSS_COMPOSITING)
90 CSSPropertyBackgroundBlendMode, 93 CSSPropertyBackgroundBlendMode,
91 #endif 94 #endif
92 CSSPropertyBackgroundClip, 95 CSSPropertyBackgroundClip,
93 CSSPropertyBackgroundColor, 96 CSSPropertyBackgroundColor,
94 CSSPropertyBackgroundImage, 97 CSSPropertyBackgroundImage,
95 CSSPropertyBackgroundOrigin, 98 CSSPropertyBackgroundOrigin,
96 CSSPropertyBackgroundPosition, // more-specific background-position-x/y are non-standard 99 CSSPropertyBackgroundPosition, // more-specific background-position-x/y are non-standard
97 CSSPropertyBackgroundRepeat, 100 CSSPropertyBackgroundRepeat,
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 CSSPropertyKerning, 399 CSSPropertyKerning,
397 CSSPropertyTextAnchor, 400 CSSPropertyTextAnchor,
398 CSSPropertyWritingMode, 401 CSSPropertyWritingMode,
399 CSSPropertyGlyphOrientationHorizontal, 402 CSSPropertyGlyphOrientationHorizontal,
400 CSSPropertyGlyphOrientationVertical, 403 CSSPropertyGlyphOrientationVertical,
401 CSSPropertyWebkitSvgShadow, 404 CSSPropertyWebkitSvgShadow,
402 CSSPropertyVectorEffect 405 CSSPropertyVectorEffect
403 #endif 406 #endif
404 }; 407 };
405 408
406 const unsigned numComputedProperties = WTF_ARRAY_LENGTH(computedProperties); 409 static const Vector<CSSPropertyID>& computableProperties()
410 {
411 DEFINE_STATIC_LOCAL(Vector<CSSPropertyID>, properties, ());
412 if (properties.isEmpty())
413 RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(staticComputable Properties, WTF_ARRAY_LENGTH(staticComputableProperties), properties);
414 return properties;
415 }
407 416
408 static int valueForRepeatRule(int rule) 417 static int valueForRepeatRule(int rule)
409 { 418 {
410 switch (rule) { 419 switch (rule) {
411 case RepeatImageRule: 420 case RepeatImageRule:
412 return CSSValueRepeat; 421 return CSSValueRepeat;
413 case RoundImageRule: 422 case RoundImageRule:
414 return CSSValueRound; 423 return CSSValueRound;
415 case SpaceImageRule: 424 case SpaceImageRule:
416 return CSSValueSpace; 425 return CSSValueSpace;
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 void CSSComputedStyleDeclaration::deref() 1184 void CSSComputedStyleDeclaration::deref()
1176 { 1185 {
1177 ASSERT(m_refCount); 1186 ASSERT(m_refCount);
1178 if (!--m_refCount) 1187 if (!--m_refCount)
1179 delete this; 1188 delete this;
1180 } 1189 }
1181 1190
1182 String CSSComputedStyleDeclaration::cssText() const 1191 String CSSComputedStyleDeclaration::cssText() const
1183 { 1192 {
1184 StringBuilder result; 1193 StringBuilder result;
1194 const Vector<CSSPropertyID>& properties = computableProperties();
1185 1195
1186 for (unsigned i = 0; i < numComputedProperties; i++) { 1196 for (unsigned i = 0; i < properties.size(); i++) {
1187 if (i) 1197 if (i)
1188 result.append(' '); 1198 result.append(' ');
1189 result.append(getPropertyName(computedProperties[i])); 1199 result.append(getPropertyName(properties[i]));
1190 result.append(": ", 2); 1200 result.append(": ", 2);
1191 result.append(getPropertyValue(computedProperties[i])); 1201 result.append(getPropertyValue(properties[i]));
1192 result.append(';'); 1202 result.append(';');
1193 } 1203 }
1194 1204
1195 return result.toString(); 1205 return result.toString();
1196 } 1206 }
1197 1207
1198 void CSSComputedStyleDeclaration::setCssText(const String&, ExceptionCode& ec) 1208 void CSSComputedStyleDeclaration::setCssText(const String&, ExceptionCode& ec)
1199 { 1209 {
1200 ec = NO_MODIFICATION_ALLOWED_ERR; 1210 ec = NO_MODIFICATION_ALLOWED_ERR;
1201 } 1211 }
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after
2812 unsigned CSSComputedStyleDeclaration::length() const 2822 unsigned CSSComputedStyleDeclaration::length() const
2813 { 2823 {
2814 Node* node = m_node.get(); 2824 Node* node = m_node.get();
2815 if (!node) 2825 if (!node)
2816 return 0; 2826 return 0;
2817 2827
2818 RenderStyle* style = node->computedStyle(m_pseudoElementSpecifier); 2828 RenderStyle* style = node->computedStyle(m_pseudoElementSpecifier);
2819 if (!style) 2829 if (!style)
2820 return 0; 2830 return 0;
2821 2831
2822 return numComputedProperties; 2832 return computableProperties().size();
2823 } 2833 }
2824 2834
2825 String CSSComputedStyleDeclaration::item(unsigned i) const 2835 String CSSComputedStyleDeclaration::item(unsigned i) const
2826 { 2836 {
2827 if (i >= length()) 2837 if (i >= length())
2828 return ""; 2838 return "";
2829 2839
2830 return getPropertyNameString(computedProperties[i]); 2840 return getPropertyNameString(computableProperties()[i]);
2831 } 2841 }
2832 2842
2833 bool CSSComputedStyleDeclaration::cssPropertyMatches(CSSPropertyID propertyID, c onst CSSValue* propertyValue) const 2843 bool CSSComputedStyleDeclaration::cssPropertyMatches(CSSPropertyID propertyID, c onst CSSValue* propertyValue) const
2834 { 2844 {
2835 if (propertyID == CSSPropertyFontSize && propertyValue->isPrimitiveValue() & & m_node) { 2845 if (propertyID == CSSPropertyFontSize && propertyValue->isPrimitiveValue() & & m_node) {
2836 m_node->document()->updateLayoutIgnorePendingStylesheets(); 2846 m_node->document()->updateLayoutIgnorePendingStylesheets();
2837 RenderStyle* style = m_node->computedStyle(m_pseudoElementSpecifier); 2847 RenderStyle* style = m_node->computedStyle(m_pseudoElementSpecifier);
2838 if (style && style->fontDescription().keywordSize()) { 2848 if (style && style->fontDescription().keywordSize()) {
2839 int sizeValue = cssIdentifierForFontSizeKeyword(style->fontDescripti on().keywordSize()); 2849 int sizeValue = cssIdentifierForFontSizeKeyword(style->fontDescripti on().keywordSize());
2840 const CSSPrimitiveValue* primitiveValue = static_cast<const CSSPrimi tiveValue*>(propertyValue); 2850 const CSSPrimitiveValue* primitiveValue = static_cast<const CSSPrimi tiveValue*>(propertyValue);
2841 if (primitiveValue->isIdent() && primitiveValue->getIdent() == sizeV alue) 2851 if (primitiveValue->isIdent() && primitiveValue->getIdent() == sizeV alue)
2842 return true; 2852 return true;
2843 } 2853 }
2844 } 2854 }
2845 RefPtr<CSSValue> value = getPropertyCSSValue(propertyID); 2855 RefPtr<CSSValue> value = getPropertyCSSValue(propertyID);
2846 return value && propertyValue && value->equals(*propertyValue); 2856 return value && propertyValue && value->equals(*propertyValue);
2847 } 2857 }
2848 2858
2849 PassRefPtr<StylePropertySet> CSSComputedStyleDeclaration::copy() const 2859 PassRefPtr<StylePropertySet> CSSComputedStyleDeclaration::copy() const
2850 { 2860 {
2851 return copyPropertiesInSet(computedProperties, numComputedProperties); 2861 return copyPropertiesInSet(computableProperties());
2852 } 2862 }
2853 2863
2854 PassRefPtr<CSSValueList> CSSComputedStyleDeclaration::getCSSPropertyValuesForSho rthandProperties(const StylePropertyShorthand& shorthand) const 2864 PassRefPtr<CSSValueList> CSSComputedStyleDeclaration::getCSSPropertyValuesForSho rthandProperties(const StylePropertyShorthand& shorthand) const
2855 { 2865 {
2856 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated(); 2866 RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
2857 for (size_t i = 0; i < shorthand.length(); ++i) { 2867 for (size_t i = 0; i < shorthand.length(); ++i) {
2858 RefPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i], DoNotUpdateLayout); 2868 RefPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i], DoNotUpdateLayout);
2859 list->append(value); 2869 list->append(value);
2860 } 2870 }
2861 return list.release(); 2871 return list.release();
(...skipping 30 matching lines...) Expand all
2892 PassRefPtr<CSSValueList> CSSComputedStyleDeclaration::getCSSPropertyValuesForGri dShorthand(const StylePropertyShorthand& shorthand) const 2902 PassRefPtr<CSSValueList> CSSComputedStyleDeclaration::getCSSPropertyValuesForGri dShorthand(const StylePropertyShorthand& shorthand) const
2893 { 2903 {
2894 RefPtr<CSSValueList> list = CSSValueList::createSlashSeparated(); 2904 RefPtr<CSSValueList> list = CSSValueList::createSlashSeparated();
2895 for (size_t i = 0; i < shorthand.length(); ++i) { 2905 for (size_t i = 0; i < shorthand.length(); ++i) {
2896 RefPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i], DoNotUpdateLayout); 2906 RefPtr<CSSValue> value = getPropertyCSSValue(shorthand.properties()[i], DoNotUpdateLayout);
2897 list->append(value); 2907 list->append(value);
2898 } 2908 }
2899 return list.release(); 2909 return list.release();
2900 } 2910 }
2901 2911
2902 PassRefPtr<StylePropertySet> CSSComputedStyleDeclaration::copyPropertiesInSet(co nst CSSPropertyID* set, unsigned length) const 2912 PassRefPtr<StylePropertySet> CSSComputedStyleDeclaration::copyPropertiesInSet(co nst Vector<CSSPropertyID>& properties) const
2903 { 2913 {
2904 Vector<CSSProperty, 256> list; 2914 Vector<CSSProperty, 256> list;
2905 list.reserveInitialCapacity(length); 2915 list.reserveInitialCapacity(properties.size());
2906 for (unsigned i = 0; i < length; ++i) { 2916 for (unsigned i = 0; i < properties.size(); ++i) {
2907 RefPtr<CSSValue> value = getPropertyCSSValue(set[i]); 2917 RefPtr<CSSValue> value = getPropertyCSSValue(properties[i]);
2908 if (value) 2918 if (value)
2909 list.append(CSSProperty(set[i], value.release(), false)); 2919 list.append(CSSProperty(properties[i], value.release(), false));
2910 } 2920 }
2911 return StylePropertySet::create(list.data(), list.size()); 2921 return StylePropertySet::create(list.data(), list.size());
2912 } 2922 }
2913 2923
2914 void CSSComputedStyleDeclaration::reportMemoryUsage(MemoryObjectInfo* memoryObje ctInfo) const 2924 void CSSComputedStyleDeclaration::reportMemoryUsage(MemoryObjectInfo* memoryObje ctInfo) const
2915 { 2925 {
2916 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS); 2926 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
2917 info.addMember(m_node, "node"); 2927 info.addMember(m_node, "node");
2918 } 2928 }
2919 2929
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
2989 static const CSSPropertyID propertiesAfterSlashSeperator[3] = { CSSPropertyB ackgroundSize, CSSPropertyBackgroundOrigin, 2999 static const CSSPropertyID propertiesAfterSlashSeperator[3] = { CSSPropertyB ackgroundSize, CSSPropertyBackgroundOrigin,
2990 CSSPropertyB ackgroundClip }; 3000 CSSPropertyB ackgroundClip };
2991 3001
2992 RefPtr<CSSValueList> list = CSSValueList::createSlashSeparated(); 3002 RefPtr<CSSValueList> list = CSSValueList::createSlashSeparated();
2993 list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShortha nd(propertiesBeforeSlashSeperator, WTF_ARRAY_LENGTH(propertiesBeforeSlashSeperat or)))); 3003 list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShortha nd(propertiesBeforeSlashSeperator, WTF_ARRAY_LENGTH(propertiesBeforeSlashSeperat or))));
2994 list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShortha nd(propertiesAfterSlashSeperator, WTF_ARRAY_LENGTH(propertiesAfterSlashSeperator )))); 3004 list->append(getCSSPropertyValuesForShorthandProperties(StylePropertyShortha nd(propertiesAfterSlashSeperator, WTF_ARRAY_LENGTH(propertiesAfterSlashSeperator ))));
2995 return list.release(); 3005 return list.release();
2996 } 3006 }
2997 3007
2998 } // namespace WebCore 3008 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/CSSComputedStyleDeclaration.h ('k') | Source/core/css/CSSParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698