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

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

Issue 21625003: StyleBuilder should not know about StyleResolver. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 // FIXME: Can't keyframes contain variables? 657 // FIXME: Can't keyframes contain variables?
658 applyMatchedProperties<AnimationProperties>(state, result, false, 0, res ult.matchedProperties.size() - 1, inheritedOnly); 658 applyMatchedProperties<AnimationProperties>(state, result, false, 0, res ult.matchedProperties.size() - 1, inheritedOnly);
659 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly); 659 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
660 } 660 }
661 661
662 // If our font got dirtied, go ahead and update it now. 662 // If our font got dirtied, go ahead and update it now.
663 updateFont(state); 663 updateFont(state);
664 664
665 // Line-height is set when we are sure we decided on the font-size 665 // Line-height is set when we are sure we decided on the font-size
666 if (state.lineHeightValue()) 666 if (state.lineHeightValue())
667 applyProperty(state, CSSPropertyLineHeight, state.lineHeightValue()); 667 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
668 668
669 // Now do rest of the properties. 669 // Now do rest of the properties.
670 if (keyframe->properties()) 670 if (keyframe->properties())
671 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, r esult.matchedProperties.size() - 1, inheritedOnly); 671 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, r esult.matchedProperties.size() - 1, inheritedOnly);
672 672
673 // If our font got dirtied by one of the non-essential font props, 673 // If our font got dirtied by one of the non-essential font props,
674 // go ahead and update it a second time. 674 // go ahead and update it a second time.
675 updateFont(state); 675 updateFont(state);
676 676
677 // Start loading resources referenced by this style. 677 // Start loading resources referenced by this style.
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 851
852 MatchResult& result = collector.matchedResult(); 852 MatchResult& result = collector.matchedResult();
853 applyMatchedProperties<VariableDefinitions>(state, result, false, 0, result. matchedProperties.size() - 1, inheritedOnly); 853 applyMatchedProperties<VariableDefinitions>(state, result, false, 0, result. matchedProperties.size() - 1, inheritedOnly);
854 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu lt.matchedProperties.size() - 1, inheritedOnly); 854 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu lt.matchedProperties.size() - 1, inheritedOnly);
855 855
856 // If our font got dirtied, go ahead and update it now. 856 // If our font got dirtied, go ahead and update it now.
857 updateFont(state); 857 updateFont(state);
858 858
859 // Line-height is set when we are sure we decided on the font-size. 859 // Line-height is set when we are sure we decided on the font-size.
860 if (state.lineHeightValue()) 860 if (state.lineHeightValue())
861 applyProperty(state, CSSPropertyLineHeight, state.lineHeightValue()); 861 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
862 862
863 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul t.matchedProperties.size() - 1, inheritedOnly); 863 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul t.matchedProperties.size() - 1, inheritedOnly);
864 864
865 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); 865 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features);
866 866
867 // Start loading resources referenced by this style. 867 // Start loading resources referenced by this style.
868 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources()); 868 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
869 869
870 document()->didAccessStyleResolver(); 870 document()->didAccessStyleResolver();
871 871
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 CSSPropertyID property = iter->key; 1004 CSSPropertyID property = iter->key;
1005 if (!isPropertyForPass<pass>(property)) 1005 if (!isPropertyForPass<pass>(property))
1006 continue; 1006 continue;
1007 RefPtr<AnimatableValue> animatableValue = iter->value->compositeOnto (AnimatableValue::neutralValue()); 1007 RefPtr<AnimatableValue> animatableValue = iter->value->compositeOnto (AnimatableValue::neutralValue());
1008 if (animatableValue->isDeferredSnapshot()) 1008 if (animatableValue->isDeferredSnapshot())
1009 continue; 1009 continue;
1010 RefPtr<CSSValue> cssValue = animatableValue->toCSSValue(); 1010 RefPtr<CSSValue> cssValue = animatableValue->toCSSValue();
1011 if (pass == HighPriorityProperties && property == CSSPropertyLineHei ght) 1011 if (pass == HighPriorityProperties && property == CSSPropertyLineHei ght)
1012 state.setLineHeightValue(cssValue.get()); 1012 state.setLineHeightValue(cssValue.get());
1013 else 1013 else
1014 applyProperty(state, property, cssValue.get()); 1014 StyleBuilder::applyProperty(property, state, cssValue.get());
1015 } 1015 }
1016 } 1016 }
1017 } 1017 }
1018 1018
1019 static inline bool isValidVisitedLinkProperty(CSSPropertyID id)
1020 {
1021 switch (id) {
1022 case CSSPropertyBackgroundColor:
1023 case CSSPropertyBorderLeftColor:
1024 case CSSPropertyBorderRightColor:
1025 case CSSPropertyBorderTopColor:
1026 case CSSPropertyBorderBottomColor:
1027 case CSSPropertyColor:
1028 case CSSPropertyFill:
1029 case CSSPropertyOutlineColor:
1030 case CSSPropertyStroke:
1031 case CSSPropertyTextDecorationColor:
1032 case CSSPropertyWebkitColumnRuleColor:
1033 case CSSPropertyWebkitTextEmphasisColor:
1034 case CSSPropertyWebkitTextFillColor:
1035 case CSSPropertyWebkitTextStrokeColor:
1036 return true;
1037 default:
1038 break;
1039 }
1040
1041 return false;
1042 }
1043
1044 // http://dev.w3.org/csswg/css3-regions/#the-at-region-style-rule 1019 // http://dev.w3.org/csswg/css3-regions/#the-at-region-style-rule
1045 // FIXME: add incremental support for other region styling properties. 1020 // FIXME: add incremental support for other region styling properties.
1046 static inline bool isValidRegionStyleProperty(CSSPropertyID id) 1021 static inline bool isValidRegionStyleProperty(CSSPropertyID id)
1047 { 1022 {
1048 switch (id) { 1023 switch (id) {
1049 case CSSPropertyBackgroundColor: 1024 case CSSPropertyBackgroundColor:
1050 case CSSPropertyColor: 1025 case CSSPropertyColor:
1051 return true; 1026 return true;
1052 default: 1027 default:
1053 break; 1028 break;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 1126
1152 if (propertyWhitelistType == PropertyWhitelistRegion && !isValidRegionSt yleProperty(property)) 1127 if (propertyWhitelistType == PropertyWhitelistRegion && !isValidRegionSt yleProperty(property))
1153 continue; 1128 continue;
1154 if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStylePro perty(property)) 1129 if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStylePro perty(property))
1155 continue; 1130 continue;
1156 if (!isPropertyForPass<pass>(property)) 1131 if (!isPropertyForPass<pass>(property))
1157 continue; 1132 continue;
1158 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight) 1133 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight)
1159 state.setLineHeightValue(current.value()); 1134 state.setLineHeightValue(current.value());
1160 else 1135 else
1161 applyProperty(state, current.id(), current.value()); 1136 StyleBuilder::applyProperty(current.id(), state, current.value());
1162 } 1137 }
1163 } 1138 }
1164 1139
1165 template <StyleResolver::StyleApplicationPass pass> 1140 template <StyleResolver::StyleApplicationPass pass>
1166 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult, bool isImportant, int startIndex, int endIndex, bool inher itedOnly) 1141 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult, bool isImportant, int startIndex, int endIndex, bool inher itedOnly)
1167 { 1142 {
1168 if (startIndex == -1) 1143 if (startIndex == -1)
1169 return; 1144 return;
1170 1145
1171 if (state.style()->insideLink() != NotInsideLink) { 1146 if (state.style()->insideLink() != NotInsideLink) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->effecti veZoom() != state.style()->effectiveZoom()) { 1234 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->effecti veZoom() != state.style()->effectiveZoom()) {
1260 state.fontBuilder().setFontDirty(true); 1235 state.fontBuilder().setFontDirty(true);
1261 applyInheritedOnly = false; 1236 applyInheritedOnly = false;
1262 } 1237 }
1263 1238
1264 // If our font got dirtied, go ahead and update it now. 1239 // If our font got dirtied, go ahead and update it now.
1265 updateFont(state); 1240 updateFont(state);
1266 1241
1267 // Line-height is set when we are sure we decided on the font-size. 1242 // Line-height is set when we are sure we decided on the font-size.
1268 if (state.lineHeightValue()) 1243 if (state.lineHeightValue())
1269 applyProperty(state, CSSPropertyLineHeight, state.lineHeightValue()); 1244 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
1270 1245
1271 // Many properties depend on the font. If it changes we just apply all prope rties. 1246 // Many properties depend on the font. If it changes we just apply all prope rties.
1272 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDes cription() != state.style()->fontDescription()) 1247 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDes cription() != state.style()->fontDescription())
1273 applyInheritedOnly = false; 1248 applyInheritedOnly = false;
1274 1249
1275 // Now do the normal priority UA properties. 1250 // Now do the normal priority UA properties.
1276 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, mat chResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); 1251 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, mat chResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1277 1252
1278 // Cache the UA properties to pass them to RenderTheme in adjustRenderStyle. 1253 // Cache the UA properties to pass them to RenderTheme in adjustRenderStyle.
1279 state.cacheUserAgentBorderAndBackground(); 1254 state.cacheUserAgentBorderAndBackground();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 // which assumes the fontMetrics are available for the affected font , otherwise a crash occurs (see http://trac.webkit.org/changeset/96122). 1296 // which assumes the fontMetrics are available for the affected font , otherwise a crash occurs (see http://trac.webkit.org/changeset/96122).
1322 // The updateFont() call below updates the fontMetrics and ensure th e proper setting of font-size and line-height. 1297 // The updateFont() call below updates the fontMetrics and ensure th e proper setting of font-size and line-height.
1323 switch (properties[i].property) { 1298 switch (properties[i].property) {
1324 case CSSPropertyFontSize: 1299 case CSSPropertyFontSize:
1325 case CSSPropertyLineHeight: 1300 case CSSPropertyLineHeight:
1326 updateFont(state); 1301 updateFont(state);
1327 break; 1302 break;
1328 default: 1303 default:
1329 break; 1304 break;
1330 } 1305 }
1331 applyProperty(state, properties[i].property, properties[i].value); 1306 StyleBuilder::applyProperty(properties[i].property, state, propertie s[i].value);
1332 } 1307 }
1333 } 1308 }
1334 } 1309 }
1335 1310
1336 static bool hasVariableReference(CSSValue* value)
1337 {
1338 if (value->isPrimitiveValue()) {
1339 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
1340 return primitiveValue->hasVariableReference();
1341 }
1342
1343 if (value->isCalculationValue())
1344 return static_cast<CSSCalcValue*>(value)->hasVariableReference();
1345
1346 if (value->isReflectValue()) {
1347 CSSReflectValue* reflectValue = static_cast<CSSReflectValue*>(value);
1348 CSSPrimitiveValue* direction = reflectValue->direction();
1349 CSSPrimitiveValue* offset = reflectValue->offset();
1350 CSSValue* mask = reflectValue->mask();
1351 return (direction && hasVariableReference(direction)) || (offset && hasV ariableReference(offset)) || (mask && hasVariableReference(mask));
1352 }
1353
1354 for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
1355 if (hasVariableReference(i.value()))
1356 return true;
1357 }
1358
1359 return false;
1360 }
1361
1362 void StyleResolver::resolveVariables(StyleResolverState& state, CSSPropertyID id , CSSValue* value, Vector<std::pair<CSSPropertyID, String> >& knownExpressions)
1363 {
1364 std::pair<CSSPropertyID, String> expression(id, value->serializeResolvingVar iables(*state.style()->variables()));
1365
1366 if (knownExpressions.contains(expression))
1367 return; // cycle detected.
1368
1369 knownExpressions.append(expression);
1370
1371 // FIXME: It would be faster not to re-parse from strings, but for now CSS p roperty validation lives inside the parser so we do it there.
1372 RefPtr<MutableStylePropertySet> resultSet = MutableStylePropertySet::create( );
1373 if (!CSSParser::parseValue(resultSet.get(), id, expression.second, false, do cument()))
1374 return; // expression failed to parse.
1375
1376 for (unsigned i = 0; i < resultSet->propertyCount(); i++) {
1377 StylePropertySet::PropertyReference property = resultSet->propertyAt(i);
1378 if (property.id() != CSSPropertyVariable && hasVariableReference(propert y.value())) {
1379 resolveVariables(state, property.id(), property.value(), knownExpres sions);
1380 } else {
1381 applyProperty(state, property.id(), property.value());
1382 // All properties become dependent on their parent style when they u se variables.
1383 state.style()->setHasExplicitlyInheritedProperties();
1384 }
1385 }
1386 }
1387
1388 void StyleResolver::applyProperty(StyleResolverState& state, CSSPropertyID id, C SSValue* value)
1389 {
1390 if (id != CSSPropertyVariable && hasVariableReference(value)) {
1391 Vector<std::pair<CSSPropertyID, String> > knownExpressions;
1392 resolveVariables(state, id, value, knownExpressions);
1393 return;
1394 }
1395
1396 // CSS variables don't resolve shorthands at parsing time, so this should be *after* handling variables.
1397 ASSERT_WITH_MESSAGE(!isExpandedShorthand(id), "Shorthand property id = %d wa sn't expanded at parsing time", id);
1398
1399 bool isInherit = state.parentNode() && value->isInheritedValue();
1400 bool isInitial = value->isInitialValue() || (!state.parentNode() && value->i sInheritedValue());
1401
1402 ASSERT(!isInherit || !isInitial); // isInherit -> !isInitial && isInitial -> !isInherit
1403 ASSERT(!isInherit || (state.parentNode() && state.parentStyle())); // isInhe rit -> (state.parentNode() && state.parentStyle())
1404
1405 if (!state.applyPropertyToRegularStyle() && (!state.applyPropertyToVisitedLi nkStyle() || !isValidVisitedLinkProperty(id))) {
1406 // Limit the properties that can be applied to only the ones honored by :visited.
1407 return;
1408 }
1409
1410 if (isInherit && !state.parentStyle()->hasExplicitlyInheritedProperties() && !CSSProperty::isInheritedProperty(id))
1411 state.parentStyle()->setHasExplicitlyInheritedProperties();
1412
1413 if (id == CSSPropertyVariable) {
1414 ASSERT_WITH_SECURITY_IMPLICATION(value->isVariableValue());
1415 CSSVariableValue* variable = toCSSVariableValue(value);
1416 ASSERT(!variable->name().isEmpty());
1417 ASSERT(!variable->value().isEmpty());
1418 state.style()->setVariable(variable->name(), variable->value());
1419 return;
1420 }
1421
1422 if (StyleBuilder::applyProperty(id, this, state, value, isInitial, isInherit ))
1423 return;
1424
1425 // Fall back to the old switch statement, which is now in StyleBuilderCustom .cpp
1426 StyleBuilder::oldApplyProperty(id, this, state, value, isInitial, isInherit) ;
1427 }
1428
1429 void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp* ex pr, bool result) 1311 void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp* ex pr, bool result)
1430 { 1312 {
1431 m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*e xpr, result))); 1313 m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*e xpr, result)));
1432 } 1314 }
1433 1315
1434 bool StyleResolver::affectedByViewportChange() const 1316 bool StyleResolver::affectedByViewportChange() const
1435 { 1317 {
1436 unsigned s = m_viewportDependentMediaQueryResults.size(); 1318 unsigned s = m_viewportDependentMediaQueryResults.size();
1437 for (unsigned i = 0; i < s; i++) { 1319 for (unsigned i = 0; i < s; i++) {
1438 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result) 1320 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che); 1352 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che);
1471 1353
1472 fprintf(stderr, "Total:\n"); 1354 fprintf(stderr, "Total:\n");
1473 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, 1355 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing,
1474 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache); 1356 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache);
1475 fprintf(stderr, "----------------------------------------------------------- ---------------------\n"); 1357 fprintf(stderr, "----------------------------------------------------------- ---------------------\n");
1476 } 1358 }
1477 #endif 1359 #endif
1478 1360
1479 } // namespace WebCore 1361 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698