| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 #include "sky/engine/core/css/MediaQueryEvaluator.h" | 29 #include "sky/engine/core/css/MediaQueryEvaluator.h" |
| 30 #include "sky/engine/core/dom/Document.h" | 30 #include "sky/engine/core/dom/Document.h" |
| 31 #include "sky/engine/core/dom/Element.h" | 31 #include "sky/engine/core/dom/Element.h" |
| 32 #include "sky/engine/core/dom/StyleEngine.h" | 32 #include "sky/engine/core/dom/StyleEngine.h" |
| 33 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 33 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 34 #include "sky/engine/core/frame/LocalFrame.h" | 34 #include "sky/engine/core/frame/LocalFrame.h" |
| 35 #include "sky/engine/platform/TraceEvent.h" | 35 #include "sky/engine/platform/TraceEvent.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 inline HTMLStyleElement::HTMLStyleElement(Document& document, bool createdByPars
er) | 39 inline HTMLStyleElement::HTMLStyleElement(Document& document) |
| 40 : HTMLElement(HTMLNames::styleTag, document) | 40 : HTMLElement(HTMLNames::styleTag, document) |
| 41 , m_createdByParser(createdByParser) | |
| 42 , m_loading(false) | 41 , m_loading(false) |
| 43 , m_registeredAsCandidate(false) | 42 , m_registeredAsCandidate(false) |
| 44 , m_startPosition(TextPosition::belowRangePosition()) | |
| 45 { | 43 { |
| 46 if (createdByParser) | |
| 47 m_startPosition = document.parserPosition(); | |
| 48 } | 44 } |
| 49 | 45 |
| 50 HTMLStyleElement::~HTMLStyleElement() | 46 HTMLStyleElement::~HTMLStyleElement() |
| 51 { | 47 { |
| 52 clearDocumentData(); | 48 clearDocumentData(); |
| 53 if (m_sheet) | 49 if (m_sheet) |
| 54 clearSheet(); | 50 clearSheet(); |
| 55 } | 51 } |
| 56 | 52 |
| 57 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document, bool c
reatedByParser) | 53 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document) |
| 58 { | 54 { |
| 59 return adoptRef(new HTMLStyleElement(document, createdByParser)); | 55 return adoptRef(new HTMLStyleElement(document)); |
| 60 } | 56 } |
| 61 | 57 |
| 62 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) | 58 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) |
| 63 { | 59 { |
| 64 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() &&
m_sheet) { | 60 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() &&
m_sheet) { |
| 65 m_sheet->setMediaQueries(MediaQuerySet::create(value)); | 61 m_sheet->setMediaQueries(MediaQuerySet::create(value)); |
| 66 document().modifiedStyleSheet(m_sheet.get()); | 62 document().modifiedStyleSheet(m_sheet.get()); |
| 67 } else { | 63 } else { |
| 68 HTMLElement::parseAttribute(name, value); | 64 HTMLElement::parseAttribute(name, value); |
| 69 } | 65 } |
| 70 } | 66 } |
| 71 | 67 |
| 72 void HTMLStyleElement::finishParsingChildren() | |
| 73 { | |
| 74 process(); | |
| 75 m_createdByParser = false; | |
| 76 } | |
| 77 | |
| 78 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint) | 68 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint) |
| 79 { | 69 { |
| 80 HTMLElement::insertedInto(insertionPoint); | 70 HTMLElement::insertedInto(insertionPoint); |
| 81 | 71 |
| 82 if (!inDocument()) | 72 if (!inDocument()) |
| 83 return; | 73 return; |
| 84 | 74 |
| 85 processStyleSheet(); | 75 processStyleSheet(); |
| 86 | 76 |
| 87 if (ShadowRoot* scope = containingShadowRoot()) | 77 if (ShadowRoot* scope = containingShadowRoot()) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 114 | 104 |
| 115 if (m_sheet) | 105 if (m_sheet) |
| 116 clearSheet(); | 106 clearSheet(); |
| 117 if (removedSheet) | 107 if (removedSheet) |
| 118 document().removedStyleSheet(removedSheet.get()); | 108 document().removedStyleSheet(removedSheet.get()); |
| 119 } | 109 } |
| 120 | 110 |
| 121 void HTMLStyleElement::childrenChanged(const ChildrenChange& change) | 111 void HTMLStyleElement::childrenChanged(const ChildrenChange& change) |
| 122 { | 112 { |
| 123 HTMLElement::childrenChanged(change); | 113 HTMLElement::childrenChanged(change); |
| 124 | |
| 125 if (m_createdByParser) | |
| 126 return; | |
| 127 process(); | 114 process(); |
| 128 } | 115 } |
| 129 | 116 |
| 130 const AtomicString& HTMLStyleElement::media() const | 117 const AtomicString& HTMLStyleElement::media() const |
| 131 { | 118 { |
| 132 return getAttribute(HTMLNames::mediaAttr); | 119 return getAttribute(HTMLNames::mediaAttr); |
| 133 } | 120 } |
| 134 | 121 |
| 135 const AtomicString& HTMLStyleElement::type() const | 122 const AtomicString& HTMLStyleElement::type() const |
| 136 { | 123 { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 157 |
| 171 const AtomicString& type = this->type(); | 158 const AtomicString& type = this->type(); |
| 172 if (type.isEmpty() || type == "text/css") { | 159 if (type.isEmpty() || type == "text/css") { |
| 173 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media()); | 160 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media()); |
| 174 | 161 |
| 175 MediaQueryEvaluator screenEval("screen", true); | 162 MediaQueryEvaluator screenEval("screen", true); |
| 176 MediaQueryEvaluator printEval("print", true); | 163 MediaQueryEvaluator printEval("print", true); |
| 177 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g
et())) { | 164 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.g
et())) { |
| 178 m_loading = true; | 165 m_loading = true; |
| 179 const String& text = textFromChildren(); | 166 const String& text = textFromChildren(); |
| 180 TextPosition startPosition = m_startPosition == TextPosition::belowR
angePosition() ? TextPosition::minimumPosition() : m_startPosition; | 167 m_sheet = document().styleEngine()->createSheet(this, text); |
| 181 m_sheet = document().styleEngine()->createSheet(this, text, startPos
ition, m_createdByParser); | |
| 182 m_sheet->setMediaQueries(mediaQueries.release()); | 168 m_sheet->setMediaQueries(mediaQueries.release()); |
| 183 m_loading = false; | 169 m_loading = false; |
| 184 } | 170 } |
| 185 } | 171 } |
| 186 | 172 |
| 187 document().styleResolverChanged(); | 173 document().styleResolverChanged(); |
| 188 } | 174 } |
| 189 | 175 |
| 190 void HTMLStyleElement::clearDocumentData() | 176 void HTMLStyleElement::clearDocumentData() |
| 191 { | 177 { |
| 192 if (m_sheet) | 178 if (m_sheet) |
| 193 m_sheet->clearOwnerNode(); | 179 m_sheet->clearOwnerNode(); |
| 194 | 180 |
| 195 if (inDocument()) { | 181 if (inDocument()) { |
| 196 ContainerNode* scopingNode = this->scopingNode(); | 182 ContainerNode* scopingNode = this->scopingNode(); |
| 197 TreeScope& scope = scopingNode ? scopingNode->treeScope() : treeScope(); | 183 TreeScope& scope = scopingNode ? scopingNode->treeScope() : treeScope(); |
| 198 document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNod
e, scope); | 184 document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNod
e, scope); |
| 199 } | 185 } |
| 200 } | 186 } |
| 201 | 187 |
| 202 void HTMLStyleElement::processStyleSheet() | 188 void HTMLStyleElement::processStyleSheet() |
| 203 { | 189 { |
| 204 TRACE_EVENT0("blink", "StyleElement::processStyleSheet"); | 190 TRACE_EVENT0("blink", "StyleElement::processStyleSheet"); |
| 205 | 191 |
| 206 ASSERT(inDocument()); | 192 ASSERT(inDocument()); |
| 207 | 193 |
| 208 m_registeredAsCandidate = true; | 194 m_registeredAsCandidate = true; |
| 209 document().styleEngine()->addStyleSheetCandidateNode(this, m_createdByParser
); | 195 document().styleEngine()->addStyleSheetCandidateNode(this, false); |
| 210 if (m_createdByParser) | |
| 211 return; | |
| 212 | |
| 213 process(); | 196 process(); |
| 214 } | 197 } |
| 215 | 198 |
| 216 } | 199 } |
| OLD | NEW |