Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 33 #include "core/MediaTypeNames.h" | 33 #include "core/MediaTypeNames.h" |
| 34 #include "core/StylePropertyShorthand.h" | 34 #include "core/StylePropertyShorthand.h" |
| 35 #include "core/animation/ActiveAnimations.h" | 35 #include "core/animation/ActiveAnimations.h" |
| 36 #include "core/animation/Animation.h" | 36 #include "core/animation/Animation.h" |
| 37 #include "core/animation/AnimationTimeline.h" | 37 #include "core/animation/AnimationTimeline.h" |
| 38 #include "core/animation/StyleInterpolation.h" | 38 #include "core/animation/StyleInterpolation.h" |
| 39 #include "core/animation/animatable/AnimatableValue.h" | 39 #include "core/animation/animatable/AnimatableValue.h" |
| 40 #include "core/animation/css/CSSAnimatableValueFactory.h" | 40 #include "core/animation/css/CSSAnimatableValueFactory.h" |
| 41 #include "core/animation/css/CSSAnimations.h" | 41 #include "core/animation/css/CSSAnimations.h" |
| 42 #include "core/css/CSSCalculationValue.h" | 42 #include "core/css/CSSCalculationValue.h" |
| 43 #include "core/css/CSSDefaultStyleSheets.h" | |
| 44 #include "core/css/CSSFontSelector.h" | 43 #include "core/css/CSSFontSelector.h" |
| 45 #include "core/css/CSSKeyframeRule.h" | 44 #include "core/css/CSSKeyframeRule.h" |
| 46 #include "core/css/CSSKeyframesRule.h" | 45 #include "core/css/CSSKeyframesRule.h" |
| 47 #include "core/css/CSSRuleList.h" | 46 #include "core/css/CSSRuleList.h" |
| 48 #include "core/css/CSSSelector.h" | 47 #include "core/css/CSSSelector.h" |
| 49 #include "core/css/CSSStyleRule.h" | 48 #include "core/css/CSSStyleRule.h" |
| 50 #include "core/css/CSSValueList.h" | 49 #include "core/css/CSSValueList.h" |
| 51 #include "core/css/CSSValuePool.h" | 50 #include "core/css/CSSValuePool.h" |
| 52 #include "core/css/ElementRuleCollector.h" | 51 #include "core/css/ElementRuleCollector.h" |
| 53 #include "core/css/FontFace.h" | 52 #include "core/css/FontFace.h" |
| 54 #include "core/css/MediaQueryEvaluator.h" | 53 #include "core/css/MediaQueryEvaluator.h" |
| 54 #include "core/css/RuleSet.h" | |
| 55 #include "core/css/StylePropertySet.h" | 55 #include "core/css/StylePropertySet.h" |
| 56 #include "core/css/StyleSheetContents.h" | 56 #include "core/css/StyleSheetContents.h" |
| 57 #include "core/css/parser/BisonCSSParser.h" | 57 #include "core/css/parser/BisonCSSParser.h" |
| 58 #include "core/css/resolver/AnimatedStyleBuilder.h" | 58 #include "core/css/resolver/AnimatedStyleBuilder.h" |
| 59 #include "core/css/resolver/MatchResult.h" | 59 #include "core/css/resolver/MatchResult.h" |
| 60 #include "core/css/resolver/MediaQueryResult.h" | 60 #include "core/css/resolver/MediaQueryResult.h" |
| 61 #include "core/css/resolver/SharedStyleFinder.h" | 61 #include "core/css/resolver/SharedStyleFinder.h" |
| 62 #include "core/css/resolver/StyleAdjuster.h" | 62 #include "core/css/resolver/StyleAdjuster.h" |
| 63 #include "core/css/resolver/StyleResolverState.h" | 63 #include "core/css/resolver/StyleResolverState.h" |
| 64 #include "core/css/resolver/StyleResolverStats.h" | 64 #include "core/css/resolver/StyleResolverStats.h" |
| 65 #include "core/dom/NodeRenderStyle.h" | 65 #include "core/dom/NodeRenderStyle.h" |
| 66 #include "core/dom/StyleEngine.h" | 66 #include "core/dom/StyleEngine.h" |
| 67 #include "core/dom/Text.h" | 67 #include "core/dom/Text.h" |
| 68 #include "core/dom/shadow/ElementShadow.h" | 68 #include "core/dom/shadow/ElementShadow.h" |
| 69 #include "core/dom/shadow/ShadowRoot.h" | 69 #include "core/dom/shadow/ShadowRoot.h" |
| 70 #include "core/frame/FrameView.h" | 70 #include "core/frame/FrameView.h" |
| 71 #include "core/frame/LocalFrame.h" | 71 #include "core/frame/LocalFrame.h" |
| 72 #include "core/rendering/RenderView.h" | 72 #include "core/rendering/RenderView.h" |
| 73 #include "core/rendering/style/KeyframeList.h" | 73 #include "core/rendering/style/KeyframeList.h" |
| 74 #include "platform/RuntimeEnabledFeatures.h" | 74 #include "platform/RuntimeEnabledFeatures.h" |
| 75 #include "wtf/LeakAnnotations.h" | |
| 75 #include "wtf/StdLibExtras.h" | 76 #include "wtf/StdLibExtras.h" |
| 76 | 77 |
| 77 namespace { | 78 namespace { |
| 78 | 79 |
| 79 using namespace blink; | 80 using namespace blink; |
| 80 | 81 |
| 81 void setAnimationUpdateIfNeeded(StyleResolverState& state, Element& element) | 82 void setAnimationUpdateIfNeeded(StyleResolverState& state, Element& element) |
| 82 { | 83 { |
| 83 // If any changes to CSS Animations were detected, stash the update away for application after the | 84 // If any changes to CSS Animations were detected, stash the update away for application after the |
| 84 // render object is updated if we're in the appropriate scope. | 85 // render object is updated if we're in the appropriate scope. |
| 85 if (state.animationUpdate()) | 86 if (state.animationUpdate()) |
| 86 element.ensureActiveAnimations().cssAnimations().setPendingUpdate(state. takeAnimationUpdate()); | 87 element.ensureActiveAnimations().cssAnimations().setPendingUpdate(state. takeAnimationUpdate()); |
| 87 } | 88 } |
| 88 | 89 |
| 89 } // namespace | 90 } // namespace |
| 90 | 91 |
| 91 namespace blink { | 92 namespace blink { |
| 92 | 93 |
| 93 RenderStyle* StyleResolver::s_styleNotYetAvailable; | 94 RenderStyle* StyleResolver::s_styleNotYetAvailable; |
| 94 | 95 |
| 95 static void addFontFaceRule(Document* document, CSSFontSelector* cssFontSelector , const StyleRuleFontFace* fontFaceRule) | 96 static void addFontFaceRule(Document* document, CSSFontSelector* cssFontSelector , const StyleRuleFontFace* fontFaceRule) |
| 96 { | 97 { |
| 97 RefPtr<FontFace> fontFace = FontFace::create(document, fontFaceRule); | 98 RefPtr<FontFace> fontFace = FontFace::create(document, fontFaceRule); |
| 98 if (fontFace) | 99 if (fontFace) |
| 99 cssFontSelector->fontFaceCache()->add(cssFontSelector, fontFaceRule, fon tFace); | 100 cssFontSelector->fontFaceCache()->add(cssFontSelector, fontFaceRule, fon tFace); |
| 100 } | 101 } |
| 101 | 102 |
| 103 static RuleSet& defaultStyles() | |
| 104 { | |
| 105 DEFINE_STATIC_LOCAL(RefPtr<StyleSheetContents>, styleSheet, ()); | |
| 106 DEFINE_STATIC_LOCAL(OwnPtr<RuleSet>, ruleSet, ()); | |
| 107 DEFINE_STATIC_LOCAL(const MediaQueryEvaluator, screenEval, ("screen")); | |
| 108 | |
| 109 if (ruleSet) | |
| 110 return *ruleSet; | |
| 111 | |
| 112 String cssText = | |
| 113 "link, import, meta, script, style, template, title {\n" | |
| 114 " display: none;\n" | |
| 115 "}\n" | |
| 116 "a {\n" | |
| 117 " color: blue;\n" | |
| 118 " display: inline;\n" | |
| 119 " text-decoration: underline;\n" | |
| 120 "}\n"; | |
| 121 | |
| 122 | |
| 123 styleSheet = StyleSheetContents::create(CSSParserContext(0)); | |
| 124 styleSheet->parseString(cssText); | |
| 125 | |
| 126 ruleSet = RuleSet::create(); | |
| 127 ruleSet->addRulesFromSheet(styleSheet.get(), screenEval); | |
| 128 | |
| 129 return *ruleSet; | |
| 130 } | |
| 131 | |
| 102 StyleResolver::StyleResolver(Document& document) | 132 StyleResolver::StyleResolver(Document& document) |
| 103 : m_document(document) | 133 : m_document(document) |
| 104 , m_needCollectFeatures(false) | 134 , m_needCollectFeatures(false) |
| 105 , m_printMediaType(false) | 135 , m_printMediaType(false) |
| 106 , m_styleResourceLoader(document.fetcher()) | 136 , m_styleResourceLoader(document.fetcher()) |
| 107 , m_styleSharingDepth(0) | 137 , m_styleSharingDepth(0) |
| 108 , m_styleResolverStatsSequence(0) | 138 , m_styleResolverStatsSequence(0) |
| 109 , m_accessCount(0) | 139 , m_accessCount(0) |
| 110 { | 140 { |
| 111 FrameView* view = document.view(); | 141 FrameView* view = document.view(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 return nullptr; | 250 return nullptr; |
| 221 OwnPtr<RuleSet> ruleSet = RuleSet::create(); | 251 OwnPtr<RuleSet> ruleSet = RuleSet::create(); |
| 222 for (size_t i = 0; i < size; ++i) | 252 for (size_t i = 0; i < size; ++i) |
| 223 ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, RuleHasNoSpecial State); | 253 ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, RuleHasNoSpecial State); |
| 224 return ruleSet.release(); | 254 return ruleSet.release(); |
| 225 } | 255 } |
| 226 | 256 |
| 227 void StyleResolver::collectFeatures() | 257 void StyleResolver::collectFeatures() |
| 228 { | 258 { |
| 229 m_features.clear(); | 259 m_features.clear(); |
| 230 // Collect all ids and rules using sibling selectors (:first-child and simil ar) | 260 m_features.add(defaultStyles().features()); |
| 231 // in the current set of stylesheets. Style sharing code uses this informati on to reject | |
| 232 // sharing candidates. | |
| 233 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance( ); | |
| 234 if (defaultStyleSheets.defaultStyle()) | |
| 235 m_features.add(defaultStyleSheets.defaultStyle()->features()); | |
| 236 | 261 |
| 237 document().styleEngine()->collectScopedStyleFeaturesTo(m_features); | 262 document().styleEngine()->collectScopedStyleFeaturesTo(m_features); |
| 238 | 263 |
| 239 m_attributeRuleSet = makeRuleSet(m_features.attributeRules); | 264 m_attributeRuleSet = makeRuleSet(m_features.attributeRules); |
| 240 m_needCollectFeatures = false; | 265 m_needCollectFeatures = false; |
| 241 } | 266 } |
| 242 | 267 |
| 243 bool StyleResolver::hasRulesForId(const AtomicString& id) const | 268 bool StyleResolver::hasRulesForId(const AtomicString& id) const |
| 244 { | 269 { |
| 245 return m_features.hasSelectorForId(id); | 270 return m_features.hasSelectorForId(id); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, apply AuthorStyles, cascadeScope++, resolver->treeScope() == element->treeScope() && r esolver->treeScope().rootNode().isShadowRoot() ? 0 : cascadeOrder); | 364 resolver->collectMatchingAuthorRules(collector, includeEmptyRules, apply AuthorStyles, cascadeScope++, resolver->treeScope() == element->treeScope() && r esolver->treeScope().rootNode().isShadowRoot() ? 0 : cascadeOrder); |
| 340 } | 365 } |
| 341 | 366 |
| 342 collector.sortAndTransferMatchedRules(); | 367 collector.sortAndTransferMatchedRules(); |
| 343 } | 368 } |
| 344 | 369 |
| 345 void StyleResolver::matchUARules(ElementRuleCollector& collector) | 370 void StyleResolver::matchUARules(ElementRuleCollector& collector) |
| 346 { | 371 { |
| 347 collector.setMatchingUARules(true); | 372 collector.setMatchingUARules(true); |
| 348 | 373 |
| 349 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance( ); | 374 matchUARules(collector, &defaultStyles()); |
|
ojan
2014/11/11 02:41:51
FWIW, we need to get rid of the special UA matchin
| |
| 350 RuleSet* userAgentStyleSheet = defaultStyleSheets.defaultStyle(); | |
| 351 matchUARules(collector, userAgentStyleSheet); | |
| 352 | 375 |
| 353 collector.setMatchingUARules(false); | 376 collector.setMatchingUARules(false); |
| 354 } | 377 } |
| 355 | 378 |
| 356 void StyleResolver::matchUARules(ElementRuleCollector& collector, RuleSet* rules ) | 379 void StyleResolver::matchUARules(ElementRuleCollector& collector, RuleSet* rules ) |
| 357 { | 380 { |
| 358 collector.clearMatchedRules(); | 381 collector.clearMatchedRules(); |
| 359 collector.matchedResult().ranges.lastUARule = collector.matchedResult().matc hedProperties.size() - 1; | 382 collector.matchedResult().ranges.lastUARule = collector.matchedResult().matc hedProperties.size() - 1; |
| 360 | 383 |
| 361 RuleRange ruleRange = collector.matchedResult().ranges.UARuleRange(); | 384 RuleRange ruleRange = collector.matchedResult().ranges.UARuleRange(); |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 visitor->trace(m_viewportDependentMediaQueryResults); | 1009 visitor->trace(m_viewportDependentMediaQueryResults); |
| 987 visitor->trace(m_features); | 1010 visitor->trace(m_features); |
| 988 visitor->trace(m_attributeRuleSet); | 1011 visitor->trace(m_attributeRuleSet); |
| 989 visitor->trace(m_styleSharingLists); | 1012 visitor->trace(m_styleSharingLists); |
| 990 visitor->trace(m_pendingStyleSheets); | 1013 visitor->trace(m_pendingStyleSheets); |
| 991 visitor->trace(m_document); | 1014 visitor->trace(m_document); |
| 992 #endif | 1015 #endif |
| 993 } | 1016 } |
| 994 | 1017 |
| 995 } // namespace blink | 1018 } // namespace blink |
| OLD | NEW |