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

Side by Side Diff: Source/core/css/resolver/StyleResolver.cpp

Issue 216803002: Implement all shorthand property. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "core/css/CSSDefaultStyleSheets.h" 44 #include "core/css/CSSDefaultStyleSheets.h"
45 #include "core/css/CSSFontSelector.h" 45 #include "core/css/CSSFontSelector.h"
46 #include "core/css/CSSKeyframeRule.h" 46 #include "core/css/CSSKeyframeRule.h"
47 #include "core/css/CSSKeyframesRule.h" 47 #include "core/css/CSSKeyframesRule.h"
48 #include "core/css/parser/BisonCSSParser.h" 48 #include "core/css/parser/BisonCSSParser.h"
49 #include "core/css/CSSReflectValue.h" 49 #include "core/css/CSSReflectValue.h"
50 #include "core/css/CSSRuleList.h" 50 #include "core/css/CSSRuleList.h"
51 #include "core/css/CSSSelector.h" 51 #include "core/css/CSSSelector.h"
52 #include "core/css/CSSStyleRule.h" 52 #include "core/css/CSSStyleRule.h"
53 #include "core/css/CSSValueList.h" 53 #include "core/css/CSSValueList.h"
54 #include "core/css/CSSValuePool.h"
54 #include "core/css/ElementRuleCollector.h" 55 #include "core/css/ElementRuleCollector.h"
55 #include "core/css/FontFace.h" 56 #include "core/css/FontFace.h"
56 #include "core/css/MediaQueryEvaluator.h" 57 #include "core/css/MediaQueryEvaluator.h"
57 #include "core/css/PageRuleCollector.h" 58 #include "core/css/PageRuleCollector.h"
58 #include "core/css/StylePropertySet.h" 59 #include "core/css/StylePropertySet.h"
59 #include "core/css/StyleRuleImport.h" 60 #include "core/css/StyleRuleImport.h"
60 #include "core/css/StyleSheetContents.h" 61 #include "core/css/StyleSheetContents.h"
61 #include "core/css/resolver/AnimatedStyleBuilder.h" 62 #include "core/css/resolver/AnimatedStyleBuilder.h"
62 #include "core/css/resolver/MatchResult.h" 63 #include "core/css/resolver/MatchResult.h"
63 #include "core/css/resolver/MediaQueryResult.h" 64 #include "core/css/resolver/MediaQueryResult.h"
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 // Properties that we currently support outside of spec. 1225 // Properties that we currently support outside of spec.
1225 case CSSPropertyWebkitLineBoxContain: 1226 case CSSPropertyWebkitLineBoxContain:
1226 case CSSPropertyVisibility: 1227 case CSSPropertyVisibility:
1227 return true; 1228 return true;
1228 1229
1229 default: 1230 default:
1230 return false; 1231 return false;
1231 } 1232 }
1232 } 1233 }
1233 1234
1235 template<> CSSPropertyID StyleResolver::firstCSSPropertyId<StyleResolver::Animat ionProperties>()
1236 {
1237 COMPILE_ASSERT(firstCSSProperty == CSSPropertyDisplay, CSS_first_animation_p roperty_should_be_first_property);
1238 return CSSPropertyDisplay;
esprehn 2014/06/12 00:36:45 These all need comments.
1239 }
1240
1241 template<> CSSPropertyID StyleResolver::lastCSSPropertyId<StyleResolver::Animati onProperties>()
1242 {
1243 return CSSPropertyTransitionTimingFunction;
1244 }
1245
1246 template<> CSSPropertyID StyleResolver::firstCSSPropertyId<StyleResolver::HighPr iorityProperties>()
1247 {
1248 COMPILE_ASSERT(CSSPropertyTransitionTimingFunction + 1 == CSSPropertyColor, CSS_color_is_first_high_priority_property);
1249 return CSSPropertyColor;
1250 }
1251
1252 template<> CSSPropertyID StyleResolver::lastCSSPropertyId<StyleResolver::HighPri orityProperties>()
1253 {
1254 COMPILE_ASSERT(CSSPropertyLineHeight == CSSPropertyColor + 17, CSS_line_heig ht_is_end_of_high_prioity_property_range);
1255 COMPILE_ASSERT(CSSPropertyZoom == CSSPropertyLineHeight - 1, CSS_zoom_is_bef ore_line_height);
1256 return CSSPropertyLineHeight;
1257 }
1258
1259 template<> CSSPropertyID StyleResolver::firstCSSPropertyId<StyleResolver::LowPri orityProperties>()
1260 {
1261 COMPILE_ASSERT(CSSPropertyBackground == CSSPropertyLineHeight + 1, CSS_backg round_is_first_low_priority_property);
1262 return CSSPropertyBackground;
1263 }
1264
1265 template<> CSSPropertyID StyleResolver::lastCSSPropertyId<StyleResolver::LowPrio rityProperties>()
1266 {
1267 return static_cast<CSSPropertyID>(lastCSSProperty);
esprehn 2014/06/12 00:36:45 Can you comment this?
1268 }
1269
1234 template <StyleResolver::StyleApplicationPass pass> 1270 template <StyleResolver::StyleApplicationPass pass>
1235 bool StyleResolver::isPropertyForPass(CSSPropertyID property) 1271 bool StyleResolver::isPropertyForPass(CSSPropertyID property)
1236 { 1272 {
1237 const CSSPropertyID firstAnimationProperty = CSSPropertyDisplay; 1273 return firstCSSPropertyId<pass>() <= property && property <= lastCSSProperty Id<pass>();
1238 const CSSPropertyID lastAnimationProperty = CSSPropertyTransitionTimingFunct ion;
1239 COMPILE_ASSERT(firstCSSProperty == firstAnimationProperty, CSS_first_animati on_property_should_be_first_property);
1240 const CSSPropertyID firstHighPriorityProperty = CSSPropertyColor;
1241 const CSSPropertyID lastHighPriorityProperty = CSSPropertyLineHeight;
1242 COMPILE_ASSERT(lastAnimationProperty + 1 == firstHighPriorityProperty, CSS_c olor_is_first_high_priority_property);
1243 COMPILE_ASSERT(CSSPropertyLineHeight == firstHighPriorityProperty + 17, CSS_ line_height_is_end_of_high_prioity_property_range);
1244 COMPILE_ASSERT(CSSPropertyZoom == lastHighPriorityProperty - 1, CSS_zoom_is_ before_line_height);
1245 switch (pass) {
1246 case AnimationProperties:
1247 return property >= firstAnimationProperty && property <= lastAnimationPr operty;
1248 case HighPriorityProperties:
1249 return property >= firstHighPriorityProperty && property <= lastHighPrio rityProperty;
1250 case LowPriorityProperties:
1251 return property > lastHighPriorityProperty;
1252 }
1253 ASSERT_NOT_REACHED();
1254 return false;
1255 } 1274 }
1256 1275
1257 template <StyleResolver::StyleApplicationPass pass> 1276 template <StyleResolver::StyleApplicationPass pass>
1277 void StyleResolver::applyAllProperty(StyleResolverState& state, CSSValue* allVal ue)
esprehn 2014/06/12 00:36:45 Your patch description needs to explain what this
1278 {
1279 bool isUnsetValue = !allValue->isInitialValue() && !allValue->isInheritedVal ue();
1280 unsigned startCSSProperty = firstCSSPropertyId<pass>();
1281 unsigned endCSSProperty = lastCSSPropertyId<pass>();
1282
1283 for (unsigned i = startCSSProperty; i <= endCSSProperty; ++i) {
1284 CSSPropertyID propertyId = static_cast<CSSPropertyID>(i);
1285
1286 // StyleBuilder does not allow any expanded shorthands.
1287 if (isExpandedShorthandForAll(propertyId))
1288 continue;
1289
1290 // all shorthand spec says:
1291 // The all property is a shorthand that resets all CSS properties
1292 // except direction and unicode-bidi.
1293 // c.f. http://dev.w3.org/csswg/css-cascade/#all-shorthand
1294 // We skip applyProperty when a given property is unicode-bidi or
1295 // direction.
1296 if (!CSSProperty::isAffectedByAllProperty(propertyId))
1297 continue;
1298
1299 CSSValue* value;
1300 if (!isUnsetValue) {
1301 value = allValue;
1302 } else {
1303 if (CSSProperty::isInheritedProperty(propertyId))
1304 value = cssValuePool().createInheritedValue().get();
1305 else
1306 value = cssValuePool().createExplicitInitialValue().get();
1307 }
1308 StyleBuilder::applyProperty(propertyId, state, value);
1309 }
1310 }
1311
1312 template <StyleResolver::StyleApplicationPass pass>
1258 void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper tySet* properties, StyleRule* rule, bool isImportant, bool inheritedOnly, Proper tyWhitelistType propertyWhitelistType) 1313 void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper tySet* properties, StyleRule* rule, bool isImportant, bool inheritedOnly, Proper tyWhitelistType propertyWhitelistType)
1259 { 1314 {
1260 state.setCurrentRule(rule); 1315 state.setCurrentRule(rule);
1261 1316
1262 unsigned propertyCount = properties->propertyCount(); 1317 unsigned propertyCount = properties->propertyCount();
1263 for (unsigned i = 0; i < propertyCount; ++i) { 1318 for (unsigned i = 0; i < propertyCount; ++i) {
1264 StylePropertySet::PropertyReference current = properties->propertyAt(i); 1319 StylePropertySet::PropertyReference current = properties->propertyAt(i);
1265 if (isImportant != current.isImportant()) 1320 if (isImportant != current.isImportant())
1266 continue; 1321 continue;
1322
1323 CSSPropertyID property = current.id();
1324 if (property == CSSPropertyAll) {
1325 applyAllProperty<pass>(state, current.value());
1326 continue;
1327 }
1328
1267 if (inheritedOnly && !current.isInherited()) { 1329 if (inheritedOnly && !current.isInherited()) {
1268 // If the property value is explicitly inherited, we need to apply f urther non-inherited properties 1330 // If the property value is explicitly inherited, we need to apply f urther non-inherited properties
1269 // as they might override the value inherited here. For this reason we don't allow declarations with 1331 // as they might override the value inherited here. For this reason we don't allow declarations with
1270 // explicitly inherited properties to be cached. 1332 // explicitly inherited properties to be cached.
1271 ASSERT(!current.value()->isInheritedValue()); 1333 ASSERT(!current.value()->isInheritedValue());
1272 continue; 1334 continue;
1273 } 1335 }
1274 CSSPropertyID property = current.id();
1275 1336
1276 if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStylePro perty(property)) 1337 if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStylePro perty(property))
1277 continue; 1338 continue;
1278 if (propertyWhitelistType == PropertyWhitelistFirstLetter && !isValidFir stLetterStyleProperty(property)) 1339 if (propertyWhitelistType == PropertyWhitelistFirstLetter && !isValidFir stLetterStyleProperty(property))
1279 continue; 1340 continue;
1280 if (!isPropertyForPass<pass>(property)) 1341 if (!isPropertyForPass<pass>(property))
1281 continue; 1342 continue;
1282 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight) 1343 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight)
1283 state.setLineHeightValue(current.value()); 1344 state.setLineHeightValue(current.value());
1284 else 1345 else
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 visitor->trace(m_viewportStyleResolver); 1568 visitor->trace(m_viewportStyleResolver);
1508 visitor->trace(m_features); 1569 visitor->trace(m_features);
1509 visitor->trace(m_siblingRuleSet); 1570 visitor->trace(m_siblingRuleSet);
1510 visitor->trace(m_uncommonAttributeRuleSet); 1571 visitor->trace(m_uncommonAttributeRuleSet);
1511 visitor->trace(m_watchedSelectorsRules); 1572 visitor->trace(m_watchedSelectorsRules);
1512 visitor->trace(m_treeBoundaryCrossingRules); 1573 visitor->trace(m_treeBoundaryCrossingRules);
1513 visitor->trace(m_pendingStyleSheets); 1574 visitor->trace(m_pendingStyleSheets);
1514 } 1575 }
1515 1576
1516 } // namespace WebCore 1577 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698