Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(658)

Side by Side Diff: third_party/WebKit/Source/core/css/resolver/StyleResolver.cpp

Issue 1913833002: Current work-in-progress crbug.com/567021 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed html import issue. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 StyleResolver::~StyleResolver() {} 184 StyleResolver::~StyleResolver() {}
185 185
186 void StyleResolver::dispose() { 186 void StyleResolver::dispose() {
187 m_matchedPropertiesCache.clear(); 187 m_matchedPropertiesCache.clear();
188 } 188 }
189 189
190 void StyleResolver::setRuleUsageTracker(StyleRuleUsageTracker* tracker) { 190 void StyleResolver::setRuleUsageTracker(StyleRuleUsageTracker* tracker) {
191 m_tracker = tracker; 191 m_tracker = tracker;
192 } 192 }
193 193
194 void StyleResolver::lazyAppendAuthorStyleSheets(
195 unsigned firstNew,
196 const HeapVector<Member<CSSStyleSheet>>& styleSheets) {
197 unsigned size = styleSheets.size();
198 for (unsigned i = firstNew; i < size; ++i)
199 m_pendingStyleSheets.add(styleSheets[i].get());
200 }
201
202 void StyleResolver::removePendingAuthorStyleSheets(
203 const HeapVector<Member<CSSStyleSheet>>& styleSheets) {
204 for (unsigned i = 0; i < styleSheets.size(); ++i)
205 m_pendingStyleSheets.remove(styleSheets[i].get());
206 }
207
208 void StyleResolver::appendCSSStyleSheet(CSSStyleSheet& cssSheet) {
209 DCHECK(!cssSheet.disabled());
210 DCHECK(cssSheet.ownerDocument());
211 DCHECK(cssSheet.ownerNode());
212 DCHECK(isHTMLStyleElement(cssSheet.ownerNode()) ||
213 isSVGStyleElement(cssSheet.ownerNode()) ||
214 cssSheet.ownerNode()->isConnected());
215
216 TreeScope* treeScope = &cssSheet.ownerNode()->treeScope();
217 // TODO(rune@opera.com): This is a workaround for crbug.com/559292
218 // when we're in the middle of removing a subtree with a style element
219 // and the treescope has been changed but inDocument and isInShadowTree
220 // are not.
221 //
222 // This check can be removed when crbug.com/567021 is fixed.
223 if (cssSheet.ownerNode()->isInShadowTree() &&
224 treeScope->rootNode().isDocumentNode())
225 return;
226
227 // Sheets in the document scope of HTML imports apply to the main document
228 // (m_document), so we override it for all document scoped sheets.
229 if (treeScope->rootNode().isDocumentNode())
230 treeScope = m_document;
231 treeScope->ensureScopedStyleResolver().appendCSSStyleSheet(cssSheet);
232 }
233
234 void StyleResolver::appendPendingAuthorStyleSheets() {
235 for (const auto& styleSheet : m_pendingStyleSheets)
236 appendCSSStyleSheet(*styleSheet);
237
238 m_pendingStyleSheets.clear();
239 }
240
241 void StyleResolver::appendAuthorStyleSheets(
242 const HeapVector<Member<CSSStyleSheet>>& styleSheets) {
243 // This handles sheets added to the end of the stylesheet list only. In other
244 // cases the style resolver needs to be reconstructed. To handle insertions
245 // too the rule order numbers would need to be updated.
246 for (const auto& styleSheet : styleSheets)
247 appendCSSStyleSheet(*styleSheet);
248 }
249
250 void StyleResolver::addToStyleSharingList(Element& element) { 194 void StyleResolver::addToStyleSharingList(Element& element) {
251 DCHECK(RuntimeEnabledFeatures::styleSharingEnabled()); 195 DCHECK(RuntimeEnabledFeatures::styleSharingEnabled());
252 // Never add elements to the style sharing list if we're not in a recalcStyle, 196 // Never add elements to the style sharing list if we're not in a recalcStyle,
253 // otherwise we could leave stale pointers in there. 197 // otherwise we could leave stale pointers in there.
254 if (!document().inStyleRecalc()) 198 if (!document().inStyleRecalc())
255 return; 199 return;
256 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), sharedStyleCandidates, 200 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), sharedStyleCandidates,
257 1); 201 1);
258 StyleSharingList& list = styleSharingList(); 202 StyleSharingList& list = styleSharingList();
259 if (list.size() >= styleSharingListSize) 203 if (list.size() >= styleSharingListSize)
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 state.elementStyleResources().loadPendingResources(state.style()); 581 state.elementStyleResources().loadPendingResources(state.style());
638 } 582 }
639 583
640 PassRefPtr<ComputedStyle> StyleResolver::styleForElement( 584 PassRefPtr<ComputedStyle> StyleResolver::styleForElement(
641 Element* element, 585 Element* element,
642 const ComputedStyle* defaultParent, 586 const ComputedStyle* defaultParent,
643 StyleSharingBehavior sharingBehavior, 587 StyleSharingBehavior sharingBehavior,
644 RuleMatchingBehavior matchingBehavior) { 588 RuleMatchingBehavior matchingBehavior) {
645 DCHECK(document().frame()); 589 DCHECK(document().frame());
646 DCHECK(document().settings()); 590 DCHECK(document().settings());
647 DCHECK(!hasPendingAuthorStyleSheets());
648 591
649 // Once an element has a layoutObject, we don't try to destroy it, since 592 // Once an element has a layoutObject, we don't try to destroy it, since
650 // otherwise the layoutObject will vanish if a style recalc happens during 593 // otherwise the layoutObject will vanish if a style recalc happens during
651 // loading. 594 // loading.
652 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() && 595 if (sharingBehavior == AllowStyleSharing && !document().isRenderingReady() &&
653 !element->layoutObject()) { 596 !element->layoutObject()) {
654 if (!s_styleNotYetAvailable) { 597 if (!s_styleNotYetAvailable) {
655 s_styleNotYetAvailable = ComputedStyle::create().leakRef(); 598 s_styleNotYetAvailable = ComputedStyle::create().leakRef();
656 s_styleNotYetAvailable->setDisplay(EDisplay::None); 599 s_styleNotYetAvailable->setDisplay(EDisplay::None);
657 s_styleNotYetAvailable->font().update( 600 s_styleNotYetAvailable->font().update(
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 921
979 if (PseudoElement* pseudoElement = 922 if (PseudoElement* pseudoElement =
980 element->pseudoElement(pseudoStyleRequest.pseudoId)) 923 element->pseudoElement(pseudoStyleRequest.pseudoId))
981 setAnimationUpdateIfNeeded(state, *pseudoElement); 924 setAnimationUpdateIfNeeded(state, *pseudoElement);
982 925
983 // Now return the style. 926 // Now return the style.
984 return state.takeStyle(); 927 return state.takeStyle();
985 } 928 }
986 929
987 PassRefPtr<ComputedStyle> StyleResolver::styleForPage(int pageIndex) { 930 PassRefPtr<ComputedStyle> StyleResolver::styleForPage(int pageIndex) {
988 DCHECK(!hasPendingAuthorStyleSheets());
989 // m_rootElementStyle will be set to the document style. 931 // m_rootElementStyle will be set to the document style.
990 StyleResolverState state(document(), document().documentElement()); 932 StyleResolverState state(document(), document().documentElement());
991 933
992 RefPtr<ComputedStyle> style = ComputedStyle::create(); 934 RefPtr<ComputedStyle> style = ComputedStyle::create();
993 const ComputedStyle* rootElementStyle = state.rootElementStyle() 935 const ComputedStyle* rootElementStyle = state.rootElementStyle()
994 ? state.rootElementStyle() 936 ? state.rootElementStyle()
995 : document().computedStyle(); 937 : document().computedStyle();
996 DCHECK(rootElementStyle); 938 DCHECK(rootElementStyle);
997 style->inheritFrom(*rootElementStyle); 939 style->inheritFrom(*rootElementStyle);
998 state.setStyle(style.release()); 940 state.setStyle(style.release());
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 const MatchedProperties* properties, 1522 const MatchedProperties* properties,
1581 unsigned size) { 1523 unsigned size) {
1582 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size); 1524 return StringHasher::hashMemory(properties, sizeof(MatchedProperties) * size);
1583 } 1525 }
1584 1526
1585 void StyleResolver::invalidateMatchedPropertiesCache() { 1527 void StyleResolver::invalidateMatchedPropertiesCache() {
1586 m_matchedPropertiesCache.clear(); 1528 m_matchedPropertiesCache.clear();
1587 } 1529 }
1588 1530
1589 void StyleResolver::notifyResizeForViewportUnits() { 1531 void StyleResolver::notifyResizeForViewportUnits() {
1532 document().styleEngine().updateActiveStyle();
1590 m_matchedPropertiesCache.clearViewportDependent(); 1533 m_matchedPropertiesCache.clearViewportDependent();
1591 } 1534 }
1592 1535
1593 void StyleResolver::applyMatchedProperties(StyleResolverState& state, 1536 void StyleResolver::applyMatchedProperties(StyleResolverState& state,
1594 const MatchResult& matchResult) { 1537 const MatchResult& matchResult) {
1595 const Element* element = state.element(); 1538 const Element* element = state.element();
1596 DCHECK(element); 1539 DCHECK(element);
1597 1540
1598 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), matchedPropertyApply, 1541 INCREMENT_STYLE_STATS_COUNTER(document().styleEngine(), matchedPropertyApply,
1599 1); 1542 1);
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 if (FrameView* view = document().view()) { 1782 if (FrameView* view = document().view()) {
1840 m_printMediaType = 1783 m_printMediaType =
1841 equalIgnoringCase(view->mediaType(), MediaTypeNames::print); 1784 equalIgnoringCase(view->mediaType(), MediaTypeNames::print);
1842 } 1785 }
1843 } 1786 }
1844 1787
1845 DEFINE_TRACE(StyleResolver) { 1788 DEFINE_TRACE(StyleResolver) {
1846 visitor->trace(m_matchedPropertiesCache); 1789 visitor->trace(m_matchedPropertiesCache);
1847 visitor->trace(m_selectorFilter); 1790 visitor->trace(m_selectorFilter);
1848 visitor->trace(m_styleSharingLists); 1791 visitor->trace(m_styleSharingLists);
1849 visitor->trace(m_pendingStyleSheets);
1850 visitor->trace(m_document); 1792 visitor->trace(m_document);
1851 visitor->trace(m_tracker); 1793 visitor->trace(m_tracker);
1852 } 1794 }
1853 1795
1854 } // namespace blink 1796 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/resolver/StyleResolver.h ('k') | third_party/WebKit/Source/core/dom/Document.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698