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

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

Issue 780083003: Merge StyleElement into HTMLStyleElement. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: trim includes. 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/html/HTMLStyleElement.h ('k') | no next file » | 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
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 */ 22 */
23 23
24 #include "sky/engine/config.h" 24 #include "sky/engine/config.h"
25 #include "sky/engine/core/html/HTMLStyleElement.h" 25 #include "sky/engine/core/html/HTMLStyleElement.h"
26 26
27 #include "gen/sky/core/HTMLNames.h" 27 #include "gen/sky/core/HTMLNames.h"
28 #include "sky/engine/core/css/MediaList.h" 28 #include "sky/engine/core/css/MediaList.h"
29 #include "sky/engine/core/css/MediaQueryEvaluator.h"
29 #include "sky/engine/core/dom/Document.h" 30 #include "sky/engine/core/dom/Document.h"
31 #include "sky/engine/core/dom/Element.h"
32 #include "sky/engine/core/dom/StyleEngine.h"
30 #include "sky/engine/core/dom/shadow/ShadowRoot.h" 33 #include "sky/engine/core/dom/shadow/ShadowRoot.h"
31 #include "sky/engine/core/events/Event.h" 34 #include "sky/engine/core/frame/LocalFrame.h"
32 #include "sky/engine/core/events/EventSender.h" 35 #include "sky/engine/platform/TraceEvent.h"
33 36
34 namespace blink { 37 namespace blink {
35 38
36 inline HTMLStyleElement::HTMLStyleElement(Document& document, bool createdByPars er) 39 inline HTMLStyleElement::HTMLStyleElement(Document& document, bool createdByPars er)
37 : HTMLElement(HTMLNames::styleTag, document) 40 : HTMLElement(HTMLNames::styleTag, document)
38 , StyleElement(&document, createdByParser) 41 , m_createdByParser(createdByParser)
42 , m_loading(false)
43 , m_registeredAsCandidate(false)
44 , m_startPosition(TextPosition::belowRangePosition())
39 { 45 {
46 if (createdByParser)
47 m_startPosition = document.parserPosition();
40 } 48 }
41 49
42 HTMLStyleElement::~HTMLStyleElement() 50 HTMLStyleElement::~HTMLStyleElement()
43 { 51 {
44 #if !ENABLE(OILPAN) 52 clearDocumentData();
45 StyleElement::clearDocumentData(document(), this); 53 if (m_sheet)
46 #endif 54 clearSheet();
47 } 55 }
48 56
49 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document, bool c reatedByParser) 57 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document, bool c reatedByParser)
50 { 58 {
51 return adoptRef(new HTMLStyleElement(document, createdByParser)); 59 return adoptRef(new HTMLStyleElement(document, createdByParser));
52 } 60 }
53 61
54 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value) 62 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr ing& value)
55 { 63 {
56 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() && m_sheet) { 64 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() && m_sheet) {
57 m_sheet->setMediaQueries(MediaQuerySet::create(value)); 65 m_sheet->setMediaQueries(MediaQuerySet::create(value));
58 document().modifiedStyleSheet(m_sheet.get()); 66 document().modifiedStyleSheet(m_sheet.get());
59 } else { 67 } else {
60 HTMLElement::parseAttribute(name, value); 68 HTMLElement::parseAttribute(name, value);
61 } 69 }
62 } 70 }
63 71
64 void HTMLStyleElement::finishParsingChildren() 72 void HTMLStyleElement::finishParsingChildren()
65 { 73 {
66 StyleElement::finishParsingChildren(this); 74 process();
67 HTMLElement::finishParsingChildren(); 75 m_createdByParser = false;
68 } 76 }
69 77
70 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint) 78 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint)
71 { 79 {
72 HTMLElement::insertedInto(insertionPoint); 80 HTMLElement::insertedInto(insertionPoint);
73 81
74 if (!inDocument()) 82 if (!inDocument())
75 return; 83 return;
76 84
77 StyleElement::processStyleSheet(document(), this); 85 processStyleSheet();
78 86
79 if (ShadowRoot* scope = containingShadowRoot()) 87 if (ShadowRoot* scope = containingShadowRoot())
80 scope->registerScopedHTMLStyleChild(); 88 scope->registerScopedHTMLStyleChild();
81 } 89 }
82 90
83 void HTMLStyleElement::removedFrom(ContainerNode* insertionPoint) 91 void HTMLStyleElement::removedFrom(ContainerNode* insertionPoint)
84 { 92 {
85 HTMLElement::removedFrom(insertionPoint); 93 HTMLElement::removedFrom(insertionPoint);
86 94
87 if (!insertionPoint->inDocument()) 95 if (!insertionPoint->inDocument())
88 return; 96 return;
89 97
90 ShadowRoot* scopingNode = containingShadowRoot(); 98 ShadowRoot* scopingNode = containingShadowRoot();
91 if (!scopingNode) 99 if (!scopingNode)
92 scopingNode = insertionPoint->containingShadowRoot(); 100 scopingNode = insertionPoint->containingShadowRoot();
93 101
94 if (scopingNode) 102 if (scopingNode)
95 scopingNode->unregisterScopedHTMLStyleChild(); 103 scopingNode->unregisterScopedHTMLStyleChild();
96 104
97 TreeScope* containingScope = containingShadowRoot(); 105 TreeScope* containingScope = containingShadowRoot();
98 StyleElement::removedFromDocument(document(), this, scopingNode, containingS cope ? *containingScope : insertionPoint->treeScope()); 106 TreeScope& scope = containingScope ? *containingScope : insertionPoint->tree Scope();
107
108 if (m_registeredAsCandidate) {
109 document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNod e, scope);
110 m_registeredAsCandidate = false;
111 }
112
113 RefPtr<CSSStyleSheet> removedSheet = m_sheet.get();
114
115 if (m_sheet)
116 clearSheet();
117 if (removedSheet)
118 document().removedStyleSheet(removedSheet.get());
99 } 119 }
100 120
101 void HTMLStyleElement::childrenChanged(const ChildrenChange& change) 121 void HTMLStyleElement::childrenChanged(const ChildrenChange& change)
102 { 122 {
103 HTMLElement::childrenChanged(change); 123 HTMLElement::childrenChanged(change);
104 StyleElement::childrenChanged(this); 124
125 if (m_createdByParser)
126 return;
127 process();
105 } 128 }
106 129
107 const AtomicString& HTMLStyleElement::media() const 130 const AtomicString& HTMLStyleElement::media() const
108 { 131 {
109 return getAttribute(HTMLNames::mediaAttr); 132 return getAttribute(HTMLNames::mediaAttr);
110 } 133 }
111 134
112 const AtomicString& HTMLStyleElement::type() const 135 const AtomicString& HTMLStyleElement::type() const
113 { 136 {
114 return getAttribute(HTMLNames::typeAttr); 137 return getAttribute(HTMLNames::typeAttr);
115 } 138 }
116 139
117 ContainerNode* HTMLStyleElement::scopingNode() 140 ContainerNode* HTMLStyleElement::scopingNode()
118 { 141 {
119 if (!inDocument()) 142 if (!inDocument())
120 return 0; 143 return 0;
121 144
122 if (isInShadowTree()) 145 if (isInShadowTree())
123 return containingShadowRoot(); 146 return containingShadowRoot();
124 147
125 return &document(); 148 return &document();
126 } 149 }
127 150
151 void HTMLStyleElement::process()
152 {
153 if (!inDocument())
154 return;
155 createSheet();
128 } 156 }
157
158 void HTMLStyleElement::clearSheet()
159 {
160 ASSERT(m_sheet);
161 m_sheet.release()->clearOwnerNode();
162 }
163
164 void HTMLStyleElement::createSheet()
165 {
166 ASSERT(inDocument());
167
168 if (m_sheet)
169 clearSheet();
170
171 const AtomicString& type = this->type();
172 if (type.isEmpty() || type == "text/css") {
173 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media());
174
175 MediaQueryEvaluator screenEval("screen", true);
176 MediaQueryEvaluator printEval("print", true);
177 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g et())) {
178 m_loading = true;
179 const String& text = textFromChildren();
180 TextPosition startPosition = m_startPosition == TextPosition::belowR angePosition() ? TextPosition::minimumPosition() : m_startPosition;
181 m_sheet = document().styleEngine()->createSheet(this, text, startPos ition, m_createdByParser);
182 m_sheet->setMediaQueries(mediaQueries.release());
183 m_loading = false;
184 }
185 }
186
187 document().styleResolverChanged();
188 }
189
190 void HTMLStyleElement::clearDocumentData()
191 {
192 if (m_sheet)
193 m_sheet->clearOwnerNode();
194
195 if (inDocument()) {
196 ContainerNode* scopingNode = this->scopingNode();
197 TreeScope& scope = scopingNode ? scopingNode->treeScope() : treeScope();
198 document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNod e, scope);
199 }
200 }
201
202 void HTMLStyleElement::processStyleSheet()
203 {
204 TRACE_EVENT0("blink", "StyleElement::processStyleSheet");
205
206 ASSERT(inDocument());
207
208 m_registeredAsCandidate = true;
209 document().styleEngine()->addStyleSheetCandidateNode(this, m_createdByParser );
210 if (m_createdByParser)
211 return;
212
213 process();
214 }
215
216 }
OLDNEW
« no previous file with comments | « sky/engine/core/html/HTMLStyleElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698