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

Side by Side Diff: sky/engine/core/css/StyleSheetContents.cpp

Issue 799143002: Remove single client special cases for StyleSheetContents. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 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 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2006, 2007, 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 20 matching lines...) Expand all
31 #include "sky/engine/core/dom/StyleEngine.h" 31 #include "sky/engine/core/dom/StyleEngine.h"
32 #include "sky/engine/core/frame/UseCounter.h" 32 #include "sky/engine/core/frame/UseCounter.h"
33 #include "sky/engine/platform/TraceEvent.h" 33 #include "sky/engine/platform/TraceEvent.h"
34 #include "sky/engine/wtf/Deque.h" 34 #include "sky/engine/wtf/Deque.h"
35 35
36 namespace blink { 36 namespace blink {
37 37
38 StyleSheetContents::StyleSheetContents(const CSSParserContext& context) 38 StyleSheetContents::StyleSheetContents(const CSSParserContext& context)
39 : m_usesRemUnits(false) 39 : m_usesRemUnits(false)
40 , m_hasMediaQueries(false) 40 , m_hasMediaQueries(false)
41 , m_hasSingleOwnerDocument(true)
42 , m_parserContext(context) 41 , m_parserContext(context)
43 { 42 {
44 } 43 }
45 44
46 StyleSheetContents::~StyleSheetContents() 45 StyleSheetContents::~StyleSheetContents()
47 { 46 {
48 #if !ENABLE(OILPAN) 47 // TODO(esprehn): Why is this here? The rules will be cleared immediately
49 clearRules(); 48 // after this destructor runs anyway.
50 #endif 49 m_childRules.clear();
51 } 50 }
52 51
53 void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule) 52 void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule)
54 { 53 {
55 // Add warning message to inspector if dpi/dpcm values are used for screen m edia. 54 if (rule->isMediaRule())
56 if (rule->isMediaRule()) {
57 setHasMediaQueries(); 55 setHasMediaQueries();
58 reportMediaQueryWarningIfNeeded(singleOwnerDocument(), toStyleRuleMedia( rule.get())->mediaQueries());
59 }
60
61 m_childRules.append(rule); 56 m_childRules.append(rule);
62 } 57 }
63 58
64 void StyleSheetContents::setHasMediaQueries() 59 void StyleSheetContents::setHasMediaQueries()
65 { 60 {
66 m_hasMediaQueries = true; 61 m_hasMediaQueries = true;
67 } 62 }
68 63
69 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const 64 StyleRuleBase* StyleSheetContents::ruleAt(unsigned index) const
70 { 65 {
71 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); 66 ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount());
72 return m_childRules[index].get(); 67 return m_childRules[index].get();
73 } 68 }
74 69
75 unsigned StyleSheetContents::ruleCount() const 70 unsigned StyleSheetContents::ruleCount() const
76 { 71 {
77 return m_childRules.size(); 72 return m_childRules.size();
78 } 73 }
79 74
80 void StyleSheetContents::clearRules()
81 {
82 m_childRules.clear();
83 }
84
85 bool StyleSheetContents::parseString(const String& sheetText) 75 bool StyleSheetContents::parseString(const String& sheetText)
86 { 76 {
87 CSSParserContext context(parserContext(), UseCounter::getFrom(this)); 77 CSSParserContext context(parserContext(), UseCounter::getFrom(this));
88 BisonCSSParser p(context); 78 BisonCSSParser p(context);
89 p.parseSheet(this, sheetText); 79 p.parseSheet(this, sheetText);
90 return true; 80 return true;
91 } 81 }
92 82
93 bool StyleSheetContents::hasSingleOwnerNode() const
94 {
95 return hasOneClient();
96 }
97
98 Node* StyleSheetContents::singleOwnerNode() const
99 {
100 if (!hasOneClient())
101 return 0;
102 if (m_loadingClients.size())
103 return (*m_loadingClients.begin())->ownerNode();
104 return (*m_completedClients.begin())->ownerNode();
105 }
106
107 Document* StyleSheetContents::singleOwnerDocument() const
108 {
109 return clientSingleOwnerDocument();
110 }
111
112 Document* StyleSheetContents::clientSingleOwnerDocument() const
113 {
114 if (!m_hasSingleOwnerDocument || clientSize() <= 0)
115 return 0;
116
117 if (m_loadingClients.size())
118 return (*m_loadingClients.begin())->ownerDocument();
119 return (*m_completedClients.begin())->ownerDocument();
120 }
121
122 void StyleSheetContents::registerClient(CSSStyleSheet* sheet) 83 void StyleSheetContents::registerClient(CSSStyleSheet* sheet)
123 { 84 {
124 ASSERT(!m_loadingClients.contains(sheet) && !m_completedClients.contains(she et)); 85 ASSERT(!m_loadingClients.contains(sheet) && !m_completedClients.contains(she et));
125 86
126 // InspectorCSSAgent::buildObjectForRule creates CSSStyleSheet without any o wner node. 87 // InspectorCSSAgent::buildObjectForRule creates CSSStyleSheet without any o wner node.
127 if (!sheet->ownerDocument()) 88 if (!sheet->ownerDocument())
128 return; 89 return;
129
130 if (Document* document = clientSingleOwnerDocument()) {
131 if (sheet->ownerDocument() != document)
132 m_hasSingleOwnerDocument = false;
133 }
134 m_loadingClients.add(sheet); 90 m_loadingClients.add(sheet);
135 } 91 }
136 92
137 void StyleSheetContents::unregisterClient(CSSStyleSheet* sheet) 93 void StyleSheetContents::unregisterClient(CSSStyleSheet* sheet)
138 { 94 {
139 m_loadingClients.remove(sheet); 95 m_loadingClients.remove(sheet);
140 m_completedClients.remove(sheet); 96 m_completedClients.remove(sheet);
141 97
142 if (!sheet->ownerDocument() || !m_loadingClients.isEmpty() || !m_completedCl ients.isEmpty()) 98 if (!sheet->ownerDocument() || !m_loadingClients.isEmpty() || !m_completedCl ients.isEmpty())
143 return; 99 return;
144 100 sheet->ownerDocument()->styleEngine()->removeSheet(this);
145 if (m_hasSingleOwnerDocument)
146 removeSheetFromCache(sheet->ownerDocument());
147 m_hasSingleOwnerDocument = true;
148 }
149
150 void StyleSheetContents::removeSheetFromCache(Document* document)
151 {
152 ASSERT(document);
153 document->styleEngine()->removeSheet(this);
154 } 101 }
155 102
156 void StyleSheetContents::shrinkToFit() 103 void StyleSheetContents::shrinkToFit()
157 { 104 {
158 m_childRules.shrinkToFit(); 105 m_childRules.shrinkToFit();
159 } 106 }
160 107
161 RuleSet& StyleSheetContents::ensureRuleSet(const MediaQueryEvaluator& medium, Ad dRuleFlags addRuleFlags) 108 RuleSet& StyleSheetContents::ensureRuleSet(const MediaQueryEvaluator& medium, Ad dRuleFlags addRuleFlags)
162 { 109 {
163 if (!m_ruleSet) { 110 if (!m_ruleSet) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 } 145 }
199 } 146 }
200 147
201 void StyleSheetContents::notifyRemoveFontFaceRule(const StyleRuleFontFace* fontF aceRule) 148 void StyleSheetContents::notifyRemoveFontFaceRule(const StyleRuleFontFace* fontF aceRule)
202 { 149 {
203 removeFontFaceRules(m_loadingClients, fontFaceRule); 150 removeFontFaceRules(m_loadingClients, fontFaceRule);
204 removeFontFaceRules(m_completedClients, fontFaceRule); 151 removeFontFaceRules(m_completedClients, fontFaceRule);
205 } 152 }
206 153
207 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698