initial import
[vuplus_webkit] / Source / WebCore / html / HTMLLinkElement.h
1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved.
5  * Copyright (C) 2011 Google Inc. All rights reserved.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23
24 #ifndef HTMLLinkElement_h
25 #define HTMLLinkElement_h
26
27 #include "CSSStyleSheet.h"
28 #include "CachedResourceClient.h"
29 #include "CachedResourceHandle.h"
30 #include "DOMSettableTokenList.h"
31 #include "HTMLElement.h"
32 #include "IconURL.h"
33 #include "LinkLoader.h"
34 #include "LinkLoaderClient.h"
35 #include "LinkRelAttribute.h"
36 #include "Timer.h"
37
38 namespace WebCore {
39
40 class CachedCSSStyleSheet;
41 class CachedResource;
42 class KURL;
43
44 class HTMLLinkElement : public HTMLElement, public CachedResourceClient, public LinkLoaderClient {
45 public:
46     static PassRefPtr<HTMLLinkElement> create(const QualifiedName&, Document*, bool createdByParser);
47     virtual ~HTMLLinkElement();
48
49     KURL href() const;
50     String rel() const;
51
52     virtual String target() const;
53
54     String type() const;
55
56     StyleSheet* sheet() const;
57
58     // FIXME: This should be renamed isStyleSheetLoading as this is only used for stylesheets.
59     bool isLoading() const;
60
61     bool isDisabled() const { return m_disabledState == Disabled; }
62     bool isEnabledViaScript() const { return m_disabledState == EnabledViaScript; }
63     void setSizes(const String&);
64     DOMSettableTokenList* sizes() const;
65
66 private:
67     virtual void parseMappedAttribute(Attribute*);
68
69     virtual bool shouldLoadLink();
70     void process();
71     static void processCallback(Node*);
72
73     virtual void insertedIntoDocument();
74     virtual void removedFromDocument();
75
76     // from CachedResourceClient
77     virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet);
78     virtual bool sheetLoaded();
79     virtual void startLoadingDynamicSheet();
80
81     virtual void linkLoaded();
82     virtual void linkLoadingErrored();
83
84     bool isAlternate() const { return m_disabledState == Unset && m_relAttribute.m_isAlternate; }
85     
86     void setDisabledState(bool);
87
88     virtual bool isURLAttribute(Attribute*) const;
89
90 private:
91     virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
92
93     virtual void finishParsingChildren();
94     
95     enum PendingSheetType { None, NonBlocking, Blocking };
96     void addPendingSheet(PendingSheetType);
97     void removePendingSheet();
98
99 private:
100     HTMLLinkElement(const QualifiedName&, Document*, bool createdByParser);
101
102     LinkLoader m_linkLoader;
103     CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet;
104     RefPtr<CSSStyleSheet> m_sheet;
105     enum DisabledState {
106         Unset,
107         EnabledViaScript,
108         Disabled
109     };
110
111     KURL m_url;
112     String m_type;
113     String m_media;
114     RefPtr<DOMSettableTokenList> m_sizes;
115     DisabledState m_disabledState;
116     LinkRelAttribute m_relAttribute;
117     bool m_loading;
118     bool m_createdByParser;
119     bool m_isInShadowTree;
120     
121     PendingSheetType m_pendingSheetType;
122 };
123
124 } //namespace
125
126 #endif