| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | |
| 5 * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. | |
| 6 * (C) 2007 Rob Buis (buis@kde.org) | |
| 7 * | |
| 8 * This library is free software; you can redistribute it and/or | |
| 9 * modify it under the terms of the GNU Library General Public | |
| 10 * License as published by the Free Software Foundation; either | |
| 11 * version 2 of the License, or (at your option) any later version. | |
| 12 * | |
| 13 * This library is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 16 * Library General Public License for more details. | |
| 17 * | |
| 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 | |
| 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
| 21 * Boston, MA 02110-1301, USA. | |
| 22 */ | |
| 23 | |
| 24 #include "sky/engine/core/html/HTMLStyleElement.h" | |
| 25 | |
| 26 #include "gen/sky/core/HTMLNames.h" | |
| 27 #include "sky/engine/core/css/MediaList.h" | |
| 28 #include "sky/engine/core/css/MediaQueryEvaluator.h" | |
| 29 #include "sky/engine/core/dom/Document.h" | |
| 30 #include "sky/engine/core/dom/Element.h" | |
| 31 #include "sky/engine/core/dom/StyleEngine.h" | |
| 32 #include "sky/engine/core/dom/Text.h" | |
| 33 #include "sky/engine/core/dom/shadow/ShadowRoot.h" | |
| 34 #include "sky/engine/core/frame/LocalFrame.h" | |
| 35 #include "sky/engine/platform/TraceEvent.h" | |
| 36 | |
| 37 namespace blink { | |
| 38 | |
| 39 inline HTMLStyleElement::HTMLStyleElement(Document& document) | |
| 40 : HTMLElement(HTMLNames::styleTag, document) | |
| 41 { | |
| 42 } | |
| 43 | |
| 44 HTMLStyleElement::~HTMLStyleElement() | |
| 45 { | |
| 46 if (m_sheet) | |
| 47 m_sheet->clearOwnerNode(); | |
| 48 if (m_sheet) | |
| 49 clearSheet(); | |
| 50 } | |
| 51 | |
| 52 PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(Document& document) | |
| 53 { | |
| 54 return adoptRef(new HTMLStyleElement(document)); | |
| 55 } | |
| 56 | |
| 57 void HTMLStyleElement::parseAttribute(const QualifiedName& name, const AtomicStr
ing& value) | |
| 58 { | |
| 59 if (name == HTMLNames::mediaAttr && inDocument() && document().isActive() &&
m_sheet) { | |
| 60 m_sheet->setMediaQueries(MediaQuerySet::create(value)); | |
| 61 document().styleResolverChanged(); | |
| 62 } else { | |
| 63 HTMLElement::parseAttribute(name, value); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 void HTMLStyleElement::insertedInto(ContainerNode* insertionPoint) | |
| 68 { | |
| 69 HTMLElement::insertedInto(insertionPoint); | |
| 70 if (!inActiveDocument()) | |
| 71 return; | |
| 72 treeScope().scopedStyleResolver().addStyleSheetCandidateNode(*this); | |
| 73 process(); | |
| 74 } | |
| 75 | |
| 76 void HTMLStyleElement::removedFrom(ContainerNode* insertionPoint) | |
| 77 { | |
| 78 HTMLElement::removedFrom(insertionPoint); | |
| 79 | |
| 80 if (!insertionPoint->inActiveDocument()) | |
| 81 return; | |
| 82 | |
| 83 TreeScope* containingScope = containingShadowRoot(); | |
| 84 TreeScope& scope = containingScope ? *containingScope : insertionPoint->tree
Scope(); | |
| 85 | |
| 86 scope.scopedStyleResolver().removeStyleSheetCandidateNode(*this); | |
| 87 | |
| 88 RefPtr<CSSStyleSheet> removedSheet = m_sheet.get(); | |
| 89 | |
| 90 if (m_sheet) | |
| 91 clearSheet(); | |
| 92 if (removedSheet) | |
| 93 document().styleResolverChanged(); | |
| 94 } | |
| 95 | |
| 96 void HTMLStyleElement::childrenChanged(const ChildrenChange& change) | |
| 97 { | |
| 98 HTMLElement::childrenChanged(change); | |
| 99 process(); | |
| 100 } | |
| 101 | |
| 102 const AtomicString& HTMLStyleElement::media() const | |
| 103 { | |
| 104 return getAttribute(HTMLNames::mediaAttr); | |
| 105 } | |
| 106 | |
| 107 void HTMLStyleElement::clearSheet() | |
| 108 { | |
| 109 ASSERT(m_sheet); | |
| 110 m_sheet.release()->clearOwnerNode(); | |
| 111 } | |
| 112 | |
| 113 void HTMLStyleElement::process() | |
| 114 { | |
| 115 if (!inActiveDocument()) | |
| 116 return; | |
| 117 | |
| 118 TRACE_EVENT0("blink", "StyleElement::process"); | |
| 119 | |
| 120 if (m_sheet) | |
| 121 clearSheet(); | |
| 122 | |
| 123 RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::create(media()); | |
| 124 | |
| 125 MediaQueryEvaluator screenEval("screen", true); | |
| 126 if (screenEval.eval(mediaQueries.get())) { | |
| 127 if (hasOneTextChild()) | |
| 128 toText(firstChild())->atomize(); | |
| 129 m_sheet = document().styleEngine()->createSheet(this, textContent()); | |
| 130 m_sheet->setMediaQueries(mediaQueries.release()); | |
| 131 } | |
| 132 | |
| 133 document().styleResolverChanged(); | |
| 134 } | |
| 135 | |
| 136 } | |
| OLD | NEW |