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. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. |
6 * All rights reserved. | 6 * All rights reserved. |
7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 7 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 8 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 9 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
10 * (http://www.torchmobile.com/) | 10 * (http://www.torchmobile.com/) |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 StyleResolver::~StyleResolver() {} | 185 StyleResolver::~StyleResolver() {} |
186 | 186 |
187 void StyleResolver::dispose() { | 187 void StyleResolver::dispose() { |
188 m_matchedPropertiesCache.clear(); | 188 m_matchedPropertiesCache.clear(); |
189 } | 189 } |
190 | 190 |
191 void StyleResolver::setRuleUsageTracker(StyleRuleUsageTracker* tracker) { | 191 void StyleResolver::setRuleUsageTracker(StyleRuleUsageTracker* tracker) { |
192 m_tracker = tracker; | 192 m_tracker = tracker; |
193 } | 193 } |
194 | 194 |
195 void StyleResolver::lazyAppendAuthorStyleSheets( | |
196 unsigned firstNew, | |
197 const HeapVector<Member<CSSStyleSheet>>& styleSheets) { | |
198 unsigned size = styleSheets.size(); | |
199 for (unsigned i = firstNew; i < size; ++i) | |
200 m_pendingStyleSheets.add(styleSheets[i].get()); | |
201 } | |
202 | |
203 void StyleResolver::removePendingAuthorStyleSheets( | |
204 const HeapVector<Member<CSSStyleSheet>>& styleSheets) { | |
205 for (unsigned i = 0; i < styleSheets.size(); ++i) | |
206 m_pendingStyleSheets.remove(styleSheets[i].get()); | |
207 } | |
208 | |
209 void StyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet) { | |
210 DCHECK(!cssSheet.disabled()); | |
211 DCHECK(cssSheet.ownerDocument()); | |
212 DCHECK(cssSheet.ownerNode()); | |
213 DCHECK(isHTMLStyleElement(cssSheet.ownerNode()) || | |
214 isSVGStyleElement(cssSheet.ownerNode()) || | |
215 cssSheet.ownerNode()->isConnected()); | |
216 | |
217 TreeScope* treeScope = &cssSheet.ownerNode()->treeScope(); | |
218 // TODO(rune@opera.com): This is a workaround for crbug.com/559292 | |
219 // when we're in the middle of removing a subtree with a style element | |
220 // and the treescope has been changed but inDocument and isInShadowTree | |
221 // are not. | |
222 // | |
223 // This check can be removed when crbug.com/567021 is fixed. | |
224 if (cssSheet.ownerNode()->isInShadowTree() && | |
225 treeScope->rootNode().isDocumentNode()) | |
226 return; | |
227 | |
228 // Sheets in the document scope of HTML imports apply to the main document | |
229 // (m_document), so we override it for all document scoped sheets. | |
230 if (treeScope->rootNode().isDocumentNode()) | |
231 treeScope = m_document; | |
232 treeScope->ensureScopedStyleResolver().appendCSSStyleSheet(cssSheet); | |
233 } | |
234 | |
235 void StyleResolver::appendPendingAuthorStyleSheets() { | |
236 for (const auto& styleSheet : m_pendingStyleSheets) | |
237 appendCSSStyleSheet(*styleSheet); | |
238 | |
239 m_pendingStyleSheets.clear(); | |
240 } | |
241 | |
242 void StyleResolver::appendAuthorStyleSheets( | |
243 const HeapVector<Member<CSSStyleSheet>>& styleSheets) { | |
244 // This handles sheets added to the end of the stylesheet list only. In other | |
245 // cases the style resolver needs to be reconstructed. To handle insertions | |
246 // too the rule order numbers would need to be updated. | |
247 for (const auto& styleSheet : styleSheets) | |
248 appendCSSStyleSheet(*styleSheet); | |
249 } | |
250 | |
251 void StyleResolver::addToStyleSharingList(Element& element) { | 195 void StyleResolver::addToStyleSharingList(Element& element) { |
252 DCHECK(RuntimeEnabledFeatures::styleSharingEnabled()); | 196 DCHECK(RuntimeEnabledFeatures::styleSharingEnabled()); |
253 // Never add elements to the style sharing list if we're not in a recalcStyle, | 197 // Never add elements to the style sharing list if we're not in a recalcStyle, |
254 // otherwise we could leave stale pointers in there. | 198 // otherwise we could leave stale pointers in there. |
255 if (!document().inStyleRecalc()) | 199 if (!document().inStyleRecalc()) |
256 return; | 200 return; |
257 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), sharedStyleCandidates, | 201 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), sharedStyleCandidates, |
258 1); | 202 1); |
259 StyleSharingList& list = styleSharingList(); | 203 StyleSharingList& list = styleSharingList(); |
260 if (list.size() >= styleSharingListSize) | 204 if (list.size() >= styleSharingListSize) |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 elementAnimations->updateBaseComputedStyle(state.style()); | 619 elementAnimations->updateBaseComputedStyle(state.style()); |
676 } | 620 } |
677 | 621 |
678 PassRefPtr<ComputedStyle> StyleResolver::styleForElement( | 622 PassRefPtr<ComputedStyle> StyleResolver::styleForElement( |
679 Element* element, | 623 Element* element, |
680 const ComputedStyle* defaultParent, | 624 const ComputedStyle* defaultParent, |
681 StyleSharingBehavior sharingBehavior, | 625 StyleSharingBehavior sharingBehavior, |
682 RuleMatchingBehavior matchingBehavior) { | 626 RuleMatchingBehavior matchingBehavior) { |
683 DCHECK(document().frame()); | 627 DCHECK(document().frame()); |
684 DCHECK(document().settings()); | 628 DCHECK(document().settings()); |
685 DCHECK(!hasPendingAuthorStyleSheets()); | |
686 | 629 |
687 // Once an element has a layoutObject, we don't try to destroy it, since | 630 // Once an element has a layoutObject, we don't try to destroy it, since |
688 // otherwise the layoutObject will vanish if a style recalc happens during | 631 // otherwise the layoutObject will vanish if a style recalc happens during |
689 // loading. | 632 // loading. |
690 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() && | 633 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() && |
691 !element->layoutObject()) { | 634 !element->layoutObject()) { |
692 if (!s_styleNotYetAvailable) { | 635 if (!s_styleNotYetAvailable) { |
693 s_styleNotYetAvailable = ComputedStyle::create().leakRef(); | 636 s_styleNotYetAvailable = ComputedStyle::create().leakRef(); |
694 s_styleNotYetAvailable->setDisplay(EDisplay::None); | 637 s_styleNotYetAvailable->setDisplay(EDisplay::None); |
695 s_styleNotYetAvailable->font().update( | 638 s_styleNotYetAvailable->font().update( |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 | 956 |
1014 if (PseudoElement* pseudoElement = | 957 if (PseudoElement* pseudoElement = |
1015 element->pseudoElement(pseudoStyleRequest.pseudoId)) | 958 element->pseudoElement(pseudoStyleRequest.pseudoId)) |
1016 setAnimationUpdateIfNeeded(state, *pseudoElement); | 959 setAnimationUpdateIfNeeded(state, *pseudoElement); |
1017 | 960 |
1018 // Now return the style. | 961 // Now return the style. |
1019 return state.takeStyle(); | 962 return state.takeStyle(); |
1020 } | 963 } |
1021 | 964 |
1022 PassRefPtr<ComputedStyle> StyleResolver::styleForPage(int pageIndex) { | 965 PassRefPtr<ComputedStyle> StyleResolver::styleForPage(int pageIndex) { |
1023 DCHECK(!hasPendingAuthorStyleSheets()); | |
1024 // m_rootElementStyle will be set to the document style. | 966 // m_rootElementStyle will be set to the document style. |
1025 StyleResolverState state(document(), document().documentElement()); | 967 StyleResolverState state(document(), document().documentElement()); |
1026 | 968 |
1027 RefPtr<ComputedStyle> style = ComputedStyle::create(); | 969 RefPtr<ComputedStyle> style = ComputedStyle::create(); |
1028 const ComputedStyle* rootElementStyle = state.rootElementStyle() | 970 const ComputedStyle* rootElementStyle = state.rootElementStyle() |
1029 ? state.rootElementStyle() | 971 ? state.rootElementStyle() |
1030 : document().computedStyle(); | 972 : document().computedStyle(); |
1031 DCHECK(rootElementStyle); | 973 DCHECK(rootElementStyle); |
1032 style->inheritFrom(*rootElementStyle); | 974 style->inheritFrom(*rootElementStyle); |
1033 state.setStyle(style.release()); | 975 state.setStyle(style.release()); |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 if (FrameView* view = document().view()) { | 1919 if (FrameView* view = document().view()) { |
1978 m_printMediaType = | 1920 m_printMediaType = |
1979 equalIgnoringCase(view->mediaType(), MediaTypeNames::print); | 1921 equalIgnoringCase(view->mediaType(), MediaTypeNames::print); |
1980 } | 1922 } |
1981 } | 1923 } |
1982 | 1924 |
1983 DEFINE_TRACE(StyleResolver) { | 1925 DEFINE_TRACE(StyleResolver) { |
1984 visitor->trace(m_matchedPropertiesCache); | 1926 visitor->trace(m_matchedPropertiesCache); |
1985 visitor->trace(m_selectorFilter); | 1927 visitor->trace(m_selectorFilter); |
1986 visitor->trace(m_styleSharingLists); | 1928 visitor->trace(m_styleSharingLists); |
1987 visitor->trace(m_pendingStyleSheets); | |
1988 visitor->trace(m_document); | 1929 visitor->trace(m_document); |
1989 visitor->trace(m_tracker); | 1930 visitor->trace(m_tracker); |
1990 } | 1931 } |
1991 | 1932 |
1992 } // namespace blink | 1933 } // namespace blink |
OLD | NEW |