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

Side by Side Diff: sky/engine/core/html/HTMLStyleElement.cpp

Issue 813493003: Only the main document should have a StyleEngine. (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
« no previous file with comments | « sky/engine/core/dom/StyleSheetCollection.cpp ('k') | sky/engine/core/page/Page.cpp » ('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 * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2010 Apple Inc. All rights reserved.
6 * (C) 2007 Rob Buis (buis@kde.org) 6 * (C) 2007 Rob Buis (buis@kde.org)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 HTMLStyleElement::~HTMLStyleElement() 44 HTMLStyleElement::~HTMLStyleElement()
45 { 45 {
46 if (m_sheet) 46 if (m_sheet)
47 m_sheet->clearOwnerNode(); 47 m_sheet->clearOwnerNode();
48 48
49 // TODO(esprehn): How can we still be in the document when our destructor 49 // TODO(esprehn): How can we still be in the document when our destructor
50 // is running? 50 // is running?
51 if (inDocument()) { 51 if (inDocument()) {
52 ContainerNode* scopingNode = this->scopingNode(); 52 ContainerNode* scopingNode = this->scopingNode();
53 TreeScope& scope = scopingNode ? scopingNode->treeScope() : treeScope(); 53 TreeScope& scope = scopingNode ? scopingNode->treeScope() : treeScope();
54 document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNod e, scope); 54 if (StyleEngine* styleEngine = document().styleEngine())
55 styleEngine->removeStyleSheetCandidateNode(this, scopingNode, scope) ;
55 } 56 }
56 57
57 if (m_sheet) 58 if (m_sheet)
58 clearSheet(); 59 clearSheet();
59 } 60 }
60 61
61 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document) 62 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document)
62 { 63 {
63 return adoptRef(new HTMLStyleElement(document)); 64 return adoptRef(new HTMLStyleElement(document));
64 } 65 }
65 66
66 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value) 67 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value)
67 { 68 {
68 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() && m_sheet) { 69 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() && m_sheet) {
69 m_sheet->setMediaQueries(MediaQuerySet::create(value)); 70 m_sheet->setMediaQueries(MediaQuerySet::create(value));
70 document().modifiedStyleSheet(m_sheet.get()); 71 document().modifiedStyleSheet(m_sheet.get());
71 } else { 72 } else {
72 HTMLElement::parseAttribute(name, value); 73 HTMLElement::parseAttribute(name, value);
73 } 74 }
74 } 75 }
75 76
76 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint) 77 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint)
77 { 78 {
78 HTMLElement::insertedInto(insertionPoint); 79 HTMLElement::insertedInto(insertionPoint);
79 document().styleEngine()->addStyleSheetCandidateNode(this, false); 80 if (inActiveDocument()) {
80 process(); 81 document().styleEngine()->addStyleSheetCandidateNode(this, false);
82 process();
83 }
81 } 84 }
82 85
83 void HTMLStyleElement::removedFrom(ContainerNode* insertionPoint) 86 void HTMLStyleElement::removedFrom(ContainerNode* insertionPoint)
84 { 87 {
85 HTMLElement::removedFrom(insertionPoint); 88 HTMLElement::removedFrom(insertionPoint);
86 89
87 if (!insertionPoint->inDocument()) 90 if (!insertionPoint->inActiveDocument())
88 return; 91 return;
89 92
90 ShadowRoot* scopingNode = containingShadowRoot(); 93 ShadowRoot* scopingNode = containingShadowRoot();
91 if (!scopingNode) 94 if (!scopingNode)
92 scopingNode = insertionPoint->containingShadowRoot(); 95 scopingNode = insertionPoint->containingShadowRoot();
93 96
94 TreeScope* containingScope = containingShadowRoot(); 97 TreeScope* containingScope = containingShadowRoot();
95 TreeScope& scope = containingScope ? *containingScope : insertionPoint->tree Scope(); 98 TreeScope& scope = containingScope ? *containingScope : insertionPoint->tree Scope();
96 99
97 document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNode, s cope); 100 document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNode, s cope);
(...skipping 12 matching lines...) Expand all
110 process(); 113 process();
111 } 114 }
112 115
113 const AtomicString& HTMLStyleElement::media() const 116 const AtomicString& HTMLStyleElement::media() const
114 { 117 {
115 return getAttribute(HTMLNames::mediaAttr); 118 return getAttribute(HTMLNames::mediaAttr);
116 } 119 }
117 120
118 ContainerNode* HTMLStyleElement::scopingNode() 121 ContainerNode* HTMLStyleElement::scopingNode()
119 { 122 {
120 if (!inDocument()) 123 if (!inActiveDocument())
121 return 0; 124 return 0;
122 125
123 if (isInShadowTree()) 126 if (isInShadowTree())
124 return containingShadowRoot(); 127 return containingShadowRoot();
125 128
126 return &document(); 129 return &document();
127 } 130 }
128 131
129 void HTMLStyleElement::clearSheet() 132 void HTMLStyleElement::clearSheet()
130 { 133 {
131 ASSERT(m_sheet); 134 ASSERT(m_sheet);
132 m_sheet.release()->clearOwnerNode(); 135 m_sheet.release()->clearOwnerNode();
133 } 136 }
134 137
135 void HTMLStyleElement::process() 138 void HTMLStyleElement::process()
136 { 139 {
137 if (!inDocument()) 140 if (!inActiveDocument())
138 return; 141 return;
139 142
140 TRACE_EVENT0("blink", "StyleElement::process"); 143 TRACE_EVENT0("blink", "StyleElement::process");
141 144
142 if (m_sheet) 145 if (m_sheet)
143 clearSheet(); 146 clearSheet();
144 147
145 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media()); 148 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media());
146 149
147 MediaQueryEvaluator screenEval("screen", true); 150 MediaQueryEvaluator screenEval("screen", true);
148 if (screenEval.eval(mediaQueries.get())) { 151 if (screenEval.eval(mediaQueries.get())) {
149 const String& text = textFromChildren(); 152 const String& text = textFromChildren();
150 m_sheet = document().styleEngine()->createSheet(this, text); 153 m_sheet = document().styleEngine()->createSheet(this, text);
151 m_sheet->setMediaQueries(mediaQueries.release()); 154 m_sheet->setMediaQueries(mediaQueries.release());
152 } 155 }
153 156
154 document().styleResolverChanged(); 157 document().styleResolverChanged();
155 } 158 }
156 159
157 } 160 }
OLDNEW
« no previous file with comments | « sky/engine/core/dom/StyleSheetCollection.cpp ('k') | sky/engine/core/page/Page.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698