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) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
20 */ | 20 */ |
21 | 21 |
22 #include "core/html/HTMLImageLoader.h" | 22 #include "core/html/HTMLImageLoader.h" |
23 | 23 |
24 #include "core/HTMLNames.h" | 24 #include "core/HTMLNames.h" |
25 #include "core/dom/Element.h" | 25 #include "core/dom/Element.h" |
26 #include "core/events/Event.h" | 26 #include "core/events/Event.h" |
| 27 #include "core/events/EventSender.h" |
27 #include "core/fetch/ImageResource.h" | 28 #include "core/fetch/ImageResource.h" |
28 #include "core/fetch/ResourceLoadingLog.h" | 29 #include "core/fetch/ResourceLoadingLog.h" |
29 #include "core/html/HTMLImageElement.h" | 30 #include "core/html/HTMLImageElement.h" |
30 #include "core/html/HTMLInputElement.h" | 31 #include "core/html/HTMLInputElement.h" |
31 #include "core/html/HTMLObjectElement.h" | 32 #include "core/html/HTMLObjectElement.h" |
32 #include "core/html/parser/HTMLParserIdioms.h" | 33 #include "core/html/parser/HTMLParserIdioms.h" |
33 | 34 |
34 namespace blink { | 35 namespace blink { |
35 | 36 |
36 using namespace HTMLNames; | 37 using namespace HTMLNames; |
37 | 38 |
| 39 static ImageEventSender& loadendEventSender() |
| 40 { |
| 41 DEFINE_STATIC_LOCAL(ImageEventSender, sender, (ImageEventSender::create(Even
tTypeNames::loadend))); |
| 42 return sender; |
| 43 } |
| 44 |
| 45 void HTMLImageLoader::dispatchPendingLoadendEvents() |
| 46 { |
| 47 loadendEventSender().dispatchPendingEvents(); |
| 48 } |
| 49 |
38 HTMLImageLoader::HTMLImageLoader(Element* element) | 50 HTMLImageLoader::HTMLImageLoader(Element* element) |
39 : ImageLoader(element) | 51 : ImageLoader(element) |
40 { | 52 { |
41 } | 53 } |
42 | 54 |
43 HTMLImageLoader::~HTMLImageLoader() | 55 HTMLImageLoader::~HTMLImageLoader() |
44 { | 56 { |
45 } | 57 } |
46 | 58 |
47 void HTMLImageLoader::dispatchLoadEvent() | 59 void HTMLImageLoader::dispatchLoadEvent() |
48 { | 60 { |
49 RESOURCE_LOADING_DVLOG(1) << "HTMLImageLoader::dispatchLoadEvent " << this; | 61 RESOURCE_LOADING_DVLOG(1) << "HTMLImageLoader::dispatchLoadEvent " << this; |
50 | 62 |
51 // HTMLVideoElement uses this class to load the poster image, but it should
not fire events for loading or failure. | 63 // HTMLVideoElement uses this class to load the poster image, but it should
not fire events for loading or failure. |
52 if (isHTMLVideoElement(*element())) | 64 if (isHTMLVideoElement(*element())) |
53 return; | 65 return; |
54 | 66 |
55 bool errorOccurred = image()->errorOccurred(); | 67 bool errorOccurred = image()->errorOccurred(); |
56 if (isHTMLObjectElement(*element()) && !errorOccurred) | 68 if (isHTMLObjectElement(*element()) && !errorOccurred) |
57 errorOccurred = (image()->response().httpStatusCode() >= 400); // An <ob
ject> considers a 404 to be an error and should fire onerror. | 69 errorOccurred = (image()->response().httpStatusCode() >= 400); // An <ob
ject> considers a 404 to be an error and should fire onerror. |
58 element()->dispatchEvent(Event::create(errorOccurred ? EventTypeNames::error
: EventTypeNames::load)); | 70 element()->dispatchEvent(Event::create(errorOccurred ? EventTypeNames::error
: EventTypeNames::load)); |
59 } | 71 } |
60 | 72 |
| 73 void HTMLImageLoader::dispatchLoadendEvent() |
| 74 { |
| 75 RESOURCE_LOADING_DVLOG(1) << "HTMLImageLoader::dispatchLoadendEvent " << thi
s; |
| 76 |
| 77 if (isHTMLImageElement(*element())) |
| 78 element()->dispatchEvent(Event::create(EventTypeNames::loadend)); |
| 79 } |
| 80 |
| 81 void HTMLImageLoader::dispatchLoadendEventSoon() |
| 82 { |
| 83 RESOURCE_LOADING_DVLOG(1) << "HTMLImageLoader::dispatchLoadendEventSoon " <<
this; |
| 84 |
| 85 if (isHTMLImageElement(*element())) |
| 86 loadendEventSender().dispatchEventSoon(this); |
| 87 } |
| 88 |
61 static void loadFallbackContentForElement(Element* element) | 89 static void loadFallbackContentForElement(Element* element) |
62 { | 90 { |
63 if (isHTMLImageElement(element)) | 91 if (isHTMLImageElement(element)) |
64 toHTMLImageElement(element)->ensureFallbackContent(); | 92 toHTMLImageElement(element)->ensureFallbackContent(); |
65 else if (isHTMLInputElement(element)) | 93 else if (isHTMLInputElement(element)) |
66 toHTMLInputElement(element)->ensureFallbackContent(); | 94 toHTMLInputElement(element)->ensureFallbackContent(); |
67 } | 95 } |
68 | 96 |
69 void HTMLImageLoader::noImageResourceToLoad() | 97 void HTMLImageLoader::noImageResourceToLoad() |
70 { | 98 { |
(...skipping 18 matching lines...) Expand all Loading... |
89 | 117 |
90 if (isHTMLInputElement(*element)) { | 118 if (isHTMLInputElement(*element)) { |
91 if (loadError) | 119 if (loadError) |
92 ensureFallbackContent(); | 120 ensureFallbackContent(); |
93 else | 121 else |
94 toHTMLInputElement(element)->ensurePrimaryContent(); | 122 toHTMLInputElement(element)->ensurePrimaryContent(); |
95 } | 123 } |
96 | 124 |
97 if ((loadError || cachedImage->response().httpStatusCode() >= 400) && isHTML
ObjectElement(*element)) | 125 if ((loadError || cachedImage->response().httpStatusCode() >= 400) && isHTML
ObjectElement(*element)) |
98 toHTMLObjectElement(element)->renderFallbackContent(); | 126 toHTMLObjectElement(element)->renderFallbackContent(); |
| 127 dispatchLoadendEventSoon(); |
99 } | 128 } |
100 | 129 |
101 void HTMLImageLoader::ensureFallbackContent() | 130 void HTMLImageLoader::ensureFallbackContent() |
102 { | 131 { |
103 loadFallbackContentForElement(element()); | 132 loadFallbackContentForElement(element()); |
104 } | 133 } |
105 | 134 |
106 } // namespace blink | 135 } // namespace blink |
OLD | NEW |