1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * Copyright (C) 2003, 2010 Apple Inc. ALl rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef HTMLStyleElement_h 24 #define HTMLStyleElement_h 25 26 #include "core/dom/StyleElement.h" 27 #include "core/html/HTMLElement.h" 28 29 namespace WebCore { 30 31 class HTMLStyleElement; 32 class StyleSheet; 33 34 template<typename T> class EventSender; 35 typedef EventSender<HTMLStyleElement> StyleEventSender; 36 37 class HTMLStyleElement FINAL : public HTMLElement, private StyleElement { 38 public: 39 static PassRefPtr<HTMLStyleElement> create(Document&, bool createdByParser); 40 virtual ~HTMLStyleElement(); 41 42 void setType(const AtomicString&); 43 44 bool scoped() const; 45 void setScoped(bool); 46 ContainerNode* scopingNode(); 47 bool isRegisteredAsScoped() const 48 { 49 // Note: We cannot rely on the 'scoped' attribute still being present when this method is invoked. 50 // Therefore we cannot rely on scoped()! 51 if (m_scopedStyleRegistrationState == NotRegistered) 52 return false; 53 return true; 54 } 55 56 bool isRegisteredInShadowRoot() const 57 { 58 return m_scopedStyleRegistrationState == RegisteredInShadowRoot; 59 } 60 61 using StyleElement::sheet; 62 63 bool disabled() const; 64 void setDisabled(bool); 65 66 void dispatchPendingEvent(StyleEventSender*); 67 static void dispatchPendingLoadEvents(); 68 69 private: 70 HTMLStyleElement(Document&, bool createdByParser); 71 72 // overload from HTMLElement 73 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 74 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; 75 virtual void didNotifySubtreeInsertionsToDocument() OVERRIDE; 76 virtual void removedFrom(ContainerNode*) OVERRIDE; 77 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 78 79 virtual void finishParsingChildren(); 80 81 virtual bool isLoading() const { return StyleElement::isLoading(); } 82 virtual bool sheetLoaded() { return StyleElement::sheetLoaded(document()); } 83 virtual void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred); 84 virtual void startLoadingDynamicSheet() { StyleElement::startLoadingDynamicSheet(document()); } 85 86 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; 87 88 virtual const AtomicString& media() const; 89 virtual const AtomicString& type() const; 90 91 void scopedAttributeChanged(bool); 92 void registerWithScopingNode(bool); 93 void unregisterWithScopingNode(ContainerNode*); 94 95 bool m_firedLoad; 96 bool m_loadedSheet; 97 98 enum ScopedStyleRegistrationState { 99 NotRegistered, 100 RegisteredAsScoped, 101 RegisteredInShadowRoot 102 }; 103 ScopedStyleRegistrationState m_scopedStyleRegistrationState; 104 }; 105 106 inline bool isHTMLStyleElement(Node* node) 107 { 108 ASSERT(node); 109 return node->hasTagName(HTMLNames::styleTag); 110 } 111 112 DEFINE_NODE_TYPE_CASTS(HTMLStyleElement, hasTagName(HTMLNames::styleTag)); 113 114 } //namespace 115 116 #endif 117