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

Side by Side Diff: sky/engine/core/dom/StyleEngine.cpp

Issue 844133002: Simplify tree scope tracking in StyleEngine. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months 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
« no previous file with comments | « sky/engine/core/dom/StyleEngine.h ('k') | sky/engine/core/dom/StyleSheetCollection.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "sky/engine/core/html/imports/HTMLImportsController.h" 42 #include "sky/engine/core/html/imports/HTMLImportsController.h"
43 #include "sky/engine/core/page/Page.h" 43 #include "sky/engine/core/page/Page.h"
44 44
45 namespace blink { 45 namespace blink {
46 46
47 StyleEngine::StyleEngine(Document& document) 47 StyleEngine::StyleEngine(Document& document)
48 : m_document(&document) 48 : m_document(&document)
49 , m_fontSelector(CSSFontSelector::create(&document)) 49 , m_fontSelector(CSSFontSelector::create(&document))
50 { 50 {
51 m_fontSelector->registerForInvalidationCallbacks(this); 51 m_fontSelector->registerForInvalidationCallbacks(this);
52 m_activeTreeScopes.add(&document);
52 } 53 }
53 54
54 StyleEngine::~StyleEngine() 55 StyleEngine::~StyleEngine()
55 { 56 {
56 m_fontSelector->clearDocument(); 57 m_fontSelector->clearDocument();
57 m_fontSelector->unregisterForInvalidationCallbacks(this); 58 m_fontSelector->unregisterForInvalidationCallbacks(this);
58 } 59 }
59 60
60 void StyleEngine::addStyleSheetCandidateNode(Node* node, bool createdByParser) 61 void StyleEngine::addTreeScope(TreeScope& scope)
61 { 62 {
62 if (!node->inDocument()) 63 m_activeTreeScopes.add(&scope);
63 return;
64
65 TreeScope& treeScope = isHTMLStyleElement(*node) ? node->treeScope() : *m_do cument;
66 ASSERT(isHTMLStyleElement(node) || treeScope == m_document);
67 StyleSheetCollection& collection = treeScope.styleSheets();
68 collection.addStyleSheetCandidateNode(node, createdByParser);
69
70 if (treeScope != m_document)
71 m_activeTreeScopes.add(&treeScope);
72 } 64 }
73 65
74 void StyleEngine::removeStyleSheetCandidateNode(Node* node, ContainerNode* scopi ngNode, TreeScope& treeScope) 66 void StyleEngine::removeTreeScope(TreeScope& scope)
75 { 67 {
76 ASSERT(isHTMLStyleElement(node) || treeScope == m_document); 68 m_activeTreeScopes.remove(&scope);
77
78 StyleSheetCollection& collection = treeScope.styleSheets();
79 collection.removeStyleSheetCandidateNode(node, scopingNode);
80
81 m_activeTreeScopes.remove(&treeScope);
82 } 69 }
83 70
84 void StyleEngine::updateActiveStyleSheets() 71 void StyleEngine::updateActiveStyleSheets()
85 { 72 {
86 ASSERT(!m_document->inStyleRecalc()); 73 ASSERT(!m_document->inStyleRecalc());
87 74
88 if (!m_document->isActive()) 75 if (!m_document->isActive())
89 return; 76 return;
90 77
91 // TODO(esprehn): Remove special case for document. 78 for (TreeScope* treeScope : m_activeTreeScopes)
92 m_document->styleSheets().updateActiveStyleSheets(this); 79 treeScope->styleSheets().updateActiveStyleSheets(this);
93
94 TreeScopeSet treeScopes = m_activeTreeScopes;
95 HashSet<TreeScope*> treeScopesRemoved;
96
97 for (TreeScopeSet::iterator it = treeScopes.begin(); it != treeScopes.end(); ++it) {
98 TreeScope* treeScope = *it;
99 ASSERT(treeScope != m_document);
100 StyleSheetCollection& collection = treeScope->styleSheets();
101 collection.updateActiveStyleSheets(this);
102 if (!collection.hasStyleSheetCandidateNodes())
103 treeScopesRemoved.add(treeScope);
104 }
105 m_activeTreeScopes.removeAll(treeScopesRemoved);
106 } 80 }
107 81
108 void StyleEngine::appendActiveAuthorStyleSheets() 82 void StyleEngine::appendActiveAuthorStyleSheets()
109 { 83 {
110 // TODO(esprehn): Remove special case for document.
111 m_resolver->appendAuthorStyleSheets(m_document->styleSheets().activeAuthorSt yleSheets());
112
113 for (TreeScope* treeScope : m_activeTreeScopes) 84 for (TreeScope* treeScope : m_activeTreeScopes)
114 m_resolver->appendAuthorStyleSheets(treeScope->styleSheets().activeAutho rStyleSheets()); 85 m_resolver->appendAuthorStyleSheets(treeScope->styleSheets().activeAutho rStyleSheets());
115 86
116 m_resolver->finishAppendAuthorStyleSheets(); 87 m_resolver->finishAppendAuthorStyleSheets();
117 } 88 }
118 89
119 void StyleEngine::createResolver() 90 void StyleEngine::createResolver()
120 { 91 {
121 // It is a programming error to attempt to resolve style on a Document 92 // It is a programming error to attempt to resolve style on a Document
122 // which is not in a frame. Code which hits this should have checked 93 // which is not in a frame. Code which hits this should have checked
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 } 175 }
205 176
206 void StyleEngine::fontsNeedUpdate(CSSFontSelector*) 177 void StyleEngine::fontsNeedUpdate(CSSFontSelector*)
207 { 178 {
208 if (m_resolver) 179 if (m_resolver)
209 m_resolver->invalidateMatchedPropertiesCache(); 180 m_resolver->invalidateMatchedPropertiesCache();
210 m_document->setNeedsStyleRecalc(SubtreeStyleChange); 181 m_document->setNeedsStyleRecalc(SubtreeStyleChange);
211 } 182 }
212 183
213 } 184 }
OLDNEW
« no previous file with comments | « sky/engine/core/dom/StyleEngine.h ('k') | sky/engine/core/dom/StyleSheetCollection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698