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 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. | 5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
ed. |
6 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com) | 6 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com) |
7 * Copyright (C) 2011 Google Inc. All rights reserved. | 7 * Copyright (C) 2011 Google Inc. All rights reserved. |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 using namespace HTMLNames; | 56 using namespace HTMLNames; |
57 | 57 |
58 static LinkEventSender& linkLoadEventSender() | 58 static LinkEventSender& linkLoadEventSender() |
59 { | 59 { |
60 DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (eventNames().lo
adEvent)); | 60 DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (eventNames().lo
adEvent)); |
61 return sharedLoadEventSender; | 61 return sharedLoadEventSender; |
62 } | 62 } |
63 | 63 |
64 inline HTMLLinkElement::HTMLLinkElement(const QualifiedName& tagName, Document*
document, bool createdByParser) | 64 inline HTMLLinkElement::HTMLLinkElement(const QualifiedName& tagName, Document*
document, bool createdByParser) |
65 : HTMLElement(tagName, document) | 65 : HTMLElement(tagName, document) |
66 , m_link(adoptPtr(new LinkStyle(this))) | |
67 , m_linkLoader(this) | 66 , m_linkLoader(this) |
68 , m_sizes(DOMSettableTokenList::create()) | 67 , m_sizes(DOMSettableTokenList::create()) |
69 , m_createdByParser(createdByParser) | 68 , m_createdByParser(createdByParser) |
70 , m_isInShadowTree(false) | 69 , m_isInShadowTree(false) |
71 , m_beforeLoadRecurseCount(0) | 70 , m_beforeLoadRecurseCount(0) |
72 { | 71 { |
73 ASSERT(hasTagName(linkTag)); | 72 ASSERT(hasTagName(linkTag)); |
74 ScriptWrappable::init(this); | 73 ScriptWrappable::init(this); |
75 } | 74 } |
76 | 75 |
(...skipping 21 matching lines...) Expand all Loading... |
98 process(); | 97 process(); |
99 } else if (name == typeAttr) { | 98 } else if (name == typeAttr) { |
100 m_type = value; | 99 m_type = value; |
101 process(); | 100 process(); |
102 } else if (name == sizesAttr) { | 101 } else if (name == sizesAttr) { |
103 setSizes(value); | 102 setSizes(value); |
104 process(); | 103 process(); |
105 } else if (name == mediaAttr) { | 104 } else if (name == mediaAttr) { |
106 m_media = value.string().lower(); | 105 m_media = value.string().lower(); |
107 process(); | 106 process(); |
108 } else if (name == disabledAttr) | 107 } else if (name == disabledAttr) { |
109 m_link->setDisabledState(!value.isNull()); | 108 if (LinkStyle* link = linkStyle()) |
110 else if (name == onbeforeloadAttr) | 109 link->setDisabledState(!value.isNull()); |
| 110 } else if (name == onbeforeloadAttr) |
111 setAttributeEventListener(eventNames().beforeloadEvent, createAttributeE
ventListener(this, name, value)); | 111 setAttributeEventListener(eventNames().beforeloadEvent, createAttributeE
ventListener(this, name, value)); |
112 else { | 112 else { |
113 if (name == titleAttr) | 113 if (name == titleAttr) { |
114 m_link->setSheetTitle(value); | 114 if (LinkStyle* link = linkStyle()) |
| 115 link->setSheetTitle(value); |
| 116 } |
| 117 |
115 HTMLElement::parseAttribute(name, value); | 118 HTMLElement::parseAttribute(name, value); |
116 } | 119 } |
117 } | 120 } |
118 | 121 |
119 bool HTMLLinkElement::shouldLoadLink() | 122 bool HTMLLinkElement::shouldLoadLink() |
120 { | 123 { |
121 bool continueLoad = true; | 124 bool continueLoad = true; |
122 RefPtr<Document> originalDocument = document(); | 125 RefPtr<Document> originalDocument = document(); |
123 int recursionRank = ++m_beforeLoadRecurseCount; | 126 int recursionRank = ++m_beforeLoadRecurseCount; |
124 if (!dispatchBeforeLoadEvent(getNonEmptyURLAttribute(hrefAttr))) | 127 if (!dispatchBeforeLoadEvent(getNonEmptyURLAttribute(hrefAttr))) |
125 continueLoad = false; | 128 continueLoad = false; |
126 | 129 |
127 // A beforeload handler might have removed us from the document or changed t
he document. | 130 // A beforeload handler might have removed us from the document or changed t
he document. |
128 if (continueLoad && (!inDocument() || document() != originalDocument)) | 131 if (continueLoad && (!inDocument() || document() != originalDocument)) |
129 continueLoad = false; | 132 continueLoad = false; |
130 | 133 |
131 // If the beforeload handler recurses into the link element by mutating it,
we should only | 134 // If the beforeload handler recurses into the link element by mutating it,
we should only |
132 // let the latest (innermost) mutation occur. | 135 // let the latest (innermost) mutation occur. |
133 if (recursionRank != m_beforeLoadRecurseCount) | 136 if (recursionRank != m_beforeLoadRecurseCount) |
134 continueLoad = false; | 137 continueLoad = false; |
135 | 138 |
136 if (recursionRank == 1) | 139 if (recursionRank == 1) |
137 m_beforeLoadRecurseCount = 0; | 140 m_beforeLoadRecurseCount = 0; |
138 | 141 |
139 return continueLoad; | 142 return continueLoad; |
140 } | 143 } |
141 | 144 |
142 bool HTMLLinkElement::shouldProcessStyle() | 145 LinkStyle* HTMLLinkElement::linkStyleToProcess() |
143 { | 146 { |
144 bool should = inDocument() && !m_isInShadowTree; | 147 bool visible = inDocument() && !m_isInShadowTree; |
145 ASSERT(should || !m_link->hasSheet()); | 148 if (!visible) { |
146 return should; | 149 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); |
| 150 return 0; |
| 151 } |
| 152 |
| 153 if (!m_link) { |
| 154 m_link = adoptPtr(new LinkStyle(this)); |
| 155 if (fastHasAttribute(disabledAttr)) |
| 156 m_link->setDisabledState(true); |
| 157 } |
| 158 |
| 159 return m_link.get(); |
147 } | 160 } |
148 | 161 |
149 void HTMLLinkElement::process() | 162 void HTMLLinkElement::process() |
150 { | 163 { |
151 if (shouldProcessStyle()) | 164 if (LinkStyle* link = linkStyleToProcess()) |
152 m_link->process(); | 165 link->process(); |
153 } | 166 } |
154 | 167 |
155 Node::InsertionNotificationRequest HTMLLinkElement::insertedInto(ContainerNode*
insertionPoint) | 168 Node::InsertionNotificationRequest HTMLLinkElement::insertedInto(ContainerNode*
insertionPoint) |
156 { | 169 { |
157 HTMLElement::insertedInto(insertionPoint); | 170 HTMLElement::insertedInto(insertionPoint); |
158 if (!insertionPoint->inDocument()) | 171 if (!insertionPoint->inDocument()) |
159 return InsertionDone; | 172 return InsertionDone; |
160 | 173 |
161 m_isInShadowTree = isInShadowTree(); | 174 m_isInShadowTree = isInShadowTree(); |
162 if (m_isInShadowTree) | 175 if (m_isInShadowTree) |
163 return InsertionDone; | 176 return InsertionDone; |
164 | 177 |
165 document()->styleSheetCollection()->addStyleSheetCandidateNode(this, m_creat
edByParser); | 178 document()->styleSheetCollection()->addStyleSheetCandidateNode(this, m_creat
edByParser); |
166 | 179 |
167 process(); | 180 process(); |
168 return InsertionDone; | 181 return InsertionDone; |
169 } | 182 } |
170 | 183 |
171 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) | 184 void HTMLLinkElement::removedFrom(ContainerNode* insertionPoint) |
172 { | 185 { |
173 HTMLElement::removedFrom(insertionPoint); | 186 HTMLElement::removedFrom(insertionPoint); |
174 if (!insertionPoint->inDocument()) | 187 if (!insertionPoint->inDocument()) |
175 return; | 188 return; |
176 | 189 |
177 m_linkLoader.released(); | 190 m_linkLoader.released(); |
178 | 191 |
179 if (m_isInShadowTree) { | 192 if (m_isInShadowTree) { |
180 ASSERT(!m_link->hasSheet()); | 193 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); |
181 return; | 194 return; |
182 } | 195 } |
183 document()->styleSheetCollection()->removeStyleSheetCandidateNode(this); | 196 document()->styleSheetCollection()->removeStyleSheetCandidateNode(this); |
184 | 197 |
185 m_link->ownerRemoved(); | 198 if (LinkStyle* link = linkStyle()) |
| 199 link->ownerRemoved(); |
186 | 200 |
187 if (document()->renderer()) | 201 if (document()->renderer()) |
188 document()->styleResolverChanged(DeferRecalcStyle); | 202 document()->styleResolverChanged(DeferRecalcStyle); |
189 } | 203 } |
190 | 204 |
191 void HTMLLinkElement::finishParsingChildren() | 205 void HTMLLinkElement::finishParsingChildren() |
192 { | 206 { |
193 m_createdByParser = false; | 207 m_createdByParser = false; |
194 HTMLElement::finishParsingChildren(); | 208 HTMLElement::finishParsingChildren(); |
195 } | 209 } |
196 | 210 |
197 bool HTMLLinkElement::styleSheetIsLoading() const | 211 bool HTMLLinkElement::styleSheetIsLoading() const |
198 { | 212 { |
199 return m_link->styleSheetIsLoading(); | 213 return linkStyle() && linkStyle()->styleSheetIsLoading(); |
200 } | 214 } |
201 | 215 |
202 void HTMLLinkElement::linkLoaded() | 216 void HTMLLinkElement::linkLoaded() |
203 { | 217 { |
204 dispatchEvent(Event::create(eventNames().loadEvent, false, false)); | 218 dispatchEvent(Event::create(eventNames().loadEvent, false, false)); |
205 } | 219 } |
206 | 220 |
207 void HTMLLinkElement::linkLoadingErrored() | 221 void HTMLLinkElement::linkLoadingErrored() |
208 { | 222 { |
209 dispatchEvent(Event::create(eventNames().errorEvent, false, false)); | 223 dispatchEvent(Event::create(eventNames().errorEvent, false, false)); |
(...skipping 14 matching lines...) Expand all Loading... |
224 dispatchEvent(Event::create(eventNames().webkitprerenderloadEvent, false, fa
lse)); | 238 dispatchEvent(Event::create(eventNames().webkitprerenderloadEvent, false, fa
lse)); |
225 } | 239 } |
226 | 240 |
227 void HTMLLinkElement::didSendDOMContentLoadedForLinkPrerender() | 241 void HTMLLinkElement::didSendDOMContentLoadedForLinkPrerender() |
228 { | 242 { |
229 dispatchEvent(Event::create(eventNames().webkitprerenderdomcontentloadedEven
t, false, false)); | 243 dispatchEvent(Event::create(eventNames().webkitprerenderdomcontentloadedEven
t, false, false)); |
230 } | 244 } |
231 | 245 |
232 bool HTMLLinkElement::sheetLoaded() | 246 bool HTMLLinkElement::sheetLoaded() |
233 { | 247 { |
234 return m_link->sheetLoaded(); | 248 ASSERT(linkStyle()); |
| 249 return linkStyle()->sheetLoaded(); |
235 } | 250 } |
236 | 251 |
237 void HTMLLinkElement::notifyLoadedSheetAndAllCriticalSubresources(bool errorOccu
rred) | 252 void HTMLLinkElement::notifyLoadedSheetAndAllCriticalSubresources(bool errorOccu
rred) |
238 { | 253 { |
239 m_link->notifyLoadedSheetAndAllCriticalSubresources(errorOccurred); | 254 ASSERT(linkStyle()); |
| 255 linkStyle()->notifyLoadedSheetAndAllCriticalSubresources(errorOccurred); |
240 } | 256 } |
241 | 257 |
242 void HTMLLinkElement::dispatchPendingLoadEvents() | 258 void HTMLLinkElement::dispatchPendingLoadEvents() |
243 { | 259 { |
244 linkLoadEventSender().dispatchPendingEvents(); | 260 linkLoadEventSender().dispatchPendingEvents(); |
245 } | 261 } |
246 | 262 |
247 void HTMLLinkElement::dispatchPendingEvent(LinkEventSender* eventSender) | 263 void HTMLLinkElement::dispatchPendingEvent(LinkEventSender* eventSender) |
248 { | 264 { |
249 ASSERT_UNUSED(eventSender, eventSender == &linkLoadEventSender()); | 265 ASSERT_UNUSED(eventSender, eventSender == &linkLoadEventSender()); |
250 if (m_link->hasLoadedSheet()) | 266 ASSERT(linkStyle()); |
| 267 if (linkStyle()->hasLoadedSheet()) |
251 linkLoaded(); | 268 linkLoaded(); |
252 else | 269 else |
253 linkLoadingErrored(); | 270 linkLoadingErrored(); |
254 } | 271 } |
255 | 272 |
256 void HTMLLinkElement::startLoadingDynamicSheet() | 273 void HTMLLinkElement::startLoadingDynamicSheet() |
257 { | 274 { |
258 m_link->startLoadingDynamicSheet(); | 275 ASSERT(linkStyle()); |
| 276 linkStyle()->startLoadingDynamicSheet(); |
259 } | 277 } |
260 | 278 |
261 bool HTMLLinkElement::isURLAttribute(const Attribute& attribute) const | 279 bool HTMLLinkElement::isURLAttribute(const Attribute& attribute) const |
262 { | 280 { |
263 return attribute.name().localName() == hrefAttr || HTMLElement::isURLAttribu
te(attribute); | 281 return attribute.name().localName() == hrefAttr || HTMLElement::isURLAttribu
te(attribute); |
264 } | 282 } |
265 | 283 |
266 KURL HTMLLinkElement::href() const | 284 KURL HTMLLinkElement::href() const |
267 { | 285 { |
268 return document()->completeURL(getAttribute(hrefAttr)); | 286 return document()->completeURL(getAttribute(hrefAttr)); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 void LinkStyle::ownerRemoved() | 590 void LinkStyle::ownerRemoved() |
573 { | 591 { |
574 if (m_sheet) | 592 if (m_sheet) |
575 clearSheet(); | 593 clearSheet(); |
576 | 594 |
577 if (styleSheetIsLoading()) | 595 if (styleSheetIsLoading()) |
578 removePendingSheet(RemovePendingSheetNotifyLater); | 596 removePendingSheet(RemovePendingSheetNotifyLater); |
579 } | 597 } |
580 | 598 |
581 } // namespace WebCore | 599 } // namespace WebCore |
OLD | NEW |