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

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: Rebased 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
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | Source/core/css/resolver/StyleResolverState.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) 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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 // FIXME: Can't keyframes contain variables? 658 // FIXME: Can't keyframes contain variables?
659 applyMatchedProperties<AnimationProperties>(state, result, false, 0, res ult.matchedProperties.size() - 1, inheritedOnly); 659 applyMatchedProperties<AnimationProperties>(state, result, false, 0, res ult.matchedProperties.size() - 1, inheritedOnly);
660 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly); 660 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
661 } 661 }
662 662
663 // If our font got dirtied, go ahead and update it now. 663 // If our font got dirtied, go ahead and update it now.
664 updateFont(state); 664 updateFont(state);
665 665
666 // Line-height is set when we are sure we decided on the font-size 666 // Line-height is set when we are sure we decided on the font-size
667 if (state.lineHeightValue()) 667 if (state.lineHeightValue())
668 applyProperty(state, CSSPropertyLineHeight, state.lineHeightValue()); 668 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
669 669
670 // Now do rest of the properties. 670 // Now do rest of the properties.
671 if (keyframe->properties()) 671 if (keyframe->properties())
672 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, r esult.matchedProperties.size() - 1, inheritedOnly); 672 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, r esult.matchedProperties.size() - 1, inheritedOnly);
673 673
674 // If our font got dirtied by one of the non-essential font props, 674 // If our font got dirtied by one of the non-essential font props,
675 // go ahead and update it a second time. 675 // go ahead and update it a second time.
676 updateFont(state); 676 updateFont(state);
677 677
678 // Start loading resources referenced by this style. 678 // Start loading resources referenced by this style.
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 909
910 MatchResult& result = collector.matchedResult(); 910 MatchResult& result = collector.matchedResult();
911 applyMatchedProperties<VariableDefinitions>(state, result, false, 0, result. matchedProperties.size() - 1, inheritedOnly); 911 applyMatchedProperties<VariableDefinitions>(state, result, false, 0, result. matchedProperties.size() - 1, inheritedOnly);
912 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu lt.matchedProperties.size() - 1, inheritedOnly); 912 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu lt.matchedProperties.size() - 1, inheritedOnly);
913 913
914 // If our font got dirtied, go ahead and update it now. 914 // If our font got dirtied, go ahead and update it now.
915 updateFont(state); 915 updateFont(state);
916 916
917 // Line-height is set when we are sure we decided on the font-size. 917 // Line-height is set when we are sure we decided on the font-size.
918 if (state.lineHeightValue()) 918 if (state.lineHeightValue())
919 applyProperty(state, CSSPropertyLineHeight, state.lineHeightValue()); 919 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
920 920
921 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul t.matchedProperties.size() - 1, inheritedOnly); 921 applyMatchedProperties<LowPriorityProperties>(state, result, false, 0, resul t.matchedProperties.size() - 1, inheritedOnly);
922 922
923 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); 923 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features);
924 924
925 // Start loading resources referenced by this style. 925 // Start loading resources referenced by this style.
926 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources()); 926 m_styleResourceLoader.loadPendingResources(state.style(), state.elementStyle Resources());
927 927
928 document()->didAccessStyleResolver(); 928 document()->didAccessStyleResolver();
929 929
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 CSSPropertyID property = iter->key; 1072 CSSPropertyID property = iter->key;
1073 if (!isPropertyForPass<pass>(property)) 1073 if (!isPropertyForPass<pass>(property))
1074 continue; 1074 continue;
1075 RefPtr<AnimatableValue> animatableValue = iter->value->compositeOnto (AnimatableValue::neutralValue()); 1075 RefPtr<AnimatableValue> animatableValue = iter->value->compositeOnto (AnimatableValue::neutralValue());
1076 if (animatableValue->isDeferredSnapshot()) 1076 if (animatableValue->isDeferredSnapshot())
1077 continue; 1077 continue;
1078 RefPtr<CSSValue> cssValue = animatableValue->toCSSValue(); 1078 RefPtr<CSSValue> cssValue = animatableValue->toCSSValue();
1079 if (pass == HighPriorityProperties && property == CSSPropertyLineHei ght) 1079 if (pass == HighPriorityProperties && property == CSSPropertyLineHei ght)
1080 state.setLineHeightValue(cssValue.get()); 1080 state.setLineHeightValue(cssValue.get());
1081 else 1081 else
1082 applyProperty(state, property, cssValue.get()); 1082 StyleBuilder::applyProperty(property, state, cssValue.get());
1083 } 1083 }
1084 } 1084 }
1085 } 1085 }
1086 1086
1087 static inline bool isValidVisitedLinkProperty(CSSPropertyID id)
1088 {
1089 switch (id) {
1090 case CSSPropertyBackgroundColor:
1091 case CSSPropertyBorderLeftColor:
1092 case CSSPropertyBorderRightColor:
1093 case CSSPropertyBorderTopColor:
1094 case CSSPropertyBorderBottomColor:
1095 case CSSPropertyColor:
1096 case CSSPropertyFill:
1097 case CSSPropertyOutlineColor:
1098 case CSSPropertyStroke:
1099 case CSSPropertyTextDecorationColor:
1100 case CSSPropertyWebkitColumnRuleColor:
1101 case CSSPropertyWebkitTextEmphasisColor:
1102 case CSSPropertyWebkitTextFillColor:
1103 case CSSPropertyWebkitTextStrokeColor:
1104 return true;
1105 default:
1106 break;
1107 }
1108
1109 return false;
1110 }
1111
1112 // http://dev.w3.org/csswg/css3-regions/#the-at-region-style-rule 1087 // http://dev.w3.org/csswg/css3-regions/#the-at-region-style-rule
1113 // FIXME: add incremental support for other region styling properties. 1088 // FIXME: add incremental support for other region styling properties.
1114 static inline bool isValidRegionStyleProperty(CSSPropertyID id) 1089 static inline bool isValidRegionStyleProperty(CSSPropertyID id)
1115 { 1090 {
1116 switch (id) { 1091 switch (id) {
1117 case CSSPropertyBackgroundColor: 1092 case CSSPropertyBackgroundColor:
1118 case CSSPropertyColor: 1093 case CSSPropertyColor:
1119 return true; 1094 return true;
1120 default: 1095 default:
1121 break; 1096 break;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 1194
1220 if (propertyWhitelistType == PropertyWhitelistRegion && !isValidRegionSt yleProperty(property)) 1195 if (propertyWhitelistType == PropertyWhitelistRegion && !isValidRegionSt yleProperty(property))
1221 continue; 1196 continue;
1222 if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStylePro perty(property)) 1197 if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStylePro perty(property))
1223 continue; 1198 continue;
1224 if (!isPropertyForPass<pass>(property)) 1199 if (!isPropertyForPass<pass>(property))
1225 continue; 1200 continue;
1226 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight) 1201 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight)
1227 state.setLineHeightValue(current.value()); 1202 state.setLineHeightValue(current.value());
1228 else 1203 else
1229 applyProperty(state, current.id(), current.value()); 1204 StyleBuilder::applyProperty(current.id(), state, current.value());
1230 } 1205 }
1231 } 1206 }
1232 1207
1233 template <StyleResolver::StyleApplicationPass pass> 1208 template <StyleResolver::StyleApplicationPass pass>
1234 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult, bool isImportant, int startIndex, int endIndex, bool inher itedOnly) 1209 void StyleResolver::applyMatchedProperties(StyleResolverState& state, const Matc hResult& matchResult, bool isImportant, int startIndex, int endIndex, bool inher itedOnly)
1235 { 1210 {
1236 if (startIndex == -1) 1211 if (startIndex == -1)
1237 return; 1212 return;
1238 1213
1239 if (state.style()->insideLink() != NotInsideLink) { 1214 if (state.style()->insideLink() != NotInsideLink) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->effecti veZoom() != state.style()->effectiveZoom()) { 1321 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->effecti veZoom() != state.style()->effectiveZoom()) {
1347 state.fontBuilder().setFontDirty(true); 1322 state.fontBuilder().setFontDirty(true);
1348 applyInheritedOnly = false; 1323 applyInheritedOnly = false;
1349 } 1324 }
1350 1325
1351 // If our font got dirtied, go ahead and update it now. 1326 // If our font got dirtied, go ahead and update it now.
1352 updateFont(state); 1327 updateFont(state);
1353 1328
1354 // Line-height is set when we are sure we decided on the font-size. 1329 // Line-height is set when we are sure we decided on the font-size.
1355 if (state.lineHeightValue()) 1330 if (state.lineHeightValue())
1356 applyProperty(state, CSSPropertyLineHeight, state.lineHeightValue()); 1331 StyleBuilder::applyProperty(CSSPropertyLineHeight, state, state.lineHeig htValue());
1357 1332
1358 // Many properties depend on the font. If it changes we just apply all prope rties. 1333 // Many properties depend on the font. If it changes we just apply all prope rties.
1359 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDes cription() != state.style()->fontDescription()) 1334 if (cachedMatchedProperties && cachedMatchedProperties->renderStyle->fontDes cription() != state.style()->fontDescription())
1360 applyInheritedOnly = false; 1335 applyInheritedOnly = false;
1361 1336
1362 // Now do the normal priority UA properties. 1337 // Now do the normal priority UA properties.
1363 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, mat chResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly); 1338 applyMatchedProperties<LowPriorityProperties>(state, matchResult, false, mat chResult.ranges.firstUARule, matchResult.ranges.lastUARule, applyInheritedOnly);
1364 1339
1365 // Cache the UA properties to pass them to RenderTheme in adjustRenderStyle. 1340 // Cache the UA properties to pass them to RenderTheme in adjustRenderStyle.
1366 state.cacheUserAgentBorderAndBackground(); 1341 state.cacheUserAgentBorderAndBackground();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 // which assumes the fontMetrics are available for the affected font , otherwise a crash occurs (see http://trac.webkit.org/changeset/96122). 1383 // which assumes the fontMetrics are available for the affected font , otherwise a crash occurs (see http://trac.webkit.org/changeset/96122).
1409 // The updateFont() call below updates the fontMetrics and ensure th e proper setting of font-size and line-height. 1384 // The updateFont() call below updates the fontMetrics and ensure th e proper setting of font-size and line-height.
1410 switch (properties[i].property) { 1385 switch (properties[i].property) {
1411 case CSSPropertyFontSize: 1386 case CSSPropertyFontSize:
1412 case CSSPropertyLineHeight: 1387 case CSSPropertyLineHeight:
1413 updateFont(state); 1388 updateFont(state);
1414 break; 1389 break;
1415 default: 1390 default:
1416 break; 1391 break;
1417 } 1392 }
1418 applyProperty(state, properties[i].property, properties[i].value); 1393 StyleBuilder::applyProperty(properties[i].property, state, propertie s[i].value);
1419 } 1394 }
1420 } 1395 }
1421 } 1396 }
1422 1397
1423 static bool hasVariableReference(CSSValue* value)
1424 {
1425 if (value->isPrimitiveValue()) {
1426 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value);
1427 return primitiveValue->hasVariableReference();
1428 }
1429
1430 if (value->isCalculationValue())
1431 return static_cast<CSSCalcValue*>(value)->hasVariableReference();
1432
1433 if (value->isReflectValue()) {
1434 CSSReflectValue* reflectValue = static_cast<CSSReflectValue*>(value);
1435 CSSPrimitiveValue* direction = reflectValue->direction();
1436 CSSPrimitiveValue* offset = reflectValue->offset();
1437 CSSValue* mask = reflectValue->mask();
1438 return (direction && hasVariableReference(direction)) || (offset && hasV ariableReference(offset)) || (mask && hasVariableReference(mask));
1439 }
1440
1441 for (CSSValueListIterator i = value; i.hasMore(); i.advance()) {
1442 if (hasVariableReference(i.value()))
1443 return true;
1444 }
1445
1446 return false;
1447 }
1448
1449 void StyleResolver::resolveVariables(StyleResolverState& state, CSSPropertyID id , CSSValue* value, Vector<std::pair<CSSPropertyID, String> >& knownExpressions)
1450 {
1451 std::pair<CSSPropertyID, String> expression(id, value->serializeResolvingVar iables(*state.style()->variables()));
1452
1453 if (knownExpressions.contains(expression))
1454 return; // cycle detected.
1455
1456 knownExpressions.append(expression);
1457
1458 // 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.
1459 RefPtr<MutableStylePropertySet> resultSet = MutableStylePropertySet::create( );
1460 if (!CSSParser::parseValue(resultSet.get(), id, expression.second, false, do cument()))
1461 return; // expression failed to parse.
1462
1463 for (unsigned i = 0; i < resultSet->propertyCount(); i++) {
1464 StylePropertySet::PropertyReference property = resultSet->propertyAt(i);
1465 if (property.id() != CSSPropertyVariable && hasVariableReference(propert y.value())) {
1466 resolveVariables(state, property.id(), property.value(), knownExpres sions);
1467 } else {
1468 applyProperty(state, property.id(), property.value());
1469 // All properties become dependent on their parent style when they u se variables.
1470 state.style()->setHasExplicitlyInheritedProperties();
1471 }
1472 }
1473 }
1474
1475 void StyleResolver::applyProperty(StyleResolverState& state, CSSPropertyID id, C SSValue* value)
1476 {
1477 if (id != CSSPropertyVariable && hasVariableReference(value)) {
1478 Vector<std::pair<CSSPropertyID, String> > knownExpressions;
1479 resolveVariables(state, id, value, knownExpressions);
1480 return;
1481 }
1482
1483 // CSS variables don't resolve shorthands at parsing time, so this should be *after* handling variables.
1484 ASSERT_WITH_MESSAGE(!isExpandedShorthand(id), "Shorthand property id = %d wa sn't expanded at parsing time", id);
1485
1486 bool isInherit = state.parentNode() && value->isInheritedValue();
1487 bool isInitial = value->isInitialValue() || (!state.parentNode() && value->i sInheritedValue());
1488
1489 ASSERT(!isInherit || !isInitial); // isInherit -> !isInitial && isInitial -> !isInherit
1490 ASSERT(!isInherit || (state.parentNode() && state.parentStyle())); // isInhe rit -> (state.parentNode() && state.parentStyle())
1491
1492 if (!state.applyPropertyToRegularStyle() && (!state.applyPropertyToVisitedLi nkStyle() || !isValidVisitedLinkProperty(id))) {
1493 // Limit the properties that can be applied to only the ones honored by :visited.
1494 return;
1495 }
1496
1497 if (isInherit && !state.parentStyle()->hasExplicitlyInheritedProperties() && !CSSProperty::isInheritedProperty(id))
1498 state.parentStyle()->setHasExplicitlyInheritedProperties();
1499
1500 if (id == CSSPropertyVariable) {
1501 ASSERT_WITH_SECURITY_IMPLICATION(value->isVariableValue());
1502 CSSVariableValue* variable = toCSSVariableValue(value);
1503 ASSERT(!variable->name().isEmpty());
1504 ASSERT(!variable->value().isEmpty());
1505 state.style()->setVariable(variable->name(), variable->value());
1506 return;
1507 }
1508
1509 if (StyleBuilder::applyProperty(id, this, state, value, isInitial, isInherit ))
1510 return;
1511
1512 // Fall back to the old switch statement, which is now in StyleBuilderCustom .cpp
1513 StyleBuilder::oldApplyProperty(id, this, state, value, isInitial, isInherit) ;
1514 }
1515
1516 void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp* ex pr, bool result) 1398 void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp* ex pr, bool result)
1517 { 1399 {
1518 m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*e xpr, result))); 1400 m_viewportDependentMediaQueryResults.append(adoptPtr(new MediaQueryResult(*e xpr, result)));
1519 } 1401 }
1520 1402
1521 bool StyleResolver::affectedByViewportChange() const 1403 bool StyleResolver::affectedByViewportChange() const
1522 { 1404 {
1523 unsigned s = m_viewportDependentMediaQueryResults.size(); 1405 unsigned s = m_viewportDependentMediaQueryResults.size();
1524 for (unsigned i = 0; i < s; i++) { 1406 for (unsigned i = 0; i < s; i++) {
1525 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result) 1407 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
1557 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che); 1439 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa che);
1558 1440
1559 fprintf(stderr, "Total:\n"); 1441 fprintf(stderr, "Total:\n");
1560 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, 1442 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing,
1561 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache); 1443 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch edPropertiesEnteredIntoCache);
1562 fprintf(stderr, "----------------------------------------------------------- ---------------------\n"); 1444 fprintf(stderr, "----------------------------------------------------------- ---------------------\n");
1563 } 1445 }
1564 #endif 1446 #endif
1565 1447
1566 } // namespace WebCore 1448 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleResolver.h ('k') | Source/core/css/resolver/StyleResolverState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698