1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 *           (C) 1999 Antti Koivisto (koivisto@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 "HTMLElement.h"
27#include "StyleElement.h"
28
29namespace WebCore {
30
31class HTMLStyleElement;
32class StyleSheet;
33
34template<typename T> class EventSender;
35typedef EventSender<HTMLStyleElement> StyleEventSender;
36
37class HTMLStyleElement FINAL : public HTMLElement, private StyleElement {
38public:
39    static PassRefPtr<HTMLStyleElement> create(const QualifiedName&, Document*, bool createdByParser);
40    virtual ~HTMLStyleElement();
41
42    void setType(const AtomicString&);
43
44    bool scoped() const;
45    void setScoped(bool);
46    Element* scopingElement() const;
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    using StyleElement::sheet;
57
58    bool disabled() const;
59    void setDisabled(bool);
60
61    void dispatchPendingEvent(StyleEventSender*);
62    static void dispatchPendingLoadEvents();
63
64private:
65    HTMLStyleElement(const QualifiedName&, Document*, bool createdByParser);
66
67    // overload from HTMLElement
68    virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
69    virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
70    virtual void removedFrom(ContainerNode*) OVERRIDE;
71    virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
72
73    virtual void finishParsingChildren();
74
75    virtual bool isLoading() const { return StyleElement::isLoading(); }
76    virtual bool sheetLoaded() { return StyleElement::sheetLoaded(document()); }
77    virtual void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred);
78    virtual void startLoadingDynamicSheet() { StyleElement::startLoadingDynamicSheet(document()); }
79
80    virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
81
82    virtual const AtomicString& media() const;
83    virtual const AtomicString& type() const;
84
85    void scopedAttributeChanged(bool);
86    void registerWithScopingNode(bool);
87    void unregisterWithScopingNode(ContainerNode*);
88
89    bool m_firedLoad;
90    bool m_loadedSheet;
91
92    enum ScopedStyleRegistrationState {
93        NotRegistered,
94        RegisteredAsScoped,
95        RegisteredInShadowRoot
96    };
97    ScopedStyleRegistrationState m_scopedStyleRegistrationState;
98};
99
100} //namespace
101
102#endif
103