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

Side by Side Diff: Source/core/editing/EditingStyle.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/StylePropertySet.cpp ('k') | Source/core/page/RuntimeCSSEnabled.h » ('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) 2007, 2008, 2009 Apple Computer, Inc. 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc.
3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "StyleResolver.h" 43 #include "StyleResolver.h"
44 #include "StyleRule.h" 44 #include "StyleRule.h"
45 #include "StyledElement.h" 45 #include "StyledElement.h"
46 #include "core/editing/ApplyStyleCommand.h" 46 #include "core/editing/ApplyStyleCommand.h"
47 #include "core/editing/Editor.h" 47 #include "core/editing/Editor.h"
48 #include "core/editing/FrameSelection.h" 48 #include "core/editing/FrameSelection.h"
49 #include "core/editing/HTMLInterchange.h" 49 #include "core/editing/HTMLInterchange.h"
50 #include "core/editing/VisibleUnits.h" 50 #include "core/editing/VisibleUnits.h"
51 #include "core/editing/htmlediting.h" 51 #include "core/editing/htmlediting.h"
52 #include "core/page/Frame.h" 52 #include "core/page/Frame.h"
53 #include "core/page/RuntimeCSSEnabled.h"
53 #include "core/rendering/style/RenderStyle.h" 54 #include "core/rendering/style/RenderStyle.h"
54 #include <wtf/HashSet.h> 55 #include <wtf/HashSet.h>
55 56
56 namespace WebCore { 57 namespace WebCore {
57 58
58 // Editing style properties must be preserved during editing operation. 59 // Editing style properties must be preserved during editing operation.
59 // e.g. when a user inserts a new paragraph, all properties listed here must be copied to the new paragraph. 60 // e.g. when a user inserts a new paragraph, all properties listed here must be copied to the new paragraph.
60 static const CSSPropertyID editingProperties[] = { 61 // NOTE: Use editingProperties() to respect runtime enabling of properties.
62 static const unsigned nonInheritedStaticPropertiesCount = 2;
63
64 static const CSSPropertyID staticEditingProperties[] = {
65 // NOTE: inheritableEditingProperties depends on these two properties being first.
66 // If you change this list, make sure to update nonInheritedPropertyCount.
61 CSSPropertyBackgroundColor, 67 CSSPropertyBackgroundColor,
62 CSSPropertyTextDecoration, 68 CSSPropertyTextDecoration,
63 69
64 // CSS inheritable properties 70 // CSS inheritable properties
65 CSSPropertyColor, 71 CSSPropertyColor,
66 CSSPropertyFontFamily, 72 CSSPropertyFontFamily,
67 CSSPropertyFontSize, 73 CSSPropertyFontSize,
68 CSSPropertyFontStyle, 74 CSSPropertyFontStyle,
69 CSSPropertyFontVariant, 75 CSSPropertyFontVariant,
70 CSSPropertyFontWeight, 76 CSSPropertyFontWeight,
71 CSSPropertyLetterSpacing, 77 CSSPropertyLetterSpacing,
72 CSSPropertyLineHeight, 78 CSSPropertyLineHeight,
73 CSSPropertyOrphans, 79 CSSPropertyOrphans,
74 CSSPropertyTextAlign, 80 CSSPropertyTextAlign,
75 CSSPropertyTextIndent, 81 CSSPropertyTextIndent,
76 CSSPropertyTextTransform, 82 CSSPropertyTextTransform,
77 CSSPropertyWhiteSpace, 83 CSSPropertyWhiteSpace,
78 CSSPropertyWidows, 84 CSSPropertyWidows,
79 CSSPropertyWordSpacing, 85 CSSPropertyWordSpacing,
80 CSSPropertyWebkitTextDecorationsInEffect, 86 CSSPropertyWebkitTextDecorationsInEffect,
81 CSSPropertyWebkitTextFillColor, 87 CSSPropertyWebkitTextFillColor,
82 CSSPropertyWebkitTextStrokeColor, 88 CSSPropertyWebkitTextStrokeColor,
83 CSSPropertyWebkitTextStrokeWidth, 89 CSSPropertyWebkitTextStrokeWidth,
84 }; 90 };
85 91
86 enum EditingPropertiesType { OnlyInheritableEditingProperties, AllEditingPropert ies }; 92 enum EditingPropertiesType { OnlyInheritableEditingProperties, AllEditingPropert ies };
87 93
94 static const Vector<CSSPropertyID>& allEditingProperties()
95 {
96 DEFINE_STATIC_LOCAL(Vector<CSSPropertyID>, properties, ());
97 if (properties.isEmpty())
98 RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(staticEditingPro perties, WTF_ARRAY_LENGTH(staticEditingProperties), properties);
99 return properties;
100 }
101
102 static const Vector<CSSPropertyID>& inheritableEditingProperties()
103 {
104 DEFINE_STATIC_LOCAL(Vector<CSSPropertyID>, properties, ());
105 if (properties.isEmpty())
106 RuntimeCSSEnabled::filterEnabledCSSPropertiesIntoVector(staticEditingPro perties + nonInheritedStaticPropertiesCount, WTF_ARRAY_LENGTH(staticEditingPrope rties) - nonInheritedStaticPropertiesCount, properties);
107 return properties;
108 }
109
88 template <class StyleDeclarationType> 110 template <class StyleDeclarationType>
89 static PassRefPtr<StylePropertySet> copyEditingProperties(StyleDeclarationType* style, EditingPropertiesType type = OnlyInheritableEditingProperties) 111 static PassRefPtr<StylePropertySet> copyEditingProperties(StyleDeclarationType* style, EditingPropertiesType type = OnlyInheritableEditingProperties)
90 { 112 {
91 if (type == AllEditingProperties) 113 if (type == AllEditingProperties)
92 return style->copyPropertiesInSet(editingProperties, WTF_ARRAY_LENGTH(ed itingProperties)); 114 return style->copyPropertiesInSet(allEditingProperties());
93 return style->copyPropertiesInSet(editingProperties + 2, WTF_ARRAY_LENGTH(ed itingProperties) - 2); 115 return style->copyPropertiesInSet(inheritableEditingProperties());
94 } 116 }
95 117
96 static inline bool isEditingProperty(int id) 118 static inline bool isEditingProperty(int id)
97 { 119 {
98 for (size_t i = 0; i < WTF_ARRAY_LENGTH(editingProperties); ++i) { 120 return allEditingProperties().contains(static_cast<CSSPropertyID>(id));
99 if (editingProperties[i] == id)
100 return true;
101 }
102 return false;
103 } 121 }
104 122
105 static PassRefPtr<StylePropertySet> editingStyleFromComputedStyle(PassRefPtr<CSS ComputedStyleDeclaration> style, EditingPropertiesType type = OnlyInheritableEdi tingProperties) 123 static PassRefPtr<StylePropertySet> editingStyleFromComputedStyle(PassRefPtr<CSS ComputedStyleDeclaration> style, EditingPropertiesType type = OnlyInheritableEdi tingProperties)
106 { 124 {
107 if (!style) 125 if (!style)
108 return StylePropertySet::create(); 126 return StylePropertySet::create();
109 return copyEditingProperties(style.get(), type); 127 return copyEditingProperties(style.get(), type);
110 } 128 }
111 129
112 static PassRefPtr<StylePropertySet> getPropertiesNotIn(StylePropertySet* styleWi thRedundantProperties, CSSStyleDeclaration* baseStyle); 130 static PassRefPtr<StylePropertySet> getPropertiesNotIn(StylePropertySet* styleWi thRedundantProperties, CSSStyleDeclaration* baseStyle);
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 { 1615 {
1598 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1616 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1599 RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl aration::create(ancestor); 1617 RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl aration::create(ancestor);
1600 if (!hasTransparentBackgroundColor(ancestorStyle.get())) 1618 if (!hasTransparentBackgroundColor(ancestorStyle.get()))
1601 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1619 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1602 } 1620 }
1603 return 0; 1621 return 0;
1604 } 1622 }
1605 1623
1606 } 1624 }
OLDNEW
« no previous file with comments | « Source/core/css/StylePropertySet.cpp ('k') | Source/core/page/RuntimeCSSEnabled.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698