| 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, 2009, 2010 Apple Inc. All rights reserv
ed. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserv
ed. |
| 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 * |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "sky/engine/core/dom/Element.h" | 25 #include "sky/engine/core/dom/Element.h" |
| 26 #include "sky/engine/core/dom/IncrementLoadEventDelayCount.h" | 26 #include "sky/engine/core/dom/IncrementLoadEventDelayCount.h" |
| 27 #include "sky/engine/core/dom/Microtask.h" | 27 #include "sky/engine/core/dom/Microtask.h" |
| 28 #include "sky/engine/core/events/Event.h" | 28 #include "sky/engine/core/events/Event.h" |
| 29 #include "sky/engine/core/events/EventSender.h" | 29 #include "sky/engine/core/events/EventSender.h" |
| 30 #include "sky/engine/core/fetch/FetchRequest.h" | 30 #include "sky/engine/core/fetch/FetchRequest.h" |
| 31 #include "sky/engine/core/fetch/MemoryCache.h" | 31 #include "sky/engine/core/fetch/MemoryCache.h" |
| 32 #include "sky/engine/core/fetch/ResourceFetcher.h" | 32 #include "sky/engine/core/fetch/ResourceFetcher.h" |
| 33 #include "sky/engine/core/frame/LocalFrame.h" | 33 #include "sky/engine/core/frame/LocalFrame.h" |
| 34 #include "sky/engine/core/html/parser/HTMLParserIdioms.h" | 34 #include "sky/engine/core/html/parser/HTMLParserIdioms.h" |
| 35 #include "sky/engine/core/rendering/RenderImage.h" | |
| 36 #include "sky/engine/platform/Logging.h" | 35 #include "sky/engine/platform/Logging.h" |
| 37 #include "sky/engine/public/platform/WebURLRequest.h" | 36 #include "sky/engine/public/platform/WebURLRequest.h" |
| 38 | 37 |
| 39 namespace blink { | 38 namespace blink { |
| 40 | 39 |
| 41 static ImageEventSender& loadEventSender() | 40 static ImageEventSender& loadEventSender() |
| 42 { | 41 { |
| 43 DEFINE_STATIC_LOCAL(ImageEventSender, sender, (EventTypeNames::load)); | 42 DEFINE_STATIC_LOCAL(ImageEventSender, sender, (EventTypeNames::load)); |
| 44 return sender; | 43 return sender; |
| 45 } | 44 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 if (m_hasPendingErrorEvent) { | 147 if (m_hasPendingErrorEvent) { |
| 149 errorEventSender().cancelEvent(this); | 148 errorEventSender().cancelEvent(this); |
| 150 m_hasPendingErrorEvent = false; | 149 m_hasPendingErrorEvent = false; |
| 151 } | 150 } |
| 152 m_imageComplete = true; | 151 m_imageComplete = true; |
| 153 if (newImage) | 152 if (newImage) |
| 154 newImage->addClient(this); | 153 newImage->addClient(this); |
| 155 if (oldImage) | 154 if (oldImage) |
| 156 oldImage->removeClient(this); | 155 oldImage->removeClient(this); |
| 157 } | 156 } |
| 158 | |
| 159 if (RenderImageResource* imageResource = renderImageResource()) | |
| 160 imageResource->resetAnimation(); | |
| 161 } | 157 } |
| 162 | 158 |
| 163 inline void ImageLoader::crossSiteOrCSPViolationOccured(AtomicString imageSource
URL) | 159 inline void ImageLoader::crossSiteOrCSPViolationOccured(AtomicString imageSource
URL) |
| 164 { | 160 { |
| 165 m_failedLoadURL = imageSourceURL; | 161 m_failedLoadURL = imageSourceURL; |
| 166 m_hasPendingErrorEvent = true; | 162 m_hasPendingErrorEvent = true; |
| 167 errorEventSender().dispatchEventSoon(this); | 163 errorEventSender().dispatchEventSoon(this); |
| 168 } | 164 } |
| 169 | 165 |
| 170 inline void ImageLoader::clearFailedLoadURL() | 166 inline void ImageLoader::clearFailedLoadURL() |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 m_imageComplete = !newImage; | 239 m_imageComplete = !newImage; |
| 244 | 240 |
| 245 updateRenderer(); | 241 updateRenderer(); |
| 246 // If newImage exists and is cached, addClient() will result in the load
event | 242 // If newImage exists and is cached, addClient() will result in the load
event |
| 247 // being queued to fire. Ensure this happens after beforeload is dispatc
hed. | 243 // being queued to fire. Ensure this happens after beforeload is dispatc
hed. |
| 248 if (newImage) | 244 if (newImage) |
| 249 newImage->addClient(this); | 245 newImage->addClient(this); |
| 250 | 246 |
| 251 if (oldImage) | 247 if (oldImage) |
| 252 oldImage->removeClient(this); | 248 oldImage->removeClient(this); |
| 253 } else if (updateBehavior == UpdateSizeChanged && m_element->renderer() && m
_element->renderer()->isImage()) { | |
| 254 toRenderImage(m_element->renderer())->intrinsicSizeChanged(); | |
| 255 } | 249 } |
| 256 | 250 |
| 257 if (RenderImageResource* imageResource = renderImageResource()) | |
| 258 imageResource->resetAnimation(); | |
| 259 | |
| 260 // Only consider updating the protection ref-count of the Element immediatel
y before returning | 251 // Only consider updating the protection ref-count of the Element immediatel
y before returning |
| 261 // from this function as doing so might result in the destruction of this Im
ageLoader. | 252 // from this function as doing so might result in the destruction of this Im
ageLoader. |
| 262 updatedHasPendingEvent(); | 253 updatedHasPendingEvent(); |
| 263 } | 254 } |
| 264 | 255 |
| 265 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Lo
adType loadType) | 256 void ImageLoader::updateFromElement(UpdateFromElementBehavior updateBehavior, Lo
adType loadType) |
| 266 { | 257 { |
| 267 AtomicString imageSourceURL = m_element->imageSourceURL(); | 258 AtomicString imageSourceURL = m_element->imageSourceURL(); |
| 268 | 259 |
| 269 if (updateBehavior == UpdateIgnorePreviousError) | 260 if (updateBehavior == UpdateIgnorePreviousError) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 if (resource->wasCanceled()) { | 331 if (resource->wasCanceled()) { |
| 341 m_hasPendingLoadEvent = false; | 332 m_hasPendingLoadEvent = false; |
| 342 // Only consider updating the protection ref-count of the Element immedi
ately before returning | 333 // Only consider updating the protection ref-count of the Element immedi
ately before returning |
| 343 // from this function as doing so might result in the destruction of thi
s ImageLoader. | 334 // from this function as doing so might result in the destruction of thi
s ImageLoader. |
| 344 updatedHasPendingEvent(); | 335 updatedHasPendingEvent(); |
| 345 return; | 336 return; |
| 346 } | 337 } |
| 347 loadEventSender().dispatchEventSoon(this); | 338 loadEventSender().dispatchEventSoon(this); |
| 348 } | 339 } |
| 349 | 340 |
| 350 RenderImageResource* ImageLoader::renderImageResource() | |
| 351 { | |
| 352 RenderObject* renderer = m_element->renderer(); | |
| 353 | |
| 354 if (!renderer) | |
| 355 return 0; | |
| 356 | |
| 357 if (renderer->isImage()) | |
| 358 return toRenderImage(renderer)->imageResource(); | |
| 359 | |
| 360 return 0; | |
| 361 } | |
| 362 | |
| 363 void ImageLoader::updateRenderer() | 341 void ImageLoader::updateRenderer() |
| 364 { | 342 { |
| 365 RenderImageResource* imageResource = renderImageResource(); | |
| 366 | |
| 367 if (!imageResource) | |
| 368 return; | |
| 369 | |
| 370 // Only update the renderer if it doesn't have an image or if what we have | |
| 371 // is a complete image. This prevents flickering in the case where a dynami
c | |
| 372 // change is happening between two images. | |
| 373 ImageResource* cachedImage = imageResource->cachedImage(); | |
| 374 if (m_image != cachedImage && (m_imageComplete || !cachedImage)) | |
| 375 imageResource->setImageResource(m_image.get()); | |
| 376 } | 343 } |
| 377 | 344 |
| 378 void ImageLoader::updatedHasPendingEvent() | 345 void ImageLoader::updatedHasPendingEvent() |
| 379 { | 346 { |
| 380 // If an Element that does image loading is removed from the DOM the load/er
ror event for the image is still observable. | 347 // If an Element that does image loading is removed from the DOM the load/er
ror event for the image is still observable. |
| 381 // As long as the ImageLoader is actively loading, the Element itself needs
to be ref'ed to keep it from being | 348 // As long as the ImageLoader is actively loading, the Element itself needs
to be ref'ed to keep it from being |
| 382 // destroyed by DOM manipulation or garbage collection. | 349 // destroyed by DOM manipulation or garbage collection. |
| 383 // If such an Element wishes for the load to stop when removed from the DOM
it needs to stop the ImageLoader explicitly. | 350 // If such an Element wishes for the load to stop when removed from the DOM
it needs to stop the ImageLoader explicitly. |
| 384 bool wasProtected = m_elementIsProtected; | 351 bool wasProtected = m_elementIsProtected; |
| 385 m_elementIsProtected = m_hasPendingLoadEvent || m_hasPendingErrorEvent; | 352 m_elementIsProtected = m_hasPendingLoadEvent || m_hasPendingErrorEvent; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 void ImageLoader::sourceImageChanged() | 455 void ImageLoader::sourceImageChanged() |
| 489 { | 456 { |
| 490 HashSet<ImageLoaderClient*>::iterator end = m_clients.end(); | 457 HashSet<ImageLoaderClient*>::iterator end = m_clients.end(); |
| 491 for (HashSet<ImageLoaderClient*>::iterator it = m_clients.begin(); it != end
; ++it) { | 458 for (HashSet<ImageLoaderClient*>::iterator it = m_clients.begin(); it != end
; ++it) { |
| 492 ImageLoaderClient* handle = *it; | 459 ImageLoaderClient* handle = *it; |
| 493 handle->notifyImageSourceChanged(); | 460 handle->notifyImageSourceChanged(); |
| 494 } | 461 } |
| 495 } | 462 } |
| 496 | 463 |
| 497 } | 464 } |
| OLD | NEW |