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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 168 |
169 if (root) | 169 if (root) |
170 m_rootDefaultStyle = styleForElement(root, 0, DisallowStyleSharing, Matc
hOnlyUserAgentRules); | 170 m_rootDefaultStyle = styleForElement(root, 0, DisallowStyleSharing, Matc
hOnlyUserAgentRules); |
171 | 171 |
172 if (m_rootDefaultStyle && view) | 172 if (m_rootDefaultStyle && view) |
173 m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType(), &view->fr
ame(), m_rootDefaultStyle.get())); | 173 m_medium = adoptPtr(new MediaQueryEvaluator(view->mediaType(), &view->fr
ame(), m_rootDefaultStyle.get())); |
174 | 174 |
175 m_styleTree.clear(); | 175 m_styleTree.clear(); |
176 | 176 |
177 StyleEngine* styleSheetCollection = document.styleEngine(); | 177 StyleEngine* styleSheetCollection = document.styleEngine(); |
178 m_ruleSets.initUserStyle(styleSheetCollection, CSSSelectorWatch::from(docume
nt).watchedCallbackSelectors(), *m_medium, *this); | |
179 | 178 |
180 #if ENABLE(SVG_FONTS) | 179 #if ENABLE(SVG_FONTS) |
181 if (document.svgExtensions()) { | 180 if (document.svgExtensions()) { |
182 const HashSet<SVGFontFaceElement*>& svgFontFaceElements = document.svgEx
tensions()->svgFontFaceElements(); | 181 const HashSet<SVGFontFaceElement*>& svgFontFaceElements = document.svgEx
tensions()->svgFontFaceElements(); |
183 HashSet<SVGFontFaceElement*>::const_iterator end = svgFontFaceElements.e
nd(); | 182 HashSet<SVGFontFaceElement*>::const_iterator end = svgFontFaceElements.e
nd(); |
184 for (HashSet<SVGFontFaceElement*>::const_iterator it = svgFontFaceElemen
ts.begin(); it != end; ++it) | 183 for (HashSet<SVGFontFaceElement*>::const_iterator it = svgFontFaceElemen
ts.begin(); it != end; ++it) |
185 fontSelector()->addFontFaceRule((*it)->fontFaceRule()); | 184 fontSelector()->addFontFaceRule((*it)->fontFaceRule()); |
186 } | 185 } |
187 #endif | 186 #endif |
188 | 187 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 // FIXME: Need to clarify how to treat style scoped. | 472 // FIXME: Need to clarify how to treat style scoped. |
474 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, apply
AuthorStyles, cascadeScope++, resolver->treeScope() == element->treeScope() && r
esolver->scopingNode().isShadowRoot() ? 0 : cascadeOrder); | 473 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, apply
AuthorStyles, cascadeScope++, resolver->treeScope() == element->treeScope() && r
esolver->scopingNode().isShadowRoot() ? 0 : cascadeOrder); |
475 } | 474 } |
476 | 475 |
477 collectTreeBoundaryCrossingRules(collector, includeEmptyRules); | 476 collectTreeBoundaryCrossingRules(collector, includeEmptyRules); |
478 collector.sortAndTransferMatchedRules(); | 477 collector.sortAndTransferMatchedRules(); |
479 | 478 |
480 matchHostRules(element, resolvers.first(), collector, includeEmptyRules); | 479 matchHostRules(element, resolvers.first(), collector, includeEmptyRules); |
481 } | 480 } |
482 | 481 |
483 void StyleResolver::matchUserRules(ElementRuleCollector& collector, bool include
EmptyRules) | |
484 { | |
485 if (!m_ruleSets.userStyle()) | |
486 return; | |
487 | |
488 collector.clearMatchedRules(); | |
489 collector.matchedResult().ranges.lastUserRule = collector.matchedResult().ma
tchedProperties.size() - 1; | |
490 | |
491 MatchRequest matchRequest(m_ruleSets.userStyle(), includeEmptyRules); | |
492 RuleRange ruleRange = collector.matchedResult().ranges.userRuleRange(); | |
493 collector.collectMatchingRules(matchRequest, ruleRange); | |
494 collector.collectMatchingRulesForRegion(matchRequest, ruleRange); | |
495 | |
496 collector.sortAndTransferMatchedRules(); | |
497 } | |
498 | |
499 void StyleResolver::matchUARules(ElementRuleCollector& collector) | 482 void StyleResolver::matchUARules(ElementRuleCollector& collector) |
500 { | 483 { |
501 collector.setMatchingUARules(true); | 484 collector.setMatchingUARules(true); |
502 | 485 |
503 // First we match rules from the user agent sheet. | 486 // First we match rules from the user agent sheet. |
504 if (CSSDefaultStyleSheets::simpleDefaultStyleSheet) | 487 if (CSSDefaultStyleSheets::simpleDefaultStyleSheet) |
505 collector.matchedResult().isCacheable = false; | 488 collector.matchedResult().isCacheable = false; |
506 | 489 |
507 RuleSet* userAgentStyleSheet = m_medium->mediaTypeMatchSpecific("print") | 490 RuleSet* userAgentStyleSheet = m_medium->mediaTypeMatchSpecific("print") |
508 ? CSSDefaultStyleSheets::defaultPrintStyle : CSSDefaultStyleSheets::defa
ultStyle; | 491 ? CSSDefaultStyleSheets::defaultPrintStyle : CSSDefaultStyleSheets::defa
ultStyle; |
(...skipping 18 matching lines...) Expand all Loading... |
527 RuleRange ruleRange = collector.matchedResult().ranges.UARuleRange(); | 510 RuleRange ruleRange = collector.matchedResult().ranges.UARuleRange(); |
528 collector.collectMatchingRules(MatchRequest(rules), ruleRange); | 511 collector.collectMatchingRules(MatchRequest(rules), ruleRange); |
529 | 512 |
530 collector.sortAndTransferMatchedRules(); | 513 collector.sortAndTransferMatchedRules(); |
531 } | 514 } |
532 | 515 |
533 void StyleResolver::matchAllRules(StyleResolverState& state, ElementRuleCollecto
r& collector, bool matchAuthorAndUserStyles, bool includeSMILProperties) | 516 void StyleResolver::matchAllRules(StyleResolverState& state, ElementRuleCollecto
r& collector, bool matchAuthorAndUserStyles, bool includeSMILProperties) |
534 { | 517 { |
535 matchUARules(collector); | 518 matchUARules(collector); |
536 | 519 |
537 // Now we check user sheet rules. | |
538 if (matchAuthorAndUserStyles) | |
539 matchUserRules(collector, false); | |
540 | |
541 // Now check author rules, beginning first with presentational attributes ma
pped from HTML. | 520 // Now check author rules, beginning first with presentational attributes ma
pped from HTML. |
542 if (state.element()->isStyledElement()) { | 521 if (state.element()->isStyledElement()) { |
543 collector.addElementStyleProperties(state.element()->presentationAttribu
teStyle()); | 522 collector.addElementStyleProperties(state.element()->presentationAttribu
teStyle()); |
544 | 523 |
545 // Now we check additional mapped declarations. | 524 // Now we check additional mapped declarations. |
546 // Tables and table cells share an additional mapped rule that must be a
pplied | 525 // Tables and table cells share an additional mapped rule that must be a
pplied |
547 // after all attributes, since their mapped style depends on the values
of multiple attributes. | 526 // after all attributes, since their mapped style depends on the values
of multiple attributes. |
548 collector.addElementStyleProperties(state.element()->additionalPresentat
ionAttributeStyle()); | 527 collector.addElementStyleProperties(state.element()->additionalPresentat
ionAttributeStyle()); |
549 | 528 |
550 if (state.element()->isHTMLElement()) { | 529 if (state.element()->isHTMLElement()) { |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 | 1015 |
1037 // Since we don't use pseudo-elements in any of our quirk/print | 1016 // Since we don't use pseudo-elements in any of our quirk/print |
1038 // user agent rules, don't waste time walking those rules. | 1017 // user agent rules, don't waste time walking those rules. |
1039 | 1018 |
1040 { | 1019 { |
1041 // Check UA, user and author rules. | 1020 // Check UA, user and author rules. |
1042 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
state.style()); | 1021 ElementRuleCollector collector(state.elementContext(), m_selectorFilter,
state.style()); |
1043 collector.setPseudoStyleRequest(pseudoStyleRequest); | 1022 collector.setPseudoStyleRequest(pseudoStyleRequest); |
1044 | 1023 |
1045 matchUARules(collector); | 1024 matchUARules(collector); |
1046 if (m_matchAuthorAndUserStyles) { | 1025 if (m_matchAuthorAndUserStyles) |
1047 matchUserRules(collector, false); | |
1048 matchAuthorRules(state.element(), collector, false); | 1026 matchAuthorRules(state.element(), collector, false); |
1049 } | |
1050 | 1027 |
1051 if (collector.matchedResult().matchedProperties.isEmpty()) | 1028 if (collector.matchedResult().matchedProperties.isEmpty()) |
1052 return 0; | 1029 return 0; |
1053 | 1030 |
1054 state.style()->setStyleType(pseudoStyleRequest.pseudoId); | 1031 state.style()->setStyleType(pseudoStyleRequest.pseudoId); |
1055 | 1032 |
1056 applyMatchedProperties(state, collector.matchedResult(), e->pseudoElemen
t(pseudoStyleRequest.pseudoId)); | 1033 applyMatchedProperties(state, collector.matchedResult(), e->pseudoElemen
t(pseudoStyleRequest.pseudoId)); |
1057 | 1034 |
1058 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); | 1035 addContentAttrValuesToFeatures(state.contentAttrValues(), m_features); |
1059 } | 1036 } |
(...skipping 21 matching lines...) Expand all Loading... |
1081 state.setStyle(RenderStyle::create()); | 1058 state.setStyle(RenderStyle::create()); |
1082 const RenderStyle* rootElementStyle = state.rootElementStyle() ? state.rootE
lementStyle() : document().renderStyle(); | 1059 const RenderStyle* rootElementStyle = state.rootElementStyle() ? state.rootE
lementStyle() : document().renderStyle(); |
1083 ASSERT(rootElementStyle); | 1060 ASSERT(rootElementStyle); |
1084 state.style()->inheritFrom(rootElementStyle); | 1061 state.style()->inheritFrom(rootElementStyle); |
1085 | 1062 |
1086 state.fontBuilder().initForStyleResolve(state.document(), state.style(), sta
te.useSVGZoomRules()); | 1063 state.fontBuilder().initForStyleResolve(state.document(), state.style(), sta
te.useSVGZoomRules()); |
1087 | 1064 |
1088 PageRuleCollector collector(rootElementStyle, pageIndex); | 1065 PageRuleCollector collector(rootElementStyle, pageIndex); |
1089 | 1066 |
1090 collector.matchPageRules(CSSDefaultStyleSheets::defaultPrintStyle); | 1067 collector.matchPageRules(CSSDefaultStyleSheets::defaultPrintStyle); |
1091 collector.matchPageRules(m_ruleSets.userStyle()); | |
1092 | 1068 |
1093 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor
Document()) | 1069 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor
Document()) |
1094 scopedResolver->matchPageRules(collector); | 1070 scopedResolver->matchPageRules(collector); |
1095 | 1071 |
1096 state.setLineHeightValue(0); | 1072 state.setLineHeightValue(0); |
1097 bool inheritedOnly = false; | 1073 bool inheritedOnly = false; |
1098 | 1074 |
1099 MatchResult& result = collector.matchedResult(); | 1075 MatchResult& result = collector.matchedResult(); |
1100 applyMatchedProperties<VariableDefinitions>(state, result, false, 0, result.
matchedProperties.size() - 1, inheritedOnly); | 1076 applyMatchedProperties<VariableDefinitions>(state, result, false, 0, result.
matchedProperties.size() - 1, inheritedOnly); |
1101 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu
lt.matchedProperties.size() - 1, inheritedOnly); | 1077 applyMatchedProperties<HighPriorityProperties>(state, result, false, 0, resu
lt.matchedProperties.size() - 1, inheritedOnly); |
(...skipping 18 matching lines...) Expand all Loading... |
1120 return state.takeStyle(); | 1096 return state.takeStyle(); |
1121 } | 1097 } |
1122 | 1098 |
1123 void StyleResolver::collectViewportRules() | 1099 void StyleResolver::collectViewportRules() |
1124 { | 1100 { |
1125 viewportStyleResolver()->collectViewportRules(CSSDefaultStyleSheets::default
Style, ViewportStyleResolver::UserAgentOrigin); | 1101 viewportStyleResolver()->collectViewportRules(CSSDefaultStyleSheets::default
Style, ViewportStyleResolver::UserAgentOrigin); |
1126 | 1102 |
1127 if (document().isMobileDocument()) | 1103 if (document().isMobileDocument()) |
1128 viewportStyleResolver()->collectViewportRules(CSSDefaultStyleSheets::xht
mlMobileProfileStyle(), ViewportStyleResolver::UserAgentOrigin); | 1104 viewportStyleResolver()->collectViewportRules(CSSDefaultStyleSheets::xht
mlMobileProfileStyle(), ViewportStyleResolver::UserAgentOrigin); |
1129 | 1105 |
1130 if (m_ruleSets.userStyle()) | |
1131 viewportStyleResolver()->collectViewportRules(m_ruleSets.userStyle(), Vi
ewportStyleResolver::UserAgentOrigin); | |
1132 | |
1133 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor
Document()) | 1106 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor
Document()) |
1134 scopedResolver->collectViewportRulesTo(this); | 1107 scopedResolver->collectViewportRulesTo(this); |
1135 | 1108 |
1136 viewportStyleResolver()->resolve(); | 1109 viewportStyleResolver()->resolve(); |
1137 } | 1110 } |
1138 | 1111 |
1139 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() | 1112 PassRefPtr<RenderStyle> StyleResolver::defaultStyleForElement() |
1140 { | 1113 { |
1141 StyleResolverState state(document(), 0); | 1114 StyleResolverState state(document(), 0); |
1142 state.setStyle(RenderStyle::create()); | 1115 state.setStyle(RenderStyle::create()); |
(...skipping 13 matching lines...) Expand all Loading... |
1156 Node* parentNode = NodeRenderingTraversal::parent(textNode, &parentDetails); | 1129 Node* parentNode = NodeRenderingTraversal::parent(textNode, &parentDetails); |
1157 if (!parentNode || !parentNode->renderStyle() || parentDetails.resetStyleInh
eritance()) | 1130 if (!parentNode || !parentNode->renderStyle() || parentDetails.resetStyleInh
eritance()) |
1158 return defaultStyleForElement(); | 1131 return defaultStyleForElement(); |
1159 return parentNode->renderStyle(); | 1132 return parentNode->renderStyle(); |
1160 } | 1133 } |
1161 | 1134 |
1162 bool StyleResolver::checkRegionStyle(Element* regionElement) | 1135 bool StyleResolver::checkRegionStyle(Element* regionElement) |
1163 { | 1136 { |
1164 // FIXME (BUG 72472): We don't add @-webkit-region rules of scoped style she
ets for the moment, | 1137 // FIXME (BUG 72472): We don't add @-webkit-region rules of scoped style she
ets for the moment, |
1165 // so all region rules are global by default. Verify whether that can stand
or needs changing. | 1138 // so all region rules are global by default. Verify whether that can stand
or needs changing. |
1166 | 1139 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor
Document()) { |
1167 if (ScopedStyleResolver* scopedResolver = m_styleTree.scopedStyleResolverFor
Document()) | |
1168 if (scopedResolver->checkRegionStyle(regionElement)) | 1140 if (scopedResolver->checkRegionStyle(regionElement)) |
1169 return true; | 1141 return true; |
1170 | |
1171 if (m_ruleSets.userStyle()) { | |
1172 unsigned rulesSize = m_ruleSets.userStyle()->m_regionSelectorsAndRuleSet
s.size(); | |
1173 for (unsigned i = 0; i < rulesSize; ++i) { | |
1174 ASSERT(m_ruleSets.userStyle()->m_regionSelectorsAndRuleSets.at(i).ru
leSet.get()); | |
1175 if (checkRegionSelector(m_ruleSets.userStyle()->m_regionSelectorsAnd
RuleSets.at(i).selector, regionElement)) | |
1176 return true; | |
1177 } | |
1178 } | 1142 } |
1179 | |
1180 return false; | 1143 return false; |
1181 } | 1144 } |
1182 | 1145 |
1183 void StyleResolver::updateFont(StyleResolverState& state) | 1146 void StyleResolver::updateFont(StyleResolverState& state) |
1184 { | 1147 { |
1185 state.fontBuilder().createFont(m_fontSelector, state.parentStyle(), state.st
yle()); | 1148 state.fontBuilder().createFont(m_fontSelector, state.parentStyle(), state.st
yle()); |
1186 } | 1149 } |
1187 | 1150 |
1188 PassRefPtr<StyleRuleList> StyleResolver::styleRulesForElement(Element* element,
unsigned rulesToInclude) | 1151 PassRefPtr<StyleRuleList> StyleResolver::styleRulesForElement(Element* element,
unsigned rulesToInclude) |
1189 { | 1152 { |
(...skipping 20 matching lines...) Expand all Loading... |
1210 return pseudoCSSRulesForElement(element, NOPSEUDO, rulesToInclude, includeDo
cument); | 1173 return pseudoCSSRulesForElement(element, NOPSEUDO, rulesToInclude, includeDo
cument); |
1211 } | 1174 } |
1212 | 1175 |
1213 void StyleResolver::collectPseudoRulesForElement(Element* element, ElementRuleCo
llector& collector, PseudoId pseudoId, unsigned rulesToInclude) | 1176 void StyleResolver::collectPseudoRulesForElement(Element* element, ElementRuleCo
llector& collector, PseudoId pseudoId, unsigned rulesToInclude) |
1214 { | 1177 { |
1215 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); | 1178 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); |
1216 | 1179 |
1217 if (rulesToInclude & UAAndUserCSSRules) { | 1180 if (rulesToInclude & UAAndUserCSSRules) { |
1218 // First we match rules from the user agent sheet. | 1181 // First we match rules from the user agent sheet. |
1219 matchUARules(collector); | 1182 matchUARules(collector); |
1220 | |
1221 // Now we check user sheet rules. | |
1222 if (m_matchAuthorAndUserStyles) | |
1223 matchUserRules(collector, rulesToInclude & EmptyCSSRules); | |
1224 } | 1183 } |
1225 | 1184 |
1226 if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules)) { | 1185 if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules)) { |
1227 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules)); | 1186 collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules)); |
1228 | 1187 |
1229 // Check the rules in author sheets. | 1188 // Check the rules in author sheets. |
1230 matchAuthorRules(element, collector, rulesToInclude & EmptyCSSRules); | 1189 matchAuthorRules(element, collector, rulesToInclude & EmptyCSSRules); |
1231 } | 1190 } |
1232 } | 1191 } |
1233 | 1192 |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties
SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa
che); | 1571 m_matchedPropertiesSearches, m_matchedPropertiesHit, m_matchedProperties
SharedInheritedHit, m_matchedPropertiesToCache, m_matchedPropertiesEnteredIntoCa
che); |
1613 | 1572 |
1614 fprintf(stderr, "Total:\n"); | 1573 fprintf(stderr, "Total:\n"); |
1615 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS
tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, | 1574 printStyleStats(m_totalSearches, m_totalElementsEligibleForSharing, m_totalS
tylesShared, m_totalSearchFoundSiblingForSharing, m_totalSearchesMissedSharing, |
1616 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa
tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch
edPropertiesEnteredIntoCache); | 1575 m_totalMatchedPropertiesSearches, m_totalMatchedPropertiesHit, m_totalMa
tchedPropertiesSharedInheritedHit, m_totalMatchedPropertiesToCache, m_totalMatch
edPropertiesEnteredIntoCache); |
1617 fprintf(stderr, "-----------------------------------------------------------
---------------------\n"); | 1576 fprintf(stderr, "-----------------------------------------------------------
---------------------\n"); |
1618 } | 1577 } |
1619 #endif | 1578 #endif |
1620 | 1579 |
1621 } // namespace WebCore | 1580 } // namespace WebCore |
OLD | NEW |