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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 306 |
307 if (treeScope.rootNode().isDocumentNode()) { | 307 if (treeScope.rootNode().isDocumentNode()) { |
308 resolver->resetAuthorStyle(); | 308 resolver->resetAuthorStyle(); |
309 return; | 309 return; |
310 } | 310 } |
311 | 311 |
312 // resolver is going to be freed below. | 312 // resolver is going to be freed below. |
313 treeScope.clearScopedStyleResolver(); | 313 treeScope.clearScopedStyleResolver(); |
314 } | 314 } |
315 | 315 |
316 static RawPtr<RuleSet> makeRuleSet(const HeapVector<RuleFeature>& rules) | 316 static RuleSet* makeRuleSet(const HeapVector<RuleFeature>& rules) |
317 { | 317 { |
318 size_t size = rules.size(); | 318 size_t size = rules.size(); |
319 if (!size) | 319 if (!size) |
320 return nullptr; | 320 return nullptr; |
321 RawPtr<RuleSet> ruleSet = RuleSet::create(); | 321 RuleSet* ruleSet = RuleSet::create(); |
322 for (size_t i = 0; i < size; ++i) | 322 for (size_t i = 0; i < size; ++i) |
323 ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, rules[i].hasDocu
mentSecurityOrigin ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState); | 323 ruleSet->addRule(rules[i].rule, rules[i].selectorIndex, rules[i].hasDocu
mentSecurityOrigin ? RuleHasDocumentSecurityOrigin : RuleHasNoSpecialState); |
324 return ruleSet.release(); | 324 return ruleSet; |
325 } | 325 } |
326 | 326 |
327 void StyleResolver::collectFeatures() | 327 void StyleResolver::collectFeatures() |
328 { | 328 { |
329 m_features.clear(); | 329 m_features.clear(); |
330 // Collect all ids and rules using sibling selectors (:first-child and simil
ar) | 330 // Collect all ids and rules using sibling selectors (:first-child and simil
ar) |
331 // in the current set of stylesheets. Style sharing code uses this informati
on to reject | 331 // in the current set of stylesheets. Style sharing code uses this informati
on to reject |
332 // sharing candidates. | 332 // sharing candidates. |
333 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance(
); | 333 CSSDefaultStyleSheets& defaultStyleSheets = CSSDefaultStyleSheets::instance(
); |
334 if (defaultStyleSheets.defaultStyle()) { | 334 if (defaultStyleSheets.defaultStyle()) { |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 | 851 |
852 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(StyleRe
solverState& state, CSSPropertyID property, CSSValue* value) | 852 PassRefPtr<AnimatableValue> StyleResolver::createAnimatableValueSnapshot(StyleRe
solverState& state, CSSPropertyID property, CSSValue* value) |
853 { | 853 { |
854 if (value) { | 854 if (value) { |
855 StyleBuilder::applyProperty(property, state, value); | 855 StyleBuilder::applyProperty(property, state, value); |
856 state.fontBuilder().createFont(state.document().styleEngine().fontSelect
or(), state.mutableStyleRef()); | 856 state.fontBuilder().createFont(state.document().styleEngine().fontSelect
or(), state.mutableStyleRef()); |
857 } | 857 } |
858 return CSSAnimatableValueFactory::create(property, *state.style()); | 858 return CSSAnimatableValueFactory::create(property, *state.style()); |
859 } | 859 } |
860 | 860 |
861 RawPtr<PseudoElement> StyleResolver::createPseudoElement(Element* parent, Pseudo
Id pseudoId) | 861 PseudoElement* StyleResolver::createPseudoElement(Element* parent, PseudoId pseu
doId) |
862 { | 862 { |
863 if (pseudoId == PseudoIdFirstLetter) | 863 if (pseudoId == PseudoIdFirstLetter) |
864 return FirstLetterPseudoElement::create(parent); | 864 return FirstLetterPseudoElement::create(parent); |
865 return PseudoElement::create(parent, pseudoId); | 865 return PseudoElement::create(parent, pseudoId); |
866 } | 866 } |
867 | 867 |
868 RawPtr<PseudoElement> StyleResolver::createPseudoElementIfNeeded(Element& parent
, PseudoId pseudoId) | 868 PseudoElement* StyleResolver::createPseudoElementIfNeeded(Element& parent, Pseud
oId pseudoId) |
869 { | 869 { |
870 LayoutObject* parentLayoutObject = parent.layoutObject(); | 870 LayoutObject* parentLayoutObject = parent.layoutObject(); |
871 if (!parentLayoutObject) | 871 if (!parentLayoutObject) |
872 return nullptr; | 872 return nullptr; |
873 | 873 |
874 // The first letter pseudo element has to look up the tree and see if any | 874 // The first letter pseudo element has to look up the tree and see if any |
875 // of the ancestors are first letter. | 875 // of the ancestors are first letter. |
876 if (pseudoId < FirstInternalPseudoId && pseudoId != PseudoIdFirstLetter && !
parentLayoutObject->style()->hasPseudoStyle(pseudoId)) | 876 if (pseudoId < FirstInternalPseudoId && pseudoId != PseudoIdFirstLetter && !
parentLayoutObject->style()->hasPseudoStyle(pseudoId)) |
877 return nullptr; | 877 return nullptr; |
878 | 878 |
(...skipping 16 matching lines...) Expand all Loading... |
895 StyleResolverState state(document(), &parent, parentStyle); | 895 StyleResolverState state(document(), &parent, parentStyle); |
896 if (!pseudoStyleForElementInternal(parent, pseudoId, parentStyle, state)) | 896 if (!pseudoStyleForElementInternal(parent, pseudoId, parentStyle, state)) |
897 return nullptr; | 897 return nullptr; |
898 RefPtr<ComputedStyle> style = state.takeStyle(); | 898 RefPtr<ComputedStyle> style = state.takeStyle(); |
899 ASSERT(style); | 899 ASSERT(style); |
900 parentStyle->addCachedPseudoStyle(style); | 900 parentStyle->addCachedPseudoStyle(style); |
901 | 901 |
902 if (!pseudoElementLayoutObjectIsNeeded(style.get())) | 902 if (!pseudoElementLayoutObjectIsNeeded(style.get())) |
903 return nullptr; | 903 return nullptr; |
904 | 904 |
905 RawPtr<PseudoElement> pseudo = createPseudoElement(&parent, pseudoId); | 905 PseudoElement* pseudo = createPseudoElement(&parent, pseudoId); |
906 | 906 |
907 setAnimationUpdateIfNeeded(state, *pseudo); | 907 setAnimationUpdateIfNeeded(state, *pseudo); |
908 if (ElementAnimations* elementAnimations = pseudo->elementAnimations()) | 908 if (ElementAnimations* elementAnimations = pseudo->elementAnimations()) |
909 elementAnimations->cssAnimations().maybeApplyPendingUpdate(pseudo.get())
; | 909 elementAnimations->cssAnimations().maybeApplyPendingUpdate(pseudo); |
910 return pseudo.release(); | 910 return pseudo; |
911 } | 911 } |
912 | 912 |
913 bool StyleResolver::pseudoStyleForElementInternal(Element& element, const Pseudo
StyleRequest& pseudoStyleRequest, const ComputedStyle* parentStyle, StyleResolve
rState& state) | 913 bool StyleResolver::pseudoStyleForElementInternal(Element& element, const Pseudo
StyleRequest& pseudoStyleRequest, const ComputedStyle* parentStyle, StyleResolve
rState& state) |
914 { | 914 { |
915 ASSERT(document().frame()); | 915 ASSERT(document().frame()); |
916 ASSERT(document().settings()); | 916 ASSERT(document().settings()); |
917 ASSERT(pseudoStyleRequest.pseudoId != PseudoIdFirstLineInherited); | 917 ASSERT(pseudoStyleRequest.pseudoId != PseudoIdFirstLineInherited); |
918 ASSERT(state.parentStyle()); | 918 ASSERT(state.parentStyle()); |
919 | 919 |
920 SelectorFilterParentScope::ensureParentStackIsPushed(); | 920 SelectorFilterParentScope::ensureParentStackIsPushed(); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 return parentNode->mutableComputedStyle(); | 1054 return parentNode->mutableComputedStyle(); |
1055 } | 1055 } |
1056 | 1056 |
1057 void StyleResolver::updateFont(StyleResolverState& state) | 1057 void StyleResolver::updateFont(StyleResolverState& state) |
1058 { | 1058 { |
1059 state.fontBuilder().createFont(document().styleEngine().fontSelector(), stat
e.mutableStyleRef()); | 1059 state.fontBuilder().createFont(document().styleEngine().fontSelector(), stat
e.mutableStyleRef()); |
1060 state.setConversionFontSizes(CSSToLengthConversionData::FontSizes(state.styl
e(), state.rootElementStyle())); | 1060 state.setConversionFontSizes(CSSToLengthConversionData::FontSizes(state.styl
e(), state.rootElementStyle())); |
1061 state.setConversionZoom(state.style()->effectiveZoom()); | 1061 state.setConversionZoom(state.style()->effectiveZoom()); |
1062 } | 1062 } |
1063 | 1063 |
1064 RawPtr<StyleRuleList> StyleResolver::styleRulesForElement(Element* element, unsi
gned rulesToInclude) | 1064 StyleRuleList* StyleResolver::styleRulesForElement(Element* element, unsigned ru
lesToInclude) |
1065 { | 1065 { |
1066 ASSERT(element); | 1066 ASSERT(element); |
1067 StyleResolverState state(document(), element); | 1067 StyleResolverState state(document(), element); |
1068 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, sta
te.style()); | 1068 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, sta
te.style()); |
1069 collector.setMode(SelectorChecker::CollectingStyleRules); | 1069 collector.setMode(SelectorChecker::CollectingStyleRules); |
1070 collectPseudoRulesForElement(*element, collector, PseudoIdNone, rulesToInclu
de); | 1070 collectPseudoRulesForElement(*element, collector, PseudoIdNone, rulesToInclu
de); |
1071 return collector.matchedStyleRuleList(); | 1071 return collector.matchedStyleRuleList(); |
1072 } | 1072 } |
1073 | 1073 |
1074 RawPtr<CSSRuleList> StyleResolver::pseudoCSSRulesForElement(Element* element, Ps
eudoId pseudoId, unsigned rulesToInclude) | 1074 CSSRuleList* StyleResolver::pseudoCSSRulesForElement(Element* element, PseudoId
pseudoId, unsigned rulesToInclude) |
1075 { | 1075 { |
1076 ASSERT(element); | 1076 ASSERT(element); |
1077 StyleResolverState state(document(), element); | 1077 StyleResolverState state(document(), element); |
1078 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, sta
te.style()); | 1078 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, sta
te.style()); |
1079 collector.setMode(SelectorChecker::CollectingCSSRules); | 1079 collector.setMode(SelectorChecker::CollectingCSSRules); |
1080 collectPseudoRulesForElement(*element, collector, pseudoId, rulesToInclude); | 1080 collectPseudoRulesForElement(*element, collector, pseudoId, rulesToInclude); |
1081 return collector.matchedCSSRuleList(); | 1081 return collector.matchedCSSRuleList(); |
1082 } | 1082 } |
1083 | 1083 |
1084 RawPtr<CSSRuleList> StyleResolver::cssRulesForElement(Element* element, unsigned
rulesToInclude) | 1084 CSSRuleList* StyleResolver::cssRulesForElement(Element* element, unsigned rulesT
oInclude) |
1085 { | 1085 { |
1086 return pseudoCSSRulesForElement(element, PseudoIdNone, rulesToInclude); | 1086 return pseudoCSSRulesForElement(element, PseudoIdNone, rulesToInclude); |
1087 } | 1087 } |
1088 | 1088 |
1089 void StyleResolver::collectPseudoRulesForElement(const Element& element, Element
RuleCollector& collector, PseudoId pseudoId, unsigned rulesToInclude) | 1089 void StyleResolver::collectPseudoRulesForElement(const Element& element, Element
RuleCollector& collector, PseudoId pseudoId, unsigned rulesToInclude) |
1090 { | 1090 { |
1091 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); | 1091 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); |
1092 | 1092 |
1093 if (rulesToInclude & UAAndUserCSSRules) | 1093 if (rulesToInclude & UAAndUserCSSRules) |
1094 matchUARules(collector); | 1094 matchUARules(collector); |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1655 return; | 1655 return; |
1656 | 1656 |
1657 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, sta
te.style()); | 1657 ElementRuleCollector collector(state.elementContext(), m_selectorFilter, sta
te.style()); |
1658 collector.setMode(SelectorChecker::CollectingStyleRules); | 1658 collector.setMode(SelectorChecker::CollectingStyleRules); |
1659 collector.setIncludeEmptyRules(true); | 1659 collector.setIncludeEmptyRules(true); |
1660 | 1660 |
1661 MatchRequest matchRequest(m_watchedSelectorsRules.get()); | 1661 MatchRequest matchRequest(m_watchedSelectorsRules.get()); |
1662 collector.collectMatchingRules(matchRequest); | 1662 collector.collectMatchingRules(matchRequest); |
1663 collector.sortAndTransferMatchedRules(); | 1663 collector.sortAndTransferMatchedRules(); |
1664 | 1664 |
1665 RawPtr<StyleRuleList> rules = collector.matchedStyleRuleList(); | 1665 StyleRuleList* rules = collector.matchedStyleRuleList(); |
1666 if (!rules) | 1666 if (!rules) |
1667 return; | 1667 return; |
1668 for (size_t i = 0; i < rules->size(); i++) | 1668 for (size_t i = 0; i < rules->size(); i++) |
1669 state.style()->addCallbackSelector(rules->at(i)->selectorList().selector
sText()); | 1669 state.style()->addCallbackSelector(rules->at(i)->selectorList().selector
sText()); |
1670 } | 1670 } |
1671 | 1671 |
1672 void StyleResolver::computeFont(ComputedStyle* style, const StylePropertySet& pr
opertySet) | 1672 void StyleResolver::computeFont(ComputedStyle* style, const StylePropertySet& pr
opertySet) |
1673 { | 1673 { |
1674 CSSPropertyID properties[] = { | 1674 CSSPropertyID properties[] = { |
1675 CSSPropertyFontSize, | 1675 CSSPropertyFontSize, |
1676 CSSPropertyFontFamily, | 1676 CSSPropertyFontFamily, |
1677 CSSPropertyFontStretch, | 1677 CSSPropertyFontStretch, |
1678 CSSPropertyFontStyle, | 1678 CSSPropertyFontStyle, |
1679 CSSPropertyFontVariant, | 1679 CSSPropertyFontVariant, |
1680 CSSPropertyFontWeight, | 1680 CSSPropertyFontWeight, |
1681 CSSPropertyLineHeight, | 1681 CSSPropertyLineHeight, |
1682 }; | 1682 }; |
1683 | 1683 |
1684 // TODO(timloh): This is weird, the style is being used as its own parent | 1684 // TODO(timloh): This is weird, the style is being used as its own parent |
1685 StyleResolverState state(document(), nullptr, style); | 1685 StyleResolverState state(document(), nullptr, style); |
1686 state.setStyle(style); | 1686 state.setStyle(style); |
1687 | 1687 |
1688 for (CSSPropertyID property : properties) { | 1688 for (CSSPropertyID property : properties) { |
1689 if (property == CSSPropertyLineHeight) | 1689 if (property == CSSPropertyLineHeight) |
1690 updateFont(state); | 1690 updateFont(state); |
1691 StyleBuilder::applyProperty(property, state, propertySet.getPropertyCSSV
alue(property).get()); | 1691 StyleBuilder::applyProperty(property, state, propertySet.getPropertyCSSV
alue(property)); |
1692 } | 1692 } |
1693 } | 1693 } |
1694 | 1694 |
1695 void StyleResolver::addViewportDependentMediaQueries(const MediaQueryResultList&
list) | 1695 void StyleResolver::addViewportDependentMediaQueries(const MediaQueryResultList&
list) |
1696 { | 1696 { |
1697 for (size_t i = 0; i < list.size(); ++i) | 1697 for (size_t i = 0; i < list.size(); ++i) |
1698 m_viewportDependentMediaQueryResults.append(list[i]); | 1698 m_viewportDependentMediaQueryResults.append(list[i]); |
1699 } | 1699 } |
1700 | 1700 |
1701 void StyleResolver::addDeviceDependentMediaQueries(const MediaQueryResultList& l
ist) | 1701 void StyleResolver::addDeviceDependentMediaQueries(const MediaQueryResultList& l
ist) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1734 visitor->trace(m_siblingRuleSet); | 1734 visitor->trace(m_siblingRuleSet); |
1735 visitor->trace(m_uncommonAttributeRuleSet); | 1735 visitor->trace(m_uncommonAttributeRuleSet); |
1736 visitor->trace(m_watchedSelectorsRules); | 1736 visitor->trace(m_watchedSelectorsRules); |
1737 visitor->trace(m_treeBoundaryCrossingScopes); | 1737 visitor->trace(m_treeBoundaryCrossingScopes); |
1738 visitor->trace(m_styleSharingLists); | 1738 visitor->trace(m_styleSharingLists); |
1739 visitor->trace(m_pendingStyleSheets); | 1739 visitor->trace(m_pendingStyleSheets); |
1740 visitor->trace(m_document); | 1740 visitor->trace(m_document); |
1741 } | 1741 } |
1742 | 1742 |
1743 } // namespace blink | 1743 } // namespace blink |
OLD | NEW |