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