| 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 12 matching lines...) Expand all Loading... |
| 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/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/StyleSheetCollection.h" |
| 33 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | 34 #include "sky/engine/core/dom/shadow/ShadowRoot.h" |
| 34 #include "sky/engine/core/frame/LocalFrame.h" | 35 #include "sky/engine/core/frame/LocalFrame.h" |
| 35 #include "sky/engine/platform/TraceEvent.h" | 36 #include "sky/engine/platform/TraceEvent.h" |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 inline HTMLStyleElement::HTMLStyleElement(Document& document) | 40 inline HTMLStyleElement::HTMLStyleElement(Document& document) |
| 40 : HTMLElement(HTMLNames::styleTag, document) | 41 : HTMLElement(HTMLNames::styleTag, document) |
| 41 { | 42 { |
| 42 } | 43 } |
| 43 | 44 |
| 44 HTMLStyleElement::~HTMLStyleElement() | 45 HTMLStyleElement::~HTMLStyleElement() |
| 45 { | 46 { |
| 46 if (m_sheet) | 47 if (m_sheet) |
| 47 m_sheet->clearOwnerNode(); | 48 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 if (StyleEngine* styleEngine = document().styleEngine()) | |
| 55 styleEngine->removeStyleSheetCandidateNode(this, scopingNode, scope)
; | |
| 56 } | |
| 57 | |
| 58 if (m_sheet) | 49 if (m_sheet) |
| 59 clearSheet(); | 50 clearSheet(); |
| 60 } | 51 } |
| 61 | 52 |
| 62 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document) | 53 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document) |
| 63 { | 54 { |
| 64 return adoptRef(new HTMLStyleElement(document)); | 55 return adoptRef(new HTMLStyleElement(document)); |
| 65 } | 56 } |
| 66 | 57 |
| 67 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) | 58 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) |
| 68 { | 59 { |
| 69 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() &&
m_sheet) { | 60 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() &&
m_sheet) { |
| 70 m_sheet->setMediaQueries(MediaQuerySet::create(value)); | 61 m_sheet->setMediaQueries(MediaQuerySet::create(value)); |
| 71 document().modifiedStyleSheet(m_sheet.get()); | 62 document().modifiedStyleSheet(m_sheet.get()); |
| 72 } else { | 63 } else { |
| 73 HTMLElement::parseAttribute(name, value); | 64 HTMLElement::parseAttribute(name, value); |
| 74 } | 65 } |
| 75 } | 66 } |
| 76 | 67 |
| 77 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint) | 68 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint) |
| 78 { | 69 { |
| 79 HTMLElement::insertedInto(insertionPoint); | 70 HTMLElement::insertedInto(insertionPoint); |
| 80 if (inActiveDocument()) { | 71 if (!inActiveDocument()) |
| 81 document().styleEngine()->addStyleSheetCandidateNode(this, false); | 72 return; |
| 82 process(); | 73 treeScope().styleSheets().addStyleSheetCandidateNode(*this); |
| 83 } | 74 process(); |
| 84 } | 75 } |
| 85 | 76 |
| 86 void HTMLStyleElement::removedFrom(ContainerNode* insertionPoint) | 77 void HTMLStyleElement::removedFrom(ContainerNode* insertionPoint) |
| 87 { | 78 { |
| 88 HTMLElement::removedFrom(insertionPoint); | 79 HTMLElement::removedFrom(insertionPoint); |
| 89 | 80 |
| 90 if (!insertionPoint->inActiveDocument()) | 81 if (!insertionPoint->inActiveDocument()) |
| 91 return; | 82 return; |
| 92 | 83 |
| 93 ShadowRoot* scopingNode = containingShadowRoot(); | |
| 94 if (!scopingNode) | |
| 95 scopingNode = insertionPoint->containingShadowRoot(); | |
| 96 | |
| 97 TreeScope* containingScope = containingShadowRoot(); | 84 TreeScope* containingScope = containingShadowRoot(); |
| 98 TreeScope& scope = containingScope ? *containingScope : insertionPoint->tree
Scope(); | 85 TreeScope& scope = containingScope ? *containingScope : insertionPoint->tree
Scope(); |
| 99 | 86 |
| 100 document().styleEngine()->removeStyleSheetCandidateNode(this, scopingNode, s
cope); | 87 scope.styleSheets().removeStyleSheetCandidateNode(*this); |
| 101 | 88 |
| 102 RefPtr<CSSStyleSheet> removedSheet = m_sheet.get(); | 89 RefPtr<CSSStyleSheet> removedSheet = m_sheet.get(); |
| 103 | 90 |
| 104 if (m_sheet) | 91 if (m_sheet) |
| 105 clearSheet(); | 92 clearSheet(); |
| 106 if (removedSheet) | 93 if (removedSheet) |
| 107 document().removedStyleSheet(removedSheet.get()); | 94 document().removedStyleSheet(removedSheet.get()); |
| 108 } | 95 } |
| 109 | 96 |
| 110 void HTMLStyleElement::childrenChanged(const ChildrenChange& change) | 97 void HTMLStyleElement::childrenChanged(const ChildrenChange& change) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if (screenEval.eval(mediaQueries.get())) { | 138 if (screenEval.eval(mediaQueries.get())) { |
| 152 const String& text = textFromChildren(); | 139 const String& text = textFromChildren(); |
| 153 m_sheet = document().styleEngine()->createSheet(this, text); | 140 m_sheet = document().styleEngine()->createSheet(this, text); |
| 154 m_sheet->setMediaQueries(mediaQueries.release()); | 141 m_sheet->setMediaQueries(mediaQueries.release()); |
| 155 } | 142 } |
| 156 | 143 |
| 157 document().styleResolverChanged(); | 144 document().styleResolverChanged(); |
| 158 } | 145 } |
| 159 | 146 |
| 160 } | 147 } |
| OLD | NEW |