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

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

Issue 791633010: StyleSheetContents doesn't need a set of clients. (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 17 matching lines...) Expand all
28 #include "sky/engine/core/css/parser/BisonCSSParser.h" 28 #include "sky/engine/core/css/parser/BisonCSSParser.h"
29 #include "sky/engine/core/dom/Document.h" 29 #include "sky/engine/core/dom/Document.h"
30 #include "sky/engine/core/dom/Node.h" 30 #include "sky/engine/core/dom/Node.h"
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(Document* document, const CSSParserContex t& context)
39 : m_parserContext(context) 39 : m_parserContext(context)
40 , m_document(document)
40 { 41 {
41 } 42 }
42 43
43 StyleSheetContents::~StyleSheetContents() 44 StyleSheetContents::~StyleSheetContents()
44 { 45 {
45 // TODO(esprehn): Why is this here? The rules will be cleared immediately 46 // TODO(esprehn): Why is this here? The rules will be cleared immediately
46 // after this destructor runs anyway. 47 // after this destructor runs anyway.
47 m_childRules.clear(); 48 m_childRules.clear();
49
50 if (m_document && m_document->isActive())
51 m_document->styleEngine()->removeSheet(this);
48 } 52 }
49 53
50 void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule) 54 void StyleSheetContents::parserAppendRule(PassRefPtr<StyleRuleBase> rule)
51 { 55 {
52 m_childRules.append(rule); 56 m_childRules.append(rule);
53 } 57 }
54 58
55 bool StyleSheetContents::parseString(const String& sheetText) 59 bool StyleSheetContents::parseString(const String& sheetText)
56 { 60 {
57 CSSParserContext context(parserContext(), UseCounter::getFrom(this)); 61 CSSParserContext context(parserContext(), UseCounter::getFrom(this));
58 BisonCSSParser p(context); 62 BisonCSSParser p(context);
59 p.parseSheet(this, sheetText); 63 p.parseSheet(this, sheetText);
60 return true; 64 return true;
61 } 65 }
62 66
63 void StyleSheetContents::registerClient(CSSStyleSheet* sheet)
64 {
65 ASSERT(!m_clients.contains(sheet));
66
67 // InspectorCSSAgent::buildObjectForRule creates CSSStyleSheet without any o wner node.
68 if (!sheet->ownerDocument())
69 return;
70 m_clients.add(sheet);
71 }
72
73 void StyleSheetContents::unregisterClient(CSSStyleSheet* sheet)
74 {
75 m_clients.remove(sheet);
76
77 if (!sheet->ownerDocument() || !m_clients.isEmpty())
78 return;
79 sheet->ownerDocument()->styleEngine()->removeSheet(this);
80 }
81
82 void StyleSheetContents::shrinkToFit() 67 void StyleSheetContents::shrinkToFit()
83 { 68 {
84 m_childRules.shrinkToFit(); 69 m_childRules.shrinkToFit();
85 } 70 }
86 71
87 RuleSet& StyleSheetContents::ensureRuleSet(AddRuleFlags addRuleFlags) 72 RuleSet& StyleSheetContents::ensureRuleSet(AddRuleFlags addRuleFlags)
88 { 73 {
89 if (!m_ruleSet) { 74 if (!m_ruleSet) {
90 m_ruleSet = RuleSet::create(); 75 m_ruleSet = RuleSet::create();
91 m_ruleSet->addRulesFromSheet(this, addRuleFlags); 76 m_ruleSet->addRulesFromSheet(this, addRuleFlags);
92 } 77 }
93 return *m_ruleSet.get(); 78 return *m_ruleSet.get();
94 } 79 }
95 80
96 void StyleSheetContents::clearRuleSet()
97 {
98 // Don't want to clear the StyleResolver if the RuleSet hasn't been created
99 // since we only clear the StyleResolver so that it's members are properly
100 // updated in ScopedStyleResolver::addRulesFromSheet.
101 if (!m_ruleSet)
102 return;
103
104 // Clearing the ruleSet means we need to recreate the styleResolver data str uctures.
105 // See the StyleResolver calls in ScopedStyleResolver::addRulesFromSheet.
106 for (RawPtr<CSSStyleSheet> client : m_clients) {
107 if (Document* document = client->ownerDocument())
108 document->styleEngine()->clearResolver();
109 }
110 m_ruleSet.clear();
111 } 81 }
112
113 }
OLDNEW
« no previous file with comments | « sky/engine/core/css/StyleSheetContents.h ('k') | sky/engine/core/css/resolver/StyleResolver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698