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

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

Issue 159863002: Remove CSS regions support, keeping a bare minimum to support "region-based" multicol. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 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
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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 { 507 {
508 if (!m_watchedSelectorsRules) 508 if (!m_watchedSelectorsRules)
509 return; 509 return;
510 510
511 collector.clearMatchedRules(); 511 collector.clearMatchedRules();
512 collector.matchedResult().ranges.lastUserRule = collector.matchedResult().ma tchedProperties.size() - 1; 512 collector.matchedResult().ranges.lastUserRule = collector.matchedResult().ma tchedProperties.size() - 1;
513 513
514 MatchRequest matchRequest(m_watchedSelectorsRules.get()); 514 MatchRequest matchRequest(m_watchedSelectorsRules.get());
515 RuleRange ruleRange = collector.matchedResult().ranges.userRuleRange(); 515 RuleRange ruleRange = collector.matchedResult().ranges.userRuleRange();
516 collector.collectMatchingRules(matchRequest, ruleRange); 516 collector.collectMatchingRules(matchRequest, ruleRange);
517 collector.collectMatchingRulesForRegion(matchRequest, ruleRange);
518 517
519 collector.sortAndTransferMatchedRules(); 518 collector.sortAndTransferMatchedRules();
520 } 519 }
521 520
522 void StyleResolver::matchUARules(ElementRuleCollector& collector) 521 void StyleResolver::matchUARules(ElementRuleCollector& collector)
523 { 522 {
524 collector.setMatchingUARules(true); 523 collector.setMatchingUARules(true);
525 524
526 RuleSet* userAgentStyleSheet = m_medium->mediaTypeMatchSpecific("print") 525 RuleSet* userAgentStyleSheet = m_medium->mediaTypeMatchSpecific("print")
527 ? CSSDefaultStyleSheets::defaultPrintStyle : CSSDefaultStyleSheets::defa ultStyle; 526 ? CSSDefaultStyleSheets::defaultPrintStyle : CSSDefaultStyleSheets::defa ultStyle;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 document.setWritingModeSetOnDocumentElement(false); 619 document.setWritingModeSetOnDocumentElement(false);
621 } 620 }
622 621
623 static void addContentAttrValuesToFeatures(const Vector<AtomicString>& contentAt trValues, RuleFeatureSet& features) 622 static void addContentAttrValuesToFeatures(const Vector<AtomicString>& contentAt trValues, RuleFeatureSet& features)
624 { 623 {
625 for (size_t i = 0; i < contentAttrValues.size(); ++i) 624 for (size_t i = 0; i < contentAttrValues.size(); ++i)
626 features.addAttributeInASelector(contentAttrValues[i]); 625 features.addAttributeInASelector(contentAttrValues[i]);
627 } 626 }
628 627
629 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS tyle* defaultParent, StyleSharingBehavior sharingBehavior, 628 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS tyle* defaultParent, StyleSharingBehavior sharingBehavior,
630 RuleMatchingBehavior matchingBehavior, RenderRegion* regionForStyling) 629 RuleMatchingBehavior matchingBehavior)
631 { 630 {
632 ASSERT(document().frame()); 631 ASSERT(document().frame());
633 ASSERT(documentSettings()); 632 ASSERT(documentSettings());
634 ASSERT(!hasPendingAuthorStyleSheets()); 633 ASSERT(!hasPendingAuthorStyleSheets());
635 ASSERT(!m_needCollectFeatures); 634 ASSERT(!m_needCollectFeatures);
636 635
637 // Once an element has a renderer, we don't try to destroy it, since otherwi se the renderer 636 // Once an element has a renderer, we don't try to destroy it, since otherwi se the renderer
638 // will vanish if a style recalc happens during loading. 637 // will vanish if a style recalc happens during loading.
639 if (sharingBehavior == AllowStyleSharing && !element->document().haveStylesh eetsLoaded() && !element->renderer()) { 638 if (sharingBehavior == AllowStyleSharing && !element->document().haveStylesh eetsLoaded() && !element->renderer()) {
640 if (!s_styleNotYetAvailable) { 639 if (!s_styleNotYetAvailable) {
641 s_styleNotYetAvailable = RenderStyle::create().leakRef(); 640 s_styleNotYetAvailable = RenderStyle::create().leakRef();
642 s_styleNotYetAvailable->setDisplay(NONE); 641 s_styleNotYetAvailable->setDisplay(NONE);
643 s_styleNotYetAvailable->font().update(document().styleEngine()->font Selector()); 642 s_styleNotYetAvailable->font().update(document().styleEngine()->font Selector());
644 } 643 }
645 element->document().setHasNodesWithPlaceholderStyle(); 644 element->document().setHasNodesWithPlaceholderStyle();
646 return s_styleNotYetAvailable; 645 return s_styleNotYetAvailable;
647 } 646 }
648 647
649 didAccess(); 648 didAccess();
650 649
651 if (element == document().documentElement()) 650 if (element == document().documentElement())
652 resetDirectionAndWritingModeOnDocument(document()); 651 resetDirectionAndWritingModeOnDocument(document());
653 StyleResolverState state(document(), element, defaultParent, regionForStylin g); 652 StyleResolverState state(document(), element, defaultParent);
654 653
655 if (sharingBehavior == AllowStyleSharing && state.parentStyle()) { 654 if (sharingBehavior == AllowStyleSharing && state.parentStyle()) {
656 SharedStyleFinder styleFinder(state.elementContext(), m_features, m_sibl ingRuleSet.get(), m_uncommonAttributeRuleSet.get(), *this); 655 SharedStyleFinder styleFinder(state.elementContext(), m_features, m_sibl ingRuleSet.get(), m_uncommonAttributeRuleSet.get(), *this);
657 if (RefPtr<RenderStyle> sharedStyle = styleFinder.findSharedStyle()) 656 if (RefPtr<RenderStyle> sharedStyle = styleFinder.findSharedStyle())
658 return sharedStyle.release(); 657 return sharedStyle.release();
659 } 658 }
660 659
661 if (state.parentStyle()) { 660 if (state.parentStyle()) {
662 state.setStyle(RenderStyle::create()); 661 state.setStyle(RenderStyle::create());
663 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary); 662 state.style()->inheritFrom(state.parentStyle(), isAtShadowBoundary(eleme nt) ? RenderStyle::AtShadowBoundary : RenderStyle::NotAtShadowBoundary);
(...skipping 23 matching lines...) Expand all
687 state.style()->setInsideLink(linkState); 686 state.style()->setInsideLink(linkState);
688 } 687 }
689 688
690 bool needsCollection = false; 689 bool needsCollection = false;
691 CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(element, needsColl ection); 690 CSSDefaultStyleSheets::ensureDefaultStyleSheetsForElement(element, needsColl ection);
692 if (needsCollection) 691 if (needsCollection)
693 collectFeatures(); 692 collectFeatures();
694 693
695 { 694 {
696 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style()); 695 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, state.style());
697 collector.setRegionForStyling(regionForStyling);
698 696
699 if (matchingBehavior == MatchOnlyUserAgentRules) 697 if (matchingBehavior == MatchOnlyUserAgentRules)
700 matchUARules(collector); 698 matchUARules(collector);
701 else 699 else
702 matchAllRules(state, collector, matchingBehavior != MatchAllRulesExc ludingSMIL); 700 matchAllRules(state, collector, matchingBehavior != MatchAllRulesExc ludingSMIL);
703 701
704 applyMatchedProperties(state, collector.matchedResult()); 702 applyMatchedProperties(state, collector.matchedResult());
705 703
706 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); 704 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features);
707 } 705 }
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 { 1059 {
1062 ASSERT(textNode); 1060 ASSERT(textNode);
1063 1061
1064 NodeRenderingTraversal::ParentDetails parentDetails; 1062 NodeRenderingTraversal::ParentDetails parentDetails;
1065 Node* parentNode = NodeRenderingTraversal::parent(textNode, &parentDetails); 1063 Node* parentNode = NodeRenderingTraversal::parent(textNode, &parentDetails);
1066 if (!parentNode || !parentNode->renderStyle() || parentDetails.resetStyleInh eritance()) 1064 if (!parentNode || !parentNode->renderStyle() || parentDetails.resetStyleInh eritance())
1067 return defaultStyleForElement(); 1065 return defaultStyleForElement();
1068 return parentNode->renderStyle(); 1066 return parentNode->renderStyle();
1069 } 1067 }
1070 1068
1071 bool StyleResolver::checkRegionStyle(Element* regionElement)
1072 {
1073 // FIXME (BUG 72472): We don't add @-webkit-region rules of scoped style she ets for the moment,
1074 // so all region rules are global by default. Verify whether that can stand or needs changing.
1075 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor Document()) {
1076 if (scopedResolver->checkRegionStyle(regionElement))
1077 return true;
1078 }
1079 return false;
1080 }
1081
1082 void StyleResolver::updateFont(StyleResolverState& state) 1069 void StyleResolver::updateFont(StyleResolverState& state)
1083 { 1070 {
1084 state.fontBuilder().createFont(document().styleEngine()->fontSelector(), sta te.parentStyle(), state.style()); 1071 state.fontBuilder().createFont(document().styleEngine()->fontSelector(), sta te.parentStyle(), state.style());
1085 if (state.fontBuilder().fontSizeHasViewportUnits()) 1072 if (state.fontBuilder().fontSizeHasViewportUnits())
1086 state.style()->setHasViewportUnits(); 1073 state.style()->setHasViewportUnits();
1087 } 1074 }
1088 1075
1089 PassRefPtr<StyleRuleList> StyleResolver::styleRulesForElement(Element* element, unsigned rulesToInclude) 1076 PassRefPtr<StyleRuleList> StyleResolver::styleRulesForElement(Element* element, unsigned rulesToInclude)
1090 { 1077 {
1091 ASSERT(element); 1078 ASSERT(element);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 for (AnimationEffect::CompositableValueMap::const_iterator iter = compositab leValues.begin(); iter != compositableValues.end(); ++iter) { 1160 for (AnimationEffect::CompositableValueMap::const_iterator iter = compositab leValues.begin(); iter != compositableValues.end(); ++iter) {
1174 CSSPropertyID property = iter->key; 1161 CSSPropertyID property = iter->key;
1175 if (!isPropertyForPass<pass>(property)) 1162 if (!isPropertyForPass<pass>(property))
1176 continue; 1163 continue;
1177 ASSERT_WITH_MESSAGE(!iter->value->dependsOnUnderlyingValue(), "Web Anima tions not yet implemented: An interface for compositing onto the underlying valu e."); 1164 ASSERT_WITH_MESSAGE(!iter->value->dependsOnUnderlyingValue(), "Web Anima tions not yet implemented: An interface for compositing onto the underlying valu e.");
1178 RefPtr<AnimatableValue> animatableValue = iter->value->compositeOnto(0); 1165 RefPtr<AnimatableValue> animatableValue = iter->value->compositeOnto(0);
1179 AnimatedStyleBuilder::applyProperty(property, state, animatableValue.get ()); 1166 AnimatedStyleBuilder::applyProperty(property, state, animatableValue.get ());
1180 } 1167 }
1181 } 1168 }
1182 1169
1183 // http://dev.w3.org/csswg/css3-regions/#the-at-region-style-rule
1184 // FIXME: add incremental support for other region styling properties.
1185 static inline bool isValidRegionStyleProperty(CSSPropertyID id)
1186 {
1187 switch (id) {
1188 case CSSPropertyBackgroundColor:
1189 case CSSPropertyColor:
1190 return true;
1191 default:
1192 break;
1193 }
1194
1195 return false;
1196 }
1197
1198 static inline bool isValidCueStyleProperty(CSSPropertyID id) 1170 static inline bool isValidCueStyleProperty(CSSPropertyID id)
1199 { 1171 {
1200 switch (id) { 1172 switch (id) {
1201 case CSSPropertyBackground: 1173 case CSSPropertyBackground:
1202 case CSSPropertyBackgroundAttachment: 1174 case CSSPropertyBackgroundAttachment:
1203 case CSSPropertyBackgroundClip: 1175 case CSSPropertyBackgroundClip:
1204 case CSSPropertyBackgroundColor: 1176 case CSSPropertyBackgroundColor:
1205 case CSSPropertyBackgroundImage: 1177 case CSSPropertyBackgroundImage:
1206 case CSSPropertyBackgroundOrigin: 1178 case CSSPropertyBackgroundOrigin:
1207 case CSSPropertyBackgroundPosition: 1179 case CSSPropertyBackgroundPosition:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 case LowPriorityProperties: 1234 case LowPriorityProperties:
1263 return property > lastHighPriorityProperty; 1235 return property > lastHighPriorityProperty;
1264 } 1236 }
1265 ASSERT_NOT_REACHED(); 1237 ASSERT_NOT_REACHED();
1266 return false; 1238 return false;
1267 } 1239 }
1268 1240
1269 template <StyleResolver::StyleApplicationPass pass> 1241 template <StyleResolver::StyleApplicationPass pass>
1270 void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper tySet* properties, StyleRule* rule, bool isImportant, bool inheritedOnly, Proper tyWhitelistType propertyWhitelistType) 1242 void StyleResolver::applyProperties(StyleResolverState& state, const StyleProper tySet* properties, StyleRule* rule, bool isImportant, bool inheritedOnly, Proper tyWhitelistType propertyWhitelistType)
1271 { 1243 {
1272 ASSERT((propertyWhitelistType != PropertyWhitelistRegion) || state.regionFor Styling());
1273 state.setCurrentRule(rule); 1244 state.setCurrentRule(rule);
1274 1245
1275 unsigned propertyCount = properties->propertyCount(); 1246 unsigned propertyCount = properties->propertyCount();
1276 for (unsigned i = 0; i < propertyCount; ++i) { 1247 for (unsigned i = 0; i < propertyCount; ++i) {
1277 StylePropertySet::PropertyReference current = properties->propertyAt(i); 1248 StylePropertySet::PropertyReference current = properties->propertyAt(i);
1278 if (isImportant != current.isImportant()) 1249 if (isImportant != current.isImportant())
1279 continue; 1250 continue;
1280 if (inheritedOnly && !current.isInherited()) { 1251 if (inheritedOnly && !current.isInherited()) {
1281 // If the property value is explicitly inherited, we need to apply f urther non-inherited properties 1252 // If the property value is explicitly inherited, we need to apply f urther non-inherited properties
1282 // as they might override the value inherited here. For this reason we don't allow declarations with 1253 // as they might override the value inherited here. For this reason we don't allow declarations with
1283 // explicitly inherited properties to be cached. 1254 // explicitly inherited properties to be cached.
1284 ASSERT(!current.value()->isInheritedValue()); 1255 ASSERT(!current.value()->isInheritedValue());
1285 continue; 1256 continue;
1286 } 1257 }
1287 CSSPropertyID property = current.id(); 1258 CSSPropertyID property = current.id();
1288 1259
1289 if (propertyWhitelistType == PropertyWhitelistRegion && !isValidRegionSt yleProperty(property))
1290 continue;
1291 if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStylePro perty(property)) 1260 if (propertyWhitelistType == PropertyWhitelistCue && !isValidCueStylePro perty(property))
1292 continue; 1261 continue;
1293 if (!isPropertyForPass<pass>(property)) 1262 if (!isPropertyForPass<pass>(property))
1294 continue; 1263 continue;
1295 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight) 1264 if (pass == HighPriorityProperties && property == CSSPropertyLineHeight)
1296 state.setLineHeightValue(current.value()); 1265 state.setLineHeightValue(current.value());
1297 else 1266 else
1298 StyleBuilder::applyProperty(current.id(), state, current.value()); 1267 StyleBuilder::applyProperty(current.id(), state, current.value());
1299 } 1268 }
1300 } 1269 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 bool StyleResolver::mediaQueryAffectedByViewportChange() const 1473 bool StyleResolver::mediaQueryAffectedByViewportChange() const
1505 { 1474 {
1506 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) { 1475 for (unsigned i = 0; i < m_viewportDependentMediaQueryResults.size(); ++i) {
1507 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result) 1476 if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expressio n) != m_viewportDependentMediaQueryResults[i]->m_result)
1508 return true; 1477 return true;
1509 } 1478 }
1510 return false; 1479 return false;
1511 } 1480 }
1512 1481
1513 } // namespace WebCore 1482 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698