OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 for (unsigned i = 0; i < sheets.size() && !m_dirtiesAllStyle; ++i) | 47 for (unsigned i = 0; i < sheets.size() && !m_dirtiesAllStyle; ++i) |
48 analyzeStyleSheet(sheets[i]); | 48 analyzeStyleSheet(sheets[i]); |
49 } | 49 } |
50 | 50 |
51 static bool determineSelectorScopes(const CSSSelectorList& selectorList, | 51 static bool determineSelectorScopes(const CSSSelectorList& selectorList, |
52 HashSet<StringImpl*>& idScopes, | 52 HashSet<StringImpl*>& idScopes, |
53 HashSet<StringImpl*>& classScopes) { | 53 HashSet<StringImpl*>& classScopes) { |
54 for (const CSSSelector* selector = selectorList.first(); selector; | 54 for (const CSSSelector* selector = selectorList.first(); selector; |
55 selector = CSSSelectorList::next(*selector)) { | 55 selector = CSSSelectorList::next(*selector)) { |
56 const CSSSelector* scopeSelector = 0; | 56 const CSSSelector* scopeSelector = 0; |
57 // This picks the widest scope, not the narrowest, to minimize the number of
found scopes. | 57 // This picks the widest scope, not the narrowest, to minimize the number of |
| 58 // found scopes. |
58 for (const CSSSelector* current = selector; current; | 59 for (const CSSSelector* current = selector; current; |
59 current = current->tagHistory()) { | 60 current = current->tagHistory()) { |
60 // Prefer ids over classes. | 61 // Prefer ids over classes. |
61 if (current->match() == CSSSelector::Id) | 62 if (current->match() == CSSSelector::Id) |
62 scopeSelector = current; | 63 scopeSelector = current; |
63 else if (current->match() == CSSSelector::Class && | 64 else if (current->match() == CSSSelector::Class && |
64 (!scopeSelector || scopeSelector->match() != CSSSelector::Id)) | 65 (!scopeSelector || scopeSelector->match() != CSSSelector::Id)) |
65 scopeSelector = current; | 66 scopeSelector = current; |
66 CSSSelector::RelationType relation = current->relation(); | 67 CSSSelector::RelationType relation = current->relation(); |
67 // FIXME: it would be better to use setNeedsStyleRecalc for all shadow hos
ts matching | 68 // FIXME: it would be better to use setNeedsStyleRecalc for all shadow |
| 69 // hosts matching |
68 // scopeSelector. Currently requests full style recalc. | 70 // scopeSelector. Currently requests full style recalc. |
69 if (relation == CSSSelector::ShadowDeep || | 71 if (relation == CSSSelector::ShadowDeep || |
70 relation == CSSSelector::ShadowPseudo) | 72 relation == CSSSelector::ShadowPseudo) |
71 return false; | 73 return false; |
72 if (relation != CSSSelector::Descendant && | 74 if (relation != CSSSelector::Descendant && |
73 relation != CSSSelector::Child && | 75 relation != CSSSelector::Child && |
74 relation != CSSSelector::SubSelector) | 76 relation != CSSSelector::SubSelector) |
75 break; | 77 break; |
76 } | 78 } |
77 if (!scopeSelector) | 79 if (!scopeSelector) |
78 return false; | 80 return false; |
79 ASSERT(scopeSelector->match() == CSSSelector::Class || | 81 ASSERT(scopeSelector->match() == CSSSelector::Class || |
80 scopeSelector->match() == CSSSelector::Id); | 82 scopeSelector->match() == CSSSelector::Id); |
81 if (scopeSelector->match() == CSSSelector::Id) | 83 if (scopeSelector->match() == CSSSelector::Id) |
82 idScopes.add(scopeSelector->value().impl()); | 84 idScopes.add(scopeSelector->value().impl()); |
83 else | 85 else |
84 classScopes.add(scopeSelector->value().impl()); | 86 classScopes.add(scopeSelector->value().impl()); |
85 } | 87 } |
86 return true; | 88 return true; |
87 } | 89 } |
88 | 90 |
89 static bool ruleAdditionMightRequireDocumentStyleRecalc(StyleRuleBase* rule) { | 91 static bool ruleAdditionMightRequireDocumentStyleRecalc(StyleRuleBase* rule) { |
90 // This function is conservative. We only return false when we know that | 92 // This function is conservative. We only return false when we know that |
91 // the added @rule can't require style recalcs. | 93 // the added @rule can't require style recalcs. |
92 switch (rule->type()) { | 94 switch (rule->type()) { |
93 case StyleRule:: | 95 case StyleRule::Import: // Whatever we import should do its own analysis, |
94 Import: // Whatever we import should do its own analysis, we don't need
to invalidate the document here! | 96 // we don't need to invalidate the document here! |
95 case StyleRule:: | 97 case StyleRule::Page: // Page rules apply only during printing, we force a |
96 Page: // Page rules apply only during printing, we force a full-recalc
before printing. | 98 // full-recalc before printing. |
97 return false; | 99 return false; |
98 | 100 |
99 case StyleRule:: | 101 case StyleRule::Media: // If the media rule doesn't apply, we could avoid |
100 Media: // If the media rule doesn't apply, we could avoid recalc. | 102 // recalc. |
101 case StyleRule:: | 103 case StyleRule::FontFace: // If the fonts aren't in use, we could avoid |
102 FontFace: // If the fonts aren't in use, we could avoid recalc. | 104 // recalc. |
103 case StyleRule:: | 105 case StyleRule::Supports: // If we evaluated the supports-clause we could |
104 Supports: // If we evaluated the supports-clause we could avoid recalc. | 106 // avoid recalc. |
105 case StyleRule:: | 107 case StyleRule::Viewport: // If the viewport doesn't match, we could avoid |
106 Viewport: // If the viewport doesn't match, we could avoid recalcing. | 108 // recalcing. |
107 return true; | 109 return true; |
108 | 110 |
109 // These should all be impossible to reach: | 111 // These should all be impossible to reach: |
110 case StyleRule::Charset: | 112 case StyleRule::Charset: |
111 case StyleRule::Keyframe: | 113 case StyleRule::Keyframe: |
112 case StyleRule::Namespace: | 114 case StyleRule::Namespace: |
113 case StyleRule::Style: | 115 case StyleRule::Style: |
114 case StyleRule::Keyframes: | 116 case StyleRule::Keyframes: |
115 break; | 117 break; |
116 } | 118 } |
117 ASSERT_NOT_REACHED(); | 119 ASSERT_NOT_REACHED(); |
118 return true; | 120 return true; |
119 } | 121 } |
120 | 122 |
121 void StyleSheetInvalidationAnalysis::analyzeStyleSheet( | 123 void StyleSheetInvalidationAnalysis::analyzeStyleSheet( |
122 StyleSheetContents* styleSheetContents) { | 124 StyleSheetContents* styleSheetContents) { |
123 // Updating the style on the shadow DOM for image fallback content can bring u
s here when imports | 125 // Updating the style on the shadow DOM for image fallback content can bring |
124 // are still getting loaded in the main document. Just need to exit early as w
e will return here | 126 // us here when imports are still getting loaded in the main document. Just |
125 // when the imports finish loading. | 127 // need to exit early as we will return here when the imports finish loading. |
126 if (styleSheetContents->isLoading()) | 128 if (styleSheetContents->isLoading()) |
127 return; | 129 return; |
128 | 130 |
129 // See if all rules on the sheet are scoped to some specific ids or classes. | 131 // See if all rules on the sheet are scoped to some specific ids or classes. |
130 // Then test if we actually have any of those in the tree at the moment. | 132 // Then test if we actually have any of those in the tree at the moment. |
131 const HeapVector<Member<StyleRuleImport>>& importRules = | 133 const HeapVector<Member<StyleRuleImport>>& importRules = |
132 styleSheetContents->importRules(); | 134 styleSheetContents->importRules(); |
133 for (unsigned i = 0; i < importRules.size(); ++i) { | 135 for (unsigned i = 0; i < importRules.size(); ++i) { |
134 if (!importRules[i]->styleSheet()) | 136 if (!importRules[i]->styleSheet()) |
135 continue; | 137 continue; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 StyleChangeReason::StyleSheetChange)); | 208 StyleChangeReason::StyleSheetChange)); |
207 // The whole subtree is now invalidated, we can skip to the next sibling. | 209 // The whole subtree is now invalidated, we can skip to the next sibling. |
208 element = ElementTraversal::nextSkippingChildren(*element); | 210 element = ElementTraversal::nextSkippingChildren(*element); |
209 continue; | 211 continue; |
210 } | 212 } |
211 element = ElementTraversal::next(*element); | 213 element = ElementTraversal::next(*element); |
212 } | 214 } |
213 } | 215 } |
214 | 216 |
215 } // namespace blink | 217 } // namespace blink |
OLD | NEW |