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 { |
47 public: | 59 public: |
| 60 static PassRefPtr<LinkStyle> create(HTMLLinkElement* owner); |
| 61 |
48 explicit LinkStyle(HTMLLinkElement* owner); | 62 explicit LinkStyle(HTMLLinkElement* owner); |
49 ~LinkStyle(); | 63 virtual ~LinkStyle(); |
| 64 |
| 65 virtual Type type() const OVERRIDE { return Style; } |
| 66 virtual void process() OVERRIDE; |
| 67 virtual void ownerRemoved() OVERRIDE; |
50 | 68 |
51 void startLoadingDynamicSheet(); | 69 void startLoadingDynamicSheet(); |
52 void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred); | 70 void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred); |
53 bool sheetLoaded(); | 71 bool sheetLoaded(); |
54 | 72 |
55 void setDisabledState(bool); | 73 void setDisabledState(bool); |
56 void process(); | |
57 void ownerRemoved(); | |
58 void setSheetTitle(const String&); | 74 void setSheetTitle(const String&); |
59 | 75 |
60 bool styleSheetIsLoading() const; | 76 bool styleSheetIsLoading() const; |
61 bool hasSheet() const { return m_sheet; } | 77 bool hasSheet() const { return m_sheet; } |
62 bool hasLoadedSheet() const { return m_loadedSheet; } | 78 bool hasLoadedSheet() const { return m_loadedSheet; } |
63 bool isDisabled() const { return m_disabledState == Disabled; } | 79 bool isDisabled() const { return m_disabledState == Disabled; } |
64 bool isEnabledViaScript() const { return m_disabledState == EnabledViaScript
; } | 80 bool isEnabledViaScript() const { return m_disabledState == EnabledViaScript
; } |
65 bool isUnset() const { return m_disabledState == Unset; } | 81 bool isUnset() const { return m_disabledState == Unset; } |
66 | 82 |
67 CSSStyleSheet* sheet() const { return m_sheet.get(); } | 83 CSSStyleSheet* sheet() const { return m_sheet.get(); } |
(...skipping 24 matching lines...) Expand all Loading... |
92 void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSh
eetNotifyImmediately); | 108 void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSh
eetNotifyImmediately); |
93 Document* document(); | 109 Document* document(); |
94 | 110 |
95 CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet; | 111 CachedResourceHandle<CachedCSSStyleSheet> m_cachedSheet; |
96 RefPtr<CSSStyleSheet> m_sheet; | 112 RefPtr<CSSStyleSheet> m_sheet; |
97 DisabledState m_disabledState; | 113 DisabledState m_disabledState; |
98 PendingSheetType m_pendingSheetType; | 114 PendingSheetType m_pendingSheetType; |
99 bool m_loading; | 115 bool m_loading; |
100 bool m_firedLoad; | 116 bool m_firedLoad; |
101 bool m_loadedSheet; | 117 bool m_loadedSheet; |
102 HTMLLinkElement* m_owner; | |
103 }; | 118 }; |
104 | 119 |
105 | 120 |
106 class HTMLLinkElement FINAL : public HTMLElement, public LinkLoaderClient { | 121 class HTMLLinkElement FINAL : public HTMLElement, public LinkLoaderClient { |
107 public: | 122 public: |
108 static PassRefPtr<HTMLLinkElement> create(const QualifiedName&, Document*, b
ool createdByParser); | 123 static PassRefPtr<HTMLLinkElement> create(const QualifiedName&, Document*, b
ool createdByParser); |
109 virtual ~HTMLLinkElement(); | 124 virtual ~HTMLLinkElement(); |
110 | 125 |
111 KURL href() const; | 126 KURL href() const; |
112 String rel() const; | 127 String rel() const; |
113 String media() const { return m_media; } | 128 String media() const { return m_media; } |
114 String typeValue() const { return m_type; } | 129 String typeValue() const { return m_type; } |
115 const LinkRelAttribute& relAttribute() const { return m_relAttribute; } | 130 const LinkRelAttribute& relAttribute() const { return m_relAttribute; } |
116 | 131 |
117 virtual String target() const; | 132 virtual String target() const; |
118 | 133 |
119 String type() const; | 134 String type() const; |
120 | 135 |
121 IconType iconType() const; | 136 IconType iconType() const; |
122 | 137 |
123 // the icon size string as parsed from the HTML attribute | 138 // the icon size string as parsed from the HTML attribute |
124 String iconSizes() const; | 139 String iconSizes() const; |
125 | 140 |
126 CSSStyleSheet* sheet() const { return m_link ? m_link->sheet() : 0; } | 141 CSSStyleSheet* sheet() const { return linkStyle() ? linkStyle()->sheet() : 0
; } |
| 142 DocumentFragment* import() const; |
127 | 143 |
128 bool styleSheetIsLoading() const; | 144 bool styleSheetIsLoading() const; |
129 | 145 |
130 bool isDisabled() const { return m_link->isDisabled(); } | 146 bool isDisabled() const { return linkStyle() && linkStyle()->isDisabled(); } |
131 bool isEnabledViaScript() const { return m_link->isEnabledViaScript(); } | 147 bool isEnabledViaScript() const { return linkStyle() && linkStyle()->isEnabl
edViaScript(); } |
132 void setSizes(const String&); | 148 void setSizes(const String&); |
133 DOMSettableTokenList* sizes() const; | 149 DOMSettableTokenList* sizes() const; |
134 | 150 |
135 void dispatchPendingEvent(LinkEventSender*); | 151 void dispatchPendingEvent(LinkEventSender*); |
136 static void dispatchPendingLoadEvents(); | 152 static void dispatchPendingLoadEvents(); |
137 | 153 |
138 // From LinkLoaderClient | 154 // From LinkLoaderClient |
139 virtual bool shouldLoadLink() OVERRIDE; | 155 virtual bool shouldLoadLink() OVERRIDE; |
140 | 156 |
141 // For LinkStyle | 157 // For LinkStyle |
142 bool loadLink(const String& type, const KURL& url) { return m_linkLoader.loa
dLink(m_relAttribute, type, url, document()); } | 158 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(); } | 159 bool isAlternate() const { return linkStyle()->isUnset() && m_relAttribute.i
sAlternate(); } |
144 bool shouldProcessStyle() { return linkStyleToProcess(); } | 160 bool shouldProcessStyle() { return linkResourceToProcess() && linkStyle(); } |
145 | 161 |
146 private: | 162 private: |
147 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERR
IDE; | 163 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERR
IDE; |
148 | 164 |
149 LinkStyle* linkStyle() const { return m_link.get(); } | 165 LinkStyle* linkStyle() const; |
150 LinkStyle* linkStyleToProcess(); | 166 LinkImport* linkImport() const; |
| 167 LinkResource* linkResourceToProcess(); |
151 | 168 |
152 void process(); | 169 void process(); |
153 static void processCallback(Node*); | 170 static void processCallback(Node*); |
154 | 171 |
155 // From Node and subclassses | 172 // From Node and subclassses |
156 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; | 173 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; |
157 virtual void removedFrom(ContainerNode*) OVERRIDE; | 174 virtual void removedFrom(ContainerNode*) OVERRIDE; |
158 virtual bool isURLAttribute(const Attribute&) const OVERRIDE; | 175 virtual bool isURLAttribute(const Attribute&) const OVERRIDE; |
159 virtual bool sheetLoaded() OVERRIDE; | 176 virtual bool sheetLoaded() OVERRIDE; |
160 virtual void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred)
OVERRIDE; | 177 virtual void notifyLoadedSheetAndAllCriticalSubresources(bool errorOccurred)
OVERRIDE; |
161 virtual void startLoadingDynamicSheet() OVERRIDE; | 178 virtual void startLoadingDynamicSheet() OVERRIDE; |
162 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const OVERRIDE; | 179 virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const OVERRIDE; |
163 virtual void finishParsingChildren(); | 180 virtual void finishParsingChildren(); |
164 | 181 |
165 // From LinkLoaderClient | 182 // From LinkLoaderClient |
166 virtual void linkLoaded() OVERRIDE; | 183 virtual void linkLoaded() OVERRIDE; |
167 virtual void linkLoadingErrored() OVERRIDE; | 184 virtual void linkLoadingErrored() OVERRIDE; |
168 virtual void didStartLinkPrerender() OVERRIDE; | 185 virtual void didStartLinkPrerender() OVERRIDE; |
169 virtual void didStopLinkPrerender() OVERRIDE; | 186 virtual void didStopLinkPrerender() OVERRIDE; |
170 virtual void didSendLoadForLinkPrerender() OVERRIDE; | 187 virtual void didSendLoadForLinkPrerender() OVERRIDE; |
171 virtual void didSendDOMContentLoadedForLinkPrerender() OVERRIDE; | 188 virtual void didSendDOMContentLoadedForLinkPrerender() OVERRIDE; |
172 | 189 |
173 private: | 190 private: |
174 HTMLLinkElement(const QualifiedName&, Document*, bool createdByParser); | 191 HTMLLinkElement(const QualifiedName&, Document*, bool createdByParser); |
175 | 192 |
176 OwnPtr<LinkStyle> m_link; | 193 RefPtr<LinkResource> m_link; |
177 LinkLoader m_linkLoader; | 194 LinkLoader m_linkLoader; |
178 | 195 |
179 String m_type; | 196 String m_type; |
180 String m_media; | 197 String m_media; |
181 RefPtr<DOMSettableTokenList> m_sizes; | 198 RefPtr<DOMSettableTokenList> m_sizes; |
182 LinkRelAttribute m_relAttribute; | 199 LinkRelAttribute m_relAttribute; |
183 | 200 |
184 bool m_createdByParser; | 201 bool m_createdByParser; |
185 bool m_isInShadowTree; | 202 bool m_isInShadowTree; |
186 int m_beforeLoadRecurseCount; | 203 int m_beforeLoadRecurseCount; |
187 }; | 204 }; |
188 | 205 |
189 } //namespace | 206 } //namespace |
190 | 207 |
191 #endif | 208 #endif |
OLD | NEW |