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 * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved. | 4 * Copyright (C) 2003, 2008, 2010 Apple Inc. All rights reserved. |
5 * Copyright (C) 2011 Google Inc. All rights reserved. | 5 * Copyright (C) 2011 Google Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 11 matching lines...) Expand all Loading... |
22 */ | 22 */ |
23 | 23 |
24 #ifndef HTMLLinkElement_h | 24 #ifndef HTMLLinkElement_h |
25 #define HTMLLinkElement_h | 25 #define HTMLLinkElement_h |
26 | 26 |
27 #include "core/css/CSSStyleSheet.h" | 27 #include "core/css/CSSStyleSheet.h" |
28 #include "core/dom/IconURL.h" | 28 #include "core/dom/IconURL.h" |
29 #include "core/html/DOMSettableTokenList.h" | 29 #include "core/html/DOMSettableTokenList.h" |
30 #include "core/html/HTMLElement.h" | 30 #include "core/html/HTMLElement.h" |
31 #include "core/html/LinkRelAttribute.h" | 31 #include "core/html/LinkRelAttribute.h" |
| 32 #include "core/html/LinkResource.h" |
32 #include "core/loader/LinkLoader.h" | 33 #include "core/loader/LinkLoader.h" |
33 #include "core/loader/LinkLoaderClient.h" | 34 #include "core/loader/LinkLoaderClient.h" |
34 #include "core/loader/cache/CachedResourceHandle.h" | 35 #include "core/loader/cache/CachedResourceHandle.h" |
35 #include "core/loader/cache/CachedStyleSheetClient.h" | 36 #include "core/loader/cache/CachedStyleSheetClient.h" |
36 #include "core/platform/Timer.h" | 37 #include "core/platform/Timer.h" |
37 | 38 |
38 namespace WebCore { | 39 namespace WebCore { |
39 | 40 |
| 41 class DocumentFragment; |
40 class HTMLLinkElement; | 42 class HTMLLinkElement; |
41 class KURL; | 43 class KURL; |
| 44 class LinkImport; |
42 | 45 |
43 template<typename T> class EventSender; | 46 template<typename T> class EventSender; |
44 typedef EventSender<HTMLLinkElement> LinkEventSender; | 47 typedef EventSender<HTMLLinkElement> LinkEventSender; |
45 | 48 |
46 class LinkStyle FINAL : public CachedStyleSheetClient { | 49 // |
| 50 // LinkStyle handles dynaically change-able link resources, which is |
| 51 // typically @rel="stylesheet". |
| 52 // |
| 53 // It could be @rel="shortcut icon" or soething else though. Each of |
| 54 // types might better be handled by a separate class, but dynamically |
| 55 // changing @rel makes it harder to move such a design so we are |
| 56 // sticking current way so far. |
| 57 // |
| 58 class LinkStyle FINAL : public LinkResource, CachedStyleSheetClient { |
| 59 WTF_MAKE_FAST_ALLOCATED; |
47 public: | 60 public: |
| 61 static PassRefPtr<LinkStyle> create(HTMLLinkElement* owner); |
| 62 |
48 explicit LinkStyle(HTMLLinkElement* owner); | 63 explicit LinkStyle(HTMLLinkElement* owner); |
49 ~LinkStyle(); | 64 virtual ~LinkStyle(); |
| 65 |
| 66 virtual Type type() const OVERRIDE { return Style; } |
| 67 virtual void process() OVERRIDE; |
| 68 virtual void ownerRemoved() OVERRIDE; |
50 | 69 |
51 void startLoadingDynamicSheet(); | 70 void startLoadingDynamicSheet(); |
52 void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred); | 71 void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred); |
53 bool sheetLoaded(); | 72 bool sheetLoaded(); |
54 | 73 |
55 void setDisabledState(bool); | 74 void setDisabledState(bool); |
56 void process(); | |
57 void ownerRemoved(); | |
58 void setSheetTitle(const String&); | 75 void setSheetTitle(const String&); |
59 | 76 |
60 bool styleSheetIsLoading() const; | 77 bool styleSheetIsLoading() const; |
61 bool hasSheet() const { return m_sheet; } | 78 bool hasSheet() const { return m_sheet; } |
62 bool hasLoadedSheet() const { return m_loadedSheet; } | 79 bool hasLoadedSheet() const { return m_loadedSheet; } |
63 bool isDisabled() const { return m_disabledState == Disabled; } | 80 bool isDisabled() const { return m_disabledState == Disabled; } |
64 bool isEnabledViaScript() const { return m_disabledState == EnabledViaScript
; } | 81 bool isEnabledViaScript() const { return m_disabledState == EnabledViaScript
; } |
65 bool isUnset() const { return m_disabledState == Unset; } | 82 bool isUnset() const { return m_disabledState == Unset; } |
66 | 83 |
67 CSSStyleSheet* sheet() const { return m_sheet.get(); } | 84 CSSStyleSheet* sheet() const { return m_sheet.get(); } |
(...skipping 24 matching lines...) Expand all Loading... |
92 void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSh
eetNotifyImmediately); | 109 void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSh
eetNotifyImmediately); |
93 Document* document(); | 110 Document* document(); |
94 | 111 |
95 CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet; | 112 CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet; |
96 RefPtr<CSSStyleSheet> m_sheet; | 113 RefPtr<CSSStyleSheet> m_sheet; |
97 DisabledState m_disabledState; | 114 DisabledState m_disabledState; |
98 PendingSheetType m_pendingSheetType; | 115 PendingSheetType m_pendingSheetType; |
99 bool m_loading; | 116 bool m_loading; |
100 bool m_firedLoad; | 117 bool m_firedLoad; |
101 bool m_loadedSheet; | 118 bool m_loadedSheet; |
102 HTMLLinkElement* m_owner; | |
103 }; | 119 }; |
104 | 120 |
105 | 121 |
106 class HTMLLinkElement FINAL : public HTMLElement, public LinkLoaderClient { | 122 class HTMLLinkElement FINAL : public HTMLElement, public LinkLoaderClient { |
107 public: | 123 public: |
108 static PassRefPtr<HTMLLinkElement> create(const QualifiedName&, Document*, b
ool createdByParser); | 124 static PassRefPtr<HTMLLinkElement> create(const QualifiedName&, Document*, b
ool createdByParser); |
109 virtual ~HTMLLinkElement(); | 125 virtual ~HTMLLinkElement(); |
110 | 126 |
111 KURL href() const; | 127 KURL href() const; |
112 String rel() const; | 128 String rel() const; |
113 String media() const { return m_media; } | 129 String media() const { return m_media; } |
114 String typeValue() const { return m_type; } | 130 String typeValue() const { return m_type; } |
115 const LinkRelAttribute& relAttribute() const { return m_relAttribute; } | 131 const LinkRelAttribute& relAttribute() const { return m_relAttribute; } |
116 | 132 |
117 virtual String target() const; | 133 virtual String target() const; |
118 | 134 |
119 String type() const; | 135 String type() const; |
120 | 136 |
121 IconType iconType() const; | 137 IconType iconType() const; |
122 | 138 |
123 // the icon size string as parsed from the HTML attribute | 139 // the icon size string as parsed from the HTML attribute |
124 String iconSizes() const; | 140 String iconSizes() const; |
125 | 141 |
126 CSSStyleSheet* sheet() const { return m_link ? m_link->sheet() : 0; } | 142 CSSStyleSheet* sheet() const { return linkStyle() ? linkStyle()->sheet() : 0
; } |
| 143 DocumentFragment* import() const; |
127 | 144 |
128 bool styleSheetIsLoading() const; | 145 bool styleSheetIsLoading() const; |
129 | 146 |
130 bool isDisabled() const { return m_link->isDisabled(); } | 147 bool isDisabled() const { return linkStyle() && linkStyle()->isDisabled(); } |
131 bool isEnabledViaScript() const { return m_link->isEnabledViaScript(); } | 148 bool isEnabledViaScript() const { return linkStyle() && linkStyle()->isEnabl
edViaScript(); } |
132 void setSizes(const String&); | 149 void setSizes(const String&); |
133 DOMSettableTokenList* sizes() const; | 150 DOMSettableTokenList* sizes() const; |
134 | 151 |
135 void dispatchPendingEvent(LinkEventSender*); | 152 void dispatchPendingEvent(LinkEventSender*); |
136 static void dispatchPendingLoadEvents(); | 153 static void dispatchPendingLoadEvents(); |
137 | 154 |
138 // From LinkLoaderClient | 155 // From LinkLoaderClient |
139 virtual bool shouldLoadLink() OVERRIDE; | 156 virtual bool shouldLoadLink() OVERRIDE; |
140 | 157 |
141 // For LinkStyle | 158 // For LinkStyle |
142 bool loadLink(const String& type, const KURL& url) { return m_linkLoader.loa
dLink(m_relAttribute, type, url, document()); } | 159 bool loadLink(const String& type, const KURL& url) { return m_linkLoader.loa
dLink(m_relAttribute, type, url, document()); } |
143 bool isAlternate() const { return m_link->isUnset() && m_relAttribute.isAlte
rnate(); } | 160 bool isAlternate() const { return linkStyle()->isUnset() && m_relAttribute.i
sAlternate(); } |
144 bool shouldProcessStyle() { return linkStyleToProcess(); } | 161 bool shouldProcessStyle() { return linkResourceToProcess() && linkStyle(); } |
145 | 162 |
146 private: | 163 private: |
147 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERR
IDE; | 164 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERR
IDE; |
148 | 165 |
149 LinkStyle* linkStyle() const { return m_link.get(); } | 166 LinkStyle* linkStyle() const; |
150 LinkStyle* linkStyleToProcess(); | 167 LinkImport* linkImport() const; |
| 168 LinkResource* linkResourceToProcess(); |
151 | 169 |
152 void process(); | 170 void process(); |
153 static void processCallback(Node*); | 171 static void processCallback(Node*); |
154 | 172 |
155 // From Node and subclassses | 173 // From Node and subclassses |
156 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; | 174 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; |
157 virtual void removedFrom(ContainerNode*) OVERRIDE; | 175 virtual void removedFrom(ContainerNode*) OVERRIDE; |
158 virtual bool isURLAttribute(const Attribute&) const OVERRIDE; | 176 virtual bool isURLAttribute(const Attribute&) const OVERRIDE; |
159 virtual bool sheetLoaded() OVERRIDE; | 177 virtual bool sheetLoaded() OVERRIDE; |
160 virtual void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred)
OVERRIDE; | 178 virtual void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred)
OVERRIDE; |
161 virtual void startLoadingDynamicSheet() OVERRIDE; | 179 virtual void startLoadingDynamicSheet() OVERRIDE; |
162 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const OVERRIDE; | 180 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const OVERRIDE; |
163 virtual void finishParsingChildren(); | 181 virtual void finishParsingChildren(); |
164 | 182 |
165 // From LinkLoaderClient | 183 // From LinkLoaderClient |
166 virtual void linkLoaded() OVERRIDE; | 184 virtual void linkLoaded() OVERRIDE; |
167 virtual void linkLoadingErrored() OVERRIDE; | 185 virtual void linkLoadingErrored() OVERRIDE; |
168 virtual void didStartLinkPrerender() OVERRIDE; | 186 virtual void didStartLinkPrerender() OVERRIDE; |
169 virtual void didStopLinkPrerender() OVERRIDE; | 187 virtual void didStopLinkPrerender() OVERRIDE; |
170 virtual void didSendLoadForLinkPrerender() OVERRIDE; | 188 virtual void didSendLoadForLinkPrerender() OVERRIDE; |
171 virtual void didSendDOMContentLoadedForLinkPrerender() OVERRIDE; | 189 virtual void didSendDOMContentLoadedForLinkPrerender() OVERRIDE; |
172 | 190 |
173 private: | 191 private: |
174 HTMLLinkElement(const QualifiedName&, Document*, bool createdByParser); | 192 HTMLLinkElement(const QualifiedName&, Document*, bool createdByParser); |
175 | 193 |
176 OwnPtr<LinkStyle> m_link; | 194 RefPtr<LinkResource> m_link; |
177 LinkLoader m_linkLoader; | 195 LinkLoader m_linkLoader; |
178 | 196 |
179 String m_type; | 197 String m_type; |
180 String m_media; | 198 String m_media; |
181 RefPtr<DOMSettableTokenList> m_sizes; | 199 RefPtr<DOMSettableTokenList> m_sizes; |
182 LinkRelAttribute m_relAttribute; | 200 LinkRelAttribute m_relAttribute; |
183 | 201 |
184 bool m_createdByParser; | 202 bool m_createdByParser; |
185 bool m_isInShadowTree; | 203 bool m_isInShadowTree; |
186 int m_beforeLoadRecurseCount; | 204 int m_beforeLoadRecurseCount; |
187 }; | 205 }; |
188 | 206 |
189 } //namespace | 207 } //namespace |
190 | 208 |
191 #endif | 209 #endif |
OLD | NEW |