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

Side by Side Diff: sky/engine/core/dom/StyleElement.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/dom/StyleElement.h ('k') | sky/engine/core/html/HTMLStyleElement.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2006, 2007 Rob Buis
3 * Copyright (C) 2008 Apple, Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include "sky/engine/config.h"
22 #include "sky/engine/core/dom/StyleElement.h"
23
24 #include "sky/engine/bindings/core/v8/ScriptController.h"
25 #include "sky/engine/core/css/MediaList.h"
26 #include "sky/engine/core/css/MediaQueryEvaluator.h"
27 #include "sky/engine/core/css/StyleSheetContents.h"
28 #include "sky/engine/core/dom/Document.h"
29 #include "sky/engine/core/dom/Element.h"
30 #include "sky/engine/core/dom/StyleEngine.h"
31 #include "sky/engine/core/frame/LocalFrame.h"
32 #include "sky/engine/core/html/HTMLStyleElement.h"
33 #include "sky/engine/core/html/parser/HTMLDocumentParser.h"
34 #include "sky/engine/platform/TraceEvent.h"
35 #include "sky/engine/wtf/text/StringBuilder.h"
36
37 namespace blink {
38
39 static bool isCSS(Element* element, const AtomicString& type)
40 {
41 return type.isEmpty() || (element->isHTMLElement() ? equalIgnoringCase(type, "text/css") : (type == "text/css"));
42 }
43
44 StyleElement::StyleElement(Document* document, bool createdByParser)
45 : m_createdByParser(createdByParser)
46 , m_loading(false)
47 , m_registeredAsCandidate(false)
48 , m_startPosition(TextPosition::belowRangePosition())
49 {
50 if (createdByParser)
51 m_startPosition = document->parserPosition();
52 }
53
54 StyleElement::~StyleElement()
55 {
56 #if !ENABLE(OILPAN)
57 if (m_sheet)
58 clearSheet();
59 #endif
60 }
61
62 void StyleElement::processStyleSheet(Document& document, Element* element)
63 {
64 TRACE_EVENT0("blink", "StyleElement::processStyleSheet");
65 ASSERT(element);
66 ASSERT(element->inDocument());
67
68 m_registeredAsCandidate = true;
69 document.styleEngine()->addStyleSheetCandidateNode(element, m_createdByParse r);
70 if (m_createdByParser)
71 return;
72
73 process(element);
74 }
75
76 void StyleElement::removedFromDocument(Document& document, Element* element)
77 {
78 removedFromDocument(document, element, 0, document);
79 }
80
81 void StyleElement::removedFromDocument(Document& document, Element* element, Con tainerNode* scopingNode, TreeScope& treeScope)
82 {
83 ASSERT(element);
84
85 if (m_registeredAsCandidate) {
86 document.styleEngine()->removeStyleSheetCandidateNode(element, scopingNo de, treeScope);
87 m_registeredAsCandidate = false;
88 }
89
90 RefPtr<CSSStyleSheet> removedSheet = m_sheet.get();
91
92 if (m_sheet)
93 clearSheet(element);
94 if (removedSheet)
95 document.removedStyleSheet(removedSheet.get());
96 }
97
98 void StyleElement::clearDocumentData(Document& document, Element* element)
99 {
100 if (m_sheet)
101 m_sheet->clearOwnerNode();
102
103 if (element->inDocument()) {
104 ContainerNode* scopingNode = isHTMLStyleElement(element) ? toHTMLStyleEl ement(element)->scopingNode() : 0;
105 TreeScope& treeScope = scopingNode ? scopingNode->treeScope() : element- >treeScope();
106 document.styleEngine()->removeStyleSheetCandidateNode(element, scopingNo de, treeScope);
107 }
108 }
109
110 void StyleElement::childrenChanged(Element* element)
111 {
112 ASSERT(element);
113 if (m_createdByParser)
114 return;
115
116 process(element);
117 }
118
119 void StyleElement::finishParsingChildren(Element* element)
120 {
121 ASSERT(element);
122 process(element);
123 m_createdByParser = false;
124 }
125
126 void StyleElement::process(Element* element)
127 {
128 if (!element || !element->inDocument())
129 return;
130 createSheet(element, element->textFromChildren());
131 }
132
133 void StyleElement::clearSheet(Element* ownerElement)
134 {
135 ASSERT(m_sheet);
136 m_sheet.release()->clearOwnerNode();
137 }
138
139 void StyleElement::createSheet(Element* e, const String& text)
140 {
141 ASSERT(e);
142 ASSERT(e->inDocument());
143 Document& document = e->document();
144 if (m_sheet)
145 clearSheet(e);
146
147 // If type is empty or CSS, this is a CSS style sheet.
148 const AtomicString& type = this->type();
149 if (isCSS(e, type)) {
150 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media());
151
152 MediaQueryEvaluator screenEval("screen", true);
153 MediaQueryEvaluator printEval("print", true);
154 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g et())) {
155 m_loading = true;
156 TextPosition startPosition = m_startPosition == TextPosition::belowR angePosition() ? TextPosition::minimumPosition() : m_startPosition;
157 m_sheet = document.styleEngine()->createSheet(e, text, startPosition , m_createdByParser);
158 m_sheet->setMediaQueries(mediaQueries.release());
159 m_loading = false;
160 }
161 }
162
163
164 document.styleResolverChanged();
165 }
166
167 }
OLDNEW
« no previous file with comments | « sky/engine/core/dom/StyleElement.h ('k') | sky/engine/core/html/HTMLStyleElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698