| 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 inline HTMLStyleElement::HTMLStyleElement(Document& document) | 39 inline HTMLStyleElement::HTMLStyleElement(Document& document) |
| 40 : HTMLElement(HTMLNames::styleTag, document) | 40 : HTMLElement(HTMLNames::styleTag, document) |
| 41 { | 41 { |
| 42 } | 42 } |
| 43 | 43 |
| 44 HTMLStyleElement::~HTMLStyleElement() | 44 HTMLStyleElement::~HTMLStyleElement() |
| 45 { | 45 { |
| 46 clearDocumentData(); | 46 if (m_sheet) |
| 47 m_sheet->clearOwnerNode(); |
| 48 |
| 49 // TODO(esprehn): How can we still be in the document when our destructor |
| 50 // is running? |
| 51 if (inDocument()) { |
| 52 ContainerNode* scopingNode = this->scopingNode(); |
| 53 TreeScope& scope = scopingNode ? scopingNode->treeScope() : treeScope(); |
| 54 document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNod
e, scope); |
| 55 } |
| 56 |
| 47 if (m_sheet) | 57 if (m_sheet) |
| 48 clearSheet(); | 58 clearSheet(); |
| 49 } | 59 } |
| 50 | 60 |
| 51 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document) | 61 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document) |
| 52 { | 62 { |
| 53 return adoptRef(new HTMLStyleElement(document)); | 63 return adoptRef(new HTMLStyleElement(document)); |
| 54 } | 64 } |
| 55 | 65 |
| 56 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) | 66 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) |
| 57 { | 67 { |
| 58 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() &&
m_sheet) { | 68 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() &&
m_sheet) { |
| 59 m_sheet->setMediaQueries(MediaQuerySet::create(value)); | 69 m_sheet->setMediaQueries(MediaQuerySet::create(value)); |
| 60 document().modifiedStyleSheet(m_sheet.get()); | 70 document().modifiedStyleSheet(m_sheet.get()); |
| 61 } else { | 71 } else { |
| 62 HTMLElement::parseAttribute(name, value); | 72 HTMLElement::parseAttribute(name, value); |
| 63 } | 73 } |
| 64 } | 74 } |
| 65 | 75 |
| 66 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint) | 76 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint) |
| 67 { | 77 { |
| 68 HTMLElement::insertedInto(insertionPoint); | 78 HTMLElement::insertedInto(insertionPoint); |
| 69 | 79 document().styleEngine()->addStyleSheetCandidateNode(this, false); |
| 70 if (!inDocument()) | 80 process(); |
| 71 return; | |
| 72 | |
| 73 processStyleSheet(); | |
| 74 } | 81 } |
| 75 | 82 |
| 76 void HTMLStyleElement::removedFrom(ContainerNode* insertionPoint) | 83 void HTMLStyleElement::removedFrom(ContainerNode* insertionPoint) |
| 77 { | 84 { |
| 78 HTMLElement::removedFrom(insertionPoint); | 85 HTMLElement::removedFrom(insertionPoint); |
| 79 | 86 |
| 80 if (!insertionPoint->inDocument()) | 87 if (!insertionPoint->inDocument()) |
| 81 return; | 88 return; |
| 82 | 89 |
| 83 ShadowRoot* scopingNode = containingShadowRoot(); | 90 ShadowRoot* scopingNode = containingShadowRoot(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 112 { | 119 { |
| 113 if (!inDocument()) | 120 if (!inDocument()) |
| 114 return 0; | 121 return 0; |
| 115 | 122 |
| 116 if (isInShadowTree()) | 123 if (isInShadowTree()) |
| 117 return containingShadowRoot(); | 124 return containingShadowRoot(); |
| 118 | 125 |
| 119 return &document(); | 126 return &document(); |
| 120 } | 127 } |
| 121 | 128 |
| 122 void HTMLStyleElement::process() | |
| 123 { | |
| 124 if (!inDocument()) | |
| 125 return; | |
| 126 createSheet(); | |
| 127 } | |
| 128 | |
| 129 void HTMLStyleElement::clearSheet() | 129 void HTMLStyleElement::clearSheet() |
| 130 { | 130 { |
| 131 ASSERT(m_sheet); | 131 ASSERT(m_sheet); |
| 132 m_sheet.release()->clearOwnerNode(); | 132 m_sheet.release()->clearOwnerNode(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void HTMLStyleElement::createSheet() | 135 void HTMLStyleElement::process() |
| 136 { | 136 { |
| 137 ASSERT(inDocument()); | 137 if (!inDocument()) |
| 138 return; |
| 139 |
| 140 TRACE_EVENT0("blink", "StyleElement::process"); |
| 138 | 141 |
| 139 if (m_sheet) | 142 if (m_sheet) |
| 140 clearSheet(); | 143 clearSheet(); |
| 141 | 144 |
| 142 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media()); | 145 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media()); |
| 143 | 146 |
| 144 MediaQueryEvaluator screenEval("screen", true); | 147 MediaQueryEvaluator screenEval("screen", true); |
| 145 MediaQueryEvaluator printEval("print", true); | 148 if (screenEval.eval(mediaQueries.get())) { |
| 146 if (screenEval.eval(mediaQueries.get()) || printEval.eval(mediaQueries.get()
)) { | |
| 147 const String& text = textFromChildren(); | 149 const String& text = textFromChildren(); |
| 148 m_sheet = document().styleEngine()->createSheet(this, text); | 150 m_sheet = document().styleEngine()->createSheet(this, text); |
| 149 m_sheet->setMediaQueries(mediaQueries.release()); | 151 m_sheet->setMediaQueries(mediaQueries.release()); |
| 150 } | 152 } |
| 151 | 153 |
| 152 document().styleResolverChanged(); | 154 document().styleResolverChanged(); |
| 153 } | 155 } |
| 154 | 156 |
| 155 void HTMLStyleElement::clearDocumentData() | |
| 156 { | |
| 157 if (m_sheet) | |
| 158 m_sheet->clearOwnerNode(); | |
| 159 | |
| 160 if (inDocument()) { | |
| 161 ContainerNode* scopingNode = this->scopingNode(); | |
| 162 TreeScope& scope = scopingNode ? scopingNode->treeScope() : treeScope(); | |
| 163 document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNod
e, scope); | |
| 164 } | |
| 165 } | 157 } |
| 166 | |
| 167 void HTMLStyleElement::processStyleSheet() | |
| 168 { | |
| 169 TRACE_EVENT0("blink", "StyleElement::processStyleSheet"); | |
| 170 | |
| 171 ASSERT(inDocument()); | |
| 172 | |
| 173 document().styleEngine()->addStyleSheetCandidateNode(this, false); | |
| 174 process(); | |
| 175 } | |
| 176 | |
| 177 } | |
| OLD | NEW |