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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #include <wtf/StdLibExtras.h> | 28 #include <wtf/StdLibExtras.h> |
29 #include "HTMLNames.h" | 29 #include "HTMLNames.h" |
30 #include "bindings/v8/ScriptEventListener.h" | 30 #include "bindings/v8/ScriptEventListener.h" |
31 #include "core/css/MediaList.h" | 31 #include "core/css/MediaList.h" |
32 #include "core/css/MediaQueryEvaluator.h" | 32 #include "core/css/MediaQueryEvaluator.h" |
33 #include "core/css/StyleSheetContents.h" | 33 #include "core/css/StyleSheetContents.h" |
34 #include "core/css/resolver/StyleResolver.h" | 34 #include "core/css/resolver/StyleResolver.h" |
35 #include "core/dom/Attribute.h" | 35 #include "core/dom/Attribute.h" |
36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/dom/DocumentFragment.h" |
37 #include "core/dom/DocumentStyleSheetCollection.h" | 38 #include "core/dom/DocumentStyleSheetCollection.h" |
38 #include "core/dom/Event.h" | 39 #include "core/dom/Event.h" |
39 #include "core/dom/EventSender.h" | 40 #include "core/dom/EventSender.h" |
| 41 #include "core/html/HTMLImportsController.h" |
40 #include "core/loader/FrameLoader.h" | 42 #include "core/loader/FrameLoader.h" |
41 #include "core/loader/cache/CachedCSSStyleSheet.h" | 43 #include "core/loader/cache/CachedCSSStyleSheet.h" |
42 #include "core/loader/cache/CachedResourceLoader.h" | 44 #include "core/loader/cache/CachedResourceLoader.h" |
43 #include "core/loader/cache/CachedResourceRequest.h" | 45 #include "core/loader/cache/CachedResourceRequest.h" |
44 #include "core/page/Frame.h" | 46 #include "core/page/Frame.h" |
45 #include "core/page/FrameView.h" | 47 #include "core/page/FrameView.h" |
46 | 48 |
47 namespace WebCore { | 49 namespace WebCore { |
48 | 50 |
49 using namespace HTMLNames; | 51 using namespace HTMLNames; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // let the latest (innermost) mutation occur. | 130 // let the latest (innermost) mutation occur. |
129 if (recursionRank != m_beforeLoadRecurseCount) | 131 if (recursionRank != m_beforeLoadRecurseCount) |
130 continueLoad = false; | 132 continueLoad = false; |
131 | 133 |
132 if (recursionRank == 1) | 134 if (recursionRank == 1) |
133 m_beforeLoadRecurseCount = 0; | 135 m_beforeLoadRecurseCount = 0; |
134 | 136 |
135 return continueLoad; | 137 return continueLoad; |
136 } | 138 } |
137 | 139 |
138 LinkStyle* HTMLLinkElement::linkStyleToProcess() | 140 LinkResource* HTMLLinkElement::linkResourceToProcess() |
139 { | 141 { |
140 bool visible = inDocument() && !m_isInShadowTree; | 142 bool visible = inDocument() && !m_isInShadowTree; |
141 if (!visible) { | 143 if (!visible) { |
142 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); | 144 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); |
143 return 0; | 145 return 0; |
144 } | 146 } |
145 | 147 |
146 if (!m_link) { | 148 if (!m_link) { |
147 m_link = adoptPtr(new LinkStyle(this)); | 149 if (m_relAttribute.isImport() && RuntimeEnabledFeatures::htmlImportsEnab
led()) |
148 if (fastHasAttribute(disabledAttr)) | 150 m_link = LinkImport::create(this); |
149 m_link->setDisabledState(true); | 151 else { |
| 152 RefPtr<LinkStyle> link = LinkStyle::create(this); |
| 153 if (fastHasAttribute(disabledAttr)) |
| 154 link->setDisabledState(true); |
| 155 m_link = link.release(); |
| 156 } |
150 } | 157 } |
151 | 158 |
152 return m_link.get(); | 159 return m_link.get(); |
153 } | 160 } |
154 | 161 |
| 162 LinkStyle* HTMLLinkElement::linkStyle() const |
| 163 { |
| 164 if (!m_link || m_link->type() != LinkResource::Style) |
| 165 return 0; |
| 166 return static_cast<LinkStyle*>(m_link.get()); |
| 167 } |
| 168 |
| 169 LinkImport* HTMLLinkElement::linkImport() const |
| 170 { |
| 171 if (!m_link || m_link->type() != LinkResource::Import) |
| 172 return 0; |
| 173 return static_cast<LinkImport*>(m_link.get()); |
| 174 } |
| 175 |
| 176 DocumentFragment* HTMLLinkElement::import() const |
| 177 { |
| 178 if (LinkImport* link = linkImport()) |
| 179 return linkImport()->importedFragment(); |
| 180 return 0; |
| 181 } |
| 182 |
155 void HTMLLinkElement::process() | 183 void HTMLLinkElement::process() |
156 { | 184 { |
157 if (LinkStyle* link = linkStyleToProcess()) | 185 if (LinkResource* link = linkResourceToProcess()) |
158 link->process(); | 186 link->process(); |
159 } | 187 } |
160 | 188 |
161 Node::InsertionNotificationRequest HTMLLinkElement::insertedInto(ContainerNode*
insertionPoint) | 189 Node::InsertionNotificationRequest HTMLLinkElement::insertedInto(ContainerNode*
insertionPoint) |
162 { | 190 { |
163 HTMLElement::insertedInto(insertionPoint); | 191 HTMLElement::insertedInto(insertionPoint); |
164 if (!insertionPoint->inDocument()) | 192 if (!insertionPoint->inDocument()) |
165 return InsertionDone; | 193 return InsertionDone; |
166 | 194 |
167 m_isInShadowTree = isInShadowTree(); | 195 m_isInShadowTree = isInShadowTree(); |
(...skipping 13 matching lines...) Expand all Loading... |
181 return; | 209 return; |
182 | 210 |
183 m_linkLoader.released(); | 211 m_linkLoader.released(); |
184 | 212 |
185 if (m_isInShadowTree) { | 213 if (m_isInShadowTree) { |
186 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); | 214 ASSERT(!linkStyle() || !linkStyle()->hasSheet()); |
187 return; | 215 return; |
188 } | 216 } |
189 document()->styleSheetCollection()->removeStyleSheetCandidateNode(this); | 217 document()->styleSheetCollection()->removeStyleSheetCandidateNode(this); |
190 | 218 |
191 if (LinkStyle* link = linkStyle()) | 219 if (m_link) |
192 link->ownerRemoved(); | 220 m_link->ownerRemoved(); |
193 | 221 |
194 if (document()->renderer()) | 222 if (document()->renderer()) |
195 document()->styleResolverChanged(DeferRecalcStyle); | 223 document()->styleResolverChanged(DeferRecalcStyle); |
196 } | 224 } |
197 | 225 |
198 void HTMLLinkElement::finishParsingChildren() | 226 void HTMLLinkElement::finishParsingChildren() |
199 { | 227 { |
200 m_createdByParser = false; | 228 m_createdByParser = false; |
201 HTMLElement::finishParsingChildren(); | 229 HTMLElement::finishParsingChildren(); |
202 } | 230 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 { | 355 { |
328 return m_sizes.get(); | 356 return m_sizes.get(); |
329 } | 357 } |
330 | 358 |
331 void HTMLLinkElement::setSizes(const String& value) | 359 void HTMLLinkElement::setSizes(const String& value) |
332 { | 360 { |
333 m_sizes->setValue(value); | 361 m_sizes->setValue(value); |
334 } | 362 } |
335 | 363 |
336 | 364 |
| 365 PassRefPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) |
| 366 { |
| 367 return adoptRef(new LinkStyle(owner)); |
| 368 } |
| 369 |
337 LinkStyle::LinkStyle(HTMLLinkElement* owner) | 370 LinkStyle::LinkStyle(HTMLLinkElement* owner) |
338 : m_owner(owner) | 371 : LinkResource(owner) |
339 , m_disabledState(Unset) | 372 , m_disabledState(Unset) |
340 , m_pendingSheetType(None) | 373 , m_pendingSheetType(None) |
341 , m_loading(false) | 374 , m_loading(false) |
342 , m_firedLoad(false) | 375 , m_firedLoad(false) |
343 , m_loadedSheet(false) | 376 , m_loadedSheet(false) |
344 { | 377 { |
345 } | 378 } |
346 | 379 |
347 LinkStyle::~LinkStyle() | 380 LinkStyle::~LinkStyle() |
348 { | 381 { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 process(); | 537 process(); |
505 } else | 538 } else |
506 m_owner->document()->styleResolverChanged(DeferRecalcStyle); // Upda
te the style selector. | 539 m_owner->document()->styleResolverChanged(DeferRecalcStyle); // Upda
te the style selector. |
507 } | 540 } |
508 } | 541 } |
509 | 542 |
510 void LinkStyle::process() | 543 void LinkStyle::process() |
511 { | 544 { |
512 ASSERT(m_owner->shouldProcessStyle()); | 545 ASSERT(m_owner->shouldProcessStyle()); |
513 String type = m_owner->typeValue().lower(); | 546 String type = m_owner->typeValue().lower(); |
514 KURL url = m_owner->getNonEmptyURLAttribute(hrefAttr); | 547 LinkRequestBuilder builder(m_owner); |
515 | 548 |
516 if (m_owner->relAttribute().iconType() != InvalidIcon && url.isValid() && !u
rl.isEmpty()) { | 549 if (m_owner->relAttribute().iconType() != InvalidIcon && builder.url().isVal
id() && !builder.url().isEmpty()) { |
517 if (!m_owner->shouldLoadLink()) | 550 if (!m_owner->shouldLoadLink()) |
518 return; | 551 return; |
519 if (document()->frame()) | 552 if (document()->frame()) |
520 document()->frame()->loader()->didChangeIcons(m_owner->relAttribute(
).iconType()); | 553 document()->frame()->loader()->didChangeIcons(m_owner->relAttribute(
).iconType()); |
521 } | 554 } |
522 | 555 |
523 if (!m_owner->loadLink(type, url)) | 556 if (!m_owner->loadLink(type, builder.url())) |
524 return; | 557 return; |
525 | 558 |
526 if ((m_disabledState != Disabled) && m_owner->relAttribute().isStyleSheet() | 559 if ((m_disabledState != Disabled) && m_owner->relAttribute().isStyleSheet() |
527 && document()->frame() && url.isValid()) { | 560 && document()->frame() && builder.url().isValid()) { |
528 | |
529 String charset = m_owner->getAttribute(charsetAttr); | |
530 if (charset.isEmpty() && document()->frame()) | |
531 charset = document()->charset(); | |
532 | 561 |
533 if (m_cachedSheet) { | 562 if (m_cachedSheet) { |
534 removePendingSheet(); | 563 removePendingSheet(); |
535 m_cachedSheet->removeClient(this); | 564 m_cachedSheet->removeClient(this); |
536 m_cachedSheet = 0; | 565 m_cachedSheet = 0; |
537 } | 566 } |
538 | 567 |
539 if (!m_owner->shouldLoadLink()) | 568 if (!m_owner->shouldLoadLink()) |
540 return; | 569 return; |
541 | 570 |
542 m_loading = true; | 571 m_loading = true; |
543 | 572 |
544 bool mediaQueryMatches = true; | 573 bool mediaQueryMatches = true; |
545 if (!m_owner->media().isEmpty()) { | 574 if (!m_owner->media().isEmpty()) { |
546 RefPtr<RenderStyle> documentStyle = StyleResolver::styleForDocument(
document()); | 575 RefPtr<RenderStyle> documentStyle = StyleResolver::styleForDocument(
document()); |
547 RefPtr<MediaQuerySet> media = MediaQuerySet::createAllowingDescripti
onSyntax(m_owner->media()); | 576 RefPtr<MediaQuerySet> media = MediaQuerySet::createAllowingDescripti
onSyntax(m_owner->media()); |
548 MediaQueryEvaluator evaluator(document()->frame()->view()->mediaType
(), document()->frame(), documentStyle.get()); | 577 MediaQueryEvaluator evaluator(document()->frame()->view()->mediaType
(), document()->frame(), documentStyle.get()); |
549 mediaQueryMatches = evaluator.eval(media.get()); | 578 mediaQueryMatches = evaluator.eval(media.get()); |
550 } | 579 } |
551 | 580 |
552 // Don't hold up render tree construction and script execution on styles
heets | 581 // Don't hold up render tree construction and script execution on styles
heets |
553 // that are not needed for the rendering at the moment. | 582 // that are not needed for the rendering at the moment. |
554 bool blocking = mediaQueryMatches && !m_owner->isAlternate(); | 583 bool blocking = mediaQueryMatches && !m_owner->isAlternate(); |
555 addPendingSheet(blocking ? Blocking : NonBlocking); | 584 addPendingSheet(blocking ? Blocking : NonBlocking); |
556 | 585 |
557 // Load stylesheets that are not needed for the rendering immediately wi
th low priority. | 586 // Load stylesheets that are not needed for the rendering immediately wi
th low priority. |
558 ResourceLoadPriority priority = blocking ? ResourceLoadPriorityUnresolve
d : ResourceLoadPriorityVeryLow; | 587 CachedResourceRequest request = builder.build(blocking); |
559 CachedResourceRequest request(ResourceRequest(document()->completeURL(ur
l)), m_owner->localName(), charset, priority); | |
560 m_cachedSheet = document()->cachedResourceLoader()->requestCSSStyleSheet
(request); | 588 m_cachedSheet = document()->cachedResourceLoader()->requestCSSStyleSheet
(request); |
561 | 589 |
562 if (m_cachedSheet) | 590 if (m_cachedSheet) |
563 m_cachedSheet->addClient(this); | 591 m_cachedSheet->addClient(this); |
564 else { | 592 else { |
565 // The request may have been denied if (for example) the stylesheet
is local and the document is remote. | 593 // The request may have been denied if (for example) the stylesheet
is local and the document is remote. |
566 m_loading = false; | 594 m_loading = false; |
567 removePendingSheet(); | 595 removePendingSheet(); |
568 } | 596 } |
569 } else if (m_sheet) { | 597 } else if (m_sheet) { |
(...skipping 12 matching lines...) Expand all Loading... |
582 void LinkStyle::ownerRemoved() | 610 void LinkStyle::ownerRemoved() |
583 { | 611 { |
584 if (m_sheet) | 612 if (m_sheet) |
585 clearSheet(); | 613 clearSheet(); |
586 | 614 |
587 if (styleSheetIsLoading()) | 615 if (styleSheetIsLoading()) |
588 removePendingSheet(RemovePendingSheetNotifyLater); | 616 removePendingSheet(RemovePendingSheetNotifyLater); |
589 } | 617 } |
590 | 618 |
591 } // namespace WebCore | 619 } // namespace WebCore |
OLD | NEW |